Class: RbNaCl::Signatures::Ed25519::SigningKey
- Inherits:
-
Object
- Object
- RbNaCl::Signatures::Ed25519::SigningKey
- Extended by:
- RbNaCl::Sodium
- Includes:
- KeyComparator, RbNaCl::Serializable
- Defined in:
- lib/rbnacl/signatures/ed25519/signing_key.rb
Overview
Private key for producing digital signatures using the Ed25519 algorithm. Ed25519 provides a 128-bit security level, that is to say, all known attacks take at least 2^128 operations, providing the same security level as AES-128, NIST P-256, and RSA-3072.
Signing keys are produced from a 32-byte (256-bit) random seed value. This value can be passed into the SigningKey constructor as a String whose bytesize is 32.
The public VerifyKey can be computed from the private 32-byte seed value as well, eliminating the need to store a "keypair".
SigningKey produces 64-byte (512-bit) signatures. The signatures are deterministic: signing the same message will always produce the same signature. This prevents "entropy failure" seen in other signature algorithms like DSA and ECDSA, where poor random number generators can leak enough information to recover the private key.
Instance Attribute Summary collapse
-
#verify_key ⇒ Object
readonly
Returns the value of attribute verify_key.
Class Method Summary collapse
-
.generate ⇒ RbNaCl::SigningKey
Generate a random SigningKey.
-
.signature_bytes ⇒ Integer
The size of signatures generated by the SigningKey class.
Instance Method Summary collapse
-
#initialize(seed) ⇒ RbNaCl::SigningKey
constructor
Create a SigningKey from a seed value.
-
#primitive ⇒ Symbol
The crypto primitive this SigningKey class uses for signatures.
-
#sign(message) ⇒ String
Sign a message using this key.
-
#signature_bytes ⇒ Integer
The size of signatures generated by the SigningKey instance.
-
#to_bytes ⇒ String
Return the raw seed value of this key.
Methods included from RbNaCl::Sodium
sodium_constant, sodium_function, sodium_primitive, sodium_type
Methods included from RbNaCl::Serializable
Methods included from KeyComparator
Constructor Details
#initialize(seed) ⇒ RbNaCl::SigningKey
Create a SigningKey from a seed value
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 53 def initialize(seed) seed = seed.to_s Util.check_length(seed, Ed25519::SEEDBYTES, "seed") pk = Util.zeros(Ed25519::VERIFYKEYBYTES) sk = Util.zeros(Ed25519::SIGNINGKEYBYTES) self.class.sign_ed25519_seed_keypair(pk, sk, seed) || raise(CryptoError, "Failed to generate a key pair") @seed, @signing_key = seed, sk @verify_key = VerifyKey.new(pk) end |
Instance Attribute Details
#verify_key ⇒ Object (readonly)
Returns the value of attribute verify_key.
39 40 41 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 39 def verify_key @verify_key end |
Class Method Details
.generate ⇒ RbNaCl::SigningKey
Generate a random SigningKey
44 45 46 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 44 def self.generate new RbNaCl::Random.random_bytes(Ed25519::SEEDBYTES) end |
.signature_bytes ⇒ Integer
The size of signatures generated by the SigningKey class
94 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 94 def self.signature_bytes; Ed25519::SIGNATUREBYTES; end |
Instance Method Details
#primitive ⇒ Symbol
The crypto primitive this SigningKey class uses for signatures
89 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 89 def primitive; self.class.primitive; end |
#sign(message) ⇒ String
Sign a message using this key
72 73 74 75 76 77 78 79 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 72 def sign() buffer = Util.prepend_zeros(signature_bytes, ) buffer_len = Util.zeros(FFI::Type::LONG_LONG.size) self.class.sign_ed25519(buffer, buffer_len, , .bytesize, @signing_key) buffer[0, signature_bytes] end |
#signature_bytes ⇒ Integer
The size of signatures generated by the SigningKey instance
99 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 99 def signature_bytes; Ed25519::SIGNATUREBYTES; end |
#to_bytes ⇒ String
Return the raw seed value of this key
84 |
# File 'lib/rbnacl/signatures/ed25519/signing_key.rb', line 84 def to_bytes; @seed; end |