ttcrypt 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2472d1f0aa544b4691aaaa20728ea40625be629
4
- data.tar.gz: 3014d0c1d0075d586b4cae519b8da6ff7c3aca6d
3
+ metadata.gz: 96c4fdfa708a74c514e7716c97f12d4db701c18c
4
+ data.tar.gz: f8a53ffdba88341976f2bee9f52625c59b13fc04
5
5
  SHA512:
6
- metadata.gz: 1146a4edd2d19461bc1bda0c00c9e9a75958ce22ae520e98da5bcacca5e0dd10124f9c8d7e733ca372653124e3320ba046380479176ce1ba5e327b43384fd338
7
- data.tar.gz: 0d7afb9dd9b5fcc4e700836ea104074be7727296ede99eacdad62c2e1b7eb99d1ec3ffc90e2c6c16e8bb3648a9dbbb46250364081d8390a8f055d8f35727bf3b
6
+ metadata.gz: a2150a32c7795157812efdf0b0d66d4873413f28cfffec28d55389d0ea4a3f41ea8d130afb9e38c9d10685b21c6ba64d93858767c487392222defde1e55a8c0f
7
+ data.tar.gz: 76f9f1e4fb59e693e96560524787d83f228dcd8f8975e49bc9de7df82e9b27fcc65a0eb50d992a81043e2eec1c092023aabdc7f56af26634bf12d49559dac849
data/README.md CHANGED
@@ -14,7 +14,7 @@ thinks.
14
14
 
15
15
  ## Changes
16
16
 
17
- After years in production we are added SHA512 signing hash and ability to caclulate hashes for strings - it's faster than using Digest module - at least on reasonable sized sources we use.
17
+ After years in production we are added SHA512 signing hash and ability to caclulate hashes for strings - it's faster than using Digest module - at least on reasonable sized sources we use. Also it is possible to specify custom salt size on signature verification (almost never used though).
18
18
 
19
19
  ## Installation
20
20
 
@@ -162,6 +162,9 @@ bool emsa_pss_verify(const byte_buffer& source_message,
162
162
  if (sLen == 0)
163
163
  sLen = emLen - hLen - 2;
164
164
 
165
+ if( sLen > 5000000 )
166
+ throw rsa_key::error("invalid salt length");
167
+
165
168
  if (emLen < hLen + sLen + 2 || encoded_message[-1] != 0xbc)
166
169
  return false;
167
170
 
@@ -200,7 +200,7 @@ static VALUE rsa_sign(VALUE self, VALUE message, VALUE signature_method) {
200
200
  }
201
201
 
202
202
  static VALUE rsa_verify(VALUE self, VALUE message, VALUE signature,
203
- VALUE signature_method) {
203
+ VALUE signature_method,VALUE salt_length) {
204
204
  return wrap_exceptions([=] {
205
205
  byte_buffer m = value_to_byte_buffer(message);
206
206
  byte_buffer s = value_to_byte_buffer(signature);
@@ -208,7 +208,10 @@ static VALUE rsa_verify(VALUE self, VALUE message, VALUE signature,
208
208
  hash_t hash = hash_provider(signature_method);
209
209
 
210
210
  ruby_unblock([&] {
211
- res = rsa(self).verify(m, s, hash);
211
+ size_t sLen = 0;
212
+ if( salt_length != Qnil )
213
+ sLen = NUM2UINT(salt_length);
214
+ res = rsa(self).verify(m, s, hash, sLen);
212
215
  });
213
216
 
214
217
  return res ? Qtrue : Qfalse;
@@ -280,7 +283,7 @@ void Init_ttcrypt(void) {
280
283
  rb_define_method(rsa_class, "_encrypt", (ruby_method) rsa_encrypt, 1);
281
284
  rb_define_method(rsa_class, "_decrypt", (ruby_method) rsa_decrypt, 1);
282
285
  rb_define_method(rsa_class, "_sign", (ruby_method) rsa_sign, 2);
283
- rb_define_method(rsa_class, "_verify", (ruby_method) rsa_verify, 3);
286
+ rb_define_method(rsa_class, "_verify", (ruby_method) rsa_verify, 4);
284
287
  rb_define_method(rsa_class, "extract_public",
285
288
  (ruby_method) rsa_extract_public, 0);
286
289
  rb_define_method(rsa_class, "_is_private", (ruby_method) rsa_is_private, 0);
data/lib/ttcrypt.rb CHANGED
@@ -150,10 +150,10 @@ module TTCrypt
150
150
  #@param [String] signature
151
151
  #@param [Symbol|String] hash function used (:sha1 or :sha256)
152
152
  #@return [bool] true if the signature is consistent
153
- def verify message, signature, hash_name=:sha1
153
+ def verify message, signature, hash_name=:sha1, salt_length=0
154
154
  message.force_encoding Encoding::BINARY
155
155
  signature.force_encoding Encoding::BINARY
156
- _verify message, signature, hash_name.to_s.downcase
156
+ _verify message, signature, hash_name.to_s.downcase, salt_length
157
157
  end
158
158
 
159
159
  # Extract public key from a private (or public) key
@@ -198,6 +198,7 @@ end
198
198
  require 'ttcrypt/ttcrypt'
199
199
 
200
200
  module TTCrypt
201
- module_function :factorize, :_factorize, :_factorize2, :generate_prime, :_generate_prime, :sha256, :sha512
201
+ module_function :factorize, :_factorize, :_factorize2, :generate_prime, :_generate_prime,
202
+ :sha256, :sha512#, :self_test
202
203
  end
203
204
 
@@ -1,5 +1,5 @@
1
1
  module TTCrypt
2
2
 
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
 
5
5
  end
data/spec/ttcrypt_spec.rb CHANGED
@@ -136,8 +136,50 @@ describe 'rsa-oaep' do
136
136
  TTCrypt.sha256(source).should == Digest::SHA256.new.digest(source)
137
137
  TTCrypt.sha512(source).should == Digest::SHA512.new.digest(source)
138
138
  end
139
+
140
+ # it 'self-tests' do
141
+ # TTCrypt.self_test
142
+ # end
143
+
144
+ it 'properly signs' do
145
+
146
+ message = h2s '
147
+ 85 9e ef 2f d7 8a ca 00 30 8b dc 47 11 93 bf 55
148
+ bf 9d 78 db 8f 8a 67 2b 48 46 34 f3 c9 c2 6e 64
149
+ 78 ae 10 26 0f e0 dd 8c 08 2e 53 a5 29 3a f2 17
150
+ 3c d5 0c 6d 5d 35 4f eb f7 8b 26 02 1c 25 c0 27
151
+ 12 e7 8c d4 69 4c 9f 46 97 77 e4 51 e7 f8 e9 e0
152
+ 4c d3 73 9c 6b bf ed ae 48 7f b5 56 44 e9 ca 74
153
+ ff 77 a5 3c b7 29 80 2f 6e d4 a5 ff a8 ba 15 98
154
+ 90 fc'
155
+
156
+ e = h2s '01 00 01'
157
+
158
+ p = h2s '
159
+ d1 7f 65 5b f2 7c 8b 16 d3 54 62 c9 05 cc 04 a2
160
+ 6f 37 e2 a6 7f a9 c0 ce 0d ce d4 72 39 4a 0d f7
161
+ 43 fe 7f 92 9e 37 8e fd b3 68 ed df f4 53 cf 00
162
+ 7a f6 d9 48 e0 ad e7 57 37 1f 8a 71 1e 27 8f 6b'
163
+
164
+ q = h2s '
165
+ c6 d9 2b 6f ee 74 14 d1 35 8c e1 54 6f b6 29 87
166
+ 53 0b 90 bd 15 e0 f1 49 63 a5 e2 63 5a db 69 34
167
+ 7e c0 c0 1b 2a b1 76 3f d8 ac 1a 59 2f b2 27 57
168
+ 46 3a 98 24 25 bb 97 a3 a4 37 c5 bf 86 d0 3f 2f'
169
+
170
+ signature = h2s '
171
+ 8d aa 62 7d 3d e7 59 5d 63 05 6c 7e c6 59 e5 44
172
+ 06 f1 06 10 12 8b aa e8 21 c8 b2 a0 f3 93 6d 54
173
+ dc 3b dc e4 66 89 f6 b7 95 1b b1 8e 84 05 42 76
174
+ 97 18 d5 71 5d 21 0d 85 ef bb 59 61 92 03 2c 42
175
+ be 4c 29 97 2c 85 62 75 eb 6d 5a 45 f0 5f 51 87
176
+ 6f c6 74 3d ed dd 28 ca ec 9b b3 0e a9 9e 02 c3
177
+ 48 82 69 60 4f e4 97 f7 4c cd 7c 7f ca 16 71 89
178
+ 71 23 cb d3 0d ef 5d 54 a2 b5 53 6a d9 0a 74 7e'
139
179
 
140
- it 'should properly sign'
180
+ key = TTCrypt::RsaKey.new e: e, p: p, q: q
181
+ key.verify(message, signature, :sha1, 20).should == true
182
+ end
141
183
 
142
184
  def init_test_vectors1
143
185
  @n = h2s <<-End
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttcrypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergeych
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler