Hello, Attached is a patch that allows overwriting values (points and scalars) in the ECC API.
regards, Nikos
From 7e979007b4c79d7072ce265c92cc0548b8dabd6e Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos <[email protected]> Date: Tue, 12 Nov 2013 16:18:17 +0100 Subject: [PATCH] Added ecc_scalar_zeroize() and ecc_point_zeroize(). These two functions allow overwriting a value with zeros. Without those functions it was impossible to overwrite values with the exported API. --- ecc-point.c | 7 +++++++ ecc-scalar.c | 7 +++++++ ecc.h | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/ecc-point.c b/ecc-point.c index 3f356b9..3bded8a 100644 --- a/ecc-point.c +++ b/ecc-point.c @@ -28,6 +28,7 @@ #include "ecc.h" #include "ecc-internal.h" +#include <string.h> void ecc_point_init (struct ecc_point *p, const struct ecc_curve *ecc) @@ -42,6 +43,12 @@ ecc_point_clear (struct ecc_point *p) gmp_free_limbs (p->p, 2*p->ecc->size); } +void +ecc_point_zeroize (struct ecc_point *p) +{ + memset(p->p, 0, 2*p->ecc->size); +} + int ecc_point_set (struct ecc_point *p, const mpz_t x, const mpz_t y) { diff --git a/ecc-scalar.c b/ecc-scalar.c index 27d6571..ff08733 100644 --- a/ecc-scalar.c +++ b/ecc-scalar.c @@ -28,6 +28,7 @@ #include "ecc.h" #include "ecc-internal.h" +#include <string.h> void ecc_scalar_init (struct ecc_scalar *s, const struct ecc_curve *ecc) @@ -42,6 +43,12 @@ ecc_scalar_clear (struct ecc_scalar *s) gmp_free_limbs (s->p, s->ecc->size); } +void +ecc_scalar_zeroize (struct ecc_scalar *s) +{ + memset(s->p, 0, s->ecc->size*sizeof(mp_limb_t)); +} + int ecc_scalar_set (struct ecc_scalar *s, const mpz_t z) { diff --git a/ecc.h b/ecc.h index 609d246..c795140 100644 --- a/ecc.h +++ b/ecc.h @@ -36,12 +36,14 @@ extern "C" { /* Name mangling */ #define ecc_point_init nettle_ecc_point_init #define ecc_point_clear nettle_ecc_point_clear +#define ecc_point_zeroize nettle_ecc_point_zeroize #define ecc_point_set nettle_ecc_point_set #define ecc_point_get nettle_ecc_point_get #define ecc_point_mul nettle_ecc_point_mul #define ecc_point_mul_g nettle_ecc_point_mul_g #define ecc_scalar_init nettle_ecc_scalar_init #define ecc_scalar_clear nettle_ecc_scalar_clear +#define ecc_scalar_zeroize nettle_ecc_scalar_zeroize #define ecc_scalar_set nettle_ecc_scalar_set #define ecc_scalar_get nettle_ecc_scalar_get #define ecc_scalar_random nettle_ecc_scalar_random @@ -92,6 +94,8 @@ void ecc_point_init (struct ecc_point *p, const struct ecc_curve *ecc); void ecc_point_clear (struct ecc_point *p); +void +ecc_point_zeroize (struct ecc_point *p); /* Fails and returns zero if the point is not on the curve. */ int @@ -104,6 +108,9 @@ ecc_scalar_init (struct ecc_scalar *s, const struct ecc_curve *ecc); void ecc_scalar_clear (struct ecc_scalar *s); +void +ecc_scalar_zeroize (struct ecc_scalar *s); + /* Fails and returns zero if the scalar is not in the proper range. */ int ecc_scalar_set (struct ecc_scalar *s, const mpz_t z); -- 1.8.4.2
_______________________________________________ nettle-bugs mailing list [email protected] http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs
