From fbe7b2d888441517b0de8461f11cc05e5a00580f Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Fri, 9 Aug 2019 10:01:49 +0700 Subject: [PATCH] Refreshed bindings randombytes_salsa20_random replaced by randombytes_internal_implementation Forgot to update package.d --- source/libsodium/crypto_core_ed25519.d | 12 ++++ source/libsodium/crypto_core_ristretto255.d | 67 +++++++++++++++++++ source/libsodium/crypto_scalarmult.d | 2 +- .../libsodium/crypto_scalarmult_curve25519.d | 2 +- source/libsodium/crypto_scalarmult_ed25519.d | 2 +- .../crypto_scalarmult_ristretto255.d | 33 +++++++++ source/libsodium/package.d | 4 +- ...random.d => randombytes_internal_random.d} | 6 +- 8 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 source/libsodium/crypto_core_ristretto255.d create mode 100644 source/libsodium/crypto_scalarmult_ristretto255.d rename source/libsodium/{randombytes_salsa20_random.d => randombytes_internal_random.d} (59%) diff --git a/source/libsodium/crypto_core_ed25519.d b/source/libsodium/crypto_core_ed25519.d index 5072c4e..38e73e1 100644 --- a/source/libsodium/crypto_core_ed25519.d +++ b/source/libsodium/crypto_core_ed25519.d @@ -20,6 +20,9 @@ size_t crypto_core_ed25519_bytes (); enum crypto_core_ed25519_UNIFORMBYTES = 32; size_t crypto_core_ed25519_uniformbytes (); +enum crypto_core_ed25519_HASHBYTES = 64; +size_t crypto_core_ed25519_hashbytes (); + enum crypto_core_ed25519_SCALARBYTES = 32; size_t crypto_core_ed25519_scalarbytes (); @@ -34,6 +37,10 @@ int crypto_core_ed25519_sub (ubyte* r, const(ubyte)* p, const(ubyte)* q); int crypto_core_ed25519_from_uniform (ubyte* p, const(ubyte)* r); +int crypto_core_ed25519_from_hash (ubyte* p, const(ubyte)* h); + +void crypto_core_ed25519_random (ubyte* p); + void crypto_core_ed25519_scalar_random (ubyte* r); int crypto_core_ed25519_scalar_invert (ubyte* recip, const(ubyte)* s); @@ -52,6 +59,11 @@ void crypto_core_ed25519_scalar_sub ( const(ubyte)* x, const(ubyte)* y); +void crypto_core_ed25519_scalar_mul ( + ubyte* z, + const(ubyte)* x, + const(ubyte)* y); + /* * The interval `s` is sampled from should be at least 317 bits to ensure almost * uniformity of `r` over `L`. diff --git a/source/libsodium/crypto_core_ristretto255.d b/source/libsodium/crypto_core_ristretto255.d new file mode 100644 index 0000000..3bbe9bd --- /dev/null +++ b/source/libsodium/crypto_core_ristretto255.d @@ -0,0 +1,67 @@ +/******************************************************************************* + + D language bindings for libsodium's crypto_core_ristretto255.h + + License: ISC (see LICENSE.txt) + +*******************************************************************************/ + +module libsodium.crypto_core_ristretto255; + +@nogc nothrow: + +import libsodium.export_; + +extern (C): + +enum crypto_core_ristretto255_BYTES = 32; +size_t crypto_core_ristretto255_bytes (); + +enum crypto_core_ristretto255_HASHBYTES = 64; +size_t crypto_core_ristretto255_hashbytes (); + +enum crypto_core_ristretto255_SCALARBYTES = 32; +size_t crypto_core_ristretto255_scalarbytes (); + +enum crypto_core_ristretto255_NONREDUCEDSCALARBYTES = 64; +size_t crypto_core_ristretto255_nonreducedscalarbytes (); + +int crypto_core_ristretto255_is_valid_point (const(ubyte)* p); + +int crypto_core_ristretto255_add (ubyte* r, const(ubyte)* p, const(ubyte)* q); + +int crypto_core_ristretto255_sub (ubyte* r, const(ubyte)* p, const(ubyte)* q); + +int crypto_core_ristretto255_from_hash (ubyte* p, const(ubyte)* r); + +void crypto_core_ristretto255_random (ubyte* p); + +void crypto_core_ristretto255_scalar_random (ubyte* r); + +int crypto_core_ristretto255_scalar_invert (ubyte* recip, const(ubyte)* s); + +void crypto_core_ristretto255_scalar_negate (ubyte* neg, const(ubyte)* s); + +void crypto_core_ristretto255_scalar_complement (ubyte* comp, const(ubyte)* s); + +void crypto_core_ristretto255_scalar_add ( + ubyte* z, + const(ubyte)* x, + const(ubyte)* y); + +void crypto_core_ristretto255_scalar_sub ( + ubyte* z, + const(ubyte)* x, + const(ubyte)* y); + +void crypto_core_ristretto255_scalar_mul ( + ubyte* z, + const(ubyte)* x, + const(ubyte)* y); + +/* + * The interval `s` is sampled from should be at least 317 bits to ensure almost + * uniformity of `r` over `L`. + */ +void crypto_core_ristretto255_scalar_reduce (ubyte* r, const(ubyte)* s); + diff --git a/source/libsodium/crypto_scalarmult.d b/source/libsodium/crypto_scalarmult.d index 950b41f..1932607 100644 --- a/source/libsodium/crypto_scalarmult.d +++ b/source/libsodium/crypto_scalarmult.d @@ -27,7 +27,7 @@ const(char)* crypto_scalarmult_primitive (); int crypto_scalarmult_base (ubyte* q, const(ubyte)* n); /* - * NOTE: Do not use the result of this function directly. + * NOTE: Do not use the result of this function directly for key exchange. * * Hash the result with the public keys in order to compute a shared * secret key: H(q || client_pk || server_pk) diff --git a/source/libsodium/crypto_scalarmult_curve25519.d b/source/libsodium/crypto_scalarmult_curve25519.d index 0787b4e..5e4e5f6 100644 --- a/source/libsodium/crypto_scalarmult_curve25519.d +++ b/source/libsodium/crypto_scalarmult_curve25519.d @@ -21,7 +21,7 @@ enum crypto_scalarmult_curve25519_SCALARBYTES = 32U; size_t crypto_scalarmult_curve25519_scalarbytes (); /* - * NOTE: Do not use the result of this function directly. + * NOTE: Do not use the result of this function directly for key exchange. * * Hash the result with the public keys in order to compute a shared * secret key: H(q || client_pk || server_pk) diff --git a/source/libsodium/crypto_scalarmult_ed25519.d b/source/libsodium/crypto_scalarmult_ed25519.d index 5626b6c..970f786 100644 --- a/source/libsodium/crypto_scalarmult_ed25519.d +++ b/source/libsodium/crypto_scalarmult_ed25519.d @@ -21,7 +21,7 @@ enum crypto_scalarmult_ed25519_SCALARBYTES = 32U; size_t crypto_scalarmult_ed25519_scalarbytes (); /* - * NOTE: Do not use the result of this function directly. + * NOTE: Do not use the result of this function directly for key exchange. * * Hash the result with the public keys in order to compute a shared * secret key: H(q || client_pk || server_pk) diff --git a/source/libsodium/crypto_scalarmult_ristretto255.d b/source/libsodium/crypto_scalarmult_ristretto255.d new file mode 100644 index 0000000..955a36a --- /dev/null +++ b/source/libsodium/crypto_scalarmult_ristretto255.d @@ -0,0 +1,33 @@ +/******************************************************************************* + + D language bindings for libsodium's crypto_scalarmult_ristretto255.h + + License: ISC (see LICENSE.txt) + +*******************************************************************************/ + +module libsodium.crypto_scalarmult_ristretto255; + +@nogc nothrow: + +import libsodium.export_; + +extern (C): + +enum crypto_scalarmult_ristretto255_BYTES = 32U; +size_t crypto_scalarmult_ristretto255_bytes (); + +enum crypto_scalarmult_ristretto255_SCALARBYTES = 32U; +size_t crypto_scalarmult_ristretto255_scalarbytes (); + +/* + * NOTE: Do not use the result of this function directly for key exchange. + * + * Hash the result with the public keys in order to compute a shared + * secret key: H(q || client_pk || server_pk) + * + * Or unless this is not an option, use the crypto_kx() API instead. + */ +int crypto_scalarmult_ristretto255 (ubyte* q, const(ubyte)* n, const(ubyte)* p); + +int crypto_scalarmult_ristretto255_base (ubyte* q, const(ubyte)* n); diff --git a/source/libsodium/package.d b/source/libsodium/package.d index 9c00289..d6d55e6 100644 --- a/source/libsodium/package.d +++ b/source/libsodium/package.d @@ -22,6 +22,7 @@ public import libsodium.crypto_box_curve25519xsalsa20poly1305; public import libsodium.crypto_core_ed25519; public import libsodium.crypto_core_hchacha20; public import libsodium.crypto_core_hsalsa20; +public import libsodium.crypto_core_ristretto255; public import libsodium.crypto_core_salsa2012; public import libsodium.crypto_core_salsa208; public import libsodium.crypto_core_salsa20; @@ -42,6 +43,7 @@ public import libsodium.crypto_pwhash_scryptsalsa208sha256; public import libsodium.crypto_scalarmult; public import libsodium.crypto_scalarmult_curve25519; public import libsodium.crypto_scalarmult_ed25519; +public import libsodium.crypto_scalarmult_ristretto255; public import libsodium.crypto_secretbox; public import libsodium.crypto_secretbox_xchacha20poly1305; public import libsodium.crypto_secretbox_xsalsa20poly1305; @@ -63,8 +65,8 @@ public import libsodium.crypto_verify_32; public import libsodium.crypto_verify_64; public import libsodium.export_; public import libsodium.randombytes; +public import libsodium.randombytes_internal_random; public import libsodium.randombytes_nativeclient; -public import libsodium.randombytes_salsa20_random; public import libsodium.randombytes_sysrandom; public import libsodium.runtime; public import libsodium.utils; diff --git a/source/libsodium/randombytes_salsa20_random.d b/source/libsodium/randombytes_internal_random.d similarity index 59% rename from source/libsodium/randombytes_salsa20_random.d rename to source/libsodium/randombytes_internal_random.d index c28d783..8ceefb0 100644 --- a/source/libsodium/randombytes_salsa20_random.d +++ b/source/libsodium/randombytes_internal_random.d @@ -1,12 +1,12 @@ /******************************************************************************* - D language bindings for libsodium's randombytes_salsa20_random.h + D language bindings for libsodium's randombytes_internal_random.h License: ISC (see LICENSE.txt) *******************************************************************************/ -module libsodium.randombytes_salsa20_random; +module libsodium.randombytes_internal_random; @nogc nothrow: @@ -15,4 +15,4 @@ import libsodium.randombytes; extern (C): -extern __gshared randombytes_implementation randombytes_salsa20_implementation; +extern __gshared randombytes_implementation randombytes_internal_implementation;