| 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 |
EC_KEY *pub; |
| 35 |
char workbuf[BUFSIZE]; |
| 36 |
const unsigned char *workbuf_p; |
| 37 |
size_t len, i; |
| 38 |
|
| 39 |
if (argv[1] == NULL) |
| 40 |
{ |
| 41 |
fprintf(stderr, "usage: %s [base64key]\n", argv[0]); |
| 42 |
return EXIT_FAILURE; |
| 43 |
} |
| 44 |
|
| 45 |
memset(workbuf, '\0', sizeof workbuf); |
| 46 |
|
| 47 |
pub = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); |
| 48 |
EC_KEY_set_conv_form(pub, POINT_CONVERSION_COMPRESSED); |
| 49 |
|
| 50 |
len = base64_decode(argv[1], workbuf, BUFSIZE); |
| 51 |
workbuf_p = (unsigned char *) workbuf; |
| 52 |
|
| 53 |
o2i_ECPublicKey(&pub, &workbuf_p, len); |
| 54 |
if (!EC_KEY_check_key(pub)) |
| 55 |
{ |
| 56 |
fprintf(stderr, "Key data provided on commandline is inconsistent.\n"); |
| 57 |
return EXIT_FAILURE; |
| 58 |
} |
| 59 |
|
| 60 |
printf("Public key (reassembled):\n"); |
| 61 |
EC_KEY_print_fp(stdout, pub, 4); |
| 62 |
|
| 63 |
return EXIT_SUCCESS; |
| 64 |
} |
| 65 |
|
| 66 |
#else |
| 67 |
|
| 68 |
int main(int argc, const char **argv) |
| 69 |
{ |
| 70 |
printf("I'm sorry, you didn't compile Atheme with OpenSSL support.\n"); |
| 71 |
return EXIT_SUCCESS; |
| 72 |
} |
| 73 |
|
| 74 |
#endif |