diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2021-10-07 13:47:07 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2021-10-07 14:12:24 +0900 |
commit | 16a9eaad5d1add3a95b1da6e037b074f18b094c7 (patch) | |
tree | e322d4961d887c05b53ff8bdd9301fe5fb7e45b1 /cipher/ecc.c | |
parent | 9fc0d145278d46bb129660a57b7ca2f94577d461 (diff) | |
download | libgcrypt-16a9eaad5d1add3a95b1da6e037b074f18b094c7.tar.gz |
cipher:dsa,ecdsa: Support supplying K externally.
* cipher/dsa.c (sign): Add an argument K for DSA.
(test_keys, dsa_sign): Follow the change.
* cipher/ecc-common.h (_gcry_ecc_ecdsa_sign): Likewise for ECDSA.
* cipher/ecc-ecdsa.c (_gcry_ecc_ecdsa_sign): Likewise for ECDSA.
* cipher/ecc.c (test_keys, ecc_sign): Follow the change.
* cipher/pubkey-util.c (_gcry_pk_util_data_to_mpi): Support "label"
for K.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'cipher/ecc.c')
-rw-r--r-- | cipher/ecc.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/cipher/ecc.c b/cipher/ecc.c index 77f9417f..9f0e7b11 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -285,7 +285,7 @@ test_keys (mpi_ec_t ec, unsigned int nbits) _gcry_mpi_randomize (test, nbits, GCRY_WEAK_RANDOM); - if (_gcry_ecc_ecdsa_sign (test, ec, r, s, 0, 0) ) + if (_gcry_ecc_ecdsa_sign (test, NULL, ec, r, s, 0, 0) ) log_fatal ("ECDSA operation: sign failed\n"); if (_gcry_ecc_ecdsa_verify (test, ec, r, s, 0, 0)) @@ -683,6 +683,7 @@ ecc_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms) gcry_err_code_t rc; struct pk_encoding_ctx ctx; gcry_mpi_t data = NULL; + gcry_mpi_t k = NULL; gcry_mpi_t sig_r = NULL; gcry_mpi_t sig_s = NULL; mpi_ec_t ec = NULL; @@ -716,6 +717,11 @@ ecc_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms) if (DBG_CIPHER) log_mpidump ("ecc_sign data", data); + if (ctx.label) + rc = _gcry_mpi_scan (&k, GCRYMPI_FMT_USG, ctx.label, ctx.labellen, NULL); + if (rc) + goto leave; + /* Hash algo is determined by curve in EdDSA. Fill it if not specified. */ if ((ctx.flags & PUBKEY_FLAG_EDDSA) && !ctx.hash_algo) { @@ -752,7 +758,7 @@ ecc_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms) } else { - rc = _gcry_ecc_ecdsa_sign (data, ec, sig_r, sig_s, + rc = _gcry_ecc_ecdsa_sign (data, k, ec, sig_r, sig_s, ctx.flags, ctx.hash_algo); if (!rc) rc = sexp_build (r_sig, NULL, @@ -763,6 +769,7 @@ ecc_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms) _gcry_mpi_release (sig_r); _gcry_mpi_release (sig_s); _gcry_mpi_release (data); + _gcry_mpi_release (k); _gcry_mpi_ec_free (ec); _gcry_pk_util_free_encoding_ctx (&ctx); if (DBG_CIPHER) |