1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 1995-2022 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/* We need to use the deprecated RSA low level calls */ 11e1051a39Sopenharmony_ci#define OPENSSL_SUPPRESS_DEPRECATED 12e1051a39Sopenharmony_ci 13e1051a39Sopenharmony_ci#include <stdio.h> 14e1051a39Sopenharmony_ci#include "internal/cryptlib.h" 15e1051a39Sopenharmony_ci#include <openssl/rsa.h> 16e1051a39Sopenharmony_ci#include <openssl/evp.h> 17e1051a39Sopenharmony_ci#include <openssl/objects.h> 18e1051a39Sopenharmony_ci#include <openssl/x509.h> 19e1051a39Sopenharmony_ci#include "crypto/evp.h" 20e1051a39Sopenharmony_ci 21e1051a39Sopenharmony_ciint EVP_PKEY_encrypt_old(unsigned char *ek, const unsigned char *key, 22e1051a39Sopenharmony_ci int key_len, EVP_PKEY *pubk) 23e1051a39Sopenharmony_ci{ 24e1051a39Sopenharmony_ci int ret = 0; 25e1051a39Sopenharmony_ci RSA *rsa = NULL; 26e1051a39Sopenharmony_ci 27e1051a39Sopenharmony_ci if (EVP_PKEY_get_id(pubk) != EVP_PKEY_RSA) { 28e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_EVP, EVP_R_PUBLIC_KEY_NOT_RSA); 29e1051a39Sopenharmony_ci goto err; 30e1051a39Sopenharmony_ci } 31e1051a39Sopenharmony_ci 32e1051a39Sopenharmony_ci rsa = evp_pkey_get0_RSA_int(pubk); 33e1051a39Sopenharmony_ci if (rsa == NULL) 34e1051a39Sopenharmony_ci goto err; 35e1051a39Sopenharmony_ci 36e1051a39Sopenharmony_ci ret = 37e1051a39Sopenharmony_ci RSA_public_encrypt(key_len, key, ek, rsa, RSA_PKCS1_PADDING); 38e1051a39Sopenharmony_ci err: 39e1051a39Sopenharmony_ci return ret; 40e1051a39Sopenharmony_ci} 41