crys_rsa_prim.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_PRIM_H
  35. #define CRYS_RSA_PRIM_H
  36. #include "crys_rsa_types.h"
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. /*!
  42. @file
  43. @brief This module defines the API that implements the [PKCS1_2.1] primitive functions.
  44. @defgroup crys_rsa_prim CryptoCell RSA primitive APIs
  45. @{
  46. @ingroup crys_rsa
  47. \note Direct use of primitive functions, rather than schemes to protect data, is strongly discouraged as primitive functions are
  48. susceptible to well-known attacks.
  49. */
  50. /**********************************************************************************/
  51. /*!
  52. @brief Implements the RSAEP algorithm, as defined in [PKCS1_2.1] - 6.1.1.
  53. @return CRYS_OK on success.
  54. @return A non-zero value from crys_rsa_error.h on failure.
  55. */
  56. CIMPORT_C CRYSError_t CRYS_RSA_PRIM_Encrypt(
  57. CRYS_RSAUserPubKey_t *UserPubKey_ptr, /*!< [in] Pointer to the public key data structure. */
  58. CRYS_RSAPrimeData_t *PrimeData_ptr, /*!< [in] Pointer to a temporary structure containing internal buffers. */
  59. uint8_t *Data_ptr, /*!< [in] Pointer to the data to encrypt. */
  60. uint16_t DataSize, /*!< [in] The size (in bytes) of input data must be &le; modulus size. If is smaller,
  61. then the function padds it by zeros on left side up to the modulus size
  62. and therefore, after further decrypt operation, its result will contain
  63. zero-padding also. If the function is used for recovering the plain data
  64. from result of inverse function (CRYS_RSA_PRIM_Decrypt), the input size
  65. must be equal to modulus size exactly. */
  66. uint8_t *Output_ptr /*!< [out] Pointer to the encrypted data. The buffer size must be &ge; the modulus size. */
  67. );
  68. /**********************************************************************************/
  69. /*!
  70. @brief Implements the RSADP algorithm, as defined in [PKCS1_2.1] - 6.1.2.
  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_PRIM_Decrypt(
  75. CRYS_RSAUserPrivKey_t *UserPrivKey_ptr, /*!< [in] Pointer to the private key data structure.
  76. The key representation (pair or quintuple) and hence the RSA algorithm
  77. (CRT or not-CRT) is determined by enum value in the structure
  78. ::CRYS_RSA_Build_PrivKey or ::CRYS_RSA_Build_PrivKeyCRT. */
  79. CRYS_RSAPrimeData_t *PrimeData_ptr, /*!< [in] Pointer to a temporary structure containing internal buffers required for
  80. the RSA operation. */
  81. uint8_t *Data_ptr, /*!< [in] Pointer to the data to be decrypted. */
  82. uint16_t DataSize, /*!< [in] The size (in bytes) of input data must be &le; modulus size.
  83. If the size is smaller (not recommendet), then the data will be zero-padded
  84. by the function on left side up to the modulus size and therefore, after further
  85. decrypt operation,its result will contain zero-padding also. If the function is used
  86. for recovering the plain data from result of inverse function (CRYS_RSA_PRIM_Encrypt),
  87. the input size must be equal to modulus size exactly. */
  88. uint8_t *Output_ptr /*!< [out] Pointer to the decrypted data. The buffer size must be &le; the modulus size. */
  89. );
  90. /*!
  91. @brief Implements the RSASP1 algorithm, as defined in [PKCS1_2.1] - 6.2.1, as a call to ::CRYS_RSA_PRIM_Decrypt,
  92. since the signature primitive is identical to the decryption primitive.
  93. */
  94. #define CRYS_RSA_PRIM_Sign CRYS_RSA_PRIM_Decrypt
  95. /*!
  96. @brief Implements the RSAVP1 algorithm, as defined in [PKCS1_2.1] - 6.2.2, as a call to ::CRYS_RSA_PRIM_Encrypt.
  97. */
  98. #define CRYS_RSA_PRIM_Verify CRYS_RSA_PRIM_Encrypt
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. /**
  103. @}
  104. */
  105. #endif