inst_kbkdf.bend

bend-osdev-crypto@0.1.0.0 · 18 lines · 2 definitions

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.
7import Base
8import bend-osdev-bytes@0.1.0.0/bytes.bend as B
9import bend-osdev-crypto@0.1.0.0/crypto.bend as Cr
10import bend-osdev-crypto@0.1.0.0/hmac.bend as Hm
11import bend-osdev-crypto@0.1.0.0/kbkdf.bend as Kb
12import bend-osdev-crypto@0.1.0.0/inst_sha2.bend as SH
13
14def 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
17def 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)