pq_crypto 0.1.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 +7 -0
- data/.github/workflows/ci.yml +37 -0
- data/CHANGELOG.md +29 -0
- data/GET_STARTED.md +65 -0
- data/LICENSE.txt +21 -0
- data/README.md +135 -0
- data/SECURITY.md +57 -0
- data/ext/pqcrypto/extconf.rb +157 -0
- data/ext/pqcrypto/mldsa_api.h +51 -0
- data/ext/pqcrypto/mlkem_api.h +21 -0
- data/ext/pqcrypto/pqcrypto_ruby_secure.c +889 -0
- data/ext/pqcrypto/pqcrypto_secure.c +1178 -0
- data/ext/pqcrypto/pqcrypto_secure.h +135 -0
- data/ext/pqcrypto/vendor/.vendored +5 -0
- data/ext/pqcrypto/vendor/pqclean/common/aes.c +639 -0
- data/ext/pqcrypto/vendor/pqclean/common/aes.h +64 -0
- data/ext/pqcrypto/vendor/pqclean/common/compat.h +73 -0
- data/ext/pqcrypto/vendor/pqclean/common/crypto_declassify.h +7 -0
- data/ext/pqcrypto/vendor/pqclean/common/fips202.c +928 -0
- data/ext/pqcrypto/vendor/pqclean/common/fips202.h +166 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/feat.S +168 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.c +684 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak2x/fips202x2.h +60 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SIMD256.c +1028 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-times4-SnP.h +50 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/KeccakP-1600-unrolling.macros +198 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile +8 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/Makefile.Microsoft_nmake +8 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/SIMD256-config.h +3 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/align.h +34 -0
- data/ext/pqcrypto/vendor/pqclean/common/keccak4x/brg_endian.h +142 -0
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.c +101 -0
- data/ext/pqcrypto/vendor/pqclean/common/nistseedexpander.h +39 -0
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.c +355 -0
- data/ext/pqcrypto/vendor/pqclean/common/randombytes.h +27 -0
- data/ext/pqcrypto/vendor/pqclean/common/sha2.c +769 -0
- data/ext/pqcrypto/vendor/pqclean/common/sha2.h +173 -0
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.c +156 -0
- data/ext/pqcrypto/vendor/pqclean/common/sp800-185.h +27 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/LICENSE +5 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/Makefile.Microsoft_nmake +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/api.h +18 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.c +83 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/cbd.h +11 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.c +327 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/indcpa.h +22 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.c +164 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/kem.h +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.c +146 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/ntt.h +14 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/params.h +36 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.c +299 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/poly.h +37 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.c +188 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/polyvec.h +26 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.c +41 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/reduce.h +13 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric-shake.c +71 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/symmetric.h +30 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.c +67 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_kem/ml-kem-768/clean/verify.h +13 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/LICENSE +5 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile +19 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/Makefile.Microsoft_nmake +23 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/api.h +50 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.c +98 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/ntt.h +10 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.c +261 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/packing.h +31 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/params.h +44 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.c +799 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/poly.h +52 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.c +415 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/polyvec.h +65 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.c +69 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/reduce.h +17 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.c +92 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/rounding.h +14 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.c +407 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/sign.h +47 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric-shake.c +26 -0
- data/ext/pqcrypto/vendor/pqclean/crypto_sign/ml-dsa-65/clean/symmetric.h +34 -0
- data/lib/pq_crypto/errors.rb +10 -0
- data/lib/pq_crypto/hybrid_kem.rb +106 -0
- data/lib/pq_crypto/kem.rb +199 -0
- data/lib/pq_crypto/serialization.rb +102 -0
- data/lib/pq_crypto/signature.rb +198 -0
- data/lib/pq_crypto/version.rb +5 -0
- data/lib/pq_crypto.rb +177 -0
- data/lib/pqcrypto.rb +3 -0
- data/script/vendor_libs.rb +199 -0
- metadata +195 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#ifndef PQCRYPTO_SECURE_H
|
|
2
|
+
#define PQCRYPTO_SECURE_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
|
|
8
|
+
#ifndef HAVE_PQCLEAN
|
|
9
|
+
#error "PQClean sources are required to build pq_crypto. Run: bundle exec rake vendor"
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "mlkem_api.h"
|
|
13
|
+
#include "mldsa_api.h"
|
|
14
|
+
#define MLKEM_PUBLICKEYBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_PUBLICKEYBYTES
|
|
15
|
+
#define MLKEM_SECRETKEYBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_SECRETKEYBYTES
|
|
16
|
+
#define MLKEM_CIPHERTEXTBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_CIPHERTEXTBYTES
|
|
17
|
+
#define MLKEM_SHAREDSECRETBYTES PQCLEAN_MLKEM768_CLEAN_CRYPTO_BYTES
|
|
18
|
+
|
|
19
|
+
#define MLDSA_PUBLICKEYBYTES 1952
|
|
20
|
+
#define MLDSA_SECRETKEYBYTES 4032
|
|
21
|
+
#define MLDSA_BYTES 3309
|
|
22
|
+
|
|
23
|
+
#define X25519_PUBLICKEYBYTES 32
|
|
24
|
+
#define X25519_SECRETKEYBYTES 32
|
|
25
|
+
#define X25519_SHAREDSECRETBYTES 32
|
|
26
|
+
|
|
27
|
+
#define HYBRID_PUBLICKEYBYTES (MLKEM_PUBLICKEYBYTES + X25519_PUBLICKEYBYTES)
|
|
28
|
+
#define HYBRID_SECRETKEYBYTES (MLKEM_SECRETKEYBYTES + X25519_SECRETKEYBYTES)
|
|
29
|
+
#define HYBRID_CIPHERTEXTBYTES (MLKEM_CIPHERTEXTBYTES + X25519_PUBLICKEYBYTES)
|
|
30
|
+
#define HYBRID_SHAREDSECRETBYTES 32
|
|
31
|
+
|
|
32
|
+
typedef enum {
|
|
33
|
+
PQ_SUCCESS = 0,
|
|
34
|
+
PQ_ERROR_KEYPAIR = -1,
|
|
35
|
+
PQ_ERROR_ENCAPSULATE = -2,
|
|
36
|
+
PQ_ERROR_DECAPSULATE = -3,
|
|
37
|
+
PQ_ERROR_SIGN = -4,
|
|
38
|
+
PQ_ERROR_VERIFY = -5,
|
|
39
|
+
PQ_ERROR_KDF = -6,
|
|
40
|
+
PQ_ERROR_RANDOM = -7,
|
|
41
|
+
PQ_ERROR_BUFFER = -8,
|
|
42
|
+
PQ_ERROR_NOMEM = -9,
|
|
43
|
+
PQ_ERROR_OPENSSL = -10
|
|
44
|
+
} pq_error_t;
|
|
45
|
+
|
|
46
|
+
typedef struct {
|
|
47
|
+
uint8_t mlkem_pk[MLKEM_PUBLICKEYBYTES];
|
|
48
|
+
uint8_t x25519_pk[X25519_PUBLICKEYBYTES];
|
|
49
|
+
} hybrid_public_key_t;
|
|
50
|
+
|
|
51
|
+
typedef struct {
|
|
52
|
+
uint8_t mlkem_sk[MLKEM_SECRETKEYBYTES];
|
|
53
|
+
uint8_t x25519_sk[X25519_SECRETKEYBYTES];
|
|
54
|
+
} hybrid_secret_key_t;
|
|
55
|
+
|
|
56
|
+
typedef struct {
|
|
57
|
+
uint8_t mlkem_ct[MLKEM_CIPHERTEXTBYTES];
|
|
58
|
+
uint8_t x25519_ephemeral[X25519_PUBLICKEYBYTES];
|
|
59
|
+
} hybrid_ciphertext_t;
|
|
60
|
+
|
|
61
|
+
void pq_secure_wipe(void *ptr, size_t len);
|
|
62
|
+
|
|
63
|
+
int pq_mlkem_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
64
|
+
int pq_mlkem_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret, const uint8_t *public_key);
|
|
65
|
+
int pq_mlkem_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
|
|
66
|
+
const uint8_t *secret_key);
|
|
67
|
+
|
|
68
|
+
int pq_sign_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
69
|
+
int pq_sign(uint8_t *signature, size_t *signature_len, const uint8_t *message, size_t message_len,
|
|
70
|
+
const uint8_t *secret_key);
|
|
71
|
+
int pq_verify(const uint8_t *signature, size_t signature_len, const uint8_t *message,
|
|
72
|
+
size_t message_len, const uint8_t *public_key);
|
|
73
|
+
|
|
74
|
+
int pq_public_key_to_pqc_container_der(uint8_t **output, size_t *output_len,
|
|
75
|
+
const uint8_t *public_key,
|
|
76
|
+
size_t public_key_len, const char *algorithm);
|
|
77
|
+
int pq_public_key_to_pqc_container_pem(char **output, size_t *output_len,
|
|
78
|
+
const uint8_t *public_key,
|
|
79
|
+
size_t public_key_len, const char *algorithm);
|
|
80
|
+
int pq_secret_key_to_pqc_container_der(uint8_t **output, size_t *output_len,
|
|
81
|
+
const uint8_t *secret_key,
|
|
82
|
+
size_t secret_key_len, const char *algorithm);
|
|
83
|
+
int pq_secret_key_to_pqc_container_pem(char **output, size_t *output_len,
|
|
84
|
+
const uint8_t *secret_key,
|
|
85
|
+
size_t secret_key_len, const char *algorithm);
|
|
86
|
+
int pq_public_key_from_pqc_container_der(char **algorithm_out, uint8_t **key_out,
|
|
87
|
+
size_t *key_len_out, const uint8_t *input,
|
|
88
|
+
size_t input_len);
|
|
89
|
+
int pq_public_key_from_pqc_container_pem(char **algorithm_out, uint8_t **key_out,
|
|
90
|
+
size_t *key_len_out, const char *input,
|
|
91
|
+
size_t input_len);
|
|
92
|
+
int pq_secret_key_from_pqc_container_der(char **algorithm_out, uint8_t **key_out,
|
|
93
|
+
size_t *key_len_out, const uint8_t *input,
|
|
94
|
+
size_t input_len);
|
|
95
|
+
int pq_secret_key_from_pqc_container_pem(char **algorithm_out, uint8_t **key_out,
|
|
96
|
+
size_t *key_len_out, const char *input,
|
|
97
|
+
size_t input_len);
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
/* Test-only deterministic hooks for regression harness. */
|
|
101
|
+
int pq_testing_mlkem_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
102
|
+
const uint8_t *seed, size_t seed_len);
|
|
103
|
+
int pq_testing_mlkem_encapsulate_from_seed(uint8_t *ciphertext, uint8_t *shared_secret,
|
|
104
|
+
const uint8_t *public_key, const uint8_t *seed,
|
|
105
|
+
size_t seed_len);
|
|
106
|
+
int pq_testing_mldsa_keypair_from_seed(uint8_t *public_key, uint8_t *secret_key,
|
|
107
|
+
const uint8_t *seed, size_t seed_len);
|
|
108
|
+
int pq_testing_mldsa_sign_from_seed(uint8_t *signature, size_t *signature_len,
|
|
109
|
+
const uint8_t *message, size_t message_len,
|
|
110
|
+
const uint8_t *secret_key, const uint8_t *seed,
|
|
111
|
+
size_t seed_len);
|
|
112
|
+
|
|
113
|
+
const char *pq_version(void);
|
|
114
|
+
|
|
115
|
+
#define PQ_MLKEM_PUBLICKEYBYTES MLKEM_PUBLICKEYBYTES
|
|
116
|
+
#define PQ_MLKEM_SECRETKEYBYTES MLKEM_SECRETKEYBYTES
|
|
117
|
+
#define PQ_MLKEM_CIPHERTEXTBYTES MLKEM_CIPHERTEXTBYTES
|
|
118
|
+
#define PQ_MLKEM_SHAREDSECRETBYTES MLKEM_SHAREDSECRETBYTES
|
|
119
|
+
|
|
120
|
+
#define PQ_HYBRID_PUBLICKEYBYTES HYBRID_PUBLICKEYBYTES
|
|
121
|
+
#define PQ_HYBRID_SECRETKEYBYTES HYBRID_SECRETKEYBYTES
|
|
122
|
+
#define PQ_HYBRID_CIPHERTEXTBYTES HYBRID_CIPHERTEXTBYTES
|
|
123
|
+
#define PQ_HYBRID_SHAREDSECRETBYTES HYBRID_SHAREDSECRETBYTES
|
|
124
|
+
|
|
125
|
+
#define PQ_MLDSA_PUBLICKEYBYTES MLDSA_PUBLICKEYBYTES
|
|
126
|
+
#define PQ_MLDSA_SECRETKEYBYTES MLDSA_SECRETKEYBYTES
|
|
127
|
+
#define PQ_MLDSA_BYTES MLDSA_BYTES
|
|
128
|
+
|
|
129
|
+
int pq_hybrid_kem_keypair(uint8_t *public_key, uint8_t *secret_key);
|
|
130
|
+
int pq_hybrid_kem_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret,
|
|
131
|
+
const uint8_t *public_key);
|
|
132
|
+
int pq_hybrid_kem_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
|
|
133
|
+
const uint8_t *secret_key);
|
|
134
|
+
|
|
135
|
+
#endif
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
pqclean_version=2cc64716044832eea747234ddbffc06746ab815d
|
|
2
|
+
pqclean_url=https://github.com/PQClean/PQClean/archive/2cc64716044832eea747234ddbffc06746ab815d.tar.gz
|
|
3
|
+
pqclean_archive_sha256=0e92076a79082a8d220e27227f37b280fb2ce050af412babd2bc755ab37b871a
|
|
4
|
+
pqclean_strip=PQClean-2cc64716044832eea747234ddbffc06746ab815d
|
|
5
|
+
pqclean_tree_sha256=2af0c3ec2cbe3b06805c39d3d1389ee7a9b0b29a83183328374a0db55f56c19e
|