EVP_PKEY * b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u) { unsigned char pvk_hdr[24], *buf = NULL; const unsigned char *p; size_t buflen; EVP_PKEY *ret = NULL; unsigned int saltlen, keylen; if (BIO_read(in, pvk_hdr, 24) != 24) { PEMerror(PEM_R_PVK_DATA_TOO_SHORT); return NULL; } p = pvk_hdr; if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen)) return 0; buflen = keylen + saltlen; buf = malloc(buflen); if (!buf) { PEMerror(ERR_R_MALLOC_FAILURE); return 0; } p = buf; if (BIO_read(in, buf, buflen) != buflen) { PEMerror(PEM_R_PVK_DATA_TOO_SHORT); goto err; } ret = do_PVK_body(&p, saltlen, keylen, cb, u); err: freezero(buf, buflen); return ret; }
EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u) { unsigned char pvk_hdr[24], *buf = NULL; const unsigned char *p; int buflen; EVP_PKEY *ret = NULL; unsigned int saltlen, keylen; if (BIO_read(in, pvk_hdr, 24) != 24) { PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT); return NULL; } p = pvk_hdr; if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen)) return 0; buflen = (int)keylen + saltlen; buf = OPENSSL_malloc(buflen); if (buf == NULL) { PEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE); return 0; } p = buf; if (BIO_read(in, buf, buflen) != buflen) { PEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT); goto err; } ret = do_PVK_body(&p, saltlen, keylen, cb, u); err: OPENSSL_clear_free(buf, buflen); return ret; }