Ed25519Keccak

draft1

If you want to view full diagram of ed25519, please see to "/images/ed25519_algorithm.png".

Installation

Add this line to your application's Gemfile:

gem 'ed25519_keccak'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ed25519_keccak

Usage

You can sign with a 32byte private key and verify the signature.

You can choose Ed25519Keccak::Keccak512 or Ed25519Keccak::SHA3_512 to sign and verify. These signature / validation functions are the same for the signature algorithm. However, the hash function used in the signature algorithm is different.

Keccak512("")
>> 0x 0eab42de4c3ceb9235fc91ac...

SHA3-512("")
>> 0x a69f73cca23a9ac5c8b567dc...

[SHA 3 is based on Keccak, but these outputs are different from each other.]

This implementation is a rewrite of python codes on RFC8032 as ruby.
https://tools.ietf.org/html/rfc8032

Sign

Keccak512

require "ed25519_keccak"
require "securerandom"

# signed massage data "0x0702"
message = ["0702"].pack("H*")

# secret should be 32byte
secret  = SecureRandom.bytes(32)

ed25519_keccak = Ed25519Keccak::Keccak512.new

# create a signature as a byte-string
#
#  first arg : secret (privatekey)
# second arg : message
#     return : sigunature (byte string)
sigunature = ed25519_keccak.sign( secret , message )

SHA3 512

require "ed25519_keccak"
require "securerandom"

message = ["0702"].pack("H*")

secret  = SecureRandom.bytes(32)

# when you want to use SHA3_512 hash function
ed25519_sha3 = Ed25519Keccak::SHA3_512.new

sigunature = ed25519_sha3.sign( secret , message )

puts(sigunature)

And you can use :hex format mode.

Keccak512

require "ed25519_keccak"
require "securerandom"

# massage data "0x0702"
message = "0702"

# secret should be 32byte
secret  = SecureRandom.hex(32)

ed25519_keccak = Ed25519Keccak::Keccak512.new

# create a signature as a byte-string
#
#  first arg : secret (privatekey)
# second arg : message
#  third arg : :hex
#     return : sigunature (byte string)
sigunature = ed25519_keccak.sign( secret , message, :hex )

puts(sigunature)
# >> "d71a72e7af781b5b85090b9b3a8f9e4052f58f93580e2304fd3d52e09e45ac51"
# return hex-string of signature

SHA3 512

require "ed25519_keccak"
require "securerandom"

message = "0702"

secret  = SecureRandom.hex(32)

ed25519_sha3 = Ed25519Keccak::SHA3_512.new

sigunature = ed25519_sha3.sign( secret , message, :hex )

Verify

Keccak512

require "ed25519_keccak"

publickey = ["8A558C728C21C126181E5E654B404A45B4F0137CE88177435A69978CC6BEC1F4"].pack("H*")
message   = ["8ce03cd60514233b86789729102ea09e867fc6d964dea8c2018ef7d0a2e0e24bf7e348e917116690b9"].pack("H*")
signature = ["D9CEC0CC0E3465FAB229F8E1D6DB68AB9CC99A18CB0435F70DEB6100948576CD5C0AA1FEB550BDD8693EF81EB10A556A622DB1F9301986827B96716A7134230C"].pack("H*")

ed25519_keccak512 = Ed25519Keccak::Keccak512.new

#  first arg : publickey
# second arg : message
#  third arg : sigunature
#     return : success=>true , failed=>false
is_verify = ed25519_keccak512.verify( publickey , message , signature )

puts( is_verify )
# >> true

SHA3 512

require "ed25519_keccak"

publickey = ["53C659B47C176A70EB228DE5C0A0FF391282C96640C2A42CD5BBD0982176AB1B"].pack("H*")
message   = ["8ce03cd60514233b86789729102ea09e867fc6d964dea8c2018ef7d0a2e0e24bf7e348e917116690b9"].pack("H*")
signature = ["C9B1342EAB27E906567586803DA265CC15CCACA411E0AEF44508595ACBC47600D02527F2EED9AB3F28C856D27E30C3808AF7F22F5F243DE698182D373A9ADE03"].pack("H*")

ed25519_sha3 = Ed25519Keccak::SHA3_512.new

# create a signature as a byte-string
#
#  first arg : publickey
# second arg : message
#  third arg : sigunature
#     return : success=>true , failed=>false
is_verify = ed25519_sha3.verify( publickey , message , signature )

puts( is_verify )
# >> true

You can use :hex format mode just as you signed.

Calculate publickey from secret (privatekey)

Keccak512

require "ed25519_keccak"

secret = ["8D31B712AB28D49591EAF5066E9E967B44507FC19C3D54D742F7B3A255CFF4AB"].pack("H*")

ed25519_keccak = Ed25519Keccak::Keccak512.new

publickey = ed25519_keccak.secret_to_public( secret )

SHA3 512

require "ed25519_keccak"

secret = ["8D31B712AB28D49591EAF5066E9E967B44507FC19C3D54D742F7B3A255CFF4AB"].pack("H*")

ed25519_sha3 = Ed25519Keccak::SHA3_512.new

publickey = ed25519_sha3.secret_to_public( secret )

:hex format mode...

require "ed25519_keccak"

secret = "8D31B712AB28D49591EAF5066E9E967B44507FC19C3D54D742F7B3A255CFF4AB"

ed25519_keccak = Ed25519Keccak::Keccak512.new

publickey = ed25519_keccak.secret_to_public( secret, :hex )

puts( publickey )
# >> 8a558c728c21c126181e5e654b404a45b4f0137ce88177435a69978cc6bec1f4

Dependencies

This gem depends on gems below.

keccak
'digest-sha3-patched', '~> 1.1.1'

sha3(FIPS202)
"sha3","~> 1.0.1"

Thank you for your development.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ed25519_keccak. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Ed25519Keccak project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.