summaryrefslogtreecommitdiff
path: root/drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c
diff options
context:
space:
mode:
authormrezai <mhd.rezai@gmail.com>2016-04-10 17:48:59 +0430
committermrezai <mhd.rezai@gmail.com>2016-04-10 17:48:59 +0430
commitc860574d8ba246b5e2c59578f24accd2ace5e9bc (patch)
tree5c8f90fc94bc49da9b35c2f532f186aa0817e6bc /drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c
parentd454e64f429affb89de036eed6daa5c6e5278492 (diff)
Update OpenSSL to version 1.0.1s
Diffstat (limited to 'drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c')
-rw-r--r--drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c64
1 files changed, 40 insertions, 24 deletions
diff --git a/drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c b/drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c
index ef9acf7b61..e909aeb400 100644
--- a/drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c
+++ b/drivers/builtin_openssl2/crypto/ecdsa/ecs_vrf.c
@@ -10,7 +10,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -57,40 +57,56 @@
*/
#include "ecs_locl.h"
+#include <string.h>
#ifndef OPENSSL_NO_ENGINE
-#include <openssl/engine.h>
+# include <openssl/engine.h>
#endif
-/* returns
+/*-
+ * returns
* 1: correct signature
* 0: incorrect signature
* -1: error
*/
-int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
- const ECDSA_SIG *sig, EC_KEY *eckey)
- {
- ECDSA_DATA *ecdsa = ecdsa_check(eckey);
- if (ecdsa == NULL)
- return 0;
- return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey);
- }
+int ECDSA_do_verify(const unsigned char *dgst, int dgst_len,
+ const ECDSA_SIG *sig, EC_KEY *eckey)
+{
+ ECDSA_DATA *ecdsa = ecdsa_check(eckey);
+ if (ecdsa == NULL)
+ return 0;
+ return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey);
+}
-/* returns
+/*-
+ * returns
* 1: correct signature
* 0: incorrect signature
* -1: error
*/
int ECDSA_verify(int type, const unsigned char *dgst, int dgst_len,
- const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
- {
- ECDSA_SIG *s;
- int ret=-1;
+ const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
+{
+ ECDSA_SIG *s;
+ const unsigned char *p = sigbuf;
+ unsigned char *der = NULL;
+ int derlen = -1;
+ int ret = -1;
- s = ECDSA_SIG_new();
- if (s == NULL) return(ret);
- if (d2i_ECDSA_SIG(&s, &sigbuf, sig_len) == NULL) goto err;
- ret=ECDSA_do_verify(dgst, dgst_len, s, eckey);
-err:
- ECDSA_SIG_free(s);
- return(ret);
- }
+ s = ECDSA_SIG_new();
+ if (s == NULL)
+ return (ret);
+ if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL)
+ goto err;
+ /* Ensure signature uses DER and doesn't have trailing garbage */
+ derlen = i2d_ECDSA_SIG(s, &der);
+ if (derlen != sig_len || memcmp(sigbuf, der, derlen))
+ goto err;
+ ret = ECDSA_do_verify(dgst, dgst_len, s, eckey);
+ err:
+ if (derlen > 0) {
+ OPENSSL_cleanse(der, derlen);
+ OPENSSL_free(der);
+ }
+ ECDSA_SIG_free(s);
+ return (ret);
+}