Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JuliaCrypto/SHA.jl
A performant, 100% native-julia SHA1, SHA2, and SHA3 implementation
https://github.com/JuliaCrypto/SHA.jl
cryptography hash-functions julia sha1 sha2 sha3
Last synced: 3 months ago
JSON representation
A performant, 100% native-julia SHA1, SHA2, and SHA3 implementation
- Host: GitHub
- URL: https://github.com/JuliaCrypto/SHA.jl
- Owner: JuliaCrypto
- License: other
- Created: 2014-08-08T00:35:09.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-02-20T01:48:25.000Z (5 months ago)
- Last Synced: 2024-03-25T01:11:05.721Z (4 months ago)
- Topics: cryptography, hash-functions, julia, sha1, sha2, sha3
- Language: Julia
- Homepage:
- Size: 147 KB
- Stars: 45
- Watchers: 9
- Forks: 38
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Lists
README
# SHA
[![Build Status](https://github.com/JuliaCrypto/SHA.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaCrypto/SHA.jl/actions/workflows/CI.yml)
[![codecov.io](https://codecov.io/gh/JuliaCrypto/SHA.jl/branch/master/graph/badge.svg)](https://app.codecov.io/gh/JuliaCrypto/SHA.jl)## Setup
Enter the Julia package manager by typing `]` into your REPL. Then type:
```julia
(@v1.6) pkg> add SHA
```## Usage
```julia
julia> using SHAjulia> bytes2hex(sha256("test"))
"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 `Vector{UInt8}`, a `ByteString` or an `IO` object. This makes it trivial to checksum a file:
```julia
shell> cat /tmp/test.txt
test
julia> using SHAjulia> open("/tmp/test.txt") do f
sha2_256(f)
end
32-element Vector{UInt8}:
0x9f
0x86
0xd0
0x81
0x88
0x4c
0x7d
0x65
⋮
0x5d
0x6c
0x15
0xb0
0xf0
0x0a
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 `Vector`) 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. Pull requests are welcome.