summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa/dsa_asn1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_asn1.c')
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c96
1 files changed, 14 insertions, 82 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
index 0645facb4b..c37460b2d6 100644
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ b/src/lib/libcrypto/dsa/dsa_asn1.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -61,24 +61,23 @@
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/bn.h>
65#ifdef OPENSSL_FIPS
66#include <openssl/fips.h>
67#endif
68
69 64
70/* Override the default new methods */ 65/* Override the default new methods */
71static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) 66static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
67 void *exarg)
72{ 68{
73 if(operation == ASN1_OP_NEW_PRE) { 69 if(operation == ASN1_OP_NEW_PRE) {
74 DSA_SIG *sig; 70 DSA_SIG *sig;
75 sig = OPENSSL_malloc(sizeof(DSA_SIG)); 71 sig = OPENSSL_malloc(sizeof(DSA_SIG));
72 if (!sig)
73 {
74 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
75 return 0;
76 }
76 sig->r = NULL; 77 sig->r = NULL;
77 sig->s = NULL; 78 sig->s = NULL;
78 *pval = (ASN1_VALUE *)sig; 79 *pval = (ASN1_VALUE *)sig;
79 if(sig) return 2; 80 return 2;
80 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
81 return 0;
82 } 81 }
83 return 1; 82 return 1;
84} 83}
@@ -88,10 +87,11 @@ ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
88 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) 87 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
89} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG) 88} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
90 89
91IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG,DSA_SIG,DSA_SIG) 90IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG)
92 91
93/* Override the default free and new methods */ 92/* Override the default free and new methods */
94static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) 93static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
94 void *exarg)
95{ 95{
96 if(operation == ASN1_OP_NEW_PRE) { 96 if(operation == ASN1_OP_NEW_PRE) {
97 *pval = (ASN1_VALUE *)DSA_new(); 97 *pval = (ASN1_VALUE *)DSA_new();
@@ -144,75 +144,7 @@ ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
144 144
145IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey) 145IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
146 146
147int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, 147DSA *DSAparams_dup(DSA *dsa)
148 unsigned int *siglen, DSA *dsa)
149 {
150 DSA_SIG *s;
151#ifdef OPENSSL_FIPS
152 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
153 {
154 DSAerr(DSA_F_DSA_SIGN, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
155 return 0;
156 }
157#endif
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
169int DSA_size(const DSA *r)
170 {
171 int ret,i;
172 ASN1_INTEGER bs;
173 unsigned char buf[4]; /* 4 bytes looks really small.
174 However, i2d_ASN1_INTEGER() will not look
175 beyond the first byte, as long as the second
176 parameter is NULL. */
177
178 i=BN_num_bits(r->q);
179 bs.length=(i+7)/8;
180 bs.data=buf;
181 bs.type=V_ASN1_INTEGER;
182 /* If the top bit is set the asn1 encoding is 1 larger. */
183 buf[0]=0xff;
184
185 i=i2d_ASN1_INTEGER(&bs,NULL);
186 i+=i; /* r and s */
187 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
188 return(ret);
189 }
190
191/* data has already been hashed (probably with SHA or SHA-1). */
192/* returns
193 * 1: correct signature
194 * 0: incorrect signature
195 * -1: error
196 */
197int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
198 const unsigned char *sigbuf, int siglen, DSA *dsa)
199 { 148 {
200 DSA_SIG *s; 149 return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa);
201 int ret=-1;
202#ifdef OPENSSL_FIPS
203 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
204 {
205 DSAerr(DSA_F_DSA_VERIFY, DSA_R_OPERATION_NOT_ALLOWED_IN_FIPS_MODE);
206 return 0;
207 }
208#endif
209
210 s = DSA_SIG_new();
211 if (s == NULL) return(ret);
212 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
213 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
214err:
215 DSA_SIG_free(s);
216 return(ret);
217 } 150 }
218