Giter Site home page Giter Site logo

johanns / sha3 Goto Github PK

View Code? Open in Web Editor NEW
38.0 5.0 6.0 3.8 MB

SHA3 for Ruby is a XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing algorithm

License: MIT License

Ruby 22.08% C 66.17% Shell 0.76% C++ 11.00%
sha3 ruby keccak hash c

sha3's Introduction

sha3

Gem Version Ruby

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

# SHA3::Digest.new(224) is SHA3::Digest.new(:sha224)

Alternatively, you can instantiate using one of four sub-classes:

SHA3::Digest::SHA224.new() # 224 bits
SHA3::Digest::SHA256.new() # 256 bits
SHA3::Digest::SHA384.new() # 384 bits
SHA3::Digest::SHA512.new() # 512 bits

Basics

# Instantiate a new SHA3::Digest class with 256 bit length
s = SHA3::Digest.new(:sha256)

# OR #

s = SHA3::Digest::SHA256.new()

# Update hash state, and compute new value
s.update "Compute Me"

# << is an .update() alias
s << "Me too"

# Returns digest value in bytes
s.digest
# => "\xBE\xDF\r\xD9\xA1..."

# Returns digest value as hex string
s.hexdigest
# => "bedf0dd9a15b647..."

### Digest class-methods: ###

SHA3::Digest.hexdigest(:sha224, "Hash me, please")
# => "200e7bc18cd613..."

SHA3::Digest::SHA384.digest("Hash me, please")
# => "\xF5\xCEpC\xB0eV..."

Hashing a file

# Compute the hash value for given file, and return the result as hex
s = SHA3::Digest::SHA224.file("my_fantastical_file.bin").hexdigest

# Calling SHA3::Digest.file(...) defaults to SHA256
s = SHA3::Digest.file("tests.sh")
# => #<SHA3::Digest: a9801db49389339...>

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:

  • MRI Ruby 2.6 - 3.1

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.

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.