diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2019-06-21 11:47:33 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2019-06-21 11:47:33 +0900 |
commit | a658c9ccc2c741f40b0b5cdbcd184cfb9a841d17 (patch) | |
tree | ce0592356ad72bb7e6c28af8fc53d6f7b7e83696 /cipher/ecc-ecdh.c | |
parent | 6d77c2054ea0358fb4c6f59b4c91c673c0a83b03 (diff) | |
download | libgcrypt-a658c9ccc2c741f40b0b5cdbcd184cfb9a841d17.tar.gz |
ecc: Improve new ECDH API.
* cipher/ecc-ecdh.c (_gcry_ecc_get_algo_keylen): New.
(_gcry_ecc_mul_point): Fill into the RESULT buffer, instead of
allocating new buffer.
* src/gcrypt-int.h: Change the API.
* src/gcrypt.h.in: Likewise.
* src/libgcrypt.def (gcry_ecc_get_algo_keylen): New.
* src/libgcrypt.vers (gcry_ecc_get_algo_keylen): New.
* src/visibility.c (gcry_ecc_get_algo_keylen): New.
* src/visibility.h (gcry_ecc_get_algo_keylen): New.
* tests/t-cv25519.c: Fix the use case.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'cipher/ecc-ecdh.c')
-rw-r--r-- | cipher/ecc-ecdh.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/cipher/ecc-ecdh.c b/cipher/ecc-ecdh.c index ab083ff5..4f1af7a5 100644 --- a/cipher/ecc-ecdh.c +++ b/cipher/ecc-ecdh.c @@ -48,9 +48,21 @@ prepare_ec (const char *curve_name, elliptic_curve_t *E) return ec; } +unsigned int +_gcry_ecc_get_algo_keylen (int algo) +{ + unsigned int len = 0; + + if (algo == GCRY_ECC_CURVE25519) + len = ECC_CURVE25519_BITS/8; + else + len = ECC_CURVE448_BITS/8; + + return len; +} gpg_error_t -_gcry_ecc_mul_point (int algo, unsigned char **r_result, +_gcry_ecc_mul_point (int algo, unsigned char *result, const unsigned char *scalar, const unsigned char *point) { unsigned int nbits; @@ -66,6 +78,7 @@ _gcry_ecc_mul_point (int algo, unsigned char **r_result, gcry_mpi_t x; unsigned int len; int i; + unsigned char *buf; if (algo == GCRY_ECC_CURVE25519) { @@ -112,9 +125,11 @@ _gcry_ecc_mul_point (int algo, unsigned char **r_result, _gcry_mpi_ec_get_affine (x, NULL, Q, ec); - *r_result = _gcry_mpi_get_buffer (x, ECC_CURVE448_BITS/8, &len, NULL); - if (!*r_result) + buf = _gcry_mpi_get_buffer (x, nbytes, &len, NULL); + if (!buf) err = gpg_error_from_syserror (); + memcpy (result, buf, nbytes); + xfree (buf); leave: _gcry_mpi_release (x); |