diff options
| author | jsing <> | 2018-06-14 17:15:41 +0000 |
|---|---|---|
| committer | jsing <> | 2018-06-14 17:15:41 +0000 |
| commit | 2ec5f49426848de0651964f17c8d19871d7a34df (patch) | |
| tree | 1794040a47ada9de54150f58da53061a9ffc47cd /src/lib/libcrypto/dsa/dsa_ossl.c | |
| parent | 621b83e1f38529468073224266e98966e7f6eedb (diff) | |
| download | openbsd-2ec5f49426848de0651964f17c8d19871d7a34df.tar.gz openbsd-2ec5f49426848de0651964f17c8d19871d7a34df.tar.bz2 openbsd-2ec5f49426848de0651964f17c8d19871d7a34df.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@
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_ossl.c')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 20 |
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; |
