diff --git a/src/GENERATED/c/curve25519/decaf.c b/src/GENERATED/c/curve25519/decaf.c index cd3265a..3760272 100644 --- a/src/GENERATED/c/curve25519/decaf.c +++ b/src/GENERATED/c/curve25519/decaf.c @@ -1324,6 +1324,13 @@ decaf_error_t decaf_x25519 ( void decaf_x25519_generate_key ( uint8_t out[X_PUBLIC_BYTES], const uint8_t scalar[X_PRIVATE_BYTES] +) { + decaf_x25519_derive_public_key(out,scalar); +} + +void decaf_x25519_derive_public_key ( + uint8_t out[X_PUBLIC_BYTES], + const uint8_t scalar[X_PRIVATE_BYTES] ) { /* Scalar conditioning */ uint8_t scalar2[X_PRIVATE_BYTES]; diff --git a/src/GENERATED/c/ed448goldilocks/decaf.c b/src/GENERATED/c/ed448goldilocks/decaf.c index 4ff0b5a..d9ba6fc 100644 --- a/src/GENERATED/c/ed448goldilocks/decaf.c +++ b/src/GENERATED/c/ed448goldilocks/decaf.c @@ -1324,6 +1324,13 @@ decaf_error_t decaf_x448 ( void decaf_x448_generate_key ( uint8_t out[X_PUBLIC_BYTES], const uint8_t scalar[X_PRIVATE_BYTES] +) { + decaf_x448_derive_public_key(out,scalar); +} + +void decaf_x448_derive_public_key ( + uint8_t out[X_PUBLIC_BYTES], + const uint8_t scalar[X_PRIVATE_BYTES] ) { /* Scalar conditioning */ uint8_t scalar2[X_PRIVATE_BYTES]; diff --git a/src/GENERATED/include/decaf/point_255.h b/src/GENERATED/include/decaf/point_255.h index 621cdea..02602c5 100644 --- a/src/GENERATED/include/decaf/point_255.h +++ b/src/GENERATED/include/decaf/point_255.h @@ -404,12 +404,33 @@ extern const uint8_t decaf_x25519_base_point[DECAF_X25519_PUBLIC_BYTES] API_VIS; * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses * a different (non-Decaf) encoding. * + * @deprecated Renamed to decaf_x25519_derive_public_key. + * I have no particular timeline for removing this name. + * * @param [out] scaled The scaled point base*scalar * @param [in] scalar The scalar to multiply by. */ void decaf_x25519_generate_key ( uint8_t out[DECAF_X25519_PUBLIC_BYTES], const uint8_t scalar[DECAF_X25519_PRIVATE_BYTES] +) API_VIS NONNULL NOINLINE +__attribute__((deprecated( + "Renamed to decaf_x25519_derive_public_key" +))); + +/** + * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses + * a different (non-Decaf) encoding. + * + * Does exactly the same thing as decaf_x25519_generate_key, + * but has a better name. + * + * @param [out] scaled The scaled point base*scalar + * @param [in] scalar The scalar to multiply by. + */ +void decaf_x25519_derive_public_key ( + uint8_t out[DECAF_X25519_PUBLIC_BYTES], + const uint8_t scalar[DECAF_X25519_PRIVATE_BYTES] ) API_VIS NONNULL NOINLINE; /* FUTURE: uint8_t decaf_255_encode_like_curve25519) */ diff --git a/src/GENERATED/include/decaf/point_255.hxx b/src/GENERATED/include/decaf/point_255.hxx index b70d57a..3642720 100644 --- a/src/GENERATED/include/decaf/point_255.hxx +++ b/src/GENERATED/include/decaf/point_255.hxx @@ -645,7 +645,7 @@ public: return FixedBlock(decaf_x25519_base_point); } - /** Generate and return a shared secret with public key. */ + /** Calculate and return a shared secret with public key. */ static inline SecureBuffer shared_secret( const FixedBlock &pk, const FixedBlock &scalar @@ -657,7 +657,7 @@ public: return out; } - /** Generate and return a shared secret with public key, noexcept version. */ + /** Calculate and write into out a shared secret with public key, noexcept version. */ static inline decaf_error_t WARN_UNUSED shared_secret_noexcept ( FixedBuffer &out, @@ -667,26 +667,55 @@ public: return decaf_x25519(out.data(), pk.data(), scalar.data()); } - /** Generate and return a public key; equivalent to shared_secret(base_point(),scalar) + /** Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) * but possibly faster. + * @deprecated Renamed to derive_public_key. */ - static inline SecureBuffer generate_key( + static inline SecureBuffer __attribute__((deprecated( + "Renamed to derive_public_key" + ))) generate_key( const FixedBlock &scalar ) throw(std::bad_alloc) { SecureBuffer out(PUBLIC_BYTES); - decaf_x25519_generate_key(out.data(), scalar.data()); + decaf_x25519_derive_public_key(out.data(), scalar.data()); return out; } - /** Generate and return a public key into a fixed buffer; + /** Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) + * but possibly faster. + */ + static inline SecureBuffer derive_public_key( + const FixedBlock &scalar + ) throw(std::bad_alloc) { + SecureBuffer out(PUBLIC_BYTES); + decaf_x25519_derive_public_key(out.data(), scalar.data()); + return out; + } + + /** Calculate and return a public key into a fixed buffer; + * equivalent to shared_secret(base_point(),scalar) but possibly faster. + */ + static inline void + derive_public_key_noexcept ( + FixedBuffer &out, + const FixedBlock &scalar + ) NOEXCEPT { + decaf_x25519_derive_public_key(out.data(), scalar.data()); + } + + /** Calculate and return a public key into a fixed buffer; * equivalent to shared_secret(base_point(),scalar) but possibly faster. + * @deprecated Renamed to derive_public_key_noexcept. */ static inline void + __attribute__((deprecated( + "Renamed to derive_public_key_noexcept" + ))) generate_key_noexcept ( FixedBuffer &out, const FixedBlock &scalar ) NOEXCEPT { - decaf_x25519_generate_key(out.data(), scalar.data()); + decaf_x25519_derive_public_key(out.data(), scalar.data()); } }; diff --git a/src/GENERATED/include/decaf/point_448.h b/src/GENERATED/include/decaf/point_448.h index 65e9057..8c38195 100644 --- a/src/GENERATED/include/decaf/point_448.h +++ b/src/GENERATED/include/decaf/point_448.h @@ -404,12 +404,33 @@ extern const uint8_t decaf_x448_base_point[DECAF_X448_PUBLIC_BYTES] API_VIS; * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses * a different (non-Decaf) encoding. * + * @deprecated Renamed to decaf_x448_derive_public_key. + * I have no particular timeline for removing this name. + * * @param [out] scaled The scaled point base*scalar * @param [in] scalar The scalar to multiply by. */ void decaf_x448_generate_key ( uint8_t out[DECAF_X448_PUBLIC_BYTES], const uint8_t scalar[DECAF_X448_PRIVATE_BYTES] +) API_VIS NONNULL NOINLINE +__attribute__((deprecated( + "Renamed to decaf_x448_derive_public_key" +))); + +/** + * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses + * a different (non-Decaf) encoding. + * + * Does exactly the same thing as decaf_x448_generate_key, + * but has a better name. + * + * @param [out] scaled The scaled point base*scalar + * @param [in] scalar The scalar to multiply by. + */ +void decaf_x448_derive_public_key ( + uint8_t out[DECAF_X448_PUBLIC_BYTES], + const uint8_t scalar[DECAF_X448_PRIVATE_BYTES] ) API_VIS NONNULL NOINLINE; /* FUTURE: uint8_t decaf_448_encode_like_curve448) */ diff --git a/src/GENERATED/include/decaf/point_448.hxx b/src/GENERATED/include/decaf/point_448.hxx index 64e0346..b8605ac 100644 --- a/src/GENERATED/include/decaf/point_448.hxx +++ b/src/GENERATED/include/decaf/point_448.hxx @@ -645,7 +645,7 @@ public: return FixedBlock(decaf_x448_base_point); } - /** Generate and return a shared secret with public key. */ + /** Calculate and return a shared secret with public key. */ static inline SecureBuffer shared_secret( const FixedBlock &pk, const FixedBlock &scalar @@ -657,7 +657,7 @@ public: return out; } - /** Generate and return a shared secret with public key, noexcept version. */ + /** Calculate and write into out a shared secret with public key, noexcept version. */ static inline decaf_error_t WARN_UNUSED shared_secret_noexcept ( FixedBuffer &out, @@ -667,26 +667,55 @@ public: return decaf_x448(out.data(), pk.data(), scalar.data()); } - /** Generate and return a public key; equivalent to shared_secret(base_point(),scalar) + /** Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) * but possibly faster. + * @deprecated Renamed to derive_public_key. */ - static inline SecureBuffer generate_key( + static inline SecureBuffer __attribute__((deprecated( + "Renamed to derive_public_key" + ))) generate_key( const FixedBlock &scalar ) throw(std::bad_alloc) { SecureBuffer out(PUBLIC_BYTES); - decaf_x448_generate_key(out.data(), scalar.data()); + decaf_x448_derive_public_key(out.data(), scalar.data()); return out; } - /** Generate and return a public key into a fixed buffer; + /** Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) + * but possibly faster. + */ + static inline SecureBuffer derive_public_key( + const FixedBlock &scalar + ) throw(std::bad_alloc) { + SecureBuffer out(PUBLIC_BYTES); + decaf_x448_derive_public_key(out.data(), scalar.data()); + return out; + } + + /** Calculate and return a public key into a fixed buffer; + * equivalent to shared_secret(base_point(),scalar) but possibly faster. + */ + static inline void + derive_public_key_noexcept ( + FixedBuffer &out, + const FixedBlock &scalar + ) NOEXCEPT { + decaf_x448_derive_public_key(out.data(), scalar.data()); + } + + /** Calculate and return a public key into a fixed buffer; * equivalent to shared_secret(base_point(),scalar) but possibly faster. + * @deprecated Renamed to derive_public_key_noexcept. */ static inline void + __attribute__((deprecated( + "Renamed to derive_public_key_noexcept" + ))) generate_key_noexcept ( FixedBuffer &out, const FixedBlock &scalar ) NOEXCEPT { - decaf_x448_generate_key(out.data(), scalar.data()); + decaf_x448_derive_public_key(out.data(), scalar.data()); } }; diff --git a/src/per_curve/decaf.tmpl.c b/src/per_curve/decaf.tmpl.c index 795e0d3..81d5be4 100644 --- a/src/per_curve/decaf.tmpl.c +++ b/src/per_curve/decaf.tmpl.c @@ -1313,6 +1313,13 @@ decaf_error_t decaf_x$(gf_shortname) ( void decaf_x$(gf_shortname)_generate_key ( uint8_t out[X_PUBLIC_BYTES], const uint8_t scalar[X_PRIVATE_BYTES] +) { + decaf_x$(gf_shortname)_derive_public_key(out,scalar); +} + +void decaf_x$(gf_shortname)_derive_public_key ( + uint8_t out[X_PUBLIC_BYTES], + const uint8_t scalar[X_PRIVATE_BYTES] ) { /* Scalar conditioning */ uint8_t scalar2[X_PRIVATE_BYTES]; diff --git a/src/per_curve/point.tmpl.h b/src/per_curve/point.tmpl.h index ed3b127..f060e20 100644 --- a/src/per_curve/point.tmpl.h +++ b/src/per_curve/point.tmpl.h @@ -389,12 +389,33 @@ extern const uint8_t decaf_x$(gf_shortname)_base_point[DECAF_X$(gf_shortname)_PU * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses * a different (non-Decaf) encoding. * + * @deprecated Renamed to decaf_x$(gf_shortname)_derive_public_key. + * I have no particular timeline for removing this name. + * * @param [out] scaled The scaled point base*scalar * @param [in] scalar The scalar to multiply by. */ void decaf_x$(gf_shortname)_generate_key ( uint8_t out[DECAF_X$(gf_shortname)_PUBLIC_BYTES], const uint8_t scalar[DECAF_X$(gf_shortname)_PRIVATE_BYTES] +) API_VIS NONNULL NOINLINE +__attribute__((deprecated( + "Renamed to decaf_x$(gf_shortname)_derive_public_key" +))); + +/** + * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses + * a different (non-Decaf) encoding. + * + * Does exactly the same thing as decaf_x$(gf_shortname)_generate_key, + * but has a better name. + * + * @param [out] scaled The scaled point base*scalar + * @param [in] scalar The scalar to multiply by. + */ +void decaf_x$(gf_shortname)_derive_public_key ( + uint8_t out[DECAF_X$(gf_shortname)_PUBLIC_BYTES], + const uint8_t scalar[DECAF_X$(gf_shortname)_PRIVATE_BYTES] ) API_VIS NONNULL NOINLINE; /* FUTURE: uint8_t $(c_ns)_encode_like_curve$(gf_shortname)) */ diff --git a/src/per_curve/point.tmpl.hxx b/src/per_curve/point.tmpl.hxx index a793d50..1a8b3a0 100644 --- a/src/per_curve/point.tmpl.hxx +++ b/src/per_curve/point.tmpl.hxx @@ -632,7 +632,7 @@ public: return FixedBlock(decaf_x$(gf_shortname)_base_point); } - /** Generate and return a shared secret with public key. */ + /** Calculate and return a shared secret with public key. */ static inline SecureBuffer shared_secret( const FixedBlock &pk, const FixedBlock &scalar @@ -644,7 +644,7 @@ public: return out; } - /** Generate and return a shared secret with public key, noexcept version. */ + /** Calculate and write into out a shared secret with public key, noexcept version. */ static inline decaf_error_t WARN_UNUSED shared_secret_noexcept ( FixedBuffer &out, @@ -654,26 +654,55 @@ public: return decaf_x$(gf_shortname)(out.data(), pk.data(), scalar.data()); } - /** Generate and return a public key; equivalent to shared_secret(base_point(),scalar) + /** Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) * but possibly faster. + * @deprecated Renamed to derive_public_key. */ - static inline SecureBuffer generate_key( + static inline SecureBuffer __attribute__((deprecated( + "Renamed to derive_public_key" + ))) generate_key( const FixedBlock &scalar ) throw(std::bad_alloc) { SecureBuffer out(PUBLIC_BYTES); - decaf_x$(gf_shortname)_generate_key(out.data(), scalar.data()); + decaf_x$(gf_shortname)_derive_public_key(out.data(), scalar.data()); return out; } - /** Generate and return a public key into a fixed buffer; + /** Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) + * but possibly faster. + */ + static inline SecureBuffer derive_public_key( + const FixedBlock &scalar + ) throw(std::bad_alloc) { + SecureBuffer out(PUBLIC_BYTES); + decaf_x$(gf_shortname)_derive_public_key(out.data(), scalar.data()); + return out; + } + + /** Calculate and return a public key into a fixed buffer; + * equivalent to shared_secret(base_point(),scalar) but possibly faster. + */ + static inline void + derive_public_key_noexcept ( + FixedBuffer &out, + const FixedBlock &scalar + ) NOEXCEPT { + decaf_x$(gf_shortname)_derive_public_key(out.data(), scalar.data()); + } + + /** Calculate and return a public key into a fixed buffer; * equivalent to shared_secret(base_point(),scalar) but possibly faster. + * @deprecated Renamed to derive_public_key_noexcept. */ static inline void + __attribute__((deprecated( + "Renamed to derive_public_key_noexcept" + ))) generate_key_noexcept ( FixedBuffer &out, const FixedBlock &scalar ) NOEXCEPT { - decaf_x$(gf_shortname)_generate_key(out.data(), scalar.data()); + decaf_x$(gf_shortname)_derive_public_key(out.data(), scalar.data()); } }; diff --git a/test/bench_decaf.cxx b/test/bench_decaf.cxx index 14e7db5..8ae7508 100644 --- a/test/bench_decaf.cxx +++ b/test/bench_decaf.cxx @@ -301,7 +301,7 @@ static void cfrg() { SpongeRng rng(Block("bench_cfrg_crypto"),SpongeRng::DETERMINISTIC); FixedArrayBuffer base(rng); FixedArrayBuffer s1(rng); - for (Benchmark b("RFC 7748 keygen"); b.iter(); ) { Group::DhLadder::generate_key(s1); } + for (Benchmark b("RFC 7748 keygen"); b.iter(); ) { Group::DhLadder::derive_public_key(s1); } for (Benchmark b("RFC 7748 shared secret"); b.iter(); ) { Group::DhLadder::shared_secret(base,s1); } FixedArrayBuffer::PrivateKey::SER_BYTES> e1(rng); diff --git a/test/test_decaf.cxx b/test/test_decaf.cxx index 5b0f7ec..996c879 100644 --- a/test/test_decaf.cxx +++ b/test/test_decaf.cxx @@ -461,10 +461,10 @@ static void test_cfrg_crypto() { if (!memeq( DhLadder::shared_secret(DhLadder::base_point(),s1), - DhLadder::generate_key(s1) + DhLadder::derive_public_key(s1) )) { test.fail(); - printf(" Generated keys disagree on iteration %d.\n",i); + printf(" Public keys disagree on iteration %d.\n",i); } } }