Module: FROST::Hash

Defined in:
lib/frost/hash.rb

Overview

Constant Summary collapse

CTX_STRING_SECP256K1 =
"FROST-secp256k1-SHA256-v1"
CTX_STRING_P256 =
"FROST-P256-SHA256-v1"

Class Method Summary collapse

Class Method Details

.h1(msg, group) ⇒ Integer

H1 hash function. param [ECDSA::Group] group The elliptic curve group.

Parameters:

  • msg (String)

    The message to be hashed.

Returns:

  • (Integer)


15
16
17
# File 'lib/frost/hash.rb', line 15

def h1(msg, group)
  hash_to_field(msg, group, "rho")
end

.h2(msg, group) ⇒ Integer

H3 hash function.

Parameters:

  • msg (String)

    The message to be hashed.

  • group (ECDSA::Group)

    The elliptic curve group.

Returns:

  • (Integer)


23
24
25
# File 'lib/frost/hash.rb', line 23

def h2(msg, group)
  hash_to_field(msg, group, "chal")
end

.h3(msg, group) ⇒ Integer

H3 hash function.

Parameters:

  • msg (String)

    The message to be hashed.

  • group (ECDSA::Group)

    The elliptic curve group.

Returns:

  • (Integer)


31
32
33
# File 'lib/frost/hash.rb', line 31

def h3(msg, group)
  hash_to_field(msg, group, "nonce")
end

.h4(msg, group) ⇒ String

H4 hash function.

Parameters:

  • msg (String)

    The message to be hashed.

  • group (ECDSA::Group)

    The elliptic curve group.

Returns:

  • (String)

    The hash value.



39
40
41
# File 'lib/frost/hash.rb', line 39

def h4(msg, group)
  hash(msg, group, "msg")
end

.h5(msg, group) ⇒ String

H5 hash function.

Parameters:

  • msg (String)

    The message to be hashed.

  • group (ECDSA::Group)

    The elliptic curve group.

Returns:

  • (String)

    The hash value.



47
48
49
# File 'lib/frost/hash.rb', line 47

def h5(msg, group)
  hash(msg, group, "com")
end

.hash(msg, group, context) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/frost/hash.rb', line 72

def hash(msg, group, context)
  case group
  when ECDSA::Group::Secp256k1
    Digest::SHA256.digest(CTX_STRING_SECP256K1 + context + msg)
  when ECDSA::Group::Secp256r1
    Digest::SHA256.digest(CTX_STRING_P256 + context + msg)
  else
    # TODO support other suite.
    raise RuntimeError, "group #{group} dose not supported."
  end
end

.hash_to_field(msg, group, context) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/frost/hash.rb', line 59

def hash_to_field(msg, group, context)
  h2c = case group
        when ECDSA::Group::Secp256k1
          H2C.get(H2C::Suite::SECP256K1_XMDSHA256_SSWU_NU_, CTX_STRING_SECP256K1 + context)
        when ECDSA::Group::Secp256r1
          H2C.get(H2C::Suite::P256_XMDSHA256_SSWU_NU_, CTX_STRING_P256 + context)
        else
          # TODO support other suite.
          raise RuntimeError, "group #{group} dose not supported."
        end
  h2c.hash_to_field(msg, 1, group.order).first
end

.hdkg(msg, group) ⇒ Integer

Hash function for a FROST ciphersuite, used for the DKG.

Parameters:

  • msg (String)

    The message to be hashed.

  • group (ECDSA::Group)

    The elliptic curve group.

Returns:

  • (Integer)

    The hash value.



55
56
57
# File 'lib/frost/hash.rb', line 55

def hdkg(msg, group)
  hash_to_field(msg, group, "dkg")
end