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
9#pragma once
10
31
32#include <stdint.h>
33#include "ieee802154.h"
34#include "crypto/ciphers.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
44
64 const uint8_t *key,
65 uint8_t key_size);
75 void (*cbc)(const ieee802154_sec_dev_t *dev,
76 uint8_t *cipher,
77 uint8_t *iv,
78 const uint8_t *plain,
79 uint8_t nblocks);
88 void (*ecb)(const ieee802154_sec_dev_t *dev,
89 uint8_t *cipher,
90 const uint8_t *plain,
91 uint8_t nblocks);
93
107
108#if !defined(CONFIG_IEEE802154_SEC_DEFAULT_KEY) || defined(DOXYGEN)
115#define CONFIG_IEEE802154_SEC_DEFAULT_KEY "pizza_margherita"
116#endif
117
121#define IEEE802154_SEC_KEY_LENGTH (16U)
122
126#define IEEE802154_SEC_BLOCK_SIZE (16U)
127
131#define IEEE802154_SEC_MAX_AUX_HDR_LEN (14U)
132
136#define IEEE802154_SEC_MAX_MAC_SIZE (16U)
137
141#define IEEE802154_SEC_SCF_SECLEVEL_MASK (0x07)
142
146#define IEEE802154_SEC_SCF_SECLEVEL_SHIFT (0)
147
151#define IEEE802154_SEC_SCF_KEYMODE_MASK (0x18)
152
156#define IEEE802154_SEC_SCF_KEYMODE_SHIFT (3)
157
186
222
233
269
273typedef struct __attribute__((packed)) {
291 uint8_t scf;
295 uint32_t fc;
299 uint8_t key_id[];
301
305typedef struct __attribute__((packed)) {
309 uint8_t key_index;
311
315typedef struct __attribute__((packed)) {
319 uint8_t key_source[4];
323 uint8_t key_index;
325
329typedef struct __attribute__((packed)) {
337 uint8_t key_index;
339
343typedef struct __attribute__((packed)) {
357
361typedef struct __attribute__((packed)) {
365 uint8_t flags;
374 uint16_t counter;
376
383
402 const uint8_t *header, uint8_t *header_size,
403 uint8_t *payload, uint16_t payload_size,
404 uint8_t *mic, uint8_t *mic_size,
405 const uint8_t *src_address);
406
426 uint16_t frame_size,
427 uint8_t *header, uint8_t *header_size,
428 uint8_t **payload, uint16_t *payload_size,
429 uint8_t **mic, uint8_t *mic_size,
430 const uint8_t *src_address);
431
436
437#ifdef __cplusplus
438}
439#endif
440
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.
struct ieee802154_sec_dev ieee802154_sec_dev_t
Forward declaration of an IEEE 802.15.4 abstract security device.
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:118
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_source[4]
macPANId concatenated with macShortAddress
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.
uint8_t key_source[IEEE802154_LONG_ADDRESS_LEN]
macExtendedAddress
IEEE 802.15.4 auxiliary security header.
uint8_t scf
Security Control field (SCF)
uint32_t fc
frame counter
uint8_t key_id[]
key identifier (0 - 9 bytes) according to key id.
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.
uint8_t src_addr[IEEE802154_LONG_ADDRESS_LEN]
Source long address.
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.