| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "atheme.h" |
| 22 |
#include "libathemecore.h" |
| 23 |
|
| 24 |
#if defined HAVE_OPENSSL && defined HAVE_OPENSSL_EC_H |
| 25 |
|
| 26 |
#include <openssl/ec.h> |
| 27 |
#include <openssl/ecdsa.h> |
| 28 |
#include <openssl/evp.h> |
| 29 |
#include <openssl/rand.h> |
| 30 |
#include <openssl/sha.h> |
| 31 |
|
| 32 |
int main(int argc, const char **argv) |
| 33 |
{ |
| 34 |
BIO *out; |
| 35 |
EC_KEY *prv; |
| 36 |
unsigned char *workbuf, *workbuf_p; |
| 37 |
char encbuf[BUFSIZE]; |
| 38 |
size_t len; |
| 39 |
|
| 40 |
memset(encbuf, '\0', sizeof encbuf); |
| 41 |
|
| 42 |
prv = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
| 43 |
|
| 44 |
EC_KEY_set_conv_form(prv, POINT_CONVERSION_COMPRESSED); |
| 45 |
EC_KEY_generate_key(prv); |
| 46 |
|
| 47 |
len = i2o_ECPublicKey(prv, NULL); |
| 48 |
workbuf = mowgli_alloc(len); |
| 49 |
workbuf_p = workbuf; |
| 50 |
i2o_ECPublicKey(prv, &workbuf_p); |
| 51 |
workbuf_p = workbuf; |
| 52 |
base64_encode((const char *)workbuf_p, len, encbuf, BUFSIZE); |
| 53 |
|
| 54 |
printf("Keypair:\n"); |
| 55 |
EC_KEY_print_fp(stdout, prv, 4); |
| 56 |
|
| 57 |
printf("Private key:\n"); |
| 58 |
out = BIO_new_fp(stdout, 0); |
| 59 |
PEM_write_bio_ECPrivateKey(out, prv, NULL, NULL, 0, NULL, NULL); |
| 60 |
|
| 61 |
printf("Public key (atheme format):\n"); |
| 62 |
printf("%s\n", encbuf); |
| 63 |
|
| 64 |
return EXIT_SUCCESS; |
| 65 |
} |
| 66 |
|
| 67 |
#else |
| 68 |
|
| 69 |
int main(int argc, const char **argv) |
| 70 |
{ |
| 71 |
printf("I'm sorry, you didn't compile Atheme with OpenSSL support.\n"); |
| 72 |
return EXIT_SUCCESS; |
| 73 |
} |
| 74 |
|
| 75 |
#endif |