1 /*
2  * Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _CC_RSA_KG_H
8 #define _CC_RSA_KG_H
9 
10 #ifdef CC_IOT
11 #include "mbedtls/build_info.h"
12 #endif
13 
14 #include "cc_rsa_types.h"
15 #include "cc_rnd_common.h"
16 
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21 
22 /*!
23 @file
24 @brief Generates a RSA pair of public and private keys.
25 @defgroup cc_rsa_kg CryptoCell RSA key generation APIs
26 @{
27 @ingroup cc_rsa
28 */
29 
30 /************************ Defines ******************************/
31 
32 /* Max allowed size and values of public exponent for key generation in CryptoCell*/
33 /*! Maximal public exponent size in bits. */
34 #define CC_RSA_KG_PUB_EXP_MAX_SIZE_BITS    17
35 /*! Definition of public exponent value. */
36 #define CC_RSA_KG_PUB_EXP_ALLOW_VAL_1      0x000003
37 /*! Definition of public exponent value. */
38 #define CC_RSA_KG_PUB_EXP_ALLOW_VAL_2      0x000011
39 /*! Definition of public exponent value. */
40 #define CC_RSA_KG_PUB_EXP_ALLOW_VAL_3      0x010001
41 
42 
43 
44 
45 /***********************************************************************************************/
46 
47 /*!
48 @brief CC_RsaKgKeyPairGenerate generates a Pair of public and private keys on non CRT mode according to ANSI X9.31-1988: Public Key
49 Cryptography Using Reversible Algorithms for the Financial Services Industry (rDSA).
50 
51 \note   To be FIPS Publication 186-4: Digital Signature Standard (DSS) [5.1] compliant use only the following:
52     key sizes (in bits): 2048, 3072, 4096 and public exponent value 0x10001.
53 
54 @return CC_OK on success.
55 @return A non-zero value from cc_rsa_error.h or cc_rnd_error.h on failure.
56 
57 */
58 CIMPORT_C CCError_t CC_RsaKgKeyPairGenerate(
59                                         CCRndContext_t *rndContext_ptr,          /*!< [in/out] Pointer to the RND context buffer. */
60                                         uint8_t             *pubExp_ptr,            /*!< [in]  The pointer to the public exponent (public key). */
61                                         size_t               pubExpSizeInBytes,     /*!< [in]  The public exponent size in bytes. */
62                                         size_t               keySize,               /*!< [in]  The size of the key, in bits. Supported sizes are
63                                                    2048, 3072 and 4096 bit. */
64                                         CCRsaUserPrivKey_t *userPrivKey_ptr,     /*!< [out] Pointer to the private-key structure. */
65                                         CCRsaUserPubKey_t  *userPubKey_ptr,      /*!< [out] Pointer to the public-key structure. */
66                     CCRsaKgData_t      *keyGenData_ptr,      /*!< [in]  Pointer to a temporary structure required for the KeyGen operation. */
67                                         CCRsaKgFipsContext_t    *pFipsCtx        /*!< [in]  Pointer to temporary buffer used in case FIPS certification if required
68                                                 (may be NULL for all other cases). */
69 );
70 
71 /***********************************************************************************************/
72 /*!
73 @brief Generates a pair of public and private keys on CRT mode according to ANSI X9.31-1988: Public Key
74 Cryptography Using Reversible Algorithms for the Financial Services Industry (rDSA).
75 
76 \note To be FIPS Publication 186-4: Digital Signature Standard (DSS) compliant use only the following key sizes (in bits): 2048, 3072 and 4096.
77 
78 @return CC_OK on success.
79 @return A non-zero value from cc_rsa_error.h or cc_rnd_error.h on failure.
80 */
81 
82 CIMPORT_C CCError_t CC_RsaKgKeyPairCrtGenerate(
83                                         CCRndContext_t *rndContext_ptr,         /*!< [in/out] Pointer to the RND context buffer. */
84                                         uint8_t             *pubExp_ptr,           /*!< [in]  The pointer to the public exponent (public key). */
85                                         size_t               pubExpSizeInBytes,    /*!< [in]  The public exponent size in bytes. */
86                                         size_t               keySize,              /*!< [in]  The size of the key, in bits. Supported sizes are
87                                                                                               2048, 3072 and 4096 bit. */
88                                         CCRsaUserPrivKey_t *userPrivKey_ptr,    /*!< [out] Pointer to the private-key structure. */
89                                         CCRsaUserPubKey_t  *userPubKey_ptr,     /*!< [out] Pointer to the public-key structure. */
90                                         CCRsaKgData_t      *keyGenData_ptr,     /*!< [in] Pointer to a temporary structure required for the KeyGen operation. */
91                                         CCRsaKgFipsContext_t    *pFipsCtx       /*!< [in] Pointer to temporary buffer used in case FIPS certification if required
92                                               (may be NULL for all other cases). */
93 );
94 
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 /**
100 @}
101  */
102 
103 #endif /* _CC_RSA_KG_H */
104