Module: Minisign::Utils

Included in:
KeyPair, PrivateKey, PublicKey, Signature
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



27
28
29
30
31
32
33
34
35
# File 'lib/minisign/utils.rb', line 27

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

#hex(bytes) ⇒ String

Returns bytes as little endian hexadecimal.

Returns:

  • (String)

    bytes as little endian hexadecimal



22
23
24
# File 'lib/minisign/utils.rb', line 22

def hex(bytes)
  bytes.map { |c| c.to_s(16) }.reverse.join.upcase
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