Minimal Cryptnox example: open a secure channel and submit a PIN.
Minimal Cryptnox example: open a secure channel and submit a PIN.Wiring & prerequisites:
- PN532 NFC reader on SPI, with SS on pin PN532_SS_PIN.
- A Cryptnox card initialised with a known PIN (use the Cryptnox CLI: cryptnox init, then cryptnox seed generate).
- DEMO_PIN must match the PIN set on the card.
What the sketch does in each loop iteration:
- Connect to the card and establish the secure channel.
- Submit DEMO_PIN over the secure channel.
- Print "PIN accepted" if the card returned SW 0x9000, otherwise "PIN rejected (or channel error)". When the SW is not 0x9000 the SDK also prints the raw bytes (e.g. "Secured APDU: bad SW 0x63C2" means wrong PIN with 2 retries remaining).
- Disconnect.
- Warning
- Every wrong PIN attempt decrements the card's retry counter. Reaching 0 retries permanently blocks the PIN; recovery then requires the PUK via
cryptnox unblock_pin. Halt the sketch as soon as CryptnoxWallet::verifyPin returns false and check DEMO_PIN before retrying.
- Note
- The PIN "000000000" used by the project examples is a demo placeholder. In real deployments set a strong PIN, never commit source files containing a real PIN, and keep this value out of any version-controlled config.
#include <CryptnoxWallet.h>
#include <SPI.h>
#define PN532_SS_PIN (10U)
#define DEMO_PIN "000000000"
delay(1000);
SPI.begin();
while (1);
}
}
if (!
wallet.connect(session)) {
delay(1000);
return;
}
if (!
wallet.verifyPin(session,
reinterpret_cast<const uint8_t*
>(
DEMO_PIN),
serialAdapter.println(
F(
"PIN rejected — halting to protect retry counter"));
while (1);
}
delay(1000);
}
void setup()
Arduino setup function.
CryptnoxWallet wallet(nfc, serialAdapter, cryptoProvider, platform)
PN532Adapter nfc(serialAdapter, PN532_SS, &SPI)
ArduinoLoggerAdapter serialAdapter
ArduinoCryptoProvider cryptoProvider
void loop()
Arduino main loop.
#define PN532_SS_PIN
SPI slave-select (CS) pin connected to the PN532 module.
#define DEMO_PIN
Demo PIN used by this example. Must match the PIN that the card was initialised with (4–9 ASCII digit...
CW_CryptoProvider implementation for the Arduino UNO R4 (RA4M1).
CW_Logger implementation wrapping Arduino's HardwareSerial.
High-level interface for interacting with a Cryptnox Hardware Wallet over NFC.
CW_NfcTransport implementation over the Adafruit_PN532 driver.
Holds cryptographic session state for reentrant secure channel operations.