Commit b84dff15 authored by Niels Möller's avatar Niels Möller

Define accessor functions to get address of ecc curve structs.

parent 0143b03d
2017-04-09 Niels Möller <nisse@lysator.liu.se> 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 * nettle-meta.h (nettle_ciphers, nettle_aeads, nettle_armors): New
macros, analogous to below change to nettle_hashes. macros, analogous to below change to nettle_hashes.
......
...@@ -110,7 +110,7 @@ ecc_192_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp) ...@@ -110,7 +110,7 @@ ecc_192_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp)
#define ecc_192_modp ecc_mod #define ecc_192_modp ecc_mod
#endif #endif
const struct ecc_curve nettle_secp_192r1 = const struct ecc_curve _nettle_secp_192r1 =
{ {
{ {
192, 192,
...@@ -172,3 +172,7 @@ const struct ecc_curve nettle_secp_192r1 = ...@@ -172,3 +172,7 @@ const struct ecc_curve nettle_secp_192r1 =
ecc_table ecc_table
}; };
const struct ecc_curve *nettle_get_secp_192r1(void)
{
return &_nettle_secp_192r1;
}
...@@ -62,7 +62,7 @@ ecc_224_modp (const struct ecc_modulo *m, mp_limb_t *rp); ...@@ -62,7 +62,7 @@ ecc_224_modp (const struct ecc_modulo *m, mp_limb_t *rp);
# error Configuration error # error Configuration error
#endif #endif
const struct ecc_curve nettle_secp_224r1 = const struct ecc_curve _nettle_secp_224r1 =
{ {
{ {
224, 224,
...@@ -123,3 +123,8 @@ const struct ecc_curve nettle_secp_224r1 = ...@@ -123,3 +123,8 @@ const struct ecc_curve nettle_secp_224r1 =
ecc_unit, ecc_unit,
ecc_table ecc_table
}; };
const struct ecc_curve *nettle_get_secp_224r1(void)
{
return &_nettle_secp_224r1;
}
...@@ -239,7 +239,7 @@ ecc_256_modq (const struct ecc_modulo *q, mp_limb_t *rp) ...@@ -239,7 +239,7 @@ ecc_256_modq (const struct ecc_modulo *q, mp_limb_t *rp)
#error Unsupported parameters #error Unsupported parameters
#endif #endif
const struct ecc_curve nettle_secp_256r1 = const struct ecc_curve _nettle_secp_256r1 =
{ {
{ {
256, 256,
...@@ -300,3 +300,8 @@ const struct ecc_curve nettle_secp_256r1 = ...@@ -300,3 +300,8 @@ const struct ecc_curve nettle_secp_256r1 =
ecc_unit, ecc_unit,
ecc_table ecc_table
}; };
const struct ecc_curve *nettle_get_secp_256r1(void)
{
return &_nettle_secp_256r1;
}
...@@ -147,7 +147,7 @@ ecc_384_modp (const struct ecc_modulo *p, mp_limb_t *rp) ...@@ -147,7 +147,7 @@ ecc_384_modp (const struct ecc_modulo *p, mp_limb_t *rp)
#define ecc_384_modp ecc_mod #define ecc_384_modp ecc_mod
#endif #endif
const struct ecc_curve nettle_secp_384r1 = const struct ecc_curve _nettle_secp_384r1 =
{ {
{ {
384, 384,
...@@ -208,3 +208,8 @@ const struct ecc_curve nettle_secp_384r1 = ...@@ -208,3 +208,8 @@ const struct ecc_curve nettle_secp_384r1 =
ecc_unit, ecc_unit,
ecc_table ecc_table
}; };
const struct ecc_curve *nettle_get_secp_384r1(void)
{
return &_nettle_secp_384r1;
}
...@@ -75,7 +75,7 @@ ecc_521_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp) ...@@ -75,7 +75,7 @@ ecc_521_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp)
} }
#endif #endif
const struct ecc_curve nettle_secp_521r1 = const struct ecc_curve _nettle_secp_521r1 =
{ {
{ {
521, 521,
...@@ -137,3 +137,7 @@ const struct ecc_curve nettle_secp_521r1 = ...@@ -137,3 +137,7 @@ const struct ecc_curve nettle_secp_521r1 =
ecc_table ecc_table
}; };
const struct ecc_curve *nettle_get_secp_521r1(void)
{
return &_nettle_secp_521r1;
}
...@@ -41,11 +41,26 @@ extern "C" { ...@@ -41,11 +41,26 @@ extern "C" {
/* The contents of this struct is internal. */ /* The contents of this struct is internal. */
struct ecc_curve; struct ecc_curve;
extern const struct ecc_curve nettle_secp_192r1; #ifdef __GNUC__
extern const struct ecc_curve nettle_secp_224r1; #define NETTLE_PURE __attribute__((pure))
extern const struct ecc_curve nettle_secp_256r1; #else
extern const struct ecc_curve nettle_secp_384r1; #define NETTLE_PURE
extern const struct ecc_curve nettle_secp_521r1; #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 #ifdef __cplusplus
} }
......
...@@ -73,6 +73,12 @@ ...@@ -73,6 +73,12 @@
#define sec_modinv _nettle_sec_modinv #define sec_modinv _nettle_sec_modinv
#define curve25519_eh_to_x _nettle_curve25519_eh_to_x #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 /* Keep this structure internal for now. It's misnamed (since it's
really implementing the equivalent twisted Edwards curve, with really implementing the equivalent twisted Edwards curve, with
different coordinates). And we're not quite ready to provide different coordinates). And we're not quite ready to provide
......
...@@ -330,12 +330,12 @@ bench_curve (const struct ecc_curve *ecc) ...@@ -330,12 +330,12 @@ bench_curve (const struct ecc_curve *ecc)
} }
const struct ecc_curve * const curves[] = { const struct ecc_curve * const curves[] = {
&nettle_secp_192r1, &_nettle_secp_192r1,
&nettle_secp_224r1, &_nettle_secp_224r1,
&_nettle_curve25519, &_nettle_curve25519,
&nettle_secp_256r1, &_nettle_secp_256r1,
&nettle_secp_384r1, &_nettle_secp_384r1,
&nettle_secp_521r1, &_nettle_secp_521r1,
}; };
#define numberof(x) (sizeof (x) / sizeof ((x)[0])) #define numberof(x) (sizeof (x) / sizeof ((x)[0]))
......
...@@ -1212,11 +1212,11 @@ test_dsa_key(const struct dsa_params *params, ...@@ -1212,11 +1212,11 @@ test_dsa_key(const struct dsa_params *params,
} }
const struct ecc_curve * const ecc_curves[] = { const struct ecc_curve * const ecc_curves[] = {
&nettle_secp_192r1, &_nettle_secp_192r1,
&nettle_secp_224r1, &_nettle_secp_224r1,
&nettle_secp_256r1, &_nettle_secp_256r1,
&nettle_secp_384r1, &_nettle_secp_384r1,
&nettle_secp_521r1, &_nettle_secp_521r1,
&_nettle_curve25519, &_nettle_curve25519,
NULL NULL
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment