2019-06-08 07:49:58 -04:00
|
|
|
Digest::Keccak
|
|
|
|
==============
|
2012-10-05 06:30:09 -04:00
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
This Ruby extension implements the [Keccak](http://keccak.noekeon.org/)
|
|
|
|
(draft version of SHA-3) cryptographic hash function. It is based on
|
|
|
|
the reference C implementation, version 3.2. The exposed interface
|
|
|
|
is almost identical to that of the `digest` standard library.
|
2012-10-05 06:30:09 -04:00
|
|
|
|
2012-10-06 06:32:29 -04:00
|
|
|
[<img src="http://www.phusion.nl/assets/logo.png">](http://www.phusion.nl/)
|
|
|
|
|
2012-10-05 06:30:09 -04:00
|
|
|
|
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
Usage
|
|
|
|
-----
|
2015-06-24 03:26:34 -04:00
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
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.
|
2012-10-05 06:30:09 -04:00
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
```ruby
|
2019-06-08 07:53:04 -04:00
|
|
|
require 'digest/keccak'
|
2012-10-05 06:30:09 -04:00
|
|
|
|
|
|
|
# Generate 512-bit digest.
|
2019-06-08 07:53:04 -04:00
|
|
|
Digest::Keccak.digest("foo") # => "\025\227\204*..."
|
|
|
|
Digest::Keccak.hexdigest("foo") # => "1597842a..."
|
2012-10-05 06:30:09 -04:00
|
|
|
|
|
|
|
# Generate 224-bit digest.
|
2019-06-08 07:53:04 -04:00
|
|
|
Digest::Keccak.digest("foo", 224) # => "\332\251M\247..."
|
|
|
|
Digest::Keccak.hexdigest("foo", 224) # => "daa94da7..."
|
2012-10-05 06:30:09 -04:00
|
|
|
|
|
|
|
# Use this interface to feed data in chunks. 512-bit by default.
|
2019-06-08 07:53:04 -04:00
|
|
|
digest = Digest::Keccak.new
|
2012-10-05 06:30:09 -04:00
|
|
|
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.
|
2019-06-08 07:53:04 -04:00
|
|
|
digest = Digest::Keccak.new(224)
|
2019-06-08 07:49:58 -04:00
|
|
|
```
|
2012-10-05 14:40:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
Running the test suite
|
|
|
|
----------------------
|
2012-10-06 05:16:25 -04:00
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
Run the test suite as follows:
|
2012-10-06 06:33:57 -04:00
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
```
|
|
|
|
make test
|
|
|
|
```
|
2012-10-06 06:33:57 -04:00
|
|
|
|
2019-06-08 07:49:58 -04:00
|
|
|
A part of the test suite is automatically generated from Keccak's reference
|
|
|
|
test suite.
|