crys_rsa_kg.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**************************************************************************************
  2. * Copyright (c) 2016-2017, ARM Limited or its affiliates. All rights reserved *
  3. * *
  4. * This file and the related binary are licensed under the following license: *
  5. * *
  6. * ARM Object Code and Header Files License, v1.0 Redistribution. *
  7. * *
  8. * Redistribution and use of object code, header files, and documentation, without *
  9. * modification, are permitted provided that the following conditions are met: *
  10. * *
  11. * 1) Redistributions must reproduce the above copyright notice and the *
  12. * following disclaimer in the documentation and/or other materials *
  13. * provided with the distribution. *
  14. * *
  15. * 2) Unless to the extent explicitly permitted by law, no reverse *
  16. * engineering, decompilation, or disassembly of is permitted. *
  17. * *
  18. * 3) Redistribution and use is permitted solely for the purpose of *
  19. * developing or executing applications that are targeted for use *
  20. * on an ARM-based product. *
  21. * *
  22. * DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  23. * CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT *
  24. * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, *
  25. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
  26. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
  28. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
  33. **************************************************************************************/
  34. #ifndef CRYS_RSA_KG_H
  35. #define CRYS_RSA_KG_H
  36. #include "crys_rsa_types.h"
  37. #include "crys_rnd.h"
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. /*!
  43. @file
  44. @brief Generates a RSA pair of public and private keys.
  45. @defgroup crys_rsa_kg CryptoCell RSA key generation APIs
  46. @{
  47. @ingroup crys_rsa
  48. */
  49. /************************ Defines ******************************/
  50. /* Max allowed size and values of public exponent for key generation in CRYS */
  51. /*! Maximal public exponent size in bits. */
  52. #define CRYS_RSA_KG_PUB_EXP_MAX_SIZE_BITS 17
  53. /*! Definition of public exponent value. */
  54. #define CRYS_RSA_KG_PUB_EXP_ALLOW_VAL_1 0x000003
  55. /*! Definition of public exponent value. */
  56. #define CRYS_RSA_KG_PUB_EXP_ALLOW_VAL_2 0x000011
  57. /*! Definition of public exponent value. */
  58. #define CRYS_RSA_KG_PUB_EXP_ALLOW_VAL_3 0x010001
  59. /***********************************************************************************************/
  60. /*!
  61. @brief CRYS_RSA_KG_GenerateKeyPair generates a Pair of public and private keys on non CRT mode according to [ANS X9.31].
  62. \note To be FIPS 186-4 [5.1] compliant use only the following key sizes (in bits): 1024, 2048 and 3072.
  63. @return CRYS_OK on success.
  64. @return A non-zero value from crys_rsa_error.h or crys_rnd_error.h on failure.
  65. */
  66. CIMPORT_C CRYSError_t CRYS_RSA_KG_GenerateKeyPair(
  67. void *rndState_ptr, /*!< [in/out] Pointer to the RND state structure. */
  68. SaSiRndGenerateVectWorkFunc_t rndGenerateVectFunc, /*!< [in] Pointer to the random vector generation function. */
  69. uint8_t *pubExp_ptr, /*!< [in] The pointer to the public exponent (public key). */
  70. uint16_t pubExpSizeInBytes, /*!< [in] The public exponent size in bytes. */
  71. uint32_t keySize, /*!< [in] The size of the key, in bits. Supported sizes are
  72. 512, 1024, 2048, 3072 and 4096 bit. */
  73. CRYS_RSAUserPrivKey_t *userPrivKey_ptr, /*!< [out] Pointer to the private key structure. */
  74. CRYS_RSAUserPubKey_t *userPubKey_ptr, /*!< [out] Pointer to the public key structure. */
  75. CRYS_RSAKGData_t *keyGenData_ptr, /*!< [in] Pointer to a temporary structure required for the KeyGen operation. */
  76. CRYS_RSAKGFipsContext_t *pFipsCtx /*!< [in] Pointer to temporary buffer used in case FIPS certification if required. */
  77. );
  78. /***********************************************************************************************/
  79. /*!
  80. @brief Generates a pair of public and private keys on CRT mode according to [ANS X9.31].
  81. \note To be FIPS 186-4 [5.1] compliant use only the following key sizes (in bits): 1024, 2048 and 3072.
  82. @return CRYS_OK on success.
  83. @return A non-zero value from crys_rsa_error.h or crys_rnd_error.h on failure.
  84. */
  85. CIMPORT_C CRYSError_t CRYS_RSA_KG_GenerateKeyPairCRT(
  86. void *rndState_ptr, /*!< [in/out] Pointer to the RND state structure. */
  87. SaSiRndGenerateVectWorkFunc_t rndGenerateVectFunc, /*!< [in] Pointer to the random vector generation function. */
  88. uint8_t *pubExp_ptr, /*!< [in] The pointer to the public exponent (public key). */
  89. uint16_t pubExpSizeInBytes, /*!< [in] The public exponent size in bytes. */
  90. uint32_t keySize, /*!< [in] The size of the key, in bits. Supported sizes are
  91. 512, 1024, 2048, 3072 and 4096 bit. */
  92. CRYS_RSAUserPrivKey_t *userPrivKey_ptr, /*!< [out] Pointer to the private key structure. */
  93. CRYS_RSAUserPubKey_t *userPubKey_ptr, /*!< [out] Pointer to the public key structure. */
  94. CRYS_RSAKGData_t *keyGenData_ptr, /*!< [in] Pointer to a temporary structure required for the KeyGen operation. */
  95. CRYS_RSAKGFipsContext_t *pFipsCtx /*!< [in] Pointer to temporary buffer used in case FIPS certification if required. */
  96. );
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. /**
  101. @}
  102. */
  103. #endif