Module: Crypto::Sign::Ed25519

Extended by:
FFI::Library, Sodium::Utils
Defined in:
lib/crypto/sign/ed25519.rb

Constant Summary collapse

PRIMITIVE =
'ed25519'.freeze
PUBLICKEYBYTES =
publickeybytes.freeze
SECRETKEYBYTES =
secretkeybytes.freeze
SEEDBYTES =
seedbytes.freeze

Constants included from Sodium::Utils

Sodium::Utils::HEXY, Sodium::Utils::ZERO

Class Method Summary collapse

Methods included from Sodium::Utils

bin2hex, check_length, get_size, hex2bin, zeros

Class Method Details

.crypto_sign_ed25519_primitiveObject Also known as: primitive



16
17
18
# File 'lib/crypto/sign/ed25519.rb', line 16

def crypto_sign_ed25519_primitive
  PRIMITIVE
end

.pk_to_curve25519(public_key) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/crypto/sign/ed25519.rb', line 39

def pk_to_curve25519(public_key)
  check_length(public_key, PUBLICKEYBYTES, :PublicKey)

  curve25519_pk = zeros(ScalarMult::BYTES)
  crypto_sign_ed25519_pk_to_curve25519(curve25519_pk, public_key)

  curve25519_pk
end

.sk_to_curve25519(secret_key) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/crypto/sign/ed25519.rb', line 48

def sk_to_curve25519(secret_key)
  check_length(secret_key, SECRETKEYBYTES, :SecretKey)

  curve25519_sk = Sodium::SecretBuffer.new(ScalarMult::BYTES)
  secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
  crypto_sign_ed25519_sk_to_curve25519(curve25519_sk, secret_key)
  curve25519_sk.noaccess

  curve25519_sk
ensure
  secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
end

.sk_to_pk(secret_key) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/crypto/sign/ed25519.rb', line 73

def sk_to_pk(secret_key)
  check_length(secret_key, SECRETKEYBYTES, :SecretKey)

  public_key = zeros(PUBLICKEYBYTES)
  secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
  crypto_sign_ed25519_sk_to_pk(seed, secret_key)

  public_key
ensure
  secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
end

.sk_to_seed(secret_key) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/crypto/sign/ed25519.rb', line 61

def sk_to_seed(secret_key)
  check_length(secret_key, SECRETKEYBYTES, :SecretKey)

  seed = zeros(SEEDBYTES)
  secret_key.readonly if secret_key.is_a?(Sodium::SecretBuffer)
  crypto_sign_ed25519_sk_to_seed(seed, secret_key)

  seed
ensure
  secret_key.noaccess if secret_key.is_a?(Sodium::SecretBuffer)
end