From 33f5db32090d5ae8df43fdaf24262e623e97a568 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 10 Jun 2022 22:23:43 -0700 Subject: [PATCH] Avoid w@ and w! collision. --- lib/hashing/hashing.fs | 4 ++-- lib/hashing/sha1.fs | 8 ++++---- lib/hashing/sha256.fs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/hashing/hashing.fs b/lib/hashing/hashing.fs index 8eea6a5..964549b 100644 --- a/lib/hashing/hashing.fs +++ b/lib/hashing/hashing.fs @@ -21,8 +21,8 @@ internals vocabulary hashing hashing definitions 0 VALUE temp1 0 VALUE temp2 CREATE w 80 4* ALLOT -: w@ ( n -- n ) 4* w + UL@ ; -: w! ( n n -- ) 4* w + L! ; +: @w ( n -- n ) 4* w + UL@ ; +: !w ( n n -- ) 4* w + L! ; : 32-bit ( n -- n ) $ffffffff AND ; : L+ ( n n -- n ) + 32-bit ; diff --git a/lib/hashing/sha1.fs b/lib/hashing/sha1.fs index 13d352d..3db54a7 100644 --- a/lib/hashing/sha1.fs +++ b/lib/hashing/sha1.fs @@ -21,10 +21,10 @@ internals hashing definitions : extend 80 16 DO - I 3 - w@ I 8 - w@ XOR I 14 - w@ XOR I 16 - w@ XOR 1 <<< I w! + I 3 - @w I 8 - @w XOR I 14 - @w XOR I 16 - @w XOR 1 <<< I !w LOOP ; -: step ( n i -- ) w@ + a 5 <<< + e L+ ( to temp ) +: step ( n i -- ) @w + a 5 <<< + e L+ ( to temp ) d TO e c TO d b 30 <<< TO c a TO b ( from temp ) TO a ; : start h0 TO A h1 TO b h2 TO c h3 TO d h4 TO e ; : chunk1 20 0 DO b c AND b INVERT d AND XOR $5A827999 + I step LOOP ; @@ -53,8 +53,8 @@ create sha1-hash sha1-size allot msg edge >w edge 56 >= IF chunk w 64 ERASE THEN THEN - n 8 * 16 RSHIFT 16 RSHIFT 14 w! - n 8 * 15 w! chunk + n 8 * 16 RSHIFT 16 RSHIFT 14 !w + n 8 * 15 !w chunk format sha1-hash sha1-size ; diff --git a/lib/hashing/sha256.fs b/lib/hashing/sha256.fs index b55e048..e14dab1 100644 --- a/lib/hashing/sha256.fs +++ b/lib/hashing/sha256.fs @@ -37,7 +37,7 @@ DECIMAL : s1 { x } x 17 >>> x 19 >>> XOR x 10 RSHIFT XOR ; : extend 64 16 DO - I 16 - w@ I 7 - w@ + I 15 - w@ s0 + I 2 - w@ s1 + I w! + I 16 - @w I 7 - @w + I 15 - @w s0 + I 2 - @w s1 + I !w LOOP ; @@ -46,7 +46,7 @@ DECIMAL : sh0 { x -- n } x 2 >>> x 13 >>> XOR x 22 >>> XOR ; : sh1 { x -- n } x 6 >>> x 11 >>> XOR x 25 >>> XOR ; : step { i } - h e sh1 + e f g ch + i k@ + i w@ L+ TO temp1 + h e sh1 + e f g ch + i k@ + i @w L+ TO temp1 a sh0 a b c maj L+ TO temp2 g TO h f TO g e TO f d temp1 L+ TO e c TO d b TO c a TO b temp1 temp2 L+ TO a @@ -80,8 +80,8 @@ create sha256-hash sha256-size allot msg edge >w edge 56 >= IF chunk w 64 ERASE THEN THEN - n 8 * 16 RSHIFT 16 RSHIFT 14 w! - n 8 * 15 w! chunk + n 8 * 16 RSHIFT 16 RSHIFT 14 !w + n 8 * 15 !w chunk format sha256-hash sha256-size ;