mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2025-08-08 06:32:25 -04:00
Remove types.h in favor of standard libs such as stdint, stddef
This commit is contained in:
parent
69ef6dde8b
commit
fa75ea06ae
13 changed files with 32 additions and 41 deletions
|
@ -106,7 +106,6 @@ PICORV32_SRCS = \
|
||||||
|
|
||||||
FIRMWARE_DEPS = \
|
FIRMWARE_DEPS = \
|
||||||
$(P)/fw/tk1_mem.h \
|
$(P)/fw/tk1_mem.h \
|
||||||
$(P)/fw/tk1/types.h \
|
|
||||||
$(P)/fw/tk1/lib.h \
|
$(P)/fw/tk1/lib.h \
|
||||||
$(P)/fw/tk1/proto.h \
|
$(P)/fw/tk1/proto.h \
|
||||||
$(P)/fw/tk1/assert.h \
|
$(P)/fw/tk1/assert.h \
|
||||||
|
|
|
@ -6,9 +6,11 @@
|
||||||
#include "../tk1/blake2s/blake2s.h"
|
#include "../tk1/blake2s/blake2s.h"
|
||||||
#include "../tk1/lib.h"
|
#include "../tk1/lib.h"
|
||||||
#include "../tk1/proto.h"
|
#include "../tk1/proto.h"
|
||||||
#include "../tk1/types.h"
|
|
||||||
#include "../tk1_mem.h"
|
#include "../tk1_mem.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
volatile uint32_t *tk1name0 = (volatile uint32_t *)TK1_MMIO_TK1_NAME0;
|
volatile uint32_t *tk1name0 = (volatile uint32_t *)TK1_MMIO_TK1_NAME0;
|
||||||
volatile uint32_t *tk1name1 = (volatile uint32_t *)TK1_MMIO_TK1_NAME1;
|
volatile uint32_t *tk1name1 = (volatile uint32_t *)TK1_MMIO_TK1_NAME1;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Uses ../.clang-format
|
# 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
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
clang-format --dry-run --ferror-limit=0 $(FMTFILES)
|
clang-format --dry-run --ferror-limit=0 $(FMTFILES)
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
// A simple blake2s Reference Implementation.
|
// A simple blake2s Reference Implementation.
|
||||||
//======================================================================
|
//======================================================================
|
||||||
|
|
||||||
#include "../types.h"
|
|
||||||
#include "../lib.h"
|
#include "../lib.h"
|
||||||
#include "blake2s.h"
|
#include "blake2s.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
// Dummy printf() for verbose mode
|
// Dummy printf() for verbose mode
|
||||||
static void printf(const char *format, ...)
|
static void printf(const char *format, ...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#ifndef BLAKE2S_H
|
#ifndef BLAKE2S_H
|
||||||
#define BLAKE2S_H
|
#define BLAKE2S_H
|
||||||
|
|
||||||
#include "../types.h"
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
// state context
|
// state context
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "../tk1_mem.h"
|
#include "../tk1_mem.h"
|
||||||
#include "types.h"
|
#include <stdint.h>
|
||||||
|
|
||||||
static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED;
|
static volatile uint32_t *led = (volatile uint32_t *)TK1_MMIO_TK1_LED;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
#define LED_H
|
#define LED_H
|
||||||
|
|
||||||
#include "../tk1_mem.h"
|
#include "../tk1_mem.h"
|
||||||
#include "types.h"
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define LED_BLACK 0
|
#define LED_BLACK 0
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
|
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "types.h"
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef QEMU_CONSOLE
|
#ifdef QEMU_CONSOLE
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
#ifndef LIB_H
|
#ifndef LIB_H
|
||||||
#define LIB_H
|
#define LIB_H
|
||||||
|
|
||||||
#include "types.h"
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef QEMU_CONSOLE
|
#ifdef QEMU_CONSOLE
|
||||||
void htif_putc(char ch);
|
void htif_putc(char ch);
|
||||||
|
|
|
@ -9,7 +9,10 @@
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "types.h"
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST;
|
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
|
uint32_t left; // Bytes left to receive
|
||||||
uint8_t digest[32]; // Program digest
|
uint8_t digest[32]; // Program digest
|
||||||
uint8_t *loadaddr; // Where we are currently loading a TKey program
|
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
|
uint8_t uss[32]; // User Supplied Secret, if any
|
||||||
};
|
};
|
||||||
|
|
||||||
static void print_hw_version(void);
|
static void print_hw_version(void);
|
||||||
static void print_digest(uint8_t *md);
|
static void print_digest(uint8_t *md);
|
||||||
static uint32_t rnd_word(void);
|
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);
|
const uint8_t *uss);
|
||||||
static void copy_name(uint8_t *buf, const size_t bufsiz, const uint32_t word);
|
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,
|
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)
|
// 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)
|
const uint8_t *uss)
|
||||||
{
|
{
|
||||||
uint32_t local_uds[8] = {0};
|
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);
|
blake2s_update(&secure_ctx, digest, 32);
|
||||||
|
|
||||||
// Possibly hash in the USS as well
|
// Possibly hash in the USS as well
|
||||||
if (use_uss != 0) {
|
if (use_uss) {
|
||||||
blake2s_update(&secure_ctx, uss, 32);
|
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?
|
// Do we have a USS at all?
|
||||||
if (cmd[5] != 0) {
|
if (cmd[5] != 0) {
|
||||||
// Yes
|
// Yes
|
||||||
ctx->use_uss = TRUE;
|
ctx->use_uss = true;
|
||||||
memcpy_s(ctx->uss, 32, &cmd[6], 32);
|
memcpy_s(ctx->uss, 32, &cmd[6], 32);
|
||||||
} else {
|
} else {
|
||||||
ctx->use_uss = FALSE;
|
ctx->use_uss = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp[0] = STATUS_OK;
|
rsp[0] = STATUS_OK;
|
||||||
|
@ -410,7 +413,7 @@ int main(void)
|
||||||
*/
|
*/
|
||||||
ctx.loadaddr = (uint8_t *)TK1_RAM_BASE;
|
ctx.loadaddr = (uint8_t *)TK1_RAM_BASE;
|
||||||
/*@+mustfreeonly@*/
|
/*@+mustfreeonly@*/
|
||||||
ctx.use_uss = FALSE;
|
ctx.use_uss = false;
|
||||||
|
|
||||||
scramble_ram();
|
scramble_ram();
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "types.h"
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static volatile uint32_t *can_rx = (volatile uint32_t *)TK1_MMIO_UART_RX_STATUS;
|
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
|
* SPDX-License-Identifier: GPL-2.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "types.h"
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifndef PROTO_H
|
#ifndef PROTO_H
|
||||||
#define 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…
Add table
Add a link
Reference in a new issue