Skip to content

Commit

Permalink
Merge pull request #196 from hannesm/ed25519
Browse files Browse the repository at this point in the history
improvements for 25519
  • Loading branch information
hannesm authored Feb 23, 2024
2 parents bcfa05d + 4e8790d commit 27cb3ec
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions ec/native/curve25519_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <assert.h>
typedef WORD fe_limb_t;

/* following code is from c47bfce06 of boringssl (crypto/curve25519)
internal.h curve25519.c */
/* following code is from c47bfce06 and 0fc57bef18 of boringssl
(crypto/curve25519) internal.h curve25519.c */

/* Copyright (c) 2020, Google Inc.
*
Expand Down Expand Up @@ -500,27 +500,21 @@ static void ge_p3_tobytes(uint8_t s[32], const ge_p3 *h) {
static int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32]) {
fe u;
fe_loose v;
fe v3;
fe w;
fe vxx;
fe_loose check;

fe_frombytes(&h->Y, s);
fe_1(&h->Z);
fe_sq_tt(&v3, &h->Y);
fe_mul_ttt(&vxx, &v3, &d);
fe_sub(&v, &v3, &h->Z); // u = y^2-1
fe_sq_tt(&w, &h->Y);
fe_mul_ttt(&vxx, &w, &d);
fe_sub(&v, &w, &h->Z); // u = y^2-1
fe_carry(&u, &v);
fe_add(&v, &vxx, &h->Z); // v = dy^2+1

fe_sq_tl(&v3, &v);
fe_mul_ttl(&v3, &v3, &v); // v3 = v^3
fe_sq_tt(&h->X, &v3);
fe_mul_ttl(&h->X, &h->X, &v);
fe_mul_ttt(&h->X, &h->X, &u); // x = uv^7

fe_pow22523(&h->X, &h->X); // x = (uv^7)^((q-5)/8)
fe_mul_ttt(&h->X, &h->X, &v3);
fe_mul_ttt(&h->X, &h->X, &u); // x = uv^3(uv^7)^((q-5)/8)
fe_mul_ttl(&w, &u, &v); // w = u*v
fe_pow22523(&h->X, &w); // x = w^((q-5)/8)
fe_mul_ttt(&h->X, &h->X, &u); // x = u*w^((q-5)/8)

fe_sq_tt(&vxx, &h->X);
fe_mul_ttl(&vxx, &vxx, &v);
Expand Down

0 comments on commit 27cb3ec

Please sign in to comment.