1 /* 2 * Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 8 #ifndef _CC_RSA_PRIM_H 9 #define _CC_RSA_PRIM_H 10 11 #ifdef CC_IOT 12 #include "mbedtls/build_info.h" 13 #endif 14 15 #if !defined(CC_IOT) || ( defined(CC_IOT) && defined(MBEDTLS_RSA_C)) 16 17 #include "cc_rsa_types.h" 18 19 #ifdef __cplusplus 20 extern "C" 21 { 22 #endif 23 24 /*! 25 @file 26 @brief This file defines the API that implements the Public-Key Cryptography Standards (PKCS) #1 27 RSA Cryptography Specifications Version 2.1 primitive functions. 28 @defgroup cc_rsa_prim CryptoCell RSA primitive APIs 29 @{ 30 @ingroup cc_rsa 31 32 33 \note Direct use of primitive functions, rather than schemes to protect data, is strongly discouraged as primitive functions are 34 susceptible to well-known attacks. 35 */ 36 37 38 39 /**********************************************************************************/ 40 /*! 41 @brief Implements the RSAEP algorithm, as defined in section 6.1.1 of Public-Key Cryptography Standards (PKCS) #1 RSA Cryptography 42 Specifications Version 2.1. 43 44 @return CC_OK on success. 45 @return A non-zero value from cc_rsa_error.h on failure. 46 */ 47 CIMPORT_C CCError_t CC_RsaPrimEncrypt( 48 CCRsaUserPubKey_t *UserPubKey_ptr, /*!< [in] Pointer to the public-key data structure. */ 49 CCRsaPrimeData_t *PrimeData_ptr, /*!< [in] Pointer to a temporary structure containing internal buffers. */ 50 uint8_t *Data_ptr, /*!< [in] Pointer to the data to encrypt. */ 51 size_t DataSize, /*!< [in] The size (in bytes) of the data to encrypt. Data size must be ≤ Modulus size. 52 It can be smaller than the modulus size but it is not recommended. 53 If smaller, the data is zero-padded up to the modulus size. 54 Since the result of decryption is always the size of the modulus, 55 this causes the size of the decrypted data to be larger than the 56 originally encrypted data. */ 57 uint8_t *Output_ptr /*!< [out] Pointer to the encrypted data. The buffer size must be ≥ the modulus size. */ 58 ); 59 60 61 /**********************************************************************************/ 62 /*! 63 @brief Implements the RSADP algorithm, as defined in section 6.1.2 of Public-Key Cryptography Standards (PKCS) #1 RSA Cryptography 64 Specifications Version 2.1. 65 66 @return CC_OK on success. 67 @return A non-zero value from cc_rsa_error.h on failure. 68 69 */ 70 CIMPORT_C CCError_t CC_RsaPrimDecrypt( 71 CCRsaUserPrivKey_t *UserPrivKey_ptr, /*!< [in] Pointer to the private-key data structure. 72 The representation (pair or quintuple) and hence the algorithm (CRT or not-CRT) 73 is determined by the Private Key data structure - using 74 ::CC_RsaPrivKeyBuild or ::CC_RsaPrivKeyCrtBuild 75 to determine which algorithm is used.*/ 76 CCRsaPrimeData_t *PrimeData_ptr, /*!< [in] Pointer to a temporary structure containing internal buffers required for 77 the RSA operation. */ 78 uint8_t *Data_ptr, /*!< [in] Pointer to the data to be decrypted. */ 79 size_t DataSize, /*!< [in] The size (in bytes) of the data to decrypt. Must be equal to the modulus size. */ 80 uint8_t *Output_ptr /*!< [out] Pointer to the decrypted data. The buffer size must be ≤ the modulus size. */ 81 ); 82 83 84 /*! 85 @brief Implements the RSASP1 algorithm, as defined in [PKCS1_2.1] - 6.2.1, as a call to ::CC_RsaPrimDecrypt, 86 since the signature primitive is identical to the decryption primitive. 87 */ 88 #define CC_RsaPrimSign CC_RsaPrimDecrypt 89 90 /*! 91 @brief Implements the RSAVP1 algorithm, as defined in [PKCS1_2.1] - 6.2.2, as a call to ::CC_RsaPrimEncrypt. 92 */ 93 #define CC_RsaPrimVerify CC_RsaPrimEncrypt 94 95 #ifdef __cplusplus 96 } 97 #endif 98 /** 99 @} 100 */ 101 #endif /* !defined(CC_IOT) || ( defined(CC_IOT) && defined(MBEDTLS_RSA_C)) */ 102 #endif /* _CC_RSA_PRIM_H */ 103