Loading...
Searching...
No Matches
ieee802154_security.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Otto-von-Guericke-Universität Magdeburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
30#ifndef NET_IEEE802154_SECURITY_H
31#define NET_IEEE802154_SECURITY_H
32
33#include <stdint.h>
34#include "ieee802154.h"
35#include "crypto/ciphers.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
45
65 const uint8_t *key,
66 uint8_t key_size);
76 void (*cbc)(const ieee802154_sec_dev_t *dev,
77 uint8_t *cipher,
78 uint8_t *iv,
79 const uint8_t *plain,
80 uint8_t nblocks);
89 void (*ecb)(const ieee802154_sec_dev_t *dev,
90 uint8_t *cipher,
91 const uint8_t *plain,
92 uint8_t nblocks);
94
108
109#if !defined(CONFIG_IEEE802154_SEC_DEFAULT_KEY) || defined(DOXYGEN)
116#define CONFIG_IEEE802154_SEC_DEFAULT_KEY "pizza_margherita"
117#endif
118
122#define IEEE802154_SEC_KEY_LENGTH (16U)
123
127#define IEEE802154_SEC_BLOCK_SIZE (16U)
128
132#define IEEE802154_SEC_MAX_AUX_HDR_LEN (14U)
133
137#define IEEE802154_SEC_MAX_MAC_SIZE (16U)
138
142#define IEEE802154_SEC_SCF_SECLEVEL_MASK (0x07)
143
147#define IEEE802154_SEC_SCF_SECLEVEL_SHIFT (0)
148
152#define IEEE802154_SEC_SCF_KEYMODE_MASK (0x18)
153
157#define IEEE802154_SEC_SCF_KEYMODE_SHIFT (3)
158
187
223
234
270
274typedef struct __attribute__((packed)) {
292 uint8_t scf;
296 uint32_t fc;
300 uint8_t key_id[];
302
306typedef struct __attribute__((packed)) {
310 uint8_t key_index;
312
316typedef struct __attribute__((packed)) {
320 uint8_t key_source[4];
324 uint8_t key_index;
326
330typedef struct __attribute__((packed)) {
334 uint8_t key_source[IEEE802154_LONG_ADDRESS_LEN];
338 uint8_t key_index;
340
344typedef struct __attribute__((packed)) {
358
362typedef struct __attribute__((packed)) {
366 uint8_t flags;
375 uint16_t counter;
377
384
403 const uint8_t *header, uint8_t *header_size,
404 uint8_t *payload, uint16_t payload_size,
405 uint8_t *mic, uint8_t *mic_size,
406 const uint8_t *src_address);
407
427 uint16_t frame_size,
428 uint8_t *header, uint8_t *header_size,
429 uint8_t **payload, uint16_t *payload_size,
430 uint8_t **mic, uint8_t *mic_size,
431 const uint8_t *src_address);
432
437
438#ifdef __cplusplus
439}
440#endif
441
442#endif /* NET_IEEE802154_SECURITY_H */
Headers for the packet encryption class.
#define IEEE802154_LONG_ADDRESS_LEN
long address (EUI-64)
Definition ieee802154.h:45
int ieee802154_sec_encrypt_frame(ieee802154_sec_context_t *ctx, const uint8_t *header, uint8_t *header_size, uint8_t *payload, uint16_t payload_size, uint8_t *mic, uint8_t *mic_size, const uint8_t *src_address)
Encrypt IEEE 802.15.4 frame according to ctx.
ieee802154_sec_scf_seclevel_t
Security levels.
ieee802154_sec_error_t
IEEE 802.15.4 security error codes.
ieee802154_sec_scf_keymode_t
Key identifier modes.
struct ieee802154_radio_cipher_ops ieee802154_radio_cipher_ops_t
Struct of security operations.
void ieee802154_sec_init(ieee802154_sec_context_t *ctx)
Initialize IEEE 802.15.4 security context with default values.
int ieee802154_sec_decrypt_frame(ieee802154_sec_context_t *ctx, uint16_t frame_size, uint8_t *header, uint8_t *header_size, uint8_t **payload, uint16_t *payload_size, uint8_t **mic, uint8_t *mic_size, const uint8_t *src_address)
Decrypt IEEE 802.15.4 frame according to ctx.
struct ieee802154_sec_context ieee802154_sec_context_t
Struct to hold IEEE 802.15.4 security information.
@ IEEE802154_SEC_SCF_SECLEVEL_MIC32
32 bit MIC
@ IEEE802154_SEC_SCF_SECLEVEL_ENC_MIC32
enc.
@ IEEE802154_SEC_SCF_SECLEVEL_MIC128
128 bit MIC
@ IEEE802154_SEC_SCF_SECLEVEL_MIC64
64 bit MIC
@ IEEE802154_SEC_SCF_SECLEVEL_ENC_MIC64
enc.
@ IEEE802154_SEC_SCF_SECLEVEL_ENC_MIC128
enc.
@ IEEE802154_SEC_SCF_SECLEVEL_NONE
no security
@ IEEE802154_SEC_SCF_SECLEVEL_ENC
encryption
@ IEEE802154_SEC_OK
Everything went fine.
@ IEEE802154_SEC_UNSUPORTED
Unsupported operation.
@ IEEE802154_SEC_MAC_CHECK_FAILURE
The computet MAC did not match.
@ IEEE802154_SEC_FRAME_COUNTER_OVERFLOW
The requested operation would let the frame counter overflow.
@ IEEE802154_SEC_NO_KEY
Could not find the key to perform a requested cipher operation.
@ IEEE802154_SEC_SCF_KEYMODE_IMPLICIT
Key is determined implicitly.
@ IEEE802154_SEC_SCF_KEYMODE_INDEX
Key is determined from key index.
@ IEEE802154_SEC_SCF_KEYMODE_SHORT_INDEX
Key is determined from 4 byte key source and key index.
@ IEEE802154_SEC_SCF_KEYMODE_HW_INDEX
Key is determined from 8 byte key source and key index.
basic struct for using block ciphers contains the cipher interface and the context
Definition ciphers.h:119
Struct of security operations.
void(* ecb)(const ieee802154_sec_dev_t *dev, uint8_t *cipher, const uint8_t *plain, uint8_t nblocks)
Function type to perform ECB encryption.
void(* cbc)(const ieee802154_sec_dev_t *dev, uint8_t *cipher, uint8_t *iv, const uint8_t *plain, uint8_t nblocks)
Function type to compute CBC-MAC.
void(* set_key)(ieee802154_sec_dev_t *dev, const uint8_t *key, uint8_t key_size)
Function to set the encryption key for the next cipher operation.
Content of key_source if key mode is IEEE802154_SEC_SCF_KEYMODE_INDEX.
uint8_t key_index
Key index of key from originator, defined by key source.
Content of key_source if key mode is IEEE802154_SEC_SCF_KEYMODE_SHORT_INDEX.
uint8_t key_index
Key index of key from originator, defined by key source.
Content of key_source if key mode is IEEE802154_SEC_SCF_KEYMODE_HW_INDEX.
uint8_t key_index
Key index of key from originator, defined by key source.
IEEE 802.15.4 auxiliary security header.
uint8_t scf
Security Control field (SCF)
uint32_t fc
frame counter
Format of 16 byte input block of CCM.
ieee802154_sec_ccm_nonce_t nonce
Nonce (Number that is only used once)
uint16_t counter
Either the length of the actual message (for CBC-MAC) or a block counter (for CTR)
Format of 13 byte nonce.
uint32_t frame_counter
Frame counter.
uint8_t security_level
One of IEEE802154_SEC_SCF_SECLEVEL_*.
Struct to hold IEEE 802.15.4 security information.
ieee802154_sec_dev_t dev
802.15.4 security dev
uint8_t key_id_mode
Key mode IEEE802154_SEC_SCF_KEYMODE_*.
uint32_t frame_counter
Own frame counter.
cipher_t cipher
Cipher context with AES128 interface and key storage.
uint8_t key_source[IEEE802154_LONG_ADDRESS_LEN]
Key source.
uint8_t security_level
Security level IEEE802154_SEC_SCF_SECLEVEL_*.
IEEE 802.15.4 security device descriptor.
const struct ieee802154_radio_cipher_ops * cipher_ops
Pointer to the operations of the device.
void * ctx
Pointer to the context of the device.
IEEE 802.15.4 header definitions.