twofish 1.0.6 → 1.0.7
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/lib/twofish.rb +11 -7
- metadata +8 -9
- data/lib/string.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94fdd3f8675e917213219e3e7c20be6bb6ea7cca
|
4
|
+
data.tar.gz: e026a558a458513387b7b511a2b4c4334e04afac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b9c58fdc89dd9b7dce44500d617143fb7074b3f2f9297fd952643cabd2e97ed1e04b71f34c55bbdcec6375420604ec50516bdff23e2e6ee060aa68618652008
|
7
|
+
data.tar.gz: d3a0f83c9b58a7649942bbc5a007ea72af48cf38ff2a7194768775190a815104c0abc5a0f843b8c53a13fb487059585a7a5b611abd02048de6e299ae788d7642
|
data/lib/twofish.rb
CHANGED
@@ -9,7 +9,6 @@
|
|
9
9
|
class Twofish
|
10
10
|
|
11
11
|
require 'securerandom'
|
12
|
-
require 'string' # monkey patch for MRI 1.8.7
|
13
12
|
require 'twofish/mode'
|
14
13
|
require 'twofish/padding'
|
15
14
|
|
@@ -442,7 +441,7 @@ class Twofish
|
|
442
441
|
# must be a multiple of the block size.
|
443
442
|
def iv=(iv)
|
444
443
|
raise ArgumentError, 'cannot specify initialization vector for ECB mode' if @mode == Mode::ECB
|
445
|
-
raise ArgumentError, "initialization
|
444
|
+
raise ArgumentError, "initialization vector is not a multiple of #{BLOCK_SIZE} bytes" unless (iv.length % BLOCK_SIZE).zero?
|
446
445
|
@iv = iv
|
447
446
|
end
|
448
447
|
|
@@ -471,9 +470,9 @@ class Twofish
|
|
471
470
|
# Encrypt a plaintext string, chunking as required for
|
472
471
|
# CBC mode.
|
473
472
|
def encrypt(plaintext)
|
474
|
-
plaintext = plaintext.dup
|
473
|
+
plaintext = to_binary(plaintext.dup)
|
475
474
|
padded_plaintext = Padding.pad!(plaintext, BLOCK_SIZE, @padding)
|
476
|
-
result =
|
475
|
+
result = to_binary('')
|
477
476
|
if @mode == Mode::CBC
|
478
477
|
@iv ||= SecureRandom.random_bytes(BLOCK_SIZE)
|
479
478
|
@_feedback ||= @iv
|
@@ -490,9 +489,9 @@ class Twofish
|
|
490
489
|
# chaining modes. If @iv is not set then we use the first block
|
491
490
|
# as the initialization vector when chaining.
|
492
491
|
def decrypt(ciphertext)
|
493
|
-
ciphertext = ciphertext.dup
|
492
|
+
ciphertext = to_binary(ciphertext.dup)
|
494
493
|
raise ArgumentError, "ciphertext is not a multiple of #{BLOCK_SIZE} bytes" unless (ciphertext.length % BLOCK_SIZE).zero?
|
495
|
-
result =
|
494
|
+
result = to_binary('')
|
496
495
|
if Mode::CBC == @mode
|
497
496
|
if @iv
|
498
497
|
@_feedback ||= @iv
|
@@ -1044,7 +1043,12 @@ class Twofish
|
|
1044
1043
|
[@k[0] ^ r2, @k[1] ^ r3, @k[2] ^ r0, @k[3] ^ r1].pack("V4")
|
1045
1044
|
end
|
1046
1045
|
|
1047
|
-
private
|
1046
|
+
private
|
1047
|
+
|
1048
|
+
# Force String encoding to binary/8-bit ASCII. NB mutates argument.
|
1049
|
+
def to_binary(s)
|
1050
|
+
s.respond_to?(:force_encoding) ? s.force_encoding('BINARY') : s
|
1051
|
+
end
|
1048
1052
|
|
1049
1053
|
# The (12, 8) Reed Solomon code has the generator polynomial:
|
1050
1054
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twofish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Carpenter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Twofish symmetric cipher in pure Ruby with ECB and CBC cipher modes derived
|
14
14
|
from an original Perl implementation by Guido Flohr
|
@@ -20,15 +20,14 @@ extra_rdoc_files:
|
|
20
20
|
- Rakefile
|
21
21
|
- README.rdoc
|
22
22
|
files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
- Rakefile
|
23
26
|
- lib/twofish.rb
|
24
27
|
- lib/twofish/mode.rb
|
25
28
|
- lib/twofish/padding.rb
|
26
|
-
- lib/string.rb
|
27
29
|
- test/benchmark.rb
|
28
30
|
- test/test_twofish.rb
|
29
|
-
- LICENSE
|
30
|
-
- Rakefile
|
31
|
-
- README.rdoc
|
32
31
|
homepage: http://mcarpenter.org/projects/twofish
|
33
32
|
licenses:
|
34
33
|
- BSD
|
@@ -39,17 +38,17 @@ require_paths:
|
|
39
38
|
- lib
|
40
39
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
40
|
requirements:
|
42
|
-
- -
|
41
|
+
- - ">="
|
43
42
|
- !ruby/object:Gem::Version
|
44
43
|
version: '0'
|
45
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
45
|
requirements:
|
47
|
-
- -
|
46
|
+
- - ">="
|
48
47
|
- !ruby/object:Gem::Version
|
49
48
|
version: '0'
|
50
49
|
requirements: []
|
51
50
|
rubyforge_project:
|
52
|
-
rubygems_version: 2.
|
51
|
+
rubygems_version: 2.4.8
|
53
52
|
signing_key:
|
54
53
|
specification_version: 4
|
55
54
|
summary: Twofish symmetric cipher in pure Ruby
|
data/lib/string.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
unless method_defined?(:byteslice)
|
4
|
-
def byteslice(*args)
|
5
|
-
self.dup.force_encoding('ASCII-8BIT').slice!(*args)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
unless method_defined?(:force_encoding)
|
10
|
-
def force_encoding(encoding)
|
11
|
-
self # noop
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|