crys_rsa_build.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_BUILD_H
  35. #define CRYS_RSA_BUILD_H
  36. #include "crys_error.h"
  37. #include "crys_rsa_types.h"
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. /*!
  43. @defgroup crys_rsa CryptoCell RSA APIs
  44. @{
  45. @ingroup cryptocell_api
  46. @brief This group is the cryptocell ECC root group
  47. @}
  48. @file
  49. @brief This module defines some utility functions for working with RSA cryptography.
  50. @defgroup crys_rsa_build CryptoCell RSA Utility APIs
  51. @{
  52. @ingroup crys_rsa
  53. */
  54. /******************************************************************************************/
  55. /*!
  56. @brief Builds a ::CRYSRSAPubKey_t public key structure with the provided modulus and exponent.
  57. @return CRYS_OK on success.
  58. @return A non-zero value from crys_rsa_error.h on failure.
  59. */
  60. CIMPORT_C CRYSError_t CRYS_RSA_Build_PubKey(
  61. CRYS_RSAUserPubKey_t *UserPubKey_ptr, /*!< [out] Pointer to the public key structure. */
  62. uint8_t *Exponent_ptr, /*!< [in] Pointer to the exponent stream of bytes (Big-Endian format). */
  63. uint16_t ExponentSize, /*!< [in] The size of the exponent (in bytes). */
  64. uint8_t *Modulus_ptr, /*!< [in] Pointer to the modulus stream of bytes (Big-Endian format).
  65. The most significant bit (MSB) must be set to '1'. */
  66. uint16_t ModulusSize /*!< [in] The modulus size in bytes. Supported sizes are 64, 128, 256, 384 and 512. */
  67. );
  68. /******************************************************************************************/
  69. /*!
  70. @brief Builds a ::CRYSRSAPrivKey_t private key structure with the provided modulus and exponent, marking the key as a non-CRT key.
  71. @return CRYS_OK on success.
  72. @return A non-zero value from crys_rsa_error.h on failure.
  73. */
  74. CIMPORT_C CRYSError_t CRYS_RSA_Build_PrivKey(
  75. CRYS_RSAUserPrivKey_t *UserPrivKey_ptr, /*!< [out] Pointer to the public key structure.*/
  76. uint8_t *PrivExponent_ptr, /*!< [in] Pointer to the private exponent stream of bytes (Big-Endian format). */
  77. uint16_t PrivExponentSize, /*!< [in] The size of the private exponent (in bytes). */
  78. uint8_t *PubExponent_ptr, /*!< [in] Pointer to the public exponent stream of bytes (Big-Endian format). */
  79. uint16_t PubExponentSize, /*!< [in] The size of the public exponent (in bytes). */
  80. uint8_t *Modulus_ptr, /*!< [in] Pointer to the modulus stream of bytes (Big-Endian format).
  81. The most significant bit must be set to '1'. */
  82. uint16_t ModulusSize /*!< [in] The modulus size in bytes. Supported sizes are 64, 128, 256, 384 and 512. */
  83. );
  84. /******************************************************************************************/
  85. /*!
  86. @brief Builds a ::CRYSRSAPrivKey_t private key structure with the provided parameters, marking the key as a CRT key.
  87. @return CRYS_OK on success.
  88. @return A non-zero value from crys_rsa_error.h on failure.
  89. */
  90. CIMPORT_C CRYSError_t CRYS_RSA_Build_PrivKeyCRT(
  91. CRYS_RSAUserPrivKey_t *UserPrivKey_ptr, /*!< [out] Pointer to the public key structure. */
  92. uint8_t *P_ptr, /*!< [in] Pointer to the first factor stream of bytes (Big-Endian format). */
  93. uint16_t PSize, /*!< [in] The size of the first factor (in bytes). */
  94. uint8_t *Q_ptr, /*!< [in] Pointer to the second factor stream of bytes (Big-Endian format). */
  95. uint16_t QSize, /*!< [in] The size of the second factor (in bytes). */
  96. uint8_t *dP_ptr, /*!< [in] Pointer to the first factor's CRT exponent stream of bytes
  97. (Big-Endian format). */
  98. uint16_t dPSize, /*!< [in] The size of the first factor's CRT exponent (in bytes). */
  99. uint8_t *dQ_ptr, /*!< [in] Pointer to the second factor's CRT exponent stream of bytes
  100. (Big-Endian format). */
  101. uint16_t dQSize, /*!< [in] The size of the second factor's CRT exponent (in bytes). */
  102. uint8_t *qInv_ptr, /*!< [in] Pointer to the first CRT coefficient stream of bytes (Big-Endian format). */
  103. uint16_t qInvSize /*!< [in] The size of the first CRT coefficient (in bytes). */
  104. );
  105. /******************************************************************************************/
  106. /*!
  107. @brief The function gets the e,n public key parameters from the input
  108. CRYS_RSAUserPubKey_t structure. The function can also be used to retrieve the
  109. modulus and exponent sizes only (Exponent_ptr AND Modulus_ptr must be set to
  110. NULL).
  111. \note All members of input UserPubKey_ptr structure must be initialized.
  112. @return CRYS_OK on success.
  113. @return A non-zero value from crys_rsa_error.h on failure.
  114. */
  115. CIMPORT_C CRYSError_t CRYS_RSA_Get_PubKey(
  116. CRYS_RSAUserPubKey_t *UserPubKey_ptr, /*!< [in] A pointer to the public key structure. */
  117. uint8_t *Exponent_ptr, /*!< [out] A pointer to the exponent stream of bytes (Big-Endian format). */
  118. uint16_t *ExponentSize_ptr, /*!< [in/out] the size of the exponent buffer in bytes,
  119. it is updated to the actual size of the exponent, in bytes. */
  120. uint8_t *Modulus_ptr, /*!< [out] A pointer to the modulus stream of bytes (Big-Endian format).
  121. The MS (most significant) bit must be set to '1'. */
  122. uint16_t *ModulusSize_ptr /*!< [in/out] the size of the modulus buffer in bytes, it is updated to the actual
  123. size of the modulus, in bytes. */
  124. );
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. /**
  129. @}
  130. */
  131. #endif