Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
Use C99 uintXX_t instead of implementation-specific u_intXX_t types
Browse files Browse the repository at this point in the history
The u_intXX_t types are implementation-specific and not part of a
standard. As an example, they are not provided by the musl C library.

Therefore, this commit switches cbootimage to use the C99 uintXX_t
types. This commit has been produced by:

 1. Running:

    find . -name '*.[ch]' | xargs sed -i 's%u_int\([0-9]*\)_t%uint\1_t%g'

 2. Adding a #include <stdint.h> in cbootimage.h

The result has been compile tested with the musl C library.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
(swarren, validated "objdump -d cbootimage" is identical before/after)
Signed-off-by: Stephen Warren <swarren@nvidia.com>
  • Loading branch information
tpetazzoni authored and nvswarren committed Oct 3, 2017
1 parent 64045f9 commit 3b3c3cc
Show file tree
Hide file tree
Showing 32 changed files with 2,596 additions and 2,595 deletions.
40 changes: 20 additions & 20 deletions src/aes_ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ REDISTRIBUTION OF THIS SOFTWARE.

#include "nvaes_ref.h"

static void shift_rows(u_int8_t *state);
static void mix_sub_columns(u_int8_t *state);
static void add_round_key(u_int32_t *state, u_int32_t *key);
static void shift_rows(uint8_t *state);
static void mix_sub_columns(uint8_t *state);
static void add_round_key(uint32_t *state, uint32_t *key);

static u_int8_t s_Sbox[256] =
static uint8_t s_Sbox[256] =
{ /* forward s-box */
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
Expand Down Expand Up @@ -87,7 +87,7 @@ static u_int8_t s_Sbox[256] =
};

/* combined Xtimes2[Sbox[]] */
static u_int8_t s_Xtime2Sbox[256] =
static uint8_t s_Xtime2Sbox[256] =
{
0xc6, 0xf8, 0xee, 0xf6, 0xff, 0xd6, 0xde, 0x91,
0x60, 0x02, 0xce, 0x56, 0xe7, 0xb5, 0x4d, 0xec,
Expand Down Expand Up @@ -124,7 +124,7 @@ static u_int8_t s_Xtime2Sbox[256] =
};

/* combined Xtimes3[Sbox[]] */
static u_int8_t s_Xtime3Sbox[256] =
static uint8_t s_Xtime3Sbox[256] =
{
0xa5, 0x84, 0x99, 0x8d, 0x0d, 0xbd, 0xb1, 0x54,
0x50, 0x03, 0xa9, 0x7d, 0x19, 0x62, 0xe6, 0x9a,
Expand Down Expand Up @@ -165,9 +165,9 @@ static u_int8_t s_Xtime3Sbox[256] =
* row2 - shifted left 2 and row3 - shifted left 3
*/
static void
shift_rows(u_int8_t *state)
shift_rows(uint8_t *state)
{
u_int8_t tmp;
uint8_t tmp;

/* just substitute row 0 */
state[ 0] = s_Sbox[state[ 0]];
Expand Down Expand Up @@ -200,9 +200,9 @@ shift_rows(u_int8_t *state)

/* recombine and mix each row in a column */
static void
mix_sub_columns(u_int8_t *state)
mix_sub_columns(uint8_t *state)
{
u_int8_t tmp[4 * NVAES_STATECOLS];
uint8_t tmp[4 * NVAES_STATECOLS];

/* mixing column 0 */
tmp[ 0] = s_Xtime2Sbox[state[ 0]] ^ s_Xtime3Sbox[state[ 5]] ^
Expand Down Expand Up @@ -253,25 +253,25 @@ mix_sub_columns(u_int8_t *state)
*/

static void
add_round_key(u_int32_t *state, u_int32_t *key)
add_round_key(uint32_t *state, uint32_t *key)
{
int idx;

for (idx = 0; idx < 4; idx++)
state[idx] ^= key[idx];
}

static u_int8_t s_Rcon[11] =
static uint8_t s_Rcon[11] =
{
0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
};

/* produce NVAES_STATECOLS bytes for each round */
void
nv_aes_expand_key(u_int8_t *key, u_int8_t *expkey)
nv_aes_expand_key(uint8_t *key, uint8_t *expkey)
{
u_int8_t tmp0, tmp1, tmp2, tmp3, tmp4;
u_int32_t idx;
uint8_t tmp0, tmp1, tmp2, tmp3, tmp4;
uint32_t idx;

memcpy(expkey, key, NVAES_KEYCOLS * 4);

Expand Down Expand Up @@ -304,21 +304,21 @@ nv_aes_expand_key(u_int8_t *key, u_int8_t *expkey)

/* encrypt one 128 bit block */
void
nv_aes_encrypt(u_int8_t *in, u_int8_t *expkey, u_int8_t *out)
nv_aes_encrypt(uint8_t *in, uint8_t *expkey, uint8_t *out)
{
u_int8_t state[NVAES_STATECOLS * 4];
u_int32_t round;
uint8_t state[NVAES_STATECOLS * 4];
uint32_t round;

memcpy(state, in, NVAES_STATECOLS * 4);
add_round_key((u_int32_t *)state, (u_int32_t *)expkey);
add_round_key((uint32_t *)state, (uint32_t *)expkey);

for (round = 1; round < NVAES_ROUNDS + 1; round++) {
if (round < NVAES_ROUNDS)
mix_sub_columns (state);
else
shift_rows (state);

add_round_key((u_int32_t *)state, (u_int32_t *)expkey +
add_round_key((uint32_t *)state, (uint32_t *)expkey +
round * NVAES_STATECOLS);
}

Expand Down
30 changes: 15 additions & 15 deletions src/bct_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ typedef struct {

#define PARAM_TYPE_BINARY_DATA_MAX_SIZE 256
typedef union {
u_int32_t val;
u_int8_t uid[16];
u_int8_t binary[PARAM_TYPE_BINARY_DATA_MAX_SIZE];
uint32_t val;
uint8_t uid[16];
uint8_t binary[PARAM_TYPE_BINARY_DATA_MAX_SIZE];
} param_types;

#define MAX_PARAM_SIZE sizeof(param_types)
Expand Down Expand Up @@ -96,17 +96,17 @@ static value_data const mts_values[] = {
/*****************************************************************************/
static void format_u32_hex8(parse_token id, char const * message, void * data)
{
printf("%s0x%08x;\n", message, *((u_int32_t *) data));
printf("%s0x%08x;\n", message, *((uint32_t *) data));
}

static void format_u32(parse_token id, char const * message, void * data)
{
printf("%s%d;\n", message, *((u_int32_t *) data));
printf("%s%d;\n", message, *((uint32_t *) data));
}

static void format_chipuid(parse_token id, char const * message, void * data)
{
u_int8_t *uid = (u_int8_t *)data;
uint8_t *uid = (uint8_t *)data;
int byte_index;
char uid_str[35] = "0x";
char *s = &uid_str[2];
Expand All @@ -119,7 +119,7 @@ static void format_chipuid(parse_token id, char const * message, void * data)

static void format_hex_16_bytes(parse_token id, char const * message, void * data)
{
u_int8_t *p_byte = (u_int8_t *)data;
uint8_t *p_byte = (uint8_t *)data;
int byte_index;

printf("%s", message);
Expand All @@ -132,7 +132,7 @@ static void format_hex_16_bytes(parse_token id, char const * message, void * dat
static void format_rsa_param(parse_token id, char const * message, void * data)
{
#define MAX_BYTE_NUMBER_PER_LINE 16
u_int8_t *rsa = (u_int8_t *)data;
uint8_t *rsa = (uint8_t *)data;
int size, byte_index;

printf("%s", message);
Expand Down Expand Up @@ -177,7 +177,7 @@ static int max_width(field_item const * table)
/*****************************************************************************/
static enum_item const * find_enum_item(build_image_context *context,
enum_item const * table,
u_int32_t value)
uint32_t value)
{
int i;

Expand All @@ -191,7 +191,7 @@ static enum_item const * find_enum_item(build_image_context *context,
/*****************************************************************************/
static void display_enum_value(build_image_context *context,
enum_item const * table,
u_int32_t value)
uint32_t value)
{
enum_item const * e_item = find_enum_item(context, table, value);

Expand All @@ -203,7 +203,7 @@ static void display_enum_value(build_image_context *context,
/*****************************************************************************/
static int display_field_value(build_image_context *context,
field_item const * item,
u_int32_t value)
uint32_t value)
{
switch (item->type) {
case field_type_enum:
Expand All @@ -230,10 +230,10 @@ int main(int argc, char *argv[])
{
int e;
build_image_context context;
u_int32_t bootloaders_used;
u_int32_t parameters_used;
u_int32_t sdram_used;
u_int32_t mts_used;
uint32_t bootloaders_used;
uint32_t parameters_used;
uint32_t sdram_used;
uint32_t mts_used;
nvboot_dev_type type;
param_types data;
int i;
Expand Down
4 changes: 2 additions & 2 deletions src/cbootimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ main(int argc, char *argv[])

/* Read the bct data from image if bct configs needs to be updated */
if (context.update_image) {
u_int32_t offset = 0, bct_size, actual_size;
u_int8_t *data_block;
uint32_t offset = 0, bct_size, actual_size;
uint8_t *data_block;
struct stat stats;

if (stat(context.input_image_filename, &stats) != 0) {
Expand Down
57 changes: 29 additions & 28 deletions src/cbootimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdint.h>

#define NVBOOT_AES_BLOCK_SIZE_LOG2 4
#define MAX_BUFFER 200
Expand Down Expand Up @@ -86,49 +87,49 @@ typedef struct build_image_context_rec
char *output_image_filename;
char *input_image_filename;
FILE *raw_file;
u_int32_t block_size;
u_int32_t block_size_log2;
u_int32_t page_size;
u_int32_t page_size_log2;
u_int32_t pages_per_blk;
u_int32_t partition_size;
u_int32_t redundancy;
u_int32_t version;
u_int32_t bct_copy;
uint32_t block_size;
uint32_t block_size_log2;
uint32_t page_size;
uint32_t page_size_log2;
uint32_t pages_per_blk;
uint32_t partition_size;
uint32_t redundancy;
uint32_t version;
uint32_t bct_copy;
/*
* Number of blocks at start of device to skip before the BCT.
* This may be used to reserve space for a partition table, for
* example, in order to write the resultant boot image to e.g. an
* SD card while using the remaining space for a user filesystem.
*/
u_int32_t pre_bct_pad_blocks;
uint32_t pre_bct_pad_blocks;
/* Allocation data. */
struct blk_data_rec *memory; /* Representation of memory */
/* block number for the BCT block */
u_int32_t next_bct_blk;
uint32_t next_bct_blk;

char *newbl_filename;
u_int32_t newbl_load_addr;
u_int32_t newbl_entry_point;
u_int32_t newbl_attr;
u_int8_t generate_bct;
u_int8_t *bct;
uint32_t newbl_load_addr;
uint32_t newbl_entry_point;
uint32_t newbl_attr;
uint8_t generate_bct;
uint8_t *bct;

char *mts_filename;
u_int32_t mts_load_addr;
u_int32_t mts_entry_point;
u_int32_t mts_attr;
uint32_t mts_load_addr;
uint32_t mts_entry_point;
uint32_t mts_attr;

char *bct_filename;
u_int32_t last_blk;
u_int32_t bct_size; /* The BCT file size */
u_int32_t boot_data_version; /* The boot data version of BCT */
u_int8_t bct_init; /* The flag for the memory allocation of bct */
u_int32_t odm_data; /* The odm data value */
u_int8_t unique_chip_id[16]; /* The unique chip uid */
u_int8_t secure_jtag_control; /* The flag for enabling jtag control */
u_int32_t secure_debug_control; /* The flag for enabling jtag control */
u_int8_t update_image; /* The flag for updating image */
uint32_t last_blk;
uint32_t bct_size; /* The BCT file size */
uint32_t boot_data_version; /* The boot data version of BCT */
uint8_t bct_init; /* The flag for the memory allocation of bct */
uint32_t odm_data; /* The odm data value */
uint8_t unique_chip_id[16]; /* The unique chip uid */
uint8_t secure_jtag_control; /* The flag for enabling jtag control */
uint32_t secure_debug_control; /* The flag for enabling jtag control */
uint8_t update_image; /* The flag for updating image */
} build_image_context;

/* Function prototypes */
Expand Down
2 changes: 1 addition & 1 deletion src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cleanup_context(build_image_context *context)
int
init_context(build_image_context *context)
{
u_int32_t value;
uint32_t value;

/* Set defaults */
context->memory = new_block_list();
Expand Down
Loading

0 comments on commit 3b3c3cc

Please sign in to comment.