poulpy/spqlios/lib/test/testlib/mod_q120.h
spqlios/lib/test/testlib/mod_q120.hRaw
1#ifndef SPQLIOS_MOD_Q120_H
2#define SPQLIOS_MOD_Q120_H
3
4#include <cstdint>
5
6#include "../../spqlios/q120/q120_common.h"
7#include "test_commons.h"
8
9/** @brief centered modulo q */
10int64_t centermod(int64_t v, int64_t q);
11int64_t centermod(uint64_t v, int64_t q);
12
13/** @brief this class represents an integer mod Q120 */
14class mod_q120 {
15 public:
16 static constexpr int64_t Qi[] = {Q1, Q2, Q3, Q4};
17 int64_t a[4];
18 mod_q120(int64_t a1, int64_t a2, int64_t a3, int64_t a4);
19 mod_q120();
20 __int128_t to_int128() const;
21 static mod_q120 from_q120a(const void* addr);
22 static mod_q120 from_q120b(const void* addr);
23 static mod_q120 from_q120c(const void* addr);
24 void save_as_q120a(void* dest) const;
25 void save_as_q120b(void* dest) const;
26 void save_as_q120c(void* dest) const;
27};
28
29mod_q120 operator+(const mod_q120& x, const mod_q120& y);
30mod_q120 operator-(const mod_q120& x, const mod_q120& y);
31mod_q120 operator*(const mod_q120& x, const mod_q120& y);
32mod_q120& operator+=(mod_q120& x, const mod_q120& y);
33mod_q120& operator-=(mod_q120& x, const mod_q120& y);
34mod_q120& operator*=(mod_q120& x, const mod_q120& y);
35std::ostream& operator<<(std::ostream& out, const mod_q120& x);
36bool operator==(const mod_q120& x, const mod_q120& y);
37mod_q120 pow(const mod_q120& x, int32_t k);
38mod_q120 half(const mod_q120& x);
39
40/** @brief a uniformly drawn number mod Q120 */
41mod_q120 uniform_q120();
42/** @brief a uniformly random mod Q120 layout A (4 integers < 2^32) */
43void uniform_q120a(void* dest);
44/** @brief a uniformly random mod Q120 layout B (4 integers < 2^64) */
45void uniform_q120b(void* dest);
46/** @brief a uniformly random mod Q120 layout C (4 integers repr. x,2^32x) */
47void uniform_q120c(void* dest);
48
49#endif // SPQLIOS_MOD_Q120_H