diff options
-rw-r--r-- | crypto/pem/pvkfmt.c | 51 | ||||
-rw-r--r-- | crypto/store/loader_file.c | 2 | ||||
-rw-r--r-- | include/internal/pem.h (renamed from crypto/include/internal/pem_int.h) | 12 |
3 files changed, 40 insertions, 25 deletions
diff --git a/crypto/pem/pvkfmt.c b/crypto/pem/pvkfmt.c index 6d85a8a4e1..3745a1c1e3 100644 --- a/crypto/pem/pvkfmt.c +++ b/crypto/pem/pvkfmt.c @@ -20,7 +20,7 @@ #include "internal/cryptlib.h" #include <openssl/pem.h> -#include "internal/pem_int.h" +#include "internal/pem.h" #include <openssl/rand.h> #include <openssl/bn.h> #if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_NO_DSA) @@ -186,28 +186,27 @@ static unsigned int blob_length(unsigned bitlen, int isdss, int ispub) } -static EVP_PKEY *do_b2i(const unsigned char **in, unsigned int length, - int ispub) +EVP_PKEY *ossl_b2i(const unsigned char **in, unsigned int length, int *ispub) { const unsigned char *p = *in; unsigned int bitlen, magic; int isdss; - if (ossl_do_blob_header(&p, length, &magic, &bitlen, &isdss, &ispub) <= 0) { - PEMerr(PEM_F_DO_B2I, PEM_R_KEYBLOB_HEADER_PARSE_ERROR); + if (ossl_do_blob_header(&p, length, &magic, &bitlen, &isdss, ispub) <= 0) { + PEMerr(0, PEM_R_KEYBLOB_HEADER_PARSE_ERROR); return NULL; } length -= 16; - if (length < blob_length(bitlen, isdss, ispub)) { - PEMerr(PEM_F_DO_B2I, PEM_R_KEYBLOB_TOO_SHORT); + if (length < blob_length(bitlen, isdss, *ispub)) { + PEMerr(0, PEM_R_KEYBLOB_TOO_SHORT); return NULL; } if (isdss) - return b2i_dss(&p, bitlen, ispub); + return b2i_dss(&p, bitlen, *ispub); else - return b2i_rsa(&p, bitlen, ispub); + return b2i_rsa(&p, bitlen, *ispub); } -static EVP_PKEY *do_b2i_bio(BIO *in, int ispub) +EVP_PKEY *ossl_b2i_bio(BIO *in, int *ispub) { const unsigned char *p; unsigned char hdr_buf[16], *buf = NULL; @@ -215,33 +214,33 @@ static EVP_PKEY *do_b2i_bio(BIO *in, int ispub) int isdss; EVP_PKEY *ret = NULL; if (BIO_read(in, hdr_buf, 16) != 16) { - PEMerr(PEM_F_DO_B2I_BIO, PEM_R_KEYBLOB_TOO_SHORT); + PEMerr(0, PEM_R_KEYBLOB_TOO_SHORT); return NULL; } p = hdr_buf; - if (ossl_do_blob_header(&p, 16, &magic, &bitlen, &isdss, &ispub) <= 0) + if (ossl_do_blob_header(&p, 16, &magic, &bitlen, &isdss, ispub) <= 0) return NULL; - length = blob_length(bitlen, isdss, ispub); + length = blob_length(bitlen, isdss, *ispub); if (length > BLOB_MAX_LENGTH) { - PEMerr(PEM_F_DO_B2I_BIO, PEM_R_HEADER_TOO_LONG); + PEMerr(0, PEM_R_HEADER_TOO_LONG); return NULL; } buf = OPENSSL_malloc(length); if (buf == NULL) { - PEMerr(PEM_F_DO_B2I_BIO, ERR_R_MALLOC_FAILURE); + PEMerr(0, ERR_R_MALLOC_FAILURE); goto err; } p = buf; if (BIO_read(in, buf, length) != (int)length) { - PEMerr(PEM_F_DO_B2I_BIO, PEM_R_KEYBLOB_TOO_SHORT); + PEMerr(0, PEM_R_KEYBLOB_TOO_SHORT); goto err; } if (isdss) - ret = b2i_dss(&p, bitlen, ispub); + ret = b2i_dss(&p, bitlen, *ispub); else - ret = b2i_rsa(&p, bitlen, ispub); + ret = b2i_rsa(&p, bitlen, *ispub); err: OPENSSL_free(buf); @@ -391,22 +390,30 @@ static EVP_PKEY *b2i_rsa(const unsigned char **in, EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length) { - return do_b2i(in, length, 0); + int ispub = 0; + + return ossl_b2i(in, length, &ispub); } EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length) { - return do_b2i(in, length, 1); + int ispub = 1; + + return ossl_b2i(in, length, &ispub); } EVP_PKEY *b2i_PrivateKey_bio(BIO *in) { - return do_b2i_bio(in, 0); + int ispub = 0; + + return ossl_b2i_bio(in, &ispub); } EVP_PKEY *b2i_PublicKey_bio(BIO *in) { - return do_b2i_bio(in, 1); + int ispub = 1; + + return ossl_b2i_bio(in, &ispub); } static void write_ledword(unsigned char **out, unsigned int dw) diff --git a/crypto/store/loader_file.c b/crypto/store/loader_file.c index 5ff93e33ab..da4e96b989 100644 --- a/crypto/store/loader_file.c +++ b/crypto/store/loader_file.c @@ -21,7 +21,7 @@ #include <openssl/err.h> #include <openssl/evp.h> #include <openssl/pem.h> -#include "internal/pem_int.h" +#include "internal/pem.h" #include <openssl/pkcs12.h> /* For the PKCS8 stuff o.O */ #include <openssl/rsa.h> /* For d2i_RSAPrivateKey */ #include <openssl/safestack.h> diff --git a/crypto/include/internal/pem_int.h b/include/internal/pem.h index c8f90528c3..b6a10241f3 100644 --- a/crypto/include/internal/pem_int.h +++ b/include/internal/pem.h @@ -7,17 +7,25 @@ * https://www.openssl.org/source/license.html */ -#ifndef HEADER_PEM_INT_H -# define HEADER_PEM_INT_H +#ifndef OSSL_INTERNAL_PEM_H +# define OSSL_INTERNAL_PEM_H # include <openssl/pem.h> +# ifndef OPENSSL_NO_DSA /* Found in crypto/pem/pvkfmt.c */ int ossl_do_blob_header(const unsigned char **in, unsigned int length, unsigned int *pmagic, unsigned int *pbitlen, int *pisdss, int *pispub); +# ifndef OPENSSL_NO_RC4 int ossl_do_PVK_header(const unsigned char **in, unsigned int length, int skip_magic, unsigned int *psaltlen, unsigned int *pkeylen); +# endif + +EVP_PKEY *ossl_b2i(const unsigned char **in, unsigned int length, int *ispub); +EVP_PKEY *ossl_b2i_bio(BIO *in, int *ispub); + +# endif #endif |