1 /* crypto/dsa/dsa_asn1.c */
5 #include <openssl/dsa.h>
6 #include <openssl/asn1.h>
7 #include <openssl/asn1_mac.h>
9 DSA_SIG *DSA_SIG_new(void)
13 ret = OPENSSL_malloc(sizeof(DSA_SIG));
16 DSAerr(DSA_F_DSA_SIG_NEW,ERR_R_MALLOC_FAILURE);
24 void DSA_SIG_free(DSA_SIG *r)
26 if (r == NULL) return;
27 if (r->r) BN_clear_free(r->r);
28 if (r->s) BN_clear_free(r->s);
32 int i2d_DSA_SIG(const DSA_SIG *v, unsigned char **pp)
38 rbs.data=OPENSSL_malloc(BN_num_bits(v->r)/8+1);
41 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
44 rbs.type=V_ASN1_INTEGER;
45 rbs.length=BN_bn2bin(v->r,rbs.data);
46 sbs.data=OPENSSL_malloc(BN_num_bits(v->s)/8+1);
49 OPENSSL_free(rbs.data);
50 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
53 sbs.type=V_ASN1_INTEGER;
54 sbs.length=BN_bn2bin(v->s,sbs.data);
56 len=i2d_ASN1_INTEGER(&rbs,NULL);
57 len+=i2d_ASN1_INTEGER(&sbs,NULL);
62 ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
63 i2d_ASN1_INTEGER(&rbs,&p);
64 i2d_ASN1_INTEGER(&sbs,&p);
66 t=ASN1_object_size(1,len,V_ASN1_SEQUENCE);
67 OPENSSL_free(rbs.data);
68 OPENSSL_free(sbs.data);
72 DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, const unsigned char **pp, long length)
74 int i=ERR_R_NESTED_ASN1_ERROR;
75 ASN1_INTEGER *bs=NULL;
76 M_ASN1_D2I_vars(a,DSA_SIG *,DSA_SIG_new);
79 M_ASN1_D2I_start_sequence();
80 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
81 if ((ret->r=BN_bin2bn(bs->data,bs->length,ret->r)) == NULL)
83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
84 if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL)
86 M_ASN1_BIT_STRING_free(bs);
87 M_ASN1_D2I_Finish_2(a);
92 DSAerr(DSA_F_D2I_DSA_SIG,i);
93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret);
94 if (bs != NULL) M_ASN1_BIT_STRING_free(bs);