scalarmult(): don't use the output as a temporary buffer

So that application can use the same pointer for the public key
and the shared secret.
This commit is contained in:
Frank Denis 2022-10-11 14:02:29 +02:00
parent e2bd402400
commit 2a2fe56189
2 changed files with 6 additions and 2 deletions

View File

@ -74,7 +74,7 @@ crypto_scalarmult_curve25519_ref10(unsigned char *q,
const unsigned char *n,
const unsigned char *p)
{
unsigned char *t = q;
unsigned char t[32];
unsigned int i;
fe25519 x1;
fe25519 x2;
@ -136,6 +136,8 @@ crypto_scalarmult_curve25519_ref10(unsigned char *q,
fe25519_mul(x2, x2, z2);
fe25519_tobytes(q, x2);
sodium_memzero(t, sizeof t);
return 0;
}

View File

@ -24,7 +24,7 @@ static int
crypto_scalarmult_curve25519_sandy2x(unsigned char *q, const unsigned char *n,
const unsigned char *p)
{
unsigned char *t = q;
unsigned char t[32];
fe var[3];
fe51 x_51;
fe51 z_51;
@ -57,6 +57,8 @@ crypto_scalarmult_curve25519_sandy2x(unsigned char *q, const unsigned char *n,
fe51_mul(&x_51, &x_51, &z_51);
fe51_pack(q, &x_51);
sodium_memzero(t, sizeof t);
return 0;
}