Class: H2C::Suite

Inherits:
Object
  • Object
show all
Defined in:
lib/h2c/suite.rb

Overview

Hash to curve suites

Constant Summary collapse

SECP256K1_XMDSHA256_SSWU_NU_ =
"secp256k1_XMD:SHA-256_SSWU_NU_"
SECP256K1_XMDSHA256_SSWU_RO_ =
"secp256k1_XMD:SHA-256_SSWU_RO_"
BLS12381G1_XMDSHA256_SSWU_NU_ =
"BLS12381G1_XMD:SHA-256_SSWU_NU_"
BLS12381G1_XMDSHA256_SSWU_RO_ =
"BLS12381G1_XMD:SHA-256_SSWU_RO_"
P256_XMDSHA256_SSWU_NU_ =
"P256_XMD:SHA-256_SSWU_NU_"
P256_XMDSHA256_SSWU_RO_ =
"P256_XMD:SHA-256_SSWU_RO_"
P384_XMDSHA384_SSWU_NU_ =
"P384_XMD:SHA-384_SSWU_NU_"
P384_XMDSHA384_SSWU_RO_ =
"P384_XMD:SHA-384_SSWU_RO_"
P521_XMDSHA512_SSWU_NU_ =
"P521_XMD:SHA-512_SSWU_NU_"
P521_XMDSHA512_SSWU_RO_ =
"P521_XMD:SHA-512_SSWU_RO_"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, dst) ⇒ Suite

Initialize suite

Parameters:

  • id (String)

    Suite id.

  • dst (String)

    Domain separation tag.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/h2c/suite.rb', line 21

def initialize(id, dst)
  @id = id
  @k = 128
  @m = 1
  case id
  when SECP256K1_XMDSHA256_SSWU_NU_, SECP256K1_XMDSHA256_SSWU_RO_
    @curve = ECDSA::Group::Secp256k1
    @exp = Expander.get(HashFunc::SHA256, dst, @k)
    @l = 48
    @map = M2C::SSWUAB0.new(H2C::M2C::ISOGeny::Secp256k1.new, -11)
    @ro = (id == SECP256K1_XMDSHA256_SSWU_RO_)
  when BLS12381G1_XMDSHA256_SSWU_NU_, BLS12381G1_XMDSHA256_SSWU_RO_
    @curve = BLS::Group::BLS12381G1
    @exp = Expander.get(HashFunc::SHA256, dst, @k)
    @l = 64
    @map = M2C::SSWUAB0.new(H2C::M2C::ISOGeny::BLS12381G1.new, 11)
    @ro = (id == BLS12381G1_XMDSHA256_SSWU_RO_)
  when P256_XMDSHA256_SSWU_NU_, P256_XMDSHA256_SSWU_RO_
    @curve = ECDSA::Group::Nistp256
    @exp = Expander.get(HashFunc::SHA256, dst, @k)
    @l = 48
    @map = M2C::SSWU.new(ECDSA::Group::Nistp256, -10)
    @ro = (id == P256_XMDSHA256_SSWU_RO_)
  when P384_XMDSHA384_SSWU_NU_, P384_XMDSHA384_SSWU_RO_
    @k = 192
    @curve = ECDSA::Group::Nistp384
    @exp = Expander.get(HashFunc::SHA384, dst, @k)
    @l = 72
    @map = M2C::SSWU.new(ECDSA::Group::Nistp384, -12)
    @ro = (id == P384_XMDSHA384_SSWU_RO_)
  when P521_XMDSHA512_SSWU_NU_, P521_XMDSHA512_SSWU_RO_
    @k = 256
    @curve = ECDSA::Group::Nistp521
    @exp = Expander.get(HashFunc::SHA512, dst, @k)
    @l = 98
    @map = M2C::SSWU.new(ECDSA::Group::Nistp521, -4)
    @ro = (id == P521_XMDSHA512_SSWU_RO_)
  else
    raise H2C::Error, "suite #{curve} unsupported."
  end
end

Instance Attribute Details

#curveObject (readonly)

Returns the value of attribute curve.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def curve
  @curve
end

#expObject (readonly)

Returns the value of attribute exp.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def exp
  @exp
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def id
  @id
end

#kObject (readonly)

Returns the value of attribute k.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def k
  @k
end

#lObject (readonly)

Returns the value of attribute l.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def l
  @l
end

#mObject (readonly)

Returns the value of attribute m.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def m
  @m
end

#mapObject (readonly)

Returns the value of attribute map.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def map
  @map
end

#roObject (readonly)

Returns the value of attribute ro.



5
6
7
# File 'lib/h2c/suite.rb', line 5

def ro
  @ro
end