CycloneBOOT 2.6.6
Secure Bootloader for ARM Cortex-M MCU
Loading...
Searching...
No Matches
cipher.h File Reference

CycloneBOOT Encryption & Decryption handling. More...

#include "cipher/cipher_algorithms.h"
#include "cipher_modes/cipher_modes.h"
#include "core/cboot_error.h"
#include "boot_config.h"

Go to the source code of this file.

Classes

struct  CipherEngine
 Cipher engine structure definition. More...
 

Macros

#define CIPHER_SUPPORT   DISABLED
 
#define CIPHER_MAGIC_NUMBER   "5ef41578fcfbb9a98ffc218dde463d44"
 
#define CIPHER_MAGIC_NUMBER_SIZE   16
 
#define MAX_CIPHER_IV_SIZE   MAX_CIPHER_BLOCK_SIZE
 

Functions

cboot_error_t cipherInit (CipherEngine *engine, const CipherAlgo *algo, CipherMode mode, const uint8_t *key, size_t keyLen)
 Initialize cipher engine context.
 
cboot_error_t cipherSetIv (CipherEngine *engine, uint8_t *iv, size_t ivLen)
 Set cipher initialization vector.
 
cboot_error_t cipherGenerateIv (uint8_t *iv, size_t ivLen)
 Generate the initialization vector of an image about to be encrypted. The default implementation generates nothing, so that a build without a source of randomness refuses to encrypt rather than reusing a fixed vector. Override it with the entropy source of the platform, for example its TRNG. The vector is stored with the image, so it needs to differ between images, not to be secret.
 
cboot_error_t cipherEncryptData (CipherEngine *cipherEngine, uint8_t *data, size_t length)
 Encrypt given data using cipher engine.
 
cboot_error_t cipherDecryptData (CipherEngine *cipherEngine, uint8_t *data, size_t length)
 Decrypt given encrypted data using cipher engine.
 
cboot_error_t cipherCheckMagicNumberCrc (uint32_t magicNumberCrc, bool_t *magicNumberIsValid)
 
cboot_error_t cipherComputeMagicNumberCrc (uint32_t *magicNumberCrc)
 

Detailed Description

CycloneBOOT Encryption & Decryption handling.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2021-2026 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneBOOT Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.6.6

Function Documentation

◆ cipherCheckMagicNumberCrc()

cboot_error_t cipherCheckMagicNumberCrc ( uint32_t  magicNumberCrc,
bool_t *  magicNumberIsValid 
)
Parameters
magicNumberCrc
keyIsValid
Returns
cboot_error_t

◆ cipherComputeMagicNumberCrc()

cboot_error_t cipherComputeMagicNumberCrc ( uint32_t *  magicNumberCrc)
Parameters
magicNumberCrc
Returns
cboot_error_t

◆ cipherDecryptData()

cboot_error_t cipherDecryptData ( CipherEngine *  engine,
uint8_t *  data,
size_t  length 
)

Decrypt given encrypted data using cipher engine.

Parameters
[in]enginePointer to the cipher Engine context
[in,out]dataBuffer that initially contains encrypted data and then will hold plaintext data resulting for decryption
[in]lengthLength of the plaintext data buffer
Returns
Error code

◆ cipherEncryptData()

cboot_error_t cipherEncryptData ( CipherEngine *  engine,
uint8_t *  data,
size_t  length 
)

Encrypt given data using cipher engine.

Parameters
[in]enginePointer to the cipher Engine context
[in,out]dataBuffer that initially contains plaintext data and then will hold ciphertext data resulting from encryption
[in]lengthLength of the plaintext data buffer
Returns
Error code

◆ cipherGenerateIv()

cboot_error_t cipherGenerateIv ( uint8_t *  iv,
size_t  ivLen 
)

Generate the initialization vector of an image about to be encrypted. The default implementation generates nothing, so that a build without a source of randomness refuses to encrypt rather than reusing a fixed vector. Override it with the entropy source of the platform, for example its TRNG. The vector is stored with the image, so it needs to differ between images, not to be secret.

Parameters
[out]ivBuffer receiving the initialization vector
[in]ivLenLength of the initialization vector, in bytes
Returns
Status code

◆ cipherInit()

cboot_error_t cipherInit ( CipherEngine *  engine,
const CipherAlgo *  algo,
CipherMode  mode,
const uint8_t *  key,
size_t  keyLen 
)

Initialize cipher engine context.

Parameters
[in]enginePointer to the cipher Engine context to initialize
[in]algoCipher algorithm to be used for encryption/decryption.
[in]modeCipher mode to be used with cipher algorithm
[in]keyPointer to the cipher key
[in]keyLenLength of the cipher key
Returns
Error code

◆ cipherSetIv()

cboot_error_t cipherSetIv ( CipherEngine *  engine,
uint8_t *  iv,
size_t  ivLen 
)

Set cipher initialization vector.

Parameters
[in]enginePointer to the cipher Engine context
[in]ivInitialization vector to use for encryption
[in]ivLenLength of the cipher initialization vector
Returns
Error code