1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 #ifndef CCSW_RSA_KG_H
9 #define CCSW_RSA_KG_H
10 
11 
12 #include "cc_pal_types.h"
13 #include "ccsw_cc_rsa_types.h"
14 
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
20 
21 /**
22    @brief CC_RsaKgKeyPairGenerate generates a Pair of public and private keys on non CRT mode.
23 
24    @param [in/out] rndContext_ptr  - Pointer to the RND context buffer.
25    @param [in] PubExp_ptr - The pointer to the public exponent (public key)
26    @param [in] PubExpSizeInBytes - The public exponent size in bytes.
27    @param [in] KeySize  - The size of the key, in bits. Supported sizes are:
28                             - for PKI without PKA HW: all 256 bit multiples between 512 - 2048;
29                             - for PKI with PKA: HW all 32 bit multiples between 512 - 2112;
30    @param [out] UserPrivKey_ptr - A pointer to the private key structure.
31                            This structure is used as input to the CC_RsaPrimDecrypt API.
32    @param [out] UserPubKey_ptr - A pointer to the public key structure.
33                            This structure is used as input to the CC_RsaPrimEncrypt API.
34    @param [in] KeyGenData_ptr - a pointer to a structure required for the KeyGen
35           operation.
36  * @param rndCtx_ptr - The pointer to structure, containing context ID and void
37  *              pointer to RND State structure, which should be converted to
38  *              actual type inside of the function according to used platform
39  *                  (External or CC). Also contains the RND generate vecotr function pointer.
40 
41    @return CCError_t - CC_OK,
42                          CC_RSA_INVALID_EXPONENT_POINTER_ERROR,
43                          CC_RSA_INVALID_PRIV_KEY_STRUCT_POINTER_ERROR,
44                          CC_RSA_INVALID_PUB_KEY_STRUCT_POINTER_ERROR,
45                          CC_RSA_KEY_GEN_DATA_STRUCT_POINTER_INVALID,
46                          CC_RSA_INVALID_MODULUS_SIZE,
47                          CC_RSA_INVALID_EXPONENT_SIZE
48 */
49 CEXPORT_C CCError_t CC_SwRsaKgGenerateKeyPair(
50             CCRndContext_t *rndContext_ptr,
51             uint8_t             *PubExp_ptr,
52             uint16_t             PubExpSizeInBytes,
53             uint32_t             KeySize,
54             CCSwRsaUserPrivKey_t *UserPrivKey_ptr,
55             CCSwRsaUserPubKey_t  *UserPubKey_ptr,
56             CCSwRsaKgData_t      *KeyGenData_ptr);
57 
58 
59 /***********************************************************************************************/
60 /**
61    @brief CC_SwRsaKgGenerateKeyPairCRT generates a Pair of public and private keys on CRT mode.
62 
63    @param [in/out] rndContext_ptr  - Pointer to the RND context buffer.
64    @param [in] PubExp_ptr - The pointer to the public exponent (public key)
65    @param [in] PubExpSizeInBytes - The public exponent size in bits.
66    @param [in] KeySize  - The size of the key, in bits. Supported sizes are:
67                             - for PKI without PKA HW: all 256 bit multiples between 512 - 2048;
68                             - for PKI with PKA: HW all 32 bit multiples between 512 - 2112;
69    @param [out] UserPrivKey_ptr - A pointer to the private key structure.
70                            This structure is used as input to the CC_RsaPrimDecrypt API.
71    @param [out] UserPubKey_ptr - A pointer to the public key structure.
72                            This structure is used as input to the CC_RsaPrimEncryped API.
73    @param [in] KeyGenData_ptr - a pointer to a structure required for the KeyGen operation.
74  * @param [in/out] RndCtx_ptr - The pointer to structure, containing context ID and void
75  *              pointer to RND State structure, which should be converted to
76  *              actual type inside of the function according to used platform
77  *                  (External or CC). Also contains the RND generate vecotr function pointer.
78 
79    @return CCError_t - CC_OK,
80                          CC_RSA_INVALID_EXPONENT_POINTER_ERROR,
81                          CC_RSA_INVALID_PRIV_KEY_STRUCT_POINTER_ERROR,
82                          CC_RSA_INVALID_PUB_KEY_STRUCT_POINTER_ERROR,
83                          CC_RSA_KEY_GEN_DATA_STRUCT_POINTER_INVALID,
84                          CC_RSA_INVALID_MODULUS_SIZE,
85                          CC_RSA_INVALID_EXPONENT_SIZE
86 */
87 
88 CEXPORT_C CCError_t CC_SwRsaKgGenerateKeyPairCRT(
89                 CCRndContext_t *rndContext_ptr,
90                 uint8_t             *PubExp_ptr,
91                 uint16_t             PubExpSizeInBytes,
92                 uint32_t             KeySize,
93                 CCSwRsaUserPrivKey_t *UserPrivKey_ptr,
94                 CCSwRsaUserPubKey_t  *UserPubKey_ptr,
95                 CCSwRsaKgData_t      *KeyGenData_ptr);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif
102 
103 
104