OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 #include "cryptohi.h" | 4 #include "cryptohi.h" |
5 #include "secasn1.h" | 5 #include "secasn1.h" |
6 #include "secitem.h" | 6 #include "secitem.h" |
7 #include "prerr.h" | 7 #include "prerr.h" |
8 | 8 |
9 #ifndef DSA_SUBPRIME_LEN | 9 #ifndef DSA1_SUBPRIME_LEN |
10 #define DSA_SUBPRIME_LEN 20» /* bytes */ | 10 #define DSA1_SUBPRIME_LEN 20» /* bytes */ |
11 #endif | 11 #endif |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 SECItem r; | 14 SECItem r; |
15 SECItem s; | 15 SECItem s; |
16 } DSA_ASN1Signature; | 16 } DSA_ASN1Signature; |
17 | 17 |
18 const SEC_ASN1Template DSA_SignatureTemplate[] = | 18 const SEC_ASN1Template DSA_SignatureTemplate[] = |
19 { | 19 { |
20 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(DSA_ASN1Signature) }, | 20 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(DSA_ASN1Signature) }, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 if (item == NULL) | 148 if (item == NULL) |
149 return SECFailure; | 149 return SECFailure; |
150 | 150 |
151 /* XXX leak item? */ | 151 /* XXX leak item? */ |
152 return SECSuccess; | 152 return SECSuccess; |
153 } | 153 } |
154 | 154 |
155 /* src is a DER-encoded ECDSA or DSA signature. | 155 /* src is a DER-encoded ECDSA or DSA signature. |
156 ** Returns a newly-allocated SECItem structure, pointing at a newly allocated | 156 ** Returns a newly-allocated SECItem structure, pointing at a newly allocated |
157 ** buffer containing the "raw" signature, which is len bytes of r, | 157 ** buffer containing the "raw" signature, which is len bytes of r, |
158 ** followed by len bytes of s. For DSA, len is always DSA_SUBPRIME_LEN. | 158 ** followed by len bytes of s. For DSA, len is the length of q. |
159 ** For ECDSA, len depends on the key size used to create the signature. | 159 ** For ECDSA, len depends on the key size used to create the signature. |
160 */ | 160 */ |
161 static SECItem * | 161 static SECItem * |
162 common_DecodeDerSig(const SECItem *item, unsigned int len) | 162 common_DecodeDerSig(const SECItem *item, unsigned int len) |
163 { | 163 { |
164 SECItem * result = NULL; | 164 SECItem * result = NULL; |
165 SECStatus status; | 165 SECStatus status; |
166 DSA_ASN1Signature sig; | 166 DSA_ASN1Signature sig; |
167 SECItem dst; | 167 SECItem dst; |
168 | 168 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return result; | 206 return result; |
207 | 207 |
208 loser: | 208 loser: |
209 if (result != NULL) { | 209 if (result != NULL) { |
210 SECITEM_FreeItem(result, PR_TRUE); | 210 SECITEM_FreeItem(result, PR_TRUE); |
211 result = NULL; | 211 result = NULL; |
212 } | 212 } |
213 goto done; | 213 goto done; |
214 } | 214 } |
215 | 215 |
216 /* src is a "raw" DSA signature, 20 bytes of r followed by 20 bytes of s. | 216 /* src is a "raw" DSA1 signature, 20 bytes of r followed by 20 bytes of s. |
217 ** dest is the signature DER encoded. ? | 217 ** dest is the signature DER encoded. ? |
218 */ | 218 */ |
219 SECStatus | 219 SECStatus |
220 DSAU_EncodeDerSig(SECItem *dest, SECItem *src) | 220 DSAU_EncodeDerSig(SECItem *dest, SECItem *src) |
221 { | 221 { |
222 PORT_Assert(src->len == 2 * DSA_SUBPRIME_LEN); | 222 PORT_Assert(src->len == 2 * DSA1_SUBPRIME_LEN); |
223 if (src->len != 2 * DSA_SUBPRIME_LEN) { | 223 if (src->len != 2 * DSA1_SUBPRIME_LEN) { |
224 PORT_SetError( PR_INVALID_ARGUMENT_ERROR ); | 224 PORT_SetError( PR_INVALID_ARGUMENT_ERROR ); |
225 return SECFailure; | 225 return SECFailure; |
226 } | 226 } |
227 | 227 |
228 return common_EncodeDerSig(dest, src); | 228 return common_EncodeDerSig(dest, src); |
229 } | 229 } |
230 | 230 |
231 /* src is a "raw" DSA signature of length len (len/2 bytes of r followed | 231 /* src is a "raw" DSA signature of length len (len/2 bytes of r followed |
232 ** by len/2 bytes of s). dest is the signature DER encoded. | 232 ** by len/2 bytes of s). dest is the signature DER encoded. |
233 */ | 233 */ |
234 SECStatus | 234 SECStatus |
235 DSAU_EncodeDerSigWithLen(SECItem *dest, SECItem *src, unsigned int len) | 235 DSAU_EncodeDerSigWithLen(SECItem *dest, SECItem *src, unsigned int len) |
236 { | 236 { |
237 | 237 |
238 PORT_Assert((src->len == len) && (len % 2 == 0)); | 238 PORT_Assert((src->len == len) && (len % 2 == 0)); |
239 if ((src->len != len) || (src->len % 2 != 0)) { | 239 if ((src->len != len) || (src->len % 2 != 0)) { |
240 PORT_SetError( PR_INVALID_ARGUMENT_ERROR ); | 240 PORT_SetError( PR_INVALID_ARGUMENT_ERROR ); |
241 return SECFailure; | 241 return SECFailure; |
242 } | 242 } |
243 | 243 |
244 return common_EncodeDerSig(dest, src); | 244 return common_EncodeDerSig(dest, src); |
245 } | 245 } |
246 | 246 |
247 /* src is a DER-encoded DSA signature. | 247 /* src is a DER-encoded DSA signature. |
248 ** Returns a newly-allocated SECItem structure, pointing at a newly allocated | 248 ** Returns a newly-allocated SECItem structure, pointing at a newly allocated |
249 ** buffer containing the "raw" DSA signature, which is 20 bytes of r, | 249 ** buffer containing the "raw" DSA1 signature, which is 20 bytes of r, |
250 ** followed by 20 bytes of s. | 250 ** followed by 20 bytes of s. |
251 */ | 251 */ |
252 SECItem * | 252 SECItem * |
253 DSAU_DecodeDerSig(const SECItem *item) | 253 DSAU_DecodeDerSig(const SECItem *item) |
254 { | 254 { |
255 return common_DecodeDerSig(item, DSA_SUBPRIME_LEN); | 255 return common_DecodeDerSig(item, DSA1_SUBPRIME_LEN); |
256 } | 256 } |
257 | 257 |
258 /* src is a DER-encoded ECDSA signature. | 258 /* src is a DER-encoded ECDSA signature. |
259 ** Returns a newly-allocated SECItem structure, pointing at a newly allocated | 259 ** Returns a newly-allocated SECItem structure, pointing at a newly allocated |
260 ** buffer containing the "raw" ECDSA signature of length len containing | 260 ** buffer containing the "raw" ECDSA signature of length len containing |
261 ** r followed by s (both padded to take up exactly len/2 bytes). | 261 ** r followed by s (both padded to take up exactly len/2 bytes). |
262 */ | 262 */ |
263 SECItem * | 263 SECItem * |
264 DSAU_DecodeDerSigToLen(const SECItem *item, unsigned int len) | 264 DSAU_DecodeDerSigToLen(const SECItem *item, unsigned int len) |
265 { | 265 { |
266 return common_DecodeDerSig(item, len/2); | 266 return common_DecodeDerSig(item, len/2); |
267 } | 267 } |
OLD | NEW |