2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 * oidsalg.c - OIDs defining crypto algorithms
29 #include <Security/oidsbase.h>
30 #include <Security/cssmtype.h>
31 #include "cssmapple.h"
32 #include <Security/oidsalg.h>
35 #pragma mark ----- CSSM_OID <--> CSSM_ALGORITHMS -----
42 static const OidToAlgEnt oidToAlgMap
[] =
44 {&CSSMOID_RSA
, CSSM_ALGID_RSA
},
45 {&CSSMOID_MD2WithRSA
, CSSM_ALGID_MD2WithRSA
},
46 {&CSSMOID_MD5WithRSA
, CSSM_ALGID_MD5WithRSA
},
47 {&CSSMOID_SHA1WithRSA
, CSSM_ALGID_SHA1WithRSA
},
48 {&CSSMOID_SHA1WithRSA_OIW
, CSSM_ALGID_SHA1WithRSA
},
49 {&CSSMOID_SHA1
, CSSM_ALGID_SHA1
},
50 {&CSSMOID_MD5
, CSSM_ALGID_MD5
},
52 * These OIDs have three variants - one for BSAFE, CMS, and JDK 1.1.
53 * On the oid-to-alg map, we'll handle either one, mapping to
54 * the same CSSM alg. When we map from alg to OID, we'll use
55 * the CMS variant (being first in the list).
57 {&CSSMOID_DSA_CMS
, CSSM_ALGID_DSA
},
58 {&CSSMOID_DSA
, CSSM_ALGID_DSA
},
59 {&CSSMOID_DSA_JDK
, CSSM_ALGID_DSA
},
60 {&CSSMOID_SHA1WithDSA_CMS
, CSSM_ALGID_SHA1WithDSA
},
61 {&CSSMOID_SHA1WithDSA
, CSSM_ALGID_SHA1WithDSA
},
62 {&CSSMOID_SHA1WithDSA_JDK
, CSSM_ALGID_SHA1WithDSA
},
64 * Multiple entries for Diffie-Hellman. We favor the PKCS3 version for
67 {&CSSMOID_DH
, CSSM_ALGID_DH
},
68 {&CSSMOID_ANSI_DH_PUB_NUMBER
, CSSM_ALGID_DH
},
69 {&CSSMOID_ANSI_DH_STATIC
, CSSM_ALGID_DH
},
70 {&CSSMOID_ANSI_DH_ONE_FLOW
, CSSM_ALGID_DH
},
71 {&CSSMOID_ANSI_DH_EPHEM
, CSSM_ALGID_DH
},
72 {&CSSMOID_ANSI_DH_HYBRID1
, CSSM_ALGID_DH
},
73 {&CSSMOID_ANSI_DH_HYBRID2
, CSSM_ALGID_DH
},
74 {&CSSMOID_ANSI_DH_HYBRID_ONEFLOW
, CSSM_ALGID_DH
},
75 {&CSSMOID_APPLE_FEE
, CSSM_ALGID_FEE
},
76 {&CSSMOID_APPLE_ASC
, CSSM_ALGID_ASC
},
77 {&CSSMOID_APPLE_FEE_MD5
, CSSM_ALGID_FEE_MD5
},
78 {&CSSMOID_APPLE_FEE_SHA1
, CSSM_ALGID_FEE_SHA1
},
79 {&CSSMOID_APPLE_FEED
, CSSM_ALGID_FEED
},
80 {&CSSMOID_APPLE_FEEDEXP
, CSSM_ALGID_FEEDEXP
},
81 /* the current valid alg --> OID mapping */
82 {&CSSMOID_ECDSA_WithSHA1
, CSSM_ALGID_SHA1WithECDSA
},
83 /* for backwards compatibility */
84 {&CSSMOID_APPLE_ECDSA
, CSSM_ALGID_SHA1WithECDSA
},
85 {&CSSMOID_SHA224
, CSSM_ALGID_SHA224
},
86 {&CSSMOID_SHA256
, CSSM_ALGID_SHA256
},
87 {&CSSMOID_SHA384
, CSSM_ALGID_SHA384
},
88 {&CSSMOID_SHA512
, CSSM_ALGID_SHA512
},
89 {&CSSMOID_SHA224WithRSA
, CSSM_ALGID_SHA224WithRSA
},
90 {&CSSMOID_SHA256WithRSA
, CSSM_ALGID_SHA256WithRSA
},
91 {&CSSMOID_SHA384WithRSA
, CSSM_ALGID_SHA384WithRSA
},
92 {&CSSMOID_SHA512WithRSA
, CSSM_ALGID_SHA512WithRSA
},
93 {&CSSMOID_RSAWithOAEP
, CSSM_ALGMODE_PKCS1_EME_OAEP
},
94 {&CSSMOID_ECDSA_WithSHA224
, CSSM_ALGID_SHA224WithECDSA
},
95 {&CSSMOID_ECDSA_WithSHA256
, CSSM_ALGID_SHA256WithECDSA
},
96 {&CSSMOID_ECDSA_WithSHA384
, CSSM_ALGID_SHA384WithECDSA
},
97 {&CSSMOID_ECDSA_WithSHA512
, CSSM_ALGID_SHA512WithECDSA
},
98 /* AlgId.algorithm for ECDSA public key */
99 {&CSSMOID_ecPublicKey
, CSSM_ALGID_ECDSA
},
100 /* This OID is accompanied by an additional digest OID in AlgId.parameters */
101 {&CSSMOID_ECDSA_WithSpecified
, CSSM_ALGID_ECDSA_SPECIFIED
},
105 #define NUM_OID_TO_ALGS (sizeof(oidToAlgMap) / sizeof(oidToAlgMap[0]))
108 * Compare two CSSM_DATAs (or two CSSM_OIDs), return true if identical.
110 static bool compareCssmData(
111 const CSSM_DATA
*data1
,
112 const CSSM_DATA
*data2
)
114 if((data1
== NULL
) || (data1
->Data
== NULL
) ||
115 (data2
== NULL
) || (data2
->Data
== NULL
) ||
116 (data1
->Length
!= data2
->Length
)) {
119 if(data1
->Length
!= data2
->Length
) {
122 if(memcmp(data1
->Data
, data2
->Data
, data1
->Length
) == 0) {
132 CSSM_ALGORITHMS
*alg
) // RETURNED
134 const OidToAlgEnt
*ent
;
136 for(ent
=oidToAlgMap
; ent
->oid
; ent
++) {
137 if(compareCssmData(ent
->oid
, oid
)) {
145 const CSSM_OID
*cssmAlgToOid(
146 CSSM_ALGORITHMS algId
)
148 const OidToAlgEnt
*ent
;
150 for(ent
=oidToAlgMap
; ent
->oid
; ent
++) {
151 if(ent
->alg
== algId
) {