Skip to content

Commit

Permalink
Merge pull request aws#36 from jargh/main
Browse files Browse the repository at this point in the history
Basic point operations for the Weierstrass curves
  • Loading branch information
jargh authored Jul 22, 2022
2 parents 82c3d61 + de11577 commit 44003b0
Show file tree
Hide file tree
Showing 86 changed files with 128,410 additions and 270 deletions.
14 changes: 13 additions & 1 deletion arm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ OBJ = curve25519/bignum_add_p25519.o \
p256/bignum_sub_p256.o \
p256/bignum_tomont_p256.o \
p256/bignum_triple_p256.o \
p256/p256_montjadd.o \
p256/p256_montjdouble.o \
p256/p256_montjmixadd.o \
p384/bignum_add_p384.o \
p384/bignum_bigendian_6.o \
p384/bignum_cmul_p384.o \
Expand All @@ -214,6 +217,9 @@ OBJ = curve25519/bignum_add_p25519.o \
p384/bignum_sub_p384.o \
p384/bignum_tomont_p384.o \
p384/bignum_triple_p384.o \
p384/p384_montjadd.o \
p384/p384_montjdouble.o \
p384/p384_montjmixadd.o \
p521/bignum_add_p521.o \
p521/bignum_cmul_p521.o \
p521/bignum_deamont_p521.o \
Expand All @@ -237,6 +243,9 @@ OBJ = curve25519/bignum_add_p25519.o \
p521/bignum_tolebytes_p521.o \
p521/bignum_tomont_p521.o \
p521/bignum_triple_p521.o \
p521/p521_jadd.o \
p521/p521_jdouble.o \
p521/p521_jmixadd.o \
secp256k1/bignum_add_p256k1.o \
secp256k1/bignum_cmul_p256k1.o \
secp256k1/bignum_deamont_p256k1.o \
Expand All @@ -257,7 +266,10 @@ OBJ = curve25519/bignum_add_p25519.o \
secp256k1/bignum_sqr_p256k1_alt.o \
secp256k1/bignum_sub_p256k1.o \
secp256k1/bignum_tomont_p256k1.o \
secp256k1/bignum_triple_p256k1.o
secp256k1/bignum_triple_p256k1.o \
secp256k1/secp256k1_jadd.o \
secp256k1/secp256k1_jdouble.o \
secp256k1/secp256k1_jmixadd.o

%.o : %.S ; cat $< | $(PREPROCESS) | $(SPLIT) | $(ASSEMBLE) -o $@ -

Expand Down
5 changes: 4 additions & 1 deletion arm/p256/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ OBJ = bignum_add_p256.o \
bignum_optneg_p256.o \
bignum_sub_p256.o \
bignum_tomont_p256.o \
bignum_triple_p256.o
bignum_triple_p256.o \
p256_montjadd.o \
p256_montjdouble.o \
p256_montjmixadd.o

%.o : %.S ; $(CC) -E -I../../include $< | $(GAS) -o $@ -

Expand Down
9 changes: 3 additions & 6 deletions arm/p256/bignum_add_p256.S
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ S2N_BN_SYMBOL(bignum_add_p256):

// Now compare [d3; d2; d1; d0] with p_256

mov l, #0xffffffffffffffff
subs xzr, d0, l
subs xzr, d0, #0xffffffffffffffff
mov l, #0x00000000ffffffff
sbcs xzr, d1, l
sbcs xzr, d2, xzr
Expand All @@ -73,12 +72,10 @@ S2N_BN_SYMBOL(bignum_add_p256):
// Now correct by subtracting masked p_256

subs d0, d0, c
mov l, #0x00000000ffffffff
and l, l, c
and l, c, #0x00000000ffffffff
sbcs d1, d1, l
sbcs d2, d2, xzr
mov l, #0xffffffff00000001
and l, l, c
and l, c, #0xffffffff00000001
sbc d3, d3, l

// Store the result
Expand Down
12 changes: 8 additions & 4 deletions arm/p256/bignum_montsqr_p256_alt.S
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@
adds d1, d1, d0, lsl #32; \
lsr t1, d0, #32; \
adcs d2, d2, t1; \
mov t1, #0xFFFFFFFF00000001; \
mul t0, d0, t1; \
umulh d4, d0, t1; \
mul t0, d0, mc; \
umulh d4, d0, mc; \
adcs d3, d3, t0; \
adc d4, d4, xzr

Expand All @@ -73,6 +72,10 @@

#define u7 h

// This one is the same as a3, and is used for the Montgomery constant 0xFFFFFFFF00000001

#define mc x5

S2N_BN_SYMBOL(bignum_montsqr_p256_alt):

// Load all the elements, set up an initial window [u6;...u1] = [23;03;01]
Expand Down Expand Up @@ -144,6 +147,7 @@ S2N_BN_SYMBOL(bignum_montsqr_p256_alt):

// Squaring complete. Perform 4 Montgomery steps to rotate the lower half

mov mc, #0xFFFFFFFF00000001
montreds(u0,u3,u2,u1,u0, a1,a0)
montreds(u1,u0,u3,u2,u1, a1,a0)
montreds(u2,u1,u0,u3,u2, a1,a0)
Expand All @@ -158,9 +162,9 @@ S2N_BN_SYMBOL(bignum_montsqr_p256_alt):
cset a0, cs

// Set [a3;0;a1;-1] = p_256 and form [u7,u6,u5,u4] = [a0;u3;u2;u1;u0] - p_256
// Note that a3 == mc was already set above

mov a1, #0x00000000ffffffff
mov a3, #0xffffffff00000001

subs u4, u0, #-1
sbcs u5, u1, a1
Expand Down
6 changes: 2 additions & 4 deletions arm/p256/bignum_sub_p256.S
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ S2N_BN_SYMBOL(bignum_sub_p256):
// Now correct by adding masked p_256

adds d0, d0, c
mov l, #0x00000000ffffffff
and l, l, c
and l, c, #0x00000000ffffffff
adcs d1, d1, l
adcs d2, d2, xzr
mov l, #0xffffffff00000001
and l, l, c
and l, c, #0xffffffff00000001
adc d3, d3, l

// Store the result
Expand Down
Loading

0 comments on commit 44003b0

Please sign in to comment.