-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_gfc.c
73 lines (58 loc) · 1.95 KB
/
main_gfc.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
#include <stdlib.h>
#include <stdio.h>
#include "gf_complete.h"
const unsigned long MAX_ROUNDS = 100000000;
int main() {
unsigned int randreg;
//FILE* urand = fopen("/dev/urandom", "r");
//fread( &randreg, sizeof(randreg), 1, urand );
//fclose(urand);
randreg = 0x1650338b;
printf( "randreg = %#.8x\n", randreg );
gf_t gf;
gf_init_easy(&gf, 64);
unsigned long i;
for( i = 0; i < MAX_ROUNDS; i++ ) {
uint64_t x, y, z;
x = (uint64_t) rand_r( &randreg );
x <<= 32;
x |= (uint64_t) rand_r( &randreg );
/* y = (uint64_t) rand_r( &randreg ); */
/* y <<= 32; */
/* y |= (uint64_t) rand_r( &randreg ); */
/* z = (uint64_t) rand_r( &randreg ); */
/* z <<= 32; */
/* z |= (uint64_t) rand_r( &randreg ); */
/* // Distrbutivity test */
/* if( gf.multiply.w64( &gf, x, y ^ z ) == */
/* gf.multiply.w64( &gf, x, y ) ^ gf.multiply.w64( &gf, x, z ) ) { */
/* } else { */
/* printf( "Distributivity fail:\n" ); */
/* printf( " x = 0x%.16lx\n", x ); */
/* printf( " y = 0x%.16lx\n", y ); */
/* printf( " z = 0x%.16lx\n", z ); */
/* } */
/* // Associativity test */
/* if( gf.multiply.w64( &gf, x, gf.multiply.w64( &gf, y, z ) ) == */
/* gf.multiply.w64( &gf, gf.multiply.w64( &gf, x, y ), z ) ) { */
/* } else { */
/* printf( "Associativity fail:\n" ); */
/* printf( " x = 0x%.16lx\n", x ); */
/* printf( " y = 0x%.16lx\n", y ); */
/* printf( " z = 0x%.16lx\n", z ); */
/* } */
/* // inverse test */
/* if( x == 0 || gf.inverse.w64( &gf, x ) != 0) { */
/* } else { */
/* printf( "Inversion fail:\n" ); */
/* printf( " x = 0x%.16lx\n", x ); */
/* } */
// inverse test
if( x == 0 || (gf.multiply.w64( &gf, x, gf.inverse.w64( &gf, x ) ) == 1) ) {
} else {
printf( "Inversion fail:\n" );
printf( " x = 0x%.16llx\n", x );
}
}
printf( "%lu Tests completed\n", MAX_ROUNDS );
}