summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2018-06-14 17:15:41 +0000
committerjsing <>2018-06-14 17:15:41 +0000
commitec5ae7b7159857fa56f3374da69bcf274ba700c8 (patch)
tree1794040a47ada9de54150f58da53061a9ffc47cd
parent79620b4c52c925d67e045a74f684717cb6cc0856 (diff)
downloadopenbsd-ec5ae7b7159857fa56f3374da69bcf274ba700c8.tar.gz
openbsd-ec5ae7b7159857fa56f3374da69bcf274ba700c8.tar.bz2
openbsd-ec5ae7b7159857fa56f3374da69bcf274ba700c8.zip
Pull up the code that converts the digest to a BIGNUM - this only needs
to occur once and not be repeated if the signature generation has to be repeated. ok tb@
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
index d864875266..9545cff5f8 100644
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ b/src/lib/libcrypto/dsa/dsa_ossl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_ossl.c,v 1.34 2018/06/14 17:14:12 jsing Exp $ */ 1/* $OpenBSD: dsa_ossl.c,v 1.35 2018/06/14 17:15:41 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -117,6 +117,15 @@ dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
117 if (ctx == NULL) 117 if (ctx == NULL)
118 goto err; 118 goto err;
119 119
120 /*
121 * If the digest length is greater than the size of q use the
122 * BN_num_bits(dsa->q) leftmost bits of the digest, see FIPS 186-3, 4.2.
123 */
124 if (dlen > BN_num_bytes(dsa->q))
125 dlen = BN_num_bytes(dsa->q);
126 if (BN_bin2bn(dgst, dlen, &m) == NULL)
127 goto err;
128
120 redo: 129 redo:
121 if (dsa->kinv == NULL || dsa->r == NULL) { 130 if (dsa->kinv == NULL || dsa->r == NULL) {
122 if (!DSA_sign_setup(dsa, ctx, &kinv, &r)) 131 if (!DSA_sign_setup(dsa, ctx, &kinv, &r))
@@ -129,15 +138,6 @@ dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
129 noredo = 1; 138 noredo = 1;
130 } 139 }
131 140
132 /*
133 * If the digest length is greater than the size of q use the
134 * BN_num_bits(dsa->q) leftmost bits of the digest, see FIPS 186-3, 4.2.
135 */
136 if (dlen > BN_num_bytes(dsa->q))
137 dlen = BN_num_bytes(dsa->q);
138 if (BN_bin2bn(dgst,dlen,&m) == NULL)
139 goto err;
140
141 /* Compute s = inv(k) (m + xr) mod q */ 141 /* Compute s = inv(k) (m + xr) mod q */
142 if (!BN_mod_mul(&xr, dsa->priv_key, r, dsa->q, ctx)) /* s = xr */ 142 if (!BN_mod_mul(&xr, dsa->priv_key, r, dsa->q, ctx)) /* s = xr */
143 goto err; 143 goto err;