sha3
![Ruby](https://github.com/johanns/sha3/actions/workflows/main.yml/badge.svg)
SHA3 for Ruby is a XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing algorithm.
Warning
- Please do NOT use SHA3 to hash passwords -- use a slow hashing function instead (e.g.:
pbkdf2
, argon2
, bcrypt
or scrypt
) - Version 1.0 introduces new API and is incompatible with previous versions (0.x).
Module details
SHA3::Digest: A standard Digest subclass. The interface, and operation of this class are parallel to digest classes bundled with MRI-based Rubies (e.g.: Digest::SHA2, and OpenSSL::Digest).
See documentation for Ruby's Digest class for additional details.
Installation
gem install sha3
Usage
require 'sha3'
Valid hash bit-lengths are: 224, 256, 384, 512.
:sha224 :sha256 :sha384 :sha512
Alternatively, you can instantiate using one of four sub-classes:
SHA3::Digest::SHA224.new()
SHA3::Digest::SHA256.new()
SHA3::Digest::SHA384.new()
SHA3::Digest::SHA512.new()
Basics
s = SHA3::Digest.new(:sha256)
s = SHA3::Digest::SHA256.new()
s.update "Compute Me"
s << "Me too"
s.digest
s.hexdigest
SHA3::Digest.hexdigest(:sha224, "Hash me, please")
SHA3::Digest::SHA384.digest("Hash me, please")
Hashing a file
s = SHA3::Digest::SHA224.file("my_fantastical_file.bin").hexdigest
s = SHA3::Digest.file("tests.sh")
Development Dependencies
- Native build tools (e.g., Clang/LLVM, GCC, Minigw, etc.)
- Gems: rubygems-tasks, rake, rspec, yard
Testing
Call rake
to run the included RSpec tests.
Only a small subset of test vectors are included in the source repository; however, the complete test vectors suite is available for download. Simply run the tests.sh
shell script (available in the root of source directory) to generate full byte-length RSpec test files.
sh tests.sh
Rubies
Supported Ruby versions:
Credits
XKCP by Keccak team: https://keccak.team/index.html
Copyright
Copyright (c) 2012 - 2022 Johanns Gregorian (https://github.com/johanns)
See LICENSE.txt for details.