15 typedef unsigned char uschar;
18 #define US (unsigned char *)
28 #include <gnutls/gnutls.h>
29 #include <gnutls/abstract.h>
30 #include <gnutls/x509.h>
32 #if GNUTLS_VERSION_NUMBER >= 0x030600
33 # define SIGN_HAVE_ED25519
38 static uschar *enc64table =
39 US"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
42 b64encode(uschar *clear, int len)
44 uschar *code = malloc(4*((len+2)/3) + 2);
52 *p++ = enc64table[(x >> 2) & 63];
56 *p++ = enc64table[(x << 4) & 63];
63 *p++ = enc64table[((x << 4) | ((y >> 4) & 15)) & 63];
67 *p++ = enc64table[(y << 2) & 63];
73 *p++ = enc64table[((y << 2) | ((x >> 6) & 3)) & 63];
75 *p++ = enc64table[x & 63];
83 /*************************************************
85 *************************************************/
89 main(int argc, char **argv)
91 uschar * pemfile = argv[1];
95 gnutls_privkey_t privkey;
97 gnutls_pubkey_t pubkey;
100 #ifdef SIGN_HAVE_ED25519
101 if ((fd = open(CS pemfile, O_RDONLY)) < 0)
104 if ((len = read(fd, buf, sizeof(buf)-1)) < 0)
110 if ( (rc = gnutls_privkey_init(&privkey))
111 || (rc = gnutls_privkey_import_x509_raw(privkey, &k, GNUTLS_X509_FMT_PEM, NULL, GNUTLS_PKCS_PLAIN))
112 || (rc = gnutls_pubkey_init(&pubkey))
113 || (rc = gnutls_pubkey_import_privkey(pubkey, privkey, GNUTLS_KEY_DIGITAL_SIGNATURE, 0))
114 || (rc = gnutls_pubkey_export_ecc_raw2(pubkey, NULL, &k, NULL, GNUTLS_EXPORT_FLAG_NO_LZ))
116 fprintf(stderr, "%s\n", gnutls_strerror(rc));
118 b64 = b64encode(k.data, k.size);
124 fprintf(stderr, "No support for ed25519 signing in GnuTLS (version %s)\n", gnutls_check_version(NULL));
133 main(int argc, char **argv)
135 fprintf(stderr, "No support for ed25519 signing in OpenSSL\n");