nrf_crypto_aead_shared.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Copyright (c) 2018 - 2019, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF_CRYPTO_AEAD_SHARED_H__
  41. #define NRF_CRYPTO_AEAD_SHARED_H__
  42. /** @file
  43. *
  44. * @defgroup nrf_crypto_aead_shared AEAD related functions
  45. * @{
  46. * @ingroup nrf_crypto
  47. *
  48. * @brief Provides AEAD related functionality through nrf_crypto.
  49. */
  50. #include <stdint.h>
  51. #include "nrf_crypto_types.h"
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**@internal @brief Magic value to signal that the nrf_crypto_hash context structure is initialized.
  56. */
  57. #define NRF_CRYPTO_AEAD_INIT_MAGIC_VALUE (0x44414541) // ASCII "AEAD"
  58. #define NRF_CRYPTO_AES_CCM_STAR_MAC_BITMASK (0x1C) /* [0, 4, 8, 16] allowed MAC size in CCM mode */
  59. #define NRF_CRYPTO_AES_CCM_MAC_MIN (4u) /* MAC min value in CCM mode */
  60. #define NRF_CRYPTO_AES_CCM_MAC_MAX (16u) /* MAC max value in CCM mode */
  61. #define NRF_CRYPTO_AES_GCM_MAC_MIN (4u) /* MAC min value in GCM mode */
  62. #define NRF_CRYPTO_AES_GCM_MAC_MAX (16u) /* MAC max value in GCM mode */
  63. #define NRF_CRYPTO_AES_CCM_NONCE_SIZE_MIN (7u) /* [7...13] allowed nonce size in CCM mode */
  64. #define NRF_CRYPTO_AES_CCM_NONCE_SIZE_MAX (13u) /* [7...13] allowed nonce size in CCM mode */
  65. #define NRF_CRYPTO_AES_CCM_STAR_NONCE_SIZE (13u) /* [13] allowed nonce size in CCM* mode */
  66. #define NRF_CRYPTO_CHACHA_POLY_NONCE_SIZE (12u) /* [12] allowed nonce size in chacha-poly mode */
  67. #define NRF_CRYPTO_CHACHA_POLY_MAC_SIZE (16u) /* [16] allowed MAC size in chacha-poly mode */
  68. /**@internal @brief Enumeration of supported modes of operation in nrf_crypto_aead.
  69. */
  70. typedef enum
  71. {
  72. NRF_CRYPTO_AEAD_MODE_AES_CCM, // supported by: MBEDTLS & CC310
  73. NRF_CRYPTO_AEAD_MODE_AES_CCM_STAR, // supported by: CC310
  74. NRF_CRYPTO_AEAD_MODE_AES_EAX, // supported by: CIFRA
  75. NRF_CRYPTO_AEAD_MODE_AES_GCM, // supported by: MBEDTLS
  76. NRF_CRYPTO_AEAD_MODE_CHACHA_POLY // supported by: CC310 & OBERON
  77. } nrf_crypto_aead_mode_t;
  78. /**@internal @brief Type declaration to perform AEAD initialization in the nrf_crypto backend.
  79. *
  80. * This is internal API. See @ref nrf_crypto_aead_init for documentation.
  81. */
  82. typedef ret_code_t (*aead_init_fn_t)(void * const p_context, uint8_t * p_key);
  83. /**@internal @brief Type declaration to perform AEAD uninitialization in the nrf_crypto backend.
  84. *
  85. * This is internal API. See @ref nrf_crypto_aead_uninit for documentation.
  86. */
  87. typedef ret_code_t (*aead_uninit_fn_t)(void * const p_context);
  88. /**@internal @brief Type declaration to perform AEAD encryption in nrf_crypto backend.
  89. *
  90. * This is internal API. See @ref nrf_crypto_aead_crypt for documentation.
  91. */
  92. typedef ret_code_t (*aead_crypt_fn_t)(void * const p_context,
  93. nrf_crypto_operation_t operation,
  94. uint8_t * p_nonce,
  95. uint8_t nonce_size,
  96. uint8_t * p_adata,
  97. size_t adata_size,
  98. uint8_t * p_data_in,
  99. size_t data_in_size,
  100. uint8_t * p_data_out,
  101. uint8_t * p_mac,
  102. uint8_t mac_size);
  103. /**@internal @brief Type declaration for the nrf_crypto_aead info structure.
  104. *
  105. * @details This structure contains the calling interface and any metadata required
  106. * to call the nrf_crypto_aead API functions.
  107. */
  108. typedef struct
  109. {
  110. nrf_crypto_aead_mode_t const mode;
  111. nrf_crypto_key_size_id_t const key_size;
  112. aead_init_fn_t const init_fn;
  113. aead_uninit_fn_t const uninit_fn;
  114. aead_crypt_fn_t const crypt_fn;
  115. } nrf_crypto_aead_info_t;
  116. /**@internal @brief Type declaration of internal representation of an AEAD context structure.
  117. *
  118. * @details This is an internal type that should not be used directly.
  119. */
  120. typedef struct
  121. {
  122. uint32_t init_value;
  123. nrf_crypto_aead_info_t const * p_info;
  124. } nrf_crypto_aead_internal_context_t;
  125. /** @} */
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif // #ifndef NRF_CRYPTO_AEAD_SHARED_H__