1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#include <stdio.h> 11e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 12e1051a39Sopenharmony_ci#include <openssl/evp.h> 13e1051a39Sopenharmony_ci#include <openssl/objects.h> 14e1051a39Sopenharmony_ci#include <openssl/x509.h> 15e1051a39Sopenharmony_ci 16e1051a39Sopenharmony_ciX509_PKEY *X509_PKEY_new(void) 17e1051a39Sopenharmony_ci{ 18e1051a39Sopenharmony_ci X509_PKEY *ret = NULL; 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_ci ret = OPENSSL_zalloc(sizeof(*ret)); 21e1051a39Sopenharmony_ci if (ret == NULL) 22e1051a39Sopenharmony_ci goto err; 23e1051a39Sopenharmony_ci 24e1051a39Sopenharmony_ci ret->enc_algor = X509_ALGOR_new(); 25e1051a39Sopenharmony_ci ret->enc_pkey = ASN1_OCTET_STRING_new(); 26e1051a39Sopenharmony_ci if (ret->enc_algor == NULL || ret->enc_pkey == NULL) 27e1051a39Sopenharmony_ci goto err; 28e1051a39Sopenharmony_ci 29e1051a39Sopenharmony_ci return ret; 30e1051a39Sopenharmony_cierr: 31e1051a39Sopenharmony_ci X509_PKEY_free(ret); 32e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE); 33e1051a39Sopenharmony_ci return NULL; 34e1051a39Sopenharmony_ci} 35e1051a39Sopenharmony_ci 36e1051a39Sopenharmony_civoid X509_PKEY_free(X509_PKEY *x) 37e1051a39Sopenharmony_ci{ 38e1051a39Sopenharmony_ci if (x == NULL) 39e1051a39Sopenharmony_ci return; 40e1051a39Sopenharmony_ci 41e1051a39Sopenharmony_ci X509_ALGOR_free(x->enc_algor); 42e1051a39Sopenharmony_ci ASN1_OCTET_STRING_free(x->enc_pkey); 43e1051a39Sopenharmony_ci EVP_PKEY_free(x->dec_pkey); 44e1051a39Sopenharmony_ci if (x->key_free) 45e1051a39Sopenharmony_ci OPENSSL_free(x->key_data); 46e1051a39Sopenharmony_ci OPENSSL_free(x); 47e1051a39Sopenharmony_ci} 48