ed448 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85ce43aac8c68800b31f7822be4244001e2b8ad625af784107c4694e8853390c
4
- data.tar.gz: 6e55e7d4dd908f43bc076df315fb806ce91f56aa9c3722dccec5e8f025bf3c26
3
+ metadata.gz: cba9803fa1114b02fdfc3b326ba340da704de00a500141fe83e58975d4e1d5d7
4
+ data.tar.gz: 64a237fc8eeb1a76110b65c3e0a0a87c792a9a2cff4bbf7fbb130dbd4a6e7008
5
5
  SHA512:
6
- metadata.gz: 4bd8bbe02268d7a07862abe72d8082bd4be95873579fb78ad4040438e5b522ace9e5103149257e9889d7bd9d534d3871ca62672c7e0bc75c38f1651a907acf8f
7
- data.tar.gz: eefeee4a5261c45eda0657dceb84f729939490c7b3bf323a92220d252c8555d0a7cae325990b321e4e90883ae7b78f1adf8b809eb3d3c08566a0fb2980d45cad
6
+ metadata.gz: a3bf2f49dfb4ab3afe6ea59d897daa26a3dd9e53670f7c048d66ff01c91b956439af093b4b2659d1e5987ff57f9893d16a30c1907f3c9a07bff59aa0bf54c1d3
7
+ data.tar.gz: bbb67b03f2b01c05385e12230138e423cd9ee712f7832bd5cb8fe4943a1d92dbb587bf055b59194449cad02d3e54a2e0faa195ebcead0e2c9713b3072792da10
@@ -7,6 +7,7 @@ module Ed448
7
7
 
8
8
  module_function
9
9
 
10
+ autoload :Shake, 'ed448/shake'
10
11
  autoload :X448, 'ed448/x448'
11
12
 
12
13
  EDDSA_448_PUBLIC_BYTES = 57
@@ -26,7 +27,7 @@ module Ed448
26
27
  def load_functions
27
28
  # @brief EdDSA key generation. This function uses a different (non-Decaf)
28
29
  # encoding.
29
- #
30
+ #
30
31
  # @param [out] pubkey The public key.
31
32
  # @param [in] privkey The private key.
32
33
  #
@@ -51,6 +52,7 @@ module Ed448
51
52
  # messages, at least without some very careful protocol-level disambiguation. For Ed448 it is
52
53
  # safe. The C++ wrapper is designed to make it harder to screw this up, but this C code gives
53
54
  # you no seat belt.
55
+ #
54
56
  # void goldilocks_ed448_sign (
55
57
  # uint8_t signature[GOLDILOCKS_EDDSA_448_SIGNATURE_BYTES],
56
58
  # const uint8_t privkey[GOLDILOCKS_EDDSA_448_PRIVATE_BYTES],
@@ -120,6 +122,22 @@ module Ed448
120
122
  # const uint8_t scalar[GOLDILOCKS_X448_PRIVATE_BYTES]
121
123
  # ) GOLDILOCKS_API_VIS GOLDILOCKS_NONNULL GOLDILOCKS_NOINLINE;
122
124
  attach_function(:goldilocks_x448_derive_public_key, [:pointer, :pointer], :void)
125
+
126
+ # @brief Hash (in) to (out)
127
+ # @param [in] in The input data.
128
+ # @param [in] inlen The length of the input data.
129
+ # @param [out] out A buffer for the output data.
130
+ # @param [in] outlen The length of the output data.
131
+ # @param [in] params The parameters of the sponge hash.
132
+ #
133
+ # goldilocks_error_t goldilocks_sha3_hash (
134
+ # uint8_t *out,
135
+ # size_t outlen,
136
+ # const uint8_t *in,
137
+ # size_t inlen,
138
+ # const struct goldilocks_kparams_s *params
139
+ # ) GOLDILOCKS_API_VIS;
140
+ attach_function(:goldilocks_sha3_hash, [:pointer, :int, :pointer, :int, :pointer], :int)
123
141
  end
124
142
 
125
143
  def derive_public_key(private_key)
@@ -129,24 +147,26 @@ module Ed448
129
147
  public_key.read_string(EDDSA_448_PUBLIC_BYTES)
130
148
  end
131
149
 
132
- def sign(private_key, public_key, message)
150
+ def sign(private_key, public_key, message, context: '', prehash: false)
133
151
  signature = FFI::MemoryPointer.new(:uchar, EDDSA_448_SIGNATURE_BYTES)
134
152
  private_key = FFI::MemoryPointer.new(:uchar, EDDSA_448_PRIVATE_BYTES).put_bytes(0, private_key)
135
153
  public_key = FFI::MemoryPointer.new(:uchar, EDDSA_448_PUBLIC_BYTES).put_bytes(0, public_key)
136
154
  message_len = message.bytesize
137
155
  message = FFI::MemoryPointer.new(:uchar, message_len).put_bytes(0, message)
138
- context = FFI::MemoryPointer.new(:uchar, 0)
139
- goldilocks_ed448_sign(signature, private_key, public_key, message, message_len, 0, context, 0)
156
+ context_len = context.bytesize
157
+ context = FFI::MemoryPointer.new(:uchar, context_len).put_bytes(0, context)
158
+ goldilocks_ed448_sign(signature, private_key, public_key, message, message_len, prehash ? 1 : 0, context, context_len)
140
159
  signature.read_string(EDDSA_448_SIGNATURE_BYTES)
141
160
  end
142
161
 
143
- def verify(signature, public_key, message)
162
+ def verify(signature, public_key, message, context: '', prehash: false)
144
163
  signature = FFI::MemoryPointer.new(:uchar, EDDSA_448_SIGNATURE_BYTES).put_bytes(0, signature)
145
164
  public_key = FFI::MemoryPointer.new(:uchar, EDDSA_448_PUBLIC_BYTES).put_bytes(0, public_key)
146
165
  message_len = message.bytesize
147
166
  message = FFI::MemoryPointer.new(:uchar, message_len).put_bytes(0, message)
148
- context = FFI::MemoryPointer.new(:uchar, 0)
149
- result = goldilocks_ed448_verify(signature, public_key, message, message_len, 0, context, 0)
167
+ context_len = context.bytesize
168
+ context = FFI::MemoryPointer.new(:uchar, context_len).put_bytes(0, context)
169
+ result = goldilocks_ed448_verify(signature, public_key, message, message_len, prehash ? 1 : 0, context, context_len)
150
170
  result == -1
151
171
  end
152
172
  end
@@ -0,0 +1,16 @@
1
+ module Ed448
2
+ module Shake
3
+ module_function
4
+
5
+ DEFAULT_SHAKE256_LENGTH = 64
6
+
7
+ def hash(message, length = DEFAULT_SHAKE256_LENGTH)
8
+ message_len = message.bytesize
9
+ message = FFI::MemoryPointer.new(:uchar, message_len).put_bytes(0, message)
10
+ out = FFI::MemoryPointer.new(:uchar, length)
11
+ option = FFI::MemoryPointer.new(:uchar, 8).put_bytes(0, ["004188001f80ffff"].pack('H*'))
12
+ Ed448.goldilocks_sha3_hash(out, length, message, message_len, option)
13
+ out.read_string(length)
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Ed448
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ed448
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hajime Yamaguchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-10 00:00:00.000000000 Z
11
+ date: 2019-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -85,6 +85,7 @@ files:
85
85
  - bin/setup
86
86
  - ed448.gemspec
87
87
  - lib/ed448.rb
88
+ - lib/ed448/shake.rb
88
89
  - lib/ed448/version.rb
89
90
  - lib/ed448/x448.rb
90
91
  homepage: https://github.com/Yamaguchi/ed448rb