summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa/dsa_vrf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_vrf.c')
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c68
1 files changed, 1 insertions, 67 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
index ff552208aa..03277f80fd 100644
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ b/src/lib/libcrypto/dsa/dsa_vrf.c
@@ -69,73 +69,7 @@
69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, 69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
70 DSA *dsa) 70 DSA *dsa)
71 { 71 {
72 BN_CTX *ctx; 72 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
73 BIGNUM u1,u2,t1;
74 BN_MONT_CTX *mont=NULL;
75 int ret = -1;
76
77 if ((ctx=BN_CTX_new()) == NULL) goto err;
78 BN_init(&u1);
79 BN_init(&u2);
80 BN_init(&t1);
81
82 /* Calculate W = inv(S) mod Q
83 * save W in u2 */
84 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
85
86 /* save M in u1 */
87 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
88
89 /* u1 = M * w mod q */
90 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
91
92 /* u2 = r * w mod q */
93 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
94
95 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
96 {
97 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
98 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
99 dsa->p,ctx)) goto err;
100 }
101 mont=(BN_MONT_CTX *)dsa->method_mont_p;
102
103#if 0
104 {
105 BIGNUM t2;
106
107 BN_init(&t2);
108 /* v = ( g^u1 * y^u2 mod p ) mod q */
109 /* let t1 = g ^ u1 mod p */
110 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
111 /* let t2 = y ^ u2 mod p */
112 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
113 /* let u1 = t1 * t2 mod p */
114 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
115 BN_free(&t2);
116 }
117 /* let u1 = u1 mod q */
118 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
119#else
120 {
121 if (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont))
122 goto err;
123 /* BN_copy(&u1,&t1); */
124 /* let u1 = u1 mod q */
125 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
126 }
127#endif
128 /* V is now in u1. If the signature is correct, it will be
129 * equal to R. */
130 ret=(BN_ucmp(&u1, sig->r) == 0);
131
132 err:
133 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
134 if (ctx != NULL) BN_CTX_free(ctx);
135 BN_free(&u1);
136 BN_free(&u2);
137 BN_free(&t1);
138 return(ret);
139 } 73 }
140 74
141/* data has already been hashed (probably with SHA or SHA-1). */ 75/* data has already been hashed (probably with SHA or SHA-1). */