mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-29 17:41:24 +02:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12b4940662 | ||
|
|
668b1ac1dd | ||
|
|
20f2b3b74b | ||
|
|
50488cc890 | ||
|
|
860f77a45b | ||
|
|
42267cb237 | ||
|
|
b5c2e55c71 | ||
|
|
68600291d0 | ||
|
|
132ec29424 | ||
|
|
1125b05f9c | ||
|
|
8412727e03 | ||
|
|
8a0ef0b30c | ||
|
|
f108eebb93 | ||
|
|
263e554cc6 | ||
|
|
7de98552d1 | ||
|
|
08dc94a144 | ||
|
|
7e6e3c8f3c | ||
|
|
6305ea11ab | ||
|
|
4df616082e | ||
|
|
3bf035d68a | ||
|
|
7dc7be0909 | ||
|
|
015fb61759 | ||
|
|
1f4d638119 | ||
|
|
05fe0596ef | ||
|
|
d86371bb2c | ||
|
|
8cb2484aa3 | ||
|
|
7583ecff18 | ||
|
|
09ec0767b6 | ||
|
|
d0dea3d0c5 | ||
|
|
53d3a7ac91 | ||
|
|
2438356d83 | ||
|
|
79b69bfd7e | ||
|
|
d189c2978c | ||
|
|
c1cc33fd9d | ||
|
|
2d72a157d5 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
|||||||
[submodule "tinycbor"]
|
[submodule "tinycbor"]
|
||||||
path = tinycbor
|
path = tinycbor
|
||||||
url = https://github.com/intel/tinycbor.git
|
url = https://github.com/intel/tinycbor.git
|
||||||
|
[submodule "mlkem"]
|
||||||
|
path = mlkem
|
||||||
|
url = https://github.com/pq-code-package/mlkem-native/
|
||||||
|
|||||||
@@ -17,66 +17,86 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
if(ESP_PLATFORM)
|
if(ESP_PLATFORM)
|
||||||
set(EXTRA_COMPONENT_DIRS src)
|
set(EXTRA_COMPONENT_DIRS src)
|
||||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
set(USB_ITF_CCID 1)
|
|
||||||
#set(USB_ITF_HID 1)
|
|
||||||
include(pico_keys_sdk_import.cmake)
|
|
||||||
project(pico_keys_sdk)
|
|
||||||
else()
|
else()
|
||||||
|
if(NOT ENABLE_EMULATION)
|
||||||
if(ENABLE_EMULATION)
|
set(PICO_USE_FASTEST_SUPPORTED_CLOCK 1)
|
||||||
else()
|
|
||||||
include(pico_sdk_import.cmake)
|
include(pico_sdk_import.cmake)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(pico_keys C CXX ASM)
|
project(picokey C CXX ASM)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
if(ENABLE_EMULATION)
|
if(NOT DEFINED __FOR_CI)
|
||||||
else()
|
|
||||||
pico_sdk_init()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT DEFINED __FOR_CI)
|
|
||||||
set(__FOR_CI 0)
|
set(__FOR_CI 0)
|
||||||
endif()
|
endif()
|
||||||
if (__FOR_CI)
|
if(__FOR_CI)
|
||||||
add_definitions(-D__FOR_CI)
|
add_definitions(-D__FOR_CI)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_executable(picokey)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(USB_ITF_CCID 1)
|
set(USB_ITF_CCID 1)
|
||||||
set(USB_ITF_HID 1)
|
set(USB_ITF_WCID 1)
|
||||||
|
include(cmake/version.cmake)
|
||||||
include(pico_keys_sdk_import.cmake)
|
include(pico_keys_sdk_import.cmake)
|
||||||
|
if(NOT ESP_PLATFORM)
|
||||||
add_executable(pico_keys_sdk_exe)
|
set(SOURCES ${PICO_KEYS_SOURCES})
|
||||||
|
endif()
|
||||||
target_compile_options(pico_keys_sdk_exe PUBLIC
|
set(SOURCES ${SOURCES}
|
||||||
-Wall
|
${CMAKE_CURRENT_LIST_DIR}/src/fs/files.c
|
||||||
-Werror
|
${CMAKE_CURRENT_LIST_DIR}/src/version.c
|
||||||
)
|
)
|
||||||
|
|
||||||
if(ENABLE_EMULATION)
|
SET_VERSION(ver_major ver_minor "${CMAKE_CURRENT_LIST_DIR}/src/pico_keys_version.h" 2)
|
||||||
target_compile_options(pico_keys_sdk_exe PUBLIC
|
|
||||||
|
if(ESP_PLATFORM)
|
||||||
|
project(picokey)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT ESP_PLATFORM)
|
||||||
|
target_sources(picokey PUBLIC ${SOURCES})
|
||||||
|
target_include_directories(picokey PUBLIC ${INCLUDES})
|
||||||
|
|
||||||
|
target_compile_options(picokey PUBLIC
|
||||||
|
-Wall
|
||||||
|
)
|
||||||
|
if(NOT MSVC)
|
||||||
|
target_compile_options(picokey PUBLIC
|
||||||
|
-Werror
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_EMULATION)
|
||||||
|
if(NOT MSVC)
|
||||||
|
target_compile_options(picokey PUBLIC
|
||||||
-fdata-sections
|
-fdata-sections
|
||||||
-ffunction-sections
|
-ffunction-sections
|
||||||
)
|
)
|
||||||
if(APPLE)
|
endif()
|
||||||
target_link_options(pico_keys_sdk_exe PUBLIC
|
if(APPLE)
|
||||||
|
target_link_options(picokey PUBLIC
|
||||||
-Wl,-dead_strip
|
-Wl,-dead_strip
|
||||||
)
|
)
|
||||||
else()
|
elseif(MSVC)
|
||||||
target_link_options(pico_keys_sdk_exe PUBLIC
|
target_compile_options(picokey PUBLIC
|
||||||
|
-WX
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(picokey PUBLIC wsock32 ws2_32 Bcrypt)
|
||||||
|
else()
|
||||||
|
target_link_options(picokey PUBLIC
|
||||||
-Wl,--gc-sections
|
-Wl,--gc-sections
|
||||||
)
|
)
|
||||||
endif (APPLE)
|
endif(APPLE)
|
||||||
else()
|
target_link_libraries(picokey PRIVATE pthread m)
|
||||||
pico_add_extra_outputs(pico_keys_sdk_exe)
|
else()
|
||||||
|
pico_add_extra_outputs(${CMAKE_PROJECT_NAME})
|
||||||
target_link_libraries(pico_keys_sdk_exe PRIVATE pico_keys_sdk pico_stdlib pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id hardware_rtc tinyusb_device tinyusb_board)
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ macro(HEX2DEC VAR VAL)
|
|||||||
endwhile()
|
endwhile()
|
||||||
endmacro(HEX2DEC)
|
endmacro(HEX2DEC)
|
||||||
|
|
||||||
macro(SET_VERSION MAJOR MINOR FILE)
|
macro(SET_VERSION MAJOR MINOR FILE ROLLBACK)
|
||||||
file(READ ${FILE} ver)
|
file(READ ${FILE} ver)
|
||||||
string(REGEX MATCHALL "0x([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])" _ ${ver})
|
string(REGEX MATCHALL "0x([0-9A-F])([0-9A-F])([0-9A-F])([0-9A-F])" _ ${ver})
|
||||||
string(CONCAT ver_major ${CMAKE_MATCH_1}${CMAKE_MATCH_2})
|
string(CONCAT ver_major ${CMAKE_MATCH_1}${CMAKE_MATCH_2})
|
||||||
@@ -42,8 +42,13 @@ macro(SET_VERSION MAJOR MINOR FILE)
|
|||||||
HEX2DEC(ver_minor ${ver_minor})
|
HEX2DEC(ver_minor ${ver_minor})
|
||||||
message(STATUS "Found version:\t\t ${ver_major}.${ver_minor}")
|
message(STATUS "Found version:\t\t ${ver_major}.${ver_minor}")
|
||||||
if(PICO_PLATFORM)
|
if(PICO_PLATFORM)
|
||||||
|
if (PICO_RP2350 AND SECURE_BOOT_PKEY)
|
||||||
|
message(STATUS "Setting rollback version:\t ${ROLLBACK}")
|
||||||
|
pico_set_binary_version(${CMAKE_PROJECT_NAME} MAJOR ${ver_major} MINOR ${ver_minor} ROLLBACK ${ROLLBACK})
|
||||||
|
else()
|
||||||
pico_set_binary_version(${CMAKE_PROJECT_NAME} MAJOR ${ver_major} MINOR ${ver_minor})
|
pico_set_binary_version(${CMAKE_PROJECT_NAME} MAJOR ${ver_major} MINOR ${ver_minor})
|
||||||
endif()
|
endif()
|
||||||
SET(${MAJOR} ${ver_major})
|
endif()
|
||||||
SET(${MINOR} ${ver_minor})
|
set(${MAJOR} ${ver_major})
|
||||||
|
set(${MINOR} ${ver_minor})
|
||||||
endmacro(SET_VERSION)
|
endmacro(SET_VERSION)
|
||||||
|
|||||||
23
config/esp32/components/mlkem1024/CMakeLists.txt
Normal file
23
config/esp32/components/mlkem1024/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
set(MLKEM_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../mlkem/mlkem)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE MLKEM_SOURCES
|
||||||
|
${MLKEM_DIR}/src/*.c
|
||||||
|
)
|
||||||
|
list(FILTER MLKEM_SOURCES EXCLUDE REGEX "/native/")
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${MLKEM_SOURCES}
|
||||||
|
INCLUDE_DIRS ${MLKEM_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE
|
||||||
|
MLK_CONFIG_PARAMETER_SET=1024
|
||||||
|
MLK_CONFIG_MULTILEVEL_NO_SHARED
|
||||||
|
MLK_CONFIG_NAMESPACE_PREFIX=mlkem
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(${COMPONENT_LIB} PRIVATE
|
||||||
|
-O2
|
||||||
|
-fno-builtin
|
||||||
|
-fno-strict-aliasing
|
||||||
|
)
|
||||||
23
config/esp32/components/mlkem512/CMakeLists.txt
Normal file
23
config/esp32/components/mlkem512/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
set(MLKEM_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../mlkem/mlkem)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE MLKEM_SOURCES
|
||||||
|
${MLKEM_DIR}/src/*.c
|
||||||
|
)
|
||||||
|
list(FILTER MLKEM_SOURCES EXCLUDE REGEX "/native/")
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${MLKEM_SOURCES}
|
||||||
|
INCLUDE_DIRS ${MLKEM_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE
|
||||||
|
MLK_CONFIG_PARAMETER_SET=512
|
||||||
|
MLK_CONFIG_MULTILEVEL_WITH_SHARED
|
||||||
|
MLK_CONFIG_NAMESPACE_PREFIX=mlkem
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(${COMPONENT_LIB} PRIVATE
|
||||||
|
-O2
|
||||||
|
-fno-builtin
|
||||||
|
-fno-strict-aliasing
|
||||||
|
)
|
||||||
23
config/esp32/components/mlkem768/CMakeLists.txt
Normal file
23
config/esp32/components/mlkem768/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
set(MLKEM_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../mlkem/mlkem)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE MLKEM_SOURCES
|
||||||
|
${MLKEM_DIR}/src/*.c
|
||||||
|
)
|
||||||
|
list(FILTER MLKEM_SOURCES EXCLUDE REGEX "/native/")
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${MLKEM_SOURCES}
|
||||||
|
INCLUDE_DIRS ${MLKEM_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(${COMPONENT_LIB} PRIVATE
|
||||||
|
MLK_CONFIG_PARAMETER_SET=768
|
||||||
|
MLK_CONFIG_MULTILEVEL_NO_SHARED
|
||||||
|
MLK_CONFIG_NAMESPACE_PREFIX=mlkem
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(${COMPONENT_LIB} PRIVATE
|
||||||
|
-O2
|
||||||
|
-fno-builtin
|
||||||
|
-fno-strict-aliasing
|
||||||
|
)
|
||||||
7
config/esp32/components/pico-keys-sdk/CMakeLists.txt
Executable file
7
config/esp32/components/pico-keys-sdk/CMakeLists.txt
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
set(PICO_KEYS_SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${PICO_KEYS_SOURCES}
|
||||||
|
INCLUDE_DIRS ${PICO_KEYS_SDK_DIR}/src ${PICO_KEYS_SDK_DIR}/src/fs ${PICO_KEYS_SDK_DIR}/src/rng ${PICO_KEYS_SDK_DIR}/src/usb ${PICO_KEYS_SDK_DIR}/src/led ${PICO_KEYS_SDK_DIR}/tinycbor/src ${PICO_KEYS_SDK_DIR}/mlkem/mlkem ${PICO_KEYS_SDK_DIR}/config/mlkem
|
||||||
|
REQUIRES bootloader_support esp_partition esp_tinyusb efuse mbedtls mlkem512 mlkem768 mlkem1024 tinycbor
|
||||||
|
)
|
||||||
|
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
## IDF Component Manager Manifest File
|
## IDF Component Manager Manifest File
|
||||||
dependencies:
|
dependencies:
|
||||||
espressif/esp_tinyusb: "^1.7.2"
|
espressif/esp_tinyusb: "^1.7.6"
|
||||||
#espressif/tinyusb: "^0.15.0"
|
#espressif/tinyusb: "^0.15.0"
|
||||||
zorxx/neopixel: "^1.0.4"
|
zorxx/neopixel: "^1.0.4"
|
||||||
6
config/esp32/components/tinycbor/CMakeLists.txt
Executable file
6
config/esp32/components/tinycbor/CMakeLists.txt
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
set(PICO_KEYS_SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${CBOR_SOURCES}
|
||||||
|
INCLUDE_DIRS ${PICO_KEYS_SDK_DIR}/tinycbor/src
|
||||||
|
)
|
||||||
|
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)
|
||||||
@@ -330,7 +330,7 @@
|
|||||||
//#define MBEDTLS_RSA_ALT
|
//#define MBEDTLS_RSA_ALT
|
||||||
//#define MBEDTLS_SHA1_ALT
|
//#define MBEDTLS_SHA1_ALT
|
||||||
#ifdef PICO_RP2350
|
#ifdef PICO_RP2350
|
||||||
#define MBEDTLS_SHA256_ALT
|
//#define MBEDTLS_SHA256_ALT
|
||||||
#endif
|
#endif
|
||||||
//#define MBEDTLS_SHA512_ALT
|
//#define MBEDTLS_SHA512_ALT
|
||||||
|
|
||||||
|
|||||||
27
config/mlkem/mlkem_native_all.h
Normal file
27
config/mlkem/mlkem_native_all.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) The mlkem-native project authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(MLK_ALL_H)
|
||||||
|
#define MLK_ALL_H
|
||||||
|
|
||||||
|
/* API for MLKEM-512 */
|
||||||
|
#define MLK_CONFIG_PARAMETER_SET 512
|
||||||
|
#include "mlkem_native.h"
|
||||||
|
#undef MLK_CONFIG_PARAMETER_SET
|
||||||
|
#undef MLK_H
|
||||||
|
|
||||||
|
/* API for MLKEM-768 */
|
||||||
|
#define MLK_CONFIG_PARAMETER_SET 768
|
||||||
|
#include "mlkem_native.h"
|
||||||
|
#undef MLK_CONFIG_PARAMETER_SET
|
||||||
|
#undef MLK_H
|
||||||
|
|
||||||
|
/* API for MLKEM-1024 */
|
||||||
|
#define MLK_CONFIG_PARAMETER_SET 1024
|
||||||
|
#include "mlkem_native.h"
|
||||||
|
#undef MLK_CONFIG_PARAMETER_SET
|
||||||
|
#undef MLK_H
|
||||||
|
|
||||||
|
#endif /* !MLK_ALL_H */
|
||||||
13
config/mlkem/mlkem_native_config.h
Normal file
13
config/mlkem/mlkem_native_config.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* Disable all native/asm backends */
|
||||||
|
#define MLK_NO_NATIVE_BACKENDS 1
|
||||||
|
|
||||||
|
/* No CBMC */
|
||||||
|
#undef CBMC
|
||||||
|
|
||||||
|
/* Platform characteristics */
|
||||||
|
#define MLK_LITTLE_ENDIAN 1
|
||||||
|
|
||||||
|
/* Memory model */
|
||||||
|
#define MLK_NO_MALLOC 1
|
||||||
@@ -286,3 +286,9 @@ int mbedtls_sha256_finish(mbedtls_sha256_context *ctx, unsigned char *output) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mbedtls_sha256_clone(mbedtls_sha256_context *dst,
|
||||||
|
const mbedtls_sha256_context *src)
|
||||||
|
{
|
||||||
|
*dst = *src;
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#ifndef _SHA256_ALT_H_
|
#ifndef _SHA256_ALT_H_
|
||||||
#define _SHA256_ALT_H_
|
#define _SHA256_ALT_H_
|
||||||
|
|
||||||
#include "pico_keys.h"
|
|
||||||
#include "pico/sha256.h"
|
#include "pico/sha256.h"
|
||||||
|
|
||||||
typedef struct mbedtls_sha256_context {
|
typedef struct mbedtls_sha256_context {
|
||||||
|
|||||||
1
mlkem
Submodule
1
mlkem
Submodule
Submodule mlkem added at 1453da5cd1
@@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
include(pico-keys-sdk/cmake/version.cmake)
|
include(pico-keys-sdk/cmake/version.cmake OPTIONAL)
|
||||||
|
|
||||||
option(VIDPID "Set specific VID/PID from a known platform {NitroHSM, NitroFIDO2, NitroStart, NitroPro, Nitro3, Yubikey5, YubikeyNeo, YubiHSM, Gnuk, GnuPG}" "None")
|
option(VIDPID "Set specific VID/PID from a known platform {NitroHSM, NitroFIDO2, NitroStart, NitroPro, Nitro3, Yubikey5, YubikeyNeo, YubiHSM, Gnuk, GnuPG}" "None")
|
||||||
|
|
||||||
@@ -64,12 +64,12 @@ if(ESP_PLATFORM)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT DEFINED USB_VID)
|
if(NOT DEFINED USB_VID)
|
||||||
set(USB_VID 0xFEFF)
|
set(USB_VID 0x2E8A)
|
||||||
endif()
|
endif()
|
||||||
add_definitions(-DUSB_VID=${USB_VID})
|
add_definitions(-DUSB_VID=${USB_VID})
|
||||||
|
|
||||||
if(NOT DEFINED USB_PID)
|
if(NOT DEFINED USB_PID)
|
||||||
set(USB_PID 0xFCFD)
|
set(USB_PID 0x10FD)
|
||||||
endif()
|
endif()
|
||||||
add_definitions(-DUSB_PID=${USB_PID})
|
add_definitions(-DUSB_PID=${USB_PID})
|
||||||
|
|
||||||
@@ -109,6 +109,8 @@ endif()
|
|||||||
message(STATUS "USB VID/PID:\t\t\t ${USB_VID}:${USB_PID}")
|
message(STATUS "USB VID/PID:\t\t\t ${USB_VID}:${USB_PID}")
|
||||||
|
|
||||||
if(NOT ESP_PLATFORM)
|
if(NOT ESP_PLATFORM)
|
||||||
|
set(NEED_UPDATE OFF)
|
||||||
|
|
||||||
option(ENABLE_EDDSA "Enable/disable EdDSA support" OFF)
|
option(ENABLE_EDDSA "Enable/disable EdDSA support" OFF)
|
||||||
if(ENABLE_EDDSA)
|
if(ENABLE_EDDSA)
|
||||||
message(STATUS "EdDSA support:\t\t enabled")
|
message(STATUS "EdDSA support:\t\t enabled")
|
||||||
@@ -117,49 +119,69 @@ if(NOT ESP_PLATFORM)
|
|||||||
endif(ENABLE_EDDSA)
|
endif(ENABLE_EDDSA)
|
||||||
|
|
||||||
set(MBEDTLS_PATH "${CMAKE_SOURCE_DIR}/pico-keys-sdk/mbedtls")
|
set(MBEDTLS_PATH "${CMAKE_SOURCE_DIR}/pico-keys-sdk/mbedtls")
|
||||||
|
|
||||||
if(ENABLE_EDDSA)
|
|
||||||
set(MBEDTLS_ORIGIN "https://github.com/polhenarejos/mbedtls.git")
|
|
||||||
set(MBEDTLS_REF "mbedtls-3.6-eddsa")
|
|
||||||
add_definitions(-DMBEDTLS_ECP_DP_ED25519_ENABLED=1 -DMBEDTLS_ECP_DP_ED448_ENABLED=1 -DMBEDTLS_EDDSA_C=1 -DMBEDTLS_SHA3_C=1)
|
|
||||||
else()
|
|
||||||
set(MBEDTLS_ORIGIN "https://github.com/Mbed-TLS/mbedtls.git")
|
|
||||||
set(MBEDTLS_REF "v3.6.5")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND git config --global --add safe.directory ${MBEDTLS_PATH}
|
COMMAND git config --global --add safe.directory ${MBEDTLS_PATH}
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
OUTPUT_QUIET ERROR_QUIET
|
OUTPUT_QUIET ERROR_QUIET
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_EDDSA)
|
||||||
|
set(MBEDTLS_ORIGIN "https://github.com/polhenarejos/mbedtls.git")
|
||||||
|
set(MBEDTLS_REF "mbedtls-3.6-eddsa")
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND git -C ${MBEDTLS_PATH} submodule update --init --recursive pico-keys-sdk
|
COMMAND git -C ${MBEDTLS_PATH} symbolic-ref --quiet --short HEAD
|
||||||
|
OUTPUT_VARIABLE CURRENT_BRANCH
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
RESULT_VARIABLE BRANCH_ERR
|
||||||
|
)
|
||||||
|
|
||||||
|
message(STATUS "Current branch for mbedTLS: ${CURRENT_BRANCH}")
|
||||||
|
message(STATUS "Target branch for mbedTLS: ${MBEDTLS_REF}")
|
||||||
|
|
||||||
|
if(NOT BRANCH_ERR EQUAL 0 OR NOT "${CURRENT_BRANCH}" STREQUAL "${MBEDTLS_REF}")
|
||||||
|
set(NEED_UPDATE ON)
|
||||||
|
else()
|
||||||
|
set(NEED_UPDATE OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_definitions(-DMBEDTLS_ECP_DP_ED25519_ENABLED=1 -DMBEDTLS_ECP_DP_ED448_ENABLED=1 -DMBEDTLS_EDDSA_C=1 -DMBEDTLS_SHA3_C=1)
|
||||||
|
|
||||||
|
else()
|
||||||
|
set(MBEDTLS_ORIGIN "https://github.com/Mbed-TLS/mbedtls.git")
|
||||||
|
set(MBEDTLS_REF "v3.6.5")
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND git -C ${MBEDTLS_PATH} describe --tags --exact-match
|
||||||
|
OUTPUT_VARIABLE CURRENT_TAG
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
RESULT_VARIABLE TAG_ERR
|
||||||
|
)
|
||||||
|
|
||||||
|
message(STATUS "Current tag for mbedTLS: ${CURRENT_TAG}")
|
||||||
|
message(STATUS "Target tag for mbedTLS: ${MBEDTLS_REF}")
|
||||||
|
|
||||||
|
if(NOT TAG_ERR EQUAL 0 OR NOT "${CURRENT_TAG}" STREQUAL "${MBEDTLS_REF}")
|
||||||
|
set(NEED_UPDATE ON)
|
||||||
|
else()
|
||||||
|
set(NEED_UPDATE OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NEED_UPDATE)
|
||||||
|
message(STATUS "Updating mbedTLS source code...")
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND git -C ${MBEDTLS_PATH} submodule update --init --recursive --remote pico-keys-sdk
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
OUTPUT_QUIET ERROR_QUIET
|
OUTPUT_QUIET ERROR_QUIET
|
||||||
)
|
)
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND git -C ${MBEDTLS_PATH} remote get-url origin
|
|
||||||
OUTPUT_VARIABLE CURRENT_ORIGIN
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT "${CURRENT_ORIGIN}" STREQUAL "${MBEDTLS_ORIGIN}")
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND git -C ${MBEDTLS_PATH} remote set-url origin ${MBEDTLS_ORIGIN}
|
COMMAND git -C ${MBEDTLS_PATH} remote set-url origin ${MBEDTLS_ORIGIN}
|
||||||
OUTPUT_QUIET ERROR_QUIET
|
OUTPUT_QUIET ERROR_QUIET
|
||||||
)
|
)
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND git -C ${MBEDTLS_PATH} rev-parse --verify ${MBEDTLS_REF}
|
|
||||||
OUTPUT_VARIABLE CURRENT_REF
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
RESULT_VARIABLE REF_EXISTS
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT REF_EXISTS EQUAL 0 OR NOT CURRENT_REF STREQUAL "${MBEDTLS_REF}")
|
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND git -C ${MBEDTLS_PATH} fetch origin +refs/heads/*:refs/remotes/origin/* --tags --force
|
COMMAND git -C ${MBEDTLS_PATH} fetch origin +refs/heads/*:refs/remotes/origin/* --tags --force
|
||||||
@@ -186,10 +208,19 @@ if(NOT ESP_PLATFORM)
|
|||||||
OUTPUT_QUIET ERROR_QUIET
|
OUTPUT_QUIET ERROR_QUIET
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
else()
|
||||||
|
message(STATUS "mbedTLS source code is up to date.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif(NOT ESP_PLATFORM)
|
endif(NOT ESP_PLATFORM)
|
||||||
|
|
||||||
|
option(ENABLE_PQC "Enable/disable PQC support" OFF)
|
||||||
|
if(ENABLE_PQC)
|
||||||
|
message(STATUS "PQC support:\t\t\t enabled")
|
||||||
|
add_definitions(-DENABLE_PQC)
|
||||||
|
else()
|
||||||
|
message(STATUS "PQC support:\t\t\t disabled")
|
||||||
|
endif(ENABLE_PQC)
|
||||||
|
|
||||||
set(MBEDTLS_SOURCES
|
set(MBEDTLS_SOURCES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aes.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aes.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/asn1parse.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/asn1parse.c
|
||||||
@@ -222,9 +253,12 @@ set(MBEDTLS_SOURCES
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/poly1305.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/poly1305.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/ripemd160.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/ripemd160.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/des.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/des.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_crt.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_crt.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509_create.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509_create.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_csr.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_csr.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/base64.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pem.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk_wrap.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk_wrap.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c
|
||||||
@@ -237,6 +271,54 @@ if (ENABLE_EDDSA)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(ENABLE_PQC)
|
||||||
|
if (NOT ESP_PLATFORM)
|
||||||
|
file(GLOB_RECURSE MLKEM_SOURCES
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src/*.c
|
||||||
|
)
|
||||||
|
list(FILTER MLKEM_SOURCES EXCLUDE REGEX "/native/")
|
||||||
|
|
||||||
|
add_library(mlkem512 STATIC ${MLKEM_SOURCES})
|
||||||
|
target_include_directories(mlkem512 PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/config/mlkem
|
||||||
|
)
|
||||||
|
target_compile_definitions(mlkem512 PRIVATE
|
||||||
|
MLK_CONFIG_PARAMETER_SET=512
|
||||||
|
MLK_CONFIG_MULTILEVEL_WITH_SHARED
|
||||||
|
MLK_CONFIG_NAMESPACE_PREFIX=mlkem
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(mlkem768 STATIC ${MLKEM_SOURCES})
|
||||||
|
target_include_directories(mlkem768 PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/config/mlkem
|
||||||
|
)
|
||||||
|
target_compile_definitions(mlkem768 PRIVATE
|
||||||
|
MLK_CONFIG_PARAMETER_SET=768
|
||||||
|
MLK_CONFIG_MULTILEVEL_NO_SHARED
|
||||||
|
MLK_CONFIG_NAMESPACE_PREFIX=mlkem
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(mlkem1024 STATIC ${MLKEM_SOURCES})
|
||||||
|
target_include_directories(mlkem1024 PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/config/mlkem
|
||||||
|
)
|
||||||
|
target_compile_definitions(mlkem1024 PRIVATE
|
||||||
|
MLK_CONFIG_PARAMETER_SET=1024
|
||||||
|
MLK_CONFIG_MULTILEVEL_NO_SHARED
|
||||||
|
MLK_CONFIG_NAMESPACE_PREFIX=mlkem
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(INCLUDES ${INCLUDES}
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/config/mlkem
|
||||||
|
)
|
||||||
|
add_definitions(-DMLK_CONFIG_NAMESPACE_PREFIX=mlkem -DMLK_CONFIG_MULTILEVEL_BUILD=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES}
|
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/main.c
|
${CMAKE_CURRENT_LIST_DIR}/src/main.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/usb/usb.c
|
${CMAKE_CURRENT_LIST_DIR}/src/usb/usb.c
|
||||||
@@ -295,6 +377,9 @@ if(USB_ITF_HID)
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk_wrap.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk_wrap.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c
|
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CBOR_SOURCES
|
set(CBOR_SOURCES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborencoder.c
|
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborencoder.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborparser.c
|
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborparser.c
|
||||||
@@ -304,9 +389,22 @@ if(USB_ITF_HID)
|
|||||||
set(INCLUDES ${INCLUDES}
|
set(INCLUDES ${INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src
|
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src
|
||||||
)
|
)
|
||||||
|
set(LIBRARIES
|
||||||
|
mbedtls
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT ESP_PLATFORM)
|
||||||
|
add_library(mbedtls STATIC ${MBEDTLS_SOURCES})
|
||||||
|
target_include_directories(mbedtls PUBLIC ${CMAKE_CURRENT_LIST_DIR}/mbedtls/include)
|
||||||
|
if(USB_ITF_HID)
|
||||||
|
add_library(tinycbor STATIC ${CBOR_SOURCES})
|
||||||
|
target_include_directories(tinycbor PUBLIC ${CMAKE_CURRENT_LIST_DIR}/tinycbor/src)
|
||||||
|
set(LIBRARIES ${LIBRARIES} tinycbor)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(LIBRARIES
|
if (PICO_PLATFORM)
|
||||||
|
list(APPEND LIBRARIES
|
||||||
pico_stdlib
|
pico_stdlib
|
||||||
pico_multicore
|
pico_multicore
|
||||||
pico_rand
|
pico_rand
|
||||||
@@ -316,7 +414,16 @@ set(LIBRARIES
|
|||||||
tinyusb_device
|
tinyusb_device
|
||||||
tinyusb_board
|
tinyusb_board
|
||||||
hardware_pio
|
hardware_pio
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (ENABLE_PQC)
|
||||||
|
list(APPEND LIBRARIES
|
||||||
|
mlkem512
|
||||||
|
mlkem768
|
||||||
|
mlkem1024
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(IS_CYW43 0)
|
set(IS_CYW43 0)
|
||||||
if (PICO_PLATFORM)
|
if (PICO_PLATFORM)
|
||||||
@@ -380,10 +487,7 @@ else()
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/src/usb/usb_descriptors.c
|
${CMAKE_CURRENT_LIST_DIR}/src/usb/usb_descriptors.c
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
set(EXTERNAL_SOURCES ${CBOR_SOURCES})
|
|
||||||
if(NOT ESP_PLATFORM)
|
|
||||||
set(EXTERNAL_SOURCES ${EXTERNAL_SOURCES} ${MBEDTLS_SOURCES})
|
|
||||||
endif()
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(
|
set(
|
||||||
CMAKE_C_FLAGS
|
CMAKE_C_FLAGS
|
||||||
@@ -400,11 +504,6 @@ if(MSVC)
|
|||||||
_WIN32_WINNT_WIN10_RS5=0
|
_WIN32_WINNT_WIN10_RS5=0
|
||||||
_STRALIGN_USE_SECURE_CRT=0
|
_STRALIGN_USE_SECURE_CRT=0
|
||||||
NTDDI_WIN11_DT=0)
|
NTDDI_WIN11_DT=0)
|
||||||
set_source_files_properties(
|
|
||||||
${EXTERNAL_SOURCES}
|
|
||||||
PROPERTIES
|
|
||||||
COMPILE_FLAGS " -W3 -wd4242 -wd4065"
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PICO_PLATFORM)
|
if(PICO_PLATFORM)
|
||||||
@@ -427,13 +526,17 @@ if(PICO_RP2350)
|
|||||||
set(INCLUDES ${INCLUDES}
|
set(INCLUDES ${INCLUDES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt
|
${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt
|
||||||
)
|
)
|
||||||
|
target_include_directories(mbedtls PRIVATE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt
|
||||||
|
)
|
||||||
|
target_link_libraries(mbedtls PRIVATE pico_sha256)
|
||||||
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES}
|
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES}
|
||||||
${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt/sha256_alt.c
|
${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt/sha256_alt.c
|
||||||
)
|
)
|
||||||
|
add_definitions(-DMBEDTLS_SHA256_ALT=1)
|
||||||
set(LIBRARIES ${LIBRARIES} pico_sha256)
|
set(LIBRARIES ${LIBRARIES} pico_sha256)
|
||||||
endif()
|
endif()
|
||||||
set(INTERNAL_SOURCES ${PICO_KEYS_SOURCES})
|
set(INTERNAL_SOURCES ${PICO_KEYS_SOURCES})
|
||||||
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} ${EXTERNAL_SOURCES})
|
|
||||||
|
|
||||||
if(NOT TARGET pico_keys_sdk)
|
if(NOT TARGET pico_keys_sdk)
|
||||||
if(PICO_PLATFORM)
|
if(PICO_PLATFORM)
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
idf_component_register(
|
|
||||||
SRCS ${PICO_KEYS_SOURCES}
|
|
||||||
INCLUDE_DIRS . fs rng usb led ../tinycbor/src
|
|
||||||
REQUIRES bootloader_support esp_partition esp_tinyusb efuse mbedtls
|
|
||||||
)
|
|
||||||
28
src/fs/files.c
Normal file
28
src/fs/files.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Pico Keys SDK distribution (https://github.com/polhenarejos/pico-keys-sdk).
|
||||||
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "file.h"
|
||||||
|
|
||||||
|
file_t file_entries[] = {
|
||||||
|
/* 0 */ { .fid = 0x3f00, .parent = 0xff, .name = NULL, .type = FILE_TYPE_DF, .data = NULL,
|
||||||
|
.ef_structure = 0, .acl = { 0 } }, // MF
|
||||||
|
/* 1 */ { .fid = 0x0000, .parent = 0xff, .name = NULL, .type = FILE_TYPE_NOT_KNOWN, .data = NULL,
|
||||||
|
.ef_structure = 0, .acl = { 0 } } //end
|
||||||
|
};
|
||||||
|
|
||||||
|
const file_t *MF = &file_entries[0];
|
||||||
|
const file_t *file_last = &file_entries[sizeof(file_entries) / sizeof(file_t) - 1];
|
||||||
@@ -327,6 +327,7 @@ void init_otp_files() {
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printf("Error writing OTP key 2 [%d]\n", ret);
|
printf("Error writing OTP key 2 [%d]\n", ret);
|
||||||
}
|
}
|
||||||
|
mbedtls_platform_zeroize(pkey, sizeof(pkey));
|
||||||
#ifdef PICO_RP2350
|
#ifdef PICO_RP2350
|
||||||
otp_chaff(OTP_KEY_2, 32);
|
otp_chaff(OTP_KEY_2, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ void led_init() {
|
|||||||
#if defined(PIMORONI_TINY2040) || defined(PIMORONI_TINY2350)
|
#if defined(PIMORONI_TINY2040) || defined(PIMORONI_TINY2350)
|
||||||
led_driver = &led_driver_pimoroni;
|
led_driver = &led_driver_pimoroni;
|
||||||
phy_data.led_driver = phy_data.led_driver_present ? phy_data.led_driver : PHY_LED_DRIVER_PIMORONI;
|
phy_data.led_driver = phy_data.led_driver_present ? phy_data.led_driver : PHY_LED_DRIVER_PIMORONI;
|
||||||
|
phy_data.led_gpio = phy_data.led_gpio_present ? phy_data.led_gpio : PICO_DEFAULT_LED_PIN;
|
||||||
#elif defined(CYW43_WL_GPIO_LED_PIN)
|
#elif defined(CYW43_WL_GPIO_LED_PIN)
|
||||||
led_driver = &led_driver_cyw43;
|
led_driver = &led_driver_cyw43;
|
||||||
phy_data.led_driver = phy_data.led_driver_present ? phy_data.led_driver : PHY_LED_DRIVER_CYW43;
|
phy_data.led_driver = phy_data.led_driver_present ? phy_data.led_driver : PHY_LED_DRIVER_CYW43;
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
#include "pico_keys.h"
|
#include "pico_keys.h"
|
||||||
|
|
||||||
#ifdef PICO_DEFAULT_LED_PIN
|
#ifdef PICO_DEFAULT_LED_PIN
|
||||||
uint8_t gpio = PICO_DEFAULT_LED_PIN;
|
static uint8_t gpio = PICO_DEFAULT_LED_PIN;
|
||||||
#else
|
#else
|
||||||
uint8_t gpio = 0;
|
static uint8_t gpio = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PICO_PLATFORM
|
#ifdef PICO_PLATFORM
|
||||||
|
|||||||
@@ -18,18 +18,10 @@
|
|||||||
#include "pico_keys.h"
|
#include "pico_keys.h"
|
||||||
|
|
||||||
#ifdef PICO_PLATFORM
|
#ifdef PICO_PLATFORM
|
||||||
#ifdef PIMORONI_TINY2040
|
#ifdef PICO_DEFAULT_LED_PIN
|
||||||
#define LED_R_PIN TINY2040_LED_R_PIN
|
static uint8_t gpio = PICO_DEFAULT_LED_PIN;
|
||||||
#define LED_G_PIN TINY2040_LED_G_PIN
|
|
||||||
#define LED_B_PIN TINY2040_LED_B_PIN
|
|
||||||
#elif defined(PIMORONI_TINY2350)
|
|
||||||
#define LED_R_PIN TINY2350_LED_R_PIN
|
|
||||||
#define LED_G_PIN TINY2350_LED_G_PIN
|
|
||||||
#define LED_B_PIN TINY2350_LED_B_PIN
|
|
||||||
#else
|
#else
|
||||||
#define LED_R_PIN 0
|
static uint8_t gpio = 0;
|
||||||
#define LED_G_PIN 0
|
|
||||||
#define LED_B_PIN 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t pixel[][3] = {
|
uint8_t pixel[][3] = {
|
||||||
@@ -44,21 +36,24 @@ uint8_t pixel[][3] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void led_driver_init_pimoroni() {
|
void led_driver_init_pimoroni() {
|
||||||
gpio_init(LED_R_PIN);
|
if (phy_data.led_gpio_present) {
|
||||||
gpio_set_dir(LED_R_PIN, GPIO_OUT);
|
gpio = phy_data.led_gpio;
|
||||||
gpio_init(LED_G_PIN);
|
}
|
||||||
gpio_set_dir(LED_G_PIN, GPIO_OUT);
|
gpio_init(gpio-1);
|
||||||
gpio_init(LED_B_PIN);
|
gpio_set_dir(gpio-1, GPIO_OUT);
|
||||||
gpio_set_dir(LED_B_PIN, GPIO_OUT);
|
gpio_init(gpio);
|
||||||
|
gpio_set_dir(gpio, GPIO_OUT);
|
||||||
|
gpio_init(gpio+1);
|
||||||
|
gpio_set_dir(gpio+1, GPIO_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_driver_color_pimoroni(uint8_t color, uint32_t led_brightness, float progress) {
|
void led_driver_color_pimoroni(uint8_t color, uint32_t led_brightness, float progress) {
|
||||||
if (progress < 0.5) {
|
if (progress < 0.5) {
|
||||||
color = LED_COLOR_OFF;
|
color = LED_COLOR_OFF;
|
||||||
}
|
}
|
||||||
gpio_put(LED_R_PIN, pixel[color][0]);
|
gpio_put(gpio-1, pixel[color][0]);
|
||||||
gpio_put(LED_G_PIN, pixel[color][1]);
|
gpio_put(gpio, pixel[color][1]);
|
||||||
gpio_put(LED_B_PIN, pixel[color][2]);
|
gpio_put(gpio+1, pixel[color][2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
led_driver_t led_driver_pimoroni = {
|
led_driver_t led_driver_pimoroni = {
|
||||||
|
|||||||
48
src/main.c
48
src/main.c
@@ -58,7 +58,7 @@ const uint8_t *ccid_atr = NULL;
|
|||||||
|
|
||||||
bool app_exists(const uint8_t *aid, size_t aid_len) {
|
bool app_exists(const uint8_t *aid, size_t aid_len) {
|
||||||
for (int a = 0; a < num_apps; a++) {
|
for (int a = 0; a < num_apps; a++) {
|
||||||
if (apps[a].aid[0] == aid_len && !memcmp(apps[a].aid + 1, aid, MIN(aid_len, apps[a].aid[0]))) {
|
if (aid_len >= apps[a].aid[0] && !memcmp(apps[a].aid + 1, aid, apps[a].aid[0])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,14 +79,14 @@ int register_app(int (*select_aid)(app_t *, uint8_t), const uint8_t *aid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int select_app(const uint8_t *aid, size_t aid_len) {
|
int select_app(const uint8_t *aid, size_t aid_len) {
|
||||||
if (current_app && current_app->aid && current_app->aid[0] == aid_len && (current_app->aid + 1 == aid || !memcmp(current_app->aid + 1, aid, MIN(current_app->aid[0], aid_len)))) {
|
if (current_app && current_app->aid && (current_app->aid + 1 == aid || (aid_len >= current_app->aid[0] && !memcmp(current_app->aid + 1, aid, current_app->aid[0])))) {
|
||||||
current_app->select_aid(current_app, 0);
|
current_app->select_aid(current_app, 0);
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
for (int a = 0; a < num_apps; a++) {
|
for (int a = 0; a < num_apps; a++) {
|
||||||
if (apps[a].aid[0] == aid_len && !memcmp(apps[a].aid + 1, aid, MIN(aid_len, apps[a].aid[0]))) {
|
if (aid_len >= apps[a].aid[0] && !memcmp(apps[a].aid + 1, aid, apps[a].aid[0])) {
|
||||||
if (current_app) {
|
if (current_app) {
|
||||||
if (current_app->aid && !memcmp(current_app->aid + 1, aid, MIN(current_app->aid[0], aid_len))) {
|
if (current_app->aid && aid_len >= current_app->aid[0] && !memcmp(current_app->aid + 1, aid, current_app->aid[0])) {
|
||||||
current_app->select_aid(current_app, 1);
|
current_app->select_aid(current_app, 1);
|
||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
@@ -197,13 +197,16 @@ bool button_pressed_state = false;
|
|||||||
uint32_t button_pressed_time = 0;
|
uint32_t button_pressed_time = 0;
|
||||||
uint8_t button_press = 0;
|
uint8_t button_press = 0;
|
||||||
bool wait_button() {
|
bool wait_button() {
|
||||||
uint32_t button_timeout = 15000;
|
/* Disabled by default. As LED may not be properly configured,
|
||||||
|
it will not be possible to indicate button press unless it
|
||||||
|
is commissioned. */
|
||||||
|
uint32_t button_timeout = 0;
|
||||||
if (phy_data.up_btn_present) {
|
if (phy_data.up_btn_present) {
|
||||||
button_timeout = phy_data.up_btn * 1000;
|
button_timeout = phy_data.up_btn * 1000;
|
||||||
|
}
|
||||||
if (button_timeout == 0) {
|
if (button_timeout == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
uint32_t start_button = board_millis();
|
uint32_t start_button = board_millis();
|
||||||
bool timeout = false;
|
bool timeout = false;
|
||||||
cancel_button = false;
|
cancel_button = false;
|
||||||
@@ -234,6 +237,35 @@ bool wait_button() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool set_rtc = false;
|
||||||
|
|
||||||
|
bool has_set_rtc() {
|
||||||
|
return set_rtc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_rtc_time(time_t t) {
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
struct timespec tv = {.tv_sec = t, .tv_nsec = 0};
|
||||||
|
aon_timer_set_time(&tv);
|
||||||
|
#else
|
||||||
|
struct timeval tv = {.tv_sec = t, .tv_usec = 0};
|
||||||
|
settimeofday(&tv, NULL);
|
||||||
|
#endif
|
||||||
|
set_rtc = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t get_rtc_time() {
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
struct timespec tv;
|
||||||
|
aon_timer_get_time(&tv);
|
||||||
|
return tv.tv_sec;
|
||||||
|
#else
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
return tv.tv_sec;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct apdu apdu;
|
struct apdu apdu;
|
||||||
|
|
||||||
void init_rtc() {
|
void init_rtc() {
|
||||||
@@ -244,7 +276,7 @@ void init_rtc() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void neug_task();
|
extern void hwrng_task();
|
||||||
extern void usb_task();
|
extern void usb_task();
|
||||||
void execute_tasks()
|
void execute_tasks()
|
||||||
{
|
{
|
||||||
@@ -258,7 +290,7 @@ void execute_tasks()
|
|||||||
void core0_loop() {
|
void core0_loop() {
|
||||||
while (1) {
|
while (1) {
|
||||||
execute_tasks();
|
execute_tasks();
|
||||||
neug_task();
|
hwrng_task();
|
||||||
do_flash();
|
do_flash();
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
if (button_pressed_cb && board_millis() > 1000 && !is_busy()) { // wait 1 second to boot up
|
if (button_pressed_cb && board_millis() > 1000 && !is_busy()) { // wait 1 second to boot up
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
#ifndef _PICO_KEYS_H_
|
#ifndef _PICO_KEYS_H_
|
||||||
#define _PICO_KEYS_H_
|
#define _PICO_KEYS_H_
|
||||||
|
|
||||||
|
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
|
||||||
|
|
||||||
#if defined(PICO_RP2040) || defined(PICO_RP2350)
|
#if defined(PICO_RP2040) || defined(PICO_RP2350)
|
||||||
#define PICO_PLATFORM
|
#define PICO_PLATFORM
|
||||||
#endif
|
#endif
|
||||||
@@ -59,6 +61,15 @@
|
|||||||
#include "pico/util/queue.h"
|
#include "pico/util/queue.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
#include "pico/bootrom.h"
|
||||||
|
#include "hardware/watchdog.h"
|
||||||
|
#include "pico/aon_timer.h"
|
||||||
|
#else
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
extern bool wait_button();
|
extern bool wait_button();
|
||||||
|
|
||||||
extern void low_flash_init_core1();
|
extern void low_flash_init_core1();
|
||||||
@@ -240,4 +251,8 @@ extern uint8_t pico_serial_hash[32];
|
|||||||
#define multicore_launch_func_core1(a) multicore_launch_core1((void (*) (void))a)
|
#define multicore_launch_func_core1(a) multicore_launch_core1((void (*) (void))a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern bool has_set_rtc();
|
||||||
|
extern time_t get_rtc_time();
|
||||||
|
extern void set_rtc_time(time_t tv_sec);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#ifndef __VERSION_H_
|
#ifndef __VERSION_H_
|
||||||
#define __VERSION_H_
|
#define __VERSION_H_
|
||||||
|
|
||||||
#define PICO_KEYS_SDK_VERSION 0x0800
|
#define PICO_KEYS_SDK_VERSION 0x0804
|
||||||
|
|
||||||
#define PICO_KEYS_SDK_VERSION_MAJOR ((PICO_KEYS_SDK_VERSION >> 8) & 0xff)
|
#define PICO_KEYS_SDK_VERSION_MAJOR ((PICO_KEYS_SDK_VERSION >> 8) & 0xff)
|
||||||
#define PICO_KEYS_SDK_VERSION_MINOR (PICO_KEYS_SDK_VERSION & 0xff)
|
#define PICO_KEYS_SDK_VERSION_MINOR (PICO_KEYS_SDK_VERSION & 0xff)
|
||||||
|
|||||||
175
src/rescue.c
175
src/rescue.c
@@ -19,9 +19,13 @@
|
|||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
#include "pico_keys_version.h"
|
#include "pico_keys_version.h"
|
||||||
#include "otp.h"
|
#include "otp.h"
|
||||||
|
#include "mbedtls/ecdsa.h"
|
||||||
|
#include "mbedtls/sha256.h"
|
||||||
|
#include "random.h"
|
||||||
|
|
||||||
#ifdef PICO_PLATFORM
|
#ifdef PICO_PLATFORM
|
||||||
#include "pico/bootrom.h"
|
extern char __flash_binary_start;
|
||||||
#include "hardware/watchdog.h"
|
extern char __flash_binary_end;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int rescue_process_apdu();
|
int rescue_process_apdu();
|
||||||
@@ -54,6 +58,8 @@ int rescue_select(app_t *a, uint8_t force) {
|
|||||||
res_APDU[res_APDU_size++] = PICO_PRODUCT;
|
res_APDU[res_APDU_size++] = PICO_PRODUCT;
|
||||||
res_APDU[res_APDU_size++] = PICO_VERSION_MAJOR;
|
res_APDU[res_APDU_size++] = PICO_VERSION_MAJOR;
|
||||||
res_APDU[res_APDU_size++] = PICO_VERSION_MINOR;
|
res_APDU[res_APDU_size++] = PICO_VERSION_MINOR;
|
||||||
|
memcpy(res_APDU + res_APDU_size, pico_serial.id, sizeof(pico_serial.id));
|
||||||
|
res_APDU_size += sizeof(pico_serial.id);
|
||||||
apdu.ne = res_APDU_size;
|
apdu.ne = res_APDU_size;
|
||||||
if (force) {
|
if (force) {
|
||||||
scan_flash();
|
scan_flash();
|
||||||
@@ -69,12 +75,107 @@ int rescue_unload() {
|
|||||||
return PICOKEY_OK;
|
return PICOKEY_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cmd_keydev_sign() {
|
||||||
|
uint8_t p1 = P1(apdu);
|
||||||
|
if (p1 == 0x01) {
|
||||||
|
if (apdu.nc != 32) {
|
||||||
|
return SW_WRONG_LENGTH();
|
||||||
|
}
|
||||||
|
if (!otp_key_2) {
|
||||||
|
return SW_INS_NOT_SUPPORTED();
|
||||||
|
}
|
||||||
|
mbedtls_ecdsa_context ecdsa;
|
||||||
|
mbedtls_ecdsa_init(&ecdsa);
|
||||||
|
int ret = mbedtls_ecp_read_key(MBEDTLS_ECP_DP_SECP256K1, &ecdsa, otp_key_2, 32);
|
||||||
|
if (ret != 0) {
|
||||||
|
mbedtls_ecdsa_free(&ecdsa);
|
||||||
|
return SW_EXEC_ERROR();
|
||||||
|
}
|
||||||
|
uint16_t key_size = 2 * (int)((mbedtls_ecp_curve_info_from_grp_id(MBEDTLS_ECP_DP_SECP256K1)->bit_size + 7) / 8);
|
||||||
|
mbedtls_mpi r, s;
|
||||||
|
mbedtls_mpi_init(&r);
|
||||||
|
mbedtls_mpi_init(&s);
|
||||||
|
|
||||||
|
ret = mbedtls_ecdsa_sign(&ecdsa.MBEDTLS_PRIVATE(grp), &r, &s, &ecdsa.MBEDTLS_PRIVATE(d), apdu.data, apdu.nc, random_gen, NULL);
|
||||||
|
if (ret != 0) {
|
||||||
|
mbedtls_ecdsa_free(&ecdsa);
|
||||||
|
mbedtls_mpi_free(&r);
|
||||||
|
mbedtls_mpi_free(&s);
|
||||||
|
return SW_EXEC_ERROR();
|
||||||
|
}
|
||||||
|
|
||||||
|
mbedtls_mpi_write_binary(&r, res_APDU, key_size / 2); res_APDU_size = key_size / 2;
|
||||||
|
mbedtls_mpi_write_binary(&s, res_APDU + res_APDU_size, key_size / 2); res_APDU_size += key_size / 2;
|
||||||
|
mbedtls_ecdsa_free(&ecdsa);
|
||||||
|
mbedtls_mpi_free(&r);
|
||||||
|
mbedtls_mpi_free(&s);
|
||||||
|
}
|
||||||
|
else if (p1 == 0x02) {
|
||||||
|
// Return public key
|
||||||
|
if (!otp_key_2) {
|
||||||
|
return SW_INS_NOT_SUPPORTED();
|
||||||
|
}
|
||||||
|
if (apdu.nc != 0) {
|
||||||
|
return SW_WRONG_LENGTH();
|
||||||
|
}
|
||||||
|
mbedtls_ecp_keypair ecp;
|
||||||
|
mbedtls_ecp_keypair_init(&ecp);
|
||||||
|
int ret = mbedtls_ecp_read_key(MBEDTLS_ECP_DP_SECP256K1, &ecp, otp_key_2, 32);
|
||||||
|
if (ret != 0) {
|
||||||
|
mbedtls_ecp_keypair_free(&ecp);
|
||||||
|
return SW_EXEC_ERROR();
|
||||||
|
}
|
||||||
|
ret = mbedtls_ecp_mul(&ecp.MBEDTLS_PRIVATE(grp), &ecp.MBEDTLS_PRIVATE(Q), &ecp.MBEDTLS_PRIVATE(d), &ecp.MBEDTLS_PRIVATE(grp).G, random_gen, NULL);
|
||||||
|
if (ret != 0) {
|
||||||
|
mbedtls_ecp_keypair_free(&ecp);
|
||||||
|
return SW_EXEC_ERROR();
|
||||||
|
}
|
||||||
|
size_t olen = 0;
|
||||||
|
ret = mbedtls_ecp_point_write_binary(&ecp.MBEDTLS_PRIVATE(grp), &ecp.MBEDTLS_PRIVATE(Q), MBEDTLS_ECP_PF_UNCOMPRESSED, &olen, res_APDU, 4096);
|
||||||
|
if (ret != 0) {
|
||||||
|
mbedtls_ecp_keypair_free(&ecp);
|
||||||
|
return SW_EXEC_ERROR();
|
||||||
|
}
|
||||||
|
res_APDU_size = (uint16_t)olen;
|
||||||
|
mbedtls_ecp_keypair_free(&ecp);
|
||||||
|
}
|
||||||
|
else if (p1 == 0x03) {
|
||||||
|
// Upload device attestation certificate
|
||||||
|
if (apdu.nc == 0) {
|
||||||
|
return SW_WRONG_LENGTH();
|
||||||
|
}
|
||||||
|
file_t *ef_devcert = file_new(0x2F02); // EF_DEVCERT
|
||||||
|
if (!ef_devcert) {
|
||||||
|
return SW_FILE_NOT_FOUND();
|
||||||
|
}
|
||||||
|
file_put_data(ef_devcert, apdu.data, (uint16_t)apdu.nc);
|
||||||
|
res_APDU_size = 0;
|
||||||
|
low_flash_available();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SW_INCORRECT_P1P2();
|
||||||
|
}
|
||||||
|
return SW_OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blocking CORE1
|
||||||
|
void led_3_blinks() {
|
||||||
|
#ifndef ENABLE_EMULATION
|
||||||
|
uint32_t mode = led_get_mode();
|
||||||
|
led_set_mode(MODE_PROCESSING);
|
||||||
|
sleep_ms(500);
|
||||||
|
led_set_mode(mode);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int cmd_write() {
|
int cmd_write() {
|
||||||
if (apdu.nc < 2) {
|
if (apdu.nc < 2) {
|
||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (P1(apdu) == 0x1) { // PHY
|
uint8_t p1 = P1(apdu), p2 = P2(apdu);
|
||||||
|
|
||||||
|
if (p1 == 0x1) { // PHY
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
int ret = phy_unserialize_data(apdu.data, (uint16_t)apdu.nc, &phy_data);
|
int ret = phy_unserialize_data(apdu.data, (uint16_t)apdu.nc, &phy_data);
|
||||||
if (ret == PICOKEY_OK) {
|
if (ret == PICOKEY_OK) {
|
||||||
@@ -84,6 +185,35 @@ int cmd_write() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
else if (p1 == 0x2) { // SET TIME
|
||||||
|
time_t tv_sec = 0;
|
||||||
|
if (p2 != 0x1 && p2 != 0x2) {
|
||||||
|
return SW_INCORRECT_P1P2();
|
||||||
|
}
|
||||||
|
if (p2 == 0x1) {
|
||||||
|
if (apdu.nc != 8) {
|
||||||
|
return SW_WRONG_LENGTH();
|
||||||
|
}
|
||||||
|
struct tm tm;
|
||||||
|
tm.tm_year = get_uint16_t_be(apdu.data) - 1900;
|
||||||
|
tm.tm_mon = apdu.data[2];
|
||||||
|
tm.tm_mday = apdu.data[3];
|
||||||
|
tm.tm_wday = apdu.data[4];
|
||||||
|
tm.tm_hour = apdu.data[5];
|
||||||
|
tm.tm_min = apdu.data[6];
|
||||||
|
tm.tm_sec = apdu.data[7];
|
||||||
|
tv_sec = mktime(&tm);
|
||||||
|
}
|
||||||
|
else if (p2 == 0x2) {
|
||||||
|
if (apdu.nc != 4) {
|
||||||
|
return SW_WRONG_LENGTH();
|
||||||
|
}
|
||||||
|
uint32_t t = (apdu.data[0] << 24) | (apdu.data[1] << 16) | (apdu.data[2] << 8) | apdu.data[3];
|
||||||
|
tv_sec = (time_t)t;
|
||||||
|
}
|
||||||
|
set_rtc_time(tv_sec);
|
||||||
|
}
|
||||||
|
led_3_blinks();
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +222,7 @@ int cmd_read() {
|
|||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t p1 = P1(apdu);
|
uint8_t p1 = P1(apdu), p2 = P2(apdu);
|
||||||
if (p1 == 0x1) { // PHY
|
if (p1 == 0x1) { // PHY
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
uint16_t len = 0;
|
uint16_t len = 0;
|
||||||
@@ -111,6 +241,12 @@ int cmd_read() {
|
|||||||
res_APDU_size += put_uint32_t_be(total, res_APDU + res_APDU_size);
|
res_APDU_size += put_uint32_t_be(total, res_APDU + res_APDU_size);
|
||||||
res_APDU_size += put_uint32_t_be(nfiles, res_APDU + res_APDU_size);
|
res_APDU_size += put_uint32_t_be(nfiles, res_APDU + res_APDU_size);
|
||||||
res_APDU_size += put_uint32_t_be(size, res_APDU + res_APDU_size);
|
res_APDU_size += put_uint32_t_be(size, res_APDU + res_APDU_size);
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
uintptr_t start = (uintptr_t) &__flash_binary_start;
|
||||||
|
uintptr_t end = (uintptr_t) &__flash_binary_end;
|
||||||
|
uint32_t fw_size = (uint32_t)(end - start);
|
||||||
|
res_APDU_size += put_uint32_t_be(fw_size, res_APDU + res_APDU_size);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (p1 == 0x3) { // OTP SECURE BOOT STATUS
|
else if (p1 == 0x3) { // OTP SECURE BOOT STATUS
|
||||||
res_APDU_size = 0;
|
res_APDU_size = 0;
|
||||||
@@ -121,6 +257,34 @@ int cmd_read() {
|
|||||||
res_APDU[res_APDU_size++] = locked ? 0x1 : 0x0;
|
res_APDU[res_APDU_size++] = locked ? 0x1 : 0x0;
|
||||||
res_APDU[res_APDU_size++] = bootkey;
|
res_APDU[res_APDU_size++] = bootkey;
|
||||||
}
|
}
|
||||||
|
else if (p1 == 0x4) { // GET TIME
|
||||||
|
if (p2 != 0x1 && p2 != 0x2) {
|
||||||
|
return SW_INCORRECT_P1P2();
|
||||||
|
}
|
||||||
|
if (!has_set_rtc()) {
|
||||||
|
return SW_CONDITIONS_NOT_SATISFIED();
|
||||||
|
}
|
||||||
|
res_APDU_size = 0;
|
||||||
|
time_t tv_sec = get_rtc_time();
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
struct timespec tv = {.tv_sec = tv_sec, .tv_nsec = 0};
|
||||||
|
#else
|
||||||
|
struct timeval tv = {.tv_sec = tv_sec, .tv_usec = 0};
|
||||||
|
#endif
|
||||||
|
if (p2 == 0x1) {
|
||||||
|
struct tm *tm = localtime(&tv.tv_sec);
|
||||||
|
res_APDU_size += put_uint16_t_be(tm->tm_year + 1900, res_APDU);
|
||||||
|
res_APDU[res_APDU_size++] = tm->tm_mon;
|
||||||
|
res_APDU[res_APDU_size++] = tm->tm_mday;
|
||||||
|
res_APDU[res_APDU_size++] = tm->tm_wday;
|
||||||
|
res_APDU[res_APDU_size++] = tm->tm_hour;
|
||||||
|
res_APDU[res_APDU_size++] = tm->tm_min;
|
||||||
|
res_APDU[res_APDU_size++] = tm->tm_sec;
|
||||||
|
}
|
||||||
|
else if (p2 == 0x2) {
|
||||||
|
res_APDU_size += put_uint32_t_be((uint32_t)tv.tv_sec, res_APDU);
|
||||||
|
}
|
||||||
|
}
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +301,7 @@ int cmd_secure() {
|
|||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
}
|
}
|
||||||
|
led_3_blinks();
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -163,12 +328,14 @@ int cmd_reboot_bootsel() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define INS_KEYDEV_SIGN 0x10
|
||||||
#define INS_WRITE 0x1C
|
#define INS_WRITE 0x1C
|
||||||
#define INS_SECURE 0x1D
|
#define INS_SECURE 0x1D
|
||||||
#define INS_READ 0x1E
|
#define INS_READ 0x1E
|
||||||
#define INS_REBOOT_BOOTSEL 0x1F
|
#define INS_REBOOT_BOOTSEL 0x1F
|
||||||
|
|
||||||
static const cmd_t cmds[] = {
|
static const cmd_t cmds[] = {
|
||||||
|
{ INS_KEYDEV_SIGN, cmd_keydev_sign },
|
||||||
{ INS_WRITE, cmd_write },
|
{ INS_WRITE, cmd_write },
|
||||||
#if defined(PICO_RP2350) || defined(ESP_PLATFORM)
|
#if defined(PICO_RP2350) || defined(ESP_PLATFORM)
|
||||||
{ INS_SECURE, cmd_secure },
|
{ INS_SECURE, cmd_secure },
|
||||||
|
|||||||
@@ -44,17 +44,17 @@ void hwrng_start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t random_word = 0xcbf29ce484222325;
|
static uint64_t random_word = 0xcbf29ce484222325;
|
||||||
static uint8_t ep_round = 0;
|
static uint8_t hwrng_mix_round = 0;
|
||||||
|
|
||||||
static void ep_init() {
|
static void hwrng_mix_init() {
|
||||||
random_word = 0xcbf29ce484222325;
|
random_word = 0xcbf29ce484222325;
|
||||||
ep_round = 0;
|
hwrng_mix_round = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Here, we assume a little endian architecture. */
|
/* Here, we assume a little endian architecture. */
|
||||||
static int ep_process() {
|
static int hwrng_mix_process() {
|
||||||
if (ep_round == 0) {
|
if (hwrng_mix_round == 0) {
|
||||||
ep_init();
|
hwrng_mix_init();
|
||||||
}
|
}
|
||||||
uint64_t word = 0x0;
|
uint64_t word = 0x0;
|
||||||
|
|
||||||
@@ -69,14 +69,14 @@ static int ep_process() {
|
|||||||
#endif
|
#endif
|
||||||
random_word ^= word ^ board_millis();
|
random_word ^= word ^ board_millis();
|
||||||
random_word *= 0x00000100000001B3;
|
random_word *= 0x00000100000001B3;
|
||||||
if (++ep_round == 8) {
|
if (++hwrng_mix_round == 8) {
|
||||||
ep_round = 0;
|
hwrng_mix_round = 0;
|
||||||
return 2; //2 words
|
return sizeof(uint64_t) / sizeof(uint32_t); //2 words
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct rng_rb {
|
struct hwrng_buf {
|
||||||
uint32_t *buf;
|
uint32_t *buf;
|
||||||
uint8_t head, tail;
|
uint8_t head, tail;
|
||||||
uint8_t size;
|
uint8_t size;
|
||||||
@@ -84,7 +84,7 @@ struct rng_rb {
|
|||||||
unsigned int empty : 1;
|
unsigned int empty : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void rb_init(struct rng_rb *rb, uint32_t *p, uint8_t size) {
|
static void hwrng_buf_init(struct hwrng_buf *rb, uint32_t *p, uint8_t size) {
|
||||||
rb->buf = p;
|
rb->buf = p;
|
||||||
rb->size = size;
|
rb->size = size;
|
||||||
rb->head = rb->tail = 0;
|
rb->head = rb->tail = 0;
|
||||||
@@ -92,7 +92,7 @@ static void rb_init(struct rng_rb *rb, uint32_t *p, uint8_t size) {
|
|||||||
rb->empty = 1;
|
rb->empty = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rb_add(struct rng_rb *rb, uint32_t v) {
|
static void hwrng_buf_add(struct hwrng_buf *rb, uint32_t v) {
|
||||||
rb->buf[rb->tail++] = v;
|
rb->buf[rb->tail++] = v;
|
||||||
if (rb->tail == rb->size) {
|
if (rb->tail == rb->size) {
|
||||||
rb->tail = 0;
|
rb->tail = 0;
|
||||||
@@ -103,7 +103,7 @@ static void rb_add(struct rng_rb *rb, uint32_t v) {
|
|||||||
rb->empty = 0;
|
rb->empty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t rb_del(struct rng_rb *rb) {
|
static uint32_t hwrng_buf_del(struct hwrng_buf *rb) {
|
||||||
uint32_t v = rb->buf[rb->head++];
|
uint32_t v = rb->buf[rb->head++];
|
||||||
|
|
||||||
if (rb->head == rb->size) {
|
if (rb->head == rb->size) {
|
||||||
@@ -117,19 +117,18 @@ static uint32_t rb_del(struct rng_rb *rb) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct rng_rb the_ring_buffer;
|
static struct hwrng_buf ring_buffer;
|
||||||
|
|
||||||
void *neug_task() {
|
void *hwrng_task() {
|
||||||
struct rng_rb *rb = &the_ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if ((n = ep_process())) {
|
if ((n = hwrng_mix_process())) {
|
||||||
int i;
|
|
||||||
const uint32_t *vp = (const uint32_t *) &random_word;
|
const uint32_t *vp = (const uint32_t *) &random_word;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
rb_add(rb, *vp++);
|
hwrng_buf_add(rb, *vp++);
|
||||||
if (rb->full) {
|
if (rb->full) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -138,38 +137,37 @@ void *neug_task() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void neug_init(uint32_t *buf, uint8_t size) {
|
void hwrng_init(uint32_t *buf, uint8_t size) {
|
||||||
struct rng_rb *rb = &the_ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
|
|
||||||
rb_init(rb, buf, size);
|
hwrng_buf_init(rb, buf, size);
|
||||||
|
|
||||||
hwrng_start();
|
hwrng_start();
|
||||||
|
|
||||||
ep_init();
|
hwrng_mix_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void neug_flush(void) {
|
void hwrng_flush(void) {
|
||||||
struct rng_rb *rb = &the_ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
|
|
||||||
while (!rb->empty) {
|
while (!rb->empty) {
|
||||||
rb_del(rb);
|
hwrng_buf_del(rb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t neug_get() {
|
uint32_t hwrng_get() {
|
||||||
struct rng_rb *rb = &the_ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
uint32_t v;
|
uint32_t v;
|
||||||
|
|
||||||
while (rb->empty) {
|
while (rb->empty) {
|
||||||
neug_task();
|
hwrng_task();
|
||||||
}
|
}
|
||||||
v = rb_del(rb);
|
v = hwrng_buf_del(rb);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void neug_wait_full() {
|
void hwrng_wait_full() {
|
||||||
struct rng_rb *rb = &the_ring_buffer;
|
struct hwrng_buf *rb = &ring_buffer;
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
uint8_t core = xTaskGetCurrentTaskHandle() == hcore1 ? 1 : 0;
|
uint8_t core = xTaskGetCurrentTaskHandle() == hcore1 ? 1 : 0;
|
||||||
#elif defined(PICO_PLATFORM)
|
#elif defined(PICO_PLATFORM)
|
||||||
@@ -182,6 +180,6 @@ void neug_wait_full() {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
neug_task();
|
hwrng_task();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,17 +17,11 @@
|
|||||||
|
|
||||||
#ifndef _NEUG_H_
|
#ifndef _NEUG_H_
|
||||||
#define _NEUG_H_
|
#define _NEUG_H_
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#define NEUG_PRE_LOOP 32
|
void hwrng_init(uint32_t *buf, uint8_t size);
|
||||||
|
uint32_t hwrng_get();
|
||||||
#include <stdlib.h>
|
void hwrng_flush(void);
|
||||||
#if defined(PICO_PLATFORM)
|
void hwrng_wait_full();
|
||||||
#include "pico/stdlib.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void neug_init(uint32_t *buf, uint8_t size);
|
|
||||||
uint32_t neug_get();
|
|
||||||
void neug_flush(void);
|
|
||||||
void neug_wait_full();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,8 +15,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define HWRNG_PRE_LOOP 32
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdlib.h>
|
||||||
|
#if defined(PICO_PLATFORM)
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#endif
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "hwrng.h"
|
#include "hwrng.h"
|
||||||
@@ -25,42 +29,38 @@
|
|||||||
static uint32_t random_word[RANDOM_BYTES_LENGTH / sizeof(uint32_t)];
|
static uint32_t random_word[RANDOM_BYTES_LENGTH / sizeof(uint32_t)];
|
||||||
|
|
||||||
void random_init(void) {
|
void random_init(void) {
|
||||||
int i;
|
hwrng_init(random_word, RANDOM_BYTES_LENGTH / sizeof(uint32_t));
|
||||||
|
|
||||||
neug_init(random_word, RANDOM_BYTES_LENGTH / sizeof(uint32_t));
|
for (int i = 0; i < HWRNG_PRE_LOOP; i++) {
|
||||||
|
hwrng_get();
|
||||||
for (i = 0; i < NEUG_PRE_LOOP; i++) {
|
|
||||||
neug_get();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Return pointer to random 32-byte
|
|
||||||
*/
|
|
||||||
void random_bytes_free(const uint8_t *p);
|
|
||||||
#define MAX_RANDOM_BUFFER 1024
|
|
||||||
const uint8_t *random_bytes_get(size_t len) {
|
|
||||||
if (len > MAX_RANDOM_BUFFER) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
static uint32_t return_word[MAX_RANDOM_BUFFER / sizeof(uint32_t)];
|
|
||||||
for (size_t ix = 0; ix < len; ix += RANDOM_BYTES_LENGTH) {
|
|
||||||
neug_wait_full();
|
|
||||||
memcpy(return_word + ix / sizeof(uint32_t), random_word, RANDOM_BYTES_LENGTH);
|
|
||||||
random_bytes_free((const uint8_t *) random_word);
|
|
||||||
}
|
|
||||||
return (const uint8_t *) return_word;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free pointer to random 32-byte
|
* Free pointer to random 32-byte
|
||||||
*/
|
*/
|
||||||
void random_bytes_free(const uint8_t *p) {
|
void random_bytes_free(const uint8_t *p) {
|
||||||
(void) p;
|
(void) p;
|
||||||
memset(random_word, 0, RANDOM_BYTES_LENGTH);
|
memset(random_word, 0, RANDOM_BYTES_LENGTH);
|
||||||
neug_flush();
|
hwrng_flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return pointer to random 32-byte
|
||||||
|
*/
|
||||||
|
#define MAX_RANDOM_BUFFER 1024
|
||||||
|
const uint8_t *random_bytes_get(size_t len) {
|
||||||
|
if (len > MAX_RANDOM_BUFFER) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
static uint32_t return_word[MAX_RANDOM_BUFFER / sizeof(uint32_t)];
|
||||||
|
for (size_t ix = 0; ix < len; ix += RANDOM_BYTES_LENGTH) {
|
||||||
|
hwrng_wait_full();
|
||||||
|
memcpy(return_word + ix / sizeof(uint32_t), random_word, RANDOM_BYTES_LENGTH);
|
||||||
|
random_bytes_free((const uint8_t *) random_word);
|
||||||
|
}
|
||||||
|
return (const uint8_t *) return_word;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Random byte iterator
|
* Random byte iterator
|
||||||
@@ -71,7 +71,7 @@ int random_gen(void *arg, unsigned char *out, size_t out_len) {
|
|||||||
uint8_t n;
|
uint8_t n;
|
||||||
|
|
||||||
while (out_len) {
|
while (out_len) {
|
||||||
neug_wait_full();
|
hwrng_wait_full();
|
||||||
|
|
||||||
n = RANDOM_BYTES_LENGTH - index;
|
n = RANDOM_BYTES_LENGTH - index;
|
||||||
if (n > out_len) {
|
if (n > out_len) {
|
||||||
@@ -85,7 +85,7 @@ int random_gen(void *arg, unsigned char *out, size_t out_len) {
|
|||||||
|
|
||||||
if (index >= RANDOM_BYTES_LENGTH) {
|
if (index >= RANDOM_BYTES_LENGTH) {
|
||||||
index = 0;
|
index = 0;
|
||||||
neug_flush();
|
hwrng_flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,3 +95,9 @@ int random_gen(void *arg, unsigned char *out, size_t out_len) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_PQC
|
||||||
|
void randombytes(uint8_t *buf, size_t n) {
|
||||||
|
random_gen(NULL, buf, n);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -201,6 +201,20 @@ int driver_process_usb_packet_ccid(uint8_t itf, uint16_t rx_read) {
|
|||||||
(void) rx_read;
|
(void) rx_read;
|
||||||
if (ccid_rx[itf].w_ptr - ccid_rx[itf].r_ptr >= 10) {
|
if (ccid_rx[itf].w_ptr - ccid_rx[itf].r_ptr >= 10) {
|
||||||
driver_init_ccid(itf);
|
driver_init_ccid(itf);
|
||||||
|
if (ccid_header[itf]->dwLength > USB_BUFFER_SIZE - 10) {
|
||||||
|
//Invalid length
|
||||||
|
ccid_rx[itf].r_ptr = ccid_rx[itf].w_ptr = 0;
|
||||||
|
|
||||||
|
ccid_resp_fast[itf]->bMessageType = CCID_DATA_BLOCK_RET;
|
||||||
|
ccid_resp_fast[itf]->dwLength = 2;
|
||||||
|
ccid_resp_fast[itf]->bSlot = 0;
|
||||||
|
ccid_resp_fast[itf]->bSeq = ccid_header[itf]->bSeq;
|
||||||
|
ccid_resp_fast[itf]->abRFU0 = ccid_status;
|
||||||
|
ccid_resp_fast[itf]->abRFU1 = 0;
|
||||||
|
memcpy(&ccid_resp_fast[itf]->apdu, "\x6F\x00", 2);
|
||||||
|
ccid_write_fast(itf, (const uint8_t *)ccid_resp_fast[itf], 12);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
//printf("ccid_process %ld %d %x %x %d\n",ccid_header[itf]->dwLength,rx_read-10,ccid_header[itf]->bMessageType,ccid_header[itf]->bSeq,ccid_rx[itf].w_ptr - ccid_rx[itf].r_ptr - 10);
|
//printf("ccid_process %ld %d %x %x %d\n",ccid_header[itf]->dwLength,rx_read-10,ccid_header[itf]->bMessageType,ccid_header[itf]->bSeq,ccid_rx[itf].w_ptr - ccid_rx[itf].r_ptr - 10);
|
||||||
if (ccid_header[itf]->dwLength <= (uint32_t)(ccid_rx[itf].w_ptr - ccid_rx[itf].r_ptr - 10)){
|
if (ccid_header[itf]->dwLength <= (uint32_t)(ccid_rx[itf].w_ptr - ccid_rx[itf].r_ptr - 10)){
|
||||||
ccid_rx[itf].r_ptr += (uint16_t)(ccid_header[itf]->dwLength + 10);
|
ccid_rx[itf].r_ptr += (uint16_t)(ccid_header[itf]->dwLength + 10);
|
||||||
|
|||||||
@@ -73,8 +73,10 @@ queue_t card_to_usb_q = {0};
|
|||||||
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
extern tusb_desc_device_t desc_device;
|
extern tusb_desc_device_t desc_device;
|
||||||
|
extern char *string_desc_itf[4], *string_desc_arr[];
|
||||||
#endif
|
#endif
|
||||||
void usb_init() {
|
void usb_init()
|
||||||
|
{
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
if (phy_data.vidpid_present) {
|
if (phy_data.vidpid_present) {
|
||||||
desc_device.idVendor = phy_data.vid;
|
desc_device.idVendor = phy_data.vid;
|
||||||
@@ -108,20 +110,32 @@ void usb_init() {
|
|||||||
if (enabled_usb_itf & PHY_USB_ITF_HID) {
|
if (enabled_usb_itf & PHY_USB_ITF_HID) {
|
||||||
ITF_HID_CTAP = ITF_HID_TOTAL++;
|
ITF_HID_CTAP = ITF_HID_TOTAL++;
|
||||||
ITF_HID = ITF_TOTAL++;
|
ITF_HID = ITF_TOTAL++;
|
||||||
|
#ifndef ENABLE_EMULATION
|
||||||
|
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[5];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (enabled_usb_itf & PHY_USB_ITF_KB) {
|
if (enabled_usb_itf & PHY_USB_ITF_KB) {
|
||||||
ITF_HID_KB = ITF_HID_TOTAL++;
|
ITF_HID_KB = ITF_HID_TOTAL++;
|
||||||
ITF_KEYBOARD = ITF_TOTAL++;
|
ITF_KEYBOARD = ITF_TOTAL++;
|
||||||
|
#ifndef ENABLE_EMULATION
|
||||||
|
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[6];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
if (enabled_usb_itf & PHY_USB_ITF_CCID) {
|
if (enabled_usb_itf & PHY_USB_ITF_CCID) {
|
||||||
ITF_SC_CCID = ITF_SC_TOTAL++;
|
ITF_SC_CCID = ITF_SC_TOTAL++;
|
||||||
ITF_CCID = ITF_TOTAL++;
|
ITF_CCID = ITF_TOTAL++;
|
||||||
|
#ifndef ENABLE_EMULATION
|
||||||
|
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[7];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (enabled_usb_itf & PHY_USB_ITF_WCID) {
|
if (enabled_usb_itf & PHY_USB_ITF_WCID) {
|
||||||
ITF_SC_WCID = ITF_SC_TOTAL++;
|
ITF_SC_WCID = ITF_SC_TOTAL++;
|
||||||
ITF_WCID = ITF_TOTAL++;
|
ITF_WCID = ITF_TOTAL++;
|
||||||
|
#ifndef ENABLE_EMULATION
|
||||||
|
string_desc_itf[ITF_TOTAL - 1] = string_desc_arr[8];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
card_locked_itf = ITF_TOTAL;
|
card_locked_itf = ITF_TOTAL;
|
||||||
|
|||||||
@@ -28,14 +28,14 @@
|
|||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
#ifndef USB_VID
|
#ifndef USB_VID
|
||||||
#define USB_VID 0xFEFF
|
#define USB_VID 0x2E8A
|
||||||
#endif
|
#endif
|
||||||
#ifndef USB_PID
|
#ifndef USB_PID
|
||||||
#define USB_PID 0xFCFD
|
#define USB_PID 0x10FD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
|
||||||
#define USB_BCD 0x0200
|
#define USB_BCD 0x0210
|
||||||
#else
|
#else
|
||||||
#define USB_BCD 0x0110
|
#define USB_BCD 0x0110
|
||||||
#endif
|
#endif
|
||||||
@@ -107,7 +107,7 @@ uint8_t const desc_hid_report_kb[] = {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
EPNUM_DUMMY = 1,
|
EPNUM_DUMMY = 0,
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
EPNUM_CCID,
|
EPNUM_CCID,
|
||||||
#if TUSB_SMARTCARD_CCID_EPS == 3
|
#if TUSB_SMARTCARD_CCID_EPS == 3
|
||||||
@@ -136,7 +136,7 @@ enum {
|
|||||||
#if TUSB_SMARTCARD_CCID_EPS == 3
|
#if TUSB_SMARTCARD_CCID_EPS == 3
|
||||||
#define TUD_SMARTCARD_DESCRIPTOR(_itf, _strix, _epout, _epin, _epint, _epsize) \
|
#define TUD_SMARTCARD_DESCRIPTOR(_itf, _strix, _epout, _epin, _epint, _epsize) \
|
||||||
TUD_SMARTCARD_DESCRIPTOR_2EP(_itf, _strix, _epout, _epin, _epsize), \
|
TUD_SMARTCARD_DESCRIPTOR_2EP(_itf, _strix, _epout, _epin, _epsize), \
|
||||||
7, TUSB_DESC_ENDPOINT, _epint, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), 0
|
7, TUSB_DESC_ENDPOINT, _epint, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), 10
|
||||||
#else
|
#else
|
||||||
#define TUD_SMARTCARD_DESCRIPTOR(_itf, _strix, _epout, _epin, _epint, _epsize) \
|
#define TUD_SMARTCARD_DESCRIPTOR(_itf, _strix, _epout, _epin, _epint, _epsize) \
|
||||||
TUD_SMARTCARD_DESCRIPTOR_2EP(_itf, _strix, _epout, _epin, _epsize)
|
TUD_SMARTCARD_DESCRIPTOR_2EP(_itf, _strix, _epout, _epin, _epsize)
|
||||||
@@ -316,6 +316,7 @@ uint8_t const *tud_descriptor_bos_cb(void) {
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
// array of pointer to string descriptors
|
// array of pointer to string descriptors
|
||||||
|
char *string_desc_itf[4] = {0};
|
||||||
char const *string_desc_arr [] = {
|
char const *string_desc_arr [] = {
|
||||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||||
"Pol Henarejos", // 1: Manufacturer
|
"Pol Henarejos", // 1: Manufacturer
|
||||||
@@ -369,6 +370,9 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
|||||||
str = phy_data.usb_product;
|
str = phy_data.usb_product;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (index >= 5 && string_desc_itf[index - 5] != NULL) {
|
||||||
|
str = string_desc_itf[index - 5];
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1;
|
uint8_t buff_avail = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1;
|
||||||
if (index >= 4) {
|
if (index >= 4) {
|
||||||
|
|||||||
23
src/version.c
Normal file
23
src/version.c
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Pico Keys SDK distribution (https://github.com/polhenarejos/pico-keys-sdk).
|
||||||
|
* Copyright (c) 2022 Pol Henarejos.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pico_keys.h"
|
||||||
|
#include "pico_keys_version.h"
|
||||||
|
|
||||||
|
const uint8_t PICO_PRODUCT = 0;
|
||||||
|
const uint8_t PICO_VERSION_MAJOR = PICO_KEYS_SDK_VERSION_MAJOR;
|
||||||
|
const uint8_t PICO_VERSION_MINOR = PICO_KEYS_SDK_VERSION_MINOR;
|
||||||
Reference in New Issue
Block a user