crys_hkdf.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_HKDF_H
  35. #define CRYS_HKDF_H
  36. #include "crys_hash.h"
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. /*!
  42. @file
  43. @brief This module defines the API that supports HMAC Key derivation function as defined by RFC5869.
  44. @defgroup crys_hkdf CryptoCell HMAC Key Derivation APIs
  45. @{
  46. @ingroup cryptocell_api
  47. */
  48. /*! HKDF maximal key size in words. */
  49. #define CRYS_HKDF_MAX_HASH_KEY_SIZE_IN_BYTES 512
  50. /*! HKDF maximal HASH digest size in bytes. */
  51. #define CRYS_HKDF_MAX_HASH_DIGEST_SIZE_IN_BYTES CRYS_HASH_SHA512_DIGEST_SIZE_IN_BYTES
  52. /************************ Defines ******************************/
  53. /************************ Enums ********************************/
  54. /*! Enum defining HKDF HASH available modes. */
  55. typedef enum
  56. {
  57. /*! SHA1 mode. */
  58. CRYS_HKDF_HASH_SHA1_mode = 0,
  59. /*! SHA224 mode. */
  60. CRYS_HKDF_HASH_SHA224_mode = 1,
  61. /*! SHA256 mode. */
  62. CRYS_HKDF_HASH_SHA256_mode = 2,
  63. /*! SHA384 mode. */
  64. CRYS_HKDF_HASH_SHA384_mode = 3,
  65. /*! SHA512 mode. */
  66. CRYS_HKDF_HASH_SHA512_mode = 4,
  67. /*! Maximal number of HASH modes. */
  68. CRYS_HKDF_HASH_NumOfModes,
  69. /*! Reserved */
  70. CRYS_HKDF_HASH_OpModeLast = 0x7FFFFFFF,
  71. }CRYS_HKDF_HASH_OpMode_t;
  72. /************************ Typedefs ****************************/
  73. /************************ Structs ******************************/
  74. /************************ Public Variables **********************/
  75. /************************ Public Functions **********************/
  76. /****************************************************************/
  77. /*********************************************************************************************************/
  78. /*!
  79. @brief CRYS_HKDF_KeyDerivFunc performs the HMAC-based key derivation, according to RFC5869
  80. @return CRYS_OK on success.
  81. @return A non-zero value on failure as defined crys_kdf_error.h, crys_hash_error or crys_hmac_error.h
  82. */
  83. CEXPORT_C CRYSError_t CRYS_HKDF_KeyDerivFunc(
  84. CRYS_HKDF_HASH_OpMode_t HKDFhashMode, /*!< [in] The HKDF identifier of hash function to be used. */
  85. uint8_t* Salt_ptr, /*!< [in] A pointer to a non secret random value. can be NULL. */
  86. size_t SaltLen, /*!< [in] The size of the salt_ptr. */
  87. uint8_t* Ikm_ptr, /*!< [in] A pointer to a input key message. */
  88. uint32_t IkmLen, /*!< [in] The size of the input key message */
  89. uint8_t* Info, /*!< [in] A pointer to an optional context and application specific information. can be NULL */
  90. uint32_t InfoLen, /*!< [in] The size of the info. */
  91. uint8_t* Okm, /*!< [in] A pointer to a output key material. */
  92. uint32_t OkmLen, /*!< [in] The size of the output key material. */
  93. SaSiBool IsStrongKey /*!< [in] if TRUE , then no need to perform the extraction phase. */
  94. );
  95. #ifdef __cplusplus
  96. }
  97. #endif
  98. /**
  99. @}
  100. */
  101. #endif