integrity-test: check code and ro segments of libnttfft
This commit is contained in:
@@ -48,6 +48,11 @@ if USE_RADIUS
|
|||||||
libs += $(DESTDIR)$(ipseclibdir)/libradius.so
|
libs += $(DESTDIR)$(ipseclibdir)/libradius.so
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if USE_LIBNTTFFT
|
||||||
|
deps += $(top_builddir)/src/libstrongswan/math/libnttfft/libnttfft.la
|
||||||
|
libs += $(DESTDIR)$(ipseclibdir)/libnttfft.so
|
||||||
|
endif
|
||||||
|
|
||||||
if USE_LIBPTTLS
|
if USE_LIBPTTLS
|
||||||
deps += $(top_builddir)/src/libpttls/libpttls.la
|
deps += $(top_builddir)/src/libpttls/libpttls.la
|
||||||
libs += $(DESTDIR)$(ipseclibdir)/libpttls.so
|
libs += $(DESTDIR)$(ipseclibdir)/libpttls.so
|
||||||
|
|||||||
@@ -16,6 +16,14 @@
|
|||||||
#include "ntt_fft.h"
|
#include "ntt_fft.h"
|
||||||
#include "ntt_fft_reduce.h"
|
#include "ntt_fft_reduce.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Described in header.
|
||||||
|
*/
|
||||||
|
void libnttfft_init(void)
|
||||||
|
{
|
||||||
|
/* empty */
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct private_ntt_fft_t private_ntt_fft_t;
|
typedef struct private_ntt_fft_t private_ntt_fft_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +39,7 @@ struct private_ntt_fft_t {
|
|||||||
/**
|
/**
|
||||||
* FFT parameter set used as constants
|
* FFT parameter set used as constants
|
||||||
*/
|
*/
|
||||||
ntt_fft_params_t *p;
|
const ntt_fft_params_t *p;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -181,7 +189,7 @@ METHOD(ntt_fft_t, destroy, void,
|
|||||||
/**
|
/**
|
||||||
* See header.
|
* See header.
|
||||||
*/
|
*/
|
||||||
ntt_fft_t *ntt_fft_create(ntt_fft_params_t *params)
|
ntt_fft_t *ntt_fft_create(const ntt_fft_params_t *params)
|
||||||
{
|
{
|
||||||
private_ntt_fft_t *this;
|
private_ntt_fft_t *this;
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ struct ntt_fft_t {
|
|||||||
*
|
*
|
||||||
* @param params FFT parameters
|
* @param params FFT parameters
|
||||||
*/
|
*/
|
||||||
ntt_fft_t *ntt_fft_create(ntt_fft_params_t *params);
|
ntt_fft_t *ntt_fft_create(const ntt_fft_params_t *params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dummy libnttfft initialization function needed for integrity test
|
||||||
|
*/
|
||||||
|
void libnttfft_init(void);
|
||||||
|
|
||||||
|
|
||||||
#endif /** NTT_FFT_H_ @}*/
|
#endif /** NTT_FFT_H_ @}*/
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
/**
|
/**
|
||||||
* FFT twiddle factors in Montgomery form for q = 12289 and n = 1024
|
* FFT twiddle factors in Montgomery form for q = 12289 and n = 1024
|
||||||
*/
|
*/
|
||||||
static uint16_t wr_12289_1024[] = {
|
static const uint16_t wr_12289_1024[] = {
|
||||||
4075, 3051, 2031, 1207, 9987, 10092, 2948, 9273, 11973, 9094,
|
4075, 3051, 2031, 1207, 9987, 10092, 2948, 9273, 11973, 9094,
|
||||||
3202, 9430, 7377, 5092, 3728, 10626, 4536, 1062, 2882, 6039,
|
3202, 9430, 7377, 5092, 3728, 10626, 4536, 1062, 2882, 6039,
|
||||||
975, 10908, 6065, 2249, 11889, 4978, 10431, 7270, 12138, 4890,
|
975, 10908, 6065, 2249, 11889, 4978, 10431, 7270, 12138, 4890,
|
||||||
@@ -137,7 +137,7 @@ static uint16_t wr_12289_1024[] = {
|
|||||||
/**
|
/**
|
||||||
* FFT phase shift in forward transform for q = 12289 and n = 1024
|
* FFT phase shift in forward transform for q = 12289 and n = 1024
|
||||||
*/
|
*/
|
||||||
static uint16_t wf_12289_1024[] = {
|
static const uint16_t wf_12289_1024[] = {
|
||||||
3186, 10013, 8646, 11366, 5828, 3929, 2925, 8186, 8146, 7866,
|
3186, 10013, 8646, 11366, 5828, 3929, 2925, 8186, 8146, 7866,
|
||||||
5906, 4475, 6747, 10362, 11089, 3889, 2645, 6226, 6715, 10138,
|
5906, 4475, 6747, 10362, 11089, 3889, 2645, 6226, 6715, 10138,
|
||||||
9521, 5202, 11836, 9118, 2381, 4378, 6068, 5609, 2396, 4483,
|
9521, 5202, 11836, 9118, 2381, 4378, 6068, 5609, 2396, 4483,
|
||||||
@@ -256,7 +256,7 @@ static uint16_t wf_12289_1024[] = {
|
|||||||
/**
|
/**
|
||||||
* FFT phase shift and scaling inverse transform for q = 12289 and n = 1024
|
* FFT phase shift and scaling inverse transform for q = 12289 and n = 1024
|
||||||
*/
|
*/
|
||||||
static uint16_t wi_12289_1024[] = {
|
static const uint16_t wi_12289_1024[] = {
|
||||||
12277, 5265, 9530, 3117, 5712, 816, 10650, 3277, 9246, 4832,
|
12277, 5265, 9530, 3117, 5712, 816, 10650, 3277, 9246, 4832,
|
||||||
5957, 851, 10655, 10300, 3227, 461, 3577, 511, 73, 1766,
|
5957, 851, 10655, 10300, 3227, 461, 3577, 511, 73, 1766,
|
||||||
5519, 2544, 2119, 7325, 2802, 5667, 11343, 3376, 5749, 6088,
|
5519, 2544, 2119, 7325, 2802, 5667, 11343, 3376, 5749, 6088,
|
||||||
@@ -375,7 +375,7 @@ static uint16_t wi_12289_1024[] = {
|
|||||||
/**
|
/**
|
||||||
* Bit-reversed indices for n = 1024
|
* Bit-reversed indices for n = 1024
|
||||||
*/
|
*/
|
||||||
static uint16_t rev_1024[] = {
|
static const uint16_t rev_1024[] = {
|
||||||
0, 512, 256, 768, 128, 640, 384, 896, 64, 576,
|
0, 512, 256, 768, 128, 640, 384, 896, 64, 576,
|
||||||
320, 832, 192, 704, 448, 960, 32, 544, 288, 800,
|
320, 832, 192, 704, 448, 960, 32, 544, 288, 800,
|
||||||
160, 672, 416, 928, 96, 608, 352, 864, 224, 736,
|
160, 672, 416, 928, 96, 608, 352, 864, 224, 736,
|
||||||
@@ -491,7 +491,7 @@ static uint16_t rev_1024[] = {
|
|||||||
255, 767, 511, 1023
|
255, 767, 511, 1023
|
||||||
};
|
};
|
||||||
|
|
||||||
ntt_fft_params_t ntt_fft_12289_1024 = {
|
const ntt_fft_params_t ntt_fft_12289_1024 = {
|
||||||
12289, 12287, 18, 3186, (1<<18)-1, 1024, 12277, 10,
|
12289, 12287, 18, 3186, (1<<18)-1, 1024, 12277, 10,
|
||||||
wr_12289_1024, wf_12289_1024, wi_12289_1024, 1, rev_1024
|
wr_12289_1024, wf_12289_1024, wi_12289_1024, 1, rev_1024
|
||||||
};
|
};
|
||||||
@@ -499,7 +499,7 @@ ntt_fft_params_t ntt_fft_12289_1024 = {
|
|||||||
/**
|
/**
|
||||||
* FFT phase shift and scaling inverse transform for q = 12289 and n = 512
|
* FFT phase shift and scaling inverse transform for q = 12289 and n = 512
|
||||||
*/
|
*/
|
||||||
static uint16_t wi_12289_512[] = {
|
static const uint16_t wi_12289_512[] = {
|
||||||
12265, 6771, 11424, 9011, 6203, 11914, 9021, 6454, 7154, 146,
|
12265, 6771, 11424, 9011, 6203, 11914, 9021, 6454, 7154, 146,
|
||||||
11038, 4238, 5604, 10397, 11498, 3495, 7846, 7684, 1160, 4538,
|
11038, 4238, 5604, 10397, 11498, 3495, 7846, 7684, 1160, 4538,
|
||||||
845, 2776, 3317, 5836, 6389, 11667, 6508, 1136, 11309, 12269,
|
845, 2776, 3317, 5836, 6389, 11667, 6508, 1136, 11309, 12269,
|
||||||
@@ -562,7 +562,7 @@ static uint16_t wi_12289_512[] = {
|
|||||||
/**
|
/**
|
||||||
* Bit-reversed indices for n = 512
|
* Bit-reversed indices for n = 512
|
||||||
*/
|
*/
|
||||||
static uint16_t rev_512[] = {
|
static const uint16_t rev_512[] = {
|
||||||
0, 256, 128, 384, 64, 320, 192, 448, 32, 288,
|
0, 256, 128, 384, 64, 320, 192, 448, 32, 288,
|
||||||
160, 416, 96, 352, 224, 480, 16, 272, 144, 400,
|
160, 416, 96, 352, 224, 480, 16, 272, 144, 400,
|
||||||
80, 336, 208, 464, 48, 304, 176, 432, 112, 368,
|
80, 336, 208, 464, 48, 304, 176, 432, 112, 368,
|
||||||
@@ -622,7 +622,7 @@ static uint16_t rev_512[] = {
|
|||||||
255, 511
|
255, 511
|
||||||
};
|
};
|
||||||
|
|
||||||
ntt_fft_params_t ntt_fft_12289_512 = {
|
const ntt_fft_params_t ntt_fft_12289_512 = {
|
||||||
12289, 12287, 18, 3186, (1<<18)-1, 512, 12265, 9,
|
12289, 12287, 18, 3186, (1<<18)-1, 512, 12265, 9,
|
||||||
wr_12289_1024, wf_12289_1024, wi_12289_512, 2, rev_512
|
wr_12289_1024, wf_12289_1024, wi_12289_512, 2, rev_512
|
||||||
};
|
};
|
||||||
@@ -630,23 +630,23 @@ ntt_fft_params_t ntt_fft_12289_512 = {
|
|||||||
/**
|
/**
|
||||||
* FFT twiddle factors in Montgomery form for q = 17 and n = 8
|
* FFT twiddle factors in Montgomery form for q = 17 and n = 8
|
||||||
*/
|
*/
|
||||||
static uint16_t wr_17_8[] = { 15, 16, 8, 4, 2, 1, 9, 13, 15 };
|
static const uint16_t wr_17_8[] = { 15, 16, 8, 4, 2, 1, 9, 13, 15 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT phase shift in forward transform for q = 17 and n = 8
|
* FFT phase shift in forward transform for q = 17 and n = 8
|
||||||
*/
|
*/
|
||||||
static uint16_t wf_17_8[] = { 4, 12, 2, 6, 1, 3, 9, 10 };
|
static const uint16_t wf_17_8[] = { 4, 12, 2, 6, 1, 3, 9, 10 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT phase shift and scaling inverse transform for q = 17 and n = 8
|
* FFT phase shift and scaling inverse transform for q = 17 and n = 8
|
||||||
*/
|
*/
|
||||||
static uint16_t wi_17_8[] = { 15, 5, 13, 10, 9, 3, 1, 6 };
|
static const uint16_t wi_17_8[] = { 15, 5, 13, 10, 9, 3, 1, 6 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bit-reversed indices for n = 8
|
* Bit-reversed indices for n = 8
|
||||||
*/
|
*/
|
||||||
static uint16_t rev_8[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
|
static const uint16_t rev_8[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
|
||||||
|
|
||||||
ntt_fft_params_t ntt_fft_17_8 = {
|
const ntt_fft_params_t ntt_fft_17_8 = {
|
||||||
17, 15, 5, 4, (1<<5)-1, 8, 15, 3, wr_17_8, wf_17_8, wi_17_8, 1, rev_8
|
17, 15, 5, 4, (1<<5)-1, 8, 15, 3, wr_17_8, wf_17_8, wi_17_8, 1, rev_8
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,68 +48,68 @@ struct ntt_fft_params_t {
|
|||||||
/**
|
/**
|
||||||
* Square of Montgomery radix: r^2 mod q
|
* Square of Montgomery radix: r^2 mod q
|
||||||
*/
|
*/
|
||||||
uint32_t r2;
|
const uint32_t r2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Montgomery radix mask: (1<<rlog) - 1
|
* Montgomery radix mask: (1<<rlog) - 1
|
||||||
*/
|
*/
|
||||||
uint32_t rmask;
|
const uint32_t rmask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of the FFT with the condition k * n = q-1
|
* Size of the FFT with the condition k * n = q-1
|
||||||
*/
|
*/
|
||||||
uint16_t n;
|
const uint16_t n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inverse of n mod q used for normalization of the FFT
|
* Inverse of n mod q used for normalization of the FFT
|
||||||
*/
|
*/
|
||||||
uint16_t n_inv;
|
const uint16_t n_inv;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of FFT stages stages = log2(n)
|
* Number of FFT stages stages = log2(n)
|
||||||
*/
|
*/
|
||||||
uint16_t stages;
|
const uint16_t stages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT twiddle factors (n-th roots of unity) in Montgomery form
|
* FFT twiddle factors (n-th roots of unity) in Montgomery form
|
||||||
*/
|
*/
|
||||||
uint16_t *wr;
|
const uint16_t *wr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT phase shift (2n-th roots of unity) in forward transform
|
* FFT phase shift (2n-th roots of unity) in forward transform
|
||||||
*/
|
*/
|
||||||
uint16_t *wf;
|
const uint16_t *wf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT phase shift (2n-th roots of unity) and scaling in inverse transform
|
* FFT phase shift (2n-th roots of unity) and scaling in inverse transform
|
||||||
*/
|
*/
|
||||||
uint16_t *wi;
|
const uint16_t *wi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subsampling of FFT twiddle factors table
|
* Subsampling of FFT twiddle factors table
|
||||||
*/
|
*/
|
||||||
uint16_t s;
|
const uint16_t s;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT bit reversal
|
* FFT bit reversal
|
||||||
*/
|
*/
|
||||||
uint16_t *rev;
|
const uint16_t *rev;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT parameters for q = 12289 and n = 1024
|
* FFT parameters for q = 12289 and n = 1024
|
||||||
*/
|
*/
|
||||||
extern ntt_fft_params_t ntt_fft_12289_1024;
|
extern const ntt_fft_params_t ntt_fft_12289_1024;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT parameters for q = 12289 and n = 512
|
* FFT parameters for q = 12289 and n = 512
|
||||||
*/
|
*/
|
||||||
extern ntt_fft_params_t ntt_fft_12289_512;
|
extern const ntt_fft_params_t ntt_fft_12289_512;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FFT parameters for q = 17 and n = 8
|
* FFT parameters for q = 17 and n = 8
|
||||||
*/
|
*/
|
||||||
extern ntt_fft_params_t ntt_fft_17_8;
|
extern const ntt_fft_params_t ntt_fft_17_8;
|
||||||
|
|
||||||
#endif /** NTT_FFT_PARAMS_H_ @}*/
|
#endif /** NTT_FFT_PARAMS_H_ @}*/
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
* Montgomery, P. L. Modular multiplication without trial division.
|
* Montgomery, P. L. Modular multiplication without trial division.
|
||||||
* Mathematics of Computation 44, 170 (1985), 519–521.
|
* Mathematics of Computation 44, 170 (1985), 519–521.
|
||||||
*/
|
*/
|
||||||
static inline uint32_t ntt_fft_mreduce(uint32_t x, ntt_fft_params_t *p)
|
static inline uint32_t ntt_fft_mreduce(uint32_t x, const ntt_fft_params_t *p)
|
||||||
{
|
{
|
||||||
uint32_t m, t;
|
uint32_t m, t;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
static ntt_fft_params_t *fft_params[] = {
|
static const ntt_fft_params_t *fft_params[] = {
|
||||||
&ntt_fft_17_8,
|
&ntt_fft_17_8,
|
||||||
&ntt_fft_12289_512,
|
&ntt_fft_12289_512,
|
||||||
&ntt_fft_12289_1024
|
&ntt_fft_12289_1024
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ struct bliss_param_set_t {
|
|||||||
/**
|
/**
|
||||||
* FFT parameters
|
* FFT parameters
|
||||||
*/
|
*/
|
||||||
ntt_fft_params_t *fft_params;
|
const ntt_fft_params_t *fft_params;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of [-1, +1] secret key coefficients
|
* Number of [-1, +1] secret key coefficients
|
||||||
|
|||||||
Reference in New Issue
Block a user