115 bool changePW1(
const char* currentPin,
const char* newPin);
116 bool setPW1(
const char* newPin);
127 bool setPW1Raw(
const uint8_t* data,
size_t len);
131 bool changePW3(
const char* currentPin,
const char* newPin);
132 bool setPW3(
const char* newPin);
141 bool setPW3Raw(
const uint8_t* data,
size_t len);
185 static constexpr uint8_t MAX_RETRIES = 3;
186 static constexpr uint8_t MAGIC = 0xE0;
187 static constexpr uint8_t SIGNATURE_SIZE = 64;
188 static constexpr uint8_t PAYLOAD_SIZE = 147;
190 static constexpr uint16_t STORAGE_SIZE = PAYLOAD_SIZE + SIGNATURE_SIZE;
194 uint8_t badgeRetries_ = MAX_RETRIES;
195 bool badgeLocked_ =
false;
204 uint8_t pw1Retries_ = MAX_RETRIES;
205 uint8_t pw3Retries_ = MAX_RETRIES;
209 bool duressSet_ =
false;
216 bool persistedBadgeLocked_ =
false;
217 uint8_t persistedPw1Retries_ = MAX_RETRIES;
218 uint8_t persistedPw3Retries_ = MAX_RETRIES;
220 bool pinLoaded_ =
false;
221 bool badgePinIsSet_ =
false;
227 uint32_t lockoutStartMs_ = 0;
228 bool lockoutActive_ =
false;
230 bool loadFromStorage();
231 bool saveToStorage();
234 bool computeBadgeHash(
const char* pin, uint8_t* hashOut);
237 bool computeKdfHash(
const char* pin,
const uint8_t* salt, uint8_t* hashOut)
const;
240 bool computeKdfHash(
const uint8_t* data,
size_t len,
const uint8_t* salt,
241 uint8_t* hashOut)
const;
243 bool compareHash(
const uint8_t* h1,
const uint8_t* h2,
size_t len)
const;
244 void generateSalt(uint8_t* salt);
250 enum class PinSlot : uint8_t {
262 bool verifyPin(PinSlot slot,
const char* pin);
271 bool verifyPinRaw(PinSlot slot,
const uint8_t* data,
size_t len);
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
bool setPW3Raw(const uint8_t *data, size_t len)
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)
bool clearDuressPin()
Clears the duress PIN, disarming the self-destruct trigger.
void setMinPinLengthFloor(uint8_t minLen)
Sets the minimum badge-PIN length floor enforced on changes.
bool isPW1Blocked() const
bool verifyPW3Raw(const uint8_t *data, size_t len)
OpenPGP KDF-DO path: PW3 reference is a host-supplied pre-hash.
void startLockout()
Starts the badge recovery timer.
bool hasDuressPin() const
Returns whether a duress PIN is currently armed.
bool setPW1Raw(const uint8_t *data, size_t len)
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
uint8_t minPinLengthFloor() const
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 verifyPW1Raw(const uint8_t *data, size_t len)
bool getPW3Salt(uint8_t *saltOut) const
Copies stored PW3 salt into caller buffer.