The Keccak (draft version of SHA-3) cryptographic hash function
Find a file
Hongli Lai 12d155bebd Merge pull request #4 from payrollhero/master
Updates to fix ruby 2.2.
2015-06-24 09:25:17 +02:00
ext/digest Updates to fix ruby 2.2. Major version upgrade as this breaks compatibility with older versions of ruby. 2015-05-20 19:51:29 -07:00
lib/digest/sha3 Updates to fix ruby 2.2. Major version upgrade as this breaks compatibility with older versions of ruby. 2015-05-20 19:51:29 -07:00
test Add tests 2012-10-05 20:40:31 +02:00
.gitignore Add tests 2012-10-05 20:40:31 +02:00
digest-sha3.gemspec Updates to fix ruby 2.2. Major version upgrade as this breaks compatibility with older versions of ruby. 2015-05-20 19:51:29 -07:00
LICENSE Add documentation and license 2012-10-05 12:30:09 +02:00
Makefile Use [ instead of [[ for portability. 2013-05-21 23:26:43 +09:00
README.md Bump version number to 1.0.1 so that we have an excuse to sign the gem. 2013-03-11 19:27:39 +01:00

The SHA-3 (Keccak) extension for Ruby

This Ruby extension implements the SHA-3 (Keccak) cryptographic hashing algorithm. It is based on the reference C implementation, version 3.2. The exposed interface is almost identical to that of the digest standard library.

Installation

gem install digest-sha3

Our gem is signed using PGP with the Phusion Software Signing key. That key in turn is signed by the rubygems-openpgp Certificate Authority.

You can verify the authenticity of the gem by following The Complete Guide to Verifying Gems with rubygems-openpgp.

Usage

Keccak supports 5 hash lengths: 224-bit, 256-bit, 384-bit, 512-bit and variable length. Variable length is not supported by this Ruby extension. Unless the user specifies otherwise, this Ruby extension assumes 512-bit.

require 'digest/sha3'

# Generate 512-bit digest.
Digest::SHA3.digest("foo")       # => "\025\227\204*..."
Digest::SHA3.hexdigest("foo")    # => "1597842a..."

# Generate 224-bit digest.
Digest::SHA3.digest("foo", 224)       # => "\332\251M\247..."
Digest::SHA3.hexdigest("foo", 224)    # => "daa94da7..."

# Use this interface to feed data in chunks. 512-bit by default.
digest = Digest::SHA3.new
digest.update("f")
digest.update("o")
digest.update("o")
digest.digest       # => "\025\227\204*..."
digest.hexdigest    # => "1597842a..."

# You can pass a hash length to the constructor.
digest = Digest::SHA3.new(224)

Running the test suite

Run the test suite as follows:

make test

A part of the test suite is automatically generated from Keccak's reference test suite.

Warning

Do not use SHA-3 for hashing passwords. Do not even use SHA-3 + salt for hashing passowords. Use a slow hash instead.

See also

node-sha3