X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fopenssl%2Frsa.c;h=e1ae4f61b8777136278feda98e8a51aaaa9501c3;hp=3543df3050f3d7decaa7ee2575a6c8e831ce426f;hb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;hpb=3a316823b971396a428f020f401b9fe41252d98d diff --git a/src/openssl/rsa.c b/src/openssl/rsa.c index 3543df30..e1ae4f61 100644 --- a/src/openssl/rsa.c +++ b/src/openssl/rsa.c @@ -32,9 +32,12 @@ typedef RSA rsa_t; #ifndef HAVE_RSA_SET0_KEY int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) { - BN_free(r->n); r->n = n; - BN_free(r->e); r->e = e; - BN_free(r->d); r->d = d; + BN_free(r->n); + r->n = n; + BN_free(r->e); + r->e = e; + BN_free(r->d); + r->d = d; return 1; } #endif @@ -50,9 +53,11 @@ rsa_t *rsa_set_hex_public_key(char *n, char *e) { } rsa_t *rsa = RSA_new(); - if(!rsa) + + if(!rsa) { return NULL; - + } + RSA_set0_key(rsa, bn_n, bn_e, NULL); return rsa; @@ -71,8 +76,10 @@ rsa_t *rsa_set_hex_private_key(char *n, char *e, char *d) { } rsa_t *rsa = RSA_new(); - if(!rsa) + + if(!rsa) { return NULL; + } RSA_set0_key(rsa, bn_n, bn_e, bn_d); @@ -89,8 +96,9 @@ rsa_t *rsa_read_pem_public_key(FILE *fp) { rsa = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL); } - if(!rsa) + if(!rsa) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA public key: %s", ERR_error_string(ERR_get_error(), NULL)); + } return rsa; } @@ -98,8 +106,9 @@ rsa_t *rsa_read_pem_public_key(FILE *fp) { rsa_t *rsa_read_pem_private_key(FILE *fp) { rsa_t *rsa = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL); - if(!rsa) + if(!rsa) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA private key: %s", ERR_error_string(ERR_get_error(), NULL)); + } return rsa; } @@ -109,16 +118,18 @@ size_t rsa_size(rsa_t *rsa) { } bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) { - if(RSA_public_encrypt(len, in, out, rsa, RSA_NO_PADDING) == len) + if(RSA_public_encrypt(len, in, out, rsa, RSA_NO_PADDING) == len) { return true; + } logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA encryption: %s", ERR_error_string(ERR_get_error(), NULL)); return false; } bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { - if(RSA_private_decrypt(len, in, out, rsa, RSA_NO_PADDING) == len) + if(RSA_private_decrypt(len, in, out, rsa, RSA_NO_PADDING) == len) { return true; + } logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA decryption: %s", ERR_error_string(ERR_get_error(), NULL)); return false; @@ -129,6 +140,7 @@ bool rsa_active(rsa_t *rsa) { } void rsa_free(rsa_t *rsa) { - if(rsa) + if(rsa) { RSA_free(rsa); + } }