diff options
author | miod <> | 2014-07-09 10:16:24 +0000 |
---|---|---|
committer | miod <> | 2014-07-09 10:16:24 +0000 |
commit | 30a9e395f6ab6a5767151ca9805a33262b3acbe0 (patch) | |
tree | 9316d73cdc8c916f7b3c4bf0de6c3ad956b5f6da /src/lib/libcrypto/dsa/dsa_asn1.c | |
parent | 962b62471b32ccf7900a7f2658ec172fc691e25a (diff) | |
download | openbsd-30a9e395f6ab6a5767151ca9805a33262b3acbe0.tar.gz openbsd-30a9e395f6ab6a5767151ca9805a33262b3acbe0.tar.bz2 openbsd-30a9e395f6ab6a5767151ca9805a33262b3acbe0.zip |
KNF
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_asn1.c')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c index 25288a0dda..cc03f29823 100644 --- a/src/lib/libcrypto/dsa/dsa_asn1.c +++ b/src/lib/libcrypto/dsa/dsa_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_asn1.c,v 1.10 2014/06/12 15:49:28 deraadt Exp $ */ | 1 | /* $OpenBSD: dsa_asn1.c,v 1.11 2014/07/09 10:16:24 miod Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -64,17 +64,17 @@ | |||
64 | #include <openssl/rand.h> | 64 | #include <openssl/rand.h> |
65 | 65 | ||
66 | /* Override the default new methods */ | 66 | /* Override the default new methods */ |
67 | static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 67 | static int |
68 | void *exarg) | 68 | sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) |
69 | { | 69 | { |
70 | if(operation == ASN1_OP_NEW_PRE) { | 70 | if (operation == ASN1_OP_NEW_PRE) { |
71 | DSA_SIG *sig; | 71 | DSA_SIG *sig; |
72 | |||
72 | sig = malloc(sizeof(DSA_SIG)); | 73 | sig = malloc(sizeof(DSA_SIG)); |
73 | if (!sig) | 74 | if (!sig) { |
74 | { | ||
75 | DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE); | 75 | DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE); |
76 | return 0; | 76 | return 0; |
77 | } | 77 | } |
78 | sig->r = NULL; | 78 | sig->r = NULL; |
79 | sig->s = NULL; | 79 | sig->s = NULL; |
80 | *pval = (ASN1_VALUE *)sig; | 80 | *pval = (ASN1_VALUE *)sig; |
@@ -91,14 +91,15 @@ ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = { | |||
91 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG, DSA_SIG, DSA_SIG) | 91 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG, DSA_SIG, DSA_SIG) |
92 | 92 | ||
93 | /* Override the default free and new methods */ | 93 | /* Override the default free and new methods */ |
94 | static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, | 94 | static int |
95 | void *exarg) | 95 | dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) |
96 | { | 96 | { |
97 | if(operation == ASN1_OP_NEW_PRE) { | 97 | if (operation == ASN1_OP_NEW_PRE) { |
98 | *pval = (ASN1_VALUE *)DSA_new(); | 98 | *pval = (ASN1_VALUE *)DSA_new(); |
99 | if(*pval) return 2; | 99 | if (*pval) |
100 | return 2; | ||
100 | return 0; | 101 | return 0; |
101 | } else if(operation == ASN1_OP_FREE_PRE) { | 102 | } else if (operation == ASN1_OP_FREE_PRE) { |
102 | DSA_free((DSA *)*pval); | 103 | DSA_free((DSA *)*pval); |
103 | *pval = NULL; | 104 | *pval = NULL; |
104 | return 2; | 105 | return 2; |
@@ -125,7 +126,8 @@ ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = { | |||
125 | 126 | ||
126 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams) | 127 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams) |
127 | 128 | ||
128 | /* DSA public key is a bit trickier... its effectively a CHOICE type | 129 | /* |
130 | * DSA public key is a bit trickier... its effectively a CHOICE type | ||
129 | * decided by a field called write_params which can either write out | 131 | * decided by a field called write_params which can either write out |
130 | * just the public key as an INTEGER or the parameters and public key | 132 | * just the public key as an INTEGER or the parameters and public key |
131 | * in a SEQUENCE | 133 | * in a SEQUENCE |
@@ -145,43 +147,49 @@ ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = { | |||
145 | 147 | ||
146 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey) | 148 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey) |
147 | 149 | ||
148 | DSA *DSAparams_dup(DSA *dsa) | 150 | DSA * |
149 | { | 151 | DSAparams_dup(DSA *dsa) |
152 | { | ||
150 | return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa); | 153 | return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa); |
151 | } | 154 | } |
152 | 155 | ||
153 | int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | 156 | int |
154 | unsigned int *siglen, DSA *dsa) | 157 | DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, |
155 | { | 158 | unsigned int *siglen, DSA *dsa) |
159 | { | ||
156 | DSA_SIG *s; | 160 | DSA_SIG *s; |
157 | s=DSA_do_sign(dgst,dlen,dsa); | 161 | |
158 | if (s == NULL) | 162 | s = DSA_do_sign(dgst, dlen, dsa); |
159 | { | 163 | if (s == NULL) { |
160 | *siglen=0; | 164 | *siglen = 0; |
161 | return(0); | 165 | return 0; |
162 | } | ||
163 | *siglen=i2d_DSA_SIG(s,&sig); | ||
164 | DSA_SIG_free(s); | ||
165 | return(1); | ||
166 | } | 166 | } |
167 | *siglen = i2d_DSA_SIG(s,&sig); | ||
168 | DSA_SIG_free(s); | ||
169 | return 1; | ||
170 | } | ||
167 | 171 | ||
168 | /* data has already been hashed (probably with SHA or SHA-1). */ | 172 | /* |
169 | /* returns | 173 | * data has already been hashed (probably with SHA or SHA-1). |
174 | * returns | ||
170 | * 1: correct signature | 175 | * 1: correct signature |
171 | * 0: incorrect signature | 176 | * 0: incorrect signature |
172 | * -1: error | 177 | * -1: error |
173 | */ | 178 | */ |
174 | int DSA_verify(int type, const unsigned char *dgst, int dgst_len, | 179 | int |
175 | const unsigned char *sigbuf, int siglen, DSA *dsa) | 180 | DSA_verify(int type, const unsigned char *dgst, int dgst_len, |
176 | { | 181 | const unsigned char *sigbuf, int siglen, DSA *dsa) |
182 | { | ||
177 | DSA_SIG *s; | 183 | DSA_SIG *s; |
178 | int ret=-1; | 184 | int ret = -1; |
179 | 185 | ||
180 | s = DSA_SIG_new(); | 186 | s = DSA_SIG_new(); |
181 | if (s == NULL) return(ret); | 187 | if (s == NULL) |
182 | if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; | 188 | return ret; |
183 | ret=DSA_do_verify(dgst,dgst_len,s,dsa); | 189 | if (d2i_DSA_SIG(&s, &sigbuf, siglen) == NULL) |
190 | goto err; | ||
191 | ret = DSA_do_verify(dgst, dgst_len, s, dsa); | ||
184 | err: | 192 | err: |
185 | DSA_SIG_free(s); | 193 | DSA_SIG_free(s); |
186 | return(ret); | 194 | return ret; |
187 | } | 195 | } |