Module: Melos::PSK

Extended by:
PSK
Included in:
PSK
Defined in:
lib/melos/psk.rb

Instance Method Summary collapse

Instance Method Details

#psk_secret(suite, psk_array) ⇒ Object

input: array of [(raw PSK ID), (PSK value)]



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/melos/psk.rb', line 7

def psk_secret(suite, psk_array)
  secret = Melos::Crypto::Util.zero_vector(suite.kdf.n_h)

  psk_array.each_with_index do |tuple, idx|
    psk_id = Melos::Struct::PreSharedKeyID.new(tuple[0])
    psk_label = Melos::Struct::PSKLabel.create(
      id: psk_id,
      index: idx,
      count: psk_array.count
    )

    extracted = Melos::Crypto.kdf_extract(
      suite,
      Melos::Crypto::Util.zero_vector(suite.kdf.n_h),
      tuple[1]
    )
    input = Melos::Crypto.expand_with_label(
      suite,
      extracted,
      "derived psk",
      psk_label.raw,
      suite.kdf.n_h
    )
    secret = Melos::Crypto.kdf_extract(suite, input, secret)
  end

  return secret
end