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,235 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
#include "fft.h"
|
|
4
|
+
|
|
5
|
+
/**************************************************************************
|
|
6
|
+
* Roots of unity. This table is used to initialize the FFT data.
|
|
7
|
+
* The even entries are reused as twiddle factors in the FFT.
|
|
8
|
+
* To generate values in Python using numpy:
|
|
9
|
+
* rootsf = np.exp(-1j * np.pi * np.arange(256) / 256)
|
|
10
|
+
* roots = [(int(r.real), int(r.imag)) for r in np.round(65536 * rootsf)]
|
|
11
|
+
**************************************************************************/
|
|
12
|
+
static const complex_fp32_16 roots[] = {
|
|
13
|
+
{.real = +65536, .imag = +0}, {.real = +65531, .imag = -804},
|
|
14
|
+
{.real = +65516, .imag = -1608}, {.real = +65492, .imag = -2412},
|
|
15
|
+
{.real = +65457, .imag = -3216}, {.real = +65413, .imag = -4019},
|
|
16
|
+
{.real = +65358, .imag = -4821}, {.real = +65294, .imag = -5623},
|
|
17
|
+
{.real = +65220, .imag = -6424}, {.real = +65137, .imag = -7224},
|
|
18
|
+
{.real = +65043, .imag = -8022}, {.real = +64940, .imag = -8820},
|
|
19
|
+
{.real = +64827, .imag = -9616}, {.real = +64704, .imag = -10411},
|
|
20
|
+
{.real = +64571, .imag = -11204}, {.real = +64429, .imag = -11996},
|
|
21
|
+
{.real = +64277, .imag = -12785}, {.real = +64115, .imag = -13573},
|
|
22
|
+
{.real = +63944, .imag = -14359}, {.real = +63763, .imag = -15143},
|
|
23
|
+
{.real = +63572, .imag = -15924}, {.real = +63372, .imag = -16703},
|
|
24
|
+
{.real = +63162, .imag = -17479}, {.real = +62943, .imag = -18253},
|
|
25
|
+
{.real = +62714, .imag = -19024}, {.real = +62476, .imag = -19792},
|
|
26
|
+
{.real = +62228, .imag = -20557}, {.real = +61971, .imag = -21320},
|
|
27
|
+
{.real = +61705, .imag = -22078}, {.real = +61429, .imag = -22834},
|
|
28
|
+
{.real = +61145, .imag = -23586}, {.real = +60851, .imag = -24335},
|
|
29
|
+
{.real = +60547, .imag = -25080}, {.real = +60235, .imag = -25821},
|
|
30
|
+
{.real = +59914, .imag = -26558}, {.real = +59583, .imag = -27291},
|
|
31
|
+
{.real = +59244, .imag = -28020}, {.real = +58896, .imag = -28745},
|
|
32
|
+
{.real = +58538, .imag = -29466}, {.real = +58172, .imag = -30182},
|
|
33
|
+
{.real = +57798, .imag = -30893}, {.real = +57414, .imag = -31600},
|
|
34
|
+
{.real = +57022, .imag = -32303}, {.real = +56621, .imag = -33000},
|
|
35
|
+
{.real = +56212, .imag = -33692}, {.real = +55794, .imag = -34380},
|
|
36
|
+
{.real = +55368, .imag = -35062}, {.real = +54934, .imag = -35738},
|
|
37
|
+
{.real = +54491, .imag = -36410}, {.real = +54040, .imag = -37076},
|
|
38
|
+
{.real = +53581, .imag = -37736}, {.real = +53114, .imag = -38391},
|
|
39
|
+
{.real = +52639, .imag = -39040}, {.real = +52156, .imag = -39683},
|
|
40
|
+
{.real = +51665, .imag = -40320}, {.real = +51166, .imag = -40951},
|
|
41
|
+
{.real = +50660, .imag = -41576}, {.real = +50146, .imag = -42194},
|
|
42
|
+
{.real = +49624, .imag = -42806}, {.real = +49095, .imag = -43412},
|
|
43
|
+
{.real = +48559, .imag = -44011}, {.real = +48015, .imag = -44604},
|
|
44
|
+
{.real = +47464, .imag = -45190}, {.real = +46906, .imag = -45769},
|
|
45
|
+
{.real = +46341, .imag = -46341}, {.real = +45769, .imag = -46906},
|
|
46
|
+
{.real = +45190, .imag = -47464}, {.real = +44604, .imag = -48015},
|
|
47
|
+
{.real = +44011, .imag = -48559}, {.real = +43412, .imag = -49095},
|
|
48
|
+
{.real = +42806, .imag = -49624}, {.real = +42194, .imag = -50146},
|
|
49
|
+
{.real = +41576, .imag = -50660}, {.real = +40951, .imag = -51166},
|
|
50
|
+
{.real = +40320, .imag = -51665}, {.real = +39683, .imag = -52156},
|
|
51
|
+
{.real = +39040, .imag = -52639}, {.real = +38391, .imag = -53114},
|
|
52
|
+
{.real = +37736, .imag = -53581}, {.real = +37076, .imag = -54040},
|
|
53
|
+
{.real = +36410, .imag = -54491}, {.real = +35738, .imag = -54934},
|
|
54
|
+
{.real = +35062, .imag = -55368}, {.real = +34380, .imag = -55794},
|
|
55
|
+
{.real = +33692, .imag = -56212}, {.real = +33000, .imag = -56621},
|
|
56
|
+
{.real = +32303, .imag = -57022}, {.real = +31600, .imag = -57414},
|
|
57
|
+
{.real = +30893, .imag = -57798}, {.real = +30182, .imag = -58172},
|
|
58
|
+
{.real = +29466, .imag = -58538}, {.real = +28745, .imag = -58896},
|
|
59
|
+
{.real = +28020, .imag = -59244}, {.real = +27291, .imag = -59583},
|
|
60
|
+
{.real = +26558, .imag = -59914}, {.real = +25821, .imag = -60235},
|
|
61
|
+
{.real = +25080, .imag = -60547}, {.real = +24335, .imag = -60851},
|
|
62
|
+
{.real = +23586, .imag = -61145}, {.real = +22834, .imag = -61429},
|
|
63
|
+
{.real = +22078, .imag = -61705}, {.real = +21320, .imag = -61971},
|
|
64
|
+
{.real = +20557, .imag = -62228}, {.real = +19792, .imag = -62476},
|
|
65
|
+
{.real = +19024, .imag = -62714}, {.real = +18253, .imag = -62943},
|
|
66
|
+
{.real = +17479, .imag = -63162}, {.real = +16703, .imag = -63372},
|
|
67
|
+
{.real = +15924, .imag = -63572}, {.real = +15143, .imag = -63763},
|
|
68
|
+
{.real = +14359, .imag = -63944}, {.real = +13573, .imag = -64115},
|
|
69
|
+
{.real = +12785, .imag = -64277}, {.real = +11996, .imag = -64429},
|
|
70
|
+
{.real = +11204, .imag = -64571}, {.real = +10411, .imag = -64704},
|
|
71
|
+
{.real = +9616, .imag = -64827}, {.real = +8820, .imag = -64940},
|
|
72
|
+
{.real = +8022, .imag = -65043}, {.real = +7224, .imag = -65137},
|
|
73
|
+
{.real = +6424, .imag = -65220}, {.real = +5623, .imag = -65294},
|
|
74
|
+
{.real = +4821, .imag = -65358}, {.real = +4019, .imag = -65413},
|
|
75
|
+
{.real = +3216, .imag = -65457}, {.real = +2412, .imag = -65492},
|
|
76
|
+
{.real = +1608, .imag = -65516}, {.real = +804, .imag = -65531},
|
|
77
|
+
{.real = +0, .imag = -65536}, {.real = -804, .imag = -65531},
|
|
78
|
+
{.real = -1608, .imag = -65516}, {.real = -2412, .imag = -65492},
|
|
79
|
+
{.real = -3216, .imag = -65457}, {.real = -4019, .imag = -65413},
|
|
80
|
+
{.real = -4821, .imag = -65358}, {.real = -5623, .imag = -65294},
|
|
81
|
+
{.real = -6424, .imag = -65220}, {.real = -7224, .imag = -65137},
|
|
82
|
+
{.real = -8022, .imag = -65043}, {.real = -8820, .imag = -64940},
|
|
83
|
+
{.real = -9616, .imag = -64827}, {.real = -10411, .imag = -64704},
|
|
84
|
+
{.real = -11204, .imag = -64571}, {.real = -11996, .imag = -64429},
|
|
85
|
+
{.real = -12785, .imag = -64277}, {.real = -13573, .imag = -64115},
|
|
86
|
+
{.real = -14359, .imag = -63944}, {.real = -15143, .imag = -63763},
|
|
87
|
+
{.real = -15924, .imag = -63572}, {.real = -16703, .imag = -63372},
|
|
88
|
+
{.real = -17479, .imag = -63162}, {.real = -18253, .imag = -62943},
|
|
89
|
+
{.real = -19024, .imag = -62714}, {.real = -19792, .imag = -62476},
|
|
90
|
+
{.real = -20557, .imag = -62228}, {.real = -21320, .imag = -61971},
|
|
91
|
+
{.real = -22078, .imag = -61705}, {.real = -22834, .imag = -61429},
|
|
92
|
+
{.real = -23586, .imag = -61145}, {.real = -24335, .imag = -60851},
|
|
93
|
+
{.real = -25080, .imag = -60547}, {.real = -25821, .imag = -60235},
|
|
94
|
+
{.real = -26558, .imag = -59914}, {.real = -27291, .imag = -59583},
|
|
95
|
+
{.real = -28020, .imag = -59244}, {.real = -28745, .imag = -58896},
|
|
96
|
+
{.real = -29466, .imag = -58538}, {.real = -30182, .imag = -58172},
|
|
97
|
+
{.real = -30893, .imag = -57798}, {.real = -31600, .imag = -57414},
|
|
98
|
+
{.real = -32303, .imag = -57022}, {.real = -33000, .imag = -56621},
|
|
99
|
+
{.real = -33692, .imag = -56212}, {.real = -34380, .imag = -55794},
|
|
100
|
+
{.real = -35062, .imag = -55368}, {.real = -35738, .imag = -54934},
|
|
101
|
+
{.real = -36410, .imag = -54491}, {.real = -37076, .imag = -54040},
|
|
102
|
+
{.real = -37736, .imag = -53581}, {.real = -38391, .imag = -53114},
|
|
103
|
+
{.real = -39040, .imag = -52639}, {.real = -39683, .imag = -52156},
|
|
104
|
+
{.real = -40320, .imag = -51665}, {.real = -40951, .imag = -51166},
|
|
105
|
+
{.real = -41576, .imag = -50660}, {.real = -42194, .imag = -50146},
|
|
106
|
+
{.real = -42806, .imag = -49624}, {.real = -43412, .imag = -49095},
|
|
107
|
+
{.real = -44011, .imag = -48559}, {.real = -44604, .imag = -48015},
|
|
108
|
+
{.real = -45190, .imag = -47464}, {.real = -45769, .imag = -46906},
|
|
109
|
+
{.real = -46341, .imag = -46341}, {.real = -46906, .imag = -45769},
|
|
110
|
+
{.real = -47464, .imag = -45190}, {.real = -48015, .imag = -44604},
|
|
111
|
+
{.real = -48559, .imag = -44011}, {.real = -49095, .imag = -43412},
|
|
112
|
+
{.real = -49624, .imag = -42806}, {.real = -50146, .imag = -42194},
|
|
113
|
+
{.real = -50660, .imag = -41576}, {.real = -51166, .imag = -40951},
|
|
114
|
+
{.real = -51665, .imag = -40320}, {.real = -52156, .imag = -39683},
|
|
115
|
+
{.real = -52639, .imag = -39040}, {.real = -53114, .imag = -38391},
|
|
116
|
+
{.real = -53581, .imag = -37736}, {.real = -54040, .imag = -37076},
|
|
117
|
+
{.real = -54491, .imag = -36410}, {.real = -54934, .imag = -35738},
|
|
118
|
+
{.real = -55368, .imag = -35062}, {.real = -55794, .imag = -34380},
|
|
119
|
+
{.real = -56212, .imag = -33692}, {.real = -56621, .imag = -33000},
|
|
120
|
+
{.real = -57022, .imag = -32303}, {.real = -57414, .imag = -31600},
|
|
121
|
+
{.real = -57798, .imag = -30893}, {.real = -58172, .imag = -30182},
|
|
122
|
+
{.real = -58538, .imag = -29466}, {.real = -58896, .imag = -28745},
|
|
123
|
+
{.real = -59244, .imag = -28020}, {.real = -59583, .imag = -27291},
|
|
124
|
+
{.real = -59914, .imag = -26558}, {.real = -60235, .imag = -25821},
|
|
125
|
+
{.real = -60547, .imag = -25080}, {.real = -60851, .imag = -24335},
|
|
126
|
+
{.real = -61145, .imag = -23586}, {.real = -61429, .imag = -22834},
|
|
127
|
+
{.real = -61705, .imag = -22078}, {.real = -61971, .imag = -21320},
|
|
128
|
+
{.real = -62228, .imag = -20557}, {.real = -62476, .imag = -19792},
|
|
129
|
+
{.real = -62714, .imag = -19024}, {.real = -62943, .imag = -18253},
|
|
130
|
+
{.real = -63162, .imag = -17479}, {.real = -63372, .imag = -16703},
|
|
131
|
+
{.real = -63572, .imag = -15924}, {.real = -63763, .imag = -15143},
|
|
132
|
+
{.real = -63944, .imag = -14359}, {.real = -64115, .imag = -13573},
|
|
133
|
+
{.real = -64277, .imag = -12785}, {.real = -64429, .imag = -11996},
|
|
134
|
+
{.real = -64571, .imag = -11204}, {.real = -64704, .imag = -10411},
|
|
135
|
+
{.real = -64827, .imag = -9616}, {.real = -64940, .imag = -8820},
|
|
136
|
+
{.real = -65043, .imag = -8022}, {.real = -65137, .imag = -7224},
|
|
137
|
+
{.real = -65220, .imag = -6424}, {.real = -65294, .imag = -5623},
|
|
138
|
+
{.real = -65358, .imag = -4821}, {.real = -65413, .imag = -4019},
|
|
139
|
+
{.real = -65457, .imag = -3216}, {.real = -65492, .imag = -2412},
|
|
140
|
+
{.real = -65516, .imag = -1608}, {.real = -65531, .imag = -804}};
|
|
141
|
+
|
|
142
|
+
static inline int32_t _mulrnd16(const int32_t x, const int32_t y) {
|
|
143
|
+
int64_t r = ((int64_t)x * (int64_t)y) + (1 << 15);
|
|
144
|
+
return r >> 16;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static inline int32_t _complex_mul_real(const complex_fp32_16 x,
|
|
148
|
+
const complex_fp32_16 y) {
|
|
149
|
+
return _mulrnd16(x.real, y.real) - _mulrnd16(x.imag, y.imag);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
static inline int32_t _complex_mul_imag(const complex_fp32_16 x,
|
|
153
|
+
const complex_fp32_16 y) {
|
|
154
|
+
return _mulrnd16(x.real, y.imag) + _mulrnd16(x.imag, y.real);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static void _complex_mul(complex_fp32_16 *r, const complex_fp32_16 x,
|
|
158
|
+
const complex_fp32_16 y) {
|
|
159
|
+
r->real = _complex_mul_real(x, y);
|
|
160
|
+
r->imag = _complex_mul_imag(x, y);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/****************************************************************************
|
|
164
|
+
* To generate values in Phython:
|
|
165
|
+
* brv8 = [int(f"{t:08b}"[::-1],2) for t in range(2**8)]
|
|
166
|
+
****************************************************************************/
|
|
167
|
+
const uint16_t brv8[] = {
|
|
168
|
+
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
|
|
169
|
+
8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
|
|
170
|
+
4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
|
|
171
|
+
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
|
|
172
|
+
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
|
|
173
|
+
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
|
|
174
|
+
6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
|
|
175
|
+
14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
|
|
176
|
+
1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
|
|
177
|
+
9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
|
|
178
|
+
5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
|
|
179
|
+
13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
|
|
180
|
+
3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
|
|
181
|
+
11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
|
|
182
|
+
7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
|
|
183
|
+
15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255};
|
|
184
|
+
|
|
185
|
+
/****************************************************************************
|
|
186
|
+
* Initialize the FFT array with coeffs[i] * root[i] and
|
|
187
|
+
* store the values in bit-reversed order.
|
|
188
|
+
****************************************************************************/
|
|
189
|
+
void fft_init_and_bitrev(complex_fp32_16 r[FFT_N], const poly *x) {
|
|
190
|
+
int i, inv_i;
|
|
191
|
+
int c;
|
|
192
|
+
for (i = 0; i < FFT_N; i++) {
|
|
193
|
+
inv_i = brv8[i];
|
|
194
|
+
c = x->coeffs[i];
|
|
195
|
+
r[inv_i].real = c * roots[i].real;
|
|
196
|
+
r[inv_i].imag = c * roots[i].imag;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
int32_t complex_fp_sqabs(complex_fp32_16 x) {
|
|
201
|
+
return _mulrnd16(x.real, x.real) + _mulrnd16(x.imag, x.imag);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/*************************************************
|
|
205
|
+
* Name: fft
|
|
206
|
+
*
|
|
207
|
+
* Description:
|
|
208
|
+
*
|
|
209
|
+
* Arguments: - complex_fp32_16 data[FFT_N]
|
|
210
|
+
*
|
|
211
|
+
* Specification: Implements Algorithm 43, FFT.
|
|
212
|
+
**************************************************/
|
|
213
|
+
void fft(complex_fp32_16 data[FFT_N]) {
|
|
214
|
+
unsigned int r, m, md2, n, k, even, odd, twid;
|
|
215
|
+
complex_fp32_16 u, t;
|
|
216
|
+
|
|
217
|
+
for (r = 1; r <= FFT_LOGN; r++) {
|
|
218
|
+
m = 1 << r;
|
|
219
|
+
md2 = m >> 1;
|
|
220
|
+
for (n = 0; n < FFT_N; n += m) {
|
|
221
|
+
for (k = 0; k < md2; k++) {
|
|
222
|
+
even = n + k;
|
|
223
|
+
odd = even + md2;
|
|
224
|
+
twid = k << (FFT_LOGN - r + 1);
|
|
225
|
+
|
|
226
|
+
u = data[even];
|
|
227
|
+
_complex_mul(&t, roots[twid], data[odd]);
|
|
228
|
+
data[even].real = u.real + t.real;
|
|
229
|
+
data[even].imag = u.imag + t.imag;
|
|
230
|
+
data[odd].real = u.real - t.real;
|
|
231
|
+
data[odd].imag = u.imag - t.imag;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|