Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_AES.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Oct 16, 2020
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
10#include <nrf_soc.h>
12
18#define AES_BLOCK_SIZE 16
19
27class AES {
28public:
30 static AES& getInstance() {
31 static AES instance;
32 return instance;
33 }
34
38 void init();
39
55 cs_data_t key, cs_data_t prefix, cs_data_t input, cs_data_t output, cs_buffer_size_t& writtenSize);
56
73 cs_data_t key,
74 cs_data_t nonce,
75 cs_data_t prefix,
76 cs_data_t input,
77 cs_data_t output,
78 cs_buffer_size_t& writtenSize,
79 uint8_t blockCtr = 0);
80
97 cs_data_t key,
98 cs_data_t nonce,
99 cs_data_t input,
100 cs_data_t prefix,
101 cs_data_t output,
102 cs_buffer_size_t& writtenSize,
103 uint8_t blockCtr = 0);
104
105private:
106 // This class is singleton, make constructor private.
108
109 // This class is singleton, deny implementation
110 AES(AES const&);
111
112 // This class is singleton, deny implementation
113 void operator=(AES const&);
114
130 cs_data_t key,
131 cs_data_t nonce,
132 cs_data_t inputPrefix,
133 cs_data_t input,
134 cs_data_t outputPrefix,
135 cs_data_t output,
136 cs_buffer_size_t& writtenSize,
137 uint8_t blockCtr = 0);
138
142 nrf_ecb_hal_data_t _block __attribute__((aligned(4)));
143};
Class that implements AES encryption.
Definition: cs_AES.h:27
nrf_ecb_hal_data_t _block
Struct with key, and single block of encrypted and decypted data.
Definition: cs_AES.h:142
void operator=(AES const &)
AES(AES const &)
cs_ret_code_t encryptCtr(cs_data_t key, cs_data_t nonce, cs_data_t prefix, cs_data_t input, cs_data_t output, cs_buffer_size_t &writtenSize, uint8_t blockCtr=0)
Encrypt data with given key in CTR mode.
cs_ret_code_t ctr(cs_data_t key, cs_data_t nonce, cs_data_t inputPrefix, cs_data_t input, cs_data_t outputPrefix, cs_data_t output, cs_buffer_size_t &writtenSize, uint8_t blockCtr=0)
Encrypt or decrypt data with given key in CTR mode.
cs_ret_code_t decryptCtr(cs_data_t key, cs_data_t nonce, cs_data_t input, cs_data_t prefix, cs_data_t output, cs_buffer_size_t &writtenSize, uint8_t blockCtr=0)
Decrypt data with given key in CTR mode.
cs_ret_code_t encryptEcb(cs_data_t key, cs_data_t prefix, cs_data_t input, cs_data_t output, cs_buffer_size_t &writtenSize)
Encrypt data with given key in ECB mode.
void init()
Initialize the class, reads from State.
static AES & getInstance()
Use static variant of singleton, no dynamic memory allocation.
Definition: cs_AES.h:30
uint16_t cs_buffer_size_t
Definition: cs_Typedefs.h:20
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
Packets (structs) that are used internally in the firmware, and can be changed freely.
Definition: cs_PacketsInternal.h:27