pq_crypto 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +233 -0
- data/README.md +16 -3
- data/SECURITY.md +46 -0
- data/ext/pqcrypto/extconf.rb +8 -1
- data/ext/pqcrypto/pq_externalmu.c +35 -0
- data/ext/pqcrypto/pqcrypto_native_api.h +91 -75
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +97 -9
- data/ext/pqcrypto/pqcrypto_secure.c +95 -33
- data/ext/pqcrypto/pqcrypto_secure.h +66 -48
- data/ext/pqcrypto/pqcrypto_version.h +1 -1
- data/ext/pqcrypto/vendor/.vendored +7 -7
- data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +5 -2
- data/ext/pqcrypto/vendor/mldsa-native/LICENSE +21 -2
- data/ext/pqcrypto/vendor/mldsa-native/README.md +20 -7
- data/ext/pqcrypto/vendor/mldsa-native/RELEASE.md +160 -0
- data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/README.md +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +85 -59
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +292 -348
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +122 -76
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +184 -86
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +49 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +49 -81
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/context.h +152 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +25 -12
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +2 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +2 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +9 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +19 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_aarch64_asm.S +6 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_aarch64_asm.S +7 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_aarch64_asm.S +7 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_aarch64_asm.S +12 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_aarch64_asm.S +12 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +6 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +11 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +9 -22
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +8 -5
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +1 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_extract_bytes_x4_mve.S → keccak_f1600_x4_state_extract_bytes_mve.S} +14 -14
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/{state_xor_bytes_x4_mve.S → keccak_f1600_x4_state_xor_bytes_mve.S} +12 -12
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +5 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/fips202_native_x86_64.h +1 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2_asm.S +36 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +62 -4
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +87 -54
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{intt_aarch64_asm.S → mldsa_intt_aarch64_asm.S} +39 -6
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{ntt_aarch64_asm.S → mldsa_ntt_aarch64_asm.S} +39 -6
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{pointwise_montgomery_aarch64_asm.S → mldsa_pointwise_montgomery_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_caddq_aarch64_asm.S → mldsa_poly_caddq_aarch64_asm.S} +19 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_chknorm_aarch64_asm.S → mldsa_poly_chknorm_aarch64_asm.S} +24 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_32_aarch64_asm.S → mldsa_poly_decompose_32_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_decompose_88_aarch64_asm.S → mldsa_poly_decompose_88_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_32_aarch64_asm.S → mldsa_poly_use_hint_32_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{poly_use_hint_88_aarch64_asm.S → mldsa_poly_use_hint_88_aarch64_asm.S} +25 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S → mldsa_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_17_aarch64_asm.S → mldsa_polyz_unpack_17_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{polyz_unpack_19_aarch64_asm.S → mldsa_polyz_unpack_19_aarch64_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_aarch64_asm.S → mldsa_rej_uniform_aarch64_asm.S} +48 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta2_aarch64_asm.S → mldsa_rej_uniform_eta2_aarch64_asm.S} +42 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/{rej_uniform_eta4_aarch64_asm.S → mldsa_rej_uniform_eta4_aarch64_asm.S} +42 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +11 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +3 -2
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +28 -28
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +171 -49
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{intt_avx2_asm.S → mldsa_intt_avx2_asm.S} +23 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{ntt_avx2_asm.S → mldsa_ntt_avx2_asm.S} +23 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{nttunpack_avx2_asm.S → mldsa_nttunpack_avx2_asm.S} +17 -1
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l4_avx2_asm.S → mldsa_pointwise_acc_l4_avx2_asm.S} +37 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l5_avx2_asm.S → mldsa_pointwise_acc_l5_avx2_asm.S} +37 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_acc_l7_avx2_asm.S → mldsa_pointwise_acc_l7_avx2_asm.S} +37 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{pointwise_avx2_asm.S → mldsa_pointwise_avx2_asm.S} +31 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/{poly_caddq_avx2_asm.S → mldsa_poly_caddq_avx2_asm.S} +18 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_chknorm_avx2_asm.S +176 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_32_avx2_asm.S +490 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_decompose_88_avx2_asm.S +489 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_32_avx2_asm.S +123 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_poly_use_hint_88_avx2_asm.S +125 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_17_avx2_asm.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_polyz_unpack_19_avx2_asm.S +355 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_avx2_asm.S +132 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta2_avx2_asm.S +205 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S +176 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +27 -36
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +42 -8
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +93 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +74 -15
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +97 -11
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +7 -38
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +49 -7
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +16 -17
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +26 -9
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.c +3 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec_lazy.h +18 -19
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +15 -3
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +28 -6
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +311 -246
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +245 -240
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +64 -5
- data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +5 -2
- data/ext/pqcrypto/vendor/mlkem-native/LICENSE +21 -3
- data/ext/pqcrypto/vendor/mlkem-native/README.md +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +113 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +17 -27
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +68 -151
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +17 -27
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +46 -44
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +37 -6
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/context.h +9 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +8 -8
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +1 -1
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +3 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +3 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +3 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +11 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +3 -3
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +2 -2
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +14 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +28 -11
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +39 -14
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +10 -10
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +20 -20
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +5 -5
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +11 -10
- data/lib/pq_crypto/internal.rb +10 -0
- data/lib/pq_crypto/kem.rb +47 -5
- data/lib/pq_crypto/key.rb +14 -8
- data/lib/pq_crypto/pkcs8.rb +13 -5
- data/lib/pq_crypto/signature.rb +34 -9
- data/lib/pq_crypto/spki.rb +4 -2
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +9 -0
- data/script/vendor_libs.rb +6 -6
- metadata +40 -38
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +0 -52
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +0 -157
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +0 -157
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +0 -103
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +0 -105
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +0 -94
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +0 -96
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +0 -126
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +0 -157
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +0 -141
data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) The mldsa-native project authors
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* References
|
|
7
|
+
* ==========
|
|
8
|
+
*
|
|
9
|
+
* - [REF_AVX2]
|
|
10
|
+
* CRYSTALS-Dilithium optimized AVX2 implementation
|
|
11
|
+
* Bai, Ducas, Kiltz, Lepoint, Lyubashevsky, Schwabe, Seiler, Stehlé
|
|
12
|
+
* https://github.com/pq-crystals/dilithium/tree/master/avx2
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* This file is derived from the public domain
|
|
17
|
+
* AVX2 Dilithium implementation @[REF_AVX2].
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/*yaml
|
|
21
|
+
Name: rej_uniform_eta4_avx2_asm
|
|
22
|
+
Description: x86_64 AVX2 rejection sampling of eta=4 secret coefficients.
|
|
23
|
+
Extracts 4-bit nibbles from the input byte buffer, accepts those < 9,
|
|
24
|
+
and maps an accepted nibble n to the coefficient 4 - n, producing
|
|
25
|
+
values in [-4, 4].
|
|
26
|
+
Signature: unsigned mld_rej_uniform_eta4_avx2_asm(int32_t *r, const uint8_t *buf, const uint8_t table[256][8])
|
|
27
|
+
ABI:
|
|
28
|
+
Architecture: x86_64
|
|
29
|
+
CallingConvention: SysV
|
|
30
|
+
Features: [AVX2]
|
|
31
|
+
rdi:
|
|
32
|
+
type: buffer
|
|
33
|
+
size_bytes: 1024
|
|
34
|
+
permissions: write-only
|
|
35
|
+
c_parameter: int32_t *r
|
|
36
|
+
description: Output coefficient buffer (256 x int32_t)
|
|
37
|
+
rsi:
|
|
38
|
+
type: buffer
|
|
39
|
+
size_bytes: 272
|
|
40
|
+
permissions: read-only
|
|
41
|
+
c_parameter: const uint8_t *buf
|
|
42
|
+
description: Input byte buffer (MLD_AVX2_REJ_UNIFORM_ETA4_BUFLEN = 272)
|
|
43
|
+
rdx:
|
|
44
|
+
type: buffer
|
|
45
|
+
size_bytes: 2048
|
|
46
|
+
permissions: read-only
|
|
47
|
+
c_parameter: const uint8_t *table
|
|
48
|
+
description: Lookup table (256 x 8 uint8_t = mld_rej_uniform_table)
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
#include "../../../common.h"
|
|
52
|
+
#if defined(MLD_ARITH_BACKEND_X86_64_DEFAULT) && !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED)
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
* WARNING: This file is auto-derived from the mldsa-native source file
|
|
56
|
+
* dev/x86_64/src/mldsa_rej_uniform_eta4_avx2_asm.S using scripts/simpasm. Do not modify it directly.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
.text
|
|
60
|
+
.balign 4
|
|
61
|
+
.global MLD_ASM_NAMESPACE(rej_uniform_eta4_avx2_asm)
|
|
62
|
+
MLD_ASM_FN_SYMBOL(rej_uniform_eta4_avx2_asm)
|
|
63
|
+
|
|
64
|
+
.cfi_startproc
|
|
65
|
+
movl $0xf0f0f0f, %r8d # imm = 0xF0F0F0F
|
|
66
|
+
vmovd %r8d, %xmm2
|
|
67
|
+
vpbroadcastd %xmm2, %ymm2
|
|
68
|
+
movl $0x4040404, %r8d # imm = 0x4040404
|
|
69
|
+
vmovd %r8d, %xmm3
|
|
70
|
+
vpbroadcastd %xmm3, %ymm3
|
|
71
|
+
movl $0x9090909, %r8d # imm = 0x9090909
|
|
72
|
+
vmovd %r8d, %xmm4
|
|
73
|
+
vpbroadcastd %xmm4, %ymm4
|
|
74
|
+
xorl %eax, %eax
|
|
75
|
+
xorl %ecx, %ecx
|
|
76
|
+
|
|
77
|
+
Lmld_rej_uniform_eta4_avx2_asm_loop:
|
|
78
|
+
cmpl $0xf8, %eax
|
|
79
|
+
ja Lmld_rej_uniform_eta4_avx2_asm_scalar
|
|
80
|
+
cmpl $0x100, %ecx # imm = 0x100
|
|
81
|
+
ja Lmld_rej_uniform_eta4_avx2_asm_scalar
|
|
82
|
+
vpmovzxbw (%rsi,%rcx), %ymm0
|
|
83
|
+
vpsllw $0x4, %ymm0, %ymm1
|
|
84
|
+
vpor %ymm1, %ymm0, %ymm0
|
|
85
|
+
vpand %ymm2, %ymm0, %ymm0
|
|
86
|
+
vpsubb %ymm4, %ymm0, %ymm1
|
|
87
|
+
vpsubb %ymm0, %ymm3, %ymm0
|
|
88
|
+
vpmovmskb %ymm1, %r8d
|
|
89
|
+
vextracti128 $0x0, %ymm0, %xmm5
|
|
90
|
+
movzbl %r8b, %r10d
|
|
91
|
+
vmovq (%rdx,%r10,8), %xmm6
|
|
92
|
+
vpshufb %xmm6, %xmm5, %xmm6
|
|
93
|
+
vpmovsxbd %xmm6, %ymm1
|
|
94
|
+
vmovdqu %ymm1, (%rdi,%rax,4)
|
|
95
|
+
popcntl %r10d, %r9d
|
|
96
|
+
addl %r9d, %eax
|
|
97
|
+
shrl $0x8, %r8d
|
|
98
|
+
addl $0x4, %ecx
|
|
99
|
+
cmpl $0xf8, %eax
|
|
100
|
+
ja Lmld_rej_uniform_eta4_avx2_asm_scalar
|
|
101
|
+
vpsrldq $0x8, %xmm5, %xmm5 # xmm5 = xmm5[8,9,10,11,12,13,14,15],zero,zero,zero,zero,zero,zero,zero,zero
|
|
102
|
+
movzbl %r8b, %r10d
|
|
103
|
+
vmovq (%rdx,%r10,8), %xmm6
|
|
104
|
+
vpshufb %xmm6, %xmm5, %xmm6
|
|
105
|
+
vpmovsxbd %xmm6, %ymm1
|
|
106
|
+
vmovdqu %ymm1, (%rdi,%rax,4)
|
|
107
|
+
popcntl %r10d, %r9d
|
|
108
|
+
addl %r9d, %eax
|
|
109
|
+
shrl $0x8, %r8d
|
|
110
|
+
addl $0x4, %ecx
|
|
111
|
+
cmpl $0xf8, %eax
|
|
112
|
+
ja Lmld_rej_uniform_eta4_avx2_asm_scalar
|
|
113
|
+
vextracti128 $0x1, %ymm0, %xmm5
|
|
114
|
+
movzbl %r8b, %r10d
|
|
115
|
+
vmovq (%rdx,%r10,8), %xmm6
|
|
116
|
+
vpshufb %xmm6, %xmm5, %xmm6
|
|
117
|
+
vpmovsxbd %xmm6, %ymm1
|
|
118
|
+
vmovdqu %ymm1, (%rdi,%rax,4)
|
|
119
|
+
popcntl %r10d, %r9d
|
|
120
|
+
addl %r9d, %eax
|
|
121
|
+
shrl $0x8, %r8d
|
|
122
|
+
addl $0x4, %ecx
|
|
123
|
+
cmpl $0xf8, %eax
|
|
124
|
+
ja Lmld_rej_uniform_eta4_avx2_asm_scalar
|
|
125
|
+
vpsrldq $0x8, %xmm5, %xmm5 # xmm5 = xmm5[8,9,10,11,12,13,14,15],zero,zero,zero,zero,zero,zero,zero,zero
|
|
126
|
+
movzbl %r8b, %r10d
|
|
127
|
+
vmovq (%rdx,%r10,8), %xmm6
|
|
128
|
+
vpshufb %xmm6, %xmm5, %xmm6
|
|
129
|
+
vpmovsxbd %xmm6, %ymm1
|
|
130
|
+
vmovdqu %ymm1, (%rdi,%rax,4)
|
|
131
|
+
popcntl %r10d, %r9d
|
|
132
|
+
addl %r9d, %eax
|
|
133
|
+
addl $0x4, %ecx
|
|
134
|
+
jmp Lmld_rej_uniform_eta4_avx2_asm_loop
|
|
135
|
+
|
|
136
|
+
Lmld_rej_uniform_eta4_avx2_asm_scalar:
|
|
137
|
+
cmpl $0x100, %eax # imm = 0x100
|
|
138
|
+
jae Lmld_rej_uniform_eta4_avx2_asm_done
|
|
139
|
+
cmpl $0x110, %ecx # imm = 0x110
|
|
140
|
+
jae Lmld_rej_uniform_eta4_avx2_asm_done
|
|
141
|
+
movzbl (%rsi,%rcx), %r11d
|
|
142
|
+
incl %ecx
|
|
143
|
+
movl %r11d, %r10d
|
|
144
|
+
andl $0xf, %r10d
|
|
145
|
+
cmpl $0x9, %r10d
|
|
146
|
+
jae Lmld_rej_uniform_eta4_avx2_asm_high_nibble
|
|
147
|
+
movl $0x4, %r9d
|
|
148
|
+
subl %r10d, %r9d
|
|
149
|
+
movl %r9d, (%rdi,%rax,4)
|
|
150
|
+
incl %eax
|
|
151
|
+
cmpl $0x100, %eax # imm = 0x100
|
|
152
|
+
jae Lmld_rej_uniform_eta4_avx2_asm_done
|
|
153
|
+
|
|
154
|
+
Lmld_rej_uniform_eta4_avx2_asm_high_nibble:
|
|
155
|
+
shrl $0x4, %r11d
|
|
156
|
+
andl $0xf, %r11d
|
|
157
|
+
cmpl $0x9, %r11d
|
|
158
|
+
jae Lmld_rej_uniform_eta4_avx2_asm_scalar
|
|
159
|
+
movl $0x4, %r10d
|
|
160
|
+
subl %r11d, %r10d
|
|
161
|
+
movl %r10d, (%rdi,%rax,4)
|
|
162
|
+
incl %eax
|
|
163
|
+
jmp Lmld_rej_uniform_eta4_avx2_asm_scalar
|
|
164
|
+
|
|
165
|
+
Lmld_rej_uniform_eta4_avx2_asm_done:
|
|
166
|
+
retq
|
|
167
|
+
.cfi_endproc
|
|
168
|
+
|
|
169
|
+
MLD_ASM_FN_SIZE(rej_uniform_eta4_avx2_asm)
|
|
170
|
+
|
|
171
|
+
#endif /* MLD_ARITH_BACKEND_X86_64_DEFAULT && !MLD_CONFIG_MULTILEVEL_NO_SHARED \
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
#if defined(__ELF__)
|
|
175
|
+
.section .note.GNU-stack,"",%progbits
|
|
176
|
+
#endif
|
|
@@ -22,7 +22,7 @@ void mld_unpack_pk_t1(mld_poly *t1,
|
|
|
22
22
|
const uint8_t pk[MLDSA_CRYPTO_PUBLICKEYBYTES],
|
|
23
23
|
unsigned int i)
|
|
24
24
|
{
|
|
25
|
-
mld_polyt1_unpack(t1, pk +
|
|
25
|
+
mld_polyt1_unpack(t1, pk + MLDSA_PK_T1_OFFSET + i * MLDSA_POLYT1_PACKEDBYTES);
|
|
26
26
|
}
|
|
27
27
|
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
28
28
|
|
|
@@ -31,7 +31,7 @@ MLD_INTERNAL_API
|
|
|
31
31
|
void mld_pack_sk_s1(uint8_t sk[MLDSA_CRYPTO_SECRETKEYBYTES],
|
|
32
32
|
const mld_polyvecl *s1)
|
|
33
33
|
{
|
|
34
|
-
mld_polyvecl_pack_eta(sk +
|
|
34
|
+
mld_polyvecl_pack_eta(sk + MLDSA_SK_S1_OFFSET, s1);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
MLD_INTERNAL_API
|
|
@@ -41,19 +41,11 @@ void mld_pack_sk_rho_key_tr_s2(uint8_t sk[MLDSA_CRYPTO_SECRETKEYBYTES],
|
|
|
41
41
|
const uint8_t key[MLDSA_SEEDBYTES],
|
|
42
42
|
const mld_polyveck *s2)
|
|
43
43
|
{
|
|
44
|
-
mld_memcpy(sk, rho, MLDSA_SEEDBYTES);
|
|
45
|
-
sk
|
|
46
|
-
|
|
47
|
-
mld_memcpy(sk, key, MLDSA_SEEDBYTES);
|
|
48
|
-
sk += MLDSA_SEEDBYTES;
|
|
49
|
-
|
|
50
|
-
mld_memcpy(sk, tr, MLDSA_TRBYTES);
|
|
51
|
-
sk += MLDSA_TRBYTES;
|
|
52
|
-
|
|
44
|
+
mld_memcpy(sk + MLDSA_SK_RHO_OFFSET, rho, MLDSA_SEEDBYTES);
|
|
45
|
+
mld_memcpy(sk + MLDSA_SK_KEY_OFFSET, key, MLDSA_SEEDBYTES);
|
|
46
|
+
mld_memcpy(sk + MLDSA_SK_TR_OFFSET, tr, MLDSA_TRBYTES);
|
|
53
47
|
/* s1 already packed via mld_pack_sk_s1 */
|
|
54
|
-
sk
|
|
55
|
-
|
|
56
|
-
mld_polyveck_pack_eta(sk, s2);
|
|
48
|
+
mld_polyveck_pack_eta(sk + MLDSA_SK_S2_OFFSET, s2);
|
|
57
49
|
/* t0 already packed via mld_compute_pack_t0_t1 */
|
|
58
50
|
}
|
|
59
51
|
#endif /* !MLD_CONFIG_NO_KEYPAIR_API */
|
|
@@ -65,22 +57,12 @@ void mld_unpack_sk(uint8_t rho[MLDSA_SEEDBYTES], uint8_t tr[MLDSA_TRBYTES],
|
|
|
65
57
|
mld_sk_s1hat *s1, mld_sk_s2hat *s2,
|
|
66
58
|
const uint8_t sk[MLDSA_CRYPTO_SECRETKEYBYTES])
|
|
67
59
|
{
|
|
68
|
-
mld_memcpy(rho, sk, MLDSA_SEEDBYTES);
|
|
69
|
-
sk
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
sk
|
|
73
|
-
|
|
74
|
-
mld_memcpy(tr, sk, MLDSA_TRBYTES);
|
|
75
|
-
sk += MLDSA_TRBYTES;
|
|
76
|
-
|
|
77
|
-
mld_unpack_sk_s1hat(s1, sk);
|
|
78
|
-
sk += MLDSA_L * MLDSA_POLYETA_PACKEDBYTES;
|
|
79
|
-
|
|
80
|
-
mld_unpack_sk_s2hat(s2, sk);
|
|
81
|
-
sk += MLDSA_K * MLDSA_POLYETA_PACKEDBYTES;
|
|
82
|
-
|
|
83
|
-
mld_unpack_sk_t0hat(t0, sk);
|
|
60
|
+
mld_memcpy(rho, sk + MLDSA_SK_RHO_OFFSET, MLDSA_SEEDBYTES);
|
|
61
|
+
mld_memcpy(key, sk + MLDSA_SK_KEY_OFFSET, MLDSA_SEEDBYTES);
|
|
62
|
+
mld_memcpy(tr, sk + MLDSA_SK_TR_OFFSET, MLDSA_TRBYTES);
|
|
63
|
+
mld_unpack_sk_s1hat(s1, sk + MLDSA_SK_S1_OFFSET);
|
|
64
|
+
mld_unpack_sk_s2hat(s2, sk + MLDSA_SK_S2_OFFSET);
|
|
65
|
+
mld_unpack_sk_t0hat(t0, sk + MLDSA_SK_T0_OFFSET);
|
|
84
66
|
}
|
|
85
67
|
|
|
86
68
|
MLD_INTERNAL_API
|
|
@@ -104,7 +86,7 @@ int mld_pack_sig_h(uint8_t sig[MLDSA_CRYPTO_BYTES], const mld_polyveck *w0,
|
|
|
104
86
|
*
|
|
105
87
|
* The final K bytes record a running tally of the number of hints
|
|
106
88
|
* coming from each of the K polynomials. */
|
|
107
|
-
uint8_t *sig_h = sig +
|
|
89
|
+
uint8_t *sig_h = sig + MLDSA_SIG_H_OFFSET;
|
|
108
90
|
|
|
109
91
|
mld_memset(sig_h, 0, MLDSA_POLYVECH_PACKEDBYTES);
|
|
110
92
|
n = 0;
|
|
@@ -157,9 +139,7 @@ MLD_INTERNAL_API
|
|
|
157
139
|
void mld_pack_sig_z(uint8_t sig[MLDSA_CRYPTO_BYTES], const mld_poly *zi,
|
|
158
140
|
unsigned i)
|
|
159
141
|
{
|
|
160
|
-
sig
|
|
161
|
-
sig += i * MLDSA_POLYZ_PACKEDBYTES;
|
|
162
|
-
mld_polyz_pack(sig, zi);
|
|
142
|
+
mld_polyz_pack(sig + MLDSA_SIG_Z_OFFSET + i * MLDSA_POLYZ_PACKEDBYTES, zi);
|
|
163
143
|
}
|
|
164
144
|
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
165
145
|
|
|
@@ -168,8 +148,7 @@ MLD_INTERNAL_API
|
|
|
168
148
|
int mld_sig_unpack_hints(mld_poly *h, const uint8_t sig[MLDSA_CRYPTO_BYTES],
|
|
169
149
|
unsigned int i)
|
|
170
150
|
{
|
|
171
|
-
const uint8_t *packed_hints =
|
|
172
|
-
sig + MLDSA_CTILDEBYTES + MLDSA_L * MLDSA_POLYZ_PACKEDBYTES;
|
|
151
|
+
const uint8_t *packed_hints = sig + MLDSA_SIG_H_OFFSET;
|
|
173
152
|
const unsigned int old_hint_count =
|
|
174
153
|
(i == 0) ? 0 : packed_hints[MLDSA_OMEGA + i - 1];
|
|
175
154
|
const unsigned int new_hint_count = packed_hints[MLDSA_OMEGA + i];
|
|
@@ -187,6 +166,9 @@ int mld_sig_unpack_hints(mld_poly *h, const uint8_t sig[MLDSA_CRYPTO_BYTES],
|
|
|
187
166
|
invariant(j >= old_hint_count && j <= new_hint_count &&
|
|
188
167
|
new_hint_count <= MLDSA_OMEGA)
|
|
189
168
|
invariant(array_bound(h->coeffs, 0, MLDSA_N, 0, 2))
|
|
169
|
+
invariant(forall(p, 0, MLDSA_N,
|
|
170
|
+
(h->coeffs[p] == 1) ==
|
|
171
|
+
exists(hj, old_hint_count, j, packed_hints[hj] == p)))
|
|
190
172
|
decreases(new_hint_count - j)
|
|
191
173
|
)
|
|
192
174
|
{
|
|
@@ -214,6 +196,15 @@ int mld_sig_unpack_hints(mld_poly *h, const uint8_t sig[MLDSA_CRYPTO_BYTES],
|
|
|
214
196
|
}
|
|
215
197
|
}
|
|
216
198
|
|
|
199
|
+
/* On success, h->coeffs[p] is 1 exactly for the hint indices decoded for this
|
|
200
|
+
* row, i.e. packed_hints[old_hint_count, new_hint_count). Asserted here
|
|
201
|
+
* rather than posted as a contract to not unnecessarily increase proof
|
|
202
|
+
* complexity at callers that do not need the functional description. */
|
|
203
|
+
cassert(forall(
|
|
204
|
+
p, 0, MLDSA_N,
|
|
205
|
+
(h->coeffs[p] == 1) ==
|
|
206
|
+
exists(hj, old_hint_count, new_hint_count, packed_hints[hj] == p)));
|
|
207
|
+
|
|
217
208
|
return 0;
|
|
218
209
|
}
|
|
219
210
|
#endif /* !MLD_CONFIG_NO_VERIFY_API */
|
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
* Copyright (c) The mldsa-native project authors
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
|
4
4
|
*/
|
|
5
|
+
|
|
6
|
+
/* References
|
|
7
|
+
* ==========
|
|
8
|
+
*
|
|
9
|
+
* - [FIPS204]
|
|
10
|
+
* FIPS 204 Module-Lattice-Based Digital Signature Standard
|
|
11
|
+
* National Institute of Standards and Technology
|
|
12
|
+
* https://csrc.nist.gov/pubs/fips/204/final
|
|
13
|
+
*/
|
|
14
|
+
|
|
5
15
|
#ifndef MLD_PACKING_H
|
|
6
16
|
#define MLD_PACKING_H
|
|
7
17
|
|
|
@@ -13,6 +23,9 @@
|
|
|
13
23
|
/**
|
|
14
24
|
* Bit-pack the s1 component into the secret key.
|
|
15
25
|
*
|
|
26
|
+
* @spec{Partially implements @[FIPS204, Algorithm 24, skEncode] (s1
|
|
27
|
+
* component).}
|
|
28
|
+
*
|
|
16
29
|
* @param[out] sk Output byte array.
|
|
17
30
|
* @param[in] s1 Pointer to vector s1.
|
|
18
31
|
*/
|
|
@@ -34,6 +47,9 @@ __contract__(
|
|
|
34
47
|
* s1 must already be packed via mld_pack_sk_s1, and t0 via
|
|
35
48
|
* mld_compute_pack_t0_t1.
|
|
36
49
|
*
|
|
50
|
+
* @spec{Partially implements @[FIPS204, Algorithm 24, skEncode] (rho, key, tr,
|
|
51
|
+
* s2 components).}
|
|
52
|
+
*
|
|
37
53
|
* @param[out] sk Output byte array.
|
|
38
54
|
* @param[in] rho Byte array containing rho.
|
|
39
55
|
* @param[in] tr Byte array containing tr.
|
|
@@ -64,6 +80,9 @@ __contract__(
|
|
|
64
80
|
/**
|
|
65
81
|
* Bit-pack challenge c into sig = (c, z, h).
|
|
66
82
|
*
|
|
83
|
+
* @spec{Partially implements @[FIPS204, Algorithm 26, sigEncode] (c
|
|
84
|
+
* component).}
|
|
85
|
+
*
|
|
67
86
|
* @param[out] sig Output byte array.
|
|
68
87
|
* @param[in] c Pointer to challenge hash.
|
|
69
88
|
*/
|
|
@@ -80,6 +99,14 @@ __contract__(
|
|
|
80
99
|
/**
|
|
81
100
|
* Compute hints from (w0, w1) and pack them into the hint section of sig.
|
|
82
101
|
*
|
|
102
|
+
* @spec{Combines the hint computation @[FIPS204, Algorithm 39, MakeHint] with
|
|
103
|
+
* the packing @[FIPS204, Algorithm 20, HintBitPack] (the h component of
|
|
104
|
+
* @[FIPS204, Algorithm 26, sigEncode]): it computes the hint vector h from
|
|
105
|
+
* (w0, w1) and packs it, rather than receiving a ready-made h as HintBitPack
|
|
106
|
+
* does. The hints are computed via mld_make_hint (rounding.h), a specialized
|
|
107
|
+
* MakeHint valid only for the values arising during signing; see the block
|
|
108
|
+
* comment in mld_attempt_signature_generation (sign.c).}
|
|
109
|
+
*
|
|
83
110
|
* @param[in,out] sig Byte array containing signature.
|
|
84
111
|
* @param[in] w0 Pointer to low part of input vector.
|
|
85
112
|
* @param[in] w1 Pointer to high part of input vector.
|
|
@@ -98,9 +125,7 @@ __contract__(
|
|
|
98
125
|
requires(memory_no_alias(sig, MLDSA_CRYPTO_BYTES))
|
|
99
126
|
requires(memory_no_alias(w0, sizeof(mld_polyveck)))
|
|
100
127
|
requires(memory_no_alias(w1, sizeof(mld_polyveck)))
|
|
101
|
-
assigns(memory_slice(
|
|
102
|
-
sig + MLDSA_CTILDEBYTES + MLDSA_L * MLDSA_POLYZ_PACKEDBYTES,
|
|
103
|
-
MLDSA_POLYVECH_PACKEDBYTES))
|
|
128
|
+
assigns(memory_slice(sig + MLDSA_SIG_H_OFFSET, MLDSA_POLYVECH_PACKEDBYTES))
|
|
104
129
|
ensures(return_value == 0 || return_value == MLD_ERR_FAIL)
|
|
105
130
|
);
|
|
106
131
|
|
|
@@ -111,6 +136,9 @@ __contract__(
|
|
|
111
136
|
* The c and h components are packed separately using mld_pack_sig_c and
|
|
112
137
|
* mld_pack_sig_h.
|
|
113
138
|
*
|
|
139
|
+
* @spec{Partially implements @[FIPS204, Algorithm 26, sigEncode] (one
|
|
140
|
+
* polynomial of the z component).}
|
|
141
|
+
*
|
|
114
142
|
* @param[in,out] sig Output byte array.
|
|
115
143
|
* @param[in] zi Pointer to a single polynomial in z.
|
|
116
144
|
* @param i Index of zi in vector z.
|
|
@@ -133,6 +161,9 @@ __contract__(
|
|
|
133
161
|
* Unpack a single polynomial of the t1 component of a public key
|
|
134
162
|
* pk = (rho, t1).
|
|
135
163
|
*
|
|
164
|
+
* @spec{Partially implements @[FIPS204, Algorithm 23, pkDecode] (one polynomial
|
|
165
|
+
* of t1).}
|
|
166
|
+
*
|
|
136
167
|
* @param[out] t1 Pointer to output polynomial t1[i].
|
|
137
168
|
* @param[in] pk Byte array containing bit-packed pk.
|
|
138
169
|
* @param i Row index, must be < MLDSA_K.
|
|
@@ -157,6 +188,8 @@ __contract__(
|
|
|
157
188
|
*
|
|
158
189
|
* NOTE: In REDUCE_RAM mode, s1/s2/t0 borrow from sk rather than copying.
|
|
159
190
|
*
|
|
191
|
+
* @spec{Implements @[FIPS204, Algorithm 25, skDecode].}
|
|
192
|
+
*
|
|
160
193
|
* @param[out] rho Output byte array for rho.
|
|
161
194
|
* @param[out] tr Output byte array for tr.
|
|
162
195
|
* @param[out] key Output byte array for key.
|
|
@@ -193,11 +226,9 @@ __contract__(
|
|
|
193
226
|
array_abs_bound(s2->vec.vec[k2].coeffs, 0, MLDSA_N, MLD_NTT_BOUND)))
|
|
194
227
|
)
|
|
195
228
|
MLD_IF_REDUCE_RAM(
|
|
196
|
-
ensures(s1->packed == old(sk) +
|
|
197
|
-
ensures(s2->packed == old(sk) +
|
|
198
|
-
|
|
199
|
-
ensures(t0->packed == old(sk) + 2 * MLDSA_SEEDBYTES + MLDSA_TRBYTES +
|
|
200
|
-
(MLDSA_L + MLDSA_K) * MLDSA_POLYETA_PACKEDBYTES)
|
|
229
|
+
ensures(s1->packed == old(sk) + MLDSA_SK_S1_OFFSET)
|
|
230
|
+
ensures(s2->packed == old(sk) + MLDSA_SK_S2_OFFSET)
|
|
231
|
+
ensures(t0->packed == old(sk) + MLDSA_SK_T0_OFFSET)
|
|
201
232
|
)
|
|
202
233
|
);
|
|
203
234
|
#endif /* !MLD_CONFIG_NO_SIGN_API */
|
|
@@ -219,6 +250,9 @@ __contract__(
|
|
|
219
250
|
* call returns MLD_ERR_FAIL the encoding is malformed and the signature must
|
|
220
251
|
* be rejected.
|
|
221
252
|
*
|
|
253
|
+
* @spec{Implements @[FIPS204, Algorithm 21, HintBitUnpack] (one row; part of
|
|
254
|
+
* @[FIPS204, Algorithm 27, sigDecode]).}
|
|
255
|
+
*
|
|
222
256
|
* @param[out] h Pointer to output polynomial h[i].
|
|
223
257
|
* @param[in] sig Signature buffer.
|
|
224
258
|
* @param i Row index, must be < MLDSA_K.
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
#define MLDSA_Q_HALF ((MLDSA_Q + 1) / 2)
|
|
15
15
|
#define MLDSA_D 13
|
|
16
16
|
|
|
17
|
+
#define MLDSA_GAMMA2_88 ((MLDSA_Q - 1) / 88)
|
|
18
|
+
#define MLDSA_GAMMA2_32 ((MLDSA_Q - 1) / 32)
|
|
19
|
+
#define MLDSA_POLYW1_PACKEDBYTES_88 192
|
|
20
|
+
#define MLDSA_POLYW1_PACKEDBYTES_32 128
|
|
21
|
+
|
|
17
22
|
#if MLD_CONFIG_PARAMETER_SET == 44
|
|
18
23
|
|
|
19
24
|
#define MLDSA_K 4
|
|
@@ -21,12 +26,12 @@
|
|
|
21
26
|
#define MLDSA_ETA 2
|
|
22
27
|
#define MLDSA_TAU 39
|
|
23
28
|
#define MLDSA_BETA 78
|
|
24
|
-
#define MLDSA_GAMMA1 (1 << 17)
|
|
25
|
-
#define MLDSA_GAMMA2
|
|
29
|
+
#define MLDSA_GAMMA1 ((int32_t)1 << 17)
|
|
30
|
+
#define MLDSA_GAMMA2 MLDSA_GAMMA2_88
|
|
26
31
|
#define MLDSA_OMEGA 80
|
|
27
32
|
#define MLDSA_CTILDEBYTES 32
|
|
28
33
|
#define MLDSA_POLYZ_PACKEDBYTES 576
|
|
29
|
-
#define MLDSA_POLYW1_PACKEDBYTES
|
|
34
|
+
#define MLDSA_POLYW1_PACKEDBYTES MLDSA_POLYW1_PACKEDBYTES_88
|
|
30
35
|
#define MLDSA_POLYETA_PACKEDBYTES 96
|
|
31
36
|
|
|
32
37
|
#elif MLD_CONFIG_PARAMETER_SET == 65
|
|
@@ -36,12 +41,12 @@
|
|
|
36
41
|
#define MLDSA_ETA 4
|
|
37
42
|
#define MLDSA_TAU 49
|
|
38
43
|
#define MLDSA_BETA 196
|
|
39
|
-
#define MLDSA_GAMMA1 (1 << 19)
|
|
40
|
-
#define MLDSA_GAMMA2
|
|
44
|
+
#define MLDSA_GAMMA1 ((int32_t)1 << 19)
|
|
45
|
+
#define MLDSA_GAMMA2 MLDSA_GAMMA2_32
|
|
41
46
|
#define MLDSA_OMEGA 55
|
|
42
47
|
#define MLDSA_CTILDEBYTES 48
|
|
43
48
|
#define MLDSA_POLYZ_PACKEDBYTES 640
|
|
44
|
-
#define MLDSA_POLYW1_PACKEDBYTES
|
|
49
|
+
#define MLDSA_POLYW1_PACKEDBYTES MLDSA_POLYW1_PACKEDBYTES_32
|
|
45
50
|
#define MLDSA_POLYETA_PACKEDBYTES 128
|
|
46
51
|
|
|
47
52
|
#elif MLD_CONFIG_PARAMETER_SET == 87
|
|
@@ -51,12 +56,12 @@
|
|
|
51
56
|
#define MLDSA_ETA 2
|
|
52
57
|
#define MLDSA_TAU 60
|
|
53
58
|
#define MLDSA_BETA 120
|
|
54
|
-
#define MLDSA_GAMMA1 (1 << 19)
|
|
55
|
-
#define MLDSA_GAMMA2
|
|
59
|
+
#define MLDSA_GAMMA1 ((int32_t)1 << 19)
|
|
60
|
+
#define MLDSA_GAMMA2 MLDSA_GAMMA2_32
|
|
56
61
|
#define MLDSA_OMEGA 75
|
|
57
62
|
#define MLDSA_CTILDEBYTES 64
|
|
58
63
|
#define MLDSA_POLYZ_PACKEDBYTES 640
|
|
59
|
-
#define MLDSA_POLYW1_PACKEDBYTES
|
|
64
|
+
#define MLDSA_POLYW1_PACKEDBYTES MLDSA_POLYW1_PACKEDBYTES_32
|
|
60
65
|
#define MLDSA_POLYETA_PACKEDBYTES 96
|
|
61
66
|
|
|
62
67
|
#endif /* MLD_CONFIG_PARAMETER_SET == 87 */
|
|
@@ -65,13 +70,84 @@
|
|
|
65
70
|
#define MLDSA_POLYT0_PACKEDBYTES 416
|
|
66
71
|
#define MLDSA_POLYVECH_PACKEDBYTES (MLDSA_OMEGA + MLDSA_K)
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
/* Sampling y from counter kappa uses nonces kappa, ..., kappa+L-1, which fit in
|
|
74
|
+
* uint16_t iff kappa <= UINT16_MAX - MLDSA_L. With kappa = attempt*MLDSA_L this
|
|
75
|
+
* bounds the number of signing attempts by MLD_MAX_KAPPA / MLDSA_L; see
|
|
76
|
+
* MLD_MAX_SIGNING_ATTEMPTS in sign.c. */
|
|
77
|
+
#define MLD_MAX_KAPPA (UINT16_MAX - MLDSA_L)
|
|
78
|
+
|
|
79
|
+
/* Layout of the packed public key pk[MLDSA_CRYPTO_PUBLICKEYBYTES] = (rho, t1):
|
|
80
|
+
*
|
|
81
|
+
* +-------------+--------------------------+
|
|
82
|
+
* | rho | t1 |
|
|
83
|
+
* +-------------+--------------------------+
|
|
84
|
+
* | SEEDBYTES | K * POLYT1_PACKEDBYTES |
|
|
85
|
+
* +-------------+--------------------------+
|
|
86
|
+
*/
|
|
87
|
+
#define MLDSA_PK_RHO_OFFSET 0
|
|
88
|
+
#define MLDSA_PK_RHO_BYTES MLDSA_SEEDBYTES
|
|
89
|
+
|
|
90
|
+
#define MLDSA_PK_T1_OFFSET (MLDSA_PK_RHO_OFFSET + MLDSA_PK_RHO_BYTES)
|
|
91
|
+
#define MLDSA_PK_T1_BYTES (MLDSA_K * MLDSA_POLYT1_PACKEDBYTES)
|
|
92
|
+
|
|
93
|
+
#define MLDSA_PK_END (MLDSA_PK_T1_OFFSET + MLDSA_PK_T1_BYTES)
|
|
94
|
+
|
|
95
|
+
#define MLDSA_CRYPTO_PUBLICKEYBYTES MLDSA_PK_END
|
|
96
|
+
|
|
97
|
+
/* Layout of the packed secret key
|
|
98
|
+
* sk[MLDSA_CRYPTO_SECRETKEYBYTES] = (rho, key, tr, s1, s2, t0):
|
|
99
|
+
*
|
|
100
|
+
* +-----------+-----------+-----------+-----------+-----------+-----------+
|
|
101
|
+
* | rho | key | tr | s1 | s2 | t0 |
|
|
102
|
+
* +-----------+-----------+-----------+-----------+-----------+-----------+
|
|
103
|
+
* | SEEDBYTES | SEEDBYTES | TRBYTES | L * | K * | K * |
|
|
104
|
+
* | | | | POLYETA_ | POLYETA_ | POLYT0_ |
|
|
105
|
+
* | | | | PACKED- | PACKED- | PACKED- |
|
|
106
|
+
* | | | | BYTES | BYTES | BYTES |
|
|
107
|
+
* +-----------+-----------+-----------+-----------+-----------+-----------+
|
|
108
|
+
*/
|
|
109
|
+
#define MLDSA_SK_RHO_OFFSET 0
|
|
110
|
+
#define MLDSA_SK_RHO_BYTES MLDSA_SEEDBYTES
|
|
111
|
+
|
|
112
|
+
#define MLDSA_SK_KEY_OFFSET (MLDSA_SK_RHO_OFFSET + MLDSA_SK_RHO_BYTES)
|
|
113
|
+
#define MLDSA_SK_KEY_BYTES MLDSA_SEEDBYTES
|
|
114
|
+
|
|
115
|
+
#define MLDSA_SK_TR_OFFSET (MLDSA_SK_KEY_OFFSET + MLDSA_SK_KEY_BYTES)
|
|
116
|
+
#define MLDSA_SK_TR_BYTES MLDSA_TRBYTES
|
|
117
|
+
|
|
118
|
+
#define MLDSA_SK_S1_OFFSET (MLDSA_SK_TR_OFFSET + MLDSA_SK_TR_BYTES)
|
|
119
|
+
#define MLDSA_SK_S1_BYTES (MLDSA_L * MLDSA_POLYETA_PACKEDBYTES)
|
|
120
|
+
|
|
121
|
+
#define MLDSA_SK_S2_OFFSET (MLDSA_SK_S1_OFFSET + MLDSA_SK_S1_BYTES)
|
|
122
|
+
#define MLDSA_SK_S2_BYTES (MLDSA_K * MLDSA_POLYETA_PACKEDBYTES)
|
|
123
|
+
|
|
124
|
+
#define MLDSA_SK_T0_OFFSET (MLDSA_SK_S2_OFFSET + MLDSA_SK_S2_BYTES)
|
|
125
|
+
#define MLDSA_SK_T0_BYTES (MLDSA_K * MLDSA_POLYT0_PACKEDBYTES)
|
|
126
|
+
|
|
127
|
+
#define MLDSA_SK_END (MLDSA_SK_T0_OFFSET + MLDSA_SK_T0_BYTES)
|
|
128
|
+
|
|
129
|
+
#define MLDSA_CRYPTO_SECRETKEYBYTES MLDSA_SK_END
|
|
130
|
+
|
|
131
|
+
/* Layout of the packed signature sig[MLDSA_CRYPTO_BYTES] = (c, z, h):
|
|
132
|
+
*
|
|
133
|
+
* +----------------+-------------------+----------------------+
|
|
134
|
+
* | c (challenge) | z | h (hints) |
|
|
135
|
+
* +----------------+-------------------+----------------------+
|
|
136
|
+
* | CTILDEBYTES | L * | POLYVECH_PACKEDBYTES |
|
|
137
|
+
* | | POLYZ_PACKEDBYTES | (= OMEGA + K) |
|
|
138
|
+
* +----------------+-------------------+----------------------+
|
|
139
|
+
*/
|
|
140
|
+
#define MLDSA_SIG_C_OFFSET 0
|
|
141
|
+
#define MLDSA_SIG_C_BYTES MLDSA_CTILDEBYTES
|
|
142
|
+
|
|
143
|
+
#define MLDSA_SIG_Z_OFFSET (MLDSA_SIG_C_OFFSET + MLDSA_SIG_C_BYTES)
|
|
144
|
+
#define MLDSA_SIG_Z_BYTES (MLDSA_L * MLDSA_POLYZ_PACKEDBYTES)
|
|
145
|
+
|
|
146
|
+
#define MLDSA_SIG_H_OFFSET (MLDSA_SIG_Z_OFFSET + MLDSA_SIG_Z_BYTES)
|
|
147
|
+
#define MLDSA_SIG_H_BYTES MLDSA_POLYVECH_PACKEDBYTES
|
|
148
|
+
|
|
149
|
+
#define MLDSA_SIG_END (MLDSA_SIG_H_OFFSET + MLDSA_SIG_H_BYTES)
|
|
150
|
+
|
|
151
|
+
#define MLDSA_CRYPTO_BYTES MLDSA_SIG_END
|
|
76
152
|
|
|
77
153
|
#endif /* !MLD_PARAMS_H */
|