Module: Minisign::Utils

Included in:
KeyPair, PrivateKey, PublicKey
Defined in:
lib/minisign/utils.rb

Overview

Helpers used in multiple classes

Instance Method Summary collapse

Instance Method Details

#blake2b256(message) ⇒ Object



6
7
8
# File 'lib/minisign/utils.rb', line 6

def blake2b256(message)
  RbNaCl::Hash::Blake2b.digest(message, { digest_size: 32 })
end

#blake2b512(message) ⇒ Object



10
11
12
# File 'lib/minisign/utils.rb', line 10

def blake2b512(message)
  RbNaCl::Hash::Blake2b.digest(message, { digest_size: 64 })
end

#derive_key(password, kdf_salt, kdf_opslimit, kdf_memlimit) ⇒ String

Returns the <kdf_output> used to xor the ed25519 keys.

Returns:

  • (String)

    the <kdf_output> used to xor the ed25519 keys



22
23
24
25
26
27
28
29
30
# File 'lib/minisign/utils.rb', line 22

def derive_key(password, kdf_salt, kdf_opslimit, kdf_memlimit)
  RbNaCl::PasswordHash.scrypt(
    password,
    kdf_salt,
    kdf_opslimit,
    kdf_memlimit,
    104
  ).bytes
end

#xor(kdf_output, contents) ⇒ Array<32 bit unsigned ints>

Returns:

  • (Array<32 bit unsigned ints>)


15
16
17
18
19
# File 'lib/minisign/utils.rb', line 15

def xor(kdf_output, contents)
  kdf_output.each_with_index.map do |b, i|
    contents[i] ^ b
  end
end