-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply prettier to 4.0.3 to fix error
- Loading branch information
Showing
7 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
module BLS | ||
class Group | ||
BLS12381G2 = | ||
ECDSA::Group.new( | ||
name: "bls12381_g2", | ||
p: | ||
0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab, | ||
a: 0, | ||
b: 4, | ||
g: [ | ||
0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb, | ||
0x8b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1 | ||
], | ||
n: 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001, | ||
h: | ||
0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551 | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
module BLS | ||
class Group | ||
BLS12381G1_11ISO = | ||
ECDSA::Group.new( | ||
name: "bls12381_g2_11iso", | ||
p: | ||
0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab, | ||
a: | ||
0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d, | ||
b: | ||
0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0, | ||
g: [ | ||
0x6a0ead062ba73a09984eb7351a2d851bc817625345ce033a6eb7d78242b6466c877e022dda626a79ddb85bce57997e2, | ||
0x3b89d8bb9326270e46b6b74e19f7b3f10082fbf1a46df72da50c6571b969afc570d6529350b1b9b05ab4fe5c29920b4 | ||
], | ||
n: 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001, | ||
h: 0xd201000000010001 | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
require "digest" | ||
|
||
module H2C | ||
module Expander | ||
# Expander::XOF produces a uniformly random byte string using a cryptographic hash function H that outputs b bits. | ||
class XOF | ||
attr_reader :dst, :digest, :k | ||
|
||
# Constructor | ||
# @param [String] func Hash function name. Currently supported by 'SHA256' and 'SHA512' | ||
# @param [String] dst Domain separation tag with binary format. | ||
# @param [Integer] k | ||
def initialize(func, dst, k) | ||
@dst = dst | ||
@digest = Digest(func).new | ||
@k = k | ||
end | ||
|
||
# Expand message. | ||
# https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-16.html#name-expand_message_xmd | ||
# @param [String] msg The message to be expanded with binary format. | ||
# @param [Integer] len The length of the requested output in bytes. | ||
# @return [String] Expanded message. | ||
# @raise [H2C::Error] | ||
def expand(msg, len) | ||
b_len = digest.digest_length | ||
ell = (len + b_len - 1) / b_len | ||
dst_prime = construct_dst_prime | ||
|
||
if ell >= 0xff || len >= 0xffff || dst_prime.bytesize >= 0xff | ||
raise H2C::Error, "requested too many bytes" | ||
end | ||
lib_str = [(len >> 8) & 0xFF, (len & 0xff)].pack("CC") | ||
z_pad = Array.new(digest.block_length, 0) | ||
|
||
digest.reset | ||
digest.update(z_pad.pack("C*")) | ||
digest.update(msg) | ||
digest.update(lib_str) | ||
digest.update([0].pack("C")) | ||
digest.update(dst_prime) | ||
|
||
b0 = digest.digest | ||
digest.reset | ||
digest.update(b0) | ||
digest.update([1].pack("C")) | ||
digest.update(dst_prime) | ||
|
||
bi = digest.digest | ||
pseudo = bi | ||
(2..(ell + 1)).each do |i| | ||
digest.reset | ||
digest.update(Expander.xor(b0, bi)) | ||
digest.update([i].pack("C")) | ||
digest.update(dst_prime) | ||
bi = digest.digest | ||
pseudo += bi | ||
end | ||
pseudo[0...len] | ||
end | ||
|
||
# Construct DST prime. | ||
# @return [String] DST prime | ||
def construct_dst_prime | ||
dst_prime = | ||
if dst.bytesize > MAX_DST_LENGTH | ||
digest.digest(LONG_DST_PREFIX + dst) | ||
else | ||
dst | ||
end | ||
dst_prime + [dst_prime.bytesize].pack("C") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters