pq_crypto 0.3.1 → 0.4.2
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 +50 -0
- data/GET_STARTED.md +374 -30
- data/README.md +59 -195
- data/SECURITY.md +101 -82
- data/ext/pqcrypto/extconf.rb +85 -9
- data/ext/pqcrypto/mldsa_api.h +71 -1
- data/ext/pqcrypto/mlkem_api.h +24 -0
- data/ext/pqcrypto/pq_externalmu.c +310 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +784 -85
- data/ext/pqcrypto/pqcrypto_secure.c +179 -72
- data/ext/pqcrypto/pqcrypto_secure.h +103 -7
- data/ext/pqcrypto/pqcrypto_version.h +7 -0
- data/ext/pqcrypto/vendor/.vendored +1 -1
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +8 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/LICENSE +5 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/Makefile.Microsoft_nmake +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/api.h +18 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.c +83 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/cbd.h +11 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.c +327 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/indcpa.h +22 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.c +164 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/kem.h +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.c +146 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/ntt.h +14 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/params.h +36 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.c +311 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/poly.h +37 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.c +198 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/polyvec.h +26 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.c +41 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/reduce.h +13 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric-shake.c +71 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/symmetric.h +30 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.c +67 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-1024/clean/verify.h +13 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/LICENSE +5 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/Makefile.Microsoft_nmake +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/api.h +18 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.c +108 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/cbd.h +11 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.c +327 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/indcpa.h +22 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.c +164 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/kem.h +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.c +146 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/ntt.h +14 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/params.h +36 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.c +299 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/poly.h +37 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.c +188 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/polyvec.h +26 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.c +41 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/reduce.h +13 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric-shake.c +71 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/symmetric.h +30 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.c +67 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-512/clean/verify.h +13 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/LICENSE +5 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/Makefile.Microsoft_nmake +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/api.h +50 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.c +98 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/ntt.h +10 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.c +261 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/packing.h +31 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/params.h +44 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.c +848 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/poly.h +52 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.c +415 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/polyvec.h +65 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.c +69 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/reduce.h +17 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.c +98 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/rounding.h +14 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.c +407 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/sign.h +47 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric-shake.c +26 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-44/clean/symmetric.h +34 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/LICENSE +5 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/Makefile.Microsoft_nmake +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/api.h +50 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.c +98 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/ntt.h +10 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.c +261 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/packing.h +31 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/params.h +44 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.c +823 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/poly.h +52 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.c +415 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/polyvec.h +65 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.c +69 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/reduce.h +17 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.c +92 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/rounding.h +14 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.c +407 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/sign.h +47 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric-shake.c +26 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-87/clean/symmetric.h +34 -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 +231 -13
- data/lib/pq_crypto/spki.rb +131 -0
- data/lib/pq_crypto/version.rb +1 -1
- data/lib/pq_crypto.rb +90 -19
- data/script/vendor_libs.rb +4 -0
- metadata +99 -3
data/ext/pqcrypto/mldsa_api.h
CHANGED
|
@@ -5,46 +5,116 @@
|
|
|
5
5
|
#include <stddef.h>
|
|
6
6
|
#include <stdint.h>
|
|
7
7
|
|
|
8
|
+
#define PQCLEAN_MLDSA44_CLEAN_CRYPTO_PUBLICKEYBYTES 1312
|
|
9
|
+
#define PQCLEAN_MLDSA44_CLEAN_CRYPTO_SECRETKEYBYTES 2560
|
|
10
|
+
#define PQCLEAN_MLDSA44_CLEAN_CRYPTO_BYTES 2420
|
|
11
|
+
#define PQCLEAN_MLDSA44_CLEAN_CRYPTO_ALGNAME "ML-DSA-44"
|
|
12
|
+
|
|
13
|
+
#define PQCLEAN_MLDSA65_CLEAN_CRYPTO_PUBLICKEYBYTES 1952
|
|
14
|
+
#define PQCLEAN_MLDSA65_CLEAN_CRYPTO_SECRETKEYBYTES 4032
|
|
15
|
+
#define PQCLEAN_MLDSA65_CLEAN_CRYPTO_BYTES 3309
|
|
8
16
|
#define PQCLEAN_MLDSA65_CLEAN_CRYPTO_ALGNAME "ML-DSA-65"
|
|
9
17
|
|
|
18
|
+
#define PQCLEAN_MLDSA87_CLEAN_CRYPTO_PUBLICKEYBYTES 2592
|
|
19
|
+
#define PQCLEAN_MLDSA87_CLEAN_CRYPTO_SECRETKEYBYTES 4896
|
|
20
|
+
#define PQCLEAN_MLDSA87_CLEAN_CRYPTO_BYTES 4627
|
|
21
|
+
#define PQCLEAN_MLDSA87_CLEAN_CRYPTO_ALGNAME "ML-DSA-87"
|
|
22
|
+
|
|
23
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);
|
|
10
24
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);
|
|
25
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);
|
|
11
26
|
|
|
27
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_signature_ctx(uint8_t *sig, size_t *siglen,
|
|
28
|
+
const uint8_t *m, size_t mlen,
|
|
29
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
30
|
+
const uint8_t *sk);
|
|
12
31
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_signature_ctx(uint8_t *sig, size_t *siglen,
|
|
13
32
|
const uint8_t *m, size_t mlen,
|
|
14
33
|
const uint8_t *ctx, size_t ctxlen,
|
|
15
34
|
const uint8_t *sk);
|
|
35
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_signature_ctx(uint8_t *sig, size_t *siglen,
|
|
36
|
+
const uint8_t *m, size_t mlen,
|
|
37
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
38
|
+
const uint8_t *sk);
|
|
16
39
|
|
|
40
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_ctx(uint8_t *sm, size_t *smlen,
|
|
41
|
+
const uint8_t *m, size_t mlen,
|
|
42
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
43
|
+
const uint8_t *sk);
|
|
17
44
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_ctx(uint8_t *sm, size_t *smlen,
|
|
18
45
|
const uint8_t *m, size_t mlen,
|
|
19
46
|
const uint8_t *ctx, size_t ctxlen,
|
|
20
47
|
const uint8_t *sk);
|
|
48
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_ctx(uint8_t *sm, size_t *smlen,
|
|
49
|
+
const uint8_t *m, size_t mlen,
|
|
50
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
51
|
+
const uint8_t *sk);
|
|
21
52
|
|
|
53
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_verify_ctx(const uint8_t *sig, size_t siglen,
|
|
54
|
+
const uint8_t *m, size_t mlen,
|
|
55
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
56
|
+
const uint8_t *pk);
|
|
22
57
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_verify_ctx(const uint8_t *sig, size_t siglen,
|
|
23
58
|
const uint8_t *m, size_t mlen,
|
|
24
59
|
const uint8_t *ctx, size_t ctxlen,
|
|
25
60
|
const uint8_t *pk);
|
|
61
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_verify_ctx(const uint8_t *sig, size_t siglen,
|
|
62
|
+
const uint8_t *m, size_t mlen,
|
|
63
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
64
|
+
const uint8_t *pk);
|
|
26
65
|
|
|
66
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_open_ctx(uint8_t *m, size_t *mlen,
|
|
67
|
+
const uint8_t *sm, size_t smlen,
|
|
68
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
69
|
+
const uint8_t *pk);
|
|
27
70
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_open_ctx(uint8_t *m, size_t *mlen,
|
|
28
71
|
const uint8_t *sm, size_t smlen,
|
|
29
72
|
const uint8_t *ctx, size_t ctxlen,
|
|
30
73
|
const uint8_t *pk);
|
|
74
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_open_ctx(uint8_t *m, size_t *mlen,
|
|
75
|
+
const uint8_t *sm, size_t smlen,
|
|
76
|
+
const uint8_t *ctx, size_t ctxlen,
|
|
77
|
+
const uint8_t *pk);
|
|
31
78
|
|
|
79
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_signature(uint8_t *sig, size_t *siglen,
|
|
80
|
+
const uint8_t *m, size_t mlen,
|
|
81
|
+
const uint8_t *sk);
|
|
32
82
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_signature(uint8_t *sig, size_t *siglen,
|
|
33
83
|
const uint8_t *m, size_t mlen,
|
|
34
84
|
const uint8_t *sk);
|
|
85
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_signature(uint8_t *sig, size_t *siglen,
|
|
86
|
+
const uint8_t *m, size_t mlen,
|
|
87
|
+
const uint8_t *sk);
|
|
35
88
|
|
|
89
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign(uint8_t *sm, size_t *smlen,
|
|
90
|
+
const uint8_t *m, size_t mlen,
|
|
91
|
+
const uint8_t *sk);
|
|
36
92
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign(uint8_t *sm, size_t *smlen,
|
|
37
93
|
const uint8_t *m, size_t mlen,
|
|
38
94
|
const uint8_t *sk);
|
|
95
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign(uint8_t *sm, size_t *smlen,
|
|
96
|
+
const uint8_t *m, size_t mlen,
|
|
97
|
+
const uint8_t *sk);
|
|
39
98
|
|
|
99
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_verify(const uint8_t *sig, size_t siglen,
|
|
100
|
+
const uint8_t *m, size_t mlen,
|
|
101
|
+
const uint8_t *pk);
|
|
40
102
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_verify(const uint8_t *sig, size_t siglen,
|
|
41
103
|
const uint8_t *m, size_t mlen,
|
|
42
104
|
const uint8_t *pk);
|
|
105
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_verify(const uint8_t *sig, size_t siglen,
|
|
106
|
+
const uint8_t *m, size_t mlen,
|
|
107
|
+
const uint8_t *pk);
|
|
43
108
|
|
|
109
|
+
int PQCLEAN_MLDSA44_CLEAN_crypto_sign_open(uint8_t *m, size_t *mlen,
|
|
110
|
+
const uint8_t *sm, size_t smlen,
|
|
111
|
+
const uint8_t *pk);
|
|
44
112
|
int PQCLEAN_MLDSA65_CLEAN_crypto_sign_open(uint8_t *m, size_t *mlen,
|
|
45
113
|
const uint8_t *sm, size_t smlen,
|
|
46
114
|
const uint8_t *pk);
|
|
47
|
-
|
|
115
|
+
int PQCLEAN_MLDSA87_CLEAN_crypto_sign_open(uint8_t *m, size_t *mlen,
|
|
116
|
+
const uint8_t *sm, size_t smlen,
|
|
117
|
+
const uint8_t *pk);
|
|
48
118
|
|
|
49
119
|
#endif
|
|
50
120
|
|
data/ext/pqcrypto/mlkem_api.h
CHANGED
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
#ifdef HAVE_PQCLEAN
|
|
5
5
|
#include <stdint.h>
|
|
6
6
|
|
|
7
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_SECRETKEYBYTES 1632
|
|
8
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_PUBLICKEYBYTES 800
|
|
9
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_CIPHERTEXTBYTES 768
|
|
10
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_BYTES 32
|
|
11
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_ALGNAME "ML-KEM-512"
|
|
12
|
+
|
|
13
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk);
|
|
14
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
|
|
15
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
|
|
16
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_keypair_derand(uint8_t *pk, uint8_t *sk, const uint8_t *coins);
|
|
17
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t *pk, const uint8_t *coins);
|
|
18
|
+
|
|
7
19
|
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_SECRETKEYBYTES 2400
|
|
8
20
|
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_PUBLICKEYBYTES 1184
|
|
9
21
|
#define PQCLEAN_MLKEM768_CLEAN_CRYPTO_CIPHERTEXTBYTES 1088
|
|
@@ -16,6 +28,18 @@ int PQCLEAN_MLKEM768_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const
|
|
|
16
28
|
int PQCLEAN_MLKEM768_CLEAN_crypto_kem_keypair_derand(uint8_t *pk, uint8_t *sk, const uint8_t *coins);
|
|
17
29
|
int PQCLEAN_MLKEM768_CLEAN_crypto_kem_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t *pk, const uint8_t *coins);
|
|
18
30
|
|
|
31
|
+
#define PQCLEAN_MLKEM1024_CLEAN_CRYPTO_SECRETKEYBYTES 3168
|
|
32
|
+
#define PQCLEAN_MLKEM1024_CLEAN_CRYPTO_PUBLICKEYBYTES 1568
|
|
33
|
+
#define PQCLEAN_MLKEM1024_CLEAN_CRYPTO_CIPHERTEXTBYTES 1568
|
|
34
|
+
#define PQCLEAN_MLKEM1024_CLEAN_CRYPTO_BYTES 32
|
|
35
|
+
#define PQCLEAN_MLKEM1024_CLEAN_CRYPTO_ALGNAME "ML-KEM-1024"
|
|
36
|
+
|
|
37
|
+
int PQCLEAN_MLKEM1024_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk);
|
|
38
|
+
int PQCLEAN_MLKEM1024_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
|
|
39
|
+
int PQCLEAN_MLKEM1024_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
|
|
40
|
+
int PQCLEAN_MLKEM1024_CLEAN_crypto_kem_keypair_derand(uint8_t *pk, uint8_t *sk, const uint8_t *coins);
|
|
41
|
+
int PQCLEAN_MLKEM1024_CLEAN_crypto_kem_enc_derand(uint8_t *ct, uint8_t *ss, const uint8_t *pk, const uint8_t *coins);
|
|
42
|
+
|
|
19
43
|
#endif
|
|
20
44
|
|
|
21
45
|
#endif
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
#include "pqcrypto_secure.h"
|
|
2
|
+
|
|
3
|
+
#undef PQCLEAN_MLDSA65_CLEAN_CRYPTO_PUBLICKEYBYTES
|
|
4
|
+
#undef PQCLEAN_MLDSA65_CLEAN_CRYPTO_SECRETKEYBYTES
|
|
5
|
+
#undef PQCLEAN_MLDSA65_CLEAN_CRYPTO_BYTES
|
|
6
|
+
|
|
7
|
+
#include <stdint.h>
|
|
8
|
+
#include <stddef.h>
|
|
9
|
+
#include <string.h>
|
|
10
|
+
|
|
11
|
+
#include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h"
|
|
12
|
+
#include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h"
|
|
13
|
+
#include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h"
|
|
14
|
+
#include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h"
|
|
15
|
+
#include "vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h"
|
|
16
|
+
#include "fips202.h"
|
|
17
|
+
#include "randombytes.h"
|
|
18
|
+
|
|
19
|
+
#if CRHBYTES != PQ_MLDSA_MUBYTES
|
|
20
|
+
#error "PQ_MLDSA_MUBYTES must match PQClean's CRHBYTES"
|
|
21
|
+
#endif
|
|
22
|
+
#if TRBYTES != PQ_MLDSA_TRBYTES
|
|
23
|
+
#error "PQ_MLDSA_TRBYTES must match PQClean's TRBYTES"
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
int pq_mldsa_extract_tr_from_secret_key(uint8_t *tr_out, const uint8_t *secret_key) {
|
|
27
|
+
if (tr_out == NULL || secret_key == NULL) {
|
|
28
|
+
return PQ_ERROR_BUFFER;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
uint8_t rho[SEEDBYTES];
|
|
32
|
+
uint8_t key[SEEDBYTES];
|
|
33
|
+
polyveck t0;
|
|
34
|
+
polyvecl s1;
|
|
35
|
+
polyveck s2;
|
|
36
|
+
|
|
37
|
+
PQCLEAN_MLDSA65_CLEAN_unpack_sk(rho, tr_out, key, &t0, &s1, &s2, secret_key);
|
|
38
|
+
|
|
39
|
+
pq_secure_wipe(rho, sizeof(rho));
|
|
40
|
+
pq_secure_wipe(key, sizeof(key));
|
|
41
|
+
pq_secure_wipe(&t0, sizeof(t0));
|
|
42
|
+
pq_secure_wipe(&s1, sizeof(s1));
|
|
43
|
+
pq_secure_wipe(&s2, sizeof(s2));
|
|
44
|
+
|
|
45
|
+
return PQ_SUCCESS;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
int pq_mldsa_compute_tr_from_public_key(uint8_t *tr_out, const uint8_t *public_key) {
|
|
49
|
+
if (tr_out == NULL || public_key == NULL) {
|
|
50
|
+
return PQ_ERROR_BUFFER;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
shake256(tr_out, TRBYTES, public_key, PQCLEAN_MLDSA65_CLEAN_CRYPTO_PUBLICKEYBYTES);
|
|
54
|
+
return PQ_SUCCESS;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
int pq_sign_mu(uint8_t *signature, size_t *signature_len, const uint8_t *mu,
|
|
58
|
+
const uint8_t *secret_key) {
|
|
59
|
+
if (signature == NULL || signature_len == NULL || mu == NULL || secret_key == NULL) {
|
|
60
|
+
return PQ_ERROR_BUFFER;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
unsigned int n;
|
|
64
|
+
uint8_t rho[SEEDBYTES];
|
|
65
|
+
uint8_t tr_unused[TRBYTES];
|
|
66
|
+
uint8_t key[SEEDBYTES];
|
|
67
|
+
uint8_t rnd[RNDBYTES];
|
|
68
|
+
uint8_t mu_local[CRHBYTES];
|
|
69
|
+
uint8_t rhoprime[CRHBYTES];
|
|
70
|
+
uint16_t nonce = 0;
|
|
71
|
+
polyvecl mat[K], s1, y, z;
|
|
72
|
+
polyveck t0, s2, w1, w0, h;
|
|
73
|
+
poly cp;
|
|
74
|
+
shake256incctx state;
|
|
75
|
+
|
|
76
|
+
PQCLEAN_MLDSA65_CLEAN_unpack_sk(rho, tr_unused, key, &t0, &s1, &s2, secret_key);
|
|
77
|
+
pq_secure_wipe(tr_unused, sizeof(tr_unused));
|
|
78
|
+
|
|
79
|
+
memcpy(mu_local, mu, CRHBYTES);
|
|
80
|
+
|
|
81
|
+
if (randombytes(rnd, RNDBYTES) != 0) {
|
|
82
|
+
pq_secure_wipe(rho, sizeof(rho));
|
|
83
|
+
pq_secure_wipe(key, sizeof(key));
|
|
84
|
+
pq_secure_wipe(rnd, sizeof(rnd));
|
|
85
|
+
pq_secure_wipe(mu_local, sizeof(mu_local));
|
|
86
|
+
pq_secure_wipe(&s1, sizeof(s1));
|
|
87
|
+
pq_secure_wipe(&s2, sizeof(s2));
|
|
88
|
+
pq_secure_wipe(&t0, sizeof(t0));
|
|
89
|
+
return PQ_ERROR_RANDOM;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
{
|
|
93
|
+
uint8_t kr[SEEDBYTES + RNDBYTES + CRHBYTES];
|
|
94
|
+
memcpy(kr, key, SEEDBYTES);
|
|
95
|
+
memcpy(kr + SEEDBYTES, rnd, RNDBYTES);
|
|
96
|
+
memcpy(kr + SEEDBYTES + RNDBYTES, mu_local, CRHBYTES);
|
|
97
|
+
shake256(rhoprime, CRHBYTES, kr, sizeof(kr));
|
|
98
|
+
pq_secure_wipe(kr, sizeof(kr));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_expand(mat, rho);
|
|
102
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_ntt(&s1);
|
|
103
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_ntt(&s2);
|
|
104
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_ntt(&t0);
|
|
105
|
+
|
|
106
|
+
rej:
|
|
107
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_uniform_gamma1(&y, rhoprime, nonce++);
|
|
108
|
+
|
|
109
|
+
z = y;
|
|
110
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_ntt(&z);
|
|
111
|
+
PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_pointwise_montgomery(&w1, mat, &z);
|
|
112
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&w1);
|
|
113
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&w1);
|
|
114
|
+
|
|
115
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_caddq(&w1);
|
|
116
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_decompose(&w1, &w0, &w1);
|
|
117
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_pack_w1(signature, &w1);
|
|
118
|
+
|
|
119
|
+
shake256_inc_init(&state);
|
|
120
|
+
shake256_inc_absorb(&state, mu_local, CRHBYTES);
|
|
121
|
+
shake256_inc_absorb(&state, signature, K * POLYW1_PACKEDBYTES);
|
|
122
|
+
shake256_inc_finalize(&state);
|
|
123
|
+
shake256_inc_squeeze(signature, CTILDEBYTES, &state);
|
|
124
|
+
shake256_inc_ctx_release(&state);
|
|
125
|
+
|
|
126
|
+
PQCLEAN_MLDSA65_CLEAN_poly_challenge(&cp, signature);
|
|
127
|
+
PQCLEAN_MLDSA65_CLEAN_poly_ntt(&cp);
|
|
128
|
+
|
|
129
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_pointwise_poly_montgomery(&z, &cp, &s1);
|
|
130
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_invntt_tomont(&z);
|
|
131
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_add(&z, &z, &y);
|
|
132
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_reduce(&z);
|
|
133
|
+
if (PQCLEAN_MLDSA65_CLEAN_polyvecl_chknorm(&z, GAMMA1 - BETA)) {
|
|
134
|
+
goto rej;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_pointwise_poly_montgomery(&h, &cp, &s2);
|
|
138
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&h);
|
|
139
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_sub(&w0, &w0, &h);
|
|
140
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&w0);
|
|
141
|
+
if (PQCLEAN_MLDSA65_CLEAN_polyveck_chknorm(&w0, GAMMA2 - BETA)) {
|
|
142
|
+
goto rej;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_pointwise_poly_montgomery(&h, &cp, &t0);
|
|
146
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&h);
|
|
147
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&h);
|
|
148
|
+
if (PQCLEAN_MLDSA65_CLEAN_polyveck_chknorm(&h, GAMMA2)) {
|
|
149
|
+
goto rej;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_add(&w0, &w0, &h);
|
|
153
|
+
n = PQCLEAN_MLDSA65_CLEAN_polyveck_make_hint(&h, &w0, &w1);
|
|
154
|
+
if (n > OMEGA) {
|
|
155
|
+
goto rej;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
PQCLEAN_MLDSA65_CLEAN_pack_sig(signature, signature, &z, &h);
|
|
159
|
+
*signature_len = PQCLEAN_MLDSA65_CLEAN_CRYPTO_BYTES;
|
|
160
|
+
|
|
161
|
+
pq_secure_wipe(rho, sizeof(rho));
|
|
162
|
+
pq_secure_wipe(key, sizeof(key));
|
|
163
|
+
pq_secure_wipe(rnd, sizeof(rnd));
|
|
164
|
+
pq_secure_wipe(mu_local, sizeof(mu_local));
|
|
165
|
+
pq_secure_wipe(rhoprime, sizeof(rhoprime));
|
|
166
|
+
pq_secure_wipe(&s1, sizeof(s1));
|
|
167
|
+
pq_secure_wipe(&s2, sizeof(s2));
|
|
168
|
+
pq_secure_wipe(&t0, sizeof(t0));
|
|
169
|
+
pq_secure_wipe(&y, sizeof(y));
|
|
170
|
+
pq_secure_wipe(&z, sizeof(z));
|
|
171
|
+
pq_secure_wipe(&w0, sizeof(w0));
|
|
172
|
+
pq_secure_wipe(&cp, sizeof(cp));
|
|
173
|
+
|
|
174
|
+
return PQ_SUCCESS;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
int pq_verify_mu(const uint8_t *signature, size_t signature_len, const uint8_t *mu,
|
|
178
|
+
const uint8_t *public_key) {
|
|
179
|
+
if (signature == NULL || mu == NULL || public_key == NULL) {
|
|
180
|
+
return PQ_ERROR_BUFFER;
|
|
181
|
+
}
|
|
182
|
+
if (signature_len != PQCLEAN_MLDSA65_CLEAN_CRYPTO_BYTES) {
|
|
183
|
+
return PQ_ERROR_VERIFY;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
unsigned int i;
|
|
187
|
+
uint8_t buf[K * POLYW1_PACKEDBYTES];
|
|
188
|
+
uint8_t rho[SEEDBYTES];
|
|
189
|
+
uint8_t c[CTILDEBYTES];
|
|
190
|
+
uint8_t c2[CTILDEBYTES];
|
|
191
|
+
poly cp;
|
|
192
|
+
polyvecl mat[K], z;
|
|
193
|
+
polyveck t1, w1, h;
|
|
194
|
+
shake256incctx state;
|
|
195
|
+
|
|
196
|
+
PQCLEAN_MLDSA65_CLEAN_unpack_pk(rho, &t1, public_key);
|
|
197
|
+
if (PQCLEAN_MLDSA65_CLEAN_unpack_sig(c, &z, &h, signature)) {
|
|
198
|
+
return PQ_ERROR_VERIFY;
|
|
199
|
+
}
|
|
200
|
+
if (PQCLEAN_MLDSA65_CLEAN_polyvecl_chknorm(&z, GAMMA1 - BETA)) {
|
|
201
|
+
return PQ_ERROR_VERIFY;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
PQCLEAN_MLDSA65_CLEAN_poly_challenge(&cp, c);
|
|
205
|
+
PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_expand(mat, rho);
|
|
206
|
+
|
|
207
|
+
PQCLEAN_MLDSA65_CLEAN_polyvecl_ntt(&z);
|
|
208
|
+
PQCLEAN_MLDSA65_CLEAN_polyvec_matrix_pointwise_montgomery(&w1, mat, &z);
|
|
209
|
+
|
|
210
|
+
PQCLEAN_MLDSA65_CLEAN_poly_ntt(&cp);
|
|
211
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_shiftl(&t1);
|
|
212
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_ntt(&t1);
|
|
213
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_pointwise_poly_montgomery(&t1, &cp, &t1);
|
|
214
|
+
|
|
215
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_sub(&w1, &w1, &t1);
|
|
216
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_reduce(&w1);
|
|
217
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_invntt_tomont(&w1);
|
|
218
|
+
|
|
219
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_caddq(&w1);
|
|
220
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_use_hint(&w1, &w1, &h);
|
|
221
|
+
PQCLEAN_MLDSA65_CLEAN_polyveck_pack_w1(buf, &w1);
|
|
222
|
+
|
|
223
|
+
shake256_inc_init(&state);
|
|
224
|
+
shake256_inc_absorb(&state, mu, CRHBYTES);
|
|
225
|
+
shake256_inc_absorb(&state, buf, K * POLYW1_PACKEDBYTES);
|
|
226
|
+
shake256_inc_finalize(&state);
|
|
227
|
+
shake256_inc_squeeze(c2, CTILDEBYTES, &state);
|
|
228
|
+
shake256_inc_ctx_release(&state);
|
|
229
|
+
|
|
230
|
+
for (i = 0; i < CTILDEBYTES; ++i) {
|
|
231
|
+
if (c[i] != c2[i]) {
|
|
232
|
+
return PQ_ERROR_VERIFY;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return PQ_SUCCESS;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
void *pq_mu_builder_new(void) {
|
|
240
|
+
shake256incctx *state = (shake256incctx *)malloc(sizeof(shake256incctx));
|
|
241
|
+
if (state == NULL) {
|
|
242
|
+
return NULL;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
shake256_inc_init(state);
|
|
246
|
+
return state;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
int pq_mu_builder_init(void *state_ptr, const uint8_t *tr, const uint8_t *ctx, size_t ctxlen) {
|
|
250
|
+
if (state_ptr == NULL || tr == NULL) {
|
|
251
|
+
return PQ_ERROR_BUFFER;
|
|
252
|
+
}
|
|
253
|
+
if (ctxlen > 255) {
|
|
254
|
+
return PQ_ERROR_BUFFER;
|
|
255
|
+
}
|
|
256
|
+
if (ctxlen > 0 && ctx == NULL) {
|
|
257
|
+
return PQ_ERROR_BUFFER;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
shake256incctx *state = (shake256incctx *)state_ptr;
|
|
261
|
+
|
|
262
|
+
uint8_t prefix[2];
|
|
263
|
+
prefix[0] = 0x00;
|
|
264
|
+
prefix[1] = (uint8_t)ctxlen;
|
|
265
|
+
|
|
266
|
+
shake256_inc_absorb(state, tr, TRBYTES);
|
|
267
|
+
shake256_inc_absorb(state, prefix, sizeof(prefix));
|
|
268
|
+
if (ctxlen > 0) {
|
|
269
|
+
shake256_inc_absorb(state, ctx, ctxlen);
|
|
270
|
+
}
|
|
271
|
+
return PQ_SUCCESS;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
int pq_mu_builder_absorb(void *state_ptr, const uint8_t *chunk, size_t chunk_len) {
|
|
275
|
+
if (state_ptr == NULL) {
|
|
276
|
+
return PQ_ERROR_BUFFER;
|
|
277
|
+
}
|
|
278
|
+
if (chunk_len == 0) {
|
|
279
|
+
return PQ_SUCCESS;
|
|
280
|
+
}
|
|
281
|
+
if (chunk == NULL) {
|
|
282
|
+
return PQ_ERROR_BUFFER;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
shake256incctx *state = (shake256incctx *)state_ptr;
|
|
286
|
+
shake256_inc_absorb(state, chunk, chunk_len);
|
|
287
|
+
return PQ_SUCCESS;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
int pq_mu_builder_finalize(void *state_ptr, uint8_t *mu_out) {
|
|
291
|
+
if (state_ptr == NULL || mu_out == NULL) {
|
|
292
|
+
return PQ_ERROR_BUFFER;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
shake256incctx *state = (shake256incctx *)state_ptr;
|
|
296
|
+
shake256_inc_finalize(state);
|
|
297
|
+
shake256_inc_squeeze(mu_out, CRHBYTES, state);
|
|
298
|
+
shake256_inc_ctx_release(state);
|
|
299
|
+
free(state);
|
|
300
|
+
return PQ_SUCCESS;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
void pq_mu_builder_release(void *state_ptr) {
|
|
304
|
+
if (state_ptr == NULL) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
shake256incctx *state = (shake256incctx *)state_ptr;
|
|
308
|
+
shake256_inc_ctx_release(state);
|
|
309
|
+
free(state);
|
|
310
|
+
}
|