Contiki-NG
gcm.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, 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-gcm cc2538 AES-GCM
36 *
37 * Driver for the cc2538 AES-GCM mode of the security core
38 * @{
39 *
40 * \file
41 * Header file for the cc2538 AES-GCM driver
42 */
43#ifndef GCM_H_
44#define GCM_H_
45
46#include "contiki.h"
47#include "dev/aes.h"
48
49#include <stdbool.h>
50#include <stdint.h>
51/*---------------------------------------------------------------------------*/
52/** \name AES-GCM constants
53 * @{
54 */
55#define GCM_IV_LEN (96 / 8)
56#define GCM_TAG_LEN AES_TAG_LEN
57/** @} */
58/*---------------------------------------------------------------------------*/
59/** \name AES-GCM functions
60 * @{
61 */
62
63/** \brief Starts a GCM authentication and encryption operation
64 * \param key_area Area in Key RAM where the key is stored (0 to
65 * \c AES_KEY_AREAS - 1)
66 * \param iv Pointer to 96-bit initialization vector
67 * \param adata Pointer to additional authenticated data in SRAM, or \c NULL
68 * \param adata_len Length of additional authenticated data in octets, or \c 0
69 * \param pdata Pointer to message to authenticate and encrypt in SRAM, or
70 * \c NULL
71 * \param pdata_len Length of message to authenticate and encrypt in octets, or
72 * \c 0
73 * \param cdata Pointer to encrypted message in SRAM (may be \p pdata), or
74 * \c NULL
75 * \param process Process to be polled upon completion of the operation, or
76 * \c NULL
77 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
78 */
79uint8_t gcm_auth_encrypt_start(uint8_t key_area, const void *iv,
80 const void *adata, uint16_t adata_len,
81 const void *pdata, uint16_t pdata_len,
82 void *cdata, struct process *process);
83
84/** \brief Checks the status of the GCM authentication and encryption operation
85 * \retval false Result not yet available, and no error occurred
86 * \retval true Result available, or error occurred
87 */
88#define gcm_auth_encrypt_check_status aes_auth_crypt_check_status
89
90/** \brief Gets the result of the GCM authentication and encryption operation
91 * \param tag Pointer to 128-bit authentication tag, or \c NULL
92 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
93 * \note This function must be called only after \c gcm_auth_encrypt_start().
94 */
95uint8_t gcm_auth_encrypt_get_result(void *tag);
96
97/** \brief Starts a GCM authentication checking and decryption operation
98 * \param key_area Area in Key RAM where the key is stored (0 to
99 * \c AES_KEY_AREAS - 1)
100 * \param iv Pointer to 96-bit initialization vector
101 * \param adata Pointer to additional authenticated data in SRAM, or \c NULL
102 * \param adata_len Length of additional authenticated data in octets, or \c 0
103 * \param cdata Pointer to encrypted message in SRAM, or \c NULL
104 * \param cdata_len Length of encrypted message in octets, or \c 0
105 * \param pdata Pointer to decrypted message in SRAM (may be \p cdata), or
106 * \c NULL
107 * \param process Process to be polled upon completion of the operation, or
108 * \c NULL
109 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
110 */
111uint8_t gcm_auth_decrypt_start(uint8_t key_area, const void *iv,
112 const void *adata, uint16_t adata_len,
113 const void *cdata, uint16_t cdata_len,
114 void *pdata, struct process *process);
115
116/** \brief Checks the status of the GCM authentication checking and decryption
117 * operation
118 * \retval false Result not yet available, and no error occurred
119 * \retval true Result available, or error occurred
120 */
121#define gcm_auth_decrypt_check_status aes_auth_crypt_check_status
122
123/** \brief Gets the result of the GCM authentication checking and decryption
124 * operation
125 * \param tag_in Pointer to 128-bit input authentication tag, or \c NULL
126 * \param tag_out Pointer to 128-bit output authentication tag, or \c NULL
127 * \return \c CRYPTO_SUCCESS if successful, or CRYPTO/AES/GCM error code
128 * \note This function must be called only after \c gcm_auth_decrypt_start().
129 */
130uint8_t gcm_auth_decrypt_get_result(const void *tag_in, void *tag_out);
131
132/** @} */
133
134#endif /* GCM_H_ */
135
136/**
137 * @}
138 * @}
139 */
Header file for the cc2538 AES driver.
uint8_t gcm_auth_encrypt_start(uint8_t key_area, const void *iv, const void *adata, uint16_t adata_len, const void *pdata, uint16_t pdata_len, void *cdata, struct process *process)
Starts a GCM authentication and encryption operation.
Definition: gcm.c:98
uint8_t gcm_auth_decrypt_get_result(const void *tag_in, void *tag_out)
Gets the result of the GCM authentication checking and decryption operation.
uint8_t gcm_auth_encrypt_get_result(void *tag)
Gets the result of the GCM authentication and encryption operation.
Definition: gcm.c:107
uint8_t gcm_auth_decrypt_start(uint8_t key_area, const void *iv, const void *adata, uint16_t adata_len, const void *cdata, uint16_t cdata_len, void *pdata, struct process *process)
Starts a GCM authentication checking and decryption operation.
Definition: gcm.c:113