Sha256: 0a7b51f711f277d5d052152c94d5261edb8202779a050e61c5db171a78c6b1d3

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'red25519/version'
require 'red25519_engine'
require 'red25519/keys'

module Ed25519
  SECRET_KEY_BYTES = 32
  PUBLIC_KEY_BYTES = 32
  SIGNATURE_BYTES  = 64

  class SelfTestFailure < StandardError; end

  def self.test
    signature_key = Ed25519::SigningKey.new("A" * 32)

    unless signature_key.verify_key.to_hex == 'db995fe25169d141cab9bbba92baa01f9f2e1ece7df4cb2ac05190f37fcc1f9d'
      raise SelfTestFailure, "failed to generate verify key correctly"
    end

    message = "crypto libraries should self-test on boot"
    signature = signature_key.sign(message)
    unless signature.unpack("H*").first == 'c62c12a3a6cbfa04800d4be81468ef8aecd152a6a26a81d91257baecef13ba209531fe905a843e833c8b71cee04400fa2af3a29fef1152ece470421848758d0a'
      raise SelfTestFailure, "failed to generate correct signature"
    end

    verify_key = signature_key.verify_key
    unless verify_key.verify(signature, message)
      raise SelfTestFailure, "failed to verify a valid signature"
    end

    bad_signature = signature[0...63] + 'X'
    unless verify_key.verify(bad_signature, message) == false
      raise SelfTestFailure, "failed to detect an invalid signature"
    end
  end
end

Ed25519.test

# TIMTOWTDI!!!
Red25519 = Ed25519

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
red25519-1.0.0 lib/red25519.rb