Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_RC5.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 <protocol/cs_Packets.h>
11
12#define RC5_ROUNDS 12
13#define RC5_NUM_SUBKEYS (2 * (RC5_ROUNDS + 1)) // t = 2(r+1) - the number of round subkeys required.
14#define RC5_KEYLEN 16
15#define RC5_BLOCK_SIZE 4 // Size in bytes of an RC5 block.
16
23class RC5 {
24public:
26 static RC5& getInstance() {
27 static RC5 instance;
28 return instance;
29 }
30
34 void init();
35
44 bool decrypt(uint16_t* inBuf, uint16_t inBufSize, uint16_t* outBuf, uint16_t outBufSize);
45
46private:
47 // This class is singleton, make constructor private.
48 RC5();
49
50 // This class is singleton, deny implementation
51 RC5(RC5 const&);
52
53 // This class is singleton, deny implementation
54 void operator=(RC5 const&);
55
60
64 bool initKey(EncryptionAccessLevel accessLevel);
65
69 bool prepareKey(uint8_t* key, uint8_t keyLength);
70};
Class that implements RC5 encryption.
Definition: cs_RC5.h:23
uint16_t _subKeys[RC5_NUM_SUBKEYS]
The round subkey words.
Definition: cs_RC5.h:59
RC5(RC5 const &)
bool prepareKey(uint8_t *key, uint8_t keyLength)
Expands key into round subkey words, which are cached.
void operator=(RC5 const &)
static RC5 & getInstance()
Use static variant of singleton, no dynamic memory allocation.
Definition: cs_RC5.h:26
bool decrypt(uint16_t *inBuf, uint16_t inBufSize, uint16_t *outBuf, uint16_t outBufSize)
Decrypt data with RC5.
bool initKey(EncryptionAccessLevel accessLevel)
Expands the key of given access level.
void init()
Initialize the class, reads from State.
EncryptionAccessLevel
Packets (structs) that are used over the air, over uart, or stored in flash.
Definition: cs_Packets.h:36
#define RC5_NUM_SUBKEYS
Definition: cs_RC5.h:13