Add an argument to ed25519_small_order to optionally invert the sign

This commit is contained in:
Frank Denis
2017-10-20 16:07:52 +02:00
parent 30ad01bdba
commit 5a6deebd39
3 changed files with 8 additions and 6 deletions
@@ -16,6 +16,6 @@ int _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
const unsigned char *pk,
int prehashed);
int _crypto_sign_ed25519_small_order(const unsigned char p[32]);
int _crypto_sign_ed25519_small_order(const unsigned char p[32], unsigned char neg);
#endif
@@ -18,7 +18,7 @@ crypto_sign_ed25519_scalarmult(unsigned char *q, const unsigned char *n,
ge_p3 P;
ge_p3 pl;
if (_crypto_sign_ed25519_small_order(p) ||
if (_crypto_sign_ed25519_small_order(p, 1) ||
ge_frombytes_negate_vartime(&P, p) != 0) {
return -1;
}
@@ -83,7 +83,7 @@ crypto_sign_ed25519_pk_to_curve25519(unsigned char *curve25519_pk,
fe x;
fe one_minus_y;
if (_crypto_sign_ed25519_small_order(ed25519_pk) ||
if (_crypto_sign_ed25519_small_order(ed25519_pk, 1) ||
ge_frombytes_negate_vartime(&A, ed25519_pk) != 0) {
return -1;
}
@@ -34,7 +34,7 @@ crypto_sign_check_S_lt_L(const unsigned char *S)
}
int
_crypto_sign_ed25519_small_order(const unsigned char p[32])
_crypto_sign_ed25519_small_order(const unsigned char p[32], unsigned char neg)
{
CRYPTO_ALIGN(16)
static const unsigned char blacklist[][32] = {
@@ -94,11 +94,13 @@ _crypto_sign_ed25519_small_order(const unsigned char p[32])
size_t i, j;
unsigned char c;
neg <<= 7;
for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {
c = 0;
for (j = 0; j < 32; j++) {
for (j = 0; j < 31; j++) {
c |= p[j] ^ blacklist[i][j];
}
c |= p[j] ^ blacklist[i][j] ^ neg;
if (c == 0) {
return 1;
}
@@ -124,7 +126,7 @@ _crypto_sign_ed25519_verify_detached(const unsigned char *sig,
#ifndef ED25519_COMPAT
if (crypto_sign_check_S_lt_L(sig + 32) != 0 ||
_crypto_sign_ed25519_small_order(sig) != 0) {
_crypto_sign_ed25519_small_order(sig, 0) != 0) {
return -1;
}
#else