-
Notifications
You must be signed in to change notification settings - Fork 76
/
reduce.h
41 lines (27 loc) · 916 Bytes
/
reduce.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef HAETAE_REDUCE_H
#define HAETAE_REDUCE_H
#include "params.h"
#include <stdint.h>
#define MONT 14321 // 2^32 % Q
#define MONTSQ 4214 // 2^64 % Q
#define QINV 940508161 // q^(-1) mod 2^32
#define QREC 66575 // 2^32 / Q for Barrett
#define DQREC 33287 // 2^32 / DQ for Barrett
#define montgomery_reduce HAETAE_NAMESPACE(montgomery_reduce)
int32_t montgomery_reduce(int64_t a);
#define _montgomery_reduce HAETAE_NAMESPACE(_montgomery_reduce)
inline int32_t _montgomery_reduce(int64_t a) {
int32_t t;
t = (int64_t)(int32_t)a * QINV;
t = (a - (int64_t)t * Q) >> 32;
return t;
}
#define caddq HAETAE_NAMESPACE(caddq)
int32_t caddq(int32_t a);
#define freeze HAETAE_NAMESPACE(freeze)
int32_t freeze(int32_t a);
#define reduce32_2q HAETAE_NAMESPACE(reduce32_2q)
int32_t reduce32_2q(int32_t a);
#define freeze2q HAETAE_NAMESPACE(freeze2q)
int32_t freeze2q(int32_t a);
#endif