Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/guzba/crunchy
SIMD-optimized hashing, checksums and CRCs.
https://github.com/guzba/crunchy
adler32 checksum crc32 crc32c cyclic-redundancy-check nim sha256 simd
Last synced: about 11 hours ago
JSON representation
SIMD-optimized hashing, checksums and CRCs.
- Host: GitHub
- URL: https://github.com/guzba/crunchy
- Owner: guzba
- License: mit
- Created: 2022-06-12T17:05:59.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-26T03:20:13.000Z (about 1 year ago)
- Last Synced: 2024-11-28T07:24:11.120Z (about 2 months ago)
- Topics: adler32, checksum, crc32, crc32c, cyclic-redundancy-check, nim, sha256, simd
- Language: Nim
- Homepage:
- Size: 206 KB
- Stars: 31
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crunchy
![Github Actions](https://github.com/guzba/crunchy/workflows/Github%20Actions/badge.svg)
`nimble install crunchy`
[API reference](https://guzba.github.io/crunchy/)
## About
Crunchy provides pure Nim implementations of common hashes and data integrity checks (cyclic redundancy checks and checksums). These implementations are intended to be high-performance, including amd64 and arm64 SIMD implementations or using instruction set intrinsics.
Function | Scalar | SIMD: | amd64 | arm64
--- | --- | --- | --- | ---:
SHA-1 | ✅ | | ⛔ | ⛔
SHA-256 | ✅ | | ✅ | ⛔
CRC-32 | ✅ | | ✅ | ✅
CRC-32C | ⛔ | | ✅ | ⛔
Adler-32 | ✅ | | ✅ | ✅Crunchy is a new repo so keep an eye on releases for more functions and SIMD optimization.
## Examples
Runnable examples using Crunchy can be found in the [examples/](https://github.com/guzba/crunchy/blob/master/examples) folder.
Here is a basic example that prints the hex-encoded SHA-256 of a string:
```nim
import crunchylet data = "The quick brown fox jumps over the lazy dog"
echo sha256(data).toHex()
```Or calculating the CRC-32 of a string:
```nim
import crunchylet data = "The quick brown fox jumps over the lazy dog"
echo crc32(data)
```Now, lets say you want to compute the CRC-32 of a file. Many approaches are possible, but lets look at these two:
First, the easy way. Just read the file into memory and compute:
```nim
import crunchylet data = readFile("tests/data/zlib.rfc")
echo crc32(data)
```Alternatively, to avoid copying the file, memory-map the file and compute instead:
```nim
import crunchy, std/memfilesvar memFile = memfiles.open("tests/data/zlib.rfc")
echo crc32(memFile.mem, memFile.size)
memFile.close()
```Memory-mapping the file is great if the file is very large or you want to avoid copying a large file's contents. This uses Crunchy's pointer + len API.
## Testing
`nimble test`