-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoperations.c
100 lines (93 loc) · 2.04 KB
/
operations.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
#include <stdlib.h>
#include "../include/operations.h"
/*
* Process a 32bits addition
*/
value** bool_add_32(cnf* cnf, value** a, value** b) {
int i;
value * r, * temp;
value** res = malloc(sizeof(value*) * 32);
res[31] = xor(cnf, a[31], b[31]);
r = and(cnf, a[31], b[31]);
for (i = 30; i >= 0; i--) {
res[i] = xor_3(cnf, r, a[i], b[i]);
temp = r;
if (i != 0) {
r = maj(cnf, a[i], b[i], r);
}
free_value(temp);
}
return res;
}
/*
* Process a S0 word function
*/
value** bool_s_0(cnf* cnf, value** x) {
int i = 0;
value** res = malloc(sizeof(value*) * 32);
for (; i < 3; i++) {
res[i] = xor(cnf, x[(i-7)&31], x[(i-18)&31]);
}
for (; i < 32; i++) {
res[i] = xor_3(cnf, x[(i-7)&31], x[(i-18)&31], x[i-3]);
}
return res;
}
/*
* Process a S1 word function
*/
value** bool_s_1(cnf* cnf, value** x) {
int i = 0;
value** res = malloc(sizeof(value*) * 32);
for (; i < 10; i++) {
res[i] = xor(cnf, x[(i-17)&31], x[(i-19)&31]);
}
for (; i < 32; i++) {
res[i] = xor_3(cnf, x[(i-17)&31], x[(i-19)&31], x[i-10]);
}
return res;
}
/*
* Process a E0 word function
*/
value** bool_e_0(cnf* cnf, value** x) {
int i = 0;
value** res = malloc(sizeof(value*) * 32);
for (; i < 32; i++) {
res[i] = xor_3(cnf, x[(i-2)&31], x[(i-13)&31], x[(i-22)&31]);
}
return res;
}
/*
* Process a E1 word function
*/
value** bool_e_1(cnf* cnf, value** x) {
int i = 0;
value** res = malloc(sizeof(value*) * 32);
for (; i < 32; i++) {
res[i] = xor_3(cnf, x[(i-6)&31], x[(i-11)&31], x[(i-25)&31]);
}
return res;
}
/*
* Process a Ch word function
*/
value** bool_ch(cnf* cnf, value** x, value** y, value** z) {
int i = 0;
value** res = malloc(sizeof(value*) * 32);
for (; i < 32; i++) {
res[i] = ch(cnf, x[i], y[i], z[i]);
}
return res;
}
/*
* Process a Maj word function
*/
value** bool_maj(cnf* cnf, value** x, value** y, value** z) {
int i = 0;
value** res = malloc(sizeof(value*) * 32);
for (; i < 32; i++) {
res[i] = maj(cnf, x[i], y[i], z[i]);
}
return res;
}