Use the same key sanitization as Curve25519

This commit is contained in:
Matthias Schiffer 2012-03-28 22:57:16 +02:00
parent f1d5eb1da9
commit f67c3f36b9

View file

@ -176,12 +176,13 @@ void ecc_25519_secret_mult(ecc_secret_key_256 *out, const ecc_secret_key_256 *in
montgomery(out->s, R, C); montgomery(out->s, R, C);
} }
/* TODO implement properly, rule out zero etc. */
void ecc_25519_secret_sanitize(ecc_secret_key_256 *out, const ecc_secret_key_256 *in) { void ecc_25519_secret_sanitize(ecc_secret_key_256 *out, const ecc_secret_key_256 *in) {
int i; int i;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
out->s[i] = in->s[i]; out->s[i] = in->s[i];
out->s[31] |= 0x80; out->s[0] &= 0xf8;
out->s[31] &= 0x7f;
out->s[31] |= 0x40;
} }