-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
102 lines (71 loc) · 1.84 KB
/
test.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// Created by Ronan on 01/06/2017.
//
#include <stdio.h>
#include "mulprec.h"
#include "utilities.h"
#include "test.h"
// Product-scanning multiplication.
void test_1a(bigint a, bigint b, uint64_t c[MLEN]) {
mul_prodscan(c, a, b);
reduce(c, MLEN);
string_(c, MLEN);
}
void test_1b(bigint a, bigint b, uint64_t c[MLEN]) {
mul_karatsuba(c, a, b);
reduce(c, MLEN);
string_(c, MLEN);
}
void test_1c(bigint a, bigint b, uint64_t c[MLEN]) {
mul_refined_karatsuba(c, a, b);
reduce(c, MLEN);
string_(c, MLEN);
}
// Modular reduction after multiplication.
void test_1d(bigint a, bigint b, uint64_t c[MLEN]) {
mul_prodscan(c, a, b);
mod_reduction(c);
reduce(c, MLEN);
// c - ((a*b) % p)
string_(c, MLEN); printf(" - (("); string_(a, LEN); printf(") * (");
string_(b, LEN); printf(") %% (2 ^ 221 - 3))\n");
}
// Implement a carry routine after modular multiplication:
// multiply, reduce, carry, reduce, reduce
void test1_e(bigint a, bigint b, uint64_t c[MLEN]) {
mul_prodscan(c, a, b);
mod_reduction(c);
carry(c);
mod_reduction(c);
mod_reduction(c);
reduce(c, MLEN);
int i, flag = 1;
for (i = 0; i < MLEN; i++) {
if (bit_degree(c[i]) >= 17) flag = 0;
}
printf("%s\n", flag ? "TRUE" : "FALSE");
}
void runAllTest(){
bigint a, b;
init(a, LEN);
init(b, LEN);
int64_t c[MLEN];
init(c, MLEN);
//We create two big integers
int i;
for (i = 0; i < LEN; ++i) {
a[i] = 14384;
}
a[0] = 2; a[1] = 3; a[2] = 4;
b[0] = 5; b[1] = 8; b[2] = 2;
printf("\n\n\ntest_1a\n");
test_1a(a, b, c);
printf("\n\n\ntest_1b\n");
test_1b(a, b, c);
printf("\n\n\ntest_1c\n");
test_1c(a, b, c);
printf("\n\n\ntest_1d\n");
test_1d(a, b, c);
printf("\n\n\ntest_1e\n");
test1_e(a, b, c);
}