diff options
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_asn1.c')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c index c37460b2d6..6058534374 100644 --- a/src/lib/libcrypto/dsa/dsa_asn1.c +++ b/src/lib/libcrypto/dsa/dsa_asn1.c | |||
@@ -61,6 +61,7 @@ | |||
61 | #include <openssl/dsa.h> | 61 | #include <openssl/dsa.h> |
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | #include <openssl/asn1t.h> | 63 | #include <openssl/asn1t.h> |
64 | #include <openssl/rand.h> | ||
64 | 65 | ||
65 | /* Override the default new methods */ | 66 | /* Override the default new methods */ |
66 | static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 67 | static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
@@ -87,7 +88,7 @@ ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = { | |||
87 | ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) | 88 | ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) |
88 | } ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG) | 89 | } ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG) |
89 | 90 | ||
90 | IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG) | 91 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG, DSA_SIG, DSA_SIG) |
91 | 92 | ||
92 | /* Override the default free and new methods */ | 93 | /* Override the default free and new methods */ |
93 | static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 94 | static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, |
@@ -148,3 +149,40 @@ DSA *DSAparams_dup(DSA *dsa) | |||
148 | { | 149 | { |
149 | return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa); | 150 | return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa); |
150 | } | 151 | } |
152 | |||
153 | int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | ||
154 | unsigned int *siglen, DSA *dsa) | ||
155 | { | ||
156 | DSA_SIG *s; | ||
157 | RAND_seed(dgst, dlen); | ||
158 | s=DSA_do_sign(dgst,dlen,dsa); | ||
159 | if (s == NULL) | ||
160 | { | ||
161 | *siglen=0; | ||
162 | return(0); | ||
163 | } | ||
164 | *siglen=i2d_DSA_SIG(s,&sig); | ||
165 | DSA_SIG_free(s); | ||
166 | return(1); | ||
167 | } | ||
168 | |||
169 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
170 | /* returns | ||
171 | * 1: correct signature | ||
172 | * 0: incorrect signature | ||
173 | * -1: error | ||
174 | */ | ||
175 | int DSA_verify(int type, const unsigned char *dgst, int dgst_len, | ||
176 | const unsigned char *sigbuf, int siglen, DSA *dsa) | ||
177 | { | ||
178 | DSA_SIG *s; | ||
179 | int ret=-1; | ||
180 | |||
181 | s = DSA_SIG_new(); | ||
182 | if (s == NULL) return(ret); | ||
183 | if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; | ||
184 | ret=DSA_do_verify(dgst,dgst_len,s,dsa); | ||
185 | err: | ||
186 | DSA_SIG_free(s); | ||
187 | return(ret); | ||
188 | } | ||