1 # The named SP 800-108 KDFs (kbkdf.bend) over HMAC-SHA-256 (inst_sha2.bend), 2 # with a 32-bit counter and a 32-bit [L]_2: counter mode, and feedback mode 3 # with the counter. As a KDF (kdf.bend), counter mode is 4 # ~Kb.CrKbkdf.derive(~Hm.CrHmacKey, ~Hm.CrHmac.key_of(~64n, ~SH.CrSha2.sha256), ~Hm.CrHmac.mac(~SH.CrSha2.sha256), ~32n, ~4n, ~4n) 5 # and the same tuple with another MAC, its tag length, or other field 6 # widths gives the other members of the family. 7 import Base 8 import bend-osdev-bytes@0.1.0.0/bytes.bend as B 9 import ./crypto.bend as Cr 10 import ./hmac.bend as Hm 11 import ./kbkdf.bend as Kb 12 import ./inst_sha2.bend as SH 13 14 def CrKbkdf.hmac_sha256_counter(ki: B.Octets, label: B.Octets, context: B.Octets, n: Nat) -> Result<&2, &2, Cr.CrError, B.Octets>: 15 Kb.CrKbkdf.counter_kdf(~Hm.CrHmacKey, ~Hm.CrHmac.key_of(~64n, ~SH.CrSha2.sha256), ~Hm.CrHmac.mac(~SH.CrSha2.sha256), ~32n, ~4n, ~4n, ki, label, context, n) 16 17 def CrKbkdf.hmac_sha256_feedback(ki: B.Octets, iv: B.Octets, label: B.Octets, context: B.Octets, n: Nat) -> Result<&2, &2, Cr.CrError, B.Octets>: 18 Kb.CrKbkdf.feedback_kdf(~Hm.CrHmacKey, ~Hm.CrHmac.key_of(~64n, ~SH.CrSha2.sha256), ~Hm.CrHmac.mac(~SH.CrSha2.sha256), ~32n, ~4n, ~4n, ki, iv, label, context, n)