├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── TODO ├── docs └── hc │ └── flash_memory_managment.md ├── firmware-hc ├── .gitignore ├── Legacy │ └── stm32_hal_legacy.h ├── Makefile ├── bootloader_state.c ├── bootloader_state.h ├── buffer_manager.c ├── buffer_manager.h ├── cmsis_compiler.h ├── cmsis_gcc.h ├── cmsis_version.h ├── commands.c ├── commands.h ├── config.h ├── core_cm7.h ├── crc.c ├── crc.h ├── ct-ng │ ├── .config │ └── .gitignore ├── db.c ├── db.h ├── fido2 │ ├── apdu.c │ ├── apdu.h │ ├── cose_key.h │ ├── crypto.c │ ├── crypto.h │ ├── ctap.c │ ├── ctap.h │ ├── ctap_errors.h │ ├── ctap_parse.c │ ├── ctap_parse.h │ ├── ctaphid.c │ ├── ctaphid.h │ ├── data_migration.c │ ├── data_migration.h │ ├── device.h │ ├── extensions │ │ ├── extensions.c │ │ ├── extensions.h │ │ ├── solo.c │ │ ├── solo.h │ │ ├── wallet.c │ │ └── wallet.h │ ├── log.c │ ├── log.h │ ├── storage.h │ ├── stubs.c │ ├── u2f.c │ ├── u2f.h │ ├── util.c │ ├── util.h │ └── version.h ├── fido_device.c ├── firmware_update_state.c ├── firmware_update_state.h ├── flash.c ├── flash.h ├── hc_firmware_encoder.c ├── main.c ├── main.h ├── memory_layout.h ├── mpu_armv7.h ├── print.h ├── rand.c ├── rand.h ├── rng_rand.c ├── rng_rand.h ├── rtc_rand.c ├── rtc_rand.h ├── signet-hc-build-deps.sh ├── signet_aes.c ├── signet_aes.h ├── startup_stm32f733iekx.S ├── stm32f733iekx_a.ld ├── stm32f733iekx_b.ld ├── stm32f733xx.h ├── stm32f7xx │ ├── stm32f7xx.h │ ├── stm32f7xx_hal │ ├── stm32f7xx_hal.c │ ├── stm32f7xx_hal.h │ ├── stm32f7xx_hal_conf.h │ ├── stm32f7xx_hal_cortex.c │ ├── stm32f7xx_hal_cortex.h │ ├── stm32f7xx_hal_crc.c │ ├── stm32f7xx_hal_crc.h │ ├── stm32f7xx_hal_crc_ex.c │ ├── stm32f7xx_hal_crc_ex.h │ ├── stm32f7xx_hal_cryp.c │ ├── stm32f7xx_hal_cryp.h │ ├── stm32f7xx_hal_cryp_ex.c │ ├── stm32f7xx_hal_cryp_ex.h │ ├── stm32f7xx_hal_def.h │ ├── stm32f7xx_hal_dma.c │ ├── stm32f7xx_hal_dma.h │ ├── stm32f7xx_hal_dma_ex.c │ ├── stm32f7xx_hal_dma_ex.h │ ├── stm32f7xx_hal_exti.c │ ├── stm32f7xx_hal_exti.h │ ├── stm32f7xx_hal_flash.c │ ├── stm32f7xx_hal_flash.h │ ├── stm32f7xx_hal_flash_ex.c │ ├── stm32f7xx_hal_flash_ex.h │ ├── stm32f7xx_hal_gpio.c │ ├── stm32f7xx_hal_gpio.h │ ├── stm32f7xx_hal_gpio_ex.h │ ├── stm32f7xx_hal_i2c.c │ ├── stm32f7xx_hal_i2c.h │ ├── stm32f7xx_hal_i2c_ex.c │ ├── stm32f7xx_hal_i2c_ex.h │ ├── stm32f7xx_hal_mmc.c │ ├── stm32f7xx_hal_mmc.h │ ├── stm32f7xx_hal_pcd.c │ ├── stm32f7xx_hal_pcd.h │ ├── stm32f7xx_hal_pcd_ex.c │ ├── stm32f7xx_hal_pcd_ex.h │ ├── stm32f7xx_hal_pwr.c │ ├── stm32f7xx_hal_pwr.h │ ├── stm32f7xx_hal_pwr_ex.c │ ├── stm32f7xx_hal_pwr_ex.h │ ├── stm32f7xx_hal_rcc.c │ ├── stm32f7xx_hal_rcc.h │ ├── stm32f7xx_hal_rcc_ex.c │ ├── stm32f7xx_hal_rcc_ex.h │ ├── stm32f7xx_hal_rng.c │ ├── stm32f7xx_hal_rng.h │ ├── stm32f7xx_hal_sd.c │ ├── stm32f7xx_hal_tim.c │ ├── stm32f7xx_hal_tim_ex.c │ ├── stm32f7xx_hal_uart.c │ ├── stm32f7xx_hal_uart.h │ ├── stm32f7xx_hal_uart_ex.c │ ├── stm32f7xx_hal_uart_ex.h │ ├── stm32f7xx_it.c │ ├── stm32f7xx_it.h │ ├── stm32f7xx_ll_sdmmc.c │ ├── stm32f7xx_ll_sdmmc.h │ ├── stm32f7xx_ll_usb.c │ ├── stm32f7xx_ll_usb.h │ ├── system_stm32f7xx.c │ └── system_stm32f7xx.h ├── stm32f7xx_hal_msp.c ├── tinycbor │ ├── .appveyor.yml │ ├── .tag │ ├── .travis.yml │ ├── Doxyfile │ ├── LICENSE │ ├── Makefile │ ├── README │ ├── TODO │ ├── VERSION │ ├── cbor.dox │ ├── cbor.h │ ├── cborencoder.c │ ├── cborencoder_close_container_checked.c │ ├── cborerrorstrings.c │ ├── cborinternal_p.h │ ├── cborjson.h │ ├── cborparser.c │ ├── cborparser_dup_string.c │ ├── cborpretty.c │ ├── cborpretty_stdio.c │ ├── cbortojson.c │ ├── cborvalidation.c │ ├── compilersupport_p.h │ ├── examples │ │ ├── examples.pro │ │ ├── simplereader.c │ │ └── simplereader.pro │ ├── open_memstream.c │ ├── parsetags.pl │ ├── scripts │ │ ├── maketag.pl │ │ └── update-docs.sh │ ├── src.pri │ ├── tags.txt │ ├── tests │ │ ├── c90 │ │ │ ├── c90.pro │ │ │ └── tst_c90.c │ │ ├── cpp │ │ │ ├── cpp.pro │ │ │ └── tst_cpp.cpp │ │ ├── encoder │ │ │ ├── encoder.pro │ │ │ └── tst_encoder.cpp │ │ ├── parser │ │ │ ├── parser.pro │ │ │ └── tst_parser.cpp │ │ ├── tests.pro │ │ └── tojson │ │ │ ├── tojson.pro │ │ │ └── tst_tojson.cpp │ ├── tinycbor-version.h │ ├── tinycbor.pc.in │ ├── tinycbor.pro │ ├── tools │ │ ├── cbordump │ │ │ ├── cbordump.c │ │ │ └── cbordump.pro │ │ └── json2cbor │ │ │ ├── json2cbor.c │ │ │ └── json2cbor.pro │ └── utf8_p.h ├── types.h ├── usb-reset.c ├── usb.h ├── usb_keyboard.c ├── usb_keyboard.h ├── usb_raw_hid.c ├── usb_raw_hid.h ├── usbd_conf.c ├── usbd_conf.h ├── usbd_core.c ├── usbd_core.h ├── usbd_ctlreq.c ├── usbd_ctlreq.h ├── usbd_def.h ├── usbd_desc.c ├── usbd_desc.h ├── usbd_hid.c ├── usbd_hid.h ├── usbd_ioreq.c ├── usbd_ioreq.h ├── usbd_msc.c ├── usbd_msc.h ├── usbd_msc_bot.c ├── usbd_msc_bot.h ├── usbd_msc_data.c ├── usbd_msc_data.h ├── usbd_msc_ops.c ├── usbd_msc_ops.h ├── usbd_msc_scsi.c ├── usbd_msc_scsi.h ├── usbd_multi.c └── usbd_multi.h ├── firmware ├── .gitignore ├── Makefile ├── binutils_options ├── build-deps.sh ├── commands.c ├── commands.h ├── config.guess ├── config.h ├── config_l443xc.h ├── crc.c ├── crc.h ├── ct-ng │ ├── .config │ └── .gitignore ├── db.c ├── db.h ├── firmware-version ├── firmware_update_state.c ├── firmware_update_state.h ├── flash.h ├── flash_l443xc.c ├── gcc_options ├── gpio.c ├── gpio.h ├── i2c_eeprom.c ├── i2c_eeprom.h ├── irq.c ├── irq.h ├── ivt_l443xc.c ├── libb64-1.2.1 │ ├── AUTHORS │ ├── BENCHMARKS │ ├── CHANGELOG │ ├── INSTALL │ ├── LICENSE │ ├── Makefile │ ├── README │ ├── TODO │ ├── base64 │ │ ├── Makefile │ │ ├── VisualStudioProject │ │ │ ├── Makefile │ │ │ ├── base64.sln │ │ │ ├── base64.vcxproj │ │ │ └── base64.vcxproj.filters │ │ └── base64.cc │ ├── examples │ │ ├── Makefile │ │ ├── README.md │ │ ├── c-example1.c │ │ ├── c-example2.c │ │ └── loremgibson.txt │ ├── include │ │ └── b64 │ │ │ ├── cdecode.h │ │ │ ├── cencode.h │ │ │ ├── decode.h │ │ │ └── encode.h │ └── src │ │ ├── Makefile │ │ ├── cdecode.c │ │ ├── cencode.c │ │ └── depend ├── main.h ├── main_l443xc.c ├── print.c ├── print.h ├── regmap.h ├── regmap_aes.h ├── regmap_l443xc.h ├── rng.h ├── rng_driver.c ├── rtc_rand.c ├── rtc_rand.h ├── serial-loader.c ├── signet-firmware-encoder.c ├── spi_test_code.c ├── startup.c ├── startup.h ├── stm32l443xc.ld ├── stm_aes.c ├── stm_aes.h ├── sysinclude │ ├── assert.h │ ├── stdint.h │ ├── stdio.h │ └── sys │ │ └── types.h ├── types.h ├── update-firmware.sh ├── usart.c ├── usart.h ├── usb.c ├── usb.h ├── usb_driver.h ├── usb_fs_driver.c ├── usb_keyboard.c ├── usb_keyboard.h ├── usb_raw_hid.c ├── usb_raw_hid.h ├── usb_serial.c ├── usb_serial.h └── usb_storage.h ├── signetdev ├── common │ ├── hid_keyboard.h │ ├── signetdev_common.h │ ├── signetdev_common_priv.h │ └── signetdev_hc_common.h ├── host │ ├── linux │ │ └── 50-signet.rules │ ├── rawhid │ │ ├── hid.h │ │ └── hid_WINDOWS.c │ ├── signetdev.c │ ├── signetdev.h │ ├── signetdev_android.c │ ├── signetdev_emulate.c │ ├── signetdev_linux.c │ ├── signetdev_osx.c │ ├── signetdev_priv.h │ ├── signetdev_unix.c │ ├── signetdev_unix.h │ └── signetdev_win32.c └── signetdev.pro ├── tests └── button-press-test │ ├── button-press-test.pro │ └── main.cpp └── tools └── stage2-firmware-loader ├── .gitignore ├── main.cpp └── stage2-firmware-loader.pro /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.o.d 3 | *~ 4 | *.swp 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "nettle"] 2 | path = firmware/nettle 3 | url = ../nettle.git 4 | ignore = dirty 5 | [submodule "crosstool-ng"] 6 | path = crosstool-ng 7 | url = https://github.com/crosstool-ng/crosstool-ng.git 8 | [submodule "firmware-hc/nettle"] 9 | path = firmware-hc/external/nettle 10 | url = ../nettle.git 11 | [submodule "firmware-hc/mini-gmp"] 12 | path = firmware-hc/external/mini-gmp 13 | url = https://github.com/chfast/mini-gmp.git 14 | ignore = dirty 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Firmware for Signet Devices 2 | 3 | ## Prerequisites 4 | 5 | #### Cloning Directions 6 | 7 | This project uses git submodules, you will either need to use `git clone 8 | --recursive ` or after cloning use `git submodule update --init`. 9 | 10 | #### Dependencies 11 | 12 | The following packages must be installed: 13 | `build-essential autoconf automake gperf texinfo help2man ncurses-dev bison flex libtool-bin libjson-c-dev libiberty-dev dfu-util` 14 | 15 | This has been tested in various GNU/Linux machines, in other platforms you 16 | might need more, and possibly differently named, packages. 17 | 18 | 19 | ## Building the Signet Legacy Firmware 20 | 21 | #### Prepare the Toolchain, Dependencies and Tools 22 | 23 | This will build the toolchain and dependencies: 24 | ``` 25 | cd firmware 26 | ./build-deps.sh 27 | ``` 28 | 29 | To package the firmware for the Signet client GUI we need the firmware encoder: 30 | `make signet-firmware-encoder`. 31 | 32 | #### Build the Firmware 33 | 34 | `make` builds the Signet firmware. 35 | 36 | Package it with: `./signet-firmware-encoder signet-fw.bin signet-fw.sfw` 37 | 38 | 39 | ## Building the Signet HC Firmware 40 | 41 | #### Prepare the Toolchain, Dependencies and Tools 42 | 43 | This will build the toolchain and dependencies: 44 | ``` 45 | cd firmware-hc 46 | ./signet-hc-build-deps.sh 47 | ``` 48 | 49 | To build the Signet High-capacity firmware encoder: `make hc-firmware-encoder` 50 | 51 | #### Build the Firmware 52 | 53 | Signet HC firmware has too parts, they need to be built separately: 54 | `make BT_MODE=A` and `make BT_MODE=B`. 55 | 56 | To package Signet HC firmware, we need to specify the version number too: 57 | `./hc-firmware-encoder signet-fw-a.bin signet-fw-b.bin signet-fw-0.2.3.sfwhc 0 2 3` 58 | 59 | ### Reproducible Builds 60 | 61 | Both Signet and Signet High-capacity firmware uses locally compiled toolchains 62 | (via crosstool-ng) to increase the chance of reproducible builds. 63 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Tasks: 2 | Redundant storage with CRC's 3 | HID events for state changes 4 | Add better way to get all account meta data on connection 5 | Provide pools of buffers smaller than flash block size for DB storage 6 | Review handling of USB reset command by device 7 | Handle sleep requests 8 | -------------------------------------------------------------------------------- /firmware-hc/.gitignore: -------------------------------------------------------------------------------- 1 | toolchain 2 | *.o 3 | *.o? 4 | *.d 5 | *.bin 6 | *.map 7 | *.elf 8 | -------------------------------------------------------------------------------- /firmware-hc/bootloader_state.c: -------------------------------------------------------------------------------- 1 | #include "bootloader_state.h" 2 | #include "firmware_update_state.h" 3 | #include "signetdev_common_priv.h" 4 | 5 | int bootloader_state(int active_cmd, u8 *data, int data_len) 6 | { 7 | switch (active_cmd) { 8 | case SWITCH_BOOT_MODE: 9 | switch_boot_mode_cmd(data, data_len); 10 | break; 11 | case UPDATE_FIRMWARE: 12 | update_firmware_cmd(data, data_len); 13 | update_firmware_cmd_complete(); 14 | break; 15 | default: 16 | return -1; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /firmware-hc/bootloader_state.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOTLOADER_STATE_H 2 | 3 | #include "types.h" 4 | 5 | int bootloader_state(int active_cmd, u8 *data, int data_len); 6 | #endif 7 | -------------------------------------------------------------------------------- /firmware-hc/buffer_manager.h: -------------------------------------------------------------------------------- 1 | #ifndef BUFFER_MANAGER_H 2 | #define BUFFER_MANAGER_H 3 | 4 | 5 | #define BUFFER_FIFO_MAX_STAGES 4 6 | #define BUFFER_FIFO_MAX_BUFFERS 16 7 | 8 | struct bufferFIFO { 9 | int maxBufferSize; 10 | int bufferCount; 11 | uint8_t *bufferStorage; 12 | int numStages; 13 | void ((*processStage[BUFFER_FIFO_MAX_STAGES])(struct bufferFIFO *bf, int readSize, u32 readData, const uint8_t *bufferRead, uint8_t *bufferWrite, int stageIdx)); 14 | 15 | void (*processingComplete)(struct bufferFIFO *bf); 16 | int _bufferSize[BUFFER_FIFO_MAX_BUFFERS]; 17 | u32 _bufferData[BUFFER_FIFO_MAX_BUFFERS]; 18 | 19 | int _stageWriteIndex[BUFFER_FIFO_MAX_STAGES]; 20 | int _stageReadIndex[BUFFER_FIFO_MAX_STAGES]; 21 | 22 | int _stalled[BUFFER_FIFO_MAX_STAGES]; 23 | int _stageProcessing[BUFFER_FIFO_MAX_STAGES]; 24 | int _processing; 25 | int _stall_index; 26 | }; 27 | 28 | void bufferFIFO_processingComplete(struct bufferFIFO *bf, int stageIdx, int writeLen, u32 bufferData); 29 | void bufferFIFO_start(struct bufferFIFO *bf, int firstBufferSize); 30 | void bufferFIFO_stallStage(struct bufferFIFO *bf, int stageIdx); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /firmware-hc/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /firmware-hc/config.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_H 2 | #define CONFIG_H 3 | #include "types.h" 4 | 5 | #define FLASH_MEM_BASE_ADDR (0x8000000) 6 | #define FLASH_MEM_SIZE (0x80000) 7 | #define FLASH_MEM_END_ADDR (FLASH_MEM_BASE_ADD + FLASH_MEM_SIZE - 1) 8 | 9 | #define RAW_HID_RX_ENDPOINT 1 10 | #define RAW_HID_TX_ENDPOINT 2 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /firmware-hc/crc.c: -------------------------------------------------------------------------------- 1 | #include "crc.h" 2 | 3 | #include "stm32f7xx.h" 4 | 5 | #include "types.h" 6 | 7 | static CRC_HandleTypeDef hcrc = { 8 | .Instance = CRC, 9 | .Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE, 10 | .Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE, 11 | .Init.CRCLength = CRC_POLYLENGTH_32B, 12 | .Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_BYTE, 13 | .Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_ENABLE, 14 | .InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES, 15 | }; 16 | 17 | void crc_init() 18 | { 19 | HAL_CRC_Init(&hcrc); 20 | } 21 | 22 | u32 crc_32(const u8 *din, int count) 23 | { 24 | u32 crc = HAL_CRC_Calculate(&hcrc, (uint32_t *)din, count); 25 | return ~crc; 26 | } 27 | 28 | u32 crc_32_cont(const u8 *din, int count) 29 | { 30 | return ~HAL_CRC_Accumulate(&hcrc, (uint32_t *)din, count); 31 | } 32 | -------------------------------------------------------------------------------- /firmware-hc/crc.h: -------------------------------------------------------------------------------- 1 | #ifndef CRC_H 2 | #define CRC_H 3 | 4 | #include "signetdev_common.h" 5 | 6 | void crc_init(); 7 | 8 | u32 crc_32(const u8 *din, int count); 9 | u32 crc_32_cont(const u8 *din, int count); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /firmware-hc/ct-ng/.gitignore: -------------------------------------------------------------------------------- 1 | .build 2 | build.log 3 | -------------------------------------------------------------------------------- /firmware-hc/db.h: -------------------------------------------------------------------------------- 1 | #ifndef DB_H 2 | #define DB_H 3 | 4 | struct block_info { 5 | u8 valid; 6 | u8 occupied; 7 | u8 part_count; //# of partitions total in a block 8 | u8 part_occupancy; //# of partitions allocated in a block 9 | u16 part_size; //0 == invalid block, 61=>X>=1 == block size = X * 16,, X > 63 == invalid block 10 | u16 part_tbl_offs; // offset of partitions in sub blocks 11 | }; 12 | 13 | void read_uid_cmd(int uid, int masked); 14 | void update_uid_cmd (int uid, u8 *data, int data_len, int sz, int press_type); 15 | void read_all_uids_cmd(int masked); 16 | void read_all_uids_cmd_iter(); 17 | 18 | void read_uid_cmd_complete(); 19 | void read_all_uids_cmd_complete(); 20 | void update_uid_cmd_complete(); 21 | void update_uid_cmd_write_finished(); 22 | 23 | void db3_startup_scan(u8 *block_read, struct block_info *blk_info_temp); 24 | struct block *db3_initialize_block(int block_num, struct block *block_temp); 25 | 26 | int db3_read_block_complete(); 27 | int db3_write_block_complete(); 28 | 29 | #define ROOT_BLOCK_FORMAT_CURRENT (3) 30 | #define ROOT_BLOCK_FORMAT_3 (3) 31 | #define DB_FORMAT_CURRENT (3) 32 | #define DB_FORMAT_3 (3) 33 | #define DB_FORMAT_2 (2) 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /firmware-hc/fido2/apdu.h: -------------------------------------------------------------------------------- 1 | #ifndef _APDU_H_ 2 | #define _APDU_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef struct 9 | { 10 | uint8_t cla; 11 | uint8_t ins; 12 | uint8_t p1; 13 | uint8_t p2; 14 | uint8_t lc; 15 | } __attribute__((packed)) APDU_HEADER; 16 | 17 | typedef struct 18 | { 19 | uint8_t cla; 20 | uint8_t ins; 21 | uint8_t p1; 22 | uint8_t p2; 23 | uint8_t lc[3]; 24 | } __attribute__((packed)) EXT_APDU_HEADER; 25 | 26 | typedef struct 27 | { 28 | uint8_t cla; 29 | uint8_t ins; 30 | uint8_t p1; 31 | uint8_t p2; 32 | uint16_t lc; 33 | uint8_t *data; 34 | uint32_t le; 35 | bool extended_apdu; 36 | uint8_t case_type; 37 | } __attribute__((packed)) APDU_STRUCT; 38 | 39 | extern uint16_t apdu_decode(uint8_t *data, size_t len, APDU_STRUCT *apdu); 40 | 41 | #define APDU_FIDO_U2F_REGISTER 0x01 42 | #define APDU_FIDO_U2F_AUTHENTICATE 0x02 43 | #define APDU_FIDO_U2F_VERSION 0x03 44 | #define APDU_FIDO_NFCCTAP_MSG 0x10 45 | #define APDU_FIDO_U2F_VENDOR_FIRST 0xc0 // First vendor defined command 46 | #define APDU_FIDO_U2F_VENDOR_LAST 0xff // Last vendor defined command 47 | #define APDU_SOLO_RESET 0xee 48 | 49 | #define APDU_INS_SELECT 0xA4 50 | #define APDU_INS_READ_BINARY 0xB0 51 | #define APDU_GET_RESPONSE 0xC0 52 | 53 | #define SW_SUCCESS 0x9000 54 | #define SW_GET_RESPONSE 0x6100 // Command successfully executed; 'XX' bytes of data are available and can be requested using GET RESPONSE. 55 | #define SW_WRONG_LENGTH 0x6700 56 | #define SW_COND_USE_NOT_SATISFIED 0x6985 57 | #define SW_FILE_NOT_FOUND 0x6a82 58 | #define SW_INCORRECT_P1P2 0x6a86 59 | #define SW_INS_INVALID 0x6d00 // Instruction code not supported or invalid 60 | #define SW_CLA_INVALID 0x6e00 61 | #define SW_INTERNAL_EXCEPTION 0x6f00 62 | 63 | #endif //_APDU_H_ 64 | -------------------------------------------------------------------------------- /firmware-hc/fido2/cose_key.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef _COSE_KEY_H 8 | #define _COSE_KEY_H 9 | 10 | #define COSE_KEY_LABEL_KTY 1 11 | #define COSE_KEY_LABEL_ALG 3 12 | #define COSE_KEY_LABEL_CRV -1 13 | #define COSE_KEY_LABEL_X -2 14 | #define COSE_KEY_LABEL_Y -3 15 | 16 | #define COSE_KEY_KTY_EC2 2 17 | #define COSE_KEY_CRV_P256 1 18 | 19 | #define COSE_ALG_ES256 -7 20 | #define COSE_ALG_ECDH_ES_HKDF_256 -25 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /firmware-hc/fido2/crypto.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef _CRYPTO_H 8 | #define _CRYPTO_H 9 | 10 | #include 11 | 12 | #define USE_SOFTWARE_IMPLEMENTATION 13 | 14 | void crypto_sha256_init(); 15 | void crypto_sha256_update(uint8_t * data, size_t len); 16 | void crypto_sha256_update_secret(); 17 | void crypto_sha256_final(uint8_t * hash); 18 | 19 | void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac); 20 | void crypto_sha256_hmac_update(const uint8_t *data, size_t length); 21 | void crypto_sha256_hmac_final(uint8_t * key, uint32_t klen, uint8_t * hmac); 22 | 23 | void crypto_sha512_init(); 24 | void crypto_sha512_update(const uint8_t * data, size_t len); 25 | void crypto_sha512_final(uint8_t * hash); 26 | 27 | 28 | void crypto_ecc256_init(); 29 | void crypto_ecc256_derive_public_key(uint8_t * data, int len, uint8_t * x, uint8_t * y); 30 | void crypto_ecc256_compute_public_key(const uint8_t * privkey, uint8_t * pubkey); 31 | 32 | void crypto_ecc256_load_key(uint8_t * data, int len, uint8_t * data2, int len2); 33 | void crypto_ecc256_load_attestation_key(); 34 | void crypto_load_external_key(uint8_t * key, int len); 35 | void crypto_ecc256_sign(uint8_t * data, int len, uint8_t * sig); 36 | void crypto_ecdsa_sign(uint8_t * data, int len, uint8_t * sig, int MBEDTLS_ECP_ID); 37 | 38 | 39 | void generate_private_key(uint8_t * data, int len, uint8_t * data2, int len2, uint8_t * privkey); 40 | void crypto_ecc256_make_key_pair(uint8_t * pubkey, uint8_t * privkey); 41 | void crypto_ecc256_shared_secret(const uint8_t * pubkey, const uint8_t * privkey, uint8_t * shared_secret); 42 | 43 | #define CRYPTO_TRANSPORT_KEY2 ((uint8_t*)2) 44 | #define CRYPTO_TRANSPORT_KEY ((uint8_t*)1) 45 | #define CRYPTO_MASTER_KEY ((uint8_t*)0) 46 | 47 | void crypto_aes256_init(uint8_t * key, uint8_t * nonce); 48 | void crypto_aes256_reset_iv(uint8_t * nonce); 49 | 50 | // buf length must be multiple of 16 bytes 51 | void crypto_aes256_decrypt(uint8_t * buf, int lenth); 52 | void crypto_aes256_encrypt(uint8_t * buf, int lenth); 53 | 54 | void crypto_reset_master_secret(); 55 | void crypto_load_master_secret(uint8_t * key); 56 | 57 | void crypto_random_init(); 58 | int crypto_random_get_requested(); 59 | int crypto_random_get_served(); 60 | 61 | extern const uint8_t attestation_cert_der[]; 62 | extern const uint16_t attestation_cert_der_size; 63 | 64 | extern const uint8_t attestation_key[]; 65 | extern const uint16_t attestation_key_size; 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /firmware-hc/fido2/ctap_errors.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #define CTAP1_ERR_SUCCESS 0x00 8 | #define CTAP1_ERR_INVALID_COMMAND 0x01 9 | #define CTAP1_ERR_INVALID_PARAMETER 0x02 10 | #define CTAP1_ERR_INVALID_LENGTH 0x03 11 | #define CTAP1_ERR_INVALID_SEQ 0x04 12 | #define CTAP1_ERR_TIMEOUT 0x05 13 | #define CTAP1_ERR_CHANNEL_BUSY 0x06 14 | #define CTAP1_ERR_LOCK_REQUIRED 0x0A 15 | #define CTAP1_ERR_INVALID_CHANNEL 0x0B 16 | #define CTAP2_ERR_CBOR_PARSING 0x10 17 | #define CTAP2_ERR_CBOR_UNEXPECTED_TYPE 0x11 18 | #define CTAP2_ERR_INVALID_CBOR 0x12 19 | #define CTAP2_ERR_INVALID_CBOR_TYPE 0x13 20 | #define CTAP2_ERR_MISSING_PARAMETER 0x14 21 | #define CTAP2_ERR_LIMIT_EXCEEDED 0x15 22 | #define CTAP2_ERR_UNSUPPORTED_EXTENSION 0x16 23 | #define CTAP2_ERR_TOO_MANY_ELEMENTS 0x17 24 | #define CTAP2_ERR_EXTENSION_NOT_SUPPORTED 0x18 25 | #define CTAP2_ERR_CREDENTIAL_EXCLUDED 0x19 26 | #define CTAP2_ERR_CREDENTIAL_NOT_VALID 0x20 27 | #define CTAP2_ERR_PROCESSING 0x21 28 | #define CTAP2_ERR_INVALID_CREDENTIAL 0x22 29 | #define CTAP2_ERR_USER_ACTION_PENDING 0x23 30 | #define CTAP2_ERR_OPERATION_PENDING 0x24 31 | #define CTAP2_ERR_NO_OPERATIONS 0x25 32 | #define CTAP2_ERR_UNSUPPORTED_ALGORITHM 0x26 33 | #define CTAP2_ERR_OPERATION_DENIED 0x27 34 | #define CTAP2_ERR_KEY_STORE_FULL 0x28 35 | #define CTAP2_ERR_NOT_BUSY 0x29 36 | #define CTAP2_ERR_NO_OPERATION_PENDING 0x2A 37 | #define CTAP2_ERR_UNSUPPORTED_OPTION 0x2B 38 | #define CTAP2_ERR_INVALID_OPTION 0x2C 39 | #define CTAP2_ERR_KEEPALIVE_CANCEL 0x2D 40 | #define CTAP2_ERR_NO_CREDENTIALS 0x2E 41 | #define CTAP2_ERR_USER_ACTION_TIMEOUT 0x2F 42 | #define CTAP2_ERR_NOT_ALLOWED 0x30 43 | #define CTAP2_ERR_PIN_INVALID 0x31 44 | #define CTAP2_ERR_PIN_BLOCKED 0x32 45 | #define CTAP2_ERR_PIN_AUTH_INVALID 0x33 46 | #define CTAP2_ERR_PIN_AUTH_BLOCKED 0x34 47 | #define CTAP2_ERR_PIN_NOT_SET 0x35 48 | #define CTAP2_ERR_PIN_REQUIRED 0x36 49 | #define CTAP2_ERR_PIN_POLICY_VIOLATION 0x37 50 | #define CTAP2_ERR_PIN_TOKEN_EXPIRED 0x38 51 | #define CTAP2_ERR_REQUEST_TOO_LARGE 0x39 52 | #define CTAP2_ERR_ACTION_TIMEOUT 0x3A 53 | #define CTAP1_ERR_OTHER 0x7F 54 | #define CTAP2_ERR_SPEC_LAST 0xDF 55 | #define CTAP2_ERR_EXTENSION_FIRST 0xE0 56 | #define CTAP2_ERR_EXTENSION_LAST 0xEF 57 | #define CTAP2_ERR_VENDOR_FIRST 0xF0 58 | #define CTAP2_ERR_VENDOR_LAST 0xFF 59 | -------------------------------------------------------------------------------- /firmware-hc/fido2/ctap_parse.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef _CTAP_PARSE_H 8 | #define _CTAP_PARSE_H 9 | 10 | 11 | #define check_ret(r) _check_ret(r,__LINE__, __FILE__);\ 12 | if ((r) != CborNoError) return CTAP2_ERR_CBOR_PARSING; 13 | 14 | #define check_retr(r) _check_ret(r,__LINE__, __FILE__);\ 15 | if ((r) != CborNoError) return r; 16 | 17 | 18 | extern void _check_ret(CborError ret, int line, const char * filename); 19 | 20 | 21 | const char * cbor_value_get_type_string(const CborValue *value); 22 | 23 | 24 | uint8_t parse_user(CTAP_makeCredential * MC, CborValue * val); 25 | uint8_t parse_pub_key_cred_param(CborValue * val, uint8_t * cred_type, int32_t * alg_type); 26 | uint8_t parse_pub_key_cred_params(CTAP_makeCredential * MC, CborValue * val); 27 | uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, unsigned int len); 28 | uint8_t parse_rp_id(struct rpId * rp, CborValue * val); 29 | uint8_t parse_rp(struct rpId * rp, CborValue * val); 30 | uint8_t parse_options(CborValue * val, uint8_t * rk, uint8_t * uv, uint8_t * up); 31 | 32 | uint8_t parse_allow_list(CTAP_getAssertion * GA, CborValue * it); 33 | uint8_t parse_cose_key(CborValue * it, COSE_key * cose); 34 | 35 | 36 | uint8_t ctap_parse_make_credential(CTAP_makeCredential * MC, CborEncoder * encoder, uint8_t * request, int length); 37 | uint8_t ctap_parse_get_assertion(CTAP_getAssertion * GA, uint8_t * request, int length); 38 | uint8_t ctap_parse_client_pin(CTAP_clientPin * CP, uint8_t * request, int length); 39 | uint8_t parse_credential_descriptor(CborValue * arr, CTAP_credentialDescriptor * cred); 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /firmware-hc/fido2/data_migration.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | 8 | #ifndef FIDO2_PR_DATA_MIGRATION_H 9 | #define FIDO2_PR_DATA_MIGRATION_H 10 | 11 | #include "storage.h" 12 | 13 | void do_migration_if_required(AuthenticatorState* state_current); 14 | 15 | #endif //FIDO2_PR_DATA_MIGRATION_H 16 | -------------------------------------------------------------------------------- /firmware-hc/fido2/extensions/extensions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef EXTENSIONS_H_ 8 | #define EXTENSIONS_H_ 9 | #include "u2f.h" 10 | #include "apdu.h" 11 | 12 | int16_t bridge_u2f_to_extensions(uint8_t * chal, uint8_t * appid, uint8_t klen, uint8_t * keyh); 13 | 14 | // return 1 if request is a wallet request 15 | int is_extension_request(uint8_t * req, int len); 16 | 17 | int16_t extend_u2f(APDU_HEADER * req, uint8_t * payload, uint32_t len); 18 | 19 | int16_t extend_fido2(CredentialId * credid, uint8_t * output); 20 | 21 | int bootloader_bridge(int klen, uint8_t * keyh); 22 | 23 | int is_extension_request(uint8_t * kh, int len); 24 | 25 | 26 | void extension_writeback_init(uint8_t * buffer, uint8_t size); 27 | void extension_writeback(uint8_t * buf, uint8_t size); 28 | 29 | #endif /* EXTENSIONS_H_ */ 30 | -------------------------------------------------------------------------------- /firmware-hc/fido2/extensions/solo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoloKeys, Inc. 3 | * 4 | * This file is part of Solo. 5 | * 6 | * Solo is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * Solo is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with Solo. If not, see 18 | * 19 | * This code is available under licenses for commercial use. 20 | * Please contact SoloKeys for more information. 21 | */ 22 | #ifdef ENABLE_U2F_EXTENSIONS 23 | 24 | #include 25 | #include "extensions.h" 26 | #include "u2f.h" 27 | #include "wallet.h" 28 | #include "device.h" 29 | #include "ctap.h" 30 | #include "ctap_errors.h" 31 | 32 | #include "log.h" 33 | #include APP_CONFIG 34 | 35 | 36 | 37 | // output must be at least 71 bytes 38 | int16_t bridge_u2f_to_solo(uint8_t * output, uint8_t * keyh, int keylen) 39 | { 40 | int8_t ret = 0; 41 | 42 | wallet_request * req = (wallet_request *) keyh; 43 | extension_writeback_init(output, 71); 44 | 45 | printf1(TAG_WALLET, "u2f-solo [%d]: ", keylen); dump_hex1(TAG_WALLET, keyh, keylen); 46 | 47 | switch(req->operation) 48 | { 49 | case WalletVersion: 50 | output[0] = SOLO_VERSION_MAJ; 51 | output[1] = SOLO_VERSION_MIN; 52 | output[2] = SOLO_VERSION_PATCH; 53 | break; 54 | case WalletRng: 55 | printf1(TAG_WALLET,"SoloRng\n"); 56 | 57 | ret = ctap_generate_rng(output, 71); 58 | if (ret != 1) 59 | { 60 | printf1(TAG_WALLET,"Rng failed\n"); 61 | ret = CTAP2_ERR_PROCESSING; 62 | goto cleanup; 63 | } 64 | ret = 0; 65 | 66 | break; 67 | 68 | #ifdef ENABLE_WALLET 69 | case WalletSign: 70 | case WalletRegister: 71 | case WalletPin: 72 | case WalletReset: 73 | return bridge_to_wallet(keyh, keylen); 74 | #endif 75 | 76 | default: 77 | printf2(TAG_ERR,"Invalid wallet command: %x\n",req->operation); 78 | ret = CTAP1_ERR_INVALID_COMMAND; 79 | break; 80 | } 81 | 82 | cleanup: 83 | 84 | return ret; 85 | } 86 | #endif 87 | -------------------------------------------------------------------------------- /firmware-hc/fido2/extensions/solo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 SoloKeys, Inc. 3 | * 4 | * This file is part of Solo. 5 | * 6 | * Solo is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * Solo is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with Solo. If not, see 18 | * 19 | * This code is available under licenses for commercial use. 20 | * Please contact SoloKeys for more information. 21 | */ 22 | #ifndef SOLO_H_ 23 | #define SOLO_H_ 24 | 25 | int16_t bridge_u2f_to_solo(uint8_t * output, uint8_t * keyh, int keylen); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /firmware-hc/fido2/extensions/wallet.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef WALLET_H_ 8 | #define WALLET_H_ 9 | 10 | #include 11 | 12 | #define WALLET_MAX_BUFFER (32 + 255) 13 | 14 | // Sign request 15 | // op: 0x10 16 | // authType: 0x00 //sign? 17 | // reserved: 0x00 // mbedtls signature alg identifier 18 | // pinAuth: data[16] 19 | // challenge-length: 1-255 20 | // challenge: data[1-255] 21 | // keyID-length: 1-255 22 | // keyID: data[1-255] 23 | 24 | // Resp: normal U2F auth response 25 | 26 | // Register request 27 | // op: 0x11 28 | // formatType: 0x00 //sign? [0x00: WIF, 0x01: raw] 29 | // keyType: 0x03 // mbedtls signature alg identifier 30 | // key-length: 1-255 31 | // key: data[1-255] 32 | 33 | 34 | // Resp: modded U2F auth response 35 | 36 | // PIN request 37 | // op: 0x12 38 | // subcmd: 0x00 // Same as CTAP pin subcommands 39 | // reserved: 0x03 // mbedtls signature alg identifier 40 | // publickey: data[64] 41 | // OR 42 | // pinAuth data[64] 43 | // OR 44 | // pinHashEnc data[64] 45 | // OR 46 | // newPinEnc data[64] 47 | 48 | // key: data[1-255] 49 | // keyID-length: 1-255 50 | // keyID: data[1-255] 51 | 52 | // Resp: modded U2F auth response 53 | // Returns public key OR pinAuth 54 | 55 | // Only response to this challenge to prevent interference 56 | #define WALLET_TAG "\x8C\x27\x90\xf6" 57 | 58 | #define WALLET_MIN_LENGTH (4 + 4 + 16) 59 | 60 | #define WALLET_VERSION "WALLET_V1.0" 61 | 62 | #define MAX_CHALLENGE_SIZE 229 63 | #define MAX_KEYID_SIZE 228 64 | 65 | #define MAX_PAYLOAD_SIZE (255 - 16 - 4 - 4) 66 | 67 | typedef struct 68 | { 69 | uint8_t operation; 70 | uint8_t p1; 71 | uint8_t p2; 72 | uint8_t numArgs; 73 | uint8_t tag[4]; 74 | uint8_t pinAuth[16]; 75 | uint8_t payload[MAX_PAYLOAD_SIZE]; 76 | }__attribute__((packed)) wallet_request; 77 | 78 | 79 | typedef enum 80 | { 81 | WalletSign = 0x10, 82 | WalletRegister = 0x11, 83 | WalletPin = 0x12, 84 | WalletReset= 0x13, 85 | WalletVersion= 0x14, 86 | WalletRng = 0x15, 87 | } WalletOperation; 88 | 89 | 90 | int16_t bridge_to_wallet(uint8_t * keyh, uint8_t klen); 91 | 92 | void wallet_init(); 93 | 94 | #endif /* WALLET_H_ */ 95 | -------------------------------------------------------------------------------- /firmware-hc/fido2/log.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #include 8 | #include 9 | #include 10 | #include "log.h" 11 | #include "util.h" 12 | #include "device.h" 13 | 14 | #if DEBUG_LEVEL > 0 15 | 16 | static uint32_t LOGMASK = TAG_FILENO; 17 | 18 | 19 | void set_logging_mask(uint32_t mask) 20 | { 21 | LOGMASK = mask; 22 | } 23 | 24 | 25 | struct logtag 26 | { 27 | uint32_t tagn; 28 | const char * tag; 29 | }; 30 | 31 | struct logtag tagtable[] = { 32 | {TAG_GEN,""}, 33 | {TAG_MC,"MC"}, 34 | {TAG_GA,"GA"}, 35 | {TAG_CP,"CP"}, 36 | {TAG_ERR,"ERR"}, 37 | {TAG_PARSE,"PARSE"}, 38 | {TAG_CTAP,"CTAP"}, 39 | {TAG_U2F,"U2F"}, 40 | {TAG_DUMP,"DUMP"}, 41 | {TAG_DUMP2,"DUMP2"}, 42 | {TAG_HID,"HID"}, 43 | {TAG_USB,"USB"}, 44 | {TAG_GREEN,"DEBUG"}, 45 | {TAG_RED,"DEBUG"}, 46 | {TAG_TIME,"TIME"}, 47 | {TAG_WALLET,"WALLET"}, 48 | {TAG_STOR,"STOR"}, 49 | {TAG_BOOT,"BOOT"}, 50 | {TAG_EXT,"EXT"}, 51 | {TAG_NFC,"NFC"}, 52 | {TAG_NFC_APDU, "NAPDU"}, 53 | {TAG_CCID, "CCID"}, 54 | }; 55 | 56 | 57 | __attribute__((weak)) void set_logging_tag(uint32_t tag) 58 | { 59 | // nothing 60 | } 61 | 62 | void LOG(uint32_t tag, const char * filename, int num, const char * fmt, ...) 63 | { 64 | unsigned int i; 65 | 66 | if (((tag & 0x7fffffff) & LOGMASK) == 0) 67 | { 68 | return; 69 | } 70 | for (i = 0; i < sizeof(tagtable)/sizeof(struct logtag); i++) 71 | { 72 | if (tag & tagtable[i].tagn) 73 | { 74 | if (tagtable[i].tag[0] && !(tag & TAG_NO_TAG)) printf("[%s] ", tagtable[i].tag); 75 | i = 0; 76 | break; 77 | } 78 | } 79 | if (i != 0) 80 | { 81 | printf2(TAG_ERR,"INVALID LOG TAG\n"); 82 | exit(1); 83 | } 84 | set_logging_tag(tag); 85 | #ifdef ENABLE_FILE_LOGGING 86 | if (tag & TAG_FILENO) 87 | { 88 | printf("%s:%d: ", filename, num); 89 | } 90 | #endif 91 | va_list args; 92 | va_start(args, fmt); 93 | vprintf(fmt, args); 94 | va_end(args); 95 | } 96 | 97 | void LOG_HEX(uint32_t tag, uint8_t * data, int length) 98 | { 99 | if (((tag & 0x7fffffff) & LOGMASK) == 0) 100 | { 101 | return; 102 | } 103 | set_logging_tag(tag); 104 | dump_hex(data,length); 105 | } 106 | 107 | uint32_t timestamp() 108 | { 109 | static uint32_t t1 = 0; 110 | uint32_t t2 = millis(); 111 | uint32_t diff = t2 - t1; 112 | t1 = t2; 113 | return diff; 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /firmware-hc/fido2/log.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef _LOG_H 8 | #define _LOG_H 9 | 10 | #define DEBUG_LEVEL 0 11 | 12 | #include 13 | 14 | #ifndef DEBUG_LEVEL 15 | #define DEBUG_LEVEL 0 16 | #endif 17 | 18 | #define ENABLE_FILE_LOGGING 19 | 20 | void LOG(uint32_t tag, const char * filename, int num, const char * fmt, ...); 21 | void LOG_HEX(uint32_t tag, uint8_t * data, int length); 22 | 23 | void set_logging_tag(uint32_t tag); 24 | 25 | typedef enum 26 | { 27 | TAG_GEN = (1 << 0), 28 | TAG_MC = (1 << 1), 29 | TAG_GA = (1 << 2), 30 | TAG_CP = (1 << 3), 31 | TAG_ERR = (1 << 4), 32 | TAG_PARSE = (1 << 5), 33 | TAG_CTAP = (1 << 6), 34 | TAG_U2F = (1 << 7), 35 | TAG_DUMP = (1 << 8), 36 | TAG_GREEN = (1 << 9), 37 | TAG_RED = (1 << 10), 38 | TAG_TIME = (1 << 11), 39 | TAG_HID = (1 << 12), 40 | TAG_USB = (1 << 13), 41 | TAG_WALLET = (1 << 14), 42 | TAG_STOR = (1 << 15), 43 | TAG_DUMP2 = (1 << 16), 44 | TAG_BOOT = (1 << 17), 45 | TAG_EXT = (1 << 18), 46 | TAG_NFC = (1 << 19), 47 | TAG_NFC_APDU = (1 << 20), 48 | TAG_CCID = (1 << 21), 49 | 50 | TAG_NO_TAG = (1UL << 30), 51 | TAG_FILENO = (1UL << 31) 52 | } LOG_TAG; 53 | 54 | #if DEBUG_LEVEL > 0 55 | 56 | void set_logging_mask(uint32_t mask); 57 | #define printf1(tag,fmt, ...) LOG(tag & ~(TAG_FILENO), NULL, 0, fmt, ##__VA_ARGS__) 58 | #define printf2(tag,fmt, ...) LOG(tag | TAG_FILENO,__FILE__, __LINE__, fmt, ##__VA_ARGS__) 59 | #define printf3(tag,fmt, ...) LOG(tag | TAG_FILENO,__FILE__, __LINE__, fmt, ##__VA_ARGS__) 60 | 61 | #define dump_hex1(tag,data,len) LOG_HEX(tag,data,len) 62 | 63 | uint32_t timestamp(); 64 | 65 | #else 66 | 67 | #define set_logging_mask(mask) 68 | #define printf1(tag,fmt, ...) 69 | #define printf2(tag,fmt, ...) 70 | #define printf3(tag,fmt, ...) 71 | #define dump_hex1(tag,data,len) 72 | #define timestamp() 73 | 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /firmware-hc/fido2/storage.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef _STORAGE_H 8 | #define _STORAGE_H 9 | 10 | #include "ctap.h" 11 | 12 | #define KEY_SPACE_BYTES 128 13 | #define MAX_KEYS (1) 14 | #define PIN_SALT_LEN (32) 15 | #define STATE_VERSION (1) 16 | 17 | 18 | #define BACKUP_MARKER 0x5A 19 | #define INITIALIZED_MARKER 0xA5 20 | 21 | #define ERR_NO_KEY_SPACE (-1) 22 | #define ERR_KEY_SPACE_TAKEN (-2) 23 | #define ERR_KEY_SPACE_EMPTY (-2) 24 | 25 | typedef struct 26 | { 27 | // Pin information 28 | uint8_t is_initialized; 29 | uint8_t is_pin_set; 30 | uint8_t pin_code[NEW_PIN_ENC_MIN_SIZE]; 31 | int pin_code_length; 32 | int8_t remaining_tries; 33 | 34 | uint16_t rk_stored; 35 | 36 | uint16_t key_lens[MAX_KEYS]; 37 | uint8_t key_space[KEY_SPACE_BYTES]; 38 | } AuthenticatorState_0xFF; 39 | 40 | 41 | typedef struct 42 | { 43 | // Pin information 44 | uint8_t is_initialized; 45 | uint8_t is_pin_set; 46 | uint8_t PIN_CODE_HASH[32]; 47 | uint8_t PIN_SALT[PIN_SALT_LEN]; 48 | int _reserved; 49 | int8_t remaining_tries; 50 | 51 | uint16_t rk_stored; 52 | 53 | uint16_t key_lens[MAX_KEYS]; 54 | uint8_t key_space[KEY_SPACE_BYTES]; 55 | uint8_t data_version; 56 | } AuthenticatorState_0x01; 57 | 58 | typedef AuthenticatorState_0x01 AuthenticatorState; 59 | 60 | 61 | typedef struct 62 | { 63 | uint32_t addr; 64 | uint8_t * filename; 65 | uint32_t count; 66 | } AuthenticatorCounter; 67 | 68 | extern AuthenticatorState STATE; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /firmware-hc/fido2/stubs.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #include 8 | #include "device.h" 9 | #include "util.h" 10 | #include "ctap.h" 11 | #include "u2f.h" 12 | 13 | #if defined(STUB_CTAPHID) || defined(STUB_CTAP) 14 | 15 | 16 | 17 | void ctap_init() 18 | { 19 | printf1(TAG_GEN,"STUB: ctap_init\n"); 20 | } 21 | #endif 22 | 23 | #if defined(STUB_CTAPHID) 24 | void ctaphid_init() 25 | { 26 | printf1(TAG_GEN,"STUB: ctaphid_init\n"); 27 | } 28 | void ctaphid_handle_packet(uint8_t * hidmsg) 29 | { 30 | printf1(TAG_GEN,"STUB: ctaphid_handle_packet\n"); 31 | } 32 | 33 | void ctaphid_check_timeouts() 34 | { 35 | 36 | } 37 | 38 | #endif 39 | 40 | 41 | #ifdef STUB_CTAP 42 | 43 | void ctap_reset_state() 44 | { 45 | printf1(TAG_GEN,"STUB: ctap_reset_state\n"); 46 | } 47 | 48 | void ctap_response_init(CTAP_RESPONSE * resp) 49 | { 50 | } 51 | 52 | void u2f_request(struct u2f_request_apdu* req, CTAP_RESPONSE * resp) 53 | { 54 | printf1(TAG_GEN,"STUB: u2f_request\n"); 55 | } 56 | 57 | uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp) 58 | { 59 | printf1(TAG_GEN,"STUB: ctap_request\n"); 60 | return 0; 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /firmware-hc/fido2/util.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #include 8 | #include 9 | 10 | void dump_hex(uint8_t * buf, int size) 11 | { 12 | while(size--) 13 | { 14 | printf("%02x ", *buf++); 15 | } 16 | printf("\n"); 17 | } 18 | -------------------------------------------------------------------------------- /firmware-hc/fido2/util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 SoloKeys Developers 2 | // 3 | // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 6 | // copied, modified, or distributed except according to those terms. 7 | #ifndef _UTIL_H 8 | #define _UTIL_H 9 | 10 | #include 11 | 12 | void dump_hex(uint8_t * buf, int size); 13 | 14 | #ifndef MIN 15 | #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 16 | #endif 17 | 18 | #ifndef MAX 19 | #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /firmware-hc/fido2/version.h: -------------------------------------------------------------------------------- 1 | #ifndef _VERSION_H_ 2 | #define _VERSION_H_ 3 | 4 | 5 | #ifndef SOLO_VERSION_MAJ 6 | 7 | #define SOLO_VERSION_MAJ 0 8 | #define SOLO_VERSION_MIN 0 9 | #define SOLO_VERSION_PATCH 0 10 | 11 | #endif 12 | 13 | #define __STR_HELPER(x) #x 14 | #define __STR(x) __STR_HELPER(x) 15 | 16 | #ifndef SOLO_VERSION 17 | #define SOLO_VERSION __STR(SOLO_VERSION_MAJ) "." __STR(SOLO_VERSION_MIN) "." __STR(SOLO_VERSION_PATCH) 18 | #endif 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /firmware-hc/firmware_update_state.h: -------------------------------------------------------------------------------- 1 | #ifndef FIRMWARE_UPDATE_STATE_H 2 | #define FIRMWARE_UPDATE_STATE_H 3 | 4 | #include "types.h" 5 | 6 | int firmware_update_state(int cmd, u8 *data, int data_len); 7 | int erasing_pages_state(int cmd, u8 *data, int data_len); 8 | 9 | void firmware_update_write_block_complete(); 10 | 11 | void switch_boot_mode_cmd(u8 *data, int data_len); 12 | void update_firmware_cmd(u8 *data, int data_len); 13 | void update_firmware_cmd_complete(); 14 | void write_flash_cmd_complete(); 15 | #endif 16 | -------------------------------------------------------------------------------- /firmware-hc/flash.h: -------------------------------------------------------------------------------- 1 | #ifndef FLASH_H 2 | #define FLASH_H 3 | #include "types.h" 4 | #include "signetdev_hc_common.h" 5 | 6 | void flash_write_page(u8 *dest, const u8 *src, int count); 7 | int flash_write(u8 *dest, const u8 *src, int count); 8 | u32 flash_sector_to_addr(int x); 9 | int flash_addr_to_sector(u32 addr); 10 | void flash_idle(); 11 | int flash_idle_ready(); 12 | void flash_unlock(); 13 | int flash_writing(); 14 | int is_flash_idle(); 15 | 16 | enum hc_boot_mode flash_get_boot_mode(); 17 | void flash_set_boot_mode(enum hc_boot_mode mode); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /firmware-hc/hc_firmware_encoder.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | typedef unsigned char u8; 5 | #include "signetdev_hc_common.h" 6 | #include 7 | 8 | struct hc_firmware_file_header fw_file_hdr; 9 | struct hc_firmware_file_body fw_file_body; 10 | 11 | int main(int argc, char **argv) 12 | { 13 | if (argc <= 5) 14 | return -1; 15 | FILE *fwA = fopen(argv[1],"rb"); 16 | FILE *fwB = fopen(argv[2],"rb"); 17 | FILE *fwOut = fopen(argv[3],"wb"); 18 | fseek(fwA, 0L, SEEK_END); 19 | int szA = ftell(fwA); 20 | fseek(fwA, 0, SEEK_SET); 21 | 22 | fseek(fwB, 0L, SEEK_END); 23 | int szB = ftell(fwB); 24 | fseek(fwB, 0, SEEK_SET); 25 | 26 | memset(&fw_file_hdr, 0, sizeof(fw_file_hdr)); 27 | memset(&fw_file_body, 0, sizeof(fw_file_body)); 28 | 29 | fread(fw_file_body.firmware_A, 1, szA, fwA); 30 | fread(fw_file_body.firmware_B, 1, szB, fwB); 31 | 32 | fw_file_hdr.fw_version.major = atoi(argv[4]); 33 | fw_file_hdr.fw_version.minor = atoi(argv[5]); 34 | fw_file_hdr.fw_version.step = atoi(argv[6]); 35 | fw_file_hdr.fw_version.padding = 0;; 36 | fw_file_hdr.file_prefix = HC_FIRMWARE_FILE_PREFIX; 37 | fw_file_hdr.file_version = HC_FIRMWARE_FILE_VERSION; 38 | fw_file_hdr.header_size = sizeof(fw_file_hdr); 39 | fw_file_hdr.A_len = szA; 40 | fw_file_hdr.A_crc = crc32(0, fw_file_body.firmware_A, sizeof(fw_file_body.firmware_A)); 41 | fw_file_hdr.B_len = szB; 42 | fw_file_hdr.B_crc = crc32(0, fw_file_body.firmware_B, sizeof(fw_file_body.firmware_B)); 43 | 44 | fwrite(&fw_file_hdr, 1, sizeof(fw_file_hdr),fwOut); 45 | fwrite(&fw_file_body, 1, sizeof(fw_file_body),fwOut); 46 | fclose(fwOut); 47 | } 48 | -------------------------------------------------------------------------------- /firmware-hc/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include "stm32f7xx_hal.h" 5 | #include "usbd_core.h" 6 | #include "usbd_desc.h" 7 | #include "usbd_multi.h" 8 | 9 | #define LOW_INT_PRIORITY (3) 10 | #define DEFAULT_INT_PRIORITY (2) 11 | #define HIGH_INT_PRIORITY (1) 12 | #define HIGHEST_INT_PRIORITY (0) 13 | 14 | #define ENABLE_MMC_STANDBY 0 15 | 16 | void led_on(); 17 | void led_off(); 18 | void start_blinking(int period, int duration); 19 | void stop_blinking(); 20 | void pause_blinking(); 21 | void resume_blinking(); 22 | int is_blinking(); 23 | void timer_start(int ms); 24 | void timer_stop(); 25 | #ifndef assert 26 | void assert(int cont); 27 | #endif 28 | void assert_lit(int cont, int l1, int l2); 29 | void Error_Handler(); 30 | 31 | extern PCD_HandleTypeDef hpcd_USB_OTG_HS; 32 | 33 | int is_ctap_initialized(); 34 | 35 | #define KEYBOARD_WORK (1<<0) 36 | #define READ_DB_TX_WORK (1<<1) 37 | #define WRITE_DB_TX_WORK (1<<2) 38 | #define MMC_TX_CPLT_WORK (1<<3) 39 | #define MMC_TX_DMA_CPLT_WORK (1<<4) 40 | #define MMC_RX_CPLT_WORK (1<<5) 41 | #define READ_DB_TX_CPLT_WORK (1<<6) 42 | #define FLASH_WORK (1<<7) 43 | #define USBD_SCSI_WORK (1<<8) 44 | #define SYNC_ROOT_BLOCK_WORK (1<<9) 45 | #define BUTTON_PRESS_WORK (1<<10) 46 | #define BUTTON_PRESSING_WORK (1<<11) 47 | #define TIMER_WORK (1<<12) 48 | #define BLINK_WORK (1<<13) 49 | #define WORK_STATUS_WORK (1<<14) 50 | 51 | #if ENABLE_MMC_STANDBY 52 | #define MMC_IDLE_WORK (1<<15) 53 | #endif 54 | 55 | extern volatile int g_work_to_do; 56 | 57 | #define BEGIN_WORK(w) do {\ 58 | __disable_irq();\ 59 | g_work_to_do |= w; \ 60 | __enable_irq();\ 61 | } while (0) 62 | 63 | #define END_WORK(w) do {\ 64 | __disable_irq();\ 65 | g_work_to_do &= ~w;\ 66 | __enable_irq();\ 67 | } while (0) 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /firmware-hc/print.h: -------------------------------------------------------------------------------- 1 | #ifndef PRINT_H 2 | #define PRINT_H 3 | 4 | #include "types.h" 5 | 6 | #define dprint_s(s) 7 | #define dprint_dec(s) 8 | #define dprint_hex(s) 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /firmware-hc/rand.c: -------------------------------------------------------------------------------- 1 | #include "rand.h" 2 | 3 | #ifdef BOOT_MODE_B 4 | 5 | #include "rtc_rand.h" 6 | #include "rng_rand.h" 7 | #include "fido2/ctap.h" 8 | #include "commands.h" 9 | #include "stm32f733xx.h" 10 | 11 | struct rand_src_state rng_rand_state; 12 | struct rand_src_state rtc_rand_state; 13 | 14 | void rand_init() 15 | { 16 | rng_rand_state.rewind_tail = -1; 17 | rtc_rand_state.rewind_tail = -1; 18 | } 19 | 20 | static void rand_src_rewind(struct rand_src_state *src) 21 | { 22 | if (src->rewind_tail >= 0) { 23 | src->level = src->rewind_level; 24 | src->tail = src->rewind_tail; 25 | } 26 | } 27 | 28 | void rand_rewind() 29 | { 30 | rand_src_rewind(&rng_rand_state); 31 | rand_src_rewind(&rtc_rand_state); 32 | } 33 | 34 | int rand_avail() 35 | { 36 | int rtc_level = rtc_rand_state.level; 37 | int rng_level = rng_rand_state.level; 38 | return (rtc_level > rng_level) ? rng_level : rtc_level; 39 | } 40 | 41 | static u32 rand_src_get(struct rand_src_state *src) 42 | { 43 | if (src->head == src->tail) 44 | return 0; 45 | u32 ret = src->buf[src->tail]; 46 | src->tail = (src->tail + 1) % 1024; 47 | src->level--; 48 | return ret; 49 | } 50 | 51 | u32 rand_get() 52 | { 53 | u32 rtc_val = rand_src_get(&rtc_rand_state); 54 | u32 rng_val = rand_src_get(&rng_rand_state); 55 | rng_rand_irq_enable(1); 56 | rtc_rand_irq_enable(1); 57 | return rtc_val ^ rng_val; 58 | } 59 | 60 | static void rand_src_rewind_point(struct rand_src_state *src) 61 | { 62 | src->rewind_tail = src->tail; 63 | src->rewind_level = src->level; 64 | } 65 | 66 | void rand_set_rewind_point() 67 | { 68 | rand_src_rewind_point(&rtc_rand_state); 69 | rand_src_rewind_point(&rng_rand_state); 70 | } 71 | 72 | void rand_clear_rewind_point() 73 | { 74 | rtc_rand_state.rewind_tail = -1; 75 | rng_rand_state.rewind_tail = -1; 76 | rng_rand_irq_enable(1); 77 | rtc_rand_irq_enable(1); 78 | } 79 | 80 | void rand_push(enum rand_src _src, u32 val) 81 | { 82 | struct rand_src_state *src; 83 | switch(_src) { 84 | case RAND_SRC_TRNG: 85 | src = &rng_rand_state; 86 | break; 87 | case RAND_SRC_RTC: 88 | src = &rtc_rand_state; 89 | break; 90 | default: 91 | return; 92 | } 93 | int next_head = (src->head + 1) % 1024; 94 | int tail = (src->rewind_tail < 0) ? src->tail : src->rewind_tail; 95 | if (next_head != tail) { 96 | src->buf[src->head] ^= val; 97 | src->level++; 98 | src->head = next_head; 99 | if (src->rewind_tail >= 0) { 100 | src->rewind_level++; 101 | } 102 | rand_update(_src); 103 | } else { 104 | switch (_src) { 105 | case RAND_SRC_TRNG: 106 | rng_rand_irq_enable(0); 107 | break; 108 | case RAND_SRC_RTC: 109 | rtc_rand_irq_enable(0); 110 | break; 111 | } 112 | } 113 | } 114 | 115 | void rand_update(enum rand_src src) 116 | { 117 | 118 | switch (device_subsystem_owner()) { 119 | case SIGNET_SUBSYSTEM: 120 | cmd_rand_update(); 121 | break; 122 | #ifdef ENABLE_FIDO2 123 | case CTAP_SUBSYSTEM: 124 | ctap_rand_update(); 125 | break; 126 | #endif 127 | default: 128 | break; 129 | } 130 | } 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /firmware-hc/rand.h: -------------------------------------------------------------------------------- 1 | #ifndef RAND_H 2 | #define RAND_H 3 | 4 | #include "types.h" 5 | 6 | void rand_init(); 7 | int rand_avail(); 8 | u32 rand_get(); 9 | 10 | void rand_set_rewind_point(); 11 | void rand_rewind(); 12 | void rand_clear_rewind_point(); 13 | 14 | enum rand_owner { 15 | RAND_OWNER_COMMAND, 16 | RAND_OWNER_CTAP, 17 | RAND_OWNER_NONE 18 | }; 19 | 20 | enum rand_src { 21 | RAND_SRC_TRNG, 22 | RAND_SRC_RTC 23 | }; 24 | 25 | int rand_begin_read(enum rand_owner owner); 26 | void rand_end_read(enum rand_owner owner); 27 | void rand_update(enum rand_src src); 28 | 29 | struct rand_src_state { 30 | u32 buf[1024]; 31 | int head; 32 | int level; 33 | int tail; 34 | int rewind_level; 35 | int rewind_tail; 36 | }; 37 | 38 | void rand_push(enum rand_src src, u32 val); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /firmware-hc/rng_rand.c: -------------------------------------------------------------------------------- 1 | #include "print.h" 2 | #include "commands.h" 3 | #include "types.h" 4 | #include "stm32f7xx.h" 5 | 6 | #ifdef BOOT_MODE_B 7 | 8 | #ifdef ENABLE_FIDO2 9 | #include "fido2/ctap.h" 10 | #endif 11 | #include "rand.h" 12 | void rng_init() 13 | { 14 | RNG->CR = RNG_CR_RNGEN | RNG_CR_IE; 15 | } 16 | void rng_rand_irq_enable(int en) 17 | { 18 | if (en) { 19 | RNG->CR |= RNG_CR_IE; 20 | } else { 21 | RNG->CR &= ~RNG_CR_IE; 22 | } 23 | } 24 | 25 | void RNG_IRQHandler() 26 | { 27 | if (RNG->SR & RNG_SR_DRDY) { 28 | rand_push(RAND_SRC_TRNG, RNG->DR); 29 | } else { 30 | RNG->SR |= RNG_SR_CECS; 31 | RNG->SR |= RNG_SR_SECS; 32 | } 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /firmware-hc/rng_rand.h: -------------------------------------------------------------------------------- 1 | #ifndef RNG_RAND_H 2 | #define RNG_RAND_H 3 | 4 | #include "types.h" 5 | 6 | void rng_init(); 7 | 8 | int rng_rand_avail(); 9 | u32 rng_rand_get(); 10 | 11 | void rng_rand_set_rewind_point(); 12 | void rng_rand_rewind(); 13 | void rng_rand_clear_rewind_point(); 14 | 15 | void rng_rand_irq_enable(int en); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /firmware-hc/rtc_rand.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "rtc_rand.h" 4 | #include "types.h" 5 | #include "commands.h" 6 | #include "stm32f7xx.h" 7 | 8 | #ifdef BOOT_MODE_B 9 | 10 | #ifdef ENABLE_FIDO2 11 | #include "fido2/ctap.h" 12 | #endif 13 | 14 | #include "rand.h" 15 | 16 | void rtc_rand_irq_enable(int en) 17 | { 18 | if (en) { 19 | RTC->CR |= RTC_CR_WUTIE; 20 | } else { 21 | RTC->CR &= ~RTC_CR_WUTIE; 22 | } 23 | } 24 | 25 | void RTC_WKUP_IRQHandler(void) 26 | { 27 | static u32 rndtemp = 0; 28 | static u32 rndtemp_i = 0; 29 | u32 clk = DWT->CYCCNT; 30 | u32 rnd = (clk & 1); 31 | clk>>=1; 32 | rnd ^= (clk & 1); 33 | clk >>=1; 34 | rnd ^= (clk & 1); 35 | clk >>=1; 36 | rnd ^= (clk & 1); 37 | clk >>=1; 38 | rnd ^= (clk & 1); 39 | clk >>=1; 40 | rndtemp <<= 1; 41 | rndtemp |= rnd; 42 | rndtemp_i++; 43 | if (rndtemp_i >= 32) { 44 | rndtemp_i = 0; 45 | rand_push(RAND_SRC_RTC, rndtemp); 46 | } 47 | RTC->ISR &= ~(RTC_ISR_WUTF); 48 | EXTI->PR = 1 << RTC_EXTI_LINE; 49 | } 50 | 51 | void rtc_rand_init(u16 rate) 52 | { 53 | RTC->WPR = 0xCA;//RTC_WPR_KEY1; 54 | RTC->WPR = 0x53;//RTC_WPR_KEY2; 55 | 56 | RTC->CR &= ~RTC_CR_WUTE; 57 | while (!(RTC->ISR & RTC_ISR_WUTWF)); 58 | RTC->CR &= ~0x3; //WUT = RTC/16 == 2Khz 59 | RTC->WUTR = rate; 60 | RTC->ISR &= ~(RTC_ISR_WUTF); 61 | RTC->CR |= RTC_CR_WUTE | RTC_CR_WUTIE; 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /firmware-hc/rtc_rand.h: -------------------------------------------------------------------------------- 1 | #ifndef RTC_RAND_H 2 | #define RTC_RAND_H 3 | 4 | #include "types.h" 5 | 6 | void rtc_rand_init(u16 rate); 7 | int rtc_rand_avail(); 8 | u32 rtc_rand_get(); 9 | 10 | void rtc_rand_set_rewind_point(); 11 | void rtc_rand_rewind(); 12 | void rtc_rand_clear_rewind_point(); 13 | 14 | #define RTC_EXTI_LINE (22) 15 | 16 | void rtc_rand_irq_enable(int en); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /firmware-hc/signet-hc-build-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Make common ct-ng if needed 5 | # 6 | if [ ! -e ../crosstool-ng/ct-ng ]; then 7 | pushd ../crosstool-ng && 8 | ./bootstrap && 9 | ./configure --enable-local && 10 | make || exit -1 11 | popd 12 | fi 13 | 14 | # 15 | #Build toolchain in "toolchain/" folder 16 | # 17 | pushd ct-ng 18 | ../../crosstool-ng/ct-ng build || exit -1 19 | popd 20 | 21 | # 22 | #Environment 23 | # 24 | FW_SOURCE_ROOT=$PWD 25 | TARGET_TUPLE=arm-none-eabi 26 | TOOLCHAIN=$FW_SOURCE_ROOT/toolchain/$TARGET_TUPLE 27 | SYSROOT=$TOOLCHAIN/$TARGET_TUPLE 28 | CFLAGS="-nostartfiles -ffunction-sections -fdata-sections -O2 -Os -I$SYSROOT/include -L$SYSROOT/lib" 29 | export PATH=$TOOLCHAIN/bin:$PATH 30 | 31 | # 32 | # Make sysroot folders writable so we can install mini-gmp and nettle 33 | # 34 | chmod u+w $SYSROOT/include $SYSROOT/lib 35 | 36 | # 37 | # Install mini-gmp 38 | # 39 | pushd external/mini-gmp/mini-gmp 40 | $TARGET_TUPLE-gcc $CFLAGS -c mini-gmp.c || exit -1 41 | rm libmini-gmp.a 42 | $TARGET_TUPLE-ar -r libmini-gmp.a mini-gmp.o 43 | cp libmini-gmp.a $SYSROOT/lib 44 | cp mini-gmp.h $SYSROOT/include 45 | popd 46 | 47 | # 48 | # Install nettle 49 | # 50 | mkdir -p external/nettle/build-hc 51 | pushd external/nettle 52 | autoconf && 53 | autoheader && 54 | pushd build-hc && 55 | ../configure \ 56 | --disable-assembler \ 57 | --disable-documentation \ 58 | --disable-shared \ 59 | --disable-pic \ 60 | --enable-mini-gmp \ 61 | --enable-public-key \ 62 | --host=arm-none-eabi \ 63 | --prefix=$SYSROOT && 64 | make && 65 | make install && 66 | echo "Toolchain and dependecies are ready!" 67 | popd 68 | popd 69 | -------------------------------------------------------------------------------- /firmware-hc/signet_aes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "signet_aes.h" 3 | 4 | #include "nettle/aes.h" 5 | #include "signetdev_common.h" 6 | 7 | void signet_aes_init() 8 | { 9 | } 10 | 11 | void signet_aes_128_encrypt(const u8 *key, const u8 *din, u8 *dout) 12 | { 13 | struct aes128_ctx ctx; 14 | aes128_set_encrypt_key(&ctx, key); 15 | aes128_encrypt(&ctx, AES_BLK_SIZE, dout, din); 16 | } 17 | 18 | void signet_aes_256_encrypt(const u8 *key, const u8 *din, u8 *dout) 19 | { 20 | struct aes256_ctx ctx; 21 | aes256_set_encrypt_key(&ctx, key); 22 | aes256_encrypt(&ctx, AES_BLK_SIZE, dout, din); 23 | } 24 | 25 | void xor_block(const u8 *src_block, const u8 *mask, u8 *dst_block) 26 | { 27 | int i; 28 | if (mask) { 29 | for (i = 0; i < AES_BLK_SIZE; i++) { 30 | dst_block[i] = src_block[i] ^ mask[i]; 31 | } 32 | } else { 33 | memcpy(dst_block, src_block, AES_BLK_SIZE); 34 | } 35 | } 36 | 37 | void signet_aes_128_encrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout) 38 | { 39 | int i; 40 | for (i = 0; i < n_blocks; i++) { 41 | u8 temp[AES_BLK_SIZE]; 42 | xor_block(din, iv, temp); 43 | signet_aes_128_encrypt(key, temp, dout); 44 | iv = dout; 45 | din += AES_BLK_SIZE; 46 | dout += AES_BLK_SIZE; 47 | } 48 | } 49 | 50 | void signet_aes_256_encrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout) 51 | { 52 | int i; 53 | for (i = 0; i < n_blocks; i++) { 54 | u8 temp[AES_BLK_SIZE]; 55 | xor_block(din, iv, temp); 56 | signet_aes_256_encrypt(key, temp, dout); 57 | iv = dout; 58 | din += AES_BLK_SIZE; 59 | dout += AES_BLK_SIZE; 60 | } 61 | } 62 | 63 | void signet_aes_128_decrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout) 64 | { 65 | int i; 66 | for (i = 0; i < n_blocks; i++) { 67 | u8 temp[AES_BLK_SIZE]; 68 | signet_aes_128_decrypt(key, din, temp); 69 | xor_block(temp, iv, dout); 70 | iv = din; 71 | din += AES_BLK_SIZE; 72 | dout += AES_BLK_SIZE; 73 | } 74 | } 75 | 76 | void signet_aes_256_decrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout) 77 | { 78 | int i; 79 | for (i = 0; i < n_blocks; i++) { 80 | u8 temp[AES_BLK_SIZE]; 81 | signet_aes_256_decrypt(key, din, temp); 82 | xor_block(temp, iv, dout); 83 | iv = din; 84 | din += AES_BLK_SIZE; 85 | dout += AES_BLK_SIZE; 86 | } 87 | } 88 | 89 | void signet_aes_128_decrypt(const u8 *key, const u8 *din, u8 *dout) 90 | { 91 | struct aes128_ctx ctx; 92 | aes128_set_decrypt_key(&ctx, key); 93 | aes128_decrypt(&ctx, AES_BLK_SIZE, dout, din); 94 | } 95 | 96 | void signet_aes_256_decrypt(const u8 *key, const u8 *din, u8 *dout) 97 | { 98 | struct aes256_ctx ctx; 99 | aes256_set_decrypt_key(&ctx, key); 100 | aes256_decrypt(&ctx, AES_BLK_SIZE, dout, din); 101 | } 102 | -------------------------------------------------------------------------------- /firmware-hc/signet_aes.h: -------------------------------------------------------------------------------- 1 | #ifndef SIGNET_AES_H 2 | #define SIGNET_AES_H 3 | 4 | #include "types.h" 5 | 6 | void signet_aes_init(); 7 | void signet_aes_128_encrypt(const u8 *key, const u8 *din, u8 *dout); 8 | void signet_aes_128_decrypt(const u8 *key, const u8 *din, u8 *dout); 9 | void signet_aes_128_decrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout); 10 | void signet_aes_128_encrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout); 11 | void signet_aes_256_encrypt(const u8 *key, const u8 *din, u8 *dout); 12 | void signet_aes_256_decrypt(const u8 *key, const u8 *din, u8 *dout); 13 | void signet_aes_256_decrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout); 14 | void signet_aes_256_encrypt_cbc(const u8 *key, int n_blocks, const u8 *iv, const u8 *din, u8 *dout); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /firmware-hc/stm32f733xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nthdimtech/signet-base/3d3a5930a6e3b763579e29463617ed42b7fcaeae/firmware-hc/stm32f733xx.h -------------------------------------------------------------------------------- /firmware-hc/stm32f7xx/stm32f7xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nthdimtech/signet-base/3d3a5930a6e3b763579e29463617ed42b7fcaeae/firmware-hc/stm32f7xx/stm32f7xx.h -------------------------------------------------------------------------------- /firmware-hc/stm32f7xx/stm32f7xx_hal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nthdimtech/signet-base/3d3a5930a6e3b763579e29463617ed42b7fcaeae/firmware-hc/stm32f7xx/stm32f7xx_hal -------------------------------------------------------------------------------- /firmware-hc/stm32f7xx/stm32f7xx_hal_cryp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nthdimtech/signet-base/3d3a5930a6e3b763579e29463617ed42b7fcaeae/firmware-hc/stm32f7xx/stm32f7xx_hal_cryp.c -------------------------------------------------------------------------------- /firmware-hc/stm32f7xx/stm32f7xx_hal_cryp_ex.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nthdimtech/signet-base/3d3a5930a6e3b763579e29463617ed42b7fcaeae/firmware-hc/stm32f7xx/stm32f7xx_hal_cryp_ex.c -------------------------------------------------------------------------------- /firmware-hc/stm32f7xx/stm32f7xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f7xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F7xx_HAL_PCD_EX_H 22 | #define STM32F7xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f7xx_hal_def.h" 30 | 31 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 32 | /** @addtogroup STM32F7xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 51 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 52 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 53 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 54 | 55 | 56 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 57 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 58 | 59 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 60 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | 84 | #endif /* STM32F7xx_HAL_PCD_EX_H */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /firmware-hc/stm32f7xx/stm32f7xx_it.c: -------------------------------------------------------------------------------- 1 | /* Includes ------------------------------------------------------------------*/ 2 | #include "main.h" 3 | #include "stm32f7xx_it.h" 4 | 5 | void Error_Handler(); 6 | 7 | /******************************************************************************/ 8 | /* Cortex-M7 Processor Interruption and Exception Handlers */ 9 | /******************************************************************************/ 10 | /** 11 | * @brief This function handles Non maskable interrupt. 12 | */ 13 | void NMI_Handler(void) 14 | { 15 | } 16 | 17 | /** 18 | * @brief This function handles Hard fault interrupt. 19 | */ 20 | void HardFault_Handler(void) 21 | { 22 | Error_Handler(); 23 | } 24 | 25 | /** 26 | * @brief This function handles Memory management fault. 27 | */ 28 | void MemManage_Handler(void) 29 | { 30 | Error_Handler(); 31 | } 32 | 33 | /** 34 | * @brief This function handles Pre-fetch fault, memory access fault. 35 | */ 36 | void BusFault_Handler(void) 37 | { 38 | Error_Handler(); 39 | } 40 | 41 | /** 42 | * @brief This function handles Undefined instruction or illegal state. 43 | */ 44 | void UsageFault_Handler(void) 45 | { 46 | Error_Handler(); 47 | } 48 | 49 | /** 50 | * @brief This function handles System service call via SWI instruction. 51 | */ 52 | void SVC_Handler(void) 53 | { 54 | } 55 | 56 | /** 57 | * @brief This function handles Debug monitor. 58 | */ 59 | void DebugMon_Handler(void) 60 | { 61 | } 62 | 63 | /** 64 | * @brief This function handles Pendable request for system service. 65 | */ 66 | void PendSV_Handler(void) 67 | { 68 | } 69 | 70 | /** 71 | * @brief This function handles System tick timer. 72 | */ 73 | void SysTick_Handler(void) 74 | { 75 | HAL_IncTick(); 76 | } 77 | 78 | extern PCD_HandleTypeDef hpcd; 79 | 80 | void OTG_HS_IRQHandler(void) 81 | { 82 | HAL_PCD_IRQHandler(&hpcd); 83 | } 84 | 85 | void OTG_HS_WKUP_IRQHandler(void) 86 | { 87 | __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG(); 88 | } 89 | /******************************************************************************/ 90 | /* STM32F7xx Peripheral Interrupt Handlers */ 91 | /* Add here the Interrupt Handlers for the used peripherals. */ 92 | /* For the available peripheral interrupt handler names, */ 93 | /* please refer to the startup file (startup_stm32f7xx.s). */ 94 | /******************************************************************************/ 95 | 96 | /* USER CODE BEGIN 1 */ 97 | 98 | /* USER CODE END 1 */ 99 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 100 | -------------------------------------------------------------------------------- /firmware-hc/stm32f7xx/stm32f7xx_it.h: -------------------------------------------------------------------------------- 1 | #ifndef __STM32F7xx_IT_H 2 | #define __STM32F7xx_IT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | /* Exported functions prototypes ---------------------------------------------*/ 10 | void NMI_Handler(void); 11 | void HardFault_Handler(void); 12 | void MemManage_Handler(void); 13 | void BusFault_Handler(void); 14 | void UsageFault_Handler(void); 15 | void SVC_Handler(void); 16 | void DebugMon_Handler(void); 17 | void PendSV_Handler(void); 18 | void SysTick_Handler(void); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif /* __STM32F7xx_IT_H */ 25 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.5.3-build-{build} 2 | pull_requests: 3 | do_not_increment_build_number: true 4 | image: 5 | - Visual Studio 2015 6 | - Visual Studio 2013 7 | - Visual Studio 2017 8 | install: 9 | - cmd: >- 10 | set tests=1 11 | 12 | if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" (call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64) & (set tests=0) 13 | 14 | if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86) & (set QTDIR=C:\Qt\5.9\msvc2015) 15 | 16 | if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64) & (set QTDIR=C:\Qt\5.9\msvc2017_64) 17 | 18 | set path=%PATH%;%QTDIR%\bin 19 | build_script: 20 | - cmd: >- 21 | nmake -f Makefile.nmake -nologo CFLAGS="-W3 -Os -MDd" 22 | 23 | cd tests 24 | 25 | if /i "%tests%"=="1" qmake CONFIG-=release CONFIG+=debug 26 | 27 | if /i "%tests%"=="1" nmake -nologo -s 28 | test_script: 29 | - cmd: >- 30 | if /i "%tests%"=="1" nmake -s -nologo TESTARGS=-silent check 31 | 32 | if /i "%tests%"=="0" echo Tests skipped. 33 | artifacts: 34 | - path: lib\tinycbor.lib 35 | deploy: off 36 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/.tag: -------------------------------------------------------------------------------- 1 | 3d3a5930a6e3b763579e29463617ed42b7fcaeae 2 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | matrix: 3 | include: 4 | - os: linux 5 | dist: xenial 6 | addons: 7 | apt: 8 | sources: 9 | - sourceline: 'ppa:beineri/opt-qt-5.12.1-xenial' 10 | packages: 11 | - qt512base valgrind 12 | - doxygen 13 | env: 14 | - QMAKESPEC=linux-g++ 15 | - EVAL="CC=gcc && CXX=g++" 16 | - CFLAGS="-Os" 17 | - LDFLAGS="-Wl,--no-undefined -lm" 18 | - QMAKEFLAGS="-config release" 19 | - QT_NO_CPU_FEATURE=rdrnd 20 | - os: linux 21 | dist: xenial 22 | addons: 23 | apt: 24 | sources: 25 | - sourceline: 'ppa:beineri/opt-qt-5.12.1-xenial' 26 | packages: 27 | - qt512base 28 | env: 29 | - QMAKESPEC=linux-clang 30 | - EVAL="CC=clang && CXX=clang++" 31 | - CFLAGS="-Oz" 32 | - LDFLAGS="-Wl,--no-undefined -lm" 33 | - QMAKEFLAGS="-config release" 34 | - MAKEFLAGS=-s 35 | - TESTARGS=-silent 36 | - os: linux 37 | dist: xenial 38 | env: 39 | - QMAKESPEC=linux-gcc-freestanding 40 | - EVAL="CXX=false" 41 | - CFLAGS="-ffreestanding -Os" 42 | - LDFLAGS="-Wl,--no-undefined -lm" 43 | - os: linux 44 | dist: xenial 45 | env: 46 | - QMAKESPEC=linux-gcc-no-math 47 | - EVAL="CXX=false && touch src/math.h src/float.h" 48 | - CFLAGS="-ffreestanding -DCBOR_NO_FLOATING_POINT -Os" 49 | - LDFLAGS="-Wl,--no-undefined" 50 | - LDLIBS="" 51 | - os: osx 52 | env: 53 | - QMAKESPEC=macx-clang 54 | - CFLAGS="-Oz" 55 | - QMAKEFLAGS="-config debug" 56 | - MAKEFLAGS=-s 57 | - TESTARGS=-silent 58 | - PATH=/usr/local/opt/qt5/bin:$PATH 59 | install: 60 | - if [ "${TRAVIS_OS_NAME}" != "linux" ]; then 61 | brew update; 62 | brew install qt5; 63 | fi 64 | script: 65 | - PATH=`echo /opt/qt*/bin`:$PATH 66 | - eval "$EVAL" 67 | - make -s -f Makefile.configure configure | tee .config 68 | - make -k 69 | CFLAGS="$CFLAGS -march=native -g1 -Wall -Wextra -Werror" 70 | CPPFLAGS="-DNDEBUG" 71 | lib/libtinycbor.a 72 | - size lib/libtinycbor.a | tee sizes 73 | - make -s clean 74 | - make -k 75 | CFLAGS="$CFLAGS -O0 -g" 76 | LDFLAGS="$LDFLAGS" ${LDLIBS+LDLIBS="$LDLIBS"} 77 | - grep -q freestanding-pass .config || make 78 | QMAKEFLAGS="$QMAKEFLAGS QMAKE_CXX=$CXX" 79 | tests/Makefile 80 | - grep -q freestanding-pass .config || 81 | (cd tests && make TESTARGS=-silent check -k 82 | TESTRUNNER=`which valgrind 2>/dev/null`) 83 | - make -s clean 84 | - ./scripts/update-docs.sh 85 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "TinyCBOR $(VERSION) API" 2 | OUTPUT_DIRECTORY = ../doc 3 | ABBREVIATE_BRIEF = 4 | SHORT_NAMES = YES 5 | JAVADOC_AUTOBRIEF = YES 6 | QT_AUTOBRIEF = YES 7 | TAB_SIZE = 8 8 | ALIASES = "value=\arg \c" 9 | OPTIMIZE_OUTPUT_FOR_C = YES 10 | EXTRACT_STATIC = YES 11 | EXTRACT_LOCAL_CLASSES = NO 12 | HIDE_UNDOC_MEMBERS = YES 13 | HIDE_UNDOC_CLASSES = YES 14 | GENERATE_TODOLIST = NO 15 | GENERATE_TESTLIST = NO 16 | GENERATE_BUGLIST = NO 17 | GENERATE_DEPRECATEDLIST= NO 18 | SHOW_USED_FILES = NO 19 | WARN_IF_UNDOCUMENTED = NO 20 | WARN_LOGFILE = doxygen.log 21 | INPUT = . 22 | FILE_PATTERNS = *.h \ 23 | *.c \ 24 | *.dox 25 | EXCLUDE_PATTERNS = *_p.h 26 | STRIP_CODE_COMMENTS = NO 27 | REFERENCED_BY_RELATION = YES 28 | IGNORE_PREFIX = cbor_ \ 29 | Cbor 30 | HTML_TIMESTAMP = NO 31 | GENERATE_HTMLHELP = YES 32 | GENERATE_CHI = YES 33 | BINARY_TOC = YES 34 | TOC_EXPAND = YES 35 | MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest 36 | SEARCHENGINE = NO 37 | GENERATE_LATEX = NO 38 | COMPACT_LATEX = YES 39 | MACRO_EXPANSION = YES 40 | PREDEFINED = DOXYGEN \ 41 | CBOR_INLINE_API= 42 | CLASS_DIAGRAMS = NO 43 | CLASS_GRAPH = NO 44 | COLLABORATION_GRAPH = NO 45 | GROUP_GRAPHS = NO 46 | INCLUDE_GRAPH = NO 47 | INCLUDED_BY_GRAPH = NO 48 | GRAPHICAL_HIERARCHY = NO 49 | DIRECTORY_GRAPH = NO 50 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Intel Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/README: -------------------------------------------------------------------------------- 1 | Concise Binary Object Representation (CBOR) Library 2 | --------------------------------------------------- 3 | 4 | To build TinyCBOR: 5 | 6 | make 7 | 8 | If you want to change the compiler or pass extra compiler flags: 9 | 10 | make CC=clang CFLAGS="-m32 -Oz" LDFLAGS="-m32" 11 | 12 | Documentation: https://intel.github.io/tinycbor/current/ 13 | 14 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/TODO: -------------------------------------------------------------------------------- 1 | ==== To Do list for libcbor ==== 2 | === General === 3 | * API review 4 | * Benchmark 5 | * Write examples 6 | ** Simple decoder 7 | ** Decoder to JSON 8 | ** Windowed encoding/decoding (limited memory) 9 | 10 | === Encoder === 11 | * Write API docs 12 | * Add API for creating indeterminate-length arrays and maps 13 | * Add API for creating indeterminate-length strings 14 | * Add API for relaxing doubles to floats and to integers 15 | * Add length-checking of the sub-containers (#ifndef CBOR_ENCODER_NO_USER_CHECK) 16 | * Decide how to indicate number of bytes needed 17 | ** Suggestion: return negative number from the functions 18 | 19 | === Decoder === 20 | * Write functions not yet implemented 21 | * Add API for stream-decoding strings 22 | * Add API for checking known tags and simple types 23 | * (unlikely) Add API for checking the pairing of a tag and the tagged type 24 | * Write tests for error conditions 25 | * Fuzzy-test the decoder 26 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/VERSION: -------------------------------------------------------------------------------- 1 | 0.5.3 2 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/cborencoder_close_container_checked.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 Intel Corporation 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ** copies of the Software, and to permit persons to whom the Software is 10 | ** furnished to do so, subject to the following conditions: 11 | ** 12 | ** The above copyright notice and this permission notice shall be included in 13 | ** all copies or substantial portions of the Software. 14 | ** 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ** THE SOFTWARE. 22 | ** 23 | ****************************************************************************/ 24 | 25 | #define _BSD_SOURCE 1 26 | #define _DEFAULT_SOURCE 1 27 | #ifndef __STDC_LIMIT_MACROS 28 | # define __STDC_LIMIT_MACROS 1 29 | #endif 30 | 31 | #include "cbor.h" 32 | 33 | /** 34 | * \addtogroup CborEncoding 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @deprecated 40 | * 41 | * Closes the CBOR container (array or map) provided by \a containerEncoder and 42 | * updates the CBOR stream provided by \a encoder. Both parameters must be the 43 | * same as were passed to cbor_encoder_create_array() or 44 | * cbor_encoder_create_map(). 45 | * 46 | * Prior to version 0.5, cbor_encoder_close_container() did not check the 47 | * number of items added. Since that version, it does and now 48 | * cbor_encoder_close_container_checked() is no longer needed. 49 | * 50 | * \sa cbor_encoder_create_array(), cbor_encoder_create_map() 51 | */ 52 | CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder) 53 | { 54 | return cbor_encoder_close_container(encoder, containerEncoder); 55 | } 56 | 57 | /** @} */ 58 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/cborjson.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 Intel Corporation 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ** copies of the Software, and to permit persons to whom the Software is 10 | ** furnished to do so, subject to the following conditions: 11 | ** 12 | ** The above copyright notice and this permission notice shall be included in 13 | ** all copies or substantial portions of the Software. 14 | ** 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ** THE SOFTWARE. 22 | ** 23 | ****************************************************************************/ 24 | 25 | #ifndef CBORJSON_H 26 | #define CBORJSON_H 27 | 28 | #include "cbor.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /* Conversion to JSON */ 35 | enum CborToJsonFlags 36 | { 37 | CborConvertAddMetadata = 1, 38 | CborConvertTagsToObjects = 2, 39 | CborConvertIgnoreTags = 0, 40 | 41 | CborConvertObeyByteStringTags = 0, 42 | CborConvertByteStringsToBase64Url = 4, 43 | 44 | CborConvertRequireMapStringKeys = 0, 45 | CborConvertStringifyMapKeys = 8, 46 | 47 | CborConvertDefaultFlags = 0 48 | }; 49 | 50 | CBOR_API CborError cbor_value_to_json_advance(FILE *out, CborValue *value, int flags); 51 | CBOR_INLINE_API CborError cbor_value_to_json(FILE *out, const CborValue *value, int flags) 52 | { 53 | CborValue copy = *value; 54 | return cbor_value_to_json_advance(out, ©, flags); 55 | } 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* CBORJSON_H */ 62 | 63 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/examples/examples.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | SUBDIRS = simplereader.pro 3 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/examples/simplereader.pro: -------------------------------------------------------------------------------- 1 | CONFIG -= qt 2 | SOURCES = simplereader.c 3 | include(../src/src.pri) 4 | -------------------------------------------------------------------------------- /firmware-hc/tinycbor/scripts/maketag.pl: -------------------------------------------------------------------------------- 1 | #!perl 2 | use strict; 3 | sub run(@) { 4 | open PROC, "-|", @_ or die("Cannot run $_[0]: $!"); 5 | my @out; 6 | while () { 7 | chomp; 8 | push @out, $_; 9 | } 10 | close PROC; 11 | return @out; 12 | } 13 | 14 | my @tags = run("git", "tag"); 15 | my @v = run("git", "show", "HEAD:VERSION"); 16 | my $v = $v[0]; 17 | 18 | my $tagfile = ".git/TAG_EDITMSG"; 19 | open TAGFILE, ">", $tagfile 20 | or die("Cannot create file for editing tag message: $!"); 21 | select TAGFILE; 22 | print "TinyCBOR release $v\n"; 23 | print "\n"; 24 | print "# Write something nice about this release here\n"; 25 | 26 | # Do we have a commit template? 27 | my @result = run("git", "config", "--get", "commit.template"); 28 | if (scalar @result) { 29 | open TEMPLATE, "<", $result[0]; 30 | map { print $_; }