1 /* 2 * Copyright (c) 2021 - 2023, Nordic Semiconductor ASA 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 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 must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 18 * contributors may be used to endorse or promote products derived from this 19 * software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * 33 */ 34 35 #ifndef NRF_802154_AES_CCM_H_ 36 #define NRF_802154_AES_CCM_H_ 37 38 #include <stdbool.h> 39 #include <stdint.h> 40 41 #include "nrf_802154_const.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 #define NRF_802154_AES_CCM_L_VALUE 2 // Annex B3.2 Mode of operation d) 48 #define NRF_802154_AES_CCM_NONCE_SIZE (15 - NRF_802154_AES_CCM_L_VALUE) // Annex B4.1 CCM* mode encryption and authentication transformation b) 49 50 /** 51 * @brief Data necessary for a single AES-CCM* operation. 52 */ 53 typedef struct 54 { 55 uint8_t key[AES_CCM_KEY_SIZE]; ///< Pointer to AES-CCM* key 56 uint8_t * auth_data; ///< Pointer to AES-CCM* authorization data 57 uint64_t auth_data_len; ///< Length of AES-CCM* authorization data 58 uint8_t * plain_text_data; ///< Pointer to AES-CCM* plain text data for encryption and authorization 59 uint8_t plain_text_data_len; ///< Length of plain text data 60 uint8_t nonce[NRF_802154_AES_CCM_NONCE_SIZE]; ///< Pointer to AES-CCM* nonce 61 uint8_t mic_level; ///< Message Integrity Code level 62 uint8_t * raw_frame; ///< Pointer to the buffer that contains the PHR and PSDU of the transmitted frame. 63 } nrf_802154_aes_ccm_data_t; 64 65 /** 66 * @brief Resets AES-CCM* transformation. 67 */ 68 void nrf_802154_aes_ccm_transform_reset(void); 69 70 /** 71 * @brief Prepares AES-CCM* transformation. 72 * 73 * @param[in] p_aes_ccm_data Data to be used for the AES-CCM* transformation. 74 * 75 * @retval true The transformation was prepared successfully and can be performed. 76 * @retval false Provided parameters do not allow for successful transformation. 77 */ 78 bool nrf_802154_aes_ccm_transform_prepare(const nrf_802154_aes_ccm_data_t * p_aes_ccm_data); 79 80 /** 81 * @brief Starts AES-CCM* transformation. 82 * 83 * @note This function should not be called until the transformation is prepared with a call to 84 * @ref nrf_802154_aes_ccm_transform_prepare. Any call to this function that is not paired 85 * with an earlier prepare call will be ignored silently, i.e. the transformation will 86 * not be started at all. 87 * 88 * @param[in] p_frame Pointer to the buffer that contains a frame being transmitted. 89 */ 90 void nrf_802154_aes_ccm_transform_start(uint8_t * p_frame); 91 92 /** 93 * @brief Aborts AES-CCM* transformation. 94 * 95 * @param[in] p_frame Pointer to the buffer that contains a frame being transmitted. 96 */ 97 void nrf_802154_aes_ccm_transform_abort(uint8_t * p_frame); 98 99 #endif // NRF_802154_AES_CCM_H_ 100