Skip to content

Platform

The EMV and nexo code never touches a device. Everything that depends on the hardware sits behind four interfaces (Rust traits) in a7pay::platform:

  • the card reader;
  • the cryptography;
  • the security module;
  • the PIN pad.

Building a terminal on a7pay means implementing these four interfaces on your device. Terms in bold are in the glossary.

Trait What your platform provides Used by
reader::Reader The contactless interface: poll for a card, exchange a command and its response (an APDU), turn the field off, show a message, detect two cards at once Entry Point and the kernels
crypto::Crypto What EMV needs: unpredictable numbers, the time, RSA recovery and SHA-1 for offline data authentication, SHA-256. For Kernel 8: its key agreement, secure channel and ECC checks. For Kernel 2’s Integrated Data Storage: its digest functions The kernels
security::SecurityModule Keys and what is done with them for the host messages: MACs, card data encryption, PIN blocks nexo
pinpad::PinPad PIN entry, returning the PIN already enciphered nexo FAST

a7pay::platform is no_std and depends on no protocol crate: nothing in it is specific to EMV or nexo. emvco re-exports Reader and Crypto (emvco::l2::core::traits), and nexo the security types.

Operations only some kernels need (Kernel 8’s, Kernel 2’s Integrated Data Storage) answer “not supported” by default. A platform without Kernel 8 implements none of them.

A terminal has a single place where keys live and cryptography happens: its secure element, its HSM, or on a phone the MPoC solution’s protected cryptography. a7pay is built around that rule:

  • the protocol crates hold no keys and implement no algorithms;
  • the kernels’ offline data authentication recovers certificates and hashes through Crypto;
  • Kernel 8’s keys (its ephemeral private key, the session keys agreed with the card) never leave the provider: the provider keeps them and performs the operations that use them;
  • nexo’s MACs, card data encryption and PIN blocks go through SecurityModule;
  • a PinPad returns the PIN already enciphered (ISO 9564 format 0 under DUKPT, format 4 under AES DUKPT): the clear PIN never crosses an interface. The host side checks it with SecurityModule::verify_pin, which takes the expected PIN and says yes or no.

For an evaluation (PCI PTS, PCI MPoC), this keeps the security-sensitive code in one place, your implementation of these traits, separate from the protocol logic.

Device Reader Crypto, SecurityModule PinPad
Countertop or unattended terminal Its contactless reader’s driver Its secure element or security processor Its PIN entry device
Phone (SoftPOS, PCI MPoC) The phone’s NFC controller The MPoC solution’s protected cryptography The MPoC PIN entry
Desktop, for development A PC/SC contactless reader (pcsc::PcscReader, feature pcsc) VCrypto (below) VPinPad (below)

a7pay::platform holds the implementations that aren’t a device’s own: the PC/SC reader, which runs the kernels against real cards from a desktop, and the software ones below.

a7pay::platform comes with software implementations of each interface, behind features. They need the standard library.

Feature Type What it is
vreader vreader::VReader A contactless reader playing a scripted card
vcrypto vcrypto::VCrypto A software provider of Crypto and SecurityModule
vpinpad vpinpad::VPinPad A PIN pad playing scripted cardholder actions, enciphering with a VCrypto

VCrypto implements the following, each tested against published test vectors where they exist:

  • DES, TDES, AES; Retail-CBC-MAC, CMAC; CBC data encryption;
  • DUKPT 2009, AES DUKPT, UKPT, and an in-memory key store;
  • ISO 9564 PIN blocks, formats 0 and 4;
  • RSA public key recovery, and RSA key generation and signing for test cards;
  • SHA-1, SHA-256;
  • Kernel 8: P-256 ECSDSA and blinding, and Book E’s secure channel. Both have the card’s side too, for simulated cards;
  • Kernel 2’s IDS digest functions (OWHF2, OWHF2AES);
  • unpredictable numbers from the operating system, or fixed ones to replay a recording;
  • a virtual clock shared with a simulated card, so that relay resistance timing is exact and tests never wait.

VCrypto is for tests. It keeps keys in memory, in clear. A real terminal implements the traits on its secure hardware.

The kernels’ cryptography holds no secret: it checks the card’s signatures (RSA, P-256), hashes, and draws the unpredictable numbers. Only Kernel 8’s secure channel keys anything, with keys made for one transaction. A device can run it on its application processor, until a secure element takes it over, or for good on a device certified for Level 2 only (a reference device, a lab sample).

swcrypto::SwCrypto (feature swcrypto) is that provider, without the standard library: the same algorithms as VCrypto (they are shared), on the RustCrypto crates. The device gives it what only the device has, through swcrypto::Environment:

  • random: random bytes from its true random number generator, for the unpredictable numbers and Kernel 8’s keys;
  • now_us: a monotonic clock in microseconds, for the relay resistance timings (Kernels 2 and 8).
struct Board { /* the RNG and timer peripherals */ }

impl platform::swcrypto::Environment for Board {
    type Error = RngError;
    fn random(&mut self, out: &mut [u8]) -> Result<(), RngError> { self.rng.fill(out) }
    fn now_us(&mut self) -> u64 { self.timer.micros() }
}

let mut crypto = platform::swcrypto::SwCrypto::new(Board { /* ... */ });

It implements Crypto only: the payment application’s keys (PIN, MAC, data encryption, SecurityModule) belong on secure hardware.