Giter Club home page Giter Club logo

keccak.rb's Introduction

The Keccak (SHA3) digest for Ruby

GitHub Workflow Status GitHub top language GitHub release Gem Gem Visitors License

This Ruby extension exposes the Keccak (SHA3) digest C bindings in the non-final version used by Ethereum. It is based on the reference C implementation, version 3.2. The exposed interface is almost identical to that of the digest standard library. See #16.

⚠️ Note: version ~> 1.3 exposes digest/keccak (Digest::Keccak) whereas version ~> 1.2 maintains the old digest/sha3 (Digest::SHA3) for backward compatibility. Only use ~> 1.2 if you want to lazy-patch your library. It works, but it's not recommended. Use ~> 1.3 and simply rename SHA3 to Keccak.

Installation

The gem is called keccak.

bundle add keccak
gem install keccak
gem 'keccak', '~> 1.3'

Note: as of version ~> v1.1, digest-sha3 (historic name, see below) requires Ruby 2.2. The new keccak version ~> v1.2 now also supports Ruby 3.0. The last version that worked on older Ruby (1.x) versions was ~> v1.0. It can be found at the no longer maintained digest-sha3 repository from 2015.

Usage

This gem extends the digest/* module by a digest/keccak class.

require 'digest/keccak'

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

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

# 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       # => "\025\227\204*..."
digest.hexdigest    # => "1597842a..."

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

Keccak supports five 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.

Running the test suite

Run the test suite as follows:

bundle install
make test

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

Warning: Keccak vs. SHA3

Note: This gem still uses the Digest::SHA3 namespace in version ~> 1.2 for reasons of backward compatibility and long-term maintainability. See history section below.

⚠️ This gem does not implement the final FIPS202 standard, today known as SHA3 but rather an early version, commonly referred to as Keccak. The reason why this is kept around, is that Ethereum uses this earler version of Keccak. See also: Ethereum: Difference between keccak256 and sha3.

If you are looking for the final SHA3 gem, please use the following: https://rubygems.org/gems/sha3

History

This gem was initially developed and published as digest-sha3: https://github.com/phusion/digest-sha3-ruby

This gem was later patched multiple times:

keccak.rb's People

Contributors

bramski avatar csmetcalfe avatar dependabot[bot] avatar foobarwidget avatar httpsx avatar knu avatar q9f avatar sydneyitguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

keccak.rb's Issues

Can not install under windows

Hi,

unfortunately i have to develop under windows and this gem is pulled as a dependency of the eth gem. however, installation fails with the following error:

gcc: error: unrecognized command-line option '-std\=c11'; did you mean '-std=c11'?
gcc: error: unrecognized command-line option '-fvisibility\=hidden'; did you mean '-fvisibility=hidden'?
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <winsock2.h>
4: #include <windows.h>
5: int main(int argc, char **argv)
6: {
7:   return !!argv[argc];
8: }
/* end */

any hint is highly appreciated. just for completeness sake, the extconf.rb looks fine and does not have the backslashes in the compiler options.

thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.