digest-sip_hash 0.0.3 → 0.0.4

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: 5a7f861280074e2479ea4dd879b0689e7d68c3e1b79cd8b21d2d8a681fe3403e
4
- data.tar.gz: 88f8f40d5938dff8c6c7cc07337753e91136b891e04bfeb493b83c52baf8a055
3
+ metadata.gz: a821cc359081b3b9c8184db677719fce137d35f3a190839b99dbe2e05b3bc9a8
4
+ data.tar.gz: bc743f50abfe70fff01e3c7b9f438bfbb8e73e884928118a75dff76f72e1f314
5
5
  SHA512:
6
- metadata.gz: 5f6664550a1a456f862e5e4712946dcb199481ea3bdfb639ce6bb3c907dd61a221a7d3aa40fd81363a9d7367a7aa0880d99fa868565813a6b327cb398a1f0431
7
- data.tar.gz: 86623e37d7da7e52d2e3d87df72b68700275801ac21d7824b127d33da91d74898f1481f0feb0da264c502cb161bd3b1797fd6093067b12ba96151af2b0e89a9f
6
+ metadata.gz: 4e0c910c3e8e2b0131ccaef872e39e39767563655ef66b3ed48336125a1d17d7881b19aad12b98f5515327f175e44a7c256b1df1cd231cf3a5b42a0a6068bc80
7
+ data.tar.gz: 63743fce636a8dcd204f04d72edd1259f031d9b07e453d43783616c9341e7a0e16082598ddf5fff44d5bf0e92b0c53e162810a077a8b831d0ef69f8e3e9ac552
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ source 'https://rubygems.org'
4
+
3
5
  gemspec
@@ -23,7 +23,7 @@ options = ARGV.options do |x|
23
23
 
24
24
  x.on '-c=ROUNDS', UnsignedInteger, "Number of c rounds. Default: #{config.c}"
25
25
  x.on '-d=ROUNDS', UnsignedInteger, "Number of d rounds. Default: #{config.d}"
26
- x.on '-k', '--key=KEY', HexOctets, "Sixteen-byte hex key. Default: \"#{hex_key}\""
26
+ x.on '-k', '--key=KEY', HexOctets, "16-octet hex key. Default: \"#{hex_key}\""
27
27
  end.freeze
28
28
 
29
29
  begin
@@ -28,7 +28,7 @@ module Digest
28
28
  end
29
29
 
30
30
  def finish
31
- sip = Sip.new @buffer, @key, @c_rounds, @d_rounds
31
+ sip = Sip.new @buffer, @c_rounds, @d_rounds, @key
32
32
  sip.transform
33
33
  sip.finalize
34
34
  end
@@ -40,11 +40,10 @@ module Digest
40
40
  V2 = 'lygenera'.unpack1 'Q>'
41
41
  V3 = 'tedbytes'.unpack1 'Q>'
42
42
 
43
- def initialize buffer, key, c_rounds, d_rounds
44
- @buffer = buffer
45
- @size = @buffer.size
46
- @c_rounds = c_rounds
47
- @d_rounds = d_rounds
43
+ def initialize message, compression_rounds, finalization_rounds, key
44
+ @message = message
45
+ @compression_rounds = compression_rounds
46
+ @finalization_rounds = finalization_rounds
48
47
 
49
48
  k0 = key[0..7].unpack1 'Q<'
50
49
  k1 = key[8..15].unpack1 'Q<'
@@ -56,14 +55,13 @@ module Digest
56
55
  end
57
56
 
58
57
  def transform
59
- return compress_block 0 if @size.zero?
60
- (@size / 8).times { |n| compress_block block n }
58
+ (@message.size / 8).times { |n| compress_block block n }
61
59
  compress_block last_block
62
60
  end
63
61
 
64
62
  def finalize
65
63
  @v2 ^= 2 ** 8 - 1
66
- @d_rounds.times { compress }
64
+ @finalization_rounds.times { compress }
67
65
  [@v0 ^ @v1 ^ @v2 ^ @v3].pack 'Q>'
68
66
  end
69
67
 
@@ -71,33 +69,34 @@ module Digest
71
69
 
72
70
  def compress_block n
73
71
  @v3 ^= n
74
- @c_rounds.times { compress }
72
+ @compression_rounds.times { compress }
75
73
  @v0 ^= n
76
74
  end
77
75
 
78
76
  def block n
79
- @buffer.slice(n * 8, 8).unpack1 'Q<'
77
+ @message.slice(n * 8, 8).unpack1 'Q<'
80
78
  end
81
79
 
82
80
  def last_block
83
- remainder = @size % 8
84
- offset = @size - remainder
81
+ size = @message.size
82
+ remainder = size % 8
83
+ offset = size - remainder
85
84
 
86
- remainder.times.reverse_each.reduce @size << 56 & MASK do |last, n|
87
- last | @buffer[n + offset].ord << 8 * n
85
+ remainder.times.reduce size << 56 & MASK do |last, n|
86
+ last | @message[n + offset].ord << 8 * n
88
87
  end
89
88
  end
90
89
 
91
90
  def compress
92
91
  @v0 = add @v0, @v1
93
- @v1 = rotate @v1, 13, @v0
92
+ @v1 = rotate @v1, 13, xor: @v0
94
93
  @v0 = rotate @v0, 32
95
94
  @v2 = add @v2, @v3
96
- @v3 = rotate @v3, 16, @v2
95
+ @v3 = rotate @v3, 16, xor: @v2
97
96
  @v0 = add @v0, @v3
98
- @v3 = rotate @v3, 21, @v0
97
+ @v3 = rotate @v3, 21, xor: @v0
99
98
  @v2 = add @v2, @v1
100
- @v1 = rotate @v1, 17, @v2
99
+ @v1 = rotate @v1, 17, xor: @v2
101
100
  @v2 = rotate @v2, 32
102
101
  end
103
102
 
@@ -105,7 +104,7 @@ module Digest
105
104
  a + b & MASK
106
105
  end
107
106
 
108
- def rotate n, by, xor = 0
107
+ def rotate n, by, xor: 0
109
108
  n << by & MASK | n >> 64 - by ^ xor
110
109
  end
111
110
  end
@@ -4,6 +4,6 @@ require 'digest'
4
4
 
5
5
  module Digest
6
6
  class SipHash < Digest::Class
7
- VERSION = '0.0.3'
7
+ VERSION = '0.0.4'
8
8
  end
9
9
  end
@@ -13,6 +13,10 @@ describe Digest::SipHash do
13
13
  assert_equal '8264ceeccb16bcbe', Digest::SipHash13.hexdigest('siphash')
14
14
  assert_equal 'ce31007e34130c0a', Digest::SipHash13.hexdigest('digest-sip_hash')
15
15
  assert_equal '1b47c0cc4dd21f05', Digest::SipHash13.hexdigest('x' * 1_000)
16
+ assert_equal '136ea6cf74ee7506', Digest::SipHash13.hexdigest('abc' * 10_000)
17
+ assert_equal '8421ff50252ef54c', Digest::SipHash13.hexdigest('bulldozer')
18
+ assert_equal '1ad2b299abf672fd', Digest::SipHash13.hexdigest('ishmael')
19
+ assert_equal '1403853b32c9a3d7', Digest::SipHash13.hexdigest('latour')
16
20
  end
17
21
 
18
22
  describe 'with a key' do
@@ -25,6 +29,10 @@ describe Digest::SipHash do
25
29
  assert_equal 'd5518fe19f28c745', Digest::SipHash13.hexdigest('siphash', key: key)
26
30
  assert_equal '71783f159400d4b5', Digest::SipHash13.hexdigest('digest-sip_hash', key: key)
27
31
  assert_equal '2a82bb3e74675b16', Digest::SipHash13.hexdigest('x' * 1_000, key: key)
32
+ assert_equal '13152caa40a6671a', Digest::SipHash13.hexdigest('abc' * 10_000, key: key)
33
+ assert_equal '503567849e7ff802', Digest::SipHash13.hexdigest('bulldozer', key: key)
34
+ assert_equal '39b0f77e620b9655', Digest::SipHash13.hexdigest('ishmael', key: key)
35
+ assert_equal '6aafa6fdaf07577a', Digest::SipHash13.hexdigest('latour', key: key)
28
36
  end
29
37
  end
30
38
  end
@@ -35,6 +43,10 @@ describe Digest::SipHash do
35
43
  assert_equal '59caaeb90d542464', Digest::SipHash24.hexdigest('siphash')
36
44
  assert_equal '4b5cd6bb2500bc8f', Digest::SipHash24.hexdigest('digest-sip_hash')
37
45
  assert_equal 'a07a230346e2656b', Digest::SipHash24.hexdigest('x' * 1_000)
46
+ assert_equal '2e05ad971738666e', Digest::SipHash24.hexdigest('abc' * 10_000)
47
+ assert_equal '35e35e884f56688f', Digest::SipHash24.hexdigest('bulldozer')
48
+ assert_equal '98585807dafda42b', Digest::SipHash24.hexdigest('ishmael')
49
+ assert_equal '3802759a0e659a96', Digest::SipHash24.hexdigest('latour')
38
50
  end
39
51
 
40
52
  describe 'with a key' do
@@ -45,8 +57,12 @@ describe Digest::SipHash do
45
57
  it 'is the correct hexdigest' do
46
58
  assert_equal '726fdb47dd0e0e31', Digest::SipHash24.hexdigest('', key: key)
47
59
  assert_equal '882768570dc71c92', Digest::SipHash24.hexdigest('siphash', key: key)
48
- assert_equal '882768570dc71c92', Digest::SipHash24.hexdigest('siphash', key: key)
49
- assert_equal '882768570dc71c92', Digest::SipHash24.hexdigest('siphash', key: key)
60
+ assert_equal '064ced3bea4abf32', Digest::SipHash24.hexdigest('digest-sip_hash', key: key)
61
+ assert_equal '3d1ce6276d329229', Digest::SipHash24.hexdigest('x' * 1_000, key: key)
62
+ assert_equal 'd0da1f6b4e838b97', Digest::SipHash24.hexdigest('abc' * 10_000, key: key)
63
+ assert_equal 'dae7cd2313f56d73', Digest::SipHash24.hexdigest('bulldozer', key: key)
64
+ assert_equal 'd1ce681ecf6810e4', Digest::SipHash24.hexdigest('ishmael', key: key)
65
+ assert_equal '383e7b1932947fd0', Digest::SipHash24.hexdigest('latour', key: key)
50
66
  end
51
67
  end
52
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digest-sip_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shannon Skipper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake