SHA
Usage is very straightforward:
1. julia> using SHA
3. julia> bytes2hex(sha256("test"))
4. "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
Each exported function (at the time of this writing, SHA-1, SHA-2 224, 256, 384 and 512, and SHA-3 224, 256, 384 and 512 functions are implemented) takes in either an Array{UInt8}, a ByteString or an IO object. This makes it trivial to checksum a file:
1. shell> cat /tmp/test.txt
2. test
3. julia> using SHA
5. julia> open("/tmp/test.txt") do f
6. sha2_256(f)
7. end
8. 32-element Array{UInt8,1}:
9. 0x9f
10. 0x86
11. 0xd0
12. 0x81
13. 0x88
14. 0x4c
15. 0x7d
16. 0x65
17. ⋮
18. 0x5d
19. 0x6c
20. 0x15
21. 0xb0
22. 0xf0
23. 0x0a
24. 0x08
Note the lack of a newline at the end of /tmp/text.txt. Julia automatically inserts a newline before the julia> prompt.
Due to the colloquial usage of sha256 to refer to sha2_256, convenience functions are provided, mapping shaxxx() function calls to sha2_xxx(). For SHA-3, no such colloquialisms exist and the user must use the full sha3_xxx() names.
shaxxx() takes AbstractString and array-like objects (NTuple and Array) with elements of type UInt8.
Note that, at the time of this writing, the SHA3 code is not optimized, and as such is roughly an order of magnitude slower than SHA2.
