cryptnox-sdk-arduino 1.0.0
Arduino library for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
VerifyPin.ino
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: LGPL-3.0-or-later
3 * Copyright (c) 2026 Cryptnox SA
4 */
5
37#include <CryptnoxWallet.h>
38#include <SPI.h>
39
41#define PN532_SS_PIN (10U)
42
47#define DEMO_PIN "000000000"
48
51
54
57
60
63
70void setup() {
71 serialAdapter.begin(115200);
72 delay(1000); /* Arduino R4: wait for Serial */
73 SPI.begin();
74
75 if (!wallet.begin()) {
76 serialAdapter.println(F("PN532 init failed"));
77 while (1);
78 }
79}
80
97void loop() {
98 CW_SecureSession session;
99 if (!wallet.connect(session)) {
100 serialAdapter.println(F("Card not detected"));
101 wallet.disconnect(session);
102 delay(1000);
103 return;
104 }
105
106 if (!wallet.verifyPin(session,
107 reinterpret_cast<const uint8_t*>(DEMO_PIN),
108 (uint8_t)strlen(DEMO_PIN))) {
109 /* CRITICAL: do NOT loop on failure — each wrong PIN attempt
110 * decrements the card's retry counter (typically 3-5 tries) and
111 * permanently blocks the PIN at zero. Halt and let the developer
112 * inspect the Serial output / fix DEMO_PIN before retrying. */
113 serialAdapter.println(F("PIN rejected — halting to protect retry counter"));
114 wallet.disconnect(session);
115 while (1);
116 }
117
118 serialAdapter.println(F("PIN accepted"));
119 wallet.disconnect(session);
120 delay(1000);
121}
void setup()
Arduino setup function.
CryptnoxWallet wallet(nfc, serialAdapter, cryptoProvider, platform)
PN532Adapter nfc(serialAdapter, PN532_SS, &SPI)
ArduinoLoggerAdapter serialAdapter
ArduinoPlatform platform
ArduinoCryptoProvider cryptoProvider
void loop()
Arduino main loop.
#define PN532_SS_PIN
SPI slave-select (CS) pin connected to the PN532 module.
Definition Connect.ino:31
#define DEMO_PIN
Demo PIN used by this example. Must match the PIN that the card was initialised with (4–9 ASCII digit...
Definition Sign.ino:50
CW_CryptoProvider implementation for the Arduino UNO R4 (RA4M1).
CW_Logger implementation wrapping Arduino's HardwareSerial.
CW_Platform implementation using Arduino's blocking delay().
High-level interface for interacting with a Cryptnox Hardware Wallet over NFC.
CW_NfcTransport implementation over the Adafruit_PN532 driver.
#define F(string_literal)
Holds cryptographic session state for reentrant secure channel operations.
Definition CW_Defs.h:168