Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS-LC s2n-bignum update 2024-07-22 #1718

Merged
merged 52 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
11b105a
Add bignum_copy_row_from_table and its Neon-variants for AArch64
aqjune-aws Aug 28, 2023
0b39dc3
Merge pull request #81 from aqjune-aws/tablelookup
jargh Sep 16, 2023
a45a78f
Merge branch 'awslabs:main' into main
jargh Sep 16, 2023
bb3baa5
Add Ed25519 point compression encoding
jargh Oct 5, 2023
342a2ba
Merge branch 'awslabs:main' into main
jargh Oct 11, 2023
755bc0b
Add Ed25519 point decoding function
jargh Oct 14, 2023
d9d1d38
Add generic size curve25519/edwards25519 basepoint modulus
jargh Oct 18, 2023
1549707
Merge branch 'awslabs:main' into main
jargh Oct 20, 2023
ee9dd97
Switch curve25519 operations to divstep-based modular inverse
jargh Oct 28, 2023
f5d2c1f
Merge pull request #88 from torben-hansen/document_x25519_zero_check_no
jargh Nov 1, 2023
0698b40
Merge branch 'awslabs:main' into main
jargh Nov 1, 2023
8fd6e1a
Switch edwards25519 operations to divstep-based modular inverse
jargh Nov 2, 2023
f1227a0
Merge pull request #87 from jargh/main
jargh Nov 3, 2023
1b9b66a
Merge branch 'awslabs:main' into main
jargh Nov 4, 2023
51ffa10
Merge pull request #90 from jargh/main
jargh Nov 6, 2023
b5e5b8c
Improve integer operation support in BOUNDER_RULE and BOUNDER_TAC
jargh Nov 14, 2023
16015b4
Avoid duplicate labels in ed25519 x86 implementation
torben-hansen Nov 15, 2023
917bd14
Merge pull request #92 from torben-hansen/fix_duplicate_labels_ed25519
jargh Nov 16, 2023
e62d5c7
Merge branch 'awslabs:main' into main
jargh Nov 16, 2023
9f82fda
Merge pull request #94 from jargh/main
aqjune-aws Nov 17, 2023
0694a87
Make parameter to ed25519 decode function const
torben-hansen Nov 27, 2023
9985a1b
Merge pull request #99 from torben-hansen/ed25519_decode_signature_in…
aqjune-aws Nov 28, 2023
ce316eb
Allow MIT-0 license as well as Apache-2.0 and ISC (#104)
jargh Jan 23, 2024
e64899b
Switch non-alt ARM X25519 to unsaturated code following Lenngren
jargh Feb 9, 2024
81a5d60
Tweak attribution of SLOTHY work
jargh Feb 14, 2024
f4eae2a
Merge pull request #108 from jargh/main
jargh Feb 15, 2024
104dd57
Merge pull request #109 from aqjune-aws/table-benchmark
aqjune-aws Feb 15, 2024
bf90578
Tidy up Montgomery ladders
jargh Feb 22, 2024
1f1c0ff
Update curve25519_x25519{_byte} to make AWS-LC's delocator work
aqjune-aws Mar 5, 2024
ff6e151
Merge pull request #112 from aqjune-aws/fips25519
jargh Mar 6, 2024
cbbcbc9
Merge branch 'awslabs:main' into main
jargh Mar 6, 2024
183d824
Remove one redundant instruction, tidy a few proofs with WORD_BLAST
jargh Mar 7, 2024
8478655
Bifurcate microarchitectural variants of Weierstrass doublings
jargh Mar 8, 2024
5c6c1ee
Merge branch 'awslabs:main' into main
jargh Mar 28, 2024
d5c288c
Switch inlining to subroutines in non-alt ARM P-521 point doubling
jargh Apr 4, 2024
196061b
Merge pull request #117 from jargh/main
aqjune-aws Apr 4, 2024
ee7f834
Liberalize aliasing requirements for Weierstrass point additions
jargh Apr 20, 2024
309d21c
Merge branch 'awslabs:main' into main
jargh Apr 20, 2024
e34ecc1
Handle zero inputs in Weierstrass mixed additions
jargh Apr 25, 2024
a44e3e5
Handle zero inputs in Weierstrass point additions
jargh Apr 30, 2024
0ae7d4f
Bifurcate microarchitectural variants of Weierstrass point additions
jargh May 5, 2024
2e44242
Merge pull request #123 from jargh/main
jargh May 8, 2024
a6e023a
Add `bignum_mont{mul,sqr}_p384_neon`, speed improvements/refactoring …
aqjune-aws Apr 26, 2024
1858f15
Merge pull request #122 from aqjune-aws/equiv-p384
jargh May 10, 2024
0462e61
Add `bignum_mont{sqr,mul}_p521_neon`
aqjune-aws Jun 6, 2024
285fb43
Merge pull request #129 from aqjune-aws/equiv-p521
aqjune-aws Jun 20, 2024
c67c63f
Merge branch 'awslabs:main' into main
jargh Jun 20, 2024
46c80a4
Add `bignum_{sqr,mul}_p521_neon`
aqjune-aws Jun 20, 2024
eeb588c
Merge pull request #130 from aqjune-aws/equiv-p521_2
aqjune-aws Jun 26, 2024
62ac081
Merge branch 'awslabs:main' into main
jargh Jun 26, 2024
d6f07a3
Merge pull request #131 from jargh/main
jargh Jul 15, 2024
a4f3e5a
Merge branch 's2n-bignum-2024-07-22' into aws-lc-s2n-bignum-update-20…
Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ curve25519_x25519_scalarloop:
usra v20.2d, v25.2d, #25
and v27.16b, v25.16b, v23.16b // ubignum_of_hreglist 1 + ubignum_of_lreglist 1 // INTERMEDIATE H|L = x4|z5
bfi x17, x7, #32, #25 // ubignum_of_preglist 1 // INTERMEDIATE z4
mov v5.d[0], x3 // depth 86
mov v5.d[0], x3
mov v1.d[0], x5 // FINAL z2
usra v26.2d, v20.2d, #26 // ubignum_of_hreglist 3 + ubignum_of_lreglist 3 // INTERMEDIATE H|L = x4|z5
and v28.16b, v20.16b, v30.16b // ubignum_of_hreglist 2 + ubignum_of_lreglist 2 // INTERMEDIATE H|L = x4|z5
Expand Down
36 changes: 10 additions & 26 deletions third_party/s2n-bignum/arm/curve25519/curve25519_x25519_alt.S
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,7 @@ curve25519_x25519_alt_scalarloop:

// Multiplex directly into (xn,zn) then do three pure doubling steps;
// this accounts for the implicit zeroing of the three lowest bits
// of the scalar. On the very last doubling we *fully* reduce zn mod
// p_25519 to ease checking for degeneracy below.
// of the scalar.

cmp swap, xzr
mux_4(xn,xm,xn)
Expand Down Expand Up @@ -631,20 +630,20 @@ curve25519_x25519_alt_scalarloop:
orr x1, x1, 0x10000
cmadd_4(e,p,d)
mul_4(xn,s,d)
mul_p25519(zn,p,e)
mul_4(zn,p,e)

// The projective result of the scalar multiplication is now (xn,zn).
// Prepare to call the modular inverse function to get xm = 1/zn
// Prepare to call the modular inverse function to get zn' = 1/zn

add x0, xm
add x0, zn
add x1, zn

// Inline copy of bignum_inv_p25519, identical except for stripping out
// the prologue and epilogue saving and restoring registers and making
// and reclaiming room on the stack. For more details and explanations see
// "arm/curve25519/bignum_inv_p25519.S". Note that the stack it uses for
// its own temporaries is 128 bytes, so it has no effect on variables
// that are needed in the rest of our computation here: res, xm and zn.
// that are needed in the rest of our computation here: res, xn and zn.

mov x20, x0
mov x10, #0xffffffffffffffed
Expand Down Expand Up @@ -1675,28 +1674,13 @@ curve25519_x25519_alt_invmidloop:
stp x0, x1, [x4]
stp x2, x5, [x4, #16]

// Since we eventually want to return 0 when the result is the point at
// infinity, we force xn = 0 whenever zn = 0. This avoids building in a
// dependency on the behavior of modular inverse in out-of-scope cases.

ldp x0, x1, [zn]
ldp x2, x3, [zn+16]
orr x0, x0, x1
orr x2, x2, x3
orr x4, x0, x2
cmp x4, xzr
ldp x0, x1, [xn]
csel x0, x0, xzr, ne
csel x1, x1, xzr, ne
ldp x2, x3, [xn+16]
stp x0, x1, [xn]
csel x2, x2, xzr, ne
csel x3, x3, xzr, ne
stp x2, x3, [xn+16]

// Now the result is xn * (1/zn), fully reduced modulo p.
// Note that in the degenerate case zn = 0 (mod p_25519), the
// modular inverse code above will produce 1/zn = 0, giving
// the correct overall X25519 result of zero for the point at
// infinity.

mul_p25519(resx,xn,xm)
mul_p25519(resx,xn,zn)

// Restore stack and registers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ curve25519_x25519_byte_scalarloop:
usra v20.2d, v25.2d, #25
and v27.16b, v25.16b, v23.16b // ubignum_of_hreglist 1 + ubignum_of_lreglist 1 // INTERMEDIATE H|L = x4|z5
bfi x17, x7, #32, #25 // ubignum_of_preglist 1 // INTERMEDIATE z4
mov v5.d[0], x3 // depth 86
mov v5.d[0], x3
mov v1.d[0], x5 // FINAL z2
usra v26.2d, v20.2d, #26 // ubignum_of_hreglist 3 + ubignum_of_lreglist 3 // INTERMEDIATE H|L = x4|z5
and v28.16b, v20.16b, v30.16b // ubignum_of_hreglist 2 + ubignum_of_lreglist 2 // INTERMEDIATE H|L = x4|z5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,7 @@ curve25519_x25519_byte_alt_scalarloop:

// Multiplex directly into (xn,zn) then do three pure doubling steps;
// this accounts for the implicit zeroing of the three lowest bits
// of the scalar. On the very last doubling we *fully* reduce zn mod
// p_25519 to ease checking for degeneracy below.
// of the scalar.

cmp swap, xzr
mux_4(xn,xm,xn)
Expand Down Expand Up @@ -749,20 +748,20 @@ curve25519_x25519_byte_alt_scalarloop:
orr x1, x1, 0x10000
cmadd_4(e,p,d)
mul_4(xn,s,d)
mul_p25519(zn,p,e)
mul_4(zn,p,e)

// The projective result of the scalar multiplication is now (xn,zn).
// Prepare to call the modular inverse function to get xm = 1/zn
// Prepare to call the modular inverse function to get zn' = 1/zn

add x0, xm
add x0, zn
add x1, zn

// Inline copy of bignum_inv_p25519, identical except for stripping out
// the prologue and epilogue saving and restoring registers and making
// and reclaiming room on the stack. For more details and explanations see
// "arm/curve25519/bignum_inv_p25519.S". Note that the stack it uses for
// its own temporaries is 128 bytes, so it has no effect on variables
// that are needed in the rest of our computation here: res, xm and zn.
// that are needed in the rest of our computation here: res, xn and zn.

mov x20, x0
mov x10, #0xffffffffffffffed
Expand Down Expand Up @@ -1793,28 +1792,13 @@ curve25519_x25519_byte_alt_invmidloop:
stp x0, x1, [x4]
stp x2, x5, [x4, #16]

// Since we eventually want to return 0 when the result is the point at
// infinity, we force xn = 0 whenever zn = 0. This avoids building in a
// dependency on the behavior of modular inverse in out-of-scope cases.

ldp x0, x1, [zn]
ldp x2, x3, [zn+16]
orr x0, x0, x1
orr x2, x2, x3
orr x4, x0, x2
cmp x4, xzr
ldp x0, x1, [xn]
csel x0, x0, xzr, ne
csel x1, x1, xzr, ne
ldp x2, x3, [xn+16]
stp x0, x1, [xn]
csel x2, x2, xzr, ne
csel x3, x3, xzr, ne
stp x2, x3, [xn+16]

// Now the result is xn * (1/zn), fully reduced modulo p.
// Note that in the degenerate case zn = 0 (mod p_25519), the
// modular inverse code above will produce 1/zn = 0, giving
// the correct overall X25519 result of zero for the point at
// infinity.

mul_p25519(zn,xn,xm)
mul_p25519(zn,xn,zn)

ldp x10, x11, [zn]
strb w10, [resx]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT-0

// ----------------------------------------------------------------------------
// Given table: uint64_t[height*width], copy table[idx*width...(idx+1)*width-1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT-0

// ----------------------------------------------------------------------------
// Given table: uint64_t[height*16], copy table[idx*16...(idx+1)*16-1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT-0

// ----------------------------------------------------------------------------
// Given table: uint64_t[height*32], copy table[idx*32...(idx+1)*32-1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC
// SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT-0

// ----------------------------------------------------------------------------
// Given table: uint64_t[height*width], copy table[idx*width...(idx+1)*width-1]
// into z[0..width-1]. width must be a mutiple of 8.
// into z[0..width-1]. width must be a multiple of 8.
// This function is constant-time with respect to the value of `idx`. This is
// achieved by reading the whole table and using the bit-masking to get the
// `idx`-th row.
Expand Down
7 changes: 6 additions & 1 deletion third_party/s2n-bignum/arm/p384/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ OBJ = bignum_add_p384.o \
bignum_mod_p384_6.o \
bignum_montmul_p384.o \
bignum_montmul_p384_alt.o \
bignum_montmul_p384_neon.o \
bignum_montsqr_p384.o \
bignum_montsqr_p384_alt.o \
bignum_montsqr_p384_neon.o \
bignum_mux_6.o \
bignum_neg_p384.o \
bignum_nonzero_6.o \
Expand All @@ -45,8 +47,11 @@ OBJ = bignum_add_p384.o \
bignum_tomont_p384.o \
bignum_triple_p384.o \
p384_montjadd.o \
p384_montjadd_alt.o \
p384_montjdouble.o \
p384_montjmixadd.o
p384_montjdouble_alt.o \
p384_montjmixadd.o \
p384_montjmixadd_alt.o

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

Expand Down
Loading
Loading