digest-keccak/README.md

62 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2019-06-08 11:49:58 +00:00
Digest::Keccak
==============
2012-10-05 10:30:09 +00:00
2019-06-08 11:49:58 +00: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 10:30:09 +00:00
2019-10-04 00:56:57 +00:00
Table of contents
-----------------
* [Usage](#usage)
* [Development](#development)
2019-06-08 11:49:58 +00:00
Usage
-----
2015-06-24 07:26:34 +00:00
2019-06-08 11:49:58 +00: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 10:30:09 +00:00
2019-06-08 11:49:58 +00:00
```ruby
2019-10-04 00:56:57 +00:00
require 'digest/keccak'
# Generate 512-bit digest.
Digest::Keccak.digest 'foo' #=> "\x15\x97\x84*\xACR\xBC\x9D..."
Digest::Keccak.hexdigest 'foo' #=> "1597842aac52bc9d..."
# Generate 224-bit digest.
Digest::Keccak.digest 'foo', 224 #=> "\xDA\xA9M\xA7\xF6\x80k\xF5..."
Digest::Keccak.hexdigest 'foo', 224 #=> "daa94da7f6806bf5..."
# Use this interface to feed data in chunks. 512-bit by default.
digest = Digest::Keccak.new
digest.update 'f'
digest.update 'o'
digest.update 'o'
digest.digest #=> "\x15\x97\x84*\xACR\xBC\x9D..."
digest.hexdigest #=> "1597842aac52bc9d..."
# You can pass a hash length to the constructor.
digest = Digest::Keccak.new 224
2019-06-08 11:49:58 +00:00
```
2012-10-05 18:40:31 +00:00
2019-10-04 00:56:57 +00:00
Development
-----------
2012-10-06 09:16:25 +00:00
2019-06-08 11:49:58 +00:00
Run the test suite as follows:
2012-10-06 10:33:57 +00:00
2019-06-08 11:49:58 +00:00
```
2019-10-04 00:56:57 +00:00
make test
2019-06-08 11:49:58 +00:00
```
2012-10-06 10:33:57 +00:00
2019-06-08 11:49:58 +00:00
A part of the test suite is automatically generated from Keccak's reference
test suite.