2 * Copyright (c) 2003-2006,2008,2010-2012 Apple 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@
24 * osKeyTemplate.h - ASN1 templates for openssl asymmetric keys
27 #include "osKeyTemplates.h"
34 /* X509 style DSA algorithm parameters */
35 const SecAsn1Template kSecAsn1DSAAlgParamsTemplate
[] = {
36 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAAlgParams
) },
37 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAAlgParams
,p
) },
38 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAAlgParams
,q
) },
39 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAAlgParams
,g
) },
43 /* BSAFE style DSA algorithm parameters */
44 const SecAsn1Template kSecAsn1DSAAlgParamsBSAFETemplate
[] = {
45 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAAlgParamsBSAFE
) },
46 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAAlgParamsBSAFE
,keySizeInBits
) },
47 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAAlgParamsBSAFE
,p
) },
48 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAAlgParamsBSAFE
,q
) },
49 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAAlgParamsBSAFE
,g
) },
53 /* DSA X509-style AlgorithmID */
54 const SecAsn1Template kSecAsn1DSAAlgorithmIdX509Template
[] = {
55 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAAlgorithmIdX509
) },
56 { SEC_ASN1_OBJECT_ID
, offsetof(NSS_DSAAlgorithmIdX509
, algorithm
) },
57 /* per CMS, this is optional */
58 { SEC_ASN1_POINTER
| SEC_ASN1_OPTIONAL
,
59 offsetof(NSS_DSAAlgorithmIdX509
,params
),
60 kSecAsn1DSAAlgParamsTemplate
},
64 /* DSA BSAFE-style AlgorithmID */
65 const SecAsn1Template kSecAsn1DSAAlgorithmIdBSAFETemplate
[] = {
66 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAAlgorithmIdBSAFE
) },
67 { SEC_ASN1_OBJECT_ID
, offsetof(NSS_DSAAlgorithmIdBSAFE
, algorithm
) },
69 offsetof(NSS_DSAAlgorithmIdBSAFE
,params
),
70 kSecAsn1DSAAlgParamsBSAFETemplate
},
78 /* DSA public key, openssl/X509 format */
79 const SecAsn1Template kSecAsn1DSAPublicKeyX509Template
[] = {
80 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAPublicKeyX509
) },
82 offsetof(NSS_DSAPublicKeyX509
, dsaAlg
),
83 kSecAsn1DSAAlgorithmIdX509Template
},
84 { SEC_ASN1_BIT_STRING
,
85 offsetof(NSS_DSAPublicKeyX509
, publicKey
), },
89 /* DSA public key, BSAFE/FIPS186 format */
90 const SecAsn1Template kSecAsn1DSAPublicKeyBSAFETemplate
[] = {
91 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAPublicKeyBSAFE
) },
93 offsetof(NSS_DSAPublicKeyBSAFE
, dsaAlg
),
94 kSecAsn1DSAAlgorithmIdBSAFETemplate
},
95 { SEC_ASN1_BIT_STRING
,
96 offsetof(NSS_DSAPublicKeyBSAFE
, publicKey
), },
101 **** DSA private keys
104 /* DSA Private key, openssl custom format */
105 const SecAsn1Template kSecAsn1DSAPrivateKeyOpensslTemplate
[] = {
106 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAPrivateKeyOpenssl
) },
107 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyOpenssl
,version
) },
108 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyOpenssl
,p
) },
109 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyOpenssl
,q
) },
110 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyOpenssl
,g
) },
111 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyOpenssl
,pub
) },
112 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyOpenssl
,priv
) },
117 * DSA private key, BSAFE/FIPS186 style.
118 * This is basically a DSA-specific NSS_PrivateKeyInfo.
120 * NSS_DSAPrivateKeyBSAFE.privateKey is an octet string containing
121 * the DER encoding of this.
123 const SecAsn1Template kSecAsn1DSAPrivateKeyOctsTemplate
[] = {
124 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAPrivateKeyOcts
) },
125 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyOcts
,privateKey
) },
129 const SecAsn1Template kSecAsn1DSAPrivateKeyBSAFETemplate
[] = {
130 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAPrivateKeyBSAFE
) },
131 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyBSAFE
,version
) },
133 offsetof(NSS_DSAPrivateKeyBSAFE
, dsaAlg
),
134 kSecAsn1DSAAlgorithmIdBSAFETemplate
},
135 { SEC_ASN1_OCTET_STRING
, offsetof(NSS_DSAPrivateKeyBSAFE
,privateKey
) },
140 * DSA Private Key, PKCS8/SMIME style.
142 const SecAsn1Template kSecAsn1DSAPrivateKeyPKCS8Template
[] = {
143 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSAPrivateKeyPKCS8
) },
144 { SEC_ASN1_INTEGER
, offsetof(NSS_DSAPrivateKeyPKCS8
,version
) },
146 offsetof(NSS_DSAPrivateKeyPKCS8
, dsaAlg
),
147 kSecAsn1DSAAlgorithmIdX509Template
},
148 { SEC_ASN1_OCTET_STRING
, offsetof(NSS_DSAPrivateKeyPKCS8
,privateKey
) },
149 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
|
150 SEC_ASN1_CONTEXT_SPECIFIC
| 0,
151 offsetof(NSS_DSAPrivateKeyPKCS8
,attributes
),
152 kSecAsn1SetOfAttributeTemplate
},
156 const SecAsn1Template kSecAsn1DSASignatureTemplate
[] = {
157 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(NSS_DSASignature
) },
158 { SEC_ASN1_INTEGER
, offsetof(NSS_DSASignature
,r
) },
159 { SEC_ASN1_INTEGER
, offsetof(NSS_DSASignature
,s
) },