Contiki-NG
cbc-mac.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538-aes
33  * @{
34  *
35  * \defgroup cc2538-cbc-mac cc2538 AES-CBC-MAC
36  *
37  * Driver for the cc2538 AES-CBC-MAC mode of the security core
38  * @{
39  *
40  * \file
41  * Header file for the cc2538 AES-CBC-MAC driver
42  */
43 #ifndef CBC_MAC_H_
44 #define CBC_MAC_H_
45 
46 #include "contiki.h"
47 #include "dev/aes.h"
48 
49 #include <stdbool.h>
50 #include <stdint.h>
51 /*---------------------------------------------------------------------------*/
52 /** \name AES-CBC-MAC constants
53  * @{
54  */
55 #define CBC_MAC_MAC_LEN AES_TAG_LEN
56 /** @} */
57 /*---------------------------------------------------------------------------*/
58 /** \name AES-CBC-MAC functions
59  * @{
60  */
61 
62 /** \brief Starts a CBC-MAC authentication operation
63  * \param key_area Area in Key RAM where the key is stored (0 to
64  * \c AES_KEY_AREAS - 1)
65  * \param mdata Pointer to message to authenticate in SRAM
66  * \param mdata_len Length of message to authenticate in octets
67  * \param process Process to be polled upon completion of the operation, or
68  * \c NULL
69  * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CBC-MAC error code
70  * \warning CBC-MAC is not secure for variable-length messages. There are a few
71  * workarounds that can be implemented by the caller, like prepending the
72  * message length to the first block of the message before passing it.
73  */
74 uint8_t cbc_mac_auth_start(uint8_t key_area, const void *mdata,
75  uint16_t mdata_len, struct process *process);
76 
77 /** \brief Checks the status of the CBC-MAC authentication operation
78  * \retval false Result not yet available, and no error occurred
79  * \retval true Result available, or error occurred
80  */
81 #define cbc_mac_auth_check_status aes_auth_crypt_check_status
82 
83 /** \brief Gets the result of the CBC-MAC authentication operation
84  * \param mac_in Pointer to 128-bit input MAC, or \c NULL
85  * \param mac_out Pointer to 128-bit output MAC, or \c NULL
86  * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CBC-MAC error code
87  * \note This function must be called only after \c cbc_mac_auth_start().
88  */
89 uint8_t cbc_mac_auth_get_result(const void *mac_in, void *mac_out);
90 
91 /** @} */
92 
93 #endif /* CBC_MAC_H_ */
94 
95 /**
96  * @}
97  * @}
98  */
uint8_t cbc_mac_auth_get_result(const void *mac_in, void *mac_out)
Gets the result of the CBC-MAC authentication operation.
Definition: cbc-mac.c:66
Header file for the cc2538 AES driver.
uint8_t cbc_mac_auth_start(uint8_t key_area, const void *mdata, uint16_t mdata_len, struct process *process)
Starts a CBC-MAC authentication operation.
Definition: cbc-mac.c:46