107 bool changePW1(
const char* currentPin,
const char* newPin);
108 bool setPW1(
const char* newPin);
117 bool changePW3(
const char* currentPin,
const char* newPin);
118 bool setPW3(
const char* newPin);
167 static constexpr uint8_t MAX_RETRIES = 3;
168 static constexpr uint8_t MAGIC = 0xE0;
169 static constexpr uint8_t SIGNATURE_SIZE = 64;
170 static constexpr uint8_t PAYLOAD_SIZE = 147;
172 static constexpr uint16_t STORAGE_SIZE = PAYLOAD_SIZE + SIGNATURE_SIZE;
176 uint8_t badgeRetries_ = MAX_RETRIES;
177 bool badgeLocked_ =
false;
185 uint8_t pw1Retries_ = MAX_RETRIES;
186 uint8_t pw3Retries_ = MAX_RETRIES;
190 bool duressSet_ =
false;
197 bool persistedBadgeLocked_ =
false;
198 uint8_t persistedPw1Retries_ = MAX_RETRIES;
199 uint8_t persistedPw3Retries_ = MAX_RETRIES;
201 bool pinLoaded_ =
false;
202 bool badgePinIsSet_ =
false;
208 uint32_t lockoutStartMs_ = 0;
209 bool lockoutActive_ =
false;
211 bool loadFromStorage();
212 bool saveToStorage();
215 bool computeBadgeHash(
const char* pin, uint8_t* hashOut);
218 bool computeKdfHash(
const char* pin,
const uint8_t* salt, uint8_t* hashOut)
const;
220 bool compareHash(
const uint8_t* h1,
const uint8_t* h2,
size_t len)
const;
221 void generateSalt(uint8_t* salt);
227 enum class PinSlot : uint8_t {
239 bool verifyPin(PinSlot slot,
const char* pin);
static constexpr uint8_t PIN_MAX
bool verifyPW1(const char *pin)
OpenPGP PW1 (user PIN) workflow.
bool changeBadgePin(const char *currentPin, const char *newPin)
Changes badge PIN after validating current PIN.
static constexpr uint8_t KDF_HASH_SIZE
bool getPW1Hash(uint8_t *hashOut) const
Copies stored PW1 hash into caller buffer.
static constexpr uint32_t DEFAULT_ITERATIONS
void resetPW1Retries()
Resets PW1 retry counter to maximum.
static constexpr uint32_t LOCKOUT_DURATION_MS
bool changePW3(const char *currentPin, const char *newPin)
Changes PW3 after validating the current value.
void resetBadgeRetries()
Resets badge retry counter to maximum.
static constexpr uint16_t RMEM_SLOT_PIN
static constexpr uint8_t HASH_SHA256
bool isDuressPin(const char *pin) const
Constant-time check whether a candidate matches the duress PIN.
static constexpr uint8_t BADGE_PIN_MAX
bool getPW1Salt(uint8_t *saltOut) const
Copies stored PW1 salt into caller buffer.
static constexpr const char * DEFAULT_BADGE_PIN
uint8_t getBadgeRetries() const
bool isStorageAvailable() const
Returns whether secure storage access is currently available.
bool setPW3(const char *newPin)
Sets PW3 directly and refreshes salt/hash material.
bool verifyBadgePin(const char *pin)
Verifies badge PIN, updates retries, and handles lockout transitions.
uint8_t getKdfAlgorithm() const
uint8_t getPW1Retries() const
static constexpr uint8_t BADGE_HASH_SIZE
uint8_t getHashAlgorithm() const
static constexpr const char * DEFAULT_PW1
bool changePW1(const char *currentPin, const char *newPin)
Changes PW1 after validating the current value.
static constexpr uint8_t PW3_MIN
static constexpr uint8_t PW1_MIN
void resetPW3Retries()
Resets PW3 retry counter to maximum.
bool isBadgeBlocked() const
Lockout timer handling.
static constexpr uint8_t BADGE_PIN_MIN
static constexpr uint8_t KDF_ITERSALTED_S2K
static constexpr const char * DEFAULT_PW3
bool setBadgePin(const char *newPin)
Sets badge PIN directly with format validation.
bool clearDuressPin()
Clears the duress PIN, disarming the self-destruct trigger.
bool isPW1Blocked() const
void startLockout()
Starts the badge recovery timer.
bool hasDuressPin() const
Returns whether a duress PIN is currently armed.
bool isLockoutActive() const
Returns whether lockout is currently active without mutating state.
uint8_t getPW3Retries() const
static PinManager & instance()
Returns singleton PIN manager instance.
static constexpr uint8_t ATTESTATION_ECC_SLOT
bool getPW3Hash(uint8_t *hashOut) const
Copies stored PW3 hash into caller buffer.
uint32_t getLockoutRemainingMs() const
Returns remaining badge lockout duration.
bool isPW3Blocked() const
bool setPW1(const char *newPin)
Sets PW1 directly and refreshes salt/hash material.
bool setDuressPin(const char *pin)
Sets the duress PIN, arming the self-destruct trigger.
bool verifyBadgePinHash(const uint8_t *hashIn) const
Verifies provided hash against stored badge hash.
bool getBadgePinHash(uint8_t *hashOut) const
Copies stored badge PIN hash into caller buffer.
static constexpr uint8_t SALT_SIZE
uint32_t getIterationCount() const
bool init()
Initializes PIN state from secure storage or defaults.
bool verifyPW3(const char *pin)
OpenPGP PW3 (admin PIN) workflow.
void checkAndResetExpiredLockout()
Clears expired lockout state and resets retry counter.
bool getPW3Salt(uint8_t *saltOut) const
Copies stored PW3 salt into caller buffer.