Module: Ed25519
- Defined in:
- lib/ed25519.rb,
lib/ed25519/version.rb,
lib/ed25519/verify_key.rb,
lib/ed25519/signing_key.rb,
ext/ed25519_ref10/ed25519_ref10.c
Overview
The Ed25519 digital signatre algorithm rubocop:disable Layout/LineLength
Defined Under Namespace
Modules: Provider Classes: SigningKey, VerifyKey
Constant Summary collapse
- KEY_SIZE =
Size of an Ed25519 key (public or private) in bytes
32
- SIGNATURE_SIZE =
Size of an Ed25519 signature in bytes
64
- VerifyError =
Raised when a signature fails to verify
Class.new(StandardError)
- SelfTestFailure =
Raised when the built-in self-test fails
Class.new(StandardError)
- VERSION =
"1.3.0"
Class Attribute Summary collapse
-
.provider ⇒ Object
Obtain the backend provider module used to perform signatures.
Class Method Summary collapse
-
.self_test ⇒ Object
Perform a self-test to ensure the selected provider is working.
-
.validate_key_bytes(key_bytes) ⇒ Object
Ensure a serialized key meets the requirements.
Class Attribute Details
.provider ⇒ Object
Obtain the backend provider module used to perform signatures
26 27 28 |
# File 'lib/ed25519.rb', line 26 def provider @provider end |
Class Method Details
.self_test ⇒ Object
Perform a self-test to ensure the selected provider is working
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ed25519.rb', line 48 def self_test signature_key = Ed25519::SigningKey.new("A" * 32) raise SelfTestFailure, "failed to generate verify key correctly" unless signature_key.verify_key.to_bytes.unpack1("H*") == "db995fe25169d141cab9bbba92baa01f9f2e1ece7df4cb2ac05190f37fcc1f9d" = "crypto libraries should self-test on boot" signature = signature_key.sign() raise SelfTestFailure, "failed to generate correct signature" unless signature.unpack1("H*") == "c62c12a3a6cbfa04800d4be81468ef8aecd152a6a26a81d91257baecef13ba209531fe905a843e833c8b71cee04400fa2af3a29fef1152ece470421848758d0a" verify_key = signature_key.verify_key raise SelfTestFailure, "failed to verify a valid signature" unless verify_key.verify(signature, ) bad_signature = "#{signature[0...63]}X" ex = nil begin verify_key.verify(bad_signature, ) rescue Ed25519::VerifyError => ex end raise SelfTestFailure, "failed to detect an invalid signature" unless ex.is_a?(Ed25519::VerifyError) end |
.validate_key_bytes(key_bytes) ⇒ Object
Ensure a serialized key meets the requirements
40 41 42 43 44 45 |
# File 'lib/ed25519.rb', line 40 def validate_key_bytes(key_bytes) raise TypeError, "expected String, got #{key_bytes.class}" unless key_bytes.is_a?(String) return true if key_bytes.bytesize == KEY_SIZE raise ArgumentError, "expected #{KEY_SIZE}-byte String, got #{key_bytes.bytesize}" end |