-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathdecrypt_c.c
37 lines (31 loc) · 903 Bytes
/
decrypt_c.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
#include <stdio.h>
#include <openssl/bn.h>
void printBN(char *msg, BIGNUM *a)
{
char *number_str_a = BN_bn2hex(a);
printf("%s %s\n", msg, number_str_a);
OPENSSL_free(number_str_a);
}
int main()
{
// init
BN_CTX *ctx = BN_CTX_new();
BIGNUM *n = BN_new();
// BIGNUM *e = BN_new();
BIGNUM *M = BN_new();
BIGNUM *d = BN_new();
BIGNUM *C = BN_new();
// assign values
BN_hex2bn(&n, "DCBFFE3E51F62E09CE7032E2677A78946A849DC4CDDE3A4D0CB81629242FB1A5");
BN_hex2bn(&d, "74D806F9F3A62BAE331FFE3F0A68AFE35B3D2E4794148AACBC26AA381CD7D30D");
BN_hex2bn(&C, "8C0F971DF2F3672B28811407E2DABBE1DA0FEBBBDFC7DCB67396567EA1E2493F");
// decrypt C: C^d mod n
BN_mod_exp(M, C, d, n, ctx);
printBN("Decryption result:", M);
// clear sensitive data
BN_clear_free(n);
BN_clear_free(d);
BN_clear_free(M);
BN_clear_free(C);
return 0;
}