mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-10-01 01:45:38 -04:00
Remove types.h in favor of standard libs such as stdint, stddef
This commit is contained in:
parent
81950ef7b2
commit
698b2796ee
@ -81,7 +81,6 @@ VERILOG_SRCS = \
|
||||
|
||||
FIRMWARE_DEPS = \
|
||||
$(P)/fw/tk1_mem.h \
|
||||
$(P)/fw/tk1/types.h \
|
||||
$(P)/fw/tk1/lib.h \
|
||||
$(P)/fw/tk1/proto.h \
|
||||
$(P)/fw/tk1/assert.h \
|
||||
|
@ -6,9 +6,11 @@
|
||||
#include "../tk1/blake2s/blake2s.h"
|
||||
#include "../tk1/lib.h"
|
||||
#include "../tk1/proto.h"
|
||||
#include "../tk1/types.h"
|
||||
#include "../tk1_mem.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// clang-format off
|
||||
volatile uint32_t *tk1name0 = (volatile uint32_t *)TK1_MMIO_TK1_NAME0;
|
||||
volatile uint32_t *tk1name1 = (volatile uint32_t *)TK1_MMIO_TK1_NAME1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Uses ../.clang-format
|
||||
FMTFILES=main.c lib.h lib.c proto.h proto.c types.h assert.c assert.h led.c led.h
|
||||
FMTFILES=main.c lib.h lib.c proto.h proto.c assert.c assert.h led.c led.h
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
clang-format --dry-run --ferror-limit=0 $(FMTFILES)
|
||||
|
@ -6,10 +6,12 @@
|
||||
// A simple blake2s Reference Implementation.
|
||||
//======================================================================
|
||||
|
||||
#include "../types.h"
|
||||
#include "../lib.h"
|
||||
#include "blake2s.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Dummy printf() for verbose mode
|
||||
static void printf(const char *format, ...)
|
||||
{
|
||||
|
@ -4,7 +4,8 @@
|
||||
#ifndef BLAKE2S_H
|
||||
#define BLAKE2S_H
|
||||
|
||||
#include "../types.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// state context
|
||||
typedef struct {
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "led.h"
|
||||
#include "../tk1_mem.h"
|
||||
#include "types.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED;
|
||||
|
||||
|
@ -7,7 +7,8 @@
|
||||
#define LED_H
|
||||
|
||||
#include "../tk1_mem.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// clang-format off
|
||||
#define LED_BLACK 0
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
#include "lib.h"
|
||||
#include "assert.h"
|
||||
#include "types.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef QEMU_CONSOLE
|
||||
struct {
|
||||
|
@ -6,7 +6,8 @@
|
||||
#ifndef LIB_H
|
||||
#define LIB_H
|
||||
|
||||
#include "types.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef QEMU_CONSOLE
|
||||
void htif_putc(char ch);
|
||||
|
@ -9,7 +9,10 @@
|
||||
#include "lib.h"
|
||||
#include "proto.h"
|
||||
#include "state.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// clang-format off
|
||||
static volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST;
|
||||
@ -37,14 +40,14 @@ struct context {
|
||||
uint32_t left; // Bytes left to receive
|
||||
uint8_t digest[32]; // Program digest
|
||||
uint8_t *loadaddr; // Where we are currently loading a TKey program
|
||||
uint8_t use_uss; // Use USS?
|
||||
bool use_uss; // Use USS?
|
||||
uint8_t uss[32]; // User Supplied Secret, if any
|
||||
};
|
||||
|
||||
static void print_hw_version(void);
|
||||
static void print_digest(uint8_t *md);
|
||||
static uint32_t rnd_word(void);
|
||||
static void compute_cdi(const uint8_t *digest, const uint8_t use_uss,
|
||||
static void compute_cdi(const uint8_t *digest, const bool use_uss,
|
||||
const uint8_t *uss);
|
||||
static void copy_name(uint8_t *buf, const size_t bufsiz, const uint32_t word);
|
||||
static enum state initial_commands(const struct frame_header *hdr,
|
||||
@ -89,7 +92,7 @@ static uint32_t rnd_word(void)
|
||||
}
|
||||
|
||||
// CDI = blake2s(uds, blake2s(app), uss)
|
||||
static void compute_cdi(const uint8_t *digest, const uint8_t use_uss,
|
||||
static void compute_cdi(const uint8_t *digest, const bool use_uss,
|
||||
const uint8_t *uss)
|
||||
{
|
||||
uint32_t local_uds[8] = {0};
|
||||
@ -121,7 +124,7 @@ static void compute_cdi(const uint8_t *digest, const uint8_t use_uss,
|
||||
blake2s_update(&secure_ctx, digest, 32);
|
||||
|
||||
// Possibly hash in the USS as well
|
||||
if (use_uss != 0) {
|
||||
if (use_uss) {
|
||||
blake2s_update(&secure_ctx, uss, 32);
|
||||
}
|
||||
|
||||
@ -217,10 +220,10 @@ static enum state initial_commands(const struct frame_header *hdr,
|
||||
// Do we have a USS at all?
|
||||
if (cmd[5] != 0) {
|
||||
// Yes
|
||||
ctx->use_uss = TRUE;
|
||||
ctx->use_uss = true;
|
||||
memcpy_s(ctx->uss, 32, &cmd[6], 32);
|
||||
} else {
|
||||
ctx->use_uss = FALSE;
|
||||
ctx->use_uss = false;
|
||||
}
|
||||
|
||||
rsp[0] = STATUS_OK;
|
||||
@ -410,7 +413,7 @@ int main(void)
|
||||
*/
|
||||
ctx.loadaddr = (uint8_t *)TK1_RAM_BASE;
|
||||
/*@+mustfreeonly@*/
|
||||
ctx.use_uss = FALSE;
|
||||
ctx.use_uss = false;
|
||||
|
||||
scramble_ram();
|
||||
|
||||
|
@ -9,7 +9,9 @@
|
||||
#include "led.h"
|
||||
#include "lib.h"
|
||||
#include "state.h"
|
||||
#include "types.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// clang-format off
|
||||
static volatile uint32_t *can_rx = (volatile uint32_t *)TK1_MMIO_UART_RX_STATUS;
|
||||
|
@ -3,7 +3,8 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*/
|
||||
|
||||
#include "types.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef PROTO_H
|
||||
#define PROTO_H
|
||||
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 - Tillitis AB
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*/
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
typedef unsigned int uintptr_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long size_t;
|
||||
|
||||
#define NULL ((char *)0)
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE !FALSE
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user