2016-07-22 09:36:59 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2016 Andreas Steffen
|
|
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
|
* for more details.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2016-07-24 17:57:54 +00:00
|
|
|
|
* @defgroup ntt_fft ntt_fft
|
|
|
|
|
* @{ @ingroup ntt_p
|
2016-07-22 09:36:59 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2016-07-24 17:57:54 +00:00
|
|
|
|
#ifndef NTT_REDUCE_H_
|
|
|
|
|
#define NTT_REDUCE_H_
|
2016-07-22 09:36:59 +00:00
|
|
|
|
|
2016-07-24 17:57:54 +00:00
|
|
|
|
#include "ntt_fft_params.h"
|
2016-07-22 09:36:59 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Montgomery Reduction
|
|
|
|
|
*
|
|
|
|
|
* Montgomery, P. L. Modular multiplication without trial division.
|
|
|
|
|
* Mathematics of Computation 44, 170 (1985), 519–521.
|
|
|
|
|
*/
|
2016-07-25 10:17:49 +00:00
|
|
|
|
static inline uint32_t ntt_fft_mreduce(uint32_t x, const ntt_fft_params_t *p)
|
2016-07-22 09:36:59 +00:00
|
|
|
|
{
|
|
|
|
|
uint32_t m, t;
|
2019-07-09 15:03:23 +00:00
|
|
|
|
|
2016-07-22 09:36:59 +00:00
|
|
|
|
m = (x * p->q_inv) & p->rmask;
|
|
|
|
|
t = (x + m * p->q) >> p->rlog;
|
|
|
|
|
|
|
|
|
|
return (t < p->q) ? t : t - p->q;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-24 17:57:54 +00:00
|
|
|
|
#endif /** NTT_REDUCE_H_ @}*/
|