summaryrefslogtreecommitdiff
path: root/xs_openssl.h
diff options
context:
space:
mode:
Diffstat (limited to 'xs_openssl.h')
-rw-r--r--xs_openssl.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/xs_openssl.h b/xs_openssl.h
index 64b59dd..6d804f7 100644
--- a/xs_openssl.h
+++ b/xs_openssl.h
@@ -38,7 +38,7 @@ xs_str *xs_base64_enc(const xs_val *data, int sz)
38{ 38{
39 BIO *mem, *b64; 39 BIO *mem, *b64;
40 BUF_MEM *bptr; 40 BUF_MEM *bptr;
41 41
42 b64 = BIO_new(BIO_f_base64()); 42 b64 = BIO_new(BIO_f_base64());
43 mem = BIO_new(BIO_s_mem()); 43 mem = BIO_new(BIO_s_mem());
44 b64 = BIO_push(b64, mem); 44 b64 = BIO_push(b64, mem);
@@ -118,16 +118,16 @@ xs_dict *xs_evp_genkey(int bits)
118/* generates an RSA keypair using the EVP interface */ 118/* generates an RSA keypair using the EVP interface */
119{ 119{
120 xs_dict *keypair = NULL; 120 xs_dict *keypair = NULL;
121 EVP_PKEY_CTX *ctx; 121 EVP_PKEY_CTX *ctx = NULL;
122 EVP_PKEY *pkey = NULL; 122 EVP_PKEY *pkey = NULL;
123 123
124 if ((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL)) == NULL) 124 if ((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL)) == NULL)
125 goto end; 125 return NULL;
126 126
127 if (EVP_PKEY_keygen_init(ctx) <= 0 || 127 if (EVP_PKEY_keygen_init(ctx) <= 0 ||
128 EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) <= 0 || 128 EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) <= 0 ||
129 EVP_PKEY_keygen(ctx, &pkey) <= 0) 129 EVP_PKEY_keygen(ctx, &pkey) <= 0)
130 goto end; 130 return NULL;
131 131
132 BIO *bs = BIO_new(BIO_s_mem()); 132 BIO *bs = BIO_new(BIO_s_mem());
133 BIO *bp = BIO_new(BIO_s_mem()); 133 BIO *bp = BIO_new(BIO_s_mem());
@@ -142,13 +142,17 @@ xs_dict *xs_evp_genkey(int bits)
142 142
143 keypair = xs_dict_new(); 143 keypair = xs_dict_new();
144 144
145 keypair = xs_dict_append(keypair, "secret", sptr->data); 145 xs *secret = xs_str_new_sz(sptr->data, sptr->length);
146 keypair = xs_dict_append(keypair, "public", pptr->data); 146 xs *public = xs_str_new_sz(pptr->data, pptr->length);
147 keypair = xs_dict_append(keypair, "secret", secret);
148 keypair = xs_dict_append(keypair, "public", public);
147 149
148 BIO_free(bs); 150 BIO_free(bs);
149 BIO_free(bp); 151 BIO_free(bp);
150 152
151end: 153 EVP_PKEY_free(pkey);
154 EVP_PKEY_CTX_free(ctx);
155
152 return keypair; 156 return keypair;
153} 157}
154 158