X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fgcrypt%2Frsagen.c;h=3469c3365dd9f18d6db0229ee5a546c884afa5c4;hb=bc4df95a48857aa4ab65fb47eabd48c48d650ca0;hp=01bb1378a46bb2a1ee284f43237074edee1cb7f6;hpb=28b7a53b693f6b4e70218a926e68a36ece54cda1;p=tinc diff --git a/src/gcrypt/rsagen.c b/src/gcrypt/rsagen.c index 01bb1378..3469c336 100644 --- a/src/gcrypt/rsagen.c +++ b/src/gcrypt/rsagen.c @@ -22,16 +22,12 @@ #include #include +#include "asn1.h" #include "rsa.h" #include "pem.h" #include "../rsagen.h" #include "../xalloc.h" - -// ASN.1 tags. -typedef enum { - TAG_INTEGER = 2, - TAG_SEQUENCE = 16, -} asn1_tag_t; +#include "../utils.h" static size_t der_tag_len(size_t n) { if(n < 128) { @@ -240,7 +236,9 @@ bool rsa_write_pem_private_key(rsa_t *rsa, FILE *fp) { gcry_mpi_release(params[dq]); gcry_mpi_release(params[u]); - return pem_encode(fp, "RSA PRIVATE KEY", derbuf, derlen); + bool success = pem_encode(fp, "RSA PRIVATE KEY", derbuf, derlen); + memzero(derbuf, sizeof(derbuf)); + return success; } static gcry_mpi_t find_mpi(const gcry_sexp_t rsa, const char *token) { @@ -299,7 +297,7 @@ rsa_t *rsa_generate(size_t bits, unsigned long exponent) { return NULL; } - rsa_t *rsa = xzalloc(sizeof(*rsa)); + rsa_t *rsa = rsa_new(); rsa->n = find_mpi(s_rsa, "n"); rsa->e = find_mpi(s_rsa, "e");