From f5454af9ad307dfa2b6617cd6ecab907d309fcae Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 11 May 2025 12:10:59 -0700 Subject: hmac: use buf-xor-pattern function. * stdlib/hmac.tl (hmac-impl): Eliminate xor loop by using buf-xor-pattern. --- stdlib/hmac.tl | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/stdlib/hmac.tl b/stdlib/hmac.tl index fc487cbe..5b4aeb7f 100644 --- a/stdlib/hmac.tl +++ b/stdlib/hmac.tl @@ -39,17 +39,15 @@ (buf-set-length key block-size) - (for ((i 0) (okey (copy-buf key)) (ikey (copy-buf key)) - (ctx0 [begin-fn]) (ctx1 [begin-fn])) - ((< i block-size) - [update-fn ctx0 ikey] - [update-fn ctx0 message] - [update-fn ctx1 okey] - [update-fn ctx1 [end-fn ctx0]] - [end-fn ctx1]) - ((inc i)) - (upd [okey i] (logxor #x5c)) - (upd [ikey i] (logxor #x36)))) + (let ((okey (buf-xor-pattern key #x5c)) + (ikey (buf-xor-pattern key #x36)) + (ctx0 [begin-fn]) + (ctx1 [begin-fn])) + [update-fn ctx0 ikey] + [update-fn ctx0 message] + [update-fn ctx1 okey] + [update-fn ctx1 [end-fn ctx0]] + [end-fn ctx1])) (defun hmac-sha1 (key message) [hmac-impl key message sha1 sha1-begin sha1-hash sha1-end 64]) -- cgit v1.2.3