diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2020-06-18 09:51:58 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2020-06-18 09:51:58 +0900 |
commit | 2856ac14ae3e4c9e6288e1f0d8bc1945bb874081 (patch) | |
tree | c09479ee227b55b08fae9b467350c8353b031800 | |
parent | 1cf49754694611620fd383327cf127e91f6883df (diff) | |
download | libgcrypt-2856ac14ae3e4c9e6288e1f0d8bc1945bb874081.tar.gz |
ecc: Change EdDSA internal API.
* cipher/ecc-common.h (_gcry_ecc_eddsa_sign): Last arg is CTX.
(_gcry_ecc_eddsa_verify): Ditto.
* cipher/ecc-eddsa.c (_gcry_ecc_eddsa_sign): Get hash algo from CTX.
(_gcry_ecc_eddsa_verify): Ditto.
* cipher/ecc.c (ecc_sign, ecc_verify): Follow the change.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r-- | cipher/ecc-common.h | 4 | ||||
-rw-r--r-- | cipher/ecc-eddsa.c | 24 | ||||
-rw-r--r-- | cipher/ecc.c | 4 |
3 files changed, 17 insertions, 15 deletions
diff --git a/cipher/ecc-common.h b/cipher/ecc-common.h index b8b7c763..25c31112 100644 --- a/cipher/ecc-common.h +++ b/cipher/ecc-common.h @@ -110,11 +110,11 @@ gpg_err_code_t _gcry_ecc_eddsa_genkey (mpi_ec_t ec, int flags); gpg_err_code_t _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec, gcry_mpi_t r_r, gcry_mpi_t s, - int hashalgo); + struct pk_encoding_ctx *ctx); gpg_err_code_t _gcry_ecc_eddsa_verify (gcry_mpi_t input, mpi_ec_t ec, gcry_mpi_t r, gcry_mpi_t s, - int hashalgo); + struct pk_encoding_ctx *ctx); void reverse_buffer (unsigned char *buffer, unsigned int length); diff --git a/cipher/ecc-eddsa.c b/cipher/ecc-eddsa.c index bb96b1fa..777694ca 100644 --- a/cipher/ecc-eddsa.c +++ b/cipher/ecc-eddsa.c @@ -688,7 +688,8 @@ _gcry_ecc_eddsa_genkey (mpi_ec_t ec, int flags) gpg_err_code_t _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec, - gcry_mpi_t r_r, gcry_mpi_t s, int hashalgo) + gcry_mpi_t r_r, gcry_mpi_t s, + struct pk_encoding_ctx *ctx) { int rc; unsigned int tmp; @@ -748,12 +749,12 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec, if (DBG_CIPHER) log_printhex (" m", mbuf, mlen); - if (hashalgo == GCRY_MD_SHAKE256) + if (ctx->hash_algo == GCRY_MD_SHAKE256) { gcry_error_t err; gcry_md_hd_t hd; - err = _gcry_md_open (&hd, hashalgo, 0); + err = _gcry_md_open (&hd, ctx->hash_algo, 0); if (err) rc = gcry_err_code (err); else @@ -778,7 +779,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec, hvec[0].len = b; hvec[1].data = (char*)mbuf; hvec[1].len = mlen; - rc = _gcry_md_hash_buffers (hashalgo, 0, digest, hvec, 2); + rc = _gcry_md_hash_buffers (ctx->hash_algo, 0, digest, hvec, 2); } if (rc) @@ -799,12 +800,12 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec, if (DBG_CIPHER) log_printhex (" e_r", rawmpi, rawmpilen); - if (hashalgo == GCRY_MD_SHAKE256) + if (ctx->hash_algo == GCRY_MD_SHAKE256) { gcry_error_t err; gcry_md_hd_t hd; - err = _gcry_md_open (&hd, hashalgo, 0); + err = _gcry_md_open (&hd, ctx->hash_algo, 0); if (err) rc = gcry_err_code (err); else @@ -835,7 +836,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec, hvec[2].data = (char*)mbuf; hvec[2].off = 0; hvec[2].len = mlen; - rc = _gcry_md_hash_buffers (hashalgo, 0, digest, hvec, 3); + rc = _gcry_md_hash_buffers (ctx->hash_algo, 0, digest, hvec, 3); } if (rc) @@ -879,7 +880,8 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input, mpi_ec_t ec, */ gpg_err_code_t _gcry_ecc_eddsa_verify (gcry_mpi_t input, mpi_ec_t ec, - gcry_mpi_t r_in, gcry_mpi_t s_in, int hashalgo) + gcry_mpi_t r_in, gcry_mpi_t s_in, + struct pk_encoding_ctx *ctx) { int rc; int b; @@ -944,12 +946,12 @@ _gcry_ecc_eddsa_verify (gcry_mpi_t input, mpi_ec_t ec, goto leave; } - if (hashalgo == GCRY_MD_SHAKE256) + if (ctx->hash_algo == GCRY_MD_SHAKE256) { gcry_error_t err; gcry_md_hd_t hd; - err = _gcry_md_open (&hd, hashalgo, 0); + err = _gcry_md_open (&hd, ctx->hash_algo, 0); if (err) rc = gcry_err_code (err); else @@ -980,7 +982,7 @@ _gcry_ecc_eddsa_verify (gcry_mpi_t input, mpi_ec_t ec, hvec[2].data = (char*)mbuf; hvec[2].off = 0; hvec[2].len = mlen; - rc = _gcry_md_hash_buffers (hashalgo, 0, digest, hvec, 3); + rc = _gcry_md_hash_buffers (ctx->hash_algo, 0, digest, hvec, 3); } if (rc) diff --git a/cipher/ecc.c b/cipher/ecc.c index 80eb551a..7b3ebd54 100644 --- a/cipher/ecc.c +++ b/cipher/ecc.c @@ -715,7 +715,7 @@ ecc_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_data, gcry_sexp_t keyparms) if ((ctx.flags & PUBKEY_FLAG_EDDSA)) { /* EdDSA requires the public key. */ - rc = _gcry_ecc_eddsa_sign (data, ec, sig_r, sig_s, ctx.hash_algo); + rc = _gcry_ecc_eddsa_sign (data, ec, sig_r, sig_s, &ctx); if (!rc) rc = sexp_build (r_sig, NULL, "(sig-val(eddsa(r%M)(s%M)))", sig_r, sig_s); @@ -827,7 +827,7 @@ ecc_verify (gcry_sexp_t s_sig, gcry_sexp_t s_data, gcry_sexp_t s_keyparms) */ if ((sigflags & PUBKEY_FLAG_EDDSA)) { - rc = _gcry_ecc_eddsa_verify (data, ec, sig_r, sig_s, ctx.hash_algo); + rc = _gcry_ecc_eddsa_verify (data, ec, sig_r, sig_s, &ctx); } else if ((sigflags & PUBKEY_FLAG_GOST)) { |