-
Notifications
You must be signed in to change notification settings - Fork 17
/
rlwe_main.c
69 lines (56 loc) · 1.48 KB
/
rlwe_main.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
/* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* See LICENSE for complete information.
*/
#include <stdio.h>
#include "rlwe_kex.h"
#include "fft.h"
#include "rlwe_a.h"
#include "rlwe_rand.h"
#define CHECK_OK(op, val) \
{ \
int tmp_ret; \
tmp_ret = (op); \
if (tmp_ret != (val)) { \
fprintf(stderr, "Error (return code %d) at %s:%d\n", tmp_ret, __FILE__, __LINE__); \
return -1; \
} \
}
int main() {
uint32_t *a = rlwe_a;
uint32_t s_alice[1024];
uint32_t b_alice[1024];
uint32_t s_bob[1024];
uint32_t b_bob[1024];
uint64_t c[16];
uint64_t k_alice[16];
uint64_t k_bob[16];
FFT_CTX ctx;
if (!FFT_CTX_init(&ctx)) {
printf("Memory allocation error.");
return -1;
}
CHECK_OK(rlwe_kex_generate_keypair(a, s_alice, b_alice, &ctx), 1)
CHECK_OK(rlwe_kex_generate_keypair(a, s_bob, b_bob, &ctx), 1)
CHECK_OK(rlwe_kex_compute_key_bob(b_alice, s_bob, c, k_bob, &ctx), 1)
CHECK_OK(rlwe_kex_compute_key_alice(b_bob, s_alice, c, k_alice, &ctx), 1)
int keys_match = 1;
for (int i = 0; i < 16; i++) {
keys_match &= (k_alice[i] == k_bob[i]);
}
if (keys_match) {
printf("Keys match.\n");
} else {
printf("Keys don't match! :(\n");
FFT_CTX_free(&ctx);
return -1;
}
FFT_CTX_clear(&ctx);
FFT_CTX_free(&ctx);
return 0;
}