pq_crypto 0.3.2 → 0.5.0
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/.github/workflows/ci.yml +56 -0
- data/CHANGELOG.md +62 -0
- data/GET_STARTED.md +366 -40
- data/README.md +76 -233
- data/SECURITY.md +107 -82
- data/ext/pqcrypto/extconf.rb +169 -87
- data/ext/pqcrypto/mldsa_api.h +1 -48
- data/ext/pqcrypto/mlkem_api.h +1 -18
- data/ext/pqcrypto/pq_externalmu.c +89 -204
- data/ext/pqcrypto/pqcrypto_native_api.h +129 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +484 -84
- data/ext/pqcrypto/pqcrypto_secure.c +203 -78
- data/ext/pqcrypto/pqcrypto_secure.h +53 -14
- data/ext/pqcrypto/pqcrypto_version.h +7 -0
- data/ext/pqcrypto/randombytes.h +9 -0
- data/ext/pqcrypto/vendor/.vendored +10 -5
- data/ext/pqcrypto/vendor/mldsa-native/BUILDING.md +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/LICENSE +286 -0
- data/ext/pqcrypto/vendor/mldsa-native/META.yml +24 -0
- data/ext/pqcrypto/vendor/mldsa-native/README.md +221 -0
- data/ext/pqcrypto/vendor/mldsa-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.c +721 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native.h +975 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_asm.S +724 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/mldsa_native_config.h +723 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/cbmc.h +166 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/common.h +321 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.c +21 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/ct.h +385 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.c +73 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/debug.h +130 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.c +277 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202.h +244 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.c +182 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/fips202x4.h +117 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.c +438 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/keccakf1600.h +105 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/auto.h +71 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/fips202_native_aarch64.h +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +376 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +204 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +259 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1077 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +987 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +41 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x1_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x2_v84a.h +37 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_scalar.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +36 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/api.h +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/mve.h +32 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/fips202_native_armv81m.h +20 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +638 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +136 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/auto.h +29 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.c +488 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/src/KeccakP_1600_times4_SIMD256.h +16 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/fips202/native/x86_64/xkcp.h +31 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/meta.h +247 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/aarch64_zetas.c +231 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/arith_native_aarch64.h +150 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/intt.S +753 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l4.S +129 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l5.S +145 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/mld_polyvecl_pointwise_acc_montgomery_l7.S +177 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/ntt.S +653 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/pointwise_montgomery.S +79 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_caddq_asm.S +53 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_chknorm_asm.S +55 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_32_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_decompose_88_asm.S +85 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_32_asm.S +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/poly_use_hint_88_asm.S +110 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_17_asm.S +72 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_19_asm.S +69 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/polyz_unpack_table.c +40 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_asm.S +189 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta2_asm.S +135 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta4_asm.S +128 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_eta_table.c +543 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/aarch64/src/rej_uniform_table.c +62 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/api.h +649 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/meta.h +23 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/meta.h +315 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/arith_native_x86_64.h +124 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.c +157 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/consts.h +27 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/intt.S +2311 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/ntt.S +2383 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/nttunpack.S +239 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise.S +131 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l4.S +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l5.S +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/pointwise_acc_l7.S +187 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_caddq_avx2.c +61 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_chknorm_avx2.c +52 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_32_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_decompose_88_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_32_avx2.c +102 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/poly_use_hint_88_avx2.c +104 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_17_avx2.c +91 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/polyz_unpack_19_avx2.c +93 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_avx2.c +126 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta2_avx2.c +155 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_eta4_avx2.c +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/native/x86_64/src/rej_uniform_table.c +160 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.c +293 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/packing.h +224 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/params.h +77 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.c +991 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly.h +393 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.c +946 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/poly_kl.h +360 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.c +877 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/polyvec.h +725 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/randombytes.h +26 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/reduce.h +139 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/rounding.h +249 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.c +1511 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sign.h +806 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/symmetric.h +68 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/sys.h +268 -0
- data/ext/pqcrypto/vendor/mldsa-native/mldsa/src/zetas.inc +55 -0
- data/ext/pqcrypto/vendor/mlkem-native/BUILDING.md +104 -0
- data/ext/pqcrypto/vendor/mlkem-native/LICENSE +294 -0
- data/ext/pqcrypto/vendor/mlkem-native/META.yml +30 -0
- data/ext/pqcrypto/vendor/mlkem-native/README.md +223 -0
- data/ext/pqcrypto/vendor/mlkem-native/RELEASE.md +86 -0
- data/ext/pqcrypto/vendor/mlkem-native/SECURITY.md +8 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/README.md +23 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.c +660 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native.h +538 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_asm.S +681 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/mlkem_native_config.h +709 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/cbmc.h +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/common.h +274 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.c +717 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/compress.h +688 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.c +64 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/debug.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.c +251 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202.h +158 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.c +208 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/fips202x4.h +80 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.c +463 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/keccakf1600.h +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/auto.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/fips202_native_aarch64.h +69 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_scalar_asm.S +375 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x1_v84a_asm.S +203 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x2_v84a_asm.S +258 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_scalar_hybrid_asm.S +1076 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccak_f1600_x4_v8a_v84a_scalar_hybrid_asm.S +986 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/src/keccakf1600_round_constants.c +46 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_scalar.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x1_v84a.h +34 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x2_v84a.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +26 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/api.h +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/README.md +10 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/mve.h +79 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/fips202_native_armv81m.h +35 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.S +667 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccak_f1600_x4_mve.c +40 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/keccakf1600_round_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_extract_bytes_x4_mve.S +290 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/armv81m/src/state_xor_bytes_x4_mve.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/auto.h +28 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +33 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h +41 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccak_f1600_x4_avx2.S +451 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/fips202/native/x86_64/src/keccakf1600_constants.c +51 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.c +622 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/indcpa.h +156 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.c +446 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/kem.h +326 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/README.md +16 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/meta.h +122 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/aarch64_zetas.c +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/arith_native_aarch64.h +177 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/intt.S +628 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/ntt.S +562 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_mulcache_compute_asm.S +127 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_reduce_asm.S +150 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tobytes_asm.S +117 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/poly_tomont_asm.S +98 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +261 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +314 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +368 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_asm.S +226 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/aarch64/src/rej_uniform_table.c +542 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/api.h +637 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/meta.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/README.md +11 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/meta.h +128 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/arith_native_riscv64.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.c +81 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_debug.h +145 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_izetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_poly.c +805 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas.inc +27 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/riscv64/src/rv64v_zetas_basemul.inc +39 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/README.md +4 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/meta.h +304 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/arith_native_x86_64.h +309 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.c +94 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/compress_consts.h +45 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.c +102 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/consts.h +25 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/intt.S +719 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/mulcache_compute.S +90 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntt.S +639 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttfrombytes.S +193 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/ntttobytes.S +181 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/nttunpack.S +174 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d10.S +382 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d11.S +448 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d4.S +163 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_compress_d5.S +220 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d10.S +228 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d11.S +277 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d4.S +180 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/poly_decompress_d5.S +192 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S +750 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S +998 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/reduce.S +218 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_asm.S +103 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/rej_uniform_table.c +544 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/native/x86_64/src/tomont.S +155 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/params.h +76 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.c +572 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly.h +317 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.c +502 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/poly_k.h +668 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/randombytes.h +60 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.c +362 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sampling.h +118 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/symmetric.h +70 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/sys.h +260 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.c +20 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/verify.h +464 -0
- data/ext/pqcrypto/vendor/mlkem-native/mlkem/src/zetas.inc +30 -0
- data/lib/pq_crypto/algorithm_registry.rb +200 -0
- data/lib/pq_crypto/hybrid_kem.rb +1 -12
- data/lib/pq_crypto/kem.rb +104 -13
- data/lib/pq_crypto/pkcs8.rb +387 -0
- data/lib/pq_crypto/serialization.rb +1 -14
- data/lib/pq_crypto/signature.rb +123 -17
- data/lib/pq_crypto/spki.rb +131 -0
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +79 -20
- data/script/vendor_libs.rb +88 -155
- metadata +241 -73
- data/ext/pqcrypto/vendor/pqclean/common/aes.c +0 -639
- data/ext/pqcrypto/vendor/pqclean/common/aes.h +0 -64
- data/ext/pqcrypto/vendor/pqclean/common/compat.h +0 -73
- data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +0 -7
- data/ext/pqcrypto/vendor/pqclean/common/fips202.c +0 -928
- data/ext/pqcrypto/vendor/pqclean/common/fips202.h +0 -166
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +0 -168
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +0 -684
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +0 -60
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +0 -1028
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +0 -198
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +0 -8
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +0 -3
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +0 -34
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +0 -142
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +0 -101
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +0 -39
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +0 -355
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/common/sha2.c +0 -769
- data/ext/pqcrypto/vendor/pqclean/common/sha2.h +0 -173
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +0 -156
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +0 -27
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +0 -18
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +0 -83
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +0 -11
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +0 -327
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +0 -22
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +0 -164
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +0 -146
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +0 -36
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +0 -299
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +0 -37
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +0 -188
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +0 -41
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +0 -71
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +0 -30
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +0 -67
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +0 -13
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +0 -5
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +0 -19
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +0 -23
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +0 -50
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +0 -98
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +0 -10
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +0 -261
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +0 -31
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +0 -44
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +0 -799
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +0 -52
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +0 -415
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +0 -65
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +0 -69
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +0 -17
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +0 -92
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +0 -14
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +0 -407
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +0 -47
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +0 -26
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +0 -34
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The MIT License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2017 Daan Sprenkels <hello@dsprenkels.com>
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in
|
|
14
|
-
all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
-
THE SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
// In the case that are compiling on linux, we need to define _GNU_SOURCE
|
|
25
|
-
// *before* randombytes.h is included. Otherwise SYS_getrandom will not be
|
|
26
|
-
// declared.
|
|
27
|
-
#if defined(__linux__)
|
|
28
|
-
# define _GNU_SOURCE
|
|
29
|
-
#endif /* defined(__linux__) */
|
|
30
|
-
|
|
31
|
-
#include "randombytes.h"
|
|
32
|
-
|
|
33
|
-
#if defined(_WIN32)
|
|
34
|
-
/* Windows */
|
|
35
|
-
# include <windows.h>
|
|
36
|
-
# include <wincrypt.h> /* CryptAcquireContext, CryptGenRandom */
|
|
37
|
-
#endif /* defined(_WIN32) */
|
|
38
|
-
|
|
39
|
-
/* wasi */
|
|
40
|
-
#if defined(__wasi__)
|
|
41
|
-
#include <stdlib.h>
|
|
42
|
-
#endif
|
|
43
|
-
|
|
44
|
-
#if defined(__linux__)
|
|
45
|
-
/* Linux */
|
|
46
|
-
// We would need to include <linux/random.h>, but not every target has access
|
|
47
|
-
// to the linux headers. We only need RNDGETENTCNT, so we instead inline it.
|
|
48
|
-
// RNDGETENTCNT is originally defined in `include/uapi/linux/random.h` in the
|
|
49
|
-
// linux repo.
|
|
50
|
-
# define RNDGETENTCNT 0x80045200
|
|
51
|
-
|
|
52
|
-
# include <assert.h>
|
|
53
|
-
# include <errno.h>
|
|
54
|
-
# include <fcntl.h>
|
|
55
|
-
# include <poll.h>
|
|
56
|
-
# include <stdint.h>
|
|
57
|
-
# include <stdio.h>
|
|
58
|
-
# include <sys/ioctl.h>
|
|
59
|
-
# if defined(__linux__) && defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC_MINOR__ > 24))
|
|
60
|
-
# define USE_GLIBC
|
|
61
|
-
# include <sys/random.h>
|
|
62
|
-
# endif /* defined(__linux__) && defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC_MINOR__ > 24)) */
|
|
63
|
-
# include <sys/stat.h>
|
|
64
|
-
# include <sys/syscall.h>
|
|
65
|
-
# include <sys/types.h>
|
|
66
|
-
# include <unistd.h>
|
|
67
|
-
|
|
68
|
-
// We need SSIZE_MAX as the maximum read len from /dev/urandom
|
|
69
|
-
# if !defined(SSIZE_MAX)
|
|
70
|
-
# define SSIZE_MAX (SIZE_MAX / 2 - 1)
|
|
71
|
-
# endif /* defined(SSIZE_MAX) */
|
|
72
|
-
|
|
73
|
-
#endif /* defined(__linux__) */
|
|
74
|
-
|
|
75
|
-
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
76
|
-
/* Dragonfly, FreeBSD, NetBSD, OpenBSD (has arc4random) */
|
|
77
|
-
# include <sys/param.h>
|
|
78
|
-
# if defined(BSD)
|
|
79
|
-
# include <stdlib.h>
|
|
80
|
-
# endif
|
|
81
|
-
#endif
|
|
82
|
-
|
|
83
|
-
#if defined(__EMSCRIPTEN__)
|
|
84
|
-
# include <assert.h>
|
|
85
|
-
# include <emscripten.h>
|
|
86
|
-
# include <errno.h>
|
|
87
|
-
# include <stdbool.h>
|
|
88
|
-
#endif /* defined(__EMSCRIPTEN__) */
|
|
89
|
-
|
|
90
|
-
#if defined(_WIN32)
|
|
91
|
-
static int randombytes_win32_randombytes(void *buf, const size_t n) {
|
|
92
|
-
HCRYPTPROV ctx;
|
|
93
|
-
BOOL tmp;
|
|
94
|
-
|
|
95
|
-
tmp = CryptAcquireContext(&ctx, NULL, NULL, PROV_RSA_FULL,
|
|
96
|
-
CRYPT_VERIFYCONTEXT);
|
|
97
|
-
if (tmp == FALSE) {
|
|
98
|
-
return -1;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
tmp = CryptGenRandom(ctx, (unsigned long)n, (BYTE *) buf);
|
|
102
|
-
if (tmp == FALSE) {
|
|
103
|
-
return -1;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
tmp = CryptReleaseContext(ctx, 0);
|
|
107
|
-
if (tmp == FALSE) {
|
|
108
|
-
return -1;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
#endif /* defined(_WIN32) */
|
|
114
|
-
|
|
115
|
-
#if defined(__wasi__)
|
|
116
|
-
static int randombytes_wasi_randombytes(void *buf, size_t n) {
|
|
117
|
-
arc4random_buf(buf, n);
|
|
118
|
-
return 0;
|
|
119
|
-
}
|
|
120
|
-
#endif /* defined(__wasi__) */
|
|
121
|
-
|
|
122
|
-
#if defined(__linux__) && (defined(USE_GLIBC) || defined(SYS_getrandom))
|
|
123
|
-
# if defined(USE_GLIBC)
|
|
124
|
-
// getrandom is declared in glibc.
|
|
125
|
-
# elif defined(SYS_getrandom)
|
|
126
|
-
static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
|
|
127
|
-
return syscall(SYS_getrandom, buf, buflen, flags);
|
|
128
|
-
}
|
|
129
|
-
# endif
|
|
130
|
-
|
|
131
|
-
static int randombytes_linux_randombytes_getrandom(void *buf, size_t n) {
|
|
132
|
-
/* I have thought about using a separate PRF, seeded by getrandom, but
|
|
133
|
-
* it turns out that the performance of getrandom is good enough
|
|
134
|
-
* (250 MB/s on my laptop).
|
|
135
|
-
*/
|
|
136
|
-
size_t offset = 0, chunk;
|
|
137
|
-
int ret;
|
|
138
|
-
while (n > 0) {
|
|
139
|
-
/* getrandom does not allow chunks larger than 33554431 */
|
|
140
|
-
chunk = n <= 33554431 ? n : 33554431;
|
|
141
|
-
do {
|
|
142
|
-
ret = getrandom((char *)buf + offset, chunk, 0);
|
|
143
|
-
} while (ret == -1 && errno == EINTR);
|
|
144
|
-
if (ret < 0) {
|
|
145
|
-
return ret;
|
|
146
|
-
}
|
|
147
|
-
offset += ret;
|
|
148
|
-
n -= ret;
|
|
149
|
-
}
|
|
150
|
-
assert(n == 0);
|
|
151
|
-
return 0;
|
|
152
|
-
}
|
|
153
|
-
#endif // defined(__linux__) && (defined(USE_GLIBC) || defined(SYS_getrandom))
|
|
154
|
-
|
|
155
|
-
#if defined(__linux__) && !defined(SYS_getrandom)
|
|
156
|
-
static int randombytes_linux_read_entropy_ioctl(int device, int *entropy) {
|
|
157
|
-
return ioctl(device, RNDGETENTCNT, entropy);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
static int randombytes_linux_read_entropy_proc(FILE *stream, int *entropy) {
|
|
161
|
-
int retcode;
|
|
162
|
-
do {
|
|
163
|
-
rewind(stream);
|
|
164
|
-
retcode = fscanf(stream, "%d", entropy);
|
|
165
|
-
} while (retcode != 1 && errno == EINTR);
|
|
166
|
-
if (retcode != 1) {
|
|
167
|
-
return -1;
|
|
168
|
-
}
|
|
169
|
-
return 0;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
static int randombytes_linux_wait_for_entropy(int device) {
|
|
173
|
-
/* We will block on /dev/random, because any increase in the OS' entropy
|
|
174
|
-
* level will unblock the request. I use poll here (as does libsodium),
|
|
175
|
-
* because we don't *actually* want to read from the device. */
|
|
176
|
-
enum { IOCTL, PROC } strategy = IOCTL;
|
|
177
|
-
const int bits = 128;
|
|
178
|
-
struct pollfd pfd;
|
|
179
|
-
int fd;
|
|
180
|
-
FILE *proc_file;
|
|
181
|
-
int retcode, retcode_error = 0; // Used as return codes throughout this function
|
|
182
|
-
int entropy = 0;
|
|
183
|
-
|
|
184
|
-
/* If the device has enough entropy already, we will want to return early */
|
|
185
|
-
retcode = randombytes_linux_read_entropy_ioctl(device, &entropy);
|
|
186
|
-
// printf("errno: %d (%s)\n", errno, strerror(errno));
|
|
187
|
-
if (retcode != 0 && (errno == ENOTTY || errno == ENOSYS)) {
|
|
188
|
-
// The ioctl call on /dev/urandom has failed due to a
|
|
189
|
-
// - ENOTTY (unsupported action), or
|
|
190
|
-
// - ENOSYS (invalid ioctl; this happens on MIPS, see #22).
|
|
191
|
-
//
|
|
192
|
-
// We will fall back to reading from
|
|
193
|
-
// `/proc/sys/kernel/random/entropy_avail`. This less ideal,
|
|
194
|
-
// because it allocates a file descriptor, and it may not work
|
|
195
|
-
// in a chroot. But at this point it seems we have no better
|
|
196
|
-
// options left.
|
|
197
|
-
strategy = PROC;
|
|
198
|
-
// Open the entropy count file
|
|
199
|
-
proc_file = fopen("/proc/sys/kernel/random/entropy_avail", "r");
|
|
200
|
-
} else if (retcode != 0) {
|
|
201
|
-
// Unrecoverable ioctl error
|
|
202
|
-
return -1;
|
|
203
|
-
}
|
|
204
|
-
if (entropy >= bits) {
|
|
205
|
-
return 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
do {
|
|
209
|
-
fd = open("/dev/random", O_RDONLY);
|
|
210
|
-
} while (fd == -1 && errno == EINTR); /* EAGAIN will not occur */
|
|
211
|
-
if (fd == -1) {
|
|
212
|
-
/* Unrecoverable IO error */
|
|
213
|
-
return -1;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
pfd.fd = fd;
|
|
217
|
-
pfd.events = POLLIN;
|
|
218
|
-
for (;;) {
|
|
219
|
-
retcode = poll(&pfd, 1, -1);
|
|
220
|
-
if (retcode == -1 && (errno == EINTR || errno == EAGAIN)) {
|
|
221
|
-
continue;
|
|
222
|
-
} else if (retcode == 1) {
|
|
223
|
-
if (strategy == IOCTL) {
|
|
224
|
-
retcode = randombytes_linux_read_entropy_ioctl(device, &entropy);
|
|
225
|
-
} else if (strategy == PROC) {
|
|
226
|
-
retcode = randombytes_linux_read_entropy_proc(proc_file, &entropy);
|
|
227
|
-
} else {
|
|
228
|
-
return -1; // Unreachable
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (retcode != 0) {
|
|
232
|
-
// Unrecoverable I/O error
|
|
233
|
-
retcode_error = retcode;
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
if (entropy >= bits) {
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
// Unreachable: poll() should only return -1 or 1
|
|
241
|
-
retcode_error = -1;
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
do {
|
|
246
|
-
retcode = close(fd);
|
|
247
|
-
} while (retcode == -1 && errno == EINTR);
|
|
248
|
-
if (strategy == PROC) {
|
|
249
|
-
do {
|
|
250
|
-
retcode = fclose(proc_file);
|
|
251
|
-
} while (retcode == -1 && errno == EINTR);
|
|
252
|
-
}
|
|
253
|
-
if (retcode_error != 0) {
|
|
254
|
-
return retcode_error;
|
|
255
|
-
}
|
|
256
|
-
return retcode;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
static int randombytes_linux_randombytes_urandom(void *buf, size_t n) {
|
|
260
|
-
int fd;
|
|
261
|
-
size_t offset = 0, count;
|
|
262
|
-
ssize_t tmp;
|
|
263
|
-
do {
|
|
264
|
-
fd = open("/dev/urandom", O_RDONLY);
|
|
265
|
-
} while (fd == -1 && errno == EINTR);
|
|
266
|
-
if (fd == -1) {
|
|
267
|
-
return -1;
|
|
268
|
-
}
|
|
269
|
-
if (randombytes_linux_wait_for_entropy(fd) == -1) {
|
|
270
|
-
return -1;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
while (n > 0) {
|
|
274
|
-
count = n <= SSIZE_MAX ? n : SSIZE_MAX;
|
|
275
|
-
tmp = read(fd, (char *)buf + offset, count);
|
|
276
|
-
if (tmp == -1 && (errno == EAGAIN || errno == EINTR)) {
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
if (tmp == -1) {
|
|
280
|
-
return -1; /* Unrecoverable IO error */
|
|
281
|
-
}
|
|
282
|
-
offset += tmp;
|
|
283
|
-
n -= tmp;
|
|
284
|
-
}
|
|
285
|
-
close(fd);
|
|
286
|
-
assert(n == 0);
|
|
287
|
-
return 0;
|
|
288
|
-
}
|
|
289
|
-
#endif /* defined(__linux__) && !defined(SYS_getrandom) */
|
|
290
|
-
|
|
291
|
-
#if defined(BSD)
|
|
292
|
-
static int randombytes_bsd_randombytes(void *buf, size_t n) {
|
|
293
|
-
arc4random_buf(buf, n);
|
|
294
|
-
return 0;
|
|
295
|
-
}
|
|
296
|
-
#endif /* defined(BSD) */
|
|
297
|
-
|
|
298
|
-
#if defined(__EMSCRIPTEN__)
|
|
299
|
-
static int randombytes_js_randombytes_nodejs(void *buf, size_t n) {
|
|
300
|
-
const int ret = EM_ASM_INT({
|
|
301
|
-
var crypto;
|
|
302
|
-
try {
|
|
303
|
-
crypto = require('crypto');
|
|
304
|
-
} catch (error) {
|
|
305
|
-
return -2;
|
|
306
|
-
}
|
|
307
|
-
try {
|
|
308
|
-
writeArrayToMemory(crypto.randomBytes($1), $0);
|
|
309
|
-
return 0;
|
|
310
|
-
} catch (error) {
|
|
311
|
-
return -1;
|
|
312
|
-
}
|
|
313
|
-
}, buf, n);
|
|
314
|
-
switch (ret) {
|
|
315
|
-
case 0:
|
|
316
|
-
return 0;
|
|
317
|
-
case -1:
|
|
318
|
-
errno = EINVAL;
|
|
319
|
-
return -1;
|
|
320
|
-
case -2:
|
|
321
|
-
errno = ENOSYS;
|
|
322
|
-
return -1;
|
|
323
|
-
}
|
|
324
|
-
assert(false); // Unreachable
|
|
325
|
-
}
|
|
326
|
-
#endif /* defined(__EMSCRIPTEN__) */
|
|
327
|
-
|
|
328
|
-
int randombytes(uint8_t *output, size_t n) {
|
|
329
|
-
void *buf = (void *)output;
|
|
330
|
-
#if defined(__EMSCRIPTEN__)
|
|
331
|
-
return randombytes_js_randombytes_nodejs(buf, n);
|
|
332
|
-
#elif defined(__linux__)
|
|
333
|
-
# if defined(USE_GLIBC)
|
|
334
|
-
/* Use getrandom system call */
|
|
335
|
-
return randombytes_linux_randombytes_getrandom(buf, n);
|
|
336
|
-
# elif defined(SYS_getrandom)
|
|
337
|
-
/* Use getrandom system call */
|
|
338
|
-
return randombytes_linux_randombytes_getrandom(buf, n);
|
|
339
|
-
# else
|
|
340
|
-
/* When we have enough entropy, we can read from /dev/urandom */
|
|
341
|
-
return randombytes_linux_randombytes_urandom(buf, n);
|
|
342
|
-
# endif
|
|
343
|
-
#elif defined(BSD)
|
|
344
|
-
/* Use arc4random system call */
|
|
345
|
-
return randombytes_bsd_randombytes(buf, n);
|
|
346
|
-
#elif defined(_WIN32)
|
|
347
|
-
/* Use windows API */
|
|
348
|
-
return randombytes_win32_randombytes(buf, n);
|
|
349
|
-
#elif defined(__wasi__)
|
|
350
|
-
/* Use WASI */
|
|
351
|
-
return randombytes_wasi_randombytes(buf, n);
|
|
352
|
-
#else
|
|
353
|
-
# error "randombytes(...) is not supported on this platform"
|
|
354
|
-
#endif
|
|
355
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#ifndef PQCLEAN_RANDOMBYTES_H
|
|
2
|
-
#define PQCLEAN_RANDOMBYTES_H
|
|
3
|
-
|
|
4
|
-
#ifdef __cplusplus
|
|
5
|
-
extern "C" {
|
|
6
|
-
#endif
|
|
7
|
-
|
|
8
|
-
#include <stdint.h>
|
|
9
|
-
|
|
10
|
-
#ifdef _WIN32
|
|
11
|
-
/* Load size_t on windows */
|
|
12
|
-
#include <crtdefs.h>
|
|
13
|
-
#else
|
|
14
|
-
#include <unistd.h>
|
|
15
|
-
#endif /* _WIN32 */
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
* Write `n` bytes of high quality random bytes to `buf`
|
|
19
|
-
*/
|
|
20
|
-
#define randombytes PQCLEAN_randombytes
|
|
21
|
-
int randombytes(uint8_t *output, size_t n);
|
|
22
|
-
|
|
23
|
-
#ifdef __cplusplus
|
|
24
|
-
}
|
|
25
|
-
#endif
|
|
26
|
-
|
|
27
|
-
#endif /* PQCLEAN_RANDOMBYTES_H */
|