diff options
Diffstat (limited to 'src/lib/libcrypto/ecdsa/ecs_vrf.c')
| -rw-r--r-- | src/lib/libcrypto/ecdsa/ecs_vrf.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/lib/libcrypto/ecdsa/ecs_vrf.c b/src/lib/libcrypto/ecdsa/ecs_vrf.c index b1e66af80a..a4b627ace6 100644 --- a/src/lib/libcrypto/ecdsa/ecs_vrf.c +++ b/src/lib/libcrypto/ecdsa/ecs_vrf.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecs_vrf.c,v 1.4 2015/01/28 04:14:31 beck Exp $ */ | 1 | /* $OpenBSD: ecs_vrf.c,v 1.5 2015/02/08 13:35:07 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Nils Larsch for the OpenSSL project | 3 | * Written by Nils Larsch for the OpenSSL project |
| 4 | */ | 4 | */ |
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -69,42 +69,48 @@ | |||
| 69 | * 0: incorrect signature | 69 | * 0: incorrect signature |
| 70 | * -1: error | 70 | * -1: error |
| 71 | */ | 71 | */ |
| 72 | int ECDSA_do_verify(const unsigned char *dgst, int dgst_len, | 72 | int |
| 73 | const ECDSA_SIG *sig, EC_KEY *eckey) | 73 | ECDSA_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, |
| 74 | { | 74 | EC_KEY *eckey) |
| 75 | { | ||
| 75 | ECDSA_DATA *ecdsa = ecdsa_check(eckey); | 76 | ECDSA_DATA *ecdsa = ecdsa_check(eckey); |
| 77 | |||
| 76 | if (ecdsa == NULL) | 78 | if (ecdsa == NULL) |
| 77 | return 0; | 79 | return 0; |
| 78 | return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey); | 80 | return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey); |
| 79 | } | 81 | } |
| 80 | 82 | ||
| 81 | /* returns | 83 | /* returns |
| 82 | * 1: correct signature | 84 | * 1: correct signature |
| 83 | * 0: incorrect signature | 85 | * 0: incorrect signature |
| 84 | * -1: error | 86 | * -1: error |
| 85 | */ | 87 | */ |
| 86 | int ECDSA_verify(int type, const unsigned char *dgst, int dgst_len, | 88 | int |
| 87 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey) | 89 | ECDSA_verify(int type, const unsigned char *dgst, int dgst_len, |
| 88 | { | 90 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey) |
| 91 | { | ||
| 89 | ECDSA_SIG *s; | 92 | ECDSA_SIG *s; |
| 90 | unsigned char *der = NULL; | 93 | unsigned char *der = NULL; |
| 91 | const unsigned char *p = sigbuf; | 94 | const unsigned char *p = sigbuf; |
| 92 | int derlen = -1; | 95 | int derlen = -1; |
| 93 | int ret=-1; | 96 | int ret = -1; |
| 94 | 97 | ||
| 95 | s = ECDSA_SIG_new(); | 98 | s = ECDSA_SIG_new(); |
| 96 | if (s == NULL) return(ret); | 99 | if (s == NULL) |
| 97 | if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) goto err; | 100 | return (ret); |
| 101 | if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL) | ||
| 102 | goto err; | ||
| 98 | /* Ensure signature uses DER and doesn't have trailing garbage */ | 103 | /* Ensure signature uses DER and doesn't have trailing garbage */ |
| 99 | derlen = i2d_ECDSA_SIG(s, &der); | 104 | derlen = i2d_ECDSA_SIG(s, &der); |
| 100 | if (derlen != sig_len || memcmp(sigbuf, der, derlen)) | 105 | if (derlen != sig_len || memcmp(sigbuf, der, derlen)) |
| 101 | goto err; | 106 | goto err; |
| 102 | ret=ECDSA_do_verify(dgst, dgst_len, s, eckey); | 107 | ret = ECDSA_do_verify(dgst, dgst_len, s, eckey); |
| 108 | |||
| 103 | err: | 109 | err: |
| 104 | if (derlen > 0) { | 110 | if (derlen > 0) { |
| 105 | explicit_bzero(der, derlen); | 111 | explicit_bzero(der, derlen); |
| 106 | free(der); | 112 | free(der); |
| 107 | } | 113 | } |
| 108 | ECDSA_SIG_free(s); | 114 | ECDSA_SIG_free(s); |
| 109 | return(ret); | 115 | return (ret); |
| 110 | } | 116 | } |
