Module: JOSE::JWA::Ed25519_RbNaCl

Extended by:
Ed25519_RbNaCl
Included in:
Ed25519_RbNaCl
Defined in:
lib/jose/jwa/ed25519_rbnacl.rb

Instance Method Summary collapse

Instance Method Details

#keypair(secret = nil) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/jose/jwa/ed25519_rbnacl.rb', line 5

def keypair(secret = nil)
  secret ||= RbNaCl::Random.random_bytes(RbNaCl::Signatures::Ed25519::SEEDBYTES)
  RbNaCl::Util.check_length(secret, RbNaCl::Signatures::Ed25519::SEEDBYTES, "secret")
  pk = RbNaCl::Util.zeros(RbNaCl::Signatures::Ed25519::VERIFYKEYBYTES)
  sk = RbNaCl::Util.zeros(RbNaCl::Signatures::Ed25519::SIGNINGKEYBYTES)
  RbNaCl::Signatures::Ed25519::SigningKey.sign_ed25519_seed_keypair(pk, sk, secret) || fail(RbNaCl::CryptoError, "Failed to generate a key pair")
  return pk, sk
end

#sign(m, sk) ⇒ Object


18
19
20
21
22
# File 'lib/jose/jwa/ed25519_rbnacl.rb', line 18

def sign(m, sk)
  signing_key = RbNaCl::Signatures::Ed25519::SigningKey.allocate
  signing_key.instance_variable_set(:@signing_key, sk)
  return signing_key.sign(m)
end

#sign_ph(m, sk) ⇒ Object


24
25
26
# File 'lib/jose/jwa/ed25519_rbnacl.rb', line 24

def sign_ph(m, sk)
  return sign(RbNaCl::Hash.sha512(m), sk)
end

#sk_to_pk(sk) ⇒ Object


14
15
16
# File 'lib/jose/jwa/ed25519_rbnacl.rb', line 14

def sk_to_pk(sk)
  return sk[RbNaCl::Signatures::Ed25519::VERIFYKEYBYTES..-1]
end

#verify(sig, m, pk) ⇒ Object


28
29
30
# File 'lib/jose/jwa/ed25519_rbnacl.rb', line 28

def verify(sig, m, pk)
  return RbNaCl::Signatures::Ed25519::VerifyKey.new(pk).verify(sig, m)
end

#verify_ph(sig, m, pk) ⇒ Object


32
33
34
# File 'lib/jose/jwa/ed25519_rbnacl.rb', line 32

def verify_ph(sig, m, pk)
  return verify(sig, RbNaCl::Hash.sha512(m), pk)
end