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
102
103
104
105
|
#include "system.h"
#include "beecrypt.h"
#include "mp.h"
#include "debug.h"
#define INIT 0xdeadbeefU;
static const mpw Z[4] = { 0U, 0U, 0U, 0U };
static const mpw F[4] = { ~((mpw) 0U), ~((mpw) 0U), ~((mpw) 0U), ~((mpw) 0U)};
static const mpw P[8] = { ~((mpw) 0U), ~((mpw) 0U), ~((mpw) 0U), ~((mpw) 0U) - 1U, 0U, 0U, 0U, 1U };
int main()
{
int i, carry;
mpw x[4];
mpw r[8];
for (i = 0; i < 4; i++)
x[i] = INIT;
mpcopy(4, x, Z);
for (i = 0; i < 4; i++)
{
if (x[i] != 0)
{
printf("mpcopy failed\n");
return 1;
}
}
if (!mpeq(4, x, Z))
{
printf("mpeq failed\n");
return 1;
}
if (mpne(4, x, Z))
{
printf("mpne failed\n");
return 1;
}
mpcopy(4, x, F);
for (i = 0; i < 4; i++)
{
if (x[i] != ~((mpw) 0))
{
printf("mpcopy failed\n");
return 1;
}
}
if (!mpz(4, Z) || mpz(4, F))
{
printf("mpz failed\n");
return 1;
}
if (mpnz(4, Z) || !mpnz(4, F))
{
printf("mpnz failed\n");
return 1;
}
if (!mpeq(4, x, F))
{
printf("mpeq failed\n");
return 1;
}
if (mpne(4, x, F))
{
printf("mpne failed\n");
return 1;
}
mpcopy(4, x, F);
carry = mpaddw(4, x, (mpw) 1U);
if (!carry || mpne(4, x, Z))
{
printf("mpaddw failed");
return 1;
}
carry = mpsubw(4, x, (mpw) 1U);
if (!carry || mpne(4, x, F))
{
printf("mpsubw failed");
return 1;
}
mpzero(8, r);
mpmul(r, 4, F, 4, F);
if (!mpeq(8, r, P))
{
printf("mpmul failed\n");
return 1;
}
mpzero(8, r);
mpsqr(r, 4, F);
if (!mpeq(8, r, P))
{
printf("mpsqr failed\n");
return 1;
}
return 0;
}
|