From 75d507a4346840b6017e6180c752166406b69caa Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 13 Nov 2017 14:36:40 +0100 Subject: [PATCH] + crypto_core_ed25519_is_valid_point() --- dist-build/emscripten-symbols.def | 1 + src/libsodium/crypto_core/ed25519/core_ed25519.c | 15 +++++++++++++++ .../include/sodium/crypto_core_ed25519.h | 3 +++ 3 files changed, 19 insertions(+) diff --git a/dist-build/emscripten-symbols.def b/dist-build/emscripten-symbols.def index 7ee99adb..9cbf04c2 100644 --- a/dist-build/emscripten-symbols.def +++ b/dist-build/emscripten-symbols.def @@ -145,6 +145,7 @@ _crypto_box_seedbytes 1 1 _crypto_box_zerobytes 0 1 _crypto_core_ed25519_add 0 1 _crypto_core_ed25519_sub 0 1 +_crypto_core_ed25519_is_valid_point 0 1 _crypto_core_hchacha20 1 1 _crypto_core_hchacha20_constbytes 1 1 _crypto_core_hchacha20_inputbytes 1 1 diff --git a/src/libsodium/crypto_core/ed25519/core_ed25519.c b/src/libsodium/crypto_core/ed25519/core_ed25519.c index 5b675f1f..3f828812 100644 --- a/src/libsodium/crypto_core/ed25519/core_ed25519.c +++ b/src/libsodium/crypto_core/ed25519/core_ed25519.c @@ -3,6 +3,21 @@ #include "private/common.h" #include "private/ed25519_ref10.h" +int +crypto_core_ed25519_is_valid_point(const unsigned char *p) +{ + ge25519_p3 p_p3; + + if (ge25519_is_canonical(p) == 0 || + ge25519_has_small_order(p) != 0 || + ge25519_frombytes(&p_p3, p) != 0 || + ge25519_is_on_curve(&p_p3) == 0 || + ge25519_is_on_main_subgroup(&p_p3) == 0) { + return -1; + } + return 0; +} + int crypto_core_ed25519_add(unsigned char *r, const unsigned char *p, const unsigned char *q) diff --git a/src/libsodium/include/sodium/crypto_core_ed25519.h b/src/libsodium/include/sodium/crypto_core_ed25519.h index 64043a61..af751cf2 100644 --- a/src/libsodium/include/sodium/crypto_core_ed25519.h +++ b/src/libsodium/include/sodium/crypto_core_ed25519.h @@ -8,6 +8,9 @@ extern "C" { #endif +SODIUM_EXPORT +int crypto_core_ed25519_is_valid_point(const unsigned char *p); + SODIUM_EXPORT int crypto_core_ed25519_add(unsigned char *r, const unsigned char *p, const unsigned char *q);