CycloneBOOT 2.6.6
Secure Bootloader for ARM Cortex-M MCU
Loading...
Searching...
No Matches
cipher.h
Go to the documentation of this file.
1
31#ifndef _CIPHER_H
32#define _CIPHER_H
33
34// Dependencies
35#include "cipher/cipher_algorithms.h"
36#include "cipher_modes/cipher_modes.h"
37#include "core/cboot_error.h"
38#include "boot_config.h"
39
40#ifndef CIPHER_SUPPORT
41#define CIPHER_SUPPORT DISABLED
42#elif ((CIPHER_SUPPORT != ENABLED) && (CIPHER_SUPPORT != DISABLED))
43#error CIPHER_SUPPORT parameter is not valid!
44#endif
45
46// Magic number used to check cipher key
47#define CIPHER_MAGIC_NUMBER "5ef41578fcfbb9a98ffc218dde463d44"
48#define CIPHER_MAGIC_NUMBER_SIZE 16
49
50// Cipher initialization vector maximum size
51#define MAX_CIPHER_IV_SIZE MAX_CIPHER_BLOCK_SIZE
52
53// C++ guard
54#ifdef __cplusplus
55extern "C"
56{
57#endif
58
63typedef struct
64{
65 CipherContext context;
66 const CipherAlgo *algo;
67 CipherMode mode;
68 const uint8_t *key;
69 size_t keyLen;
70 uint8_t iv[MAX_CIPHER_IV_SIZE];
71 size_t ivLen;
73
74// CycloneBOOT cipher engine related functions
75cboot_error_t cipherInit(CipherEngine *engine, const CipherAlgo *algo, CipherMode mode,
76 const uint8_t *key, size_t keyLen);
77cboot_error_t cipherSetIv(CipherEngine *engine, uint8_t *iv, size_t ivLen);
78cboot_error_t cipherGenerateIv(uint8_t *iv, size_t ivLen);
79cboot_error_t cipherEncryptData(CipherEngine *cipherEngine, uint8_t *data, size_t length);
80cboot_error_t cipherDecryptData(CipherEngine *cipherEngine, uint8_t *data, size_t length);
81
82cboot_error_t cipherCheckMagicNumberCrc(uint32_t magicNumberCrc, bool_t *magicNumberIsValid);
83cboot_error_t cipherComputeMagicNumberCrc(uint32_t *magicNumberCrc);
84
85// C++ guard
86#ifdef __cplusplus
87}
88#endif
89
90#endif // !_CIPHER_H
Error codes description.
cboot_error_t
Error codes.
Definition cboot_error.h:57
cboot_error_t cipherGenerateIv(uint8_t *iv, size_t ivLen)
Generate the initialization vector of an image about to be encrypted. The default implementation gene...
Definition cipher.c:232
cboot_error_t cipherCheckMagicNumberCrc(uint32_t magicNumberCrc, bool_t *magicNumberIsValid)
Definition cipher.c:251
cboot_error_t cipherInit(CipherEngine *engine, const CipherAlgo *algo, CipherMode mode, const uint8_t *key, size_t keyLen)
Initialize cipher engine context.
Definition cipher.c:53
cboot_error_t cipherDecryptData(CipherEngine *cipherEngine, uint8_t *data, size_t length)
Decrypt given encrypted data using cipher engine.
Definition cipher.c:180
cboot_error_t cipherEncryptData(CipherEngine *cipherEngine, uint8_t *data, size_t length)
Encrypt given data using cipher engine.
Definition cipher.c:130
cboot_error_t cipherComputeMagicNumberCrc(uint32_t *magicNumberCrc)
Definition cipher.c:283
cboot_error_t cipherSetIv(CipherEngine *engine, uint8_t *iv, size_t ivLen)
Set cipher initialization vector.
Definition cipher.c:104
Cipher engine structure definition.
Definition cipher.h:64