packages feed

crypton-2.3.1 / cbits / s2n / import.sh

#!/bin/sh# Re-import the vendored parts of AWS's s2n-bignum.## Only the files crypton calls are kept, and they are kept unmodified -- the# dispatch that chooses between the two variants of each is in# cbits/p256/p256_s2n.c, not in here.  Run this from cbits/s2n:##     ./import.sh [commit]## and commit the result together with the COMMIT line it writes, so that the# tree always says which upstream revision it holds.set -euREPO=https://github.com/awslabs/s2n-bignumREV=${1:-main}HERE=$(cd "$(dirname "$0")" && pwd)TMP=$(mktemp -d)trap 'rm -rf "$TMP"' EXITgit clone -q "$REPO" "$TMP/s2n"git -C "$TMP/s2n" checkout -q "$REV"# The headers every vendored file includes.  Not x86_att/'s own header of# the same name, which is crypton's -- it makes the x86-64 files assemble on# Windows and hands on to this one; see README.md.  Nothing here copies into# that name, and nothing should.for h in _internal_s2n_bignum_arm.h _internal_s2n_bignum_x86_att.h; do	cp "$TMP/s2n/include/$h" "$HERE/include/$h"donecp "$TMP/s2n/LICENSE" "$HERE/LICENSE"# Both variants of each routine are taken, since which one is faster is not# the same question on the two architectures -- see README.md.  Where the# upstream tree has no separate _alt file the plain one defines both symbols,# so "copy it if it is there" gets the right set either way.# x86-64 only, for the things AArch64 does not want -- see README.md.take_x86() {	dir=$1	name=$2	cp "$TMP/s2n/x86_att/$dir/$name.S" "$HERE/x86_att/$name.S"}take() {	curve=$1	name=$2	for arch in arm x86_att; do		for v in "" _alt; do			src="$TMP/s2n/$arch/$curve/$name$v.S"			if [ -f "$src" ]; then				cp "$src" "$HERE/$arch/$name$v.S"			fi		done	done}# P-256: variable-point scalar multiplication, affine in and out, and the# fixed-base one, which reads a table of its own that# cbits/p256/gen_base_table.py builds.take p256 p256_scalarmultake p256 p256_scalarmulbase# The Jacobian point operations, which ECDSA verification walks itself: it# multiplies two scalars at once, in variable time, which is allowed there# because everything it touches is public.  See cbits/p256/p256_verify.c.take p256 p256_montjaddtake p256 p256_montjdoubletake p256 p256_montjmixaddtake p256 bignum_tomont_p256take p256 bignum_demont_p256take p256 bignum_neg_p256# P-384 and P-521 have no affine wrapper upstream, so the Montgomery and# Jacobian conversions are built here out of these; the glue is in# cbits/crypton_ecc_s2n.c.take p384 p384_montjscalarmultake p384 bignum_tomont_p384take p384 bignum_deamont_p384take p384 bignum_montmul_p384take p384 bignum_montsqr_p384take p384 bignum_montinv_p384take p521 p521_jscalarmultake p521 bignum_mul_p521take p521 bignum_sqr_p521take p521 bignum_inv_p521# X25519, both the general one and the fixed-base one that a key is# generated with.  The word form, which both architectures have, rather than# the byte form that only AArch64 has: they measure the same and this way# there is one code path.take curve25519 curve25519_x25519take curve25519 curve25519_x25519base# Ed25519's base point multiplication, which signing does twice -- once for# the nonce's point and once for the public key it derives from the secret# key every time -- and the encoding of the result, which has one form.take curve25519 edwards25519_scalarmulbasetake curve25519 edwards25519_encode# Inversion modulo an odd number of any size, which is what ECDSA does once# per signature and once per verification.  It uses no instruction beyond# the base architecture, so there is one of it and no run-time question.take generic bignum_modinv# Modular exponentiation at RSA sizes.  Only x86-64: on AArch64 crypton's C# is the faster of the two, measured, so nothing is taken for it.  The# Karatsuba multiplications and the reduction all want ADX.take_x86 fastmul bignum_kmul_16_32take_x86 fastmul bignum_ksqr_16_32take_x86 fastmul bignum_kmul_32_64take_x86 fastmul bignum_ksqr_32_64take_x86 fastmul bignum_emontredc_8n# RSA-3072's 24-limb square, built from these where the 32-limb Karatsuba# would take its operands paddedtake_x86 fastmul bignum_sqr_8_16take_x86 fastmul bignum_mul_8_16# and, for the sizes there is no Karatsuba routine for, the schoolbook# multiplication and squaring of any size, which bignum_emontredc_8n then# reduces as it reduces the otherstake_x86 generic bignum_multake_x86 generic bignum_sqr# R^2 mod m, which every exponentiation and every setup in crypton_ecc.c# begins with.  Both architectures: the C climbs to it by a ladder of# Montgomery squarings and this is faster on both.  Taken from upstream's# main when it went in rather than by this script, which is why it was# missing here; it is the same file at the COMMIT above.take generic bignum_montifiergit -C "$TMP/s2n" rev-parse HEAD > "$HERE/COMMIT"echo "imported $(cat "$HERE/COMMIT")"