canokeys/canokey-core
Core implementations of an open-source secure key
Featured achievements
The project's latest awards
#1 Repository of the week
#1 Repository of the week
#2 Repository of the week
Canokey Core
Introduction
Core implementations of an open-source secure key, with supports of:
- U2F / FIDO2 with ed25519 and HMAC-secret
- OpenPGP Card V3.4, Supported Algorithm List
- PIV (NIST SP 800-73-4)
- HOTP / TOTP
- NDEF
The USB mode contains 3 different interfaces:
- Interface 0: U2F / FIDO2, which is an HID interface
- Interface 1: PIV/OpenPGP/OATH Card, which is a CCID interface
- Interface 2: WebUSB, which is not a standard interface
- Interface 3: Keyboard
The WebUSB interface is used to configure the key via a web-based interface.
Protocol
Please refer to the documentation.
PIN Retry Configuration Extensions
This core implements vendor APDUs for configuring PIV and OpenPGP retry limits. Retry counts must be in the range 1..15; 15 is the maximum because failed-verification warnings are returned as 63Cx.
The PIV management key in slot 9B uses AES-192 (0x0A) exclusively. Its factory value remains 010203040506070801020304050607080102030405060708, matching YubiKey 5.7 and later.
- PIV:
00 FA <pinRetries> <pukRetries>with no data. The command requires management-key authentication and PIN verification, resets PIN to123456\xFF\xFF, resets PUK to12345678, and installs the requested retry limits. - OpenPGP:
00 F2 00 00 03 <pw1Retries> <resetCodeRetries> <pw3Retries>. The command requires PW3 verification, resets PW1 to123456, resets PW3 to12345678, and updates the reset-code retry limit.
Porting
Use Canokey-STM32 as an example.
-
You need to implement these functions in
device.h:void device_delay(int ms);uint32_t device_get_tick(void);int device_spinlock_lock(volatile uint32_t *lock, uint32_t blocking);void device_spinlock_unlock(volatile uint32_t *lock);int device_atomic_compare_and_swap(volatile uint32_t *var, uint32_t expect, uint32_t update);void led_on(void);void led_off(void);void device_set_timeout(void (*callback)(void), uint16_t timeout);- A hardware timer with IRQ is required
If you need NFC, you also need to implement the following functions for FM11NC08:
void fm_csn_low(void);void fm_csn_high(void);void spi_transmit(uint8_t *buf, uint8_t len);void spi_receive(uint8_t *buf, uint8_t len);
or the following functions if you use FM11NT08:
void fm_csn_low(void);void fm_csn_high(void);void i2c_start(void);void i2c_stop(void);void scl_delay(void);uint8_t i2c_read_ack(void);void i2c_send_ack(void);void i2c_send_nack(void);bool i2c_write_byte(uint8_t data);uint8_t i2c_read_byte(void);
-
You should also provide a
random32and a optionalrandom_bufferfunction inrand.h. -
You need to configure the littlefs properly.
-
You need to configure the mbed-tls according to its documentation or provide the algorithms on your own by overwriting the weak symbols.
Or instead, you may implement the cryptography algorithms by yourself.
-
You should call the
device_loopornfc_loopin the main loop, and thedevice_update_ledin a periodic interrupt. -
You should call the
set_touch_resultto report touch sensing result, andset_nfc_stateto report NFC state.
Fuzz testing
Install honggfuzz from source first, then enable fuzz tests:
cd build
cmake .. -DENABLE_FUZZING=ON -DENABLE_TESTS=ON -DCMAKE_C_COMPILER=hfuzz-clang -DCMAKE_BUILD_TYPE=Debug
Then, run fuzzing tests:
./fuzzer/run-fuzzer.sh honggfuzz ${id}
License
Similar Projects
Discover other similar projects and AI models.
Python library and command line tool for configuring any YubiKey over all USB interfaces.
OpenSK is an open-source implementation for security keys written in Rust that supports both FIDO U2F and FIDO2 standards.
🔏 A small WebAuthn API wrapper that translates to/from pure JSON using base64url.
Turn a $5 Raspberry Pi RP2350 board into an open-source hardware passkey: WebAuthn/FIDO2 logins, ssh & git signing, OpenPGP, PIV, TOTP. Rust firmware, no_std.
FIDO2 (WebAuthn) and FIDO U2F platform library for Linux written in Rust