diff --git a/ChangeLog b/ChangeLog index 8dd78c91d227fd950eabd3bc0efccf3922f155f3..9a407deb0faf9e812a41d25f55a5054269993244 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2017-04-09 Niels Möller <nisse@lysator.liu.se> + * ecc-curve.h (nettle_get_secp_192r1, nettle_get_secp_224r1) + (nettle_get_secp_256r1, nettle_get_secp_384r1) + (nettle_get_secp_521r1): New functions, returning a pointer to + corresponding structure. + (nettle_secp_192r1, nettle_secp_224r1, nettle_secp_256r1) + (nettle_secp_384r1, nettle_secp_521r1): Redefined as macros, + calling the corresponding function. + * nettle-meta.h (nettle_ciphers, nettle_aeads, nettle_armors): New macros, analogous to below change to nettle_hashes. diff --git a/ecc-192.c b/ecc-192.c index 5c52b043f66d905e8ee348c97ecc884622f99cc8..4f428113674e246e22d7ad67d32d5b114983a656 100644 --- a/ecc-192.c +++ b/ecc-192.c @@ -110,7 +110,7 @@ ecc_192_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp) #define ecc_192_modp ecc_mod #endif -const struct ecc_curve nettle_secp_192r1 = +const struct ecc_curve _nettle_secp_192r1 = { { 192, @@ -172,3 +172,7 @@ const struct ecc_curve nettle_secp_192r1 = ecc_table }; +const struct ecc_curve *nettle_get_secp_192r1(void) +{ + return &_nettle_secp_192r1; +} diff --git a/ecc-224.c b/ecc-224.c index cdb4219726e4b81e881cf6c27ad0a3971e521994..5962e1b863bfd1e4e7bf1a723943c513a2c56b43 100644 --- a/ecc-224.c +++ b/ecc-224.c @@ -62,7 +62,7 @@ ecc_224_modp (const struct ecc_modulo *m, mp_limb_t *rp); # error Configuration error #endif -const struct ecc_curve nettle_secp_224r1 = +const struct ecc_curve _nettle_secp_224r1 = { { 224, @@ -123,3 +123,8 @@ const struct ecc_curve nettle_secp_224r1 = ecc_unit, ecc_table }; + +const struct ecc_curve *nettle_get_secp_224r1(void) +{ + return &_nettle_secp_224r1; +} diff --git a/ecc-256.c b/ecc-256.c index e757985c2e1e82d08526446f0e0cfd272528d71c..7eed2835c08a0719ce6c6f5e6ff016f8d43e3eb2 100644 --- a/ecc-256.c +++ b/ecc-256.c @@ -239,7 +239,7 @@ ecc_256_modq (const struct ecc_modulo *q, mp_limb_t *rp) #error Unsupported parameters #endif -const struct ecc_curve nettle_secp_256r1 = +const struct ecc_curve _nettle_secp_256r1 = { { 256, @@ -300,3 +300,8 @@ const struct ecc_curve nettle_secp_256r1 = ecc_unit, ecc_table }; + +const struct ecc_curve *nettle_get_secp_256r1(void) +{ + return &_nettle_secp_256r1; +} diff --git a/ecc-384.c b/ecc-384.c index a393c61f87b817ad5512312973d5304f855663a0..94b8af91354e767b7a7232d955218226f9588730 100644 --- a/ecc-384.c +++ b/ecc-384.c @@ -147,7 +147,7 @@ ecc_384_modp (const struct ecc_modulo *p, mp_limb_t *rp) #define ecc_384_modp ecc_mod #endif -const struct ecc_curve nettle_secp_384r1 = +const struct ecc_curve _nettle_secp_384r1 = { { 384, @@ -208,3 +208,8 @@ const struct ecc_curve nettle_secp_384r1 = ecc_unit, ecc_table }; + +const struct ecc_curve *nettle_get_secp_384r1(void) +{ + return &_nettle_secp_384r1; +} diff --git a/ecc-521.c b/ecc-521.c index 1a08f2096c1e3ef50a75778c8a7e48ac1f90f99a..52a018dd7c9c0124c90dc1cbd389e79cd47e1c11 100644 --- a/ecc-521.c +++ b/ecc-521.c @@ -75,7 +75,7 @@ ecc_521_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp) } #endif -const struct ecc_curve nettle_secp_521r1 = +const struct ecc_curve _nettle_secp_521r1 = { { 521, @@ -137,3 +137,7 @@ const struct ecc_curve nettle_secp_521r1 = ecc_table }; +const struct ecc_curve *nettle_get_secp_521r1(void) +{ + return &_nettle_secp_521r1; +} diff --git a/ecc-curve.h b/ecc-curve.h index 574c9f2e00e13b5ecd3b6abb173c0f3e2202d9d8..f3fd63e4ddc3d160095213e2b54fe0fc696b4c15 100644 --- a/ecc-curve.h +++ b/ecc-curve.h @@ -41,11 +41,26 @@ extern "C" { /* The contents of this struct is internal. */ struct ecc_curve; -extern const struct ecc_curve nettle_secp_192r1; -extern const struct ecc_curve nettle_secp_224r1; -extern const struct ecc_curve nettle_secp_256r1; -extern const struct ecc_curve nettle_secp_384r1; -extern const struct ecc_curve nettle_secp_521r1; +#ifdef __GNUC__ +#define NETTLE_PURE __attribute__((pure)) +#else +#define NETTLE_PURE +#endif + +const struct ecc_curve * NETTLE_PURE nettle_get_secp_192r1(void); +const struct ecc_curve * NETTLE_PURE nettle_get_secp_224r1(void); +const struct ecc_curve * NETTLE_PURE nettle_get_secp_256r1(void); +const struct ecc_curve * NETTLE_PURE nettle_get_secp_384r1(void); +const struct ecc_curve * NETTLE_PURE nettle_get_secp_521r1(void); + +#undef NETTLE_PURE + +/* For backwards compatibility */ +#define nettle_secp_192r1 (*nettle_get_secp_192r1()) +#define nettle_secp_224r1 (*nettle_get_secp_224r1()) +#define nettle_secp_256r1 (*nettle_get_secp_256r1()) +#define nettle_secp_384r1 (*nettle_get_secp_384r1()) +#define nettle_secp_521r1 (*nettle_get_secp_521r1()) #ifdef __cplusplus } diff --git a/ecc-internal.h b/ecc-internal.h index ce1e34fb2117bc861272ab5159dd101cc20d6c0f..94fc218b18092c147ea95b3b986ef1166985cf01 100644 --- a/ecc-internal.h +++ b/ecc-internal.h @@ -73,6 +73,12 @@ #define sec_modinv _nettle_sec_modinv #define curve25519_eh_to_x _nettle_curve25519_eh_to_x +extern const struct ecc_curve _nettle_secp_192r1; +extern const struct ecc_curve _nettle_secp_224r1; +extern const struct ecc_curve _nettle_secp_256r1; +extern const struct ecc_curve _nettle_secp_384r1; +extern const struct ecc_curve _nettle_secp_521r1; + /* Keep this structure internal for now. It's misnamed (since it's really implementing the equivalent twisted Edwards curve, with different coordinates). And we're not quite ready to provide diff --git a/examples/ecc-benchmark.c b/examples/ecc-benchmark.c index 8e5e0953af3f905b834bad2a6c4748d0aaa509b2..ea0be17368fbc48304d6b1cf0bcc26694e848a7f 100644 --- a/examples/ecc-benchmark.c +++ b/examples/ecc-benchmark.c @@ -330,12 +330,12 @@ bench_curve (const struct ecc_curve *ecc) } const struct ecc_curve * const curves[] = { - &nettle_secp_192r1, - &nettle_secp_224r1, + &_nettle_secp_192r1, + &_nettle_secp_224r1, &_nettle_curve25519, - &nettle_secp_256r1, - &nettle_secp_384r1, - &nettle_secp_521r1, + &_nettle_secp_256r1, + &_nettle_secp_384r1, + &_nettle_secp_521r1, }; #define numberof(x) (sizeof (x) / sizeof ((x)[0])) diff --git a/testsuite/testutils.c b/testsuite/testutils.c index 6f897617cadbd23077a5adbeac91d73c671140e5..7a23a46d3eb7bfd21c0d565db848bf0b07448ae1 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -1212,11 +1212,11 @@ test_dsa_key(const struct dsa_params *params, } const struct ecc_curve * const ecc_curves[] = { - &nettle_secp_192r1, - &nettle_secp_224r1, - &nettle_secp_256r1, - &nettle_secp_384r1, - &nettle_secp_521r1, + &_nettle_secp_192r1, + &_nettle_secp_224r1, + &_nettle_secp_256r1, + &_nettle_secp_384r1, + &_nettle_secp_521r1, &_nettle_curve25519, NULL };