-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (44 loc) · 1.25 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <openssl/bn.h>
#include <openssl/dh.h>
#include <openssl/pem.h>
int main(int argc, char** argv) {
if (argc < 3) {
std::cerr << "DH.P must be the first parameter" << std::endl;
std::cerr << "DH.G must be the second parameter" << std::endl;
return 1;
}
std::string dhp = std::string(argv[1]);
std::string dhg = std::string(argv[2]);
std::cerr << "[>] Got DH.P " << dhp << std::endl;
std::cerr << "[>] Got DH.G " << dhg << std::endl;
BIGNUM *p = BN_new();
int err = BN_dec2bn(&p, dhp.c_str());
if (err == 0) {
BN_free(p);
std::cerr << "[E] BN_dec2bn returned error (p)" << std::endl;
return 1;
}
BIGNUM *g = BN_new();
err = BN_dec2bn(&g, dhg.c_str());
if (err == 0) {
BN_free(p);
BN_free(g);
std::cerr << "[E] BN_dec2bn returned error (g)" << std::endl;
return 1;
}
DH *dh = DH_new();
dh->p = p;
dh->g = g;
BIO* out = BIO_new_fp(stdout, BIO_NOCLOSE);
if (out == NULL) {
DH_free(dh);
std::cerr << "[E] Can't open stdout" << std::endl;
return 1;
}
PEM_write_bio_DHparams(out, dh);
BIO_flush(out);
BIO_free(out);
DH_free(dh);
return 0;
}