SE050 Driver
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Functions | Variables
se050_scp03_crypto.hpp File Reference

Host AES-128 / RFC 4493 CMAC / GlobalPlatform SCP03 KDF (header-only). More...

#include <cstddef>
#include <cstdint>
#include <cstring>

Go to the source code of this file.

Classes

class  se050::scp03::crypto::ScopedWipe
 Wipes a buffer with SecureZero when the scope ends, on every return path. More...
 
struct  se050::scp03::crypto::Cmac
 Streaming AES-128-CMAC (RFC 4493) — no concatenated MAC buffer. More...
 

Namespaces

namespace  se050
 
namespace  se050::scp03
 
namespace  se050::scp03::crypto
 

Functions

void se050::scp03::crypto::SecureZero (void *p, std::size_t len) noexcept
 Overwrite len bytes at p with zeros in a way the compiler cannot drop.
 
bool se050::scp03::crypto::ConstantTimeEqual (const std::uint8_t *a, const std::uint8_t *b, std::size_t len) noexcept
 Compare two byte strings in time that depends only on len, not on where they differ.
 
void se050::scp03::crypto::AddRoundKey (std::uint8_t s[16], const std::uint8_t *rk)
 
void se050::scp03::crypto::SubBytes (std::uint8_t s[16])
 
void se050::scp03::crypto::InvSubBytes (std::uint8_t s[16])
 
void se050::scp03::crypto::ShiftRows (std::uint8_t s[16])
 
void se050::scp03::crypto::InvShiftRows (std::uint8_t s[16])
 
std::uint8_t se050::scp03::crypto::Xtime (std::uint8_t x)
 
std::uint8_t se050::scp03::crypto::Gmul (std::uint8_t a, std::uint8_t b)
 
void se050::scp03::crypto::MixColumns (std::uint8_t s[16])
 
void se050::scp03::crypto::InvMixColumns (std::uint8_t s[16])
 
void se050::scp03::crypto::ExpandKey (const std::uint8_t key[16], std::uint8_t rk[176])
 
void se050::scp03::crypto::Aes128EncryptBlock (const std::uint8_t key[kAes128KeyLen], const std::uint8_t in[16], std::uint8_t out[16])
 
void se050::scp03::crypto::Aes128DecryptBlock (const std::uint8_t key[kAes128KeyLen], const std::uint8_t in[16], std::uint8_t out[16])
 
void se050::scp03::crypto::XorBlock (std::uint8_t *a, const std::uint8_t *b)
 
void se050::scp03::crypto::LeftShift1 (std::uint8_t in[16])
 
void se050::scp03::crypto::GenerateSubkeys (const std::uint8_t key[16], std::uint8_t k1[16], std::uint8_t k2[16])
 
void se050::scp03::crypto::Aes128Cmac (const std::uint8_t key[kAes128KeyLen], const std::uint8_t *msg, std::size_t msg_len, std::uint8_t out[kCmacLen])
 
bool se050::scp03::crypto::FillDerivationData (std::uint8_t constant, std::uint16_t bit_len, std::uint8_t counter, const std::uint8_t *context, std::uint16_t context_len, std::uint8_t *out, std::size_t out_cap, std::size_t *out_len)
 GP Amendment D derivation input (label || 00 || L || i || context).
 
bool se050::scp03::crypto::DeriveSessionKey (const std::uint8_t static_key[kAes128KeyLen], std::uint8_t constant, const std::uint8_t host_challenge[kChallengeLen], const std::uint8_t card_challenge[kChallengeLen], std::uint8_t out_key[kAes128KeyLen])
 
bool se050::scp03::crypto::ComputeCryptogram (const std::uint8_t session_mac_key[kAes128KeyLen], std::uint8_t constant, const std::uint8_t host_challenge[kChallengeLen], const std::uint8_t card_challenge[kChallengeLen], std::uint8_t out8[kCryptogramLen])
 
bool se050::scp03::crypto::Aes128CbcEncrypt (const std::uint8_t key[kAes128KeyLen], const std::uint8_t iv[16], const std::uint8_t *src, std::uint8_t *dst, std::size_t len)
 
bool se050::scp03::crypto::Aes128CbcDecrypt (const std::uint8_t key[kAes128KeyLen], const std::uint8_t iv[16], const std::uint8_t *src, std::uint8_t *dst, std::size_t len)
 
bool se050::scp03::crypto::IsoPad80 (std::uint8_t *buf, std::size_t *len, std::size_t cap)
 
bool se050::scp03::crypto::StaticKeysUsable (const std::uint8_t *enc, std::size_t enc_len, const std::uint8_t *mac, std::size_t mac_len)
 
void se050::scp03::crypto::CmacStart (Cmac &c, const std::uint8_t key[kAes128KeyLen])
 
void se050::scp03::crypto::CmacUpdate (Cmac &c, const std::uint8_t *data, std::size_t len)
 
void se050::scp03::crypto::CmacFinish (Cmac &c, std::uint8_t out[kCmacLen])
 
void se050::scp03::crypto::CommandIcv (const std::uint8_t senc[kAes128KeyLen], const std::uint8_t counter[16], std::uint8_t icv[16])
 Command ICV = AES-ECB(SENC, counter). CBC with IV=0 of one block.
 
void se050::scp03::crypto::ResponseIcv (const std::uint8_t senc[kAes128KeyLen], const std::uint8_t counter[16], std::uint8_t icv[16])
 Response ICV: counter with MSB 0x80, then AES-ECB(SENC, ·).
 
void se050::scp03::crypto::IncCommandCounter (std::uint8_t counter[16])
 
bool se050::scp03::crypto::IsoUnpad80 (const std::uint8_t *padded, std::size_t padded_len, std::size_t *plain_len)
 

Variables

constexpr std::size_t se050::scp03::crypto::kAes128KeyLen = 16U
 
constexpr std::size_t se050::scp03::crypto::kCmacLen = 16U
 
constexpr std::size_t se050::scp03::crypto::kChallengeLen = 8U
 
constexpr std::size_t se050::scp03::crypto::kCryptogramLen = 8U
 
constexpr std::size_t se050::scp03::crypto::kLabelLen = 12U
 
constexpr std::uint8_t se050::scp03::crypto::kDeriveCardCryptogram = 0x00U
 
constexpr std::uint8_t se050::scp03::crypto::kDeriveHostCryptogram = 0x01U
 
constexpr std::uint8_t se050::scp03::crypto::kDeriveSenc = 0x04U
 
constexpr std::uint8_t se050::scp03::crypto::kDeriveSmac = 0x06U
 
constexpr std::uint8_t se050::scp03::crypto::kDeriveSrmac = 0x07U
 
constexpr std::uint8_t se050::scp03::crypto::kKdfCounter = 0x01U
 
constexpr std::uint16_t se050::scp03::crypto::kLen128Bit = 0x0080U
 
constexpr std::uint16_t se050::scp03::crypto::kLen64Bit = 0x0040U
 
constexpr std::uint8_t se050::scp03::crypto::kSbox [256]
 
constexpr std::uint8_t se050::scp03::crypto::kInvSbox [256]
 
constexpr std::uint8_t se050::scp03::crypto::kRcon [10]
 

Detailed Description

Host AES-128 / RFC 4493 CMAC / GlobalPlatform SCP03 KDF (header-only).

This is the host-side primitive set the SE050 T=1 stack needs so I²C1 can run an authenticated SCP03 channel. It is not NXP Plug & Trust and does not contain NXP default platform keys.

Derivation layout matches GP Card Spec Amendment D (label || 00 || L || counter || host_challenge || card_challenge).