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

Conversation

torben-hansen
Copy link
Contributor

Description of changes:

(2023-11-15) Pull in the latest changes from s2n-bignum:

  • Adds Ed25519 implementations
  • Adds optimized X25519 implementations

The commands in the internal Quip document was used, with PATHS_TO_KEEP defined as follows:

PATHS_TO_KEEP="\
./arm/p384 ./x86_att/p384 ./arm/p521 ./x86_att/p521 \
./arm/fastmul/bignum_emontredc_8n.S \
./arm/fastmul/bignum_kmul_16_32.S \
./arm/fastmul/bignum_kmul_32_64.S \
./arm/fastmul/bignum_ksqr_16_32.S \
./arm/fastmul/bignum_ksqr_32_64.S \
./arm/generic/bignum_ge.S \
./arm/generic/bignum_mul.S \
./arm/generic/bignum_optsub.S \
./arm/generic/bignum_sqr.S \
./x86_att/curve25519/curve25519_x25519.S \
./x86_att/curve25519/curve25519_x25519base.S \
./x86_att/curve25519/curve25519_x25519_alt.S \
./x86_att/curve25519/curve25519_x25519base_alt.S  \
./x86_att/curve25519/bignum_neg_p25519.S \
./x86_att/curve25519/bignum_mod_n25519.S  \
./x86_att/curve25519/edwards25519_decode.S  \
./x86_att/curve25519/edwards25519_decode_alt.S  \
./x86_att/curve25519/edwards25519_encode.S  \
./x86_att/curve25519/edwards25519_scalarmulbase.S  \
./x86_att/curve25519/edwards25519_scalarmulbase_alt.S  \
./x86_att/curve25519/edwards25519_scalarmuldouble.S  \
./x86_att/curve25519/edwards25519_scalarmuldouble_alt.S  \
./arm/curve25519/curve25519_x25519.S \
./arm/curve25519/curve25519_x25519base.S \
./arm/curve25519/curve25519_x25519_alt.S \
./arm/curve25519/curve25519_x25519base_alt.S \
./arm/curve25519/curve25519_x25519_byte.S \
./arm/curve25519/curve25519_x25519base_byte.S \
./arm/curve25519/curve25519_x25519_byte_alt.S \
./arm/curve25519/curve25519_x25519base_byte_alt.S \
./arm/curve25519/bignum_neg_p25519.S \
./arm/curve25519/bignum_mod_n25519.S  \
./arm/curve25519/edwards25519_decode.S  \
./arm/curve25519/edwards25519_decode_alt.S  \
./arm/curve25519/edwards25519_encode.S  \
./arm/curve25519/edwards25519_scalarmulbase.S  \
./arm/curve25519/edwards25519_scalarmulbase_alt.S  \
./arm/curve25519/edwards25519_scalarmuldouble.S  \
./arm/curve25519/edwards25519_scalarmuldouble_alt.S \
./include/_internal_s2n_bignum.h"

Call-outs:

Had to resolve a number of conflicts in the merge step in the existing x25519 files... Solely took "theirs".

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

jargh and others added 30 commits March 7, 2022 16:28
No labels on the same line as an instruction, and all instructions
with initial 8 spaces. Also tweak a couple of instances in the testing
code where "bignum_copy" was used inside a reference function.

s2n-bignum original commit: awslabs/s2n-bignum@6d2bf13
The x86 ABI on Windows differs from the "standard" one used on Linux,
Mac OS etc. For our purposes the relevant differences are that RDI and
RSI are callee-saved (need to be preserved if modified), and that the
input arguments are in different places. Integer return values are
still in RAX. Here are the conventions for the first 6 integer
arguments (the maximum that s2n-bignum functions rely on so far):

   Argument number       Standard        Windows

          1                RDI            RCX
          2                RSI            RDX
          3                RDX             R8
          4                RCX             R9
          5                 R8           [RSP+40]
          6                 R9           [RSP+48]

Here we add a wrapper round each s2n-bignum function that optionally
(controlled by the WINDOWS_ABI variable in preprocessing) makes the
function compatible with the Windows ABI. This is done in a simplistic
way simply by pushing the extra callee-saved registers (RSI and RDI),
shuffling arguments (only the ones actually used by that function),
performing the same computation in exactly the original way, and
finally popping back the extra registers.

The Makefile currently selects this WINDOWS_ABI mode when `uname -s`
gives "CYGWIN_NT-10.0", as on the main test platform, but this can be
configured.

s2n-bignum original commit: awslabs/s2n-bignum@8ac4010
WIndows ABI code and proofs
s2n-bignum original commit: awslabs/s2n-bignum@3908e3d
s2n-bignum original commit: awslabs/s2n-bignum@e5d0f81
Several files missing .text directive
s2n-bignum original commit: awslabs/s2n-bignum@2530c31
Improvements to ARM small Karatsuba muls
s2n-bignum original commit: awslabs/s2n-bignum@5162347
curve25519 Montgomery ladder step
s2n-bignum original commit: awslabs/s2n-bignum@82c3d61
A point doubling function, point addition function, and point mixed
addition function for the P-384 curve, all using Jacobian coordinates
in a Montgomery representation, with input nondegeneracy assumed.
Once again, the addition and mixed addition functions offer only
marginal efficiency gains over just calling a sequence of basic field
operations, but the doubling has some beneficial mathematically
equivalent short-cutting of the intermediate modular reductions.

s2n-bignum original commit: awslabs/s2n-bignum@df8e913
The same trio of a point doubling function, point addition function
and point mixed addition function, this time for the P-521 curve,
all using Jacobian coordinates, with input nondegeneracy assumed.

s2n-bignum original commit: awslabs/s2n-bignum@047c0b1
Basic point operations for the Weierstrass curves
s2n-bignum original commit: awslabs/s2n-bignum@44003b0
jargh and others added 22 commits July 26, 2023 10:41
Adding support for SHA256 and SHA512 intrinsics
s2n-bignum original commit: awslabs/s2n-bignum@e6024ae
This implements the point compression encoding to a byte array from
https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.2
as function "edwards25519_encode". It assumes the input is a point
(x,y) on the edwards25519 curve, with coordinates reduced mod
p_25519 = 2^255 - 19, and does not check any of that.

s2n-bignum original commit: awslabs/s2n-bignum@67430be
This implements point decoding from a 256-bit little-endian byte
sequence to a point (x,y) on the edwards25519 curve as specified in
https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.3
The function returns 0 for success and 1 for failure, the latter
meaning that the input is not the encoding of any edwards25519 point.

s2n-bignum original commit: awslabs/s2n-bignum@97f7493
The function bignum_mod_n25519 performs reduction of an input of any
size (k digits) modulo the order of the curve25519/edwards25519
basepoint, n_25519 = 2^252 + 27742317777372353535851937790883648493.
It generalizes bignum_mod_n25519_4, which is the special case of
4-digit (256-bit) inputs.

s2n-bignum original commit: awslabs/s2n-bignum@e23fd30
This replaces the inlined variant of "bignum_modinv" with code from
"bignum_inv_p25519" in all "curve25519_" functions returning an affine
point and hence using modular inverse. There are also a few
consequential changes related to the slightly different amount of
temporary storage needed by this function.

s2n-bignum original commit: awslabs/s2n-bignum@777d574
…ck_no

Document that x25519 function does not implement zero-check
s2n-bignum original commit: awslabs/s2n-bignum@5c4b15a
This replaces the inlined variant of "bignum_modinv" with code from
"bignum_inv_p25519" in all "edwards25519_scalarmul*" functions.
Again, there are consequential changes related to the slightly
different amount of temporary storage needed by bignum_inv_p25519.

s2n-bignum original commit: awslabs/s2n-bignum@7e7b18e
Ed25519 support and related updates
s2n-bignum original commit: awslabs/s2n-bignum@db8409d
Add BFM, BIC, FCSEL, INS, SUB, TRN1, TRN2, USHR, ZIP2 to ARM model
s2n-bignum original commit: awslabs/s2n-bignum@f1caaf1
@torben-hansen torben-hansen requested a review from a team as a code owner November 15, 2023 16:57
@torben-hansen torben-hansen merged commit b15b9d3 into aws:main Nov 15, 2023
12 checks passed
justsmth pushed a commit to justsmth/aws-lc that referenced this pull request Nov 16, 2023
…te-2023-11-15

Update s2n-bignum subtree 2023-11-15
justsmth pushed a commit to justsmth/aws-lc that referenced this pull request Nov 16, 2023
…te-2023-11-15

Update s2n-bignum subtree 2023-11-15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants