69 static DSA_SIG *dsa_do_sign(
const unsigned char *dgst,
int dlen,
DSA *dsa);
71 static int dsa_do_verify(
const unsigned char *dgst,
int dgst_len,
DSA_SIG *sig,
73 static int dsa_init(
DSA *dsa);
74 static int dsa_finish(
DSA *dsa);
104 #define DSA_MOD_EXP(err_instr,dsa,rr,a1,p1,a2,p2,m,ctx,in_mont) \
107 if((dsa)->meth->dsa_mod_exp) \
108 _tmp_res53 = (dsa)->meth->dsa_mod_exp((dsa), (rr), (a1), (p1), \
109 (a2), (p2), (m), (ctx), (in_mont)); \
111 _tmp_res53 = BN_mod_exp2_mont((rr), (a1), (p1), (a2), (p2), \
112 (m), (ctx), (in_mont)); \
113 if(!_tmp_res53) err_instr; \
115 #define DSA_BN_MOD_EXP(err_instr,dsa,r,a,p,m,ctx,m_ctx) \
118 if((dsa)->meth->bn_mod_exp) \
119 _tmp_res53 = (dsa)->meth->bn_mod_exp((dsa), (r), (a), (p), \
120 (m), (ctx), (m_ctx)); \
122 _tmp_res53 = BN_mod_exp_mont((r), (a), (p), (m), (ctx), (m_ctx)); \
123 if(!_tmp_res53) err_instr; \
128 return &openssl_dsa_meth;
131 static DSA_SIG *dsa_do_sign(
const unsigned char *dgst,
int dlen,
DSA *dsa)
133 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
144 if (!dsa->
p || !dsa->
q || !dsa->
g)
151 if (s == NULL)
goto err;
153 if (ctx == NULL)
goto err;
155 if ((dsa->
kinv == NULL) || (dsa->
r == NULL))
179 if (!
BN_add(s, &xr, &m))
goto err;
181 if (!
BN_sub(s,s,dsa->
q))
goto err;
185 if (ret == NULL)
goto err;
219 BIGNUM k,kq,*K,*kinv=NULL,*r=NULL;
222 if (!dsa->
p || !dsa->
q || !dsa->
g)
238 if ((r=
BN_new()) == NULL)
goto err;
261 if (!
BN_copy(&kq, &k))
goto err;
269 if (!
BN_add(&kq, &kq, dsa->
q))
goto err;
272 if (!
BN_add(&kq, &kq, dsa->
q))
goto err;
283 if (!
BN_mod(r,r,dsa->
q,ctx))
goto err;
307 static int dsa_do_verify(
const unsigned char *dgst,
int dgst_len,
DSA_SIG *sig,
314 if (!dsa->
p || !dsa->
q || !dsa->
g)
322 if (i != 160 && i != 224 && i != 256)
357 if (dgst_len > (i >> 3))
362 if (
BN_bin2bn(dgst,dgst_len,&u1) == NULL)
goto err;
383 if (!
BN_mod(&u1,&t1,dsa->
q,ctx))
goto err;
400 static int dsa_init(
DSA *dsa)
406 static int dsa_finish(
DSA *dsa)