]>
git.saurik.com Git - apple/security.git/blob - AppleCSP/open_ssl/dsa/dsa_asn1.c
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 /* crypto/dsa/dsa_asn1.c */
23 #include <openssl/dsa.h>
24 #include <openssl/asn1.h>
25 #ifndef _OPENSSL_APPLE_CDSA_
26 #include <openssl/asn1_mac.h>
29 DSA_SIG
*DSA_SIG_new(void)
33 ret
= Malloc(sizeof(DSA_SIG
));
36 DSAerr(DSA_F_DSA_SIG_NEW
,ERR_R_MALLOC_FAILURE
);
44 void DSA_SIG_free(DSA_SIG
*r
)
46 if (r
== NULL
) return;
47 if (r
->r
) BN_clear_free(r
->r
);
48 if (r
->s
) BN_clear_free(r
->s
);
52 #ifndef _OPENSSL_APPLE_CDSA_
54 int i2d_DSA_SIG(DSA_SIG
*v
, unsigned char **pp
)
60 rbs
.data
=Malloc(BN_num_bits(v
->r
)/8+1);
63 DSAerr(DSA_F_I2D_DSA_SIG
, ERR_R_MALLOC_FAILURE
);
66 rbs
.type
=V_ASN1_INTEGER
;
67 rbs
.length
=BN_bn2bin(v
->r
,rbs
.data
);
68 sbs
.data
=Malloc(BN_num_bits(v
->s
)/8+1);
72 DSAerr(DSA_F_I2D_DSA_SIG
, ERR_R_MALLOC_FAILURE
);
75 sbs
.type
=V_ASN1_INTEGER
;
76 sbs
.length
=BN_bn2bin(v
->s
,sbs
.data
);
78 len
=i2d_ASN1_INTEGER(&rbs
,NULL
);
79 len
+=i2d_ASN1_INTEGER(&sbs
,NULL
);
84 ASN1_put_object(&p
,1,len
,V_ASN1_SEQUENCE
,V_ASN1_UNIVERSAL
);
85 i2d_ASN1_INTEGER(&rbs
,&p
);
86 i2d_ASN1_INTEGER(&sbs
,&p
);
88 t
=ASN1_object_size(1,len
,V_ASN1_SEQUENCE
);
94 DSA_SIG
*d2i_DSA_SIG(DSA_SIG
**a
, unsigned char **pp
, long length
)
96 int i
=ERR_R_NESTED_ASN1_ERROR
;
97 ASN1_INTEGER
*bs
=NULL
;
98 M_ASN1_D2I_vars(a
,DSA_SIG
*,DSA_SIG_new
);
101 M_ASN1_D2I_start_sequence();
102 M_ASN1_D2I_get(bs
,d2i_ASN1_INTEGER
);
103 if ((ret
->r
=BN_bin2bn(bs
->data
,bs
->length
,ret
->r
)) == NULL
)
105 M_ASN1_D2I_get(bs
,d2i_ASN1_INTEGER
);
106 if ((ret
->s
=BN_bin2bn(bs
->data
,bs
->length
,ret
->s
)) == NULL
)
108 M_ASN1_BIT_STRING_free(bs
);
109 M_ASN1_D2I_Finish_2(a
);
114 DSAerr(DSA_F_D2I_DSA_SIG
,i
);
115 if ((ret
!= NULL
) && ((a
== NULL
) || (*a
!= ret
))) DSA_SIG_free(ret
);
116 if (bs
!= NULL
) M_ASN1_BIT_STRING_free(bs
);
120 #endif /* _OPENSSL_APPLE_CDSA_ */