kpqc 0.1.1 → 0.2.1

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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +29 -14
  4. data/THIRD_PARTY_NOTICES.md +14 -47
  5. data/ext/kpqc/extconf_helper.rb +6 -3
  6. data/ext/kpqc/secure_clear.c +8 -0
  7. data/kpqc.gemspec +5 -3
  8. data/lib/kpqc/aimer.rb +6 -6
  9. data/lib/kpqc/api.rb +1 -1
  10. data/lib/kpqc/ntruplus.rb +1 -1
  11. data/lib/kpqc/smaugt.rb +1 -1
  12. data/lib/kpqc/types.rb +2 -2
  13. data/lib/kpqc/version.rb +1 -1
  14. data/test/kat/aimer128f.rsp +4 -4
  15. data/test/kat/aimer128s.rsp +4 -4
  16. data/test/kat/aimer192f.rsp +4 -4
  17. data/test/kat/aimer192s.rsp +4 -4
  18. data/test/kat/aimer256f.rsp +4 -4
  19. data/test/kat/aimer256s.rsp +4 -4
  20. data/test/kat/haetae2.rsp +1 -1
  21. data/test/kat/haetae3.rsp +1 -1
  22. data/test/kat/haetae5.rsp +1 -1
  23. data/test/kat_test.rb +108 -52
  24. data/vendor/AIMer/LICENSE +1 -1
  25. data/vendor/AIMer/aim3.c +227 -0
  26. data/vendor/AIMer/aim3.h +63 -0
  27. data/vendor/AIMer/field.h +12 -4
  28. data/vendor/AIMer/field128.c +24 -381
  29. data/vendor/AIMer/field192.c +24 -400
  30. data/vendor/AIMer/field256.c +28 -447
  31. data/vendor/AIMer/field_common.c +98 -0
  32. data/vendor/AIMer/field_internal.h +218 -0
  33. data/vendor/AIMer/params/params-aimer-128f.h +8 -8
  34. data/vendor/AIMer/params/params-aimer-128s.h +8 -8
  35. data/vendor/AIMer/params/params-aimer-192f.h +8 -8
  36. data/vendor/AIMer/params/params-aimer-192s.h +8 -8
  37. data/vendor/AIMer/params/params-aimer-256f.h +8 -8
  38. data/vendor/AIMer/params/params-aimer-256s.h +8 -8
  39. data/vendor/AIMer/params.h +5 -0
  40. data/vendor/AIMer/sign.c +246 -167
  41. data/vendor/AIMer/sign.h +6 -6
  42. data/vendor/AIMer/tree.c +10 -4
  43. data/vendor/AIMer/tree.h +1 -1
  44. data/vendor/HAETAE/include/fixpoint.h +14 -14
  45. data/vendor/HAETAE/include/rans_byte.h +10 -9
  46. data/vendor/HAETAE/src/decompose.c +8 -4
  47. data/vendor/HAETAE/src/encoding.c +5 -5
  48. data/vendor/HAETAE/src/fft.c +1 -1
  49. data/vendor/HAETAE/src/fips202.c +26 -14
  50. data/vendor/HAETAE/src/fixpoint.c +21 -18
  51. data/vendor/HAETAE/src/ntt.c +2 -0
  52. data/vendor/HAETAE/src/packing.c +15 -15
  53. data/vendor/HAETAE/src/poly.c +30 -3
  54. data/vendor/HAETAE/src/polyfix.c +2 -2
  55. data/vendor/HAETAE/src/polymat.c +2 -2
  56. data/vendor/HAETAE/src/polyvec.c +7 -5
  57. data/vendor/HAETAE/src/reduce.c +2 -0
  58. data/vendor/HAETAE/src/sampler.c +231 -47
  59. data/vendor/HAETAE/src/sign.c +11 -10
  60. data/vendor/NTRUplus/NTRU+1152/api.h +27 -8
  61. data/vendor/NTRUplus/NTRU+1152/fips202/fips202.c +12 -269
  62. data/vendor/NTRUplus/NTRU+1152/fips202/fips202.h +4 -113
  63. data/vendor/NTRUplus/NTRU+1152/kem.c +110 -40
  64. data/vendor/NTRUplus/NTRU+1152/ntt.c +50 -54
  65. data/vendor/NTRUplus/NTRU+1152/poly.c +21 -13
  66. data/vendor/NTRUplus/NTRU+1152/poly.h +3 -3
  67. data/vendor/NTRUplus/NTRU+1152/randombytes.h +1 -0
  68. data/vendor/NTRUplus/NTRU+1152/symmetric.c +3 -9
  69. data/vendor/NTRUplus/NTRU+1152/symmetric.h +13 -3
  70. data/vendor/NTRUplus/NTRU+1152/util.h +15 -0
  71. data/vendor/NTRUplus/NTRU+768/api.h +27 -8
  72. data/vendor/NTRUplus/NTRU+768/fips202/fips202.c +12 -269
  73. data/vendor/NTRUplus/NTRU+768/fips202/fips202.h +4 -113
  74. data/vendor/NTRUplus/NTRU+768/kem.c +110 -40
  75. data/vendor/NTRUplus/NTRU+768/ntt.c +50 -54
  76. data/vendor/NTRUplus/NTRU+768/poly.c +23 -13
  77. data/vendor/NTRUplus/NTRU+768/poly.h +3 -3
  78. data/vendor/NTRUplus/NTRU+768/randombytes.h +1 -0
  79. data/vendor/NTRUplus/NTRU+768/symmetric.c +3 -9
  80. data/vendor/NTRUplus/NTRU+768/symmetric.h +13 -3
  81. data/vendor/NTRUplus/NTRU+768/util.h +15 -0
  82. data/vendor/NTRUplus/NTRU+864/api.h +27 -8
  83. data/vendor/NTRUplus/NTRU+864/fips202/fips202.c +12 -269
  84. data/vendor/NTRUplus/NTRU+864/fips202/fips202.h +4 -113
  85. data/vendor/NTRUplus/NTRU+864/kem.c +110 -40
  86. data/vendor/NTRUplus/NTRU+864/ntt.c +24 -28
  87. data/vendor/NTRUplus/NTRU+864/poly.c +26 -12
  88. data/vendor/NTRUplus/NTRU+864/poly.h +3 -3
  89. data/vendor/NTRUplus/NTRU+864/randombytes.h +1 -0
  90. data/vendor/NTRUplus/NTRU+864/symmetric.c +3 -9
  91. data/vendor/NTRUplus/NTRU+864/symmetric.h +13 -3
  92. data/vendor/NTRUplus/NTRU+864/util.h +15 -0
  93. data/vendor/SMAUG-T/src/cbd.c +4 -4
  94. data/vendor/SMAUG-T/src/ciphertext.c +2 -2
  95. data/vendor/SMAUG-T/src/dg.c +2 -2
  96. data/vendor/SMAUG-T/src/hwt.c +4 -4
  97. data/vendor/SMAUG-T/src/indcpa.c +5 -5
  98. data/vendor/SMAUG-T/src/kem.c +9 -7
  99. data/vendor/SMAUG-T/src/key.c +2 -2
  100. data/vendor/SMAUG-T/src/pack.c +8 -8
  101. metadata +16 -10
  102. data/vendor/AIMer/aim2.c +0 -163
  103. data/vendor/AIMer/aim2.h +0 -36
  104. data/vendor/AIMer/aim2_constant.h +0 -74
  105. data/vendor/SOURCES.json +0 -130
@@ -19,7 +19,7 @@
19
19
  * - uint8_t *seed: pointer to input seed (of length
20
20
  * SMAUGT_DELTA_BYTES)
21
21
  *
22
- * Specification: Implements Algorithm 5, ExpandR.
22
+ * Specification: Implements @[KS X 123456, Algorithm 5, ExpandR]
23
23
  **************************************************/
24
24
  void expand_r(polyvec *r, const uint8_t *seed) {
25
25
  unsigned int i;
@@ -49,7 +49,7 @@ void expand_r(polyvec *r, const uint8_t *seed) {
49
49
  * private key
50
50
  * - uint8_t seed[SMAUGT_CRYPTO_BYTES]: pointer to input seed
51
51
  *
52
- * Specification: Implements Algorithm 25, SMAUGT-T.PKE.KeyGen.
52
+ * Specification: Implements @[KS X 123456, Algorithm 25, SMAUGT-T.PKE.KeyGen]
53
53
  **************************************************/
54
54
  void indcpa_keypair(uint8_t pk[SMAUGT_PUBLICKEY_BYTES],
55
55
  uint8_t sk[SMAUGT_PKE_SECRETKEY_BYTES],
@@ -94,7 +94,7 @@ void indcpa_keypair(uint8_t pk[SMAUGT_PUBLICKEY_BYTES],
94
94
  * message
95
95
  * - const uint8_t seed[SMAUGT_DELTA_BYTES]: pointer to input seed
96
96
  *
97
- * Specification: Implements Algorithm 26, SMAUGT-T.PKE.Enc.
97
+ * Specification: Implements @[KS X 123456, Algorithm 26, SMAUGT-T.PKE.Enc]
98
98
  **************************************************/
99
99
  void indcpa_enc(uint8_t ctxt[SMAUGT_CIPHERTEXT_BYTES],
100
100
  const uint8_t pk[SMAUGT_PUBLICKEY_BYTES],
@@ -110,7 +110,7 @@ void indcpa_enc(uint8_t ctxt[SMAUGT_CIPHERTEXT_BYTES],
110
110
  memset(&r, 0, sizeof(polyvec));
111
111
 
112
112
  if (seed == NULL)
113
- { if (randombytes(seed_r, SMAUGT_DELTA_BYTES) != 0) return; }
113
+ randombytes(seed_r, SMAUGT_DELTA_BYTES);
114
114
  else
115
115
  cmov(seed_r, seed, SMAUGT_DELTA_BYTES, 1);
116
116
  expand_r(&r, seed_r);
@@ -139,7 +139,7 @@ void indcpa_enc(uint8_t ctxt[SMAUGT_CIPHERTEXT_BYTES],
139
139
  * - const uint8_t ctxt[SMAUGT_CIPHERTEXT_BYTES]: pointer to input
140
140
  * ciphertext
141
141
  *
142
- * Specification: Implements Algorithm 28, SMAUGT-T.PKE.Dec.
142
+ * Specification: Implements @[KS X 123456, Algorithm 28, SMAUGT-T.PKE.Dec]
143
143
  **************************************************/
144
144
  void indcpa_dec(uint8_t mu[SMAUGT_MSG_BYTES],
145
145
  const uint8_t sk[SMAUGT_PKE_SECRETKEY_BYTES],
@@ -1,4 +1,3 @@
1
- /* kpqc-py: propagate OS entropy failures (2026-09-06). */
2
1
  // SPDX-License-Identifier: MIT
3
2
 
4
3
  #include "api.h"
@@ -25,7 +24,8 @@
25
24
  *
26
25
  * Return: 0 on success, 1 on failure
27
26
  *
28
- * Specification: Implements Algorithm 33, SMAUG-T.KEM.EncapInternal.
27
+ * Specification: Implements @[KS X 123456, Algorithm 33,
28
+ * SMAUG-T.KEM.EncapInternal]
29
29
  **************************************************/
30
30
  int crypto_kem_keypair_internal(uint8_t *pk, uint8_t *sk,
31
31
  uint8_t d[SMAUGT_T_BYTES],
@@ -51,7 +51,7 @@ int crypto_kem_keypair_internal(uint8_t *pk, uint8_t *sk,
51
51
  *
52
52
  * Return: 0 on success, 1 on failure
53
53
  *
54
- * Specification: Implements Algorithm 30, SMAUG-T.KEM.KeyGen.
54
+ * Specification: Implements @[KS X 123456, Algorithm 30, SMAUG-T.KEM.KeyGen]
55
55
  **************************************************/
56
56
  int crypto_kem_keypair(uint8_t *pk, uint8_t *sk) {
57
57
  int ret = 0;
@@ -81,7 +81,8 @@ int crypto_kem_keypair(uint8_t *pk, uint8_t *sk) {
81
81
  *
82
82
  * Return: 0 on success, 1 on failure
83
83
  *
84
- * Specification: Implements Algorithm 34, SMAUG-T.KEM.EncapInternal.
84
+ * Specification: Implements @[KS X 123456, Algorithm 34,
85
+ * SMAUG-T.KEM.EncapInternal]
85
86
  **************************************************/
86
87
  int crypto_kem_enc_internal(uint8_t *ctxt, uint8_t *ss, const uint8_t *pk,
87
88
  const uint8_t *mu) {
@@ -111,7 +112,7 @@ int crypto_kem_enc_internal(uint8_t *ctxt, uint8_t *ss, const uint8_t *pk,
111
112
  *
112
113
  * Return: 0 on success, 1 on failure
113
114
  *
114
- * Specification: Implements Algorithm 31, SMAUG-T.KEM.Encap.
115
+ * Specification: Implements @[KS X 123456, Algorithm 31, SMAUG-T.KEM.Encap]
115
116
  **************************************************/
116
117
  int crypto_kem_enc(uint8_t *ctxt, uint8_t *ss, const uint8_t *pk) {
117
118
  int ret = 0;
@@ -136,7 +137,8 @@ int crypto_kem_enc(uint8_t *ctxt, uint8_t *ss, const uint8_t *pk) {
136
137
  *
137
138
  * Return: 0 on success, 1 on failure
138
139
  *
139
- * Specification: Implements Algorithm 35, SMAUG-T.KEM.DecapInternal.
140
+ * Specification: Implements @[KS X 123456, Algorithm 35,
141
+ * SMAUG-T.KEM.DecapInternal]
140
142
  **************************************************/
141
143
  int crypto_kem_dec_internal(uint8_t *ss, const uint8_t *ctxt,
142
144
  const uint8_t *sk) {
@@ -185,7 +187,7 @@ int crypto_kem_dec_internal(uint8_t *ss, const uint8_t *ctxt,
185
187
  *
186
188
  * Return: 0 on success, 1 on failure
187
189
  *
188
- * Specification: Implements Algorithm 32, SMAUG-T.KEM.Decap.
190
+ * Specification: Implements @[KS X 123456, Algorithm 32, SMAUG-T.KEM.Decap]
189
191
  **************************************************/
190
192
  int crypto_kem_dec(uint8_t *ss, const uint8_t *ctxt, const uint8_t *sk) {
191
193
  int ret = 0;
@@ -18,7 +18,7 @@
18
18
  * Arguments: - polyvec A[SMAUGT_K]: pointer to output matrix A
19
19
  * - const uint8_t seed[SMAUGT_PKSEED_BYTES]: pointer to input seed
20
20
  *
21
- * Specification: Implements Algorithm 1, ExpandA.
21
+ * Specification: Implements @[KS X 123456, Algorithm 1, ExpandA]
22
22
  **************************************************/
23
23
  void expand_A(polyvec A[SMAUGT_K], const uint8_t seed[SMAUGT_PKSEED_BYTES]) {
24
24
  unsigned int i, j;
@@ -65,7 +65,7 @@ void expand_b(polyvec *b, const polyvec A[SMAUGT_K], const polyvec *s,
65
65
  * - const uint8_t seed[SMAUGT_CRYPTO_BYTES]: pointer to input seed
66
66
  * of s(x)
67
67
  *
68
- * Specification: Implements Algorithm 2, ExpandS.
68
+ * Specification: Implements @[KS X 123456, Algorithm 2, ExpandS]
69
69
  **************************************************/
70
70
  void expand_s(secret_key *sk, const uint8_t seed[SMAUGT_CRYPTO_BYTES]) {
71
71
  unsigned int i, j;
@@ -13,7 +13,7 @@
13
13
  * Arguments: - uint8_t *output: pointer to output byte array
14
14
  * - const public_key *pk: pointer to input public key
15
15
  *
16
- * Specification: Implements Algorithm 14, PackEncK.
16
+ * Specification: Implements @[KS X 123456, Algorithm 14, PackEncK]
17
17
  **************************************************/
18
18
  void pack_enck(uint8_t *output, const public_key *pk) {
19
19
  memcpy(output, pk->seed, sizeof(uint8_t) * SMAUGT_PKSEED_BYTES);
@@ -28,7 +28,7 @@ void pack_enck(uint8_t *output, const public_key *pk) {
28
28
  * Arguments: - public_key *pk: pointer to output public key
29
29
  * - const uint8_t *input: pointer to input byte array
30
30
  *
31
- * Specification: Implements Algorithm 15, UnpackEncK.
31
+ * Specification: Implements @[KS X 123456, Algorithm 15, UnpackEncK]
32
32
  **************************************************/
33
33
  void unpack_enck(public_key *pk, const uint8_t *input) {
34
34
  memcpy(pk->seed, input, SMAUGT_PKSEED_BYTES);
@@ -44,7 +44,7 @@ void unpack_enck(public_key *pk, const uint8_t *input) {
44
44
  * Arguments: - uint8_t *output: pointer to output byte array
45
45
  * - const secret_key *sk: pointer to input private key
46
46
  *
47
- * Specification: Implements Algorithm 16, PackDecK.
47
+ * Specification: Implements @[KS X 123456, Algorithm 16, PackDecK]
48
48
  **************************************************/
49
49
  void pack_deck(uint8_t *output, const secret_key *sk) {
50
50
  for (size_t i = 0; i < SMAUGT_K; ++i)
@@ -59,7 +59,7 @@ void pack_deck(uint8_t *output, const secret_key *sk) {
59
59
  * Arguments: - secret_key *sk: pointer to output private key
60
60
  * - const uint8_t *input: pointer to input byte array
61
61
  *
62
- * Specification: Implements Algorithm 17, UnpackDecK.
62
+ * Specification: Implements @[KS X 123456, Algorithm 17, UnpackDecK]
63
63
  **************************************************/
64
64
  void unpack_deck(secret_key *sk, const uint8_t *input) {
65
65
  for (size_t i = 0; i < SMAUGT_K; ++i)
@@ -74,7 +74,7 @@ void unpack_deck(secret_key *sk, const uint8_t *input) {
74
74
  * Arguments: - uint8_t *bytes: pointer to output bytes
75
75
  * - const poly *s: pointer to input poly in Sn
76
76
  *
77
- * Specification: Implements Algorithm 18, PackSPoly.
77
+ * Specification: Implements @[KS X 123456, Algorithm 18, PackSPoly]
78
78
  **************************************************/
79
79
  void pack_s_poly(uint8_t *bytes, const poly *s) {
80
80
  unsigned int i;
@@ -96,7 +96,7 @@ void pack_s_poly(uint8_t *bytes, const poly *s) {
96
96
  * Arguments: - poly *s: pointer to output poly in Sn
97
97
  * - const uint8_t *bytes: pointer to input bytes
98
98
  *
99
- * Specification: Implements Algorithm 19, UnpackSPoly.
99
+ * Specification: Implements @[KS X 123456, Algorithm 19, UnpackSPoly]
100
100
  **************************************************/
101
101
  void unpack_s_poly(poly *s, const uint8_t *bytes) {
102
102
  unsigned int i;
@@ -123,7 +123,7 @@ void unpack_s_poly(poly *s, const uint8_t *bytes) {
123
123
  * Arguments: - uint8_t *output: pointer to output byte array
124
124
  * - const ciphertext *ctxt: pointer to input ciphertext
125
125
  *
126
- * Specification: Implements Algorithm 20, PackCT.
126
+ * Specification: Implements @[KS X 123456, Algorithm 20, PackCT]
127
127
  * **************************************************/
128
128
  void pack_ct(uint8_t *output, const ciphertext *ctxt) {
129
129
  pack_ring_p_vec(output, &(ctxt->c1));
@@ -138,7 +138,7 @@ void pack_ct(uint8_t *output, const ciphertext *ctxt) {
138
138
  * Arguments: - ciphertext *ctxt: pointer to output ciphertext
139
139
  * - const uint8_t *input: pointer to input byte array
140
140
  *
141
- * Specification: Implements Algorithm 21, UnpackCT.
141
+ * Specification: Implements @[KS X 123456, Algorithm 21, UnpackCT]
142
142
  **************************************************/
143
143
  void unpack_ct(ciphertext *ctxt, const uint8_t *input) {
144
144
  unpack_ring_p_vec(&(ctxt->c1), input);
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kpqc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - osuolfou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-09 00:00:00.000000000 Z
11
+ date: 2026-10-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Synchronous Ruby bindings for the bundled AIMer and HAETAE signature
14
- schemes and NTRU+ and SMAUG-T key-encapsulation mechanisms.
14
+ schemes and NTRU+ and SMAUG-T key encapsulation mechanisms (KEMs).
15
15
  email:
16
16
  - osuolfou@naver.com
17
17
  executables: []
@@ -34,6 +34,7 @@ extensions:
34
34
  - ext/kpqc/timer/extconf.rb
35
35
  extra_rdoc_files: []
36
36
  files:
37
+ - CHANGELOG.md
37
38
  - Gemfile
38
39
  - LICENSE
39
40
  - README.md
@@ -54,6 +55,7 @@ files:
54
55
  - ext/kpqc/ntruplus768/extconf.rb
55
56
  - ext/kpqc/ntruplus864/extconf.rb
56
57
  - ext/kpqc/randombytes.c
58
+ - ext/kpqc/secure_clear.c
57
59
  - ext/kpqc/smaugt128/extconf.rb
58
60
  - ext/kpqc/smaugt192/extconf.rb
59
61
  - ext/kpqc/smaugt256/extconf.rb
@@ -91,9 +93,8 @@ files:
91
93
  - test/kat_test.rb
92
94
  - test/test_helper.rb
93
95
  - vendor/AIMer/LICENSE
94
- - vendor/AIMer/aim2.c
95
- - vendor/AIMer/aim2.h
96
- - vendor/AIMer/aim2_constant.h
96
+ - vendor/AIMer/aim3.c
97
+ - vendor/AIMer/aim3.h
97
98
  - vendor/AIMer/api.h
98
99
  - vendor/AIMer/common/crypto_declassify.h
99
100
  - vendor/AIMer/common/fips202.c
@@ -103,6 +104,8 @@ files:
103
104
  - vendor/AIMer/field128.c
104
105
  - vendor/AIMer/field192.c
105
106
  - vendor/AIMer/field256.c
107
+ - vendor/AIMer/field_common.c
108
+ - vendor/AIMer/field_internal.h
106
109
  - vendor/AIMer/hash.c
107
110
  - vendor/AIMer/hash.h
108
111
  - vendor/AIMer/params.h
@@ -165,6 +168,7 @@ files:
165
168
  - vendor/NTRUplus/NTRU+1152/randombytes.h
166
169
  - vendor/NTRUplus/NTRU+1152/symmetric.c
167
170
  - vendor/NTRUplus/NTRU+1152/symmetric.h
171
+ - vendor/NTRUplus/NTRU+1152/util.h
168
172
  - vendor/NTRUplus/NTRU+768/api.h
169
173
  - vendor/NTRUplus/NTRU+768/fips202/fips202.c
170
174
  - vendor/NTRUplus/NTRU+768/fips202/fips202.h
@@ -177,6 +181,7 @@ files:
177
181
  - vendor/NTRUplus/NTRU+768/randombytes.h
178
182
  - vendor/NTRUplus/NTRU+768/symmetric.c
179
183
  - vendor/NTRUplus/NTRU+768/symmetric.h
184
+ - vendor/NTRUplus/NTRU+768/util.h
180
185
  - vendor/NTRUplus/NTRU+864/api.h
181
186
  - vendor/NTRUplus/NTRU+864/fips202/fips202.c
182
187
  - vendor/NTRUplus/NTRU+864/fips202/fips202.h
@@ -189,6 +194,7 @@ files:
189
194
  - vendor/NTRUplus/NTRU+864/randombytes.h
190
195
  - vendor/NTRUplus/NTRU+864/symmetric.c
191
196
  - vendor/NTRUplus/NTRU+864/symmetric.h
197
+ - vendor/NTRUplus/NTRU+864/util.h
192
198
  - vendor/SMAUG-T/LICENSE
193
199
  - vendor/SMAUG-T/include/api.h
194
200
  - vendor/SMAUG-T/include/cbd.h
@@ -222,13 +228,13 @@ files:
222
228
  - vendor/SMAUG-T/src/poly.c
223
229
  - vendor/SMAUG-T/src/toomcook.c
224
230
  - vendor/SMAUG-T/src/verify.c
225
- - vendor/SOURCES.json
226
- homepage: https://github.com/osuolfou/kpqc-rb
231
+ homepage: https://github.com/KpqC/kpqc-ruby
227
232
  licenses:
228
233
  - MIT
229
234
  metadata:
230
- source_code_uri: https://github.com/osuolfou/kpqc-rb
231
- bug_tracker_uri: https://github.com/osuolfou/kpqc-rb/issues
235
+ source_code_uri: https://github.com/KpqC/kpqc-ruby
236
+ bug_tracker_uri: https://github.com/KpqC/kpqc-ruby/issues
237
+ changelog_uri: https://github.com/KpqC/kpqc-ruby/blob/main/CHANGELOG.md
232
238
  rubygems_mfa_required: 'true'
233
239
  post_install_message:
234
240
  rdoc_options: []
data/vendor/AIMer/aim2.c DELETED
@@ -1,163 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- #include "aim2.h"
4
- #include "field.h"
5
- #include "hash.h"
6
- #include "params.h"
7
- #include <stddef.h>
8
- #include <stdint.h>
9
-
10
- static void generate_matrices_L_and_U(
11
- gf matrix_L[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD],
12
- gf matrix_U[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD],
13
- gf vector_b,
14
- const uint8_t iv[AIM2_IV_SIZE])
15
- {
16
- uint8_t buf[AIM2_NUM_BYTES_FIELD];
17
- uint64_t ormask, lmask, umask;
18
- hash_instance ctx;
19
- gf temp = {0,};
20
-
21
- // initialize hash
22
- hash_init(&ctx);
23
- hash_update(&ctx, iv, AIM2_IV_SIZE);
24
- hash_final(&ctx);
25
-
26
- for (size_t ell = 0; ell < AIM2_NUM_INPUT_SBOX; ell++)
27
- {
28
- for (size_t row = 0; row < AIM2_NUM_BITS_FIELD; row++)
29
- {
30
- hash_squeeze(&ctx, buf, AIM2_NUM_BYTES_FIELD);
31
- gf_from_bytes(temp, buf);
32
-
33
- ormask = ((uint64_t)1) << (row % 64);
34
- lmask = ((uint64_t)-1) << (row % 64);
35
- umask = ~lmask;
36
-
37
- size_t inter = row / 64;
38
- size_t col_word;
39
- for (col_word = 0; col_word < inter; col_word++)
40
- {
41
- // L is zero, U is full
42
- matrix_L[ell][row][col_word] = 0;
43
- matrix_U[ell][row][col_word] = temp[col_word];
44
- }
45
- matrix_L[ell][row][inter] = (temp[inter] & lmask) | ormask;
46
- matrix_U[ell][row][inter] = (temp[inter] & umask) | ormask;
47
- for (col_word = inter + 1; col_word < AIM2_NUM_WORDS_FIELD; col_word++)
48
- {
49
- // L is full, U is zero
50
- matrix_L[ell][row][col_word] = temp[col_word];
51
- matrix_U[ell][row][col_word] = 0;
52
- }
53
- }
54
- }
55
-
56
- hash_squeeze(&ctx, (uint8_t *)vector_b, AIM2_NUM_BYTES_FIELD);
57
- hash_ctx_release(&ctx);
58
- }
59
-
60
- void aim2_generate_linear(gf matrix_A[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD],
61
- gf vector_b,
62
- const uint8_t iv[AIM2_IV_SIZE])
63
- {
64
- gf matrix_L[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD];
65
- gf matrix_U[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD];
66
-
67
- generate_matrices_L_and_U(matrix_L, matrix_U, vector_b, iv);
68
-
69
- for (size_t ell = 0; ell < AIM2_NUM_INPUT_SBOX; ell++)
70
- {
71
- for (size_t i = 0; i < AIM2_NUM_BITS_FIELD; i++)
72
- {
73
- gf_mat_vec_mul(matrix_A[ell][i], matrix_U[ell][i],
74
- (const gf *)matrix_L[ell]);
75
- }
76
- }
77
- }
78
-
79
- void aim2(uint8_t ct[AIM2_NUM_BYTES_FIELD],
80
- const uint8_t pt[AIM2_NUM_BYTES_FIELD],
81
- const uint8_t iv[AIM2_IV_SIZE])
82
- {
83
- gf matrix_L[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD];
84
- gf matrix_U[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD];
85
- gf vector_b = {0,};
86
-
87
- gf state[AIM2_NUM_INPUT_SBOX];
88
- gf pt_gf = {0,}, ct_gf = {0,};
89
- gf_from_bytes(pt_gf, pt);
90
-
91
- // generate random matrix
92
- generate_matrices_L_and_U(matrix_L, matrix_U, vector_b, iv);
93
-
94
- for (size_t i = 0; i < AIMER_L; i++)
95
- {
96
- // linear component: constant addition
97
- gf_add(state[i], pt_gf, aim2_constants[i]);
98
-
99
- // non-linear component: inverse Mersenne S-box
100
- gf_exp(state[i], state[i], aim2_sbox_exponents[i]);
101
-
102
- // linear component: affine layer
103
- gf_mat_vec_mul(state[i], state[i], (const gf *)matrix_U[i]);
104
- gf_mat_vec_mul(state[i], state[i], (const gf *)matrix_L[i]);
105
- }
106
-
107
- for (size_t i = 1; i < AIMER_L; i++)
108
- {
109
- gf_add(state[0], state[0], state[i]);
110
- }
111
- gf_add(state[0], state[0], vector_b);
112
-
113
- // non-linear component: Mersenne S-box
114
- gf_exp(state[0], state[0], aim2_sbox_exponents[AIMER_L]);
115
-
116
- // linear component: feed-forward
117
- gf_add(ct_gf, state[0], pt_gf);
118
-
119
- gf_to_bytes(ct, ct_gf);
120
- }
121
-
122
- void aim2_sbox_outputs(gf sbox_outputs[AIM2_NUM_INPUT_SBOX], const gf pt)
123
- {
124
- for (size_t i = 0; i < AIMER_L; i ++)
125
- {
126
- // linear component: constant addition
127
- gf_add(sbox_outputs[i], pt, aim2_constants[i]);
128
-
129
- // non-linear component: inverse Mersenne S-box
130
- gf_exp(sbox_outputs[i], sbox_outputs[i], aim2_sbox_exponents[i]);
131
- }
132
- }
133
-
134
- void aim2_mpc(mult_chk_t *mult_chk,
135
- const gf matrix_A[AIMER_L][AIM2_NUM_BITS_FIELD],
136
- const gf ct_gf)
137
- {
138
- // pt + c = t ^ {2 ^ e - 1}
139
- // --> t ^ {2 ^ e} + t * c = t * pt
140
- // --> z = x * pt
141
- for (size_t ell = 0; ell < AIMER_L; ell++)
142
- {
143
- gf_sqr(mult_chk->z_shares[ell], mult_chk->x_shares[ell]);
144
- for (size_t i = 1; i < aim2_exponents[ell]; i++)
145
- {
146
- gf_sqr(mult_chk->z_shares[ell], mult_chk->z_shares[ell]);
147
- }
148
- gf_mul_add(mult_chk->z_shares[ell], mult_chk->x_shares[ell],
149
- aim2_constants[ell]);
150
- gf_mat_vec_mul_add(mult_chk->x_shares[AIMER_L],
151
- mult_chk->x_shares[ell], matrix_A[ell]);
152
- }
153
-
154
- // x ^ {2 ^ e - 1} = pt + ct
155
- // --> x ^ {2 ^ e} + x * ct = x * pt
156
- // --> z = x * pt
157
- gf_sqr(mult_chk->z_shares[AIMER_L], mult_chk->x_shares[AIMER_L]);
158
- for (size_t i = 1; i < aim2_exponents[AIMER_L]; i++)
159
- {
160
- gf_sqr(mult_chk->z_shares[AIMER_L], mult_chk->z_shares[AIMER_L]);
161
- }
162
- gf_mul_add(mult_chk->z_shares[AIMER_L], mult_chk->x_shares[AIMER_L], ct_gf);
163
- }
data/vendor/AIMer/aim2.h DELETED
@@ -1,36 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- #ifndef AIM2_H
4
- #define AIM2_H
5
-
6
- #include "aim2_constant.h"
7
- #include "field.h"
8
- #include "params.h"
9
- #include <stdint.h>
10
-
11
- typedef struct mult_chk_t
12
- {
13
- gf pt_share;
14
- gf x_shares[AIMER_L + 1];
15
- gf z_shares[AIMER_L + 1];
16
- } mult_chk_t;
17
-
18
- #define aim2_generate_linear AIMER_NAMESPACE(aim2_generate_linear)
19
- void aim2_generate_linear(gf matrix_A[AIM2_NUM_INPUT_SBOX][AIM2_NUM_BITS_FIELD],
20
- gf vector_b,
21
- const uint8_t iv[AIM2_IV_SIZE]);
22
-
23
- #define aim2_sbox_outputs AIMER_NAMESPACE(aim2_sbox_outputs)
24
- void aim2_sbox_outputs(gf sbox_outputs[AIM2_NUM_INPUT_SBOX], const gf pt);
25
-
26
- #define aim2 AIMER_NAMESPACE(aim2)
27
- void aim2(uint8_t ct[AIM2_NUM_BYTES_FIELD],
28
- const uint8_t pt[AIM2_NUM_BYTES_FIELD],
29
- const uint8_t iv[AIM2_IV_SIZE]);
30
-
31
- #define aim2_mpc AIMER_NAMESPACE(aim2_mpc)
32
- void aim2_mpc(mult_chk_t *mult_chk,
33
- const gf matrix_A[AIMER_L][AIM2_NUM_BITS_FIELD],
34
- const gf ct_gf);
35
-
36
- #endif // AIM2_H
@@ -1,74 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- #ifndef AIM2_CONSTANT_H
4
- #define AIM2_CONSTANT_H
5
-
6
- #include "field.h"
7
- #include "params.h"
8
- #include <stdint.h>
9
-
10
- #if SECURITY_BITS == 128
11
- static const gf aim2_constants[AIM2_NUM_INPUT_SBOX] =
12
- {
13
- {0x13198a2e03707344, 0x243f6a8885a308d3},
14
- {0x082efa98ec4e6c89, 0xa4093822299f31d0},
15
- };
16
-
17
- static const uint64_t
18
- aim2_sbox_exponents[AIM2_NUM_INPUT_SBOX + 1][AIM2_NUM_WORDS_FIELD] =
19
- {
20
- {0x6b6b6d6dadadb5b5, 0xb6b6d6d6dadb5b5b},
21
- {0x6d6db6d6db6b6db5, 0xb6db5b6dadb6dadb},
22
- {7, 0}
23
- };
24
-
25
- static const size_t aim2_exponents[AIM2_NUM_INPUT_SBOX + 1] =
26
- {
27
- 49, 91, 3
28
- };
29
-
30
- #elif SECURITY_BITS == 192
31
- static const gf aim2_constants[AIM2_NUM_INPUT_SBOX] =
32
- {
33
- {0xc0ac29b7c97c50dd, 0xbe5466cf34e90c6c, 0x452821e638d01377},
34
- {0xd1310ba698dfb5ac, 0x9216d5d98979fb1b, 0x3f84d5b5b5470917}
35
- };
36
-
37
- static const uint64_t
38
- aim2_sbox_exponents[AIM2_NUM_INPUT_SBOX + 1][AIM2_NUM_WORDS_FIELD] =
39
- {
40
- {0xd6ad6b56b5ab5ad5, 0x6ad6b56b5ab5ad5a, 0xad6b56b5ab5ad5ad},
41
- {0x7776eeeeeeeeeeed, 0xbbbbbbbb77777777, 0xddddddddddddbbbb},
42
- {31, 0, 0}
43
- };
44
-
45
- static const size_t aim2_exponents[AIM2_NUM_INPUT_SBOX + 1] =
46
- {
47
- 17, 47, 5
48
- };
49
-
50
- #else
51
- static const gf aim2_constants[AIM2_NUM_INPUT_SBOX] =
52
- {
53
- {0x24a19947b3916cf7,0xba7c9045f12c7f99,0xb8e1afed6a267e96,0x2ffd72dbd01adfb7},
54
- {0x0d95748f728eb658,0xa458fea3f4933d7e,0x636920d871574e69,0x0801f2e2858efc16},
55
- {0xc5d1b023286085f0,0x9c30d5392af26013,0x7b54a41dc25a59b5,0x718bcd5882154aee}
56
- };
57
-
58
- static const uint64_t
59
- aim2_sbox_exponents[AIM2_NUM_INPUT_SBOX + 1][AIM2_NUM_WORDS_FIELD] =
60
- {
61
- {0xdadb5b6b6d6dadb5,0x6b6d6dadb5b6b6d6,0xadb5b6b6d6dadb5b,0xb6d6dadb5b6b6d6d},
62
- {0x1112224444889111,0x8891112224444889,0x4448889112222444,0x2224448889112222},
63
- {0xeddbb76eddbb76ed,0x76eddbb76eddbb76,0xbb76eddbb76eddbb,0xddbb76eddbb76edd},
64
- {7, 0, 0, 0}
65
- };
66
-
67
- static const size_t aim2_exponents[AIM2_NUM_INPUT_SBOX + 1] =
68
- {
69
- 11, 141, 7, 3
70
- };
71
-
72
- #endif
73
-
74
- #endif // AIM2_CONSTANT_H