h2c 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -2
- data/README.md +16 -0
- data/lib/h2c/expander/xmd.rb +2 -1
- data/lib/h2c/expander.rb +4 -1
- data/lib/h2c/hash_to_point.rb +1 -1
- data/lib/h2c/m2c/sswu.rb +3 -2
- data/lib/h2c/suite.rb +1 -1
- data/lib/h2c/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a7b6c9428d078ca27c842f19c62bde2898392719ea38eba400ad7da05b42b14
|
|
4
|
+
data.tar.gz: 2f25543f2e98f350b200c2674639a49922f1a211dbe58d2bb2673bdc924cf384
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e76d02628e7938801beaf24275793d26e1811aca3adfc4b180951b9b9ea419c9eb7705e06b2eb76503c1955a100ec5e209a6ad8fdabbcf9634aaa8299d104e4b
|
|
7
|
+
data.tar.gz: a580f648bc69621849c7bb825e90cd2f3b58d27619e6a8a05f8b79b7396598682751d628e2ea6e257641ffab3f44cf47959966e4f495f97dd7ada0c9c15ddc97
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
plugins:
|
|
2
2
|
- rubocop-rake
|
|
3
3
|
- rubocop-rspec
|
|
4
4
|
inherit_gem:
|
|
@@ -17,5 +17,7 @@ Style/WhileUntilModifier:
|
|
|
17
17
|
Enabled: false
|
|
18
18
|
Naming/MethodParameterName:
|
|
19
19
|
Enabled: false
|
|
20
|
-
RSpec/
|
|
20
|
+
RSpec/SpecFilePathFormat:
|
|
21
|
+
Enabled: false
|
|
22
|
+
RSpec/SpecFilePathSuffix:
|
|
21
23
|
Enabled: false
|
data/README.md
CHANGED
|
@@ -4,6 +4,22 @@ This is a Ruby implementation of the [Hash to Curves](https://github.com/cfrg/dr
|
|
|
4
4
|
|
|
5
5
|
It has been tested using the Test Vector provided, but the code has not been audited to ensure functional specification and safety. Also It is under development and is subject to change without backward compatibility.
|
|
6
6
|
|
|
7
|
+
## Security considerations
|
|
8
|
+
|
|
9
|
+
**This library is not constant-time and must not be used with secret input messages.**
|
|
10
|
+
|
|
11
|
+
[RFC 9380 Section 4](https://www.rfc-editor.org/rfc/rfc9380.html#section-4) requires a constant-time implementation when the message being hashed is secret. This library does not meet that requirement:
|
|
12
|
+
|
|
13
|
+
* Field arithmetic is performed with Ruby's arbitrary-precision `Integer`, whose execution time depends on the operand values.
|
|
14
|
+
* The mapping in `H2C::M2C::SSWU#map` selects between candidates with ordinary `if`/ternary branches rather than constant-time conditional moves.
|
|
15
|
+
* Byte-string handling in `H2C::Expander` allocates and copies in ways that depend on the requested length.
|
|
16
|
+
|
|
17
|
+
An attacker able to measure timing or cache behaviour may therefore be able to recover information about the input. Hashing a **public** message to a curve point (the primary use case of RFC 9380) is unaffected.
|
|
18
|
+
|
|
19
|
+
In particular, do not use this library to derive nonces or key material directly from secret values — for example, FROST's `nonce_generate`, which hashes a secret share. Such protocols require a constant-time implementation.
|
|
20
|
+
|
|
21
|
+
Additionally, `H2C::HashToPoint` and the `H2C::Expander` instance it holds keep mutable digest state, so a single instance must not be shared across threads. Create one instance per thread instead.
|
|
22
|
+
|
|
7
23
|
The following cipher suites are currently supported:
|
|
8
24
|
|
|
9
25
|
* secp256k1_XMD:SHA-256_SSWU_NU_
|
data/lib/h2c/expander/xmd.rb
CHANGED
|
@@ -46,7 +46,8 @@ module H2C
|
|
|
46
46
|
|
|
47
47
|
bi = digest.digest
|
|
48
48
|
pseudo = bi
|
|
49
|
-
|
|
49
|
+
# b_1 is already computed above, so this yields b_1, ..., b_ell in total.
|
|
50
|
+
(2..ell).each do |i|
|
|
50
51
|
digest.reset
|
|
51
52
|
digest.update(Expander.xor(b0, bi))
|
|
52
53
|
digest.update([i].pack("C"))
|
data/lib/h2c/expander.rb
CHANGED
|
@@ -32,12 +32,15 @@ module H2C
|
|
|
32
32
|
|
|
33
33
|
# Get expander implementation
|
|
34
34
|
# @param [String] func Hash function name. Currently supported by 'SHA-256' and 'SHA-512'.
|
|
35
|
-
# @
|
|
35
|
+
# @param [String] dst Domain separation tag with binary format. Must not be empty.
|
|
36
|
+
# @raise [H2C::Error] If invalid func or empty dst specified.
|
|
36
37
|
# @return [XMD] expander implementation, currently only XMD is supported.
|
|
37
38
|
def get(func, dst, _k)
|
|
38
39
|
unless HashFunc::XMD_FUNCS.include?(func)
|
|
39
40
|
raise H2C::Error, "func #{func} is unsupported."
|
|
40
41
|
end
|
|
42
|
+
# RFC 9380 3.1 requires domain separation tags to have nonzero length.
|
|
43
|
+
raise H2C::Error, "dst must not be empty." if dst.nil? || dst.empty?
|
|
41
44
|
XMD.new(func, dst)
|
|
42
45
|
# TODO: XOR
|
|
43
46
|
end
|
data/lib/h2c/hash_to_point.rb
CHANGED
data/lib/h2c/m2c/sswu.rb
CHANGED
|
@@ -25,8 +25,9 @@ module H2C
|
|
|
25
25
|
t1 = f.mod(f.power(u, 2) * f.mod(z))
|
|
26
26
|
t2 = f.power(t1, 2)
|
|
27
27
|
x1 = f.mod(t1 + t2)
|
|
28
|
-
x1 = f.inverse(x1)
|
|
29
28
|
e1 = x1.zero?
|
|
29
|
+
# inv0(x) is the multiplicative inverse of x, with inv0(0) = 0.
|
|
30
|
+
x1 = e1 ? 0 : f.inverse(x1)
|
|
30
31
|
x1 = f.mod(x1 + 1)
|
|
31
32
|
x1 = e1 ? c2 : x1
|
|
32
33
|
x1 = f.mod(x1 * c1)
|
|
@@ -47,7 +48,7 @@ module H2C
|
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
def square?(x)
|
|
50
|
-
test = curve.field.power(x, (
|
|
51
|
+
test = curve.field.power(x, (curve.field.prime - 1) / 2)
|
|
51
52
|
[0, 1].include?(test)
|
|
52
53
|
end
|
|
53
54
|
|
data/lib/h2c/suite.rb
CHANGED
data/lib/h2c/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: h2c
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- azuchi
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: ecdsa
|
|
@@ -69,7 +68,6 @@ metadata:
|
|
|
69
68
|
homepage_uri: https://github.com/azuchi/h2c
|
|
70
69
|
source_code_uri: https://github.com/azuchi/h2c
|
|
71
70
|
changelog_uri: https://github.com/azuchi/h2c
|
|
72
|
-
post_install_message:
|
|
73
71
|
rdoc_options: []
|
|
74
72
|
require_paths:
|
|
75
73
|
- lib
|
|
@@ -84,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
84
82
|
- !ruby/object:Gem::Version
|
|
85
83
|
version: '0'
|
|
86
84
|
requirements: []
|
|
87
|
-
rubygems_version: 3.
|
|
88
|
-
signing_key:
|
|
85
|
+
rubygems_version: 3.6.9
|
|
89
86
|
specification_version: 4
|
|
90
87
|
summary: Ruby implementation of hash to curve.
|
|
91
88
|
test_files: []
|