kpqc 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/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +174 -0
- data/Rakefile +57 -0
- data/THIRD_PARTY_NOTICES.md +53 -0
- data/ext/kpqc/aimer128f/extconf.rb +4 -0
- data/ext/kpqc/aimer128s/extconf.rb +4 -0
- data/ext/kpqc/aimer192f/extconf.rb +4 -0
- data/ext/kpqc/aimer192s/extconf.rb +4 -0
- data/ext/kpqc/aimer256f/extconf.rb +4 -0
- data/ext/kpqc/aimer256s/extconf.rb +4 -0
- data/ext/kpqc/extconf_helper.rb +93 -0
- data/ext/kpqc/haetae2/extconf.rb +4 -0
- data/ext/kpqc/haetae3/extconf.rb +4 -0
- data/ext/kpqc/haetae5/extconf.rb +4 -0
- data/ext/kpqc/module.c +195 -0
- data/ext/kpqc/ntruplus1152/extconf.rb +4 -0
- data/ext/kpqc/ntruplus768/extconf.rb +4 -0
- data/ext/kpqc/ntruplus864/extconf.rb +4 -0
- data/ext/kpqc/randombytes.c +107 -0
- data/ext/kpqc/smaugt128/extconf.rb +4 -0
- data/ext/kpqc/smaugt192/extconf.rb +4 -0
- data/ext/kpqc/smaugt256/extconf.rb +4 -0
- data/ext/kpqc/timer/extconf.rb +4 -0
- data/kpqc.gemspec +41 -0
- data/lib/kpqc/aimer.rb +38 -0
- data/lib/kpqc/api.rb +129 -0
- data/lib/kpqc/haetae.rb +25 -0
- data/lib/kpqc/ntruplus.rb +25 -0
- data/lib/kpqc/smaugt.rb +29 -0
- data/lib/kpqc/types.rb +103 -0
- data/lib/kpqc/version.rb +6 -0
- data/lib/kpqc.rb +33 -0
- data/test/algorithm_test.rb +111 -0
- data/test/api_test.rb +52 -0
- data/test/interop.mjs +34 -0
- data/test/interop_test.rb +82 -0
- data/test/kat/aimer128f.rsp +10 -0
- data/test/kat/aimer128s.rsp +10 -0
- data/test/kat/aimer192f.rsp +10 -0
- data/test/kat/aimer192s.rsp +10 -0
- data/test/kat/aimer256f.rsp +10 -0
- data/test/kat/aimer256s.rsp +10 -0
- data/test/kat/haetae2.rsp +10 -0
- data/test/kat/haetae3.rsp +10 -0
- data/test/kat/haetae5.rsp +10 -0
- data/test/kat/ntruplus1152.rsp +8 -0
- data/test/kat/ntruplus768.rsp +8 -0
- data/test/kat/ntruplus864.rsp +8 -0
- data/test/kat/smaugt128.rsp +8 -0
- data/test/kat/smaugt192.rsp +8 -0
- data/test/kat/smaugt256.rsp +8 -0
- data/test/kat/timer.rsp +8 -0
- data/test/kat_drbg.rb +155 -0
- data/test/kat_test.rb +99 -0
- data/test/test_helper.rb +21 -0
- data/vendor/AIMer/LICENSE +21 -0
- data/vendor/AIMer/aim2.c +163 -0
- data/vendor/AIMer/aim2.h +36 -0
- data/vendor/AIMer/aim2_constant.h +74 -0
- data/vendor/AIMer/api.h +42 -0
- data/vendor/AIMer/common/crypto_declassify.h +7 -0
- data/vendor/AIMer/common/fips202.c +878 -0
- data/vendor/AIMer/common/fips202.h +166 -0
- data/vendor/AIMer/common/rng.h +56 -0
- data/vendor/AIMer/field.h +43 -0
- data/vendor/AIMer/field128.c +454 -0
- data/vendor/AIMer/field192.c +485 -0
- data/vendor/AIMer/field256.c +564 -0
- data/vendor/AIMer/hash.c +50 -0
- data/vendor/AIMer/hash.h +37 -0
- data/vendor/AIMer/params/params-aimer-128f.h +34 -0
- data/vendor/AIMer/params/params-aimer-128s.h +34 -0
- data/vendor/AIMer/params/params-aimer-192f.h +34 -0
- data/vendor/AIMer/params/params-aimer-192s.h +34 -0
- data/vendor/AIMer/params/params-aimer-256f.h +34 -0
- data/vendor/AIMer/params/params-aimer-256s.h +34 -0
- data/vendor/AIMer/params.h +5 -0
- data/vendor/AIMer/sign.c +631 -0
- data/vendor/AIMer/sign.h +40 -0
- data/vendor/AIMer/tree.c +75 -0
- data/vendor/AIMer/tree.h +26 -0
- data/vendor/HAETAE/LICENSE +22 -0
- data/vendor/HAETAE/include/api.h +54 -0
- data/vendor/HAETAE/include/common.h +12 -0
- data/vendor/HAETAE/include/config.h +42 -0
- data/vendor/HAETAE/include/decompose.h +19 -0
- data/vendor/HAETAE/include/encoding.h +20 -0
- data/vendor/HAETAE/include/fft.h +26 -0
- data/vendor/HAETAE/include/fips202.h +40 -0
- data/vendor/HAETAE/include/fixpoint.h +125 -0
- data/vendor/HAETAE/include/ntt.h +16 -0
- data/vendor/HAETAE/include/packing.h +58 -0
- data/vendor/HAETAE/include/params.h +117 -0
- data/vendor/HAETAE/include/poly.h +65 -0
- data/vendor/HAETAE/include/polyfix.h +65 -0
- data/vendor/HAETAE/include/polymat.h +32 -0
- data/vendor/HAETAE/include/polyvec.h +131 -0
- data/vendor/HAETAE/include/randombytes.h +39 -0
- data/vendor/HAETAE/include/rans_byte.h +335 -0
- data/vendor/HAETAE/include/reduce.h +31 -0
- data/vendor/HAETAE/include/sampler.h +23 -0
- data/vendor/HAETAE/include/symmetric.h +52 -0
- data/vendor/HAETAE/src/decompose.c +73 -0
- data/vendor/HAETAE/src/encoding.c +700 -0
- data/vendor/HAETAE/src/fft.c +235 -0
- data/vendor/HAETAE/src/fips202.c +745 -0
- data/vendor/HAETAE/src/fixpoint.c +143 -0
- data/vendor/HAETAE/src/ntt.c +98 -0
- data/vendor/HAETAE/src/packing.c +595 -0
- data/vendor/HAETAE/src/poly.c +371 -0
- data/vendor/HAETAE/src/polyfix.c +298 -0
- data/vendor/HAETAE/src/polymat.c +82 -0
- data/vendor/HAETAE/src/polyvec.c +534 -0
- data/vendor/HAETAE/src/reduce.c +96 -0
- data/vendor/HAETAE/src/sampler.c +310 -0
- data/vendor/HAETAE/src/sign.c +558 -0
- data/vendor/HAETAE/src/symmetric-shake.c +50 -0
- data/vendor/NTRUplus/LICENSE +21 -0
- data/vendor/NTRUplus/NTRU+1152/api.h +24 -0
- data/vendor/NTRUplus/NTRU+1152/fips202/fips202.c +878 -0
- data/vendor/NTRUplus/NTRU+1152/fips202/fips202.h +166 -0
- data/vendor/NTRUplus/NTRU+1152/kem.c +286 -0
- data/vendor/NTRUplus/NTRU+1152/ntt.c +394 -0
- data/vendor/NTRUplus/NTRU+1152/ntt.h +16 -0
- data/vendor/NTRUplus/NTRU+1152/params.h +18 -0
- data/vendor/NTRUplus/NTRU+1152/poly.c +318 -0
- data/vendor/NTRUplus/NTRU+1152/poly.h +31 -0
- data/vendor/NTRUplus/NTRU+1152/randombytes.h +9 -0
- data/vendor/NTRUplus/NTRU+1152/symmetric.c +39 -0
- data/vendor/NTRUplus/NTRU+1152/symmetric.h +12 -0
- data/vendor/NTRUplus/NTRU+768/api.h +24 -0
- data/vendor/NTRUplus/NTRU+768/fips202/fips202.c +878 -0
- data/vendor/NTRUplus/NTRU+768/fips202/fips202.h +166 -0
- data/vendor/NTRUplus/NTRU+768/kem.c +286 -0
- data/vendor/NTRUplus/NTRU+768/ntt.c +379 -0
- data/vendor/NTRUplus/NTRU+768/ntt.h +16 -0
- data/vendor/NTRUplus/NTRU+768/params.h +18 -0
- data/vendor/NTRUplus/NTRU+768/poly.c +320 -0
- data/vendor/NTRUplus/NTRU+768/poly.h +31 -0
- data/vendor/NTRUplus/NTRU+768/randombytes.h +9 -0
- data/vendor/NTRUplus/NTRU+768/symmetric.c +39 -0
- data/vendor/NTRUplus/NTRU+768/symmetric.h +12 -0
- data/vendor/NTRUplus/NTRU+864/api.h +24 -0
- data/vendor/NTRUplus/NTRU+864/fips202/fips202.c +878 -0
- data/vendor/NTRUplus/NTRU+864/fips202/fips202.h +166 -0
- data/vendor/NTRUplus/NTRU+864/kem.c +286 -0
- data/vendor/NTRUplus/NTRU+864/ntt.c +383 -0
- data/vendor/NTRUplus/NTRU+864/ntt.h +16 -0
- data/vendor/NTRUplus/NTRU+864/params.h +18 -0
- data/vendor/NTRUplus/NTRU+864/poly.c +314 -0
- data/vendor/NTRUplus/NTRU+864/poly.h +31 -0
- data/vendor/NTRUplus/NTRU+864/randombytes.h +9 -0
- data/vendor/NTRUplus/NTRU+864/symmetric.c +39 -0
- data/vendor/NTRUplus/NTRU+864/symmetric.h +12 -0
- data/vendor/SMAUG-T/LICENSE +22 -0
- data/vendor/SMAUG-T/include/api.h +37 -0
- data/vendor/SMAUG-T/include/cbd.h +15 -0
- data/vendor/SMAUG-T/include/ciphertext.h +45 -0
- data/vendor/SMAUG-T/include/common.h +12 -0
- data/vendor/SMAUG-T/include/config.h +48 -0
- data/vendor/SMAUG-T/include/dg.h +28 -0
- data/vendor/SMAUG-T/include/fips202.h +41 -0
- data/vendor/SMAUG-T/include/hash.h +21 -0
- data/vendor/SMAUG-T/include/hwt.h +28 -0
- data/vendor/SMAUG-T/include/indcpa.h +33 -0
- data/vendor/SMAUG-T/include/key.h +34 -0
- data/vendor/SMAUG-T/include/pack.h +78 -0
- data/vendor/SMAUG-T/include/packring.h +50 -0
- data/vendor/SMAUG-T/include/params.h +84 -0
- data/vendor/SMAUG-T/include/poly.h +41 -0
- data/vendor/SMAUG-T/include/randombytes.h +11 -0
- data/vendor/SMAUG-T/include/toomcook.h +14 -0
- data/vendor/SMAUG-T/include/verify.h +16 -0
- data/vendor/SMAUG-T/src/cbd.c +159 -0
- data/vendor/SMAUG-T/src/ciphertext.c +95 -0
- data/vendor/SMAUG-T/src/dg.c +112 -0
- data/vendor/SMAUG-T/src/fips202.c +745 -0
- data/vendor/SMAUG-T/src/hash.c +15 -0
- data/vendor/SMAUG-T/src/hwt.c +121 -0
- data/vendor/SMAUG-T/src/indcpa.c +187 -0
- data/vendor/SMAUG-T/src/kem.c +194 -0
- data/vendor/SMAUG-T/src/key.c +102 -0
- data/vendor/SMAUG-T/src/pack.c +349 -0
- data/vendor/SMAUG-T/src/packring.c +503 -0
- data/vendor/SMAUG-T/src/poly.c +200 -0
- data/vendor/SMAUG-T/src/toomcook.c +256 -0
- data/vendor/SMAUG-T/src/verify.c +48 -0
- data/vendor/SOURCES.json +130 -0
- metadata +280 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
#include "pack.h"
|
|
4
|
+
#include "packring.h"
|
|
5
|
+
|
|
6
|
+
#include <string.h>
|
|
7
|
+
|
|
8
|
+
/*************************************************
|
|
9
|
+
* Name: pack_enck
|
|
10
|
+
*
|
|
11
|
+
* Description: pack an encryption key to a byte array
|
|
12
|
+
*
|
|
13
|
+
* Arguments: - uint8_t *output: pointer to output byte array
|
|
14
|
+
* - const public_key *pk: pointer to input public key
|
|
15
|
+
*
|
|
16
|
+
* Specification: Implements Algorithm 14, PackEncK.
|
|
17
|
+
**************************************************/
|
|
18
|
+
void pack_enck(uint8_t *output, const public_key *pk) {
|
|
19
|
+
memcpy(output, pk->seed, sizeof(uint8_t) * SMAUGT_PKSEED_BYTES);
|
|
20
|
+
pack_ring_vec(output + SMAUGT_PKSEED_BYTES, &(pk->b));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*************************************************
|
|
24
|
+
* Name: unpack_enck
|
|
25
|
+
*
|
|
26
|
+
* Description: unpack a byte array to an encryption key
|
|
27
|
+
*
|
|
28
|
+
* Arguments: - public_key *pk: pointer to output public key
|
|
29
|
+
* - const uint8_t *input: pointer to input byte array
|
|
30
|
+
*
|
|
31
|
+
* Specification: Implements Algorithm 15, UnpackEncK.
|
|
32
|
+
**************************************************/
|
|
33
|
+
void unpack_enck(public_key *pk, const uint8_t *input) {
|
|
34
|
+
memcpy(pk->seed, input, SMAUGT_PKSEED_BYTES);
|
|
35
|
+
expand_A(pk->A, pk->seed);
|
|
36
|
+
unpack_ring_vec(&(pk->b), input + SMAUGT_PKSEED_BYTES);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*************************************************
|
|
40
|
+
* Name: pack_deck
|
|
41
|
+
*
|
|
42
|
+
* Description: pack a decryption key to a byte array
|
|
43
|
+
*
|
|
44
|
+
* Arguments: - uint8_t *output: pointer to output byte array
|
|
45
|
+
* - const secret_key *sk: pointer to input private key
|
|
46
|
+
*
|
|
47
|
+
* Specification: Implements Algorithm 16, PackDecK.
|
|
48
|
+
**************************************************/
|
|
49
|
+
void pack_deck(uint8_t *output, const secret_key *sk) {
|
|
50
|
+
for (size_t i = 0; i < SMAUGT_K; ++i)
|
|
51
|
+
pack_s_poly(output + SMAUGT_SKPOLY_BYTES * i, &sk->vec[i]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/*************************************************
|
|
55
|
+
* Name: unpack_deck
|
|
56
|
+
*
|
|
57
|
+
* Description: unpack a byte array to a decryption key
|
|
58
|
+
*
|
|
59
|
+
* Arguments: - secret_key *sk: pointer to output private key
|
|
60
|
+
* - const uint8_t *input: pointer to input byte array
|
|
61
|
+
*
|
|
62
|
+
* Specification: Implements Algorithm 17, UnpackDecK.
|
|
63
|
+
**************************************************/
|
|
64
|
+
void unpack_deck(secret_key *sk, const uint8_t *input) {
|
|
65
|
+
for (size_t i = 0; i < SMAUGT_K; ++i)
|
|
66
|
+
unpack_s_poly(&sk->vec[i], input + SMAUGT_SKPOLY_BYTES * i);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*************************************************
|
|
70
|
+
* Name: pack_s_poly
|
|
71
|
+
*
|
|
72
|
+
* Description: Transform to bytes array from a degree of array of secrey poly
|
|
73
|
+
*
|
|
74
|
+
* Arguments: - uint8_t *bytes: pointer to output bytes
|
|
75
|
+
* - const poly *s: pointer to input poly in Sn
|
|
76
|
+
*
|
|
77
|
+
* Specification: Implements Algorithm 18, PackSPoly.
|
|
78
|
+
**************************************************/
|
|
79
|
+
void pack_s_poly(uint8_t *bytes, const poly *s) {
|
|
80
|
+
unsigned int i;
|
|
81
|
+
int d_idx = 0;
|
|
82
|
+
for (i = 0; i < SMAUGT_N / 4; ++i) {
|
|
83
|
+
d_idx = i * 4;
|
|
84
|
+
bytes[i] = ((1 - s->coeffs[d_idx]) & 0x03) |
|
|
85
|
+
(((1 - s->coeffs[d_idx + 1]) & 0x03) << 2) |
|
|
86
|
+
(((1 - s->coeffs[d_idx + 2]) & 0x03) << 4) |
|
|
87
|
+
(((1 - s->coeffs[d_idx + 3]) & 0x03) << 6);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*************************************************
|
|
92
|
+
* Name: unpack_s_poly
|
|
93
|
+
*
|
|
94
|
+
* Description: Transform to a degree of array of secrey poly from bytes array
|
|
95
|
+
*
|
|
96
|
+
* Arguments: - poly *s: pointer to output poly in Sn
|
|
97
|
+
* - const uint8_t *bytes: pointer to input bytes
|
|
98
|
+
*
|
|
99
|
+
* Specification: Implements Algorithm 19, UnpackSPoly.
|
|
100
|
+
**************************************************/
|
|
101
|
+
void unpack_s_poly(poly *s, const uint8_t *bytes) {
|
|
102
|
+
unsigned int i;
|
|
103
|
+
int d_idx = 0;
|
|
104
|
+
for (i = 0; i < SMAUGT_N / 4; ++i) {
|
|
105
|
+
d_idx = i * 4;
|
|
106
|
+
uint8_t t[4] = {0};
|
|
107
|
+
t[0] = (bytes[i] & 0x03);
|
|
108
|
+
t[1] = ((bytes[i] >> 2) & 0x03);
|
|
109
|
+
t[2] = ((bytes[i] >> 4) & 0x03);
|
|
110
|
+
t[3] = ((bytes[i] >> 6) & 0x03);
|
|
111
|
+
s->coeffs[d_idx] = 1 - t[0];
|
|
112
|
+
s->coeffs[d_idx + 1] = 1 - t[1];
|
|
113
|
+
s->coeffs[d_idx + 2] = 1 - t[2];
|
|
114
|
+
s->coeffs[d_idx + 3] = 1 - t[3];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/*************************************************
|
|
119
|
+
* Name: pack_ct
|
|
120
|
+
*
|
|
121
|
+
* Description: pack a ciphertext to a byte array
|
|
122
|
+
*
|
|
123
|
+
* Arguments: - uint8_t *output: pointer to output byte array
|
|
124
|
+
* - const ciphertext *ctxt: pointer to input ciphertext
|
|
125
|
+
*
|
|
126
|
+
* Specification: Implements Algorithm 20, PackCT.
|
|
127
|
+
* **************************************************/
|
|
128
|
+
void pack_ct(uint8_t *output, const ciphertext *ctxt) {
|
|
129
|
+
pack_ring_p_vec(output, &(ctxt->c1));
|
|
130
|
+
pack_ring_p_prime(output + SMAUGT_CTPOLYVEC_BYTES, &(ctxt->c2));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/*************************************************
|
|
134
|
+
* Name: unpack_ct
|
|
135
|
+
*
|
|
136
|
+
* Description: unpack a byte array to a ciphertext
|
|
137
|
+
*
|
|
138
|
+
* Arguments: - ciphertext *ctxt: pointer to output ciphertext
|
|
139
|
+
* - const uint8_t *input: pointer to input byte array
|
|
140
|
+
*
|
|
141
|
+
* Specification: Implements Algorithm 21, UnpackCT.
|
|
142
|
+
**************************************************/
|
|
143
|
+
void unpack_ct(ciphertext *ctxt, const uint8_t *input) {
|
|
144
|
+
unpack_ring_p_vec(&(ctxt->c1), input);
|
|
145
|
+
unpack_ring_p_prime(&(ctxt->c2), input + SMAUGT_CTPOLYVEC_BYTES);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/*************************************************
|
|
149
|
+
* Name: pack_ring
|
|
150
|
+
*
|
|
151
|
+
* Description: Transform to bytes array from polynomial in Rq
|
|
152
|
+
*
|
|
153
|
+
* Arguments: - uint8_t bytes[SMAUGT_PKPOLY_BYTES]: pointer to output bytes
|
|
154
|
+
* - const poly *data: pointer to input polynomial in Rq
|
|
155
|
+
**************************************************/
|
|
156
|
+
void pack_ring(uint8_t bytes[SMAUGT_PKPOLY_BYTES], const poly *data) {
|
|
157
|
+
#if SMAUGT_LOG_Q == 10
|
|
158
|
+
pack_R2_10(bytes, data);
|
|
159
|
+
#elif SMAUGT_LOG_Q == 11
|
|
160
|
+
pack_R2_11(bytes, data);
|
|
161
|
+
#endif
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/*************************************************
|
|
165
|
+
* Name: unpack_ring
|
|
166
|
+
*
|
|
167
|
+
* Description: Transform to polynomial in Rq from bytes array
|
|
168
|
+
*
|
|
169
|
+
* Arguments: - poly *data: pointer to output polynomial in Rq
|
|
170
|
+
* - const uint8_t bytes[SMAUGT_PKPOLY_BYTES]: pointer to input
|
|
171
|
+
* bytes
|
|
172
|
+
**************************************************/
|
|
173
|
+
void unpack_ring(poly *data, const uint8_t bytes[SMAUGT_PKPOLY_BYTES]) {
|
|
174
|
+
#if SMAUGT_LOG_Q == 10
|
|
175
|
+
unpack_R2_10(data, bytes);
|
|
176
|
+
#elif SMAUGT_LOG_Q == 11
|
|
177
|
+
unpack_R2_11(data, bytes);
|
|
178
|
+
#endif
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/*************************************************
|
|
182
|
+
* Name: pack_ring_p
|
|
183
|
+
*
|
|
184
|
+
* Description: Transform to bytes array from polynomial in Rp
|
|
185
|
+
*
|
|
186
|
+
* Arguments: - uint8_t bytes[SMAUGT_CTPOLY1_BYTES]: pointer to output bytes
|
|
187
|
+
* - const poly *data: pointer to input polynomial in Rp
|
|
188
|
+
**************************************************/
|
|
189
|
+
void pack_ring_p(uint8_t bytes[SMAUGT_CTPOLY1_BYTES], const poly *data) {
|
|
190
|
+
#if SMAUGT_LOG_P == 8
|
|
191
|
+
pack_R2_8(bytes, data);
|
|
192
|
+
#elif SMAUGT_LOG_P == 9
|
|
193
|
+
pack_R2_9(bytes, data);
|
|
194
|
+
#endif
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/*************************************************
|
|
198
|
+
* Name: unpack_ring_p
|
|
199
|
+
*
|
|
200
|
+
* Description: Transform to polynomial in Rp from bytes array
|
|
201
|
+
*
|
|
202
|
+
* Arguments: - poly *data: pointer to output polynomial in Rp
|
|
203
|
+
* - const uint8_t bytes[SMAUGT_CTPOLY1_BYTES]: pointer to input
|
|
204
|
+
* bytes
|
|
205
|
+
**************************************************/
|
|
206
|
+
void unpack_ring_p(poly *data, const uint8_t bytes[SMAUGT_CTPOLY1_BYTES]) {
|
|
207
|
+
#if SMAUGT_LOG_P == 8
|
|
208
|
+
unpack_R2_8(data, bytes);
|
|
209
|
+
#elif SMAUGT_LOG_P == 9
|
|
210
|
+
unpack_R2_9(data, bytes);
|
|
211
|
+
#endif
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/*************************************************
|
|
215
|
+
* Name: pack_ring_p_prime
|
|
216
|
+
*
|
|
217
|
+
* Description: Transform to bytes array from polynomial in Rp'
|
|
218
|
+
*
|
|
219
|
+
* Arguments: - uint8_t bytes[SMAUGT_CTPOLY2_BYTES]: pointer to output bytes
|
|
220
|
+
* - const poly *data: pointer to input polynomial in Rp'
|
|
221
|
+
**************************************************/
|
|
222
|
+
void pack_ring_p_prime(uint8_t bytes[SMAUGT_CTPOLY2_BYTES], const poly *data) {
|
|
223
|
+
#if SMAUGT_LOG_P_PRIME == 3
|
|
224
|
+
pack_R2_3(bytes, data);
|
|
225
|
+
#elif SMAUGT_LOG_P_PRIME == 4
|
|
226
|
+
pack_R2_4(bytes, data);
|
|
227
|
+
#elif SMAUGT_LOG_P_PRIME == 5
|
|
228
|
+
pack_R2_5(bytes, data);
|
|
229
|
+
#elif SMAUGT_LOG_P_PRIME == 7
|
|
230
|
+
pack_R2_7(bytes, data);
|
|
231
|
+
#endif
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/*************************************************
|
|
235
|
+
* Name: unpack_ring_p_prime
|
|
236
|
+
*
|
|
237
|
+
* Description: Transform to polynomial in Rp' from bytes array
|
|
238
|
+
*
|
|
239
|
+
* Arguments: - poly *data: pointer to output polynomial in Rp'
|
|
240
|
+
* - const uint8_t bytes[SMAUGT_CTPOLY2_BYTES]: pointer to input
|
|
241
|
+
* bytes
|
|
242
|
+
**************************************************/
|
|
243
|
+
void unpack_ring_p_prime(poly *data,
|
|
244
|
+
const uint8_t bytes[SMAUGT_CTPOLY2_BYTES]) {
|
|
245
|
+
#if SMAUGT_LOG_P_PRIME == 3
|
|
246
|
+
unpack_R2_3(data, bytes);
|
|
247
|
+
#elif SMAUGT_LOG_P_PRIME == 4
|
|
248
|
+
unpack_R2_4(data, bytes);
|
|
249
|
+
#elif SMAUGT_LOG_P_PRIME == 5
|
|
250
|
+
unpack_R2_5(data, bytes);
|
|
251
|
+
#elif SMAUGT_LOG_P_PRIME == 7
|
|
252
|
+
unpack_R2_7(data, bytes);
|
|
253
|
+
#endif
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/*************************************************
|
|
257
|
+
* Name: pack_ring_vec
|
|
258
|
+
*
|
|
259
|
+
* Description: Transform to bytes array from vector of polynomial in Rq
|
|
260
|
+
*
|
|
261
|
+
* Arguments: - uint8_t bytes[SMAUGT_PKPOLYVEC_BYTES]: pointer to output bytes
|
|
262
|
+
* - const polyvec *data: pointer to input vector of polynomial in
|
|
263
|
+
* Rq
|
|
264
|
+
**************************************************/
|
|
265
|
+
void pack_ring_vec(uint8_t bytes[SMAUGT_PKPOLYVEC_BYTES], const polyvec *data) {
|
|
266
|
+
unsigned int i;
|
|
267
|
+
for (i = 0; i < SMAUGT_K; ++i)
|
|
268
|
+
pack_ring(bytes + i * SMAUGT_PKPOLY_BYTES, &(data->vec[i]));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/*************************************************
|
|
272
|
+
* Name: unpack_ring_vec
|
|
273
|
+
*
|
|
274
|
+
* Description: Transform to vector of polynomial in Rq from bytes array
|
|
275
|
+
*
|
|
276
|
+
* Arguments: - polyvec *data: pointer to output a vector of poly in Rq
|
|
277
|
+
* - uint8_t *bytes: pointer to input bytes
|
|
278
|
+
**************************************************/
|
|
279
|
+
void unpack_ring_vec(polyvec *data,
|
|
280
|
+
const uint8_t bytes[SMAUGT_PKPOLYVEC_BYTES]) {
|
|
281
|
+
unsigned int i;
|
|
282
|
+
for (i = 0; i < SMAUGT_K; ++i)
|
|
283
|
+
unpack_ring(&(data->vec[i]), bytes + i * SMAUGT_PKPOLY_BYTES);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/*************************************************
|
|
287
|
+
* Name: pack_ring_p_vec
|
|
288
|
+
*
|
|
289
|
+
* Description: Transform to bytes array from vector of polynomial in Rp
|
|
290
|
+
*
|
|
291
|
+
* Arguments: - uint8_t bytes[SMAUGT_CTPOLYVEC_BYTES]: pointer to output bytes
|
|
292
|
+
* - const polyvec *data: pointer to input vector of polynomial in
|
|
293
|
+
* Rp
|
|
294
|
+
**************************************************/
|
|
295
|
+
void pack_ring_p_vec(uint8_t bytes[SMAUGT_CTPOLYVEC_BYTES],
|
|
296
|
+
const polyvec *data) {
|
|
297
|
+
unsigned int i;
|
|
298
|
+
for (i = 0; i < SMAUGT_K; ++i)
|
|
299
|
+
pack_ring_p(bytes + i * SMAUGT_CTPOLY1_BYTES, &(data->vec[i]));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/*************************************************
|
|
303
|
+
* Name: unpack_ring_p_vec
|
|
304
|
+
*
|
|
305
|
+
* Description: Transform to vector of polynomial in Rp from bytes array
|
|
306
|
+
*
|
|
307
|
+
* Arguments: - polyvec *data: pointer to output a vector of poly in Rp
|
|
308
|
+
* - const uint8_t bytes[SMAUGT_CTPOLYVEC_BYTES]: pointer to input
|
|
309
|
+
* bytes
|
|
310
|
+
**************************************************/
|
|
311
|
+
void unpack_ring_p_vec(polyvec *data,
|
|
312
|
+
const uint8_t bytes[SMAUGT_CTPOLYVEC_BYTES]) {
|
|
313
|
+
unsigned int i;
|
|
314
|
+
for (i = 0; i < SMAUGT_K; ++i)
|
|
315
|
+
unpack_ring_p(&(data->vec[i]), bytes + i * SMAUGT_CTPOLY1_BYTES);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/*************************************************
|
|
319
|
+
* Name: pack_ring_mat
|
|
320
|
+
*
|
|
321
|
+
* Description: Transform to bytes array from matrix of polynomial in Rq
|
|
322
|
+
*
|
|
323
|
+
* Arguments: - uint8_t bytes[SMAUGT_PKPOLYMAT_BYTES]: pointer to output bytes
|
|
324
|
+
* - const polyvec data[SMAUGT_K]: pointer to input matrix of
|
|
325
|
+
* polynomial in Rq
|
|
326
|
+
**************************************************/
|
|
327
|
+
void pack_ring_mat(uint8_t bytes[SMAUGT_PKPOLYMAT_BYTES],
|
|
328
|
+
const polyvec data[SMAUGT_K]) {
|
|
329
|
+
unsigned int i;
|
|
330
|
+
for (i = 0; i < SMAUGT_K; ++i)
|
|
331
|
+
pack_ring_vec(bytes + i * SMAUGT_PKPOLYVEC_BYTES, &(data[i]));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/*************************************************
|
|
335
|
+
* Name: unpack_ring_mat
|
|
336
|
+
*
|
|
337
|
+
* Description: Transform to matrix of polynomial in Rq from bytes array
|
|
338
|
+
*
|
|
339
|
+
* Arguments: - polyvec data[SMAUGT_K]: pointer to output matrix of polynomial
|
|
340
|
+
* in Rq
|
|
341
|
+
* - const uint8_t bytes[SMAUGT_PKPOLYMAT_BYTES]: pointer to input
|
|
342
|
+
* bytes
|
|
343
|
+
**************************************************/
|
|
344
|
+
void unpack_ring_mat(polyvec data[SMAUGT_K],
|
|
345
|
+
const uint8_t bytes[SMAUGT_PKPOLYMAT_BYTES]) {
|
|
346
|
+
unsigned int i;
|
|
347
|
+
for (i = 0; i < SMAUGT_K; ++i)
|
|
348
|
+
unpack_ring_vec(&(data[i]), bytes + i * SMAUGT_PKPOLYVEC_BYTES);
|
|
349
|
+
}
|