1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

Leverage p3_add()/p3_sub()

This commit is contained in:
Frank Denis 2022-11-26 22:20:37 +01:00
parent d2d8f573b7
commit f29f58e6ed
3 changed files with 5 additions and 25 deletions

View File

@ -30,16 +30,12 @@ crypto_core_ed25519_add(unsigned char *r,
const unsigned char *p, const unsigned char *q)
{
ge25519_p3 p_p3, q_p3, r_p3;
ge25519_p1p1 r_p1p1;
ge25519_cached q_cached;
if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 ||
ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) {
return -1;
}
ge25519_p3_to_cached(&q_cached, &q_p3);
ge25519_add_cached(&r_p1p1, &p_p3, &q_cached);
ge25519_p1p1_to_p3(&r_p3, &r_p1p1);
ge25519_p3_add(&r_p3, &p_p3, &q_p3);
ge25519_p3_tobytes(r, &r_p3);
return 0;
@ -50,16 +46,12 @@ crypto_core_ed25519_sub(unsigned char *r,
const unsigned char *p, const unsigned char *q)
{
ge25519_p3 p_p3, q_p3, r_p3;
ge25519_p1p1 r_p1p1;
ge25519_cached q_cached;
if (ge25519_frombytes(&p_p3, p) != 0 || ge25519_is_on_curve(&p_p3) == 0 ||
ge25519_frombytes(&q_p3, q) != 0 || ge25519_is_on_curve(&q_p3) == 0) {
return -1;
}
ge25519_p3_to_cached(&q_cached, &q_p3);
ge25519_sub_cached(&r_p1p1, &p_p3, &q_cached);
ge25519_p1p1_to_p3(&r_p3, &r_p1p1);
ge25519_p3_sub(&r_p3, &p_p3, &q_p3);
ge25519_p3_tobytes(r, &r_p3);
return 0;

View File

@ -28,16 +28,12 @@ crypto_core_ristretto255_add(unsigned char *r,
const unsigned char *p, const unsigned char *q)
{
ge25519_p3 p_p3, q_p3, r_p3;
ge25519_p1p1 r_p1p1;
ge25519_cached q_cached;
if (ristretto255_frombytes(&p_p3, p) != 0 ||
ristretto255_frombytes(&q_p3, q) != 0) {
return -1;
}
ge25519_p3_to_cached(&q_cached, &q_p3);
ge25519_add_cached(&r_p1p1, &p_p3, &q_cached);
ge25519_p1p1_to_p3(&r_p3, &r_p1p1);
ge25519_p3_add(&r_p3, &p_p3, &q_p3);
ristretto255_p3_tobytes(r, &r_p3);
return 0;
@ -48,16 +44,12 @@ crypto_core_ristretto255_sub(unsigned char *r,
const unsigned char *p, const unsigned char *q)
{
ge25519_p3 p_p3, q_p3, r_p3;
ge25519_p1p1 r_p1p1;
ge25519_cached q_cached;
if (ristretto255_frombytes(&p_p3, p) != 0 ||
ristretto255_frombytes(&q_p3, q) != 0) {
return -1;
}
ge25519_p3_to_cached(&q_cached, &q_p3);
ge25519_sub_cached(&r_p1p1, &p_p3, &q_cached);
ge25519_p1p1_to_p3(&r_p3, &r_p1p1);
ge25519_p3_sub(&r_p3, &p_p3, &q_p3);
ristretto255_p3_tobytes(r, &r_p3);
return 0;

View File

@ -2995,8 +2995,6 @@ void
ristretto255_from_hash(unsigned char s[32], const unsigned char h[64])
{
fe25519 r0, r1;
ge25519_cached p1_cached;
ge25519_p1p1 p_p1p1;
ge25519_p3 p0, p1;
ge25519_p3 p;
@ -3004,8 +3002,6 @@ ristretto255_from_hash(unsigned char s[32], const unsigned char h[64])
fe25519_frombytes(r1, h + 32);
ristretto255_elligator(&p0, r0);
ristretto255_elligator(&p1, r1);
ge25519_p3_to_cached(&p1_cached, &p1);
ge25519_add_cached(&p_p1p1, &p0, &p1_cached);
ge25519_p1p1_to_p3(&p, &p_p1p1);
ge25519_p3_add(&p, &p0, &p1);
ristretto255_p3_tobytes(s, &p);
}