Contiki-NG
ccm.h
Go to the documentation of this file.
1/*
2 * Original file:
3 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
4 * All rights reserved.
5 *
6 * Port to Contiki:
7 * Copyright (c) 2013, ADVANSEE - http://www.advansee.com/
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34 * OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36/**
37 * \addtogroup cc2538-aes
38 * @{
39 *
40 * \defgroup cc2538-ccm cc2538 AES-CCM
41 *
42 * Driver for the cc2538 AES-CCM mode of the security core
43 * @{
44 *
45 * \file
46 * Header file for the cc2538 AES-CCM driver
47 */
48#ifndef CCM_H_
49#define CCM_H_
50
51#include "contiki.h"
52#include "dev/aes.h"
53
54#include <stdbool.h>
55#include <stdint.h>
56/*---------------------------------------------------------------------------*/
57/** \name AES-CCM constants
58 * @{
59 */
60#define CCM_FLAGS_LEN 1
61#define CCM_NONCE_LEN_LEN (AES_IV_LEN - CCM_FLAGS_LEN)
62#define CCM_MIC_MAX_LEN AES_TAG_LEN
63/** @} */
64/*---------------------------------------------------------------------------*/
65/** \name AES-CCM functions
66 * @{
67 */
68
69/** \brief Starts a CCM authentication and encryption operation
70 * \param len_len Number of octets in length field (2, 4, or 8)
71 * \param key_area Area in Key RAM where the key is stored (0 to
72 * \c AES_KEY_AREAS - 1)
73 * \param nonce Pointer to nonce (\c CCM_NONCE_LEN_LEN - \p len_len octets)
74 * \param adata Pointer to additional authenticated data in SRAM, or \c NULL
75 * \param adata_len Length of additional authenticated data in octets, or \c 0
76 * \param pdata Pointer to message to authenticate and encrypt in SRAM, or
77 * \c NULL
78 * \param pdata_len Length of message to authenticate and encrypt in octets, or
79 * \c 0
80 * \param cdata Pointer to encrypted message in SRAM (may be \p pdata), or
81 * \c NULL
82 * \param mic_len Number of octets in authentication field (even value between 0
83 * and \c CCM_MIC_MAX_LEN)
84 * \param process Process to be polled upon completion of the operation, or
85 * \c NULL
86 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code
87 */
88uint8_t ccm_auth_encrypt_start(uint8_t len_len, uint8_t key_area,
89 const void *nonce, const void *adata,
90 uint16_t adata_len, const void *pdata,
91 uint16_t pdata_len, void *cdata, uint8_t mic_len,
92 struct process *process);
93
94/** \brief Checks the status of the CCM authentication and encryption operation
95 * \retval false Result not yet available, and no error occurred
96 * \retval true Result available, or error occurred
97 */
98#define ccm_auth_encrypt_check_status aes_auth_crypt_check_status
99
100/** \brief Gets the result of the CCM authentication and encryption operation
101 * \param mic Pointer to authentication field, or \c NULL
102 * \param mic_len Number of octets in authentication field (even value between 0
103 * and \c CCM_MIC_MAX_LEN)
104 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code
105 * \note This function must be called only after \c ccm_auth_encrypt_start().
106 */
107uint8_t ccm_auth_encrypt_get_result(void *mic, uint8_t mic_len);
108
109/** \brief Starts a CCM authentication checking and decryption operation
110 * \param len_len Number of octets in length field (2, 4, or 8)
111 * \param key_area Area in Key RAM where the key is stored (0 to
112 * \c AES_KEY_AREAS - 1)
113 * \param nonce Pointer to nonce (\c CCM_NONCE_LEN_LEN - \p len_len octets)
114 * \param adata Pointer to additional authenticated data in SRAM, or \c NULL
115 * \param adata_len Length of additional authenticated data in octets, or \c 0
116 * \param cdata Pointer to encrypted and authenticated message in SRAM
117 * \param cdata_len Length of encrypted and authenticated message in octets
118 * \param pdata Pointer to decrypted message in SRAM (may be \p cdata), or
119 * \c NULL
120 * \param mic_len Number of octets in authentication field (even value between 0
121 * and \c CCM_MIC_MAX_LEN)
122 * \param process Process to be polled upon completion of the operation, or
123 * \c NULL
124 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code
125 */
126uint8_t ccm_auth_decrypt_start(uint8_t len_len, uint8_t key_area,
127 const void *nonce, const void *adata,
128 uint16_t adata_len, const void *cdata,
129 uint16_t cdata_len, void *pdata, uint8_t mic_len,
130 struct process *process);
131
132/** \brief Checks the status of the CCM authentication checking and decryption
133 * operation
134 * \retval false Result not yet available, and no error occurred
135 * \retval true Result available, or error occurred
136 */
137#define ccm_auth_decrypt_check_status aes_auth_crypt_check_status
138
139/** \brief Gets the result of the CCM authentication checking and decryption
140 * operation
141 * \param cdata Pointer to encrypted and authenticated message
142 * \param cdata_len Length of encrypted and authenticated message in octets
143 * \param mic Pointer to authentication field, or \c NULL
144 * \param mic_len Number of octets in authentication field (even value between 0
145 * and \c CCM_MIC_MAX_LEN)
146 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/CCM error code
147 * \note This function must be called only after \c ccm_auth_decrypt_start().
148 */
149uint8_t ccm_auth_decrypt_get_result(const void *cdata, uint16_t cdata_len,
150 void *mic, uint8_t mic_len);
151
152/** @} */
153
154#endif /* CCM_H_ */
155
156/**
157 * @}
158 * @}
159 */
Header file for the cc2538 AES driver.
uint8_t ccm_auth_decrypt_get_result(const void *cdata, uint16_t cdata_len, void *mic, uint8_t mic_len)
Gets the result of the CCM authentication checking and decryption operation.
uint8_t ccm_auth_encrypt_start(uint8_t len_len, uint8_t key_area, const void *nonce, const void *adata, uint16_t adata_len, const void *pdata, uint16_t pdata_len, void *cdata, uint8_t mic_len, struct process *process)
Starts a CCM authentication and encryption operation.
Definition: ccm.c:110
uint8_t ccm_auth_decrypt_start(uint8_t len_len, uint8_t key_area, const void *nonce, const void *adata, uint16_t adata_len, const void *cdata, uint16_t cdata_len, void *pdata, uint8_t mic_len, struct process *process)
Starts a CCM authentication checking and decryption operation.
Definition: ccm.c:126
uint8_t ccm_auth_encrypt_get_result(void *mic, uint8_t mic_len)
Gets the result of the CCM authentication and encryption operation.
Definition: ccm.c:120