2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Netscape security libraries.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1994-2000 Netscape Communications Corporation. All
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
36 #include <security_asn1/secasn1.h>
37 #include <security_asn1/secerr.h>
39 const SecAsn1Template SECOID_AlgorithmIDTemplate
[] = {
41 0, NULL
, sizeof(SECAlgorithmID
) },
43 offsetof(SECAlgorithmID
,algorithm
), },
44 { SEC_ASN1_OPTIONAL
| SEC_ASN1_ANY
,
45 offsetof(SECAlgorithmID
,parameters
), },
50 SECOID_GetAlgorithmTag(const SECAlgorithmID
*id
)
52 if (id
== NULL
|| id
->algorithm
.Data
== NULL
)
53 return SEC_OID_UNKNOWN
;
55 return SECOID_FindOIDTag (&(id
->algorithm
));
59 SECOID_SetAlgorithmID(PRArenaPool
*arena
, SECAlgorithmID
*id
, SECOidTag which
,
63 Boolean add_null_param
;
65 oiddata
= SECOID_FindOIDByTag(which
);
68 PORT_SetError(SEC_ERROR_INVALID_ALGORITHM
);
72 if (SECITEM_CopyItem(arena
, &id
->algorithm
, &oiddata
->oid
))
84 case SEC_OID_PKCS1_RSA_ENCRYPTION
:
85 case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION
:
86 case SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION
:
87 case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION
:
88 case SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION
:
89 case SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION
:
90 case SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION
:
91 case SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION
:
92 add_null_param
= PR_TRUE
;
95 add_null_param
= PR_FALSE
;
101 * I am specifically *not* enforcing the following assertion
102 * (by following it up with an error and a return of failure)
103 * because I do not want to introduce any change in the current
104 * behavior. But I do want for us to notice if the following is
105 * ever true, because I do not think it should be so and probably
106 * signifies an error/bug somewhere.
107 * This assertion removed Sep 9 2008 by dmitch, we really do need
108 * to be able to do this for an odd SEC_OID_EC_PUBLIC_KEY case.
110 PORT_Assert(!add_null_param || (params->Length == 2
111 && params->Data[0] == SEC_ASN1_NULL
112 && params->Data[1] == 0));
114 if (SECITEM_CopyItem(arena
, &id
->parameters
, params
)) {
119 * Again, this is not considered an error. But if we assume
120 * that nobody tries to set the parameters field themselves
121 * (but always uses this routine to do that), then we should
122 * not hit the following assertion. Unless they forgot to zero
123 * the structure, which could also be a bad (and wrong) thing.
125 PORT_Assert(id
->parameters
.Data
== NULL
);
127 if (add_null_param
) {
128 (void) SECITEM_AllocItem(arena
, &id
->parameters
, 2);
129 if (id
->parameters
.Data
== NULL
) {
132 id
->parameters
.Data
[0] = SEC_ASN1_NULL
;
133 id
->parameters
.Data
[1] = 0;
141 SECOID_CopyAlgorithmID(PRArenaPool
*arena
, SECAlgorithmID
*to
, const SECAlgorithmID
*from
)
145 rv
= SECITEM_CopyItem(arena
, &to
->algorithm
, &from
->algorithm
);
147 rv
= SECITEM_CopyItem(arena
, &to
->parameters
, &from
->parameters
);
151 void SECOID_DestroyAlgorithmID(SECAlgorithmID
*algid
, Boolean freeit
)
153 SECITEM_FreeItem(&algid
->parameters
, PR_FALSE
);
154 SECITEM_FreeItem(&algid
->algorithm
, PR_FALSE
);
155 if(freeit
== PR_TRUE
)
160 SECOID_CompareAlgorithmID(const SECAlgorithmID
*a
, const SECAlgorithmID
*b
)
164 rv
= SECITEM_CompareItem(&a
->algorithm
, &b
->algorithm
);
166 rv
= SECITEM_CompareItem(&a
->parameters
, &b
->parameters
);
170 /* This functions simply returns the address of the above-declared template. */
171 SEC_ASN1_CHOOSER_IMPLEMENT(SECOID_AlgorithmIDTemplate
)