diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-05-11 12:10:59 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-05-11 12:10:59 -0700 |
commit | f5454af9ad307dfa2b6617cd6ecab907d309fcae (patch) | |
tree | 991b466efe35bd0b820fc03ca63de3d13c0563d1 | |
parent | d42389d842cbe7d40e7a60eba33ee1295673180b (diff) | |
download | txr-f5454af9ad307dfa2b6617cd6ecab907d309fcae.tar.gz txr-f5454af9ad307dfa2b6617cd6ecab907d309fcae.tar.bz2 txr-f5454af9ad307dfa2b6617cd6ecab907d309fcae.zip |
hmac: use buf-xor-pattern function.
* stdlib/hmac.tl (hmac-impl): Eliminate xor loop
by using buf-xor-pattern.
-rw-r--r-- | stdlib/hmac.tl | 20 |
1 files 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]) |