Module: H2C::Expander

Defined in:
lib/h2c/expander.rb,
lib/h2c/expander/xmd.rb

Overview

Expander allows to generate a pseudo-random byte string of a determined length.

Defined Under Namespace

Classes: XMD

Constant Summary collapse

MAX_DST_LENGTH =

Maximum allowed length for domain separation tags.

255
LONG_DST_PREFIX =
[
  0x48,
  0x32,
  0x43,
  0x2d,
  0x4f,
  0x56,
  0x45,
  0x52,
  0x53,
  0x49,
  0x5a,
  0x45,
  0x2d,
  0x44,
  0x53,
  0x54,
  0x2d
].pack("C*")

Class Method Summary collapse

Class Method Details

.get(func, dst, _k) ⇒ XMD

Get expander implementation

Parameters:

  • func (String)

    Hash function name. Currently supported by ‘SHA-256’ and ‘SHA-512’.

Returns:

  • (XMD)

    expander implementation, currently only XMD is supported.

Raises:



37
38
39
40
41
42
43
# File 'lib/h2c/expander.rb', line 37

def get(func, dst, _k)
  unless HashFunc::XMD_FUNCS.include?(func)
    raise H2C::Error, "func #{func} is unsupported."
  end
  XMD.new(func, dst)
  # TODO: XOR
end

.xor(x, y) ⇒ String

XOR two byte(x and y) string.

Parameters:

  • x (String)

    byte strings

  • y (String)

    byte strings

Returns:

  • (String)

    xored byte strings



49
50
51
52
53
# File 'lib/h2c/expander.rb', line 49

def xor(x, y)
  x_bytes = x.unpack("C*")
  y_bytes = y.unpack("C*")
  x_bytes.zip(y_bytes).map { |a, b| a ^ b }.pack("C*")
end