1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is the Netscape security libraries.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corporation.
18
* Portions created by the Initial Developer are Copyright (C) 1994-2000
19
* the Initial Developer. All Rights Reserved.
23
* Alternatively, the contents of this file may be used under the terms of
24
* either the GNU General Public License Version 2 or later (the "GPL"), or
25
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26
* in which case the provisions of the GPL or the LGPL are applicable instead
27
* of those above. If you wish to allow use of your version of this file only
28
* under the terms of either the GPL or the LGPL, and not to allow others to
29
* use your version of this file under the terms of the MPL, indicate your
30
* decision by deleting the provisions above and replace them with the notice
31
* and other provisions required by the GPL or the LGPL. If you do not delete
32
* the provisions above, a recipient may use your version of this file under
33
* the terms of any one of the MPL, the GPL or the LGPL.
35
* ***** END LICENSE BLOCK ***** */
38
#include "secder.h" /* XXX remove this when remove the DERTemplate */
43
/* XXX Old template; want to expunge it eventually. */
44
DERTemplate SECAlgorithmIDTemplate[] = {
46
0, NULL, sizeof(SECAlgorithmID) },
48
offsetof(SECAlgorithmID,algorithm), },
49
{ DER_OPTIONAL | DER_ANY,
50
offsetof(SECAlgorithmID,parameters), },
54
const SEC_ASN1Template SECOID_AlgorithmIDTemplate[] = {
56
0, NULL, sizeof(SECAlgorithmID) },
58
offsetof(SECAlgorithmID,algorithm), },
59
{ SEC_ASN1_OPTIONAL | SEC_ASN1_ANY,
60
offsetof(SECAlgorithmID,parameters), },
65
SECOID_GetAlgorithmTag(SECAlgorithmID *id)
67
if (id == NULL || id->algorithm.data == NULL)
68
return SEC_OID_UNKNOWN;
70
return SECOID_FindOIDTag (&(id->algorithm));
74
SECOID_SetAlgorithmID(PRArenaPool *arena, SECAlgorithmID *id, SECOidTag which,
78
PRBool add_null_param;
80
oiddata = SECOID_FindOIDByTag(which);
82
PORT_SetError(SEC_ERROR_INVALID_ALGORITHM);
86
if (SECITEM_CopyItem(arena, &id->algorithm, &oiddata->oid))
97
case SEC_OID_PKCS1_RSA_ENCRYPTION:
98
case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION:
99
case SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION:
100
case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION:
101
case SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION:
102
case SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION:
103
case SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION:
104
case SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION:
105
add_null_param = PR_TRUE;
108
add_null_param = PR_FALSE;
114
* I am specifically *not* enforcing the following assertion
115
* (by following it up with an error and a return of failure)
116
* because I do not want to introduce any change in the current
117
* behavior. But I do want for us to notice if the following is
118
* ever true, because I do not think it should be so and probably
119
* signifies an error/bug somewhere.
121
PORT_Assert(!add_null_param || (params->len == 2
122
&& params->data[0] == SEC_ASN1_NULL
123
&& params->data[1] == 0));
124
if (SECITEM_CopyItem(arena, &id->parameters, params)) {
129
* Again, this is not considered an error. But if we assume
130
* that nobody tries to set the parameters field themselves
131
* (but always uses this routine to do that), then we should
132
* not hit the following assertion. Unless they forgot to zero
133
* the structure, which could also be a bad (and wrong) thing.
135
PORT_Assert(id->parameters.data == NULL);
137
if (add_null_param) {
138
(void) SECITEM_AllocItem(arena, &id->parameters, 2);
139
if (id->parameters.data == NULL) {
142
id->parameters.data[0] = SEC_ASN1_NULL;
143
id->parameters.data[1] = 0;
151
SECOID_CopyAlgorithmID(PRArenaPool *arena, SECAlgorithmID *to, SECAlgorithmID *from)
155
rv = SECITEM_CopyItem(arena, &to->algorithm, &from->algorithm);
157
rv = SECITEM_CopyItem(arena, &to->parameters, &from->parameters);
161
void SECOID_DestroyAlgorithmID(SECAlgorithmID *algid, PRBool freeit)
163
SECITEM_FreeItem(&algid->parameters, PR_FALSE);
164
SECITEM_FreeItem(&algid->algorithm, PR_FALSE);
165
if(freeit == PR_TRUE)
170
SECOID_CompareAlgorithmID(SECAlgorithmID *a, SECAlgorithmID *b)
174
rv = SECITEM_CompareItem(&a->algorithm, &b->algorithm);
176
rv = SECITEM_CompareItem(&a->parameters, &b->parameters);
180
/* This functions simply returns the address of the above-declared template. */
181
SEC_ASN1_CHOOSER_IMPLEMENT(SECOID_AlgorithmIDTemplate)