Class: H2C::HashToPoint
- Inherits:
-
Object
- Object
- H2C::HashToPoint
- Defined in:
- lib/h2c/hash_to_point.rb
Overview
Complete and secure function for hashing strings to points.
Instance Attribute Summary collapse
-
#suite ⇒ Object
readonly
Returns the value of attribute suite.
Instance Method Summary collapse
-
#digest(msg) ⇒ ECDSA::Point
Hash returns a point on an elliptic curve given a message.
-
#hash_to_field(msg, count) ⇒ Array
Hashes a msg of any length into an element of a finite field.
-
#initialize(suite) ⇒ HashToPoint
constructor
A new instance of HashToPoint.
Constructor Details
#initialize(suite) ⇒ HashToPoint
Returns a new instance of HashToPoint.
9 10 11 |
# File 'lib/h2c/hash_to_point.rb', line 9 def initialize(suite) @suite = suite end |
Instance Attribute Details
#suite ⇒ Object (readonly)
Returns the value of attribute suite.
6 7 8 |
# File 'lib/h2c/hash_to_point.rb', line 6 def suite @suite end |
Instance Method Details
#digest(msg) ⇒ ECDSA::Point
Hash returns a point on an elliptic curve given a message.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/h2c/hash_to_point.rb', line 16 def digest(msg) p = if suite.ro u = hash_to_field(msg, 2) p0 = suite.map.map(u[0]) p1 = suite.map.map(u[1]) p0 + p1 else u = hash_to_field(msg, 1) suite.map.map(u[0]) end suite.curve.cofactor ? p.multiply_by_scalar(suite.curve.cofactor) : p end |
#hash_to_field(msg, count) ⇒ Array
Hashes a msg of any length into an element of a finite field. www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-16.html#name-hash_to_field-implementatio
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/h2c/hash_to_point.rb', line 35 def hash_to_field(msg, count) field = suite.curve.field len = count * suite.m * suite.l pseudo = suite.exp.(msg, len) u = [] (0...count).each do |i| v = [] (0...suite.m).each do |j| offset = suite.l * (j + i * suite.m) t = pseudo[offset, (offset + suite.l)] vj = t.unpack1("H*").to_i(16) v[j] = field.mod(vj) end u[i] = v end u.flatten end |