aboutsummaryrefslogtreecommitdiff
path: root/source/crypto/Kdf.mc
diff options
context:
space:
mode:
Diffstat (limited to 'source/crypto/Kdf.mc')
-rw-r--r--source/crypto/Kdf.mc33
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;
- }
}