openssl-cmac 2.0.0 → 2.0.1

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
- SHA1:
3
- metadata.gz: 63fc4231601c14a5a8a6fc04bdcc4291b7be2cda
4
- data.tar.gz: cbcabe5e112d41adf149d6eac700157569731636
2
+ SHA256:
3
+ metadata.gz: 58e850b8ce1e363d8f266ca946ed468f04a9161bd7eb971952aed8bbbe7f710e
4
+ data.tar.gz: f0e70e6e6aea806c6c84a79f7dc08dfc8cd943d25252e58b624151041eb2a829
5
5
  SHA512:
6
- metadata.gz: 3d1d6128a6a4c99b71461f7d14411502215e19aa33779f38d907203d62333052000cd3aed8c4f1a1d3706bf0f554ea7ce70a2b44173145683e345343d92486ca
7
- data.tar.gz: a86fc591bd98f5505986c1807d61a32214a9892366553268e3e3791c90865a6c339520a0d8929de1322030a1eca837643018af5655800e03ac79c8599dbbd483
6
+ metadata.gz: e9ad7b7a1d120025675cecd4f58839f295614bde15174a96581f055c064b418b33a40e54c99faa76776a2da93c1dee6765c2d8c21dbfe1463a85a1fcfd153fd6
7
+ data.tar.gz: 9769d44ea03d292b490a16cf352a47dd42fce4ff0fe87426bd0efa5ffd56c20cd1ef64282233328edaba7a0a0a9b180266763aa6c6d721e1e2078725b4c4fcda
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rake', '>=10.2.2'
4
- gem 'rdoc', '>=4.1.1'
5
- gem 'yard', '>=0.8.7.3'
6
- gem 'rubocop', '>=0.18.1'
7
- gem 'coveralls', '>=00.7.0'
3
+ gem 'rake', '>=12.3.2'
4
+ gem 'rdoc', '>=4.3.0'
5
+ gem 'yard', '>=0.9.16'
6
+ gem 'rubocop', '>=0.50.0'
7
+ gem 'test-unit', '>=3.2.9'
8
+ gem 'coveralls', '>=0.8.22'
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/SmallLars/openssl-cmac.png?branch=master)](https://travis-ci.org/SmallLars/openssl-cmac)
4
4
  [![Coverage Status](https://coveralls.io/repos/SmallLars/openssl-cmac/badge.png?branch=master)](https://coveralls.io/r/SmallLars/openssl-cmac)
5
5
  [![Code Climate](https://codeclimate.com/github/SmallLars/openssl-cmac.png)](https://codeclimate.com/github/SmallLars/openssl-cmac)
6
- [![Inline docs](http://inch-pages.github.io/github/smalllars/openssl-cmac.png)](http://inch-pages.github.io/github/smalllars/openssl-cmac)
6
+ [![Inline docs](http://inch-ci.org/github/smalllars/openssl-cmac.png)](http://inch-ci.org/github/smalllars/openssl-cmac)
7
7
 
8
8
  # openssl-cmac
9
9
 
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ task :clean do
24
24
  end
25
25
 
26
26
  desc "Development Dependencies"
27
- task (:devinst) { sh "gem install --dev ./openssl-cmac-#{OpenSSL::CMAC::VERSION}.gem" }
27
+ task (:devinst) { sh "gem install --dev ./pkg/openssl-cmac-#{OpenSSL::CMAC::VERSION}.gem" }
28
28
 
29
29
  desc "Bundle install"
30
30
  task (:bundle) { sh "bundle install" }
@@ -26,9 +26,7 @@ module OpenSSL
26
26
  #
27
27
  # @return [[String]] supported algorithms
28
28
  def self.ciphers
29
- l = OpenSSL::Cipher.ciphers.keep_if { |c| c.end_with?('-128-CBC') }
30
- l.length.times { |i| l[i] = l[i][0..-9] }
31
- l
29
+ @ciphers ||= OpenSSL::Cipher.ciphers.select { |c| c.match(/-128-CBC$/i) }.map { |e| e[0..-9].upcase }.uniq
32
30
  end
33
31
 
34
32
  # Returns the authentication code as a binary string. The cipher parameter
@@ -56,13 +54,13 @@ module OpenSSL
56
54
  #
57
55
  # @return [Object] the new CMAC object
58
56
  def initialize(cipher, key = '')
59
- unless CMAC.ciphers.include?(cipher)
57
+ unless CMAC.ciphers.include?(cipher.upcase)
60
58
  fail CMACError, "unsupported cipher algorithm (#{cipher})"
61
59
  end
62
60
 
63
61
  @keys = []
64
62
  @buffer = ''.force_encoding('ASCII-8BIT')
65
- @cipher = OpenSSL::Cipher.new("#{cipher}-128-CBC")
63
+ @cipher = OpenSSL::Cipher.new("#{cipher.upcase}-128-CBC")
66
64
 
67
65
  self.key = key unless key == ''
68
66
  end
@@ -83,7 +81,7 @@ module OpenSSL
83
81
  cipher = OpenSSL::Cipher.new(@cipher.name)
84
82
  cipher.encrypt
85
83
  cipher.key = @keys[0]
86
- k = cipher.update("\x00" * 16).bytes
84
+ k = (cipher.update("\x00" * 16) + cipher.final).bytes[0...16]
87
85
  1.upto(2) do |i|
88
86
  k = k.pack('C*').unpack('B*')[0]
89
87
  msb = k.slice!(0)
@@ -127,7 +125,7 @@ module OpenSSL
127
125
  def reset
128
126
  @keys.clear
129
127
  @buffer.clear
130
- @cipher.reset
128
+ @cipher.reset unless @keys[0].nil?
131
129
  @cipher.encrypt
132
130
  self
133
131
  end
@@ -158,11 +156,14 @@ module OpenSSL
158
156
  k = @keys[block.length == 16 ? 1 : 2].dup
159
157
  i = block.length.times { |t| k[t] ^= block[t] }
160
158
  k[i] ^= 0x80 if i < 16
161
- mac = @cipher.update(k.pack('C*'))
159
+ mac = @cipher.update(k.pack('C*')) + @cipher.final
162
160
  @cipher.reset
163
161
  @cipher.encrypt
164
162
  @cipher.key = @keys[0]
165
- mac[0...length]
163
+ # Each block is 16-bytes and the last block will always be PKCS#7 padding
164
+ # which we want to discard. Take the last block prior to the padding for
165
+ # the MAC.
166
+ mac[-32...(-32 + length)]
166
167
  end
167
168
  end
168
169
  end
@@ -1,5 +1,5 @@
1
1
  module OpenSSL
2
2
  class CMAC
3
- VERSION = '2.0.0'
3
+ VERSION = '2.0.1'
4
4
  end
5
5
  end
@@ -87,39 +87,41 @@ class CMACTest < Test::Unit::TestCase
87
87
  end
88
88
 
89
89
  def test_cmac_update
90
- # Test with 1 call of update and new CCM object for each test.
91
- DATA.length.times do |i|
92
- cmac = OpenSSL::CMAC.new('AES', KEY)
93
- m = cmac.update(DATA[i]).digest.unpack('H*')[0]
94
- assert_equal(MAC[i], m, "Test: 1, Vector: #{i + 1}")
95
- end
90
+ for cipher in ['aes', 'AES']
91
+ # Test with 1 call of update and new CCM object for each test.
92
+ DATA.length.times do |i|
93
+ cmac = OpenSSL::CMAC.new(cipher, KEY)
94
+ m = cmac.update(DATA[i]).digest.unpack('H*')[0]
95
+ assert_equal(MAC[i], m, "Test: 1, Vector: #{i + 1}")
96
+ end
96
97
 
97
- # Test with 1 call of update and same CCM object for each test.
98
- # There is no reset, because it should be possible to calculate
99
- # a new mac after digest without reset.
100
- cmac = OpenSSL::CMAC.new('AES', KEY)
101
- DATA.length.times do |i|
102
- m = cmac.update(DATA[i]).digest.unpack('H*')[0]
103
- assert_equal(MAC[i], m, "Test: 2, Vector: #{i + 1}")
104
- end
98
+ # Test with 1 call of update and same CCM object for each test.
99
+ # There is no reset, because it should be possible to calculate
100
+ # a new mac after digest without reset.
101
+ cmac = OpenSSL::CMAC.new(cipher, KEY)
102
+ DATA.length.times do |i|
103
+ m = cmac.update(DATA[i]).digest.unpack('H*')[0]
104
+ assert_equal(MAC[i], m, "Test: 2, Vector: #{i + 1}")
105
+ end
105
106
 
106
- # Test with multiple calls of update and new CCM object for each test
107
- 1.upto(DATA.length - 1) do |i|
108
- 1.upto(17) do |c|
109
- cmac = OpenSSL::CMAC.new('AES', KEY)
110
- DATA[i].bytes.each_slice(c) { |w| cmac.update(w.pack('C*')) }
111
- m = cmac.digest.unpack('H*')[0]
112
- assert_equal(MAC[i], m, "Test: 3, Vector: #{i + 1}, Tokenlen: #{c}")
107
+ # Test with multiple calls of update and new CCM object for each test
108
+ 1.upto(DATA.length - 1) do |i|
109
+ 1.upto(17) do |c|
110
+ cmac = OpenSSL::CMAC.new(cipher, KEY)
111
+ DATA[i].bytes.each_slice(c) { |w| cmac.update(w.pack('C*')) }
112
+ m = cmac.digest.unpack('H*')[0]
113
+ assert_equal(MAC[i], m, "Test: 3, Vector: #{i + 1}, Tokenlen: #{c}")
114
+ end
113
115
  end
114
- end
115
116
 
116
- # Test with multiple calls of update and same CCM object for each test
117
- cmac = OpenSSL::CMAC.new('AES', KEY)
118
- 1.upto(DATA.length - 1) do |i|
119
- 1.upto(17) do |c|
120
- DATA[i].bytes.each_slice(c) { |w| cmac.update(w.pack('C*')) }
121
- m = cmac.digest.unpack('H*')[0]
122
- assert_equal(MAC[i], m, "Test: 4, Vector: #{i + 1}, Tokenlen: #{c}")
117
+ # Test with multiple calls of update and same CCM object for each test
118
+ cmac = OpenSSL::CMAC.new(cipher, KEY)
119
+ 1.upto(DATA.length - 1) do |i|
120
+ 1.upto(17) do |c|
121
+ DATA[i].bytes.each_slice(c) { |w| cmac.update(w.pack('C*')) }
122
+ m = cmac.digest.unpack('H*')[0]
123
+ assert_equal(MAC[i], m, "Test: 4, Vector: #{i + 1}, Tokenlen: #{c}")
124
+ end
123
125
  end
124
126
  end
125
127
 
@@ -130,25 +132,27 @@ class CMACTest < Test::Unit::TestCase
130
132
  end
131
133
 
132
134
  def test_cmac_digest
133
- cmac = OpenSSL::CMAC.new('AES', KEY)
134
- m = cmac.update(DATA[3]).digest.unpack('H*')[0]
135
- assert_equal(MAC[3], m, 'Digest with no update')
136
-
137
- cmac.update(DATA[3].b[0...20])
138
- m = cmac.update(DATA[3].b[20...64]).digest.unpack('H*')[0]
139
- assert_equal(MAC[3], m, 'Digest after update')
140
-
141
- cmac.update(DATA[3])
142
- m = cmac.update('').digest.unpack('H*')[0]
143
- assert_equal(MAC[3], m, 'Empty digest')
144
-
145
- DATA.length.times do |i|
146
- m = OpenSSL::CMAC.digest('AES', KEY, DATA[i]).unpack('H*')[0]
147
- assert_equal(MAC[i], m, "Vector: #{i + 1}")
148
-
149
- m = OpenSSL::CMAC.digest('AES', KEY, DATA[i], 12).unpack('H*')[0]
150
- assert_equal(24, m.length, "Vector: #{i + 1} - length")
151
- assert_equal(MAC[i][0...24], m, "Vector: #{i + 1} - 12")
135
+ for cipher in ['aes', 'AES']
136
+ cmac = OpenSSL::CMAC.new(cipher, KEY)
137
+ m = cmac.update(DATA[3]).digest.unpack('H*')[0]
138
+ assert_equal(MAC[3], m, 'Digest with no update')
139
+
140
+ cmac.update(DATA[3].b[0...20])
141
+ m = cmac.update(DATA[3].b[20...64]).digest.unpack('H*')[0]
142
+ assert_equal(MAC[3], m, 'Digest after update')
143
+
144
+ cmac.update(DATA[3])
145
+ m = cmac.update('').digest.unpack('H*')[0]
146
+ assert_equal(MAC[3], m, 'Empty digest')
147
+
148
+ DATA.length.times do |i|
149
+ m = OpenSSL::CMAC.digest(cipher, KEY, DATA[i]).unpack('H*')[0]
150
+ assert_equal(MAC[i], m, "Vector: #{i + 1}")
151
+
152
+ m = OpenSSL::CMAC.digest(cipher, KEY, DATA[i], 12).unpack('H*')[0]
153
+ assert_equal(24, m.length, "Vector: #{i + 1} - length")
154
+ assert_equal(MAC[i][0...24], m, "Vector: #{i + 1} - 12")
155
+ end
152
156
  end
153
157
  end
154
158
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openssl-cmac
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim M. Chechel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-02 00:00:00.000000000 Z
12
+ date: 2019-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -17,100 +17,120 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '10.2'
20
+ version: '12.3'
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 10.2.2
23
+ version: 12.3.2
24
24
  type: :development
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: '10.2'
30
+ version: '12.3'
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 10.2.2
33
+ version: 12.3.2
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdoc
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '4.1'
41
38
  - - ">="
42
39
  - !ruby/object:Gem::Version
43
- version: 4.1.1
40
+ version: 4.3.0
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '4.3'
44
44
  type: :development
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - "~>"
49
- - !ruby/object:Gem::Version
50
- version: '4.1'
51
48
  - - ">="
52
49
  - !ruby/object:Gem::Version
53
- version: 4.1.1
50
+ version: 4.3.0
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '4.3'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: yard
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.8'
60
+ version: '0.9'
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 0.8.7.3
63
+ version: 0.9.16
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '0.8'
70
+ version: '0.9'
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: 0.8.7.3
73
+ version: 0.9.16
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: rubocop
76
76
  requirement: !ruby/object:Gem::Requirement
77
77
  requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 0.50.0
78
81
  - - "~>"
79
82
  - !ruby/object:Gem::Version
80
- version: '0.18'
83
+ version: '0.50'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
81
88
  - - ">="
82
89
  - !ruby/object:Gem::Version
83
- version: 0.18.1
90
+ version: 0.50.0
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '0.50'
94
+ - !ruby/object:Gem::Dependency
95
+ name: test-unit
96
+ requirement: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '3.2'
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.2.9
84
104
  type: :development
85
105
  prerelease: false
86
106
  version_requirements: !ruby/object:Gem::Requirement
87
107
  requirements:
88
108
  - - "~>"
89
109
  - !ruby/object:Gem::Version
90
- version: '0.18'
110
+ version: '3.2'
91
111
  - - ">="
92
112
  - !ruby/object:Gem::Version
93
- version: 0.18.1
113
+ version: 3.2.9
94
114
  - !ruby/object:Gem::Dependency
95
115
  name: coveralls
96
116
  requirement: !ruby/object:Gem::Requirement
97
117
  requirements:
98
118
  - - "~>"
99
119
  - !ruby/object:Gem::Version
100
- version: '0.7'
120
+ version: '0.8'
101
121
  - - ">="
102
122
  - !ruby/object:Gem::Version
103
- version: 0.7.0
123
+ version: 0.8.22
104
124
  type: :development
105
125
  prerelease: false
106
126
  version_requirements: !ruby/object:Gem::Requirement
107
127
  requirements:
108
128
  - - "~>"
109
129
  - !ruby/object:Gem::Version
110
- version: '0.7'
130
+ version: '0.8'
111
131
  - - ">="
112
132
  - !ruby/object:Gem::Version
113
- version: 0.7.0
133
+ version: 0.8.22
114
134
  description: Ruby Gem for RFC 4493, 4494, 4615 - The AES-CMAC Algorithm
115
135
  email:
116
136
  - maximchick@gmail.com
@@ -151,11 +171,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
171
  - !ruby/object:Gem::Version
152
172
  version: '0'
153
173
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.2.2
174
+ rubygems_version: 3.0.3
156
175
  signing_key:
157
176
  specification_version: 4
158
177
  summary: RFC 4493, 4494, 4615 - CMAC
159
178
  test_files:
160
179
  - test/test_cmac.rb
161
- has_rdoc: