forked from BUSEC/TumbleBit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalice_client_test.cpp
41 lines (29 loc) · 1.02 KB
/
alice_client_test.cpp
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
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE alice_client
#include <boost/test/unit_test.hpp>
#include "alice_client.h"
BOOST_AUTO_TEST_CASE(client){
bool status;
// Setup RSA
RSA * rsa = get_public_rsa(2048, (char *)"tumbler");
BOOST_REQUIRE_MESSAGE(rsa != NULL, "test_alice_client: Failed load RSA key");
int rsa_len = RSA_size(rsa);
Bin* y_sk = new Bin();
// Create epsilon
Bin* epsilon = new Bin();
Bin *y = new Bin(rsa_len);
epsilon->len = rsa_len;
epsilon->data = get_random(rsa_len * 8, rsa->n);
// Encrypt epsilon
int s = RSA_public_encrypt(rsa_len, epsilon->data, y->data, rsa, RSA_NO_PADDING);
BOOST_REQUIRE_MESSAGE(s != -1, "test_alice_client: Failed to create e^pk");
status = get_decryption(y, y_sk);
BOOST_REQUIRE_MESSAGE(status == true, "test_alice_client: Failed to get decryption");
BOOST_REQUIRE_MESSAGE(*y_sk == *epsilon, "test_alice_client: Decryption is invalid!");
printf("Success!\n");
// Cleanup
delete y;
delete y_sk;
delete epsilon;
RSA_free(rsa);
}