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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#include "fips202.h"
|
|
2
|
+
#include "params.h"
|
|
3
|
+
#include "symmetric.h"
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
|
|
8
|
+
/*************************************************
|
|
9
|
+
* Name: PQCLEAN_MLKEM1024_CLEAN_kyber_shake128_absorb
|
|
10
|
+
*
|
|
11
|
+
* Description: Absorb step of the SHAKE128 specialized for the Kyber context.
|
|
12
|
+
*
|
|
13
|
+
* Arguments: - xof_state *state: pointer to (uninitialized) output Keccak state
|
|
14
|
+
* - const uint8_t *seed: pointer to KYBER_SYMBYTES input to be absorbed into state
|
|
15
|
+
* - uint8_t i: additional byte of input
|
|
16
|
+
* - uint8_t j: additional byte of input
|
|
17
|
+
**************************************************/
|
|
18
|
+
void PQCLEAN_MLKEM1024_CLEAN_kyber_shake128_absorb(xof_state *state,
|
|
19
|
+
const uint8_t seed[KYBER_SYMBYTES],
|
|
20
|
+
uint8_t x,
|
|
21
|
+
uint8_t y) {
|
|
22
|
+
uint8_t extseed[KYBER_SYMBYTES + 2];
|
|
23
|
+
|
|
24
|
+
memcpy(extseed, seed, KYBER_SYMBYTES);
|
|
25
|
+
extseed[KYBER_SYMBYTES + 0] = x;
|
|
26
|
+
extseed[KYBER_SYMBYTES + 1] = y;
|
|
27
|
+
|
|
28
|
+
shake128_absorb(state, extseed, sizeof(extseed));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/*************************************************
|
|
32
|
+
* Name: PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_prf
|
|
33
|
+
*
|
|
34
|
+
* Description: Usage of SHAKE256 as a PRF, concatenates secret and public input
|
|
35
|
+
* and then generates outlen bytes of SHAKE256 output
|
|
36
|
+
*
|
|
37
|
+
* Arguments: - uint8_t *out: pointer to output
|
|
38
|
+
* - size_t outlen: number of requested output bytes
|
|
39
|
+
* - const uint8_t *key: pointer to the key (of length KYBER_SYMBYTES)
|
|
40
|
+
* - uint8_t nonce: single-byte nonce (public PRF input)
|
|
41
|
+
**************************************************/
|
|
42
|
+
void PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_prf(uint8_t *out, size_t outlen, const uint8_t key[KYBER_SYMBYTES], uint8_t nonce) {
|
|
43
|
+
uint8_t extkey[KYBER_SYMBYTES + 1];
|
|
44
|
+
|
|
45
|
+
memcpy(extkey, key, KYBER_SYMBYTES);
|
|
46
|
+
extkey[KYBER_SYMBYTES] = nonce;
|
|
47
|
+
|
|
48
|
+
shake256(out, outlen, extkey, sizeof(extkey));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/*************************************************
|
|
52
|
+
* Name: PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_prf
|
|
53
|
+
*
|
|
54
|
+
* Description: Usage of SHAKE256 as a PRF, concatenates secret and public input
|
|
55
|
+
* and then generates outlen bytes of SHAKE256 output
|
|
56
|
+
*
|
|
57
|
+
* Arguments: - uint8_t *out: pointer to output
|
|
58
|
+
* - size_t outlen: number of requested output bytes
|
|
59
|
+
* - const uint8_t *key: pointer to the key (of length KYBER_SYMBYTES)
|
|
60
|
+
* - uint8_t nonce: single-byte nonce (public PRF input)
|
|
61
|
+
**************************************************/
|
|
62
|
+
void PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_rkprf(uint8_t out[KYBER_SSBYTES], const uint8_t key[KYBER_SYMBYTES], const uint8_t input[KYBER_CIPHERTEXTBYTES]) {
|
|
63
|
+
shake256incctx s;
|
|
64
|
+
|
|
65
|
+
shake256_inc_init(&s);
|
|
66
|
+
shake256_inc_absorb(&s, key, KYBER_SYMBYTES);
|
|
67
|
+
shake256_inc_absorb(&s, input, KYBER_CIPHERTEXTBYTES);
|
|
68
|
+
shake256_inc_finalize(&s);
|
|
69
|
+
shake256_inc_squeeze(out, KYBER_SSBYTES, &s);
|
|
70
|
+
shake256_inc_ctx_release(&s);
|
|
71
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#ifndef PQCLEAN_MLKEM1024_CLEAN_SYMMETRIC_H
|
|
2
|
+
#define PQCLEAN_MLKEM1024_CLEAN_SYMMETRIC_H
|
|
3
|
+
#include "fips202.h"
|
|
4
|
+
#include "params.h"
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
typedef shake128ctx xof_state;
|
|
10
|
+
|
|
11
|
+
void PQCLEAN_MLKEM1024_CLEAN_kyber_shake128_absorb(xof_state *s,
|
|
12
|
+
const uint8_t seed[KYBER_SYMBYTES],
|
|
13
|
+
uint8_t x,
|
|
14
|
+
uint8_t y);
|
|
15
|
+
|
|
16
|
+
void PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_prf(uint8_t *out, size_t outlen, const uint8_t key[KYBER_SYMBYTES], uint8_t nonce);
|
|
17
|
+
|
|
18
|
+
void PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_rkprf(uint8_t out[KYBER_SSBYTES], const uint8_t key[KYBER_SYMBYTES], const uint8_t input[KYBER_CIPHERTEXTBYTES]);
|
|
19
|
+
|
|
20
|
+
#define XOF_BLOCKBYTES SHAKE128_RATE
|
|
21
|
+
|
|
22
|
+
#define hash_h(OUT, IN, INBYTES) sha3_256(OUT, IN, INBYTES)
|
|
23
|
+
#define hash_g(OUT, IN, INBYTES) sha3_512(OUT, IN, INBYTES)
|
|
24
|
+
#define xof_absorb(STATE, SEED, X, Y) PQCLEAN_MLKEM1024_CLEAN_kyber_shake128_absorb(STATE, SEED, X, Y)
|
|
25
|
+
#define xof_squeezeblocks(OUT, OUTBLOCKS, STATE) shake128_squeezeblocks(OUT, OUTBLOCKS, STATE)
|
|
26
|
+
#define xof_ctx_release(STATE) shake128_ctx_release(STATE)
|
|
27
|
+
#define prf(OUT, OUTBYTES, KEY, NONCE) PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_prf(OUT, OUTBYTES, KEY, NONCE)
|
|
28
|
+
#define rkprf(OUT, KEY, INPUT) PQCLEAN_MLKEM1024_CLEAN_kyber_shake256_rkprf(OUT, KEY, INPUT)
|
|
29
|
+
|
|
30
|
+
#endif /* SYMMETRIC_H */
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#include "compat.h"
|
|
2
|
+
#include "verify.h"
|
|
3
|
+
#include <stddef.h>
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
/*************************************************
|
|
7
|
+
* Name: PQCLEAN_MLKEM1024_CLEAN_verify
|
|
8
|
+
*
|
|
9
|
+
* Description: Compare two arrays for equality in constant time.
|
|
10
|
+
*
|
|
11
|
+
* Arguments: const uint8_t *a: pointer to first byte array
|
|
12
|
+
* const uint8_t *b: pointer to second byte array
|
|
13
|
+
* size_t len: length of the byte arrays
|
|
14
|
+
*
|
|
15
|
+
* Returns 0 if the byte arrays are equal, 1 otherwise
|
|
16
|
+
**************************************************/
|
|
17
|
+
int PQCLEAN_MLKEM1024_CLEAN_verify(const uint8_t *a, const uint8_t *b, size_t len) {
|
|
18
|
+
size_t i;
|
|
19
|
+
uint8_t r = 0;
|
|
20
|
+
|
|
21
|
+
for (i = 0; i < len; i++) {
|
|
22
|
+
r |= a[i] ^ b[i];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (-(uint64_t)r) >> 63;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*************************************************
|
|
29
|
+
* Name: PQCLEAN_MLKEM1024_CLEAN_cmov
|
|
30
|
+
*
|
|
31
|
+
* Description: Copy len bytes from x to r if b is 1;
|
|
32
|
+
* don't modify x if b is 0. Requires b to be in {0,1};
|
|
33
|
+
* assumes two's complement representation of negative integers.
|
|
34
|
+
* Runs in constant time.
|
|
35
|
+
*
|
|
36
|
+
* Arguments: uint8_t *r: pointer to output byte array
|
|
37
|
+
* const uint8_t *x: pointer to input byte array
|
|
38
|
+
* size_t len: Amount of bytes to be copied
|
|
39
|
+
* uint8_t b: Condition bit; has to be in {0,1}
|
|
40
|
+
**************************************************/
|
|
41
|
+
void PQCLEAN_MLKEM1024_CLEAN_cmov(uint8_t *r, const uint8_t *x, size_t len, uint8_t b) {
|
|
42
|
+
size_t i;
|
|
43
|
+
|
|
44
|
+
PQCLEAN_PREVENT_BRANCH_HACK(b);
|
|
45
|
+
|
|
46
|
+
b = -b;
|
|
47
|
+
for (i = 0; i < len; i++) {
|
|
48
|
+
r[i] ^= b & (r[i] ^ x[i]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/*************************************************
|
|
54
|
+
* Name: PQCLEAN_MLKEM1024_CLEAN_cmov_int16
|
|
55
|
+
*
|
|
56
|
+
* Description: Copy input v to *r if b is 1, don't modify *r if b is 0.
|
|
57
|
+
* Requires b to be in {0,1};
|
|
58
|
+
* Runs in constant time.
|
|
59
|
+
*
|
|
60
|
+
* Arguments: int16_t *r: pointer to output int16_t
|
|
61
|
+
* int16_t v: input int16_t
|
|
62
|
+
* uint8_t b: Condition bit; has to be in {0,1}
|
|
63
|
+
**************************************************/
|
|
64
|
+
void PQCLEAN_MLKEM1024_CLEAN_cmov_int16(int16_t *r, int16_t v, uint16_t b) {
|
|
65
|
+
b = -b;
|
|
66
|
+
*r ^= b & ((*r) ^ v);
|
|
67
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#ifndef PQCLEAN_MLKEM1024_CLEAN_VERIFY_H
|
|
2
|
+
#define PQCLEAN_MLKEM1024_CLEAN_VERIFY_H
|
|
3
|
+
#include "params.h"
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
int PQCLEAN_MLKEM1024_CLEAN_verify(const uint8_t *a, const uint8_t *b, size_t len);
|
|
8
|
+
|
|
9
|
+
void PQCLEAN_MLKEM1024_CLEAN_cmov(uint8_t *r, const uint8_t *x, size_t len, uint8_t b);
|
|
10
|
+
|
|
11
|
+
void PQCLEAN_MLKEM1024_CLEAN_cmov_int16(int16_t *r, int16_t v, uint16_t b);
|
|
12
|
+
|
|
13
|
+
#endif
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# This Makefile can be used with GNU Make or BSD Make
|
|
2
|
+
|
|
3
|
+
LIB=libml-kem-512_clean.a
|
|
4
|
+
HEADERS=api.h cbd.h indcpa.h kem.h ntt.h params.h poly.h polyvec.h reduce.h symmetric.h verify.h
|
|
5
|
+
OBJECTS=cbd.o indcpa.o kem.o ntt.o poly.o polyvec.o reduce.o symmetric-shake.o verify.o
|
|
6
|
+
|
|
7
|
+
CFLAGS=-O3 -Wall -Wextra -Wpedantic -Werror -Wmissing-prototypes -Wredundant-decls -std=c99 -I../../../common $(EXTRAFLAGS)
|
|
8
|
+
|
|
9
|
+
all: $(LIB)
|
|
10
|
+
|
|
11
|
+
%.o: %.c $(HEADERS)
|
|
12
|
+
$(CC) $(CFLAGS) -c -o $@ $<
|
|
13
|
+
|
|
14
|
+
$(LIB): $(OBJECTS)
|
|
15
|
+
$(AR) -r $@ $(OBJECTS)
|
|
16
|
+
|
|
17
|
+
clean:
|
|
18
|
+
$(RM) $(OBJECTS)
|
|
19
|
+
$(RM) $(LIB)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# This Makefile can be used with Microsoft Visual Studio's nmake using the command:
|
|
2
|
+
# nmake /f Makefile.Microsoft_nmake
|
|
3
|
+
|
|
4
|
+
LIBRARY=libml-kem-512_clean.lib
|
|
5
|
+
OBJECTS=cbd.obj indcpa.obj kem.obj ntt.obj poly.obj polyvec.obj reduce.obj symmetric-shake.obj verify.obj
|
|
6
|
+
|
|
7
|
+
# Warning C4146 is raised when a unary minus operator is applied to an
|
|
8
|
+
# unsigned type; this has nonetheless been standard and portable for as
|
|
9
|
+
# long as there has been a C standard, and we need it for constant-time
|
|
10
|
+
# computations. Thus, we disable that spurious warning.
|
|
11
|
+
CFLAGS=/nologo /O2 /I ..\..\..\common /W4 /WX /wd4146
|
|
12
|
+
|
|
13
|
+
all: $(LIBRARY)
|
|
14
|
+
|
|
15
|
+
# Make sure objects are recompiled if headers change.
|
|
16
|
+
$(OBJECTS): *.h
|
|
17
|
+
|
|
18
|
+
$(LIBRARY): $(OBJECTS)
|
|
19
|
+
LIB.EXE /NOLOGO /WX /OUT:$@ $**
|
|
20
|
+
|
|
21
|
+
clean:
|
|
22
|
+
-DEL $(OBJECTS)
|
|
23
|
+
-DEL $(LIBRARY)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifndef PQCLEAN_MLKEM512_CLEAN_API_H
|
|
2
|
+
#define PQCLEAN_MLKEM512_CLEAN_API_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_SECRETKEYBYTES 1632
|
|
7
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_PUBLICKEYBYTES 800
|
|
8
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_CIPHERTEXTBYTES 768
|
|
9
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_BYTES 32
|
|
10
|
+
#define PQCLEAN_MLKEM512_CLEAN_CRYPTO_ALGNAME "ML-KEM-512"
|
|
11
|
+
|
|
12
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_keypair(uint8_t *pk, uint8_t *sk);
|
|
13
|
+
|
|
14
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t *pk);
|
|
15
|
+
|
|
16
|
+
int PQCLEAN_MLKEM512_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
|
|
17
|
+
|
|
18
|
+
#endif
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#include "cbd.h"
|
|
2
|
+
#include "params.h"
|
|
3
|
+
#include <stdint.h>
|
|
4
|
+
|
|
5
|
+
/*************************************************
|
|
6
|
+
* Name: load32_littleendian
|
|
7
|
+
*
|
|
8
|
+
* Description: load 4 bytes into a 32-bit integer
|
|
9
|
+
* in little-endian order
|
|
10
|
+
*
|
|
11
|
+
* Arguments: - const uint8_t *x: pointer to input byte array
|
|
12
|
+
*
|
|
13
|
+
* Returns 32-bit unsigned integer loaded from x
|
|
14
|
+
**************************************************/
|
|
15
|
+
static uint32_t load32_littleendian(const uint8_t x[4]) {
|
|
16
|
+
uint32_t r;
|
|
17
|
+
r = (uint32_t)x[0];
|
|
18
|
+
r |= (uint32_t)x[1] << 8;
|
|
19
|
+
r |= (uint32_t)x[2] << 16;
|
|
20
|
+
r |= (uint32_t)x[3] << 24;
|
|
21
|
+
return r;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*************************************************
|
|
25
|
+
* Name: load24_littleendian
|
|
26
|
+
*
|
|
27
|
+
* Description: load 3 bytes into a 32-bit integer
|
|
28
|
+
* in little-endian order.
|
|
29
|
+
* This function is only needed for Kyber-512
|
|
30
|
+
*
|
|
31
|
+
* Arguments: - const uint8_t *x: pointer to input byte array
|
|
32
|
+
*
|
|
33
|
+
* Returns 32-bit unsigned integer loaded from x (most significant byte is zero)
|
|
34
|
+
**************************************************/
|
|
35
|
+
static uint32_t load24_littleendian(const uint8_t x[3]) {
|
|
36
|
+
uint32_t r;
|
|
37
|
+
r = (uint32_t)x[0];
|
|
38
|
+
r |= (uint32_t)x[1] << 8;
|
|
39
|
+
r |= (uint32_t)x[2] << 16;
|
|
40
|
+
return r;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/*************************************************
|
|
45
|
+
* Name: cbd2
|
|
46
|
+
*
|
|
47
|
+
* Description: Given an array of uniformly random bytes, compute
|
|
48
|
+
* polynomial with coefficients distributed according to
|
|
49
|
+
* a centered binomial distribution with parameter eta=2
|
|
50
|
+
*
|
|
51
|
+
* Arguments: - poly *r: pointer to output polynomial
|
|
52
|
+
* - const uint8_t *buf: pointer to input byte array
|
|
53
|
+
**************************************************/
|
|
54
|
+
static void cbd2(poly *r, const uint8_t buf[2 * KYBER_N / 4]) {
|
|
55
|
+
unsigned int i, j;
|
|
56
|
+
uint32_t t, d;
|
|
57
|
+
int16_t a, b;
|
|
58
|
+
|
|
59
|
+
for (i = 0; i < KYBER_N / 8; i++) {
|
|
60
|
+
t = load32_littleendian(buf + 4 * i);
|
|
61
|
+
d = t & 0x55555555;
|
|
62
|
+
d += (t >> 1) & 0x55555555;
|
|
63
|
+
|
|
64
|
+
for (j = 0; j < 8; j++) {
|
|
65
|
+
a = (d >> (4 * j + 0)) & 0x3;
|
|
66
|
+
b = (d >> (4 * j + 2)) & 0x3;
|
|
67
|
+
r->coeffs[8 * i + j] = a - b;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/*************************************************
|
|
73
|
+
* Name: cbd3
|
|
74
|
+
*
|
|
75
|
+
* Description: Given an array of uniformly random bytes, compute
|
|
76
|
+
* polynomial with coefficients distributed according to
|
|
77
|
+
* a centered binomial distribution with parameter eta=3.
|
|
78
|
+
* This function is only needed for Kyber-512
|
|
79
|
+
*
|
|
80
|
+
* Arguments: - poly *r: pointer to output polynomial
|
|
81
|
+
* - const uint8_t *buf: pointer to input byte array
|
|
82
|
+
**************************************************/
|
|
83
|
+
static void cbd3(poly *r, const uint8_t buf[3 * KYBER_N / 4]) {
|
|
84
|
+
unsigned int i, j;
|
|
85
|
+
uint32_t t, d;
|
|
86
|
+
int16_t a, b;
|
|
87
|
+
|
|
88
|
+
for (i = 0; i < KYBER_N / 4; i++) {
|
|
89
|
+
t = load24_littleendian(buf + 3 * i);
|
|
90
|
+
d = t & 0x00249249;
|
|
91
|
+
d += (t >> 1) & 0x00249249;
|
|
92
|
+
d += (t >> 2) & 0x00249249;
|
|
93
|
+
|
|
94
|
+
for (j = 0; j < 4; j++) {
|
|
95
|
+
a = (d >> (6 * j + 0)) & 0x7;
|
|
96
|
+
b = (d >> (6 * j + 3)) & 0x7;
|
|
97
|
+
r->coeffs[4 * i + j] = a - b;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void PQCLEAN_MLKEM512_CLEAN_poly_cbd_eta1(poly *r, const uint8_t buf[KYBER_ETA1 * KYBER_N / 4]) {
|
|
103
|
+
cbd3(r, buf);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void PQCLEAN_MLKEM512_CLEAN_poly_cbd_eta2(poly *r, const uint8_t buf[KYBER_ETA2 * KYBER_N / 4]) {
|
|
107
|
+
cbd2(r, buf);
|
|
108
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#ifndef PQCLEAN_MLKEM512_CLEAN_CBD_H
|
|
2
|
+
#define PQCLEAN_MLKEM512_CLEAN_CBD_H
|
|
3
|
+
#include "params.h"
|
|
4
|
+
#include "poly.h"
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
void PQCLEAN_MLKEM512_CLEAN_poly_cbd_eta1(poly *r, const uint8_t buf[KYBER_ETA1 * KYBER_N / 4]);
|
|
8
|
+
|
|
9
|
+
void PQCLEAN_MLKEM512_CLEAN_poly_cbd_eta2(poly *r, const uint8_t buf[KYBER_ETA2 * KYBER_N / 4]);
|
|
10
|
+
|
|
11
|
+
#endif
|