sec_aes_ccm.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
  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. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form, except as embedded into a Nordic
  14. * Semiconductor ASA integrated circuit in a product or a software update for
  15. * such product, must reproduce the above copyright notice, this list of
  16. * conditions and the following disclaimer in the documentation and/or other
  17. * materials provided with the distribution.
  18. *
  19. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * 4. This software, with or without modification, must only be used with a
  24. * Nordic Semiconductor ASA integrated circuit.
  25. *
  26. * 5. Any software provided in binary form under this license must not be reverse
  27. * engineered, decompiled, modified and/or disassembled.
  28. *
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  31. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  36. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  39. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. */
  42. #ifndef SEC_AES_CCM_H_INCLUDED
  43. #define SEC_AES_CCM_H_INCLUDED
  44. #include <stdint.h>
  45. /** @file
  46. * This file contains declarations of the AES CCM encryption/decryption routines and necessary types.
  47. * It also contains the declaration of the Security Abstract library initialization routine.
  48. *
  49. * @defgroup sec_aes_ccm Security AES CCM declarations
  50. * @ingroup sec_15_4
  51. * @{
  52. * @brief Module to declare Security AES CCM API
  53. */
  54. /**
  55. * @brief AES CCM Status enumeration.
  56. */
  57. typedef enum
  58. {
  59. AES_CCM_OK, /**< AES CCM operation succeeded. */
  60. AES_ENGINE_FAIL, /**< AES engine failed. */
  61. AES_CCM_FAIL, /**< CCM algorithm failed. */
  62. AES_CCM_AUTH_FAIL /**< CCM authentication failed. */
  63. } sec_aes_ccm_status_t;
  64. /**
  65. * @brief AES CCM request.
  66. *
  67. * @details The AES CCM request primitive is issued by the AES user.
  68. * There are two use cases for the request:
  69. * The first one is to encrypt the user text with some given key.
  70. * The second one is to decrypt the cipher text against the key.
  71. * The encrypted or decrypted data is stored in text_data.
  72. */
  73. typedef struct
  74. {
  75. /** Counted authentication tag. */
  76. uint8_t * mic;
  77. /** Security level identifier. */
  78. uint8_t level;
  79. /** A 128-bit-long string to be used as a key. Each entity must have evidence that access
  80. * to this key is restricted to the entity itself and its intended key sharing group member(s). */
  81. uint8_t * key;
  82. /** A nonce N of 15 - L octets. Within the scope of any encryption key, the nonce value must be unique. */
  83. uint8_t * nonce;
  84. /** An octet string representing plain text data in case of encryption and cipher text data
  85. * in case of decryption. */
  86. uint8_t * text_data;
  87. /** Text data length. */
  88. uint8_t text_data_len;
  89. /** Octet string representing input data to perform authentication. */
  90. uint8_t * auth_data;
  91. /** Auth data length. */
  92. uint8_t auth_data_len;
  93. } sec_aes_ccm_req_t;
  94. /**
  95. * @brief Function for initializing the security abstraction layer.
  96. */
  97. void sec_init(void);
  98. /**
  99. * @brief AES CCM encryption transformation.
  100. *
  101. * @details Performs synchronous encryption of data.
  102. *
  103. * @param req Encryption request structure.
  104. * @return AES_CCM_OK on success, otherwise an implementation defined error.
  105. */
  106. sec_aes_ccm_status_t sec_aes_ccm_enc(sec_aes_ccm_req_t * req);
  107. /**
  108. * @brief AES CCM decryption transformation.
  109. *
  110. * @details Performs synchronous decryption of a cipher.
  111. *
  112. * @param req Decryption request structure.
  113. * @return AES_CCM_OK on success, otherwise an implementation defined error.
  114. */
  115. sec_aes_ccm_status_t sec_aes_ccm_dec(sec_aes_ccm_req_t * req);
  116. /** @} */
  117. #endif /* SEC_AES_CCM_H_INCLUDED */