diff options
author | siddharth <s@ricketyspace.net> | 2022-03-05 16:20:14 -0500 |
---|---|---|
committer | siddharth <s@ricketyspace.net> | 2022-03-05 16:20:14 -0500 |
commit | eadd6510088f87b012361bfc80332cafd5af7615 (patch) | |
tree | 5a5b6d47a1907455342c89695e1d0008c1807411 /lib/sha256_test.go | |
parent | 86eedb619f8135adc2b457b5928367fb72f4d4b2 (diff) |
lib: add sha256 implementation
Diffstat (limited to 'lib/sha256_test.go')
-rw-r--r-- | lib/sha256_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/sha256_test.go b/lib/sha256_test.go new file mode 100644 index 0000000..ca429fd --- /dev/null +++ b/lib/sha256_test.go @@ -0,0 +1,31 @@ +// Copyright © 2022 siddharth <s@ricketyspace.net> +// SPDX-License-Identifier: ISC + +package lib + +import "testing" + +// Tests from +// https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA256.pdf +func TestSha256Hash(t *testing.T) { + sha256 := Sha256{} + sha256.Init([]uint32{}) + + // Test 1 + m := "abc" + sha256.Message(StrToBytes(m)) + h := sha256.Hash() + e := "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" + if BytesToHexStr(h) != e { + t.Errorf("sha256 test 1 failed: %x != %s\n", h, e) + } + + // Test 2 + m = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + sha256.Message(StrToBytes(m)) + h = sha256.Hash() + e = "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" + if BytesToHexStr(h) != e { + t.Errorf("sha256 test 1 failed: %x != %s\n", h, e) + } +} |