Skip to content

Commit

Permalink
Merge pull request #94 from formosa-crypto/feature/curve25519
Browse files Browse the repository at this point in the history
curve25519: mulx .s size ++ refactor to isolate loads
  • Loading branch information
tfaoliveira authored Oct 12, 2023
2 parents 69fa7e0 + c8f796a commit e428b8f
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 275 deletions.
53 changes: 53 additions & 0 deletions src/crypto_scalarmult/curve25519/amd64/common/51/decode_u5.jinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
inline fn __decode_u_coordinate5(reg u64[4] t) -> reg u64[5]
{
reg u64[5] u;
reg u64 mask;

mask = 0x7ffffffffffff;

//u[0] = t[0] & mask; // 51; 13 left
u[0] = t[0];
u[0] &= mask;

//u[1] = (t[1] << 13) || (t[0] >> 51) & mask; // 38; 26 left
u[1] = t[1];
u[1] <<= 13;
t[0] >>= 51;
u[1] |= t[0];
u[1] &= mask;

//u[2] = (t[2] << 26) || (t[1] >> 38) & mask; // 25; 39 left
u[2] = t[2];
u[2] <<= 26;
t[1] >>= 38;
u[2] |= t[1];
u[2] &= mask;

//u[3] = (t[3] << 39) || (t[2] >> 25) & mask; // 12; '52' left
u[3] = t[3];
u[3] <<= 39;
t[2] >>= 25;
u[3] |= t[2];
u[3] &= mask;

//u[4] = (t[3] >> 12) & mask;
u[4] = t[3];
u[4] >>= 12;
u[4] &= mask;

return u;
}

inline fn __decode_u_coordinate_base5() -> reg u64[5]
{
reg u64[5] u;

u[0] = 9;
u[1] = 0;
u[2] = 0;
u[3] = 0;
u[4] = 0;

return u;
}

56 changes: 56 additions & 0 deletions src/crypto_scalarmult/curve25519/amd64/common/51/init_points5.jinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
inline fn __init_points5(
reg u64[5] initr)
->
stack u64[5],
reg u64[5],
stack u64[5],
stack u64[5]
{
inline int i;
stack u64[5] x2 x3 z3;
reg u64[5] z2r;
reg u64 z;

?{}, z = #set0();

x2[0] = 1;
z2r[0] = 0;
x3 = #copy(initr);
z3[0] = 1;

for i=1 to 5
{ x2[i] = z;
z2r[i] = z;
z3[i] = z;
}

// (1, 0, init, 1)
return x2, z2r, x3, z3;
}

inline fn __init_points5_x3()
->
stack u64[5],
reg u64[5],
stack u64[5]
{
inline int i;
stack u64[5] f1s f3s;
reg u64[5] f2;
reg u64 z;

?{}, z = #set0();

f1s[0] = 1;
f2[0] = 1;
f3s[0] = 1;

for i=1 to 5
{ f1s[i] = z;
f2[i] = z;
f3s[i] = z;
}

return f1s, f2, f3s;
}

113 changes: 0 additions & 113 deletions src/crypto_scalarmult/curve25519/amd64/common/51/load5.jinc

This file was deleted.

18 changes: 18 additions & 0 deletions src/crypto_scalarmult/curve25519/amd64/common/64/decode_u4.jinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
inline fn __decode_u_coordinate4(reg u64[4] u) -> reg u64[4]
{
u[3] &= 0x7fffffffffffffff;
return u;
}

inline fn __decode_u_coordinate_base4() -> reg u64[4]
{
reg u64[4] u;

u[0] = 9;
u[1] = 0;
u[2] = 0;
u[3] = 0;

return u;
}

Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
inline fn __decode_u_coordinate4(reg u64 up) -> reg u64[4]
{
inline int i;
reg u64[4] u;

for i=0 to 4
{ u[i] = [up + 8*i]; }
u[3] &= 0x7fffffffffffffff;

return u;
}

inline fn __decode_u_coordinate_base4() -> reg u64[4]
{
reg u64[4] u;

u[0] = 9;
u[1] = 0;
u[2] = 0;
u[3] = 0;

return u;
}

inline fn __init_points4(
reg u64[4] initr)
->
Expand Down
34 changes: 0 additions & 34 deletions src/crypto_scalarmult/curve25519/amd64/common/decode.jinc

This file was deleted.

28 changes: 28 additions & 0 deletions src/crypto_scalarmult/curve25519/amd64/common/decode_scalar.jinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
inline fn __decode_scalar(reg u64[4] k) -> stack u8[32]
{
inline int i;
stack u8[32] ks;

for i=0 to 4
{ ks[u64 i] = k[i]; }

ks[0] &= 0xf8;
ks[31] &= 0x7f;
ks[31] |= 0x40;

return ks;
}

inline fn __decode_scalar_shl1(reg u64[4] k) -> stack u64[4]
{
stack u64[4] ks;

k[3] <<= 1;
k[0] &= 0xfffffffffffffff8;
k[3] |= 0x8000000000000000;

ks = #copy(k);

return ks;
}

19 changes: 19 additions & 0 deletions src/crypto_scalarmult/curve25519/amd64/common/load_store4.jinc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
inline fn __load4(reg u64 p) -> reg u64[4]
{
inline int i;
reg u64[4] a;

for i=0 to 4
{ a[i] = [p + 8*i]; }

return a;
}

inline fn __store4(reg u64 p, reg u64[4] a)
{
inline int i;

for i=0 to 4
{ [p + 8*i] = a[i]; }
}

Loading

0 comments on commit e428b8f

Please sign in to comment.