From 57dac9eb602352ed5eee8455393f1a841d8eb3e4 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 13 Nov 2017 14:21:14 +0100 Subject: [PATCH] + crypto_core_ed25519_add(), crypto_core_ed25519_sub() --- .../msvc/vs2010/libsodium/libsodium.vcxproj | 3 ++ .../libsodium/libsodium.vcxproj.filters | 9 ++++ .../msvc/vs2012/libsodium/libsodium.vcxproj | 3 ++ .../libsodium/libsodium.vcxproj.filters | 9 ++++ .../msvc/vs2013/libsodium/libsodium.vcxproj | 3 ++ .../libsodium/libsodium.vcxproj.filters | 9 ++++ .../msvc/vs2015/libsodium/libsodium.vcxproj | 3 ++ .../libsodium/libsodium.vcxproj.filters | 9 ++++ .../msvc/vs2017/libsodium/libsodium.vcxproj | 3 ++ .../libsodium/libsodium.vcxproj.filters | 9 ++++ dist-build/emscripten-symbols.def | 2 + libsodium.vcxproj | 3 ++ libsodium.vcxproj.filters | 9 ++++ src/libsodium/Makefile.am | 1 + .../crypto_core/ed25519/core_ed25519.c | 44 +++++++++++++++++++ .../crypto_core/ed25519/ref10/ed25519_ref10.c | 4 +- src/libsodium/include/Makefile.am | 1 + src/libsodium/include/sodium.h | 1 + .../include/sodium/crypto_core_ed25519.h | 25 +++++++++++ .../include/sodium/private/ed25519_ref10.h | 4 ++ 20 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 src/libsodium/crypto_core/ed25519/core_ed25519.c create mode 100644 src/libsodium/include/sodium/crypto_core_ed25519.h diff --git a/builds/msvc/vs2010/libsodium/libsodium.vcxproj b/builds/msvc/vs2010/libsodium/libsodium.vcxproj index 10112203..e0e16418 100644 --- a/builds/msvc/vs2010/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2010/libsodium/libsodium.vcxproj @@ -180,6 +180,7 @@ + @@ -198,6 +199,7 @@ + @@ -243,6 +245,7 @@ + diff --git a/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters index d3b56126..4170617c 100644 --- a/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters @@ -333,6 +333,9 @@ crypto_core\hsalsa20\ref2 + + crypto_core\ed25519 + crypto_core\ed25519\ref10 @@ -383,6 +386,9 @@ include\sodium + + include\sodium + include\sodium @@ -518,6 +524,9 @@ include\sodium + + include\sodium + include\sodium diff --git a/builds/msvc/vs2012/libsodium/libsodium.vcxproj b/builds/msvc/vs2012/libsodium/libsodium.vcxproj index 821212c2..4f162572 100644 --- a/builds/msvc/vs2012/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2012/libsodium/libsodium.vcxproj @@ -180,6 +180,7 @@ + @@ -198,6 +199,7 @@ + @@ -243,6 +245,7 @@ + diff --git a/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters index d3b56126..4170617c 100644 --- a/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters @@ -333,6 +333,9 @@ crypto_core\hsalsa20\ref2 + + crypto_core\ed25519 + crypto_core\ed25519\ref10 @@ -383,6 +386,9 @@ include\sodium + + include\sodium + include\sodium @@ -518,6 +524,9 @@ include\sodium + + include\sodium + include\sodium diff --git a/builds/msvc/vs2013/libsodium/libsodium.vcxproj b/builds/msvc/vs2013/libsodium/libsodium.vcxproj index d24f224d..b6fddfe8 100644 --- a/builds/msvc/vs2013/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2013/libsodium/libsodium.vcxproj @@ -180,6 +180,7 @@ + @@ -198,6 +199,7 @@ + @@ -243,6 +245,7 @@ + diff --git a/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters index d3b56126..4170617c 100644 --- a/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters @@ -333,6 +333,9 @@ crypto_core\hsalsa20\ref2 + + crypto_core\ed25519 + crypto_core\ed25519\ref10 @@ -383,6 +386,9 @@ include\sodium + + include\sodium + include\sodium @@ -518,6 +524,9 @@ include\sodium + + include\sodium + include\sodium diff --git a/builds/msvc/vs2015/libsodium/libsodium.vcxproj b/builds/msvc/vs2015/libsodium/libsodium.vcxproj index 51f8c51c..0b4dc07f 100644 --- a/builds/msvc/vs2015/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2015/libsodium/libsodium.vcxproj @@ -180,6 +180,7 @@ + @@ -198,6 +199,7 @@ + @@ -243,6 +245,7 @@ + diff --git a/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters index d3b56126..4170617c 100644 --- a/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters @@ -333,6 +333,9 @@ crypto_core\hsalsa20\ref2 + + crypto_core\ed25519 + crypto_core\ed25519\ref10 @@ -383,6 +386,9 @@ include\sodium + + include\sodium + include\sodium @@ -518,6 +524,9 @@ include\sodium + + include\sodium + include\sodium diff --git a/builds/msvc/vs2017/libsodium/libsodium.vcxproj b/builds/msvc/vs2017/libsodium/libsodium.vcxproj index 815c1137..69626389 100644 --- a/builds/msvc/vs2017/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2017/libsodium/libsodium.vcxproj @@ -180,6 +180,7 @@ + @@ -198,6 +199,7 @@ + @@ -243,6 +245,7 @@ + diff --git a/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters index d3b56126..4170617c 100644 --- a/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters @@ -333,6 +333,9 @@ crypto_core\hsalsa20\ref2 + + crypto_core\ed25519 + crypto_core\ed25519\ref10 @@ -383,6 +386,9 @@ include\sodium + + include\sodium + include\sodium @@ -518,6 +524,9 @@ include\sodium + + include\sodium + include\sodium diff --git a/dist-build/emscripten-symbols.def b/dist-build/emscripten-symbols.def index f14cfdf5..7ee99adb 100644 --- a/dist-build/emscripten-symbols.def +++ b/dist-build/emscripten-symbols.def @@ -143,6 +143,8 @@ _crypto_box_secretkeybytes 1 1 _crypto_box_seed_keypair 1 1 _crypto_box_seedbytes 1 1 _crypto_box_zerobytes 0 1 +_crypto_core_ed25519_add 0 1 +_crypto_core_ed25519_sub 0 1 _crypto_core_hchacha20 1 1 _crypto_core_hchacha20_constbytes 1 1 _crypto_core_hchacha20_inputbytes 1 1 diff --git a/libsodium.vcxproj b/libsodium.vcxproj index b0dd3431..645f9ad5 100644 --- a/libsodium.vcxproj +++ b/libsodium.vcxproj @@ -418,6 +418,7 @@ + @@ -436,6 +437,7 @@ + @@ -481,6 +483,7 @@ + diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters index 627197f7..72eb19e4 100644 --- a/libsodium.vcxproj.filters +++ b/libsodium.vcxproj.filters @@ -324,6 +324,9 @@ Source Files + + Source Files + Source Files @@ -374,6 +377,9 @@ Header Files + + Header Files + Header Files @@ -509,6 +515,9 @@ Header Files + + Header Files + Header Files diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index 83aac249..5d726545 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -164,6 +164,7 @@ if !MINIMAL libsodium_la_SOURCES += \ crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c \ crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c \ + crypto_core/ed25519/core_ed25519.c \ crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c \ crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h \ crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c \ diff --git a/src/libsodium/crypto_core/ed25519/core_ed25519.c b/src/libsodium/crypto_core/ed25519/core_ed25519.c new file mode 100644 index 00000000..5b675f1f --- /dev/null +++ b/src/libsodium/crypto_core/ed25519/core_ed25519.c @@ -0,0 +1,44 @@ + +#include "crypto_core_ed25519.h" +#include "private/common.h" +#include "private/ed25519_ref10.h" + +int +crypto_core_ed25519_add(unsigned char *r, + const unsigned char *p, const unsigned char *q) +{ + ge25519_p3 p_p3, q_p3, r_p3; + ge25519_p1p1 r_p1p1; + ge25519_cached q_cached; + + if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 || + ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) { + return -1; + } + ge25519_p3_to_cached(&q_cached, &q_p3); + ge25519_add(&r_p1p1, &p_p3, &q_cached); + ge25519_p1p1_to_p3(&r_p3, &r_p1p1); + ge25519_p3_tobytes(r, &r_p3); + + return 0; +} + +int +crypto_core_ed25519_sub(unsigned char *r, + const unsigned char *p, const unsigned char *q) +{ + ge25519_p3 p_p3, q_p3, r_p3; + ge25519_p1p1 r_p1p1; + ge25519_cached q_cached; + + if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 || + ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) { + return -1; + } + ge25519_p3_to_cached(&q_cached, &q_p3); + ge25519_sub(&r_p1p1, &p_p3, &q_cached); + ge25519_p1p1_to_p3(&r_p3, &r_p1p1); + ge25519_p3_tobytes(r, &r_p3); + + return 0; +} diff --git a/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c b/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c index 6ddffa05..47ef6a10 100644 --- a/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c +++ b/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c @@ -375,7 +375,7 @@ ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p) r = p */ -static void +void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p) { fe25519_mul(r->X, p->X, p->T); @@ -569,7 +569,7 @@ ge25519_select_base(ge25519_precomp *t, const int pos, const signed char b) r = p - q */ -static void +void ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q) { fe25519 t0; diff --git a/src/libsodium/include/Makefile.am b/src/libsodium/include/Makefile.am index b4826c2f..b70c22b3 100644 --- a/src/libsodium/include/Makefile.am +++ b/src/libsodium/include/Makefile.am @@ -12,6 +12,7 @@ SODIUM_EXPORT = \ sodium/crypto_box.h \ sodium/crypto_box_curve25519xchacha20poly1305.h \ sodium/crypto_box_curve25519xsalsa20poly1305.h \ + sodium/crypto_core_ed25519.h \ sodium/crypto_core_hchacha20.h \ sodium/crypto_core_hsalsa20.h \ sodium/crypto_core_salsa20.h \ diff --git a/src/libsodium/include/sodium.h b/src/libsodium/include/sodium.h index 77f1f11f..e7b1af46 100644 --- a/src/libsodium/include/sodium.h +++ b/src/libsodium/include/sodium.h @@ -58,6 +58,7 @@ #ifndef SODIUM_LIBRARY_MINIMAL # include "sodium/crypto_box_curve25519xchacha20poly1305.h" +# include "sodium/crypto_core_ed25519.h" # include "sodium/crypto_scalarmult_ed25519.h" # include "sodium/crypto_secretbox_xchacha20poly1305.h" # include "sodium/crypto_pwhash_scryptsalsa208sha256.h" diff --git a/src/libsodium/include/sodium/crypto_core_ed25519.h b/src/libsodium/include/sodium/crypto_core_ed25519.h new file mode 100644 index 00000000..64043a61 --- /dev/null +++ b/src/libsodium/include/sodium/crypto_core_ed25519.h @@ -0,0 +1,25 @@ +#ifndef crypto_core_ed25519_H +#define crypto_core_ed25519_H + +#include +#include "export.h" + +#ifdef __cplusplus +extern "C" { +#endif + +SODIUM_EXPORT +int crypto_core_ed25519_add(unsigned char *r, + const unsigned char *p, const unsigned char *q); + +SODIUM_EXPORT +int crypto_core_ed25519_sub(unsigned char *r, + const unsigned char *p, const unsigned char *q); + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/src/libsodium/include/sodium/private/ed25519_ref10.h b/src/libsodium/include/sodium/private/ed25519_ref10.h index dc45369a..42577229 100644 --- a/src/libsodium/include/sodium/private/ed25519_ref10.h +++ b/src/libsodium/include/sodium/private/ed25519_ref10.h @@ -85,8 +85,12 @@ void ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p); void ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p); +void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p); + void ge25519_add(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q); +void ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q); + void ge25519_scalarmult_base(ge25519_p3 *h, const unsigned char *a); void ge25519_double_scalarmult_vartime(ge25519_p2 *r, const unsigned char *a,