From dd6d60fc1a14d4569d0f76919e40710e2cec6127 Mon Sep 17 00:00:00 2001 From: sergey-shandar Date: Wed, 17 Jul 2024 10:02:49 -0700 Subject: [PATCH] hmac --- blockset-lib/src/hmac.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/blockset-lib/src/hmac.rs b/blockset-lib/src/hmac.rs index 0d1a47f5..948a654e 100644 --- a/blockset-lib/src/hmac.rs +++ b/blockset-lib/src/hmac.rs @@ -19,7 +19,11 @@ const fn sha256(data: U512) -> U256 { state.end(u512x::ZERO, 0) } +const fn op(key: U256, pad: U256, data: U256) -> U256 { + sha256([u256x::bitor(&key, &pad), data]) +} + pub const fn hmac(key: U256, msg: U256) -> U256 { - let hash = sha256([u256x::bitor(&key, &I_PAD), msg]); - sha256([u256x::bitor(&key, &O_PAD), hash]) + let hash = op(key, I_PAD, msg); + op(key, O_PAD, hash) }