GithubHelp home page GithubHelp logo

oscarbarrett / crystal-sha3 Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 4.0 2.58 MB

An SHA-3 implementation written in Crystal.

License: MIT License

Makefile 3.42% Crystal 96.28% Ruby 0.30%
crystal sha3 keccak

crystal-sha3's Introduction

crystal-sha3 Build Status

An SHA-3 implementation written in Crystal.

Supports:

  • The FIPS 202 SHA-3 standard (Digest::SHA3)
  • Keccak[3] (Digest::Keccak3)

The main difference between the two is the value of the first byte of padding set after the input in the buffer. For SHA-3, this byte is 6u8. For Keccak[3] it is 1u8.

Usage

Add the dependency to your shard.yml:

dependencies:
  sha3:
    github: OscarBarrett/crystal-sha3
    version: ~> 0.3

Then in your code:

require "sha3"

SHA-3

# Defaults to SHA3-512
Digest::SHA3.hexdigest("abc123")
# => 3274f8455be84b8c7d79f9bd93e6c8520d13f6bd2855f3bb9c006ca9f3cce25d4b924d0370f8af4e27a350fd2baeef58bc37e0f4e4a403fe64c98017fa012757

digest = Digest::SHA3.new(256)
digest.update("abc123")
digest.hexdigest
# => f58fa3df820114f56e1544354379820cff464c9c41cb3ca0ad0b0843c9bb67ee

Keccak3

# Defaults to a hash size of 512
Digest::Keccak3.hexdigest("abc123")
# => 17c4bf22aaa8fcd7ff070fd3435619b5666dc3eac901872c73f091d9f3753cd871161269f14741e3b263c616e9f4bb4314abcbb271b2796d14eb89434a0afd03

digest = Digest::Keccak3.new(256)
digest.update("abc123")
digest.hexdigest
# => 719accc61a9cc126830e5906f9d672d06eab6f8597287095a2c55a8b775e7016

Running specs

Currently KAT specs are generated and not stored in this repository.

make spec
crystal spec

ExtremelyLongMsg KAT data for Keccak is included in the repo but is not tested.

LongMsg KAT data for SHA3 has not been located but should be added if a suitable source is found.

Benchmarks

256,000 hashes:

Version Time Comparison
Ruby (uses a C binding) 7.320000 0.080000 7.400000 ( 7.399895)
v0.3.0 6.300000 2.540000 8.840000 ( 7.068621) 1.05 times faster

Benchmarks can be run using make benchmark.

To compare with the Ruby sha3 gem (which uses a C binding), run:
make benchmark-compare
Ruby and bundler are required dependencies.

crystal-sha3's People

Contributors

dependabot[bot] avatar oscarbarrett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

crystal-sha3's Issues

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.