set rng when making a curve25519 key and cast type after shift

pull/8736/head
JacobBarthelmeh 2025-05-07 11:45:55 -06:00
parent aa840f9c94
commit cbc4cba263
1 changed files with 5 additions and 2 deletions

View File

@ -212,11 +212,11 @@ static int curve25519_smul_blind(byte* rp, const byte* n, const byte* p,
return ret;
a[CURVE25519_KEYSIZE-1] &= 0x7f;
/* k' = k ^ 2k ^ a */
n_a[0] = n[0] ^ (n[0] << 1) ^ a[0];
n_a[0] = n[0] ^ (byte)(n[0] << 1) ^ a[0];
for (i = 1; i < CURVE25519_KEYSIZE; i++) {
byte b1, b2, b3;
b1 = n[i] ^ a[i];
b2 = (n[i] << 1) ^ a[i];
b2 = (byte)(n[i] << 1) ^ a[i];
b3 = (n[i-1] >> 7) ^ a[i];
n_a[i] = b1 ^ b2 ^ b3;
}
@ -422,6 +422,9 @@ int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key)
ret = wc_curve25519_make_pub_blind((int)sizeof(key->p.point),
key->p.point, (int)sizeof(key->k),
key->k, rng);
if (ret == 0) {
ret = wc_curve25519_set_rng(key, rng);
}
#else
ret = wc_curve25519_make_pub((int)sizeof(key->p.point), key->p.point,
(int)sizeof(key->k), key->k);