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

Update s2n-bignum subtree 2023-11-15 #1308

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
0145060
Add curve25519 field negation
jargh Mar 8, 2022
64b8ca5
Regularize spacing of assembler files
jargh Mar 11, 2022
9630338
Add Windows ABI wrappers
jargh Mar 31, 2022
888b29a
Merge branch 'awslabs:main' into main
jargh Apr 22, 2022
b48360c
Merge pull request #30 from jargh/main
jargh May 5, 2022
ed4f27b
Merge branch 'main' of github.com:jargh/s2n-bignum
jargh May 13, 2022
22d0652
Platform-aware symbol macros
justsmth May 19, 2022
ed031d3
Cleanup and indentation
justsmth May 20, 2022
4cc5280
#include "_internal_s2n_bignum.h"
justsmth May 20, 2022
1ba86f2
Invoke cpp as ' -E'
justsmth May 23, 2022
02cb77f
Use .hidden directive on non-Apple platforms
justsmth May 23, 2022
e7f49a9
Use '$(CC) -E' for preprocessor
justsmth May 24, 2022
fc06fa0
Merge pull request #32 from justsmth/symbol-macros
jargh Jun 4, 2022
1eddae5
Merge branch 'awslabs:main' into main
jargh Jun 4, 2022
3c8db85
Several files missing .text directive
justsmth Jun 8, 2022
b534700
Re-make x86_att
justsmth Jun 8, 2022
a7c1d12
Merge pull request #33 from justsmth/missing-text
jargh Jun 9, 2022
5408453
Merge branch 'awslabs:main' into main
jargh Jun 9, 2022
a51b41b
Merge pull request #34 from jargh/main
jargh Jun 10, 2022
1371596
Merge branch 'awslabs:main' into main
jargh Jun 16, 2022
39b1a7e
Merge pull request #35 from jargh/main
jargh Jun 23, 2022
1eaf8c5
Merge branch 'main' of github.com:jargh/s2n-bignum
jargh Jun 27, 2022
de00f96
Add basic NIST P-384 point operations
jargh Jul 2, 2022
6fec512
Tweak ARM bignum_sqr_p521_alt to use fewer registers
jargh Jul 16, 2022
7b51bdf
Add basic NIST P-521 point operations
jargh Jul 21, 2022
e01e3be
Merge branch 'awslabs:main' into main
jargh Jul 21, 2022
2af9c6a
Merge pull request #36 from jargh/main
jargh Jul 22, 2022
e2d3037
Merge branch 'main' of github.com:jargh/s2n-bignum
jargh Jul 28, 2022
0e27f1c
Merge branch 'awslabs:main' into main
jargh Jul 28, 2022
1026324
Merge branch 'main' of github.com:jargh/s2n-bignum
jargh Aug 23, 2022
15e269c
Add X25519 function
jargh Sep 30, 2022
1d23770
Merge pull request #37 from jargh/main
jargh Oct 7, 2022
6774fef
Add curve25519 field doubling
jargh Oct 11, 2022
0025707
Update forgotten AT&T syntax forms in line with previous changes
jargh Oct 26, 2022
a49bf78
update license headers of .c and .s files
samuel40791765 Oct 28, 2022
9c62e93
update license headers of Makefiles and sed files
samuel40791765 Oct 28, 2022
176fc78
Merge pull request #38 from samuel40791765/update-license
samuel40791765 Nov 7, 2022
f9ec3f3
Merge branch 'awslabs:main' into main
jargh Nov 7, 2022
31076a7
Add X25519 basepoint function
jargh Nov 8, 2022
52a5a35
Merge pull request #39 from jargh/main
jargh Nov 10, 2022
feff47e
Add SM2 mapping to Montgomery representation
jargh Jan 10, 2023
fb5363a
Add SM2 field negation
jargh Jan 11, 2023
d852f9c
Add SM2 field doubling and halving
jargh Jan 11, 2023
59c7dfe
Merge branch 'awslabs:main' into main
jargh Jan 12, 2023
74de793
Merge branch 'awslabs:main' into main
jargh Jan 27, 2023
c10d13e
Merge pull request #44 from jargh/main
jargh Feb 1, 2023
dc9e7a8
Slightly optimize x86 modular inverse inner loop
jargh Feb 10, 2023
8124ddf
Loosen modular reductions in X25519 basepoint functions
jargh Mar 1, 2023
05108ef
Loosen modular reductions in X25519 fresh-point functions
jargh Mar 7, 2023
26b8398
Reorder some field operations in X25519 functions
jargh Mar 8, 2023
c323a2d
Eliminate 5-digit intermediates in ARM X25519 functions
jargh Mar 9, 2023
04a48dd
Propagate field operation improvements to ARM X25519 functions
jargh Mar 9, 2023
b2c1f4d
Merge branch 'awslabs:main' into main
jargh Mar 10, 2023
ef98948
Merge pull request #45 from jargh/main
jargh Mar 13, 2023
b10cd6c
Add basic SM2 point operations
jargh Mar 17, 2023
c63ccef
Merge pull request #46 from jargh/main
jargh Mar 18, 2023
b233c58
Add byte-level interfaces for X25519 functions
jargh Mar 21, 2023
4f0928e
Merge branch 'awslabs:main' into main
jargh Mar 21, 2023
754cd0d
Merge pull request #48 from jargh/main
jargh Mar 22, 2023
6887081
Per file namespace for symbolic labels
torben-hansen Apr 12, 2023
56f8e3a
Merge pull request #50 from torben-hansen/per_file_namespace_for_symb…
jargh Apr 13, 2023
ee9c3af
Add edwards25519 (Ed25519) basepoint multiplication
jargh Apr 21, 2023
dc4268b
Make labels unique across new Edwards functions
jargh Apr 21, 2023
c816a48
Merge pull request #52 from jargh/main
jargh Apr 24, 2023
1054fb3
Merge branch 'main' into newinsts
aqjune Apr 24, 2023
935b9dc
Merge pull request #51 from aqjune/newinsts
jargh Apr 27, 2023
7ac88c7
Merge branch 'main' into add_unique_label_rename_script
torben-hansen Apr 27, 2023
59e5975
Merge pull request #53 from torben-hansen/add_unique_label_rename_script
jargh Apr 28, 2023
b13f1e7
Add edwards25519 combined fresh and base point scalar multiplication
jargh Jun 14, 2023
a033437
Merge branch 'awslabs:main' into main
jargh Jun 26, 2023
1d4bad3
Merge branch 'awslabs:main' into main
jargh Jul 10, 2023
5ec7750
Avoid using assembler macros and rename labels in the functions for RSA
aqjune-aws Jul 22, 2023
21f3498
Merge pull request #71 from aqjune-aws/fips
jargh Jul 24, 2023
53213bb
Merge branch 'awslabs:main' into main
jargh Jul 26, 2023
4637345
Merge branch 'awslabs:main' into main
jargh Jul 27, 2023
40315b3
Merge branch 'awslabs:main' into main
jargh Jul 28, 2023
b527913
Merge pull request #70 from kwancarl/main
jargh Jul 29, 2023
6f1512a
Merge branch 'awslabs:main' into main
jargh Jul 29, 2023
ea5f41b
Merge branch 'awslabs:main' into main
jargh Aug 16, 2023
d73c310
Merge branch 'awslabs:main' into main
jargh Sep 12, 2023
d0846df
Merge branch 'awslabs:main' into main
jargh Sep 16, 2023
6c1499d
Add Ed25519 point compression encoding
jargh Oct 5, 2023
e3da22f
Merge branch 'awslabs:main' into main
jargh Oct 11, 2023
55ea174
Add Ed25519 point decoding function
jargh Oct 14, 2023
d2bb439
Add generic size curve25519/edwards25519 basepoint modulus
jargh Oct 18, 2023
062a321
Merge branch 'awslabs:main' into main
jargh Oct 20, 2023
7f883e5
Switch curve25519 operations to divstep-based modular inverse
jargh Oct 28, 2023
b8ee5c0
Document that x25519 function does not implement zero-check
torben-hansen Nov 1, 2023
519f95f
Merge pull request #88 from torben-hansen/document_x25519_zero_check_no
jargh Nov 1, 2023
6184cdd
Merge branch 'awslabs:main' into main
jargh Nov 1, 2023
e618f26
Switch edwards25519 operations to divstep-based modular inverse
jargh Nov 2, 2023
462f117
Merge pull request #87 from jargh/main
jargh Nov 3, 2023
db8ea6b
Merge branch 'awslabs:main' into main
jargh Nov 4, 2023
86cc518
Merge pull request #90 from jargh/main
jargh Nov 6, 2023
e140013
Merge branch 's2n-bignum-2023-11-15' into aws-lc-s2n-bignum-update-20…
torben-hansen Nov 15, 2023
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
186 changes: 186 additions & 0 deletions third_party/s2n-bignum/arm/curve25519/bignum_mod_n25519.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

// ----------------------------------------------------------------------------
// Reduce modulo basepoint order, z := x mod n_25519
// Input x[k]; output z[4]
//
// extern void bignum_mod_n25519
// (uint64_t z[static 4], uint64_t k, uint64_t *x);
//
// Reduction is modulo the order of the curve25519/edwards25519 basepoint,
// which is n_25519 = 2^252 + 27742317777372353535851937790883648493
//
// Standard ARM ABI: X0 = z, X1 = k, X2 = x
// ----------------------------------------------------------------------------
#include "_internal_s2n_bignum.h"

S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_mod_n25519)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_mod_n25519)
.text
.balign 4

#define z x0
#define k x1
#define x x2

#define m0 x3
#define m1 x4
#define m2 x5
#define m3 x6

#define t0 x7
#define t1 x8
#define t2 x9
#define t3 x10

#define n0 x11
#define n1 x12

// These two are aliased: we only load d when finished with q

#define q x13
#define d x13

// Loading large constants

#define movbig(nn,n3,n2,n1,n0) \
movz nn, n0; \
movk nn, n1, lsl #16; \
movk nn, n2, lsl #32; \
movk nn, n3, lsl #48

S2N_BN_SYMBOL(bignum_mod_n25519):

// If the input is already <= 3 words long, go to a trivial "copy" path

cmp k, #4
bcc short

// Otherwise load the top 4 digits (top-down) and reduce k by 4
// This [m3;m2;m1;m0] is the initial x where we begin reduction.

sub k, k, #4
lsl t0, k, #3
add t0, t0, x
ldp m2, m3, [t0, #16]
ldp m0, m1, [t0]

// Load the complicated two words of n_25519 = 2^252 + [n1; n0]

movbig( n0, #0x5812, #0x631a, #0x5cf5, #0xd3ed)
movbig( n1, #0x14de, #0xf9de, #0xa2f7, #0x9cd6)

// Get the quotient estimate q = floor(x/2^252).
// Also delete it from m3, in effect doing x' = x - q * 2^252

lsr q, m3, #60
and m3, m3, #0x0FFFFFFFFFFFFFFF

// Multiply [t2;t1;t0] = q * [n1;n0]

mul t0, n0, q
mul t1, n1, q
umulh t2, n0, q
adds t1, t1, t2
umulh t2, n1, q
adc t2, t2, xzr

// Subtract [m3;m2;m1;m0] = x' - q * [n1;n0] = x - q * n_25519

subs m0, m0, t0
sbcs m1, m1, t1
sbcs m2, m2, t2
sbcs m3, m3, xzr

// If this borrows (CF = 0 because of inversion), add back n_25519.
// The masked n3 digit exploits the fact that bit 60 of n0 is set.

csel t0, n0, xzr, cc
csel t1, n1, xzr, cc
adds m0, m0, t0
adcs m1, m1, t1
and t0, t0, #0x1000000000000000
adcs m2, m2, xzr
adc m3, m3, t0

// Now do (k-4) iterations of 5->4 word modular reduction. Each one
// is similar to the sequence above except for the more refined quotient
// estimation process.

cbz k, writeback

loop:

// Assume that the new 5-digit x is 2^64 * previous_x + next_digit.
// Get the quotient estimate q = max (floor(x/2^252)) (2^64 - 1)
// and first compute x' = x - 2^252 * q.

extr q, m3, m2, #60
and m2, m2, #0x0FFFFFFFFFFFFFFF
sub q, q, m3, lsr #60
and m3, m3, #0xF000000000000000
add m2, m2, m3

// Multiply [t2;t1;t0] = q * [n1;n0]

mul t0, n0, q
mul t1, n1, q
umulh t2, n0, q
adds t1, t1, t2
umulh t2, n1, q
adc t2, t2, xzr

// Decrement k and load the next digit (note that d aliases to q)

sub k, k, #1
ldr d, [x, k, lsl #3]

// Subtract [t3;t2;t1;t0] = x' - q * [n1;n0] = x - q * n_25519

subs t0, d, t0
sbcs t1, m0, t1
sbcs t2, m1, t2
sbcs t3, m2, xzr

// If this borrows (CF = 0 because of inversion), add back n_25519.
// The masked n3 digit exploits the fact that bit 60 of n1 is set.

csel m0, n0, xzr, cc
csel m1, n1, xzr, cc
adds m0, t0, m0
and m3, m1, #0x1000000000000000
adcs m1, t1, m1
adcs m2, t2, xzr
adc m3, t3, m3

cbnz k, loop

// Finally write back [m3;m2;m1;m0] and return

writeback:
stp m0, m1, [z]
stp m2, m3, [z, #16]
ret

// Short case: just copy the input with zero-padding

short:
mov m0, xzr
mov m1, xzr
mov m2, xzr
mov m3, xzr

cbz k, writeback
ldr m0, [x]
subs k, k, #1
beq writeback
ldr m1, [x, #8]
subs k, k, #1
beq writeback
ldr m2, [x, #16]
b writeback

#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif
65 changes: 65 additions & 0 deletions third_party/s2n-bignum/arm/curve25519/bignum_neg_p25519.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR ISC

// ----------------------------------------------------------------------------
// Negate modulo p_25519, z := (-x) mod p_25519, assuming x reduced
// Input x[4]; output z[4]
//
// extern void bignum_neg_p25519
// (uint64_t z[static 4], uint64_t x[static 4]);
//
// Standard ARM ABI: X0 = z, X1 = x
// ----------------------------------------------------------------------------
#include "_internal_s2n_bignum.h"

S2N_BN_SYM_VISIBILITY_DIRECTIVE(bignum_neg_p25519)
S2N_BN_SYM_PRIVACY_DIRECTIVE(bignum_neg_p25519)
.text
.balign 4

#define z x0
#define x x1

#define d0 x2
#define d1 x3
#define d2 x4
#define d3 x5
#define c x6
#define d x7

S2N_BN_SYMBOL(bignum_neg_p25519):

// Load the digits of x and compute [d3;d2;d1;d0] = (2^255 - 19) - x
// while also computing c = the OR of the digits of x

ldp d0, d1, [x]
mov d, #-19
orr c, d0, d1
subs d0, d, d0
mov d, #-1
sbcs d1, d, d1
ldp d2, d3, [x, #16]
orr c, c, d2
sbcs d2, d, d2
mov d, #0x7FFFFFFFFFFFFFFF
orr c, c, d3
sbc d3, d, d3

// If in fact c = 0 then the result is zero, otherwise the main result

cmp c, xzr
csel d0, d0, xzr, ne
csel d1, d1, xzr, ne
csel d2, d2, xzr, ne
csel d3, d3, xzr, ne

// Write back result and return

stp d0, d1, [z]
stp d2, d3, [z, #16]

ret

#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits
#endif
Loading
Loading