diff options
| author | cirakg <cirakg@cirakg.xyz> | 2026-10-21 03:55:10 +0200 |
|---|---|---|
| committer | cirakg <cirakg@cirakg.xyz> | 2026-10-21 03:55:10 +0200 |
| commit | 5e8ac1e2f5a660e55ea132996e1d5730cfa4fa64 (patch) | |
| tree | 9bb99bdca1ef8f33c93c5100816448681329d810 /source/crypto/Kdf.mc | |
| parent | 88f1cac4fa530fc30fd6ef01970af11c7a959b8e (diff) | |
feat(glance): show the favourite code in the glance (opt-in)
With "Show the favourite code in the glance" on, the glance shows the
code of the first favourite TOTP or Steam entry without the PIN, with a
countdown bar. The glance can't open the vault, so the About scan seals
that entry under "g" (device key, aad OTPW-GL-1) after every change, and
removes it when the option is off or no entry qualifies; the glance also
reads the option itself. HKDF moves to its own module so the glance loads
only the crypto it needs (37 % of its 64 KB). Manage entry gains "Mark as
favourite (glance)" and "Remove favourite", queued for locked entries
like the other changes. Lines are inset on round screens so the
Instinct 3's curved glance corner doesn't cut them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'source/crypto/Kdf.mc')
| -rw-r--r-- | source/crypto/Kdf.mc | 33 |
1 files changed, 5 insertions, 28 deletions
diff --git a/source/crypto/Kdf.mc b/source/crypto/Kdf.mc index 5bace1c..e64c8ff 100644 --- a/source/crypto/Kdf.mc +++ b/source/crypto/Kdf.mc @@ -1,5 +1,5 @@ // Author: cirakg & claude ai -// Summary: Key derivation: resumable PBKDF2-HMAC-SHA256 (RFC 8018) with calibration, and HKDF-SHA256 (RFC 5869). +// Summary: PIN key derivation: resumable PBKDF2-HMAC-SHA256 (RFC 8018) with calibration. // // PBKDF2 turns the PIN into a key (README 7.2). It runs as a Jobs.Job, a // bounded number of iterations per step, because the iteration count is @@ -7,11 +7,11 @@ // watchdog budget. It uses the native HMAC-SHA256: the object keeps the key // and digest() resets it, so each iteration is one native call. // -// HKDF splits one master key into separate encryption and MAC keys -// (README 7.3). +// HKDF, which splits one master key into separate encryption and MAC keys +// (README 7.3), is in Hkdf.mc (the glance needs it, but not PBKDF2). // -// Verified with RFC 7914 section 11 (PBKDF2) and RFC 5869 A.1-A.3 (HKDF), -// plus seeded vectors from Python's hashlib (test/crypto/KdfTest.mc). +// Verified with RFC 7914 section 11 (PBKDF2) plus seeded vectors from +// Python's hashlib (test/crypto/KdfAesTest.mc). import Toybox.Cryptography; import Toybox.Lang; @@ -191,27 +191,4 @@ module Kdf { } return estimate > MAX_ITERATIONS ? MAX_ITERATIONS : estimate.toNumber(); } - - // HKDF-SHA256 (RFC 5869): extract with salt (empty means 32 zero bytes), - // then expand to `length` bytes with info. length <= 255 * 32. - function hkdf(ikm as ByteArray, salt as ByteArray, info as ByteArray, length as Number) as ByteArray { - if (length < 1 || length > 255 * SHA256_BYTES) { - throw new Lang.InvalidValueException("HKDF: bad key length"); - } - var prk = Hmac.nativeSha256(salt.size() > 0 ? salt : new [SHA256_BYTES]b, ikm); - var okm = new [0]b; - var block = new [0]b; - for (var counter = 1; okm.size() < length; counter++) { - var input = Bytes.concat(block, info); - input.add(counter); - Bytes.wipe(block); - block = Hmac.nativeSha256(prk, input); - okm.addAll(block); - } - Bytes.wipe(prk); - Bytes.wipe(block); - var key = okm.slice(0, length); - Bytes.wipe(okm); - return key; - } } |
