SHA-1 hashing helpers for whole-input and incremental hashing.
(source -- digest)Computes one SHA-1 digest for one complete source span.
Incremental SHA-1 state that accepts appended input chunks and produces one final digest.
state: five-word SHA-1 state.buffer: pending input buffer.bufferProcessed: number of bytes currently stored in the buffer.bitSize: total processed bit count.append (source --): appends one source span to the current hashing state.finish (-- digest): finalizes the digest and returns one Nat8 20 array.append accepts the same source classes as sha1.finish uses the buffered partial block together with the accumulated bit count.Nat8 20 array.Sha1Internal.finish.sha1 hashes the whole accepted source in one call.ShaCounter allows the same byte sequence to be supplied in chunks.Low-level helpers used by ShaCounter and sha1.
rol: left-rotation helper.f1, f2, f3, f4: SHA-1 round helpers.m and r: message-schedule and round helpers.finish: final padding and digest assembly helper.transform: one 64-byte block transform helper."sha1" use
"control" use
{} () {} [
direct: "abc" sha1;
counter: ShaCounter;
"ab" @counter.append
"c" @counter.append
incremental: @counter.finish;
direct incremental same printStack _:;
] "main" exportFunction
TRUE
"sha1" use
"String" use
"control" use
{} Int32 {} [
digest: "abc" sha1;
out: String;
20 [
byte: i digest @;
i 0 > [" " @out.catString] when
byte 16n8 < ["0" @out.catString] when
byte @out.catHex
] times
@out.getStringView print
0
] "main" exportFunction
A9 99 3E 36 47 06 81 6A BA 3E 25 71 78 50 C2 6C 9C D0 D8 9D