RepositoryC
canokeys

canokeys/canokey-core

Core implementations of an open-source secure key

440stars
55forks
2issues
5views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: webusb

#1 Repository of the week

1
TINIX TRENDING·Topic: ndef

#1 Repository of the week

2
TINIX TRENDING·Topic: piv

#2 Repository of the week

Canokey Core

Tests Coverage Apache License 2.0 FOSSA Status

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 to 123456\xFF\xFF, resets PUK to 12345678, and installs the requested retry limits.
  • OpenPGP: 00 F2 00 00 03 <pw1Retries> <resetCodeRetries> <pw3Retries>. The command requires PW3 verification, resets PW1 to 123456, resets PW3 to 12345678, and updates the reset-code retry limit.

Porting

Use Canokey-STM32 as an example.

  1. 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);
  1. You should also provide a random32 and a optional random_buffer function in rand.h.

  2. You need to configure the littlefs properly.

  3. 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.

  4. You should call the device_loop or nfc_loop in the main loop, and the device_update_led in a periodic interrupt.

  5. You should call the set_touch_result to report touch sensing result, and set_nfc_state to 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

FOSSA Status

Similar Projects

Discover other similar projects and AI models.

RepositoryRust
Yubico/yubikey-manager

Python library and command line tool for configuring any YubiKey over all USB interfaces.

1.2k
Nov 27, 2026
RepositoryC
jocover/esp32_u2f

Create a FIDO2/U2F token using ESP32

205
Jun 28, 2024
RepositoryC
polhenarejos/pico-openpgp

OpenPGP CCID smart card for Raspberry Pico and ESP32

209
Nov 3, 2026
RepositoryJava
andOTP/andOTP

[Unmaintained] Open source two-factor authentication for Android

3.7k
Jun 14, 2022
RepositoryRust
google/OpenSK

OpenSK is an open-source implementation for security keys written in Rust that supports both FIDO U2F and FIDO2 standards.

3.5k
Nov 27, 2026
RepositoryGo
duo-labs/webauthn

WebAuthn (FIDO2) server library written in Go

1.0k
Dec 5, 2022
RepositoryTypeScript
github/webauthn-json

🔏 A small WebAuthn API wrapper that translates to/from pure JSON using base64url.

787
Aug 25, 2025
RepositoryRust
TheMaxMur/RS-Key

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.

737
Dec 1, 2026
RepositoryRust
linux-credentials/libwebauthn

FIDO2 (WebAuthn) and FIDO U2F platform library for Linux written in Rust

602
Nov 16, 2026