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

Utility functions used throughout the application. More...

#include <stdio.h>
#include <strings.h>
#include "core/crc32.h"
#include "hash/md5.h"
#include "hash/sha1.h"
#include "hash/sha224.h"
#include "hash/sha256.h"
#include "hash/sha384.h"
#include "hash/sha512.h"
#include "main.h"
#include "header.h"
#include "body.h"
#include "utils.h"
#include "cli.h"
#include "debug.h"

Functions

const HashAlgo * hash_algo_by_name (const char *name)
 Map a hash/checksum algorithm name to its HashAlgo.
 
int read_file (const char *file_path, char **file_contents, size_t *file_size)
 Read a file.
 
int blockify (size_t blockSize, char **input, size_t inputSize, char **output, size_t *outputSize)
 Slice a given buffer in to a blocks of a given size.
 
int seedInitVector (uint8_t *buffer, size_t length)
 Generate an initialization vector with random data.
 
int write_image_to_file (UpdateImage *image, CipherInfo *cipherInfo, const char *output_file_path)
 Write the update image to a file.
 
void dump_buffer (void *buffer, size_t buffer_size)
 
void dump_buffer_2 (void *buffer, size_t buffer_size, size_t columSize)
 
void dumpHeader (ImageHeader *header)
 
void dumpBody (ImageBody *body)
 
void dumpFooter (char *check_data, size_t check_data_size)
 
void dump_cleartext_image (void *buffer, size_t buffer_size)
 
void dump_ciphertext_image (void *buffer, size_t buffer_size)
 
int is_hex (const char *str)
 
int hexCharToDecimal (char c)
 
int hex_string_to_byte_array (const char *hexString, unsigned char **byteArray, size_t *byteArraySize)
 
void parse_firmware_version (const char *version, ImageVersion *imageVersion)
 Parse a "MA.MI.RE.BUILD" firmware version, BUILD in hex.
 
uint32_t version_string_to_int (const char *version)
 
void imageBuildCleanup (ImageBuild *build)
 Release all working buffers.
 

Detailed Description

Utility functions used throughout the application.

License

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

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

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

◆ blockify()

int blockify ( size_t  blockSize,
char **  input,
size_t  inputSize,
char **  output,
size_t *  outputSize 
)

Slice a given buffer in to a blocks of a given size.

Parameters
[in]blockSizeSize of the blocks
[in]inputInput buffer
[in]inputSizeSize of the input buffer
[in]outputOutput buffer
[in]outputSizeSize of the output buffer
Returns
Status code

◆ hash_algo_by_name()

const HashAlgo * hash_algo_by_name ( const char *  name)

Map a hash/checksum algorithm name to its HashAlgo.

Parameters
[in]nameAlgorithm name: crc32, md5, sha1, sha224, sha256, sha384 or sha512.
Returns
Pointer to the const HashAlgo, or NULL if the name is unknown.

◆ parse_firmware_version()

void parse_firmware_version ( const char *  version,
ImageVersion *  imageVersion 
)

Parse a "MA.MI.RE.BUILD" firmware version, BUILD in hex.

Parameters
[in]versionFirmware version string
[out]imageVersionParsed version

◆ read_file()

int read_file ( const char *  file_path,
char **  file_contents,
size_t *  file_size 
)

Read a file.

Parameters
[in]file_pathPath to the file to be read
[in]file_contentsBuffer to store content of the file read
[in]file_sizePointer to the file size
Returns
Status code

◆ seedInitVector()

int seedInitVector ( uint8_t *  buffer,
size_t  length 
)

Generate an initialization vector with random data.

Parameters
[in]bufferBuffer containing initialization vector
[in]lengthBuffer length
Returns
Status code

◆ write_image_to_file()

int write_image_to_file ( UpdateImage *  image,
CipherInfo *  cipherInfo,
const char *  output_file_path 
)

Write the update image to a file.

Parameters
[in]imagePointer containing the update image to be rewritten to disk
[in]cipherInfoCrypto related information
[in]output_file_pathPath to write the image
Returns
Status code