Debian Codegraph @

src/ecdsakeygen/main.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013 William Pitcock <[email protected]>.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
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