Skip to content

Digital Signatures

tarcieri edited this page Mar 8, 2013 · 22 revisions

In the real world, signatures help uniquely identify people because everyone's signature is unique. Digital signatures work similarly in that they are unique to holders of a private key, but unlike real world signatures, digital signatures are unforgable.

Digital signatures allow you to publish a public key, then you can use your private signing key to sign messages. Others who have your public key can then use it to validate that your messages are actually authentic.

Code Example

Signer's perspective (Crypto::SigningKey):

# Generate a new random signing key
signing_key = Crypto::SigningKey.generate

# Sign a message with the signing key
# Signature will be returned in hex format
signature = signing_key.sign(message, :hex)

# Obtain the verify key for a given signing key
verify_key = signing_key.verify_key

# Serialize the verify key to send it to a third party
# Verify key will be returned in hex format
verify_key.to_s(:hex)

Verifier's perspective (Crypto::VerifyKey):

# Create a VerifyKey object from a hex serialized public key
verify_key = Crypto::VerifyKey.new(verify_key_hex, :hex)

# Check the validity of a message's signature
# Will raise Crypto::BadSignatureError if the signature check fails
verify_key.verify!(message, signature, :hex)

Algorithm features:

  • Small keys: Ed25519 keys are only 256-bits (32 bytes), making them small enough to easily copy and paste. Ed25519 also allows the public key to be derived from the private key, meaning that it doesn't need to be included in a serialized private key in cases you want both.
  • Small signatures: Ed25519 signatures are only 512-bits (64 bytes), one of the smallest signature sizes available.
  • Deterministic: Unlike (EC)DSA, Ed25519 does not rely on an entropy source when signing messages (which has lead to catastrophic private key compromises), but instead computes signature nonces from a combination of a hash of the signing key's "seed" and the message to be signed. This avoids using an entropy source for nonces, which can be a potential attack vector if the entropy source is not generating good random numbers. Even a single reused nonce can lead to a complete disclosure of the private key in these schemes, which Ed25519 avoids entirely by being deterministic instead of tied to an entropy source.
  • Collision Resistant: Hash-function collisions do not break this system. This adds a layer of defense against the possibility of weakness in the selected hash function.

Algorithm details:

Algorithm diagram (Ed25519):

Ed25519 Diagram

  • k: Ed25519 private key (passed into Crypto::SigningKey#new)
  • A: Ed25519 public key derived from k
  • M: message to be signed
  • R: a deterministic nonce value calculated from a combination of private key data RH and the message M
  • S: Ed25519 signature

See also

RDoc

Clone this wiki locally