diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-05 08:06:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-05 08:06:15 +0000 |
commit | 8c52b877f3d8787395386b939b89cb9741c317f0 (patch) | |
tree | e052839fe22d99118333120a62a659ff19b0a6bd /src | |
parent | 69a409b107c52744b637a5115300b93ef53190e3 (diff) | |
download | gnunet-8c52b877f3d8787395386b939b89cb9741c317f0.tar.gz gnunet-8c52b877f3d8787395386b939b89cb9741c317f0.zip |
-only use x for ECDH
Diffstat (limited to 'src')
-rw-r--r-- | src/util/crypto_ecc.c | 30 | ||||
-rw-r--r-- | src/util/crypto_hash.c | 2 |
2 files changed, 7 insertions, 25 deletions
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index c89ac6904..6617ac6ea 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c | |||
@@ -835,26 +835,21 @@ GNUNET_CRYPTO_ecc_verify (uint32_t purpose, | |||
835 | * @param priv private key to use for the ECDH (x) | 835 | * @param priv private key to use for the ECDH (x) |
836 | * @param pub public key to use for the ECDH (yG) | 836 | * @param pub public key to use for the ECDH (yG) |
837 | * @param key_material where to write the key material (xyG) | 837 | * @param key_material where to write the key material (xyG) |
838 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 838 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
839 | */ | 839 | */ |
840 | int | 840 | int |
841 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv, | 841 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv, |
842 | const struct GNUNET_CRYPTO_EccPublicKey *pub, | 842 | const struct GNUNET_CRYPTO_EccPublicKey *pub, |
843 | struct GNUNET_HashCode *key_material) | 843 | struct GNUNET_HashCode *key_material) |
844 | { | 844 | { |
845 | size_t slen; | ||
846 | unsigned char sdata_buf[2048]; /* big enough to print | ||
847 | dh-shared-secret as | ||
848 | S-expression */ | ||
849 | gcry_mpi_point_t result; | 845 | gcry_mpi_point_t result; |
850 | gcry_mpi_point_t q; | 846 | gcry_mpi_point_t q; |
851 | gcry_mpi_t d; | 847 | gcry_mpi_t d; |
852 | gcry_ctx_t ctx; | 848 | gcry_ctx_t ctx; |
853 | gcry_sexp_t pub_sexpr; | 849 | gcry_sexp_t pub_sexpr; |
854 | gcry_sexp_t ecdh_sexp; | ||
855 | gcry_mpi_t result_x; | 850 | gcry_mpi_t result_x; |
856 | gcry_mpi_t result_y; | 851 | gcry_mpi_t result_y; |
857 | int rc; | 852 | unsigned char xbuf[256 / 8]; |
858 | 853 | ||
859 | /* first, extract the q = dP value from the public key */ | 854 | /* first, extract the q = dP value from the public key */ |
860 | if (! (pub_sexpr = decode_public_key (pub))) | 855 | if (! (pub_sexpr = decode_public_key (pub))) |
@@ -885,26 +880,11 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv, | |||
885 | gcry_mpi_point_release (result); | 880 | gcry_mpi_point_release (result); |
886 | gcry_ctx_release (ctx); | 881 | gcry_ctx_release (ctx); |
887 | /* FIXME: only use 'result_x' as key material */ | 882 | /* FIXME: only use 'result_x' as key material */ |
888 | if (0 != (rc = gcry_sexp_build (&ecdh_sexp, NULL, | 883 | |
889 | "(dh-shared-secret (x %m)(y %m))", | 884 | mpi_print (xbuf, sizeof (xbuf), result_x); |
890 | result_x, | 885 | GNUNET_CRYPTO_hash (xbuf, sizeof (xbuf), key_material); |
891 | result_y))) | ||
892 | { | ||
893 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); | ||
894 | gcry_mpi_release (result_x); | ||
895 | gcry_mpi_release (result_y); | ||
896 | return GNUNET_SYSERR; | ||
897 | } | ||
898 | gcry_mpi_release (result_x); | 886 | gcry_mpi_release (result_x); |
899 | gcry_mpi_release (result_y); | 887 | gcry_mpi_release (result_y); |
900 | slen = gcry_sexp_sprint (ecdh_sexp, | ||
901 | GCRYSEXP_FMT_DEFAULT, | ||
902 | sdata_buf, sizeof (sdata_buf)); | ||
903 | GNUNET_assert (0 != slen); | ||
904 | gcry_sexp_release (ecdh_sexp); | ||
905 | /* finally, get a string of the resulting S-expression and hash it | ||
906 | to generate the key material */ | ||
907 | GNUNET_CRYPTO_hash (sdata_buf, slen, key_material); | ||
908 | return GNUNET_OK; | 888 | return GNUNET_OK; |
909 | } | 889 | } |
910 | 890 | ||
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index c1d82abae..a5b97148b 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -290,6 +290,8 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, | |||
290 | 290 | ||
291 | 291 | ||
292 | /** | 292 | /** |
293 | * @ingroup hash | ||
294 | * | ||
293 | * Compute the distance between 2 hashcodes. The computation must be | 295 | * Compute the distance between 2 hashcodes. The computation must be |
294 | * fast, not involve bits[0] or bits[4] (they're used elsewhere), and be | 296 | * fast, not involve bits[0] or bits[4] (they're used elsewhere), and be |
295 | * somewhat consistent. And of course, the result should be a positive | 297 | * somewhat consistent. And of course, the result should be a positive |