siphash-ir 0.1.0
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 +7 -0
- data/Gemfile +2 -0
- data/MIT-LICENSE +19 -0
- data/README.md +23 -0
- data/Rakefile +7 -0
- data/bin/siphash-digest +19 -0
- data/lib/siphash-ir.rb +3 -0
- data/pool/siphash-ir.cut +6 -0
- data/pool/siphash-ir.jar +0 -0
- data/ruby/SipHash.rb +90 -0
- data/siphash-ir.gemspec +16 -0
- data/spec/spec_helper.rb +1 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e55091c7036c3907e829a763ad81b969cfd4191
|
4
|
+
data.tar.gz: 4e55f649e006f4d25a6a27b3800bcf6ccf5c6ec7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 255d583c4f09f75ea3d26abc580022f8e416bc949c9cfea477b6363d5ba2201f71aff2256b0ccf2b084d2e34a616504e6a7fe47e0b4b69c90ef3a9dcc37a1bf1
|
7
|
+
data.tar.gz: 50dd66edc2a0a75ca23402f022367c85f4ce2bd4aff4a87b5f7ce56a8581c34d068f7bd201c24814d6b11c9cfd7f4718ec83bb55bde991e4c674713ee4fb5d44
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011-2015 InfraRuby Vision
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
copy of this software and associated documentation files (the "Software"),
|
5
|
+
to deal in the Software without restriction, including without limitation
|
6
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
7
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
8
|
+
Software is furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
19
|
+
DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
InfraRuby siphash
|
2
|
+
=================
|
3
|
+
|
4
|
+
This gem provides a SipHash implementation.
|
5
|
+
|
6
|
+
|
7
|
+
Example
|
8
|
+
-------
|
9
|
+
|
10
|
+
require "siphash-ir"
|
11
|
+
|
12
|
+
puts SipHash.digest("0123456789ABCDEF", "hello, world")
|
13
|
+
|
14
|
+
|
15
|
+
Support
|
16
|
+
-------
|
17
|
+
|
18
|
+
InfraRuby Vision
|
19
|
+
rubygems@infraruby.com
|
20
|
+
|
21
|
+
http://infraruby.com/
|
22
|
+
https://github.com/InfraRuby
|
23
|
+
https://twitter.com/InfraRuby
|
data/Rakefile
ADDED
data/bin/siphash-digest
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "siphash-ir"
|
4
|
+
|
5
|
+
if ARGV.size_as_int32 != 1
|
6
|
+
STDERR.puts "Usage: siphash-digest key"
|
7
|
+
STDERR.puts "Example:"
|
8
|
+
STDERR.puts "\t" + "siphash-digest 0123456789ABCDEF"
|
9
|
+
Kernel.exit(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
key = ARGV.first!
|
13
|
+
|
14
|
+
if key.bytesize_as_int32 != 16
|
15
|
+
STDERR.puts "siphash-digest: key must be 16 bytes"
|
16
|
+
Kernel.exit(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
puts SipHash.digest(key, STDIN.read)
|
data/lib/siphash-ir.rb
ADDED
data/pool/siphash-ir.cut
ADDED
data/pool/siphash-ir.jar
ADDED
Binary file
|
data/ruby/SipHash.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
## <>
|
2
|
+
module SipHash
|
3
|
+
class << self
|
4
|
+
## int64, int64, int64, int64 -> [int64, int64, int64, int64]
|
5
|
+
def __round(v0, v1, v2, v3)
|
6
|
+
v0 += v1
|
7
|
+
v2 += v3
|
8
|
+
v1 = v1.rol(13)
|
9
|
+
v3 = v3.rol(16)
|
10
|
+
v1 ^= v0
|
11
|
+
v3 ^= v2
|
12
|
+
v0 = v0.rol(32)
|
13
|
+
v2 += v1
|
14
|
+
v0 += v3
|
15
|
+
v1 = v1.rol(17)
|
16
|
+
v3 = v3.rol(21)
|
17
|
+
v1 ^= v2
|
18
|
+
v3 ^= v0
|
19
|
+
v2 = v2.rol(32)
|
20
|
+
return [v0, v1, v2, v3]
|
21
|
+
end
|
22
|
+
|
23
|
+
## int64, int64, byte[] -> int64
|
24
|
+
def digest_as_int64(k0, k1, m)
|
25
|
+
v0 = k0 ^ 0x736F6D6570736575
|
26
|
+
v1 = k1 ^ 0x646F72616E646F6D
|
27
|
+
v2 = k0 ^ 0x6C7967656E657261
|
28
|
+
v3 = k1 ^ 0x7465646279746573
|
29
|
+
n = m.length.i32 & ~7.i32
|
30
|
+
i = 0.i32
|
31
|
+
while i < n
|
32
|
+
w = 0.i64
|
33
|
+
j = 0.i32
|
34
|
+
while j < 64
|
35
|
+
w |= (m[i.as_i].byte & 0xFF).to_int64 << j
|
36
|
+
i += 1
|
37
|
+
j += 8
|
38
|
+
end
|
39
|
+
v3 ^= w
|
40
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
41
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
42
|
+
v0 ^= w
|
43
|
+
end
|
44
|
+
w = 0.i64
|
45
|
+
j = 0.i32
|
46
|
+
while i < m.length
|
47
|
+
w |= (m[i.as_i].byte & 0xFF).to_int64 << j
|
48
|
+
i += 1
|
49
|
+
j += 8
|
50
|
+
end
|
51
|
+
w |= m.length.i32.to_int64 << 070
|
52
|
+
v3 ^= w
|
53
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
54
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
55
|
+
v0 ^= w
|
56
|
+
v2 ^= 0xFF
|
57
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
58
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
59
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
60
|
+
v0, v1, v2, v3 = __round(v0, v1, v2, v3)
|
61
|
+
return v0 ^ v1 ^ v2 ^ v3
|
62
|
+
end
|
63
|
+
|
64
|
+
## String, String -> Integer
|
65
|
+
def digest(k, s)
|
66
|
+
m = k.to_java_bytes_unsafe
|
67
|
+
n = m.length.i32
|
68
|
+
if n != 020
|
69
|
+
raise ArgumentError, "key must be 16 bytes"
|
70
|
+
end
|
71
|
+
k1 = 0.i64
|
72
|
+
while n > 8
|
73
|
+
n -= 1
|
74
|
+
k1 <<= 8
|
75
|
+
k1 |= (m[n.as_i].byte & 0xFF).to_int64
|
76
|
+
end
|
77
|
+
k0 = 0.i64
|
78
|
+
while n > 0
|
79
|
+
n -= 1
|
80
|
+
k0 <<= 8
|
81
|
+
k0 |= (m[n.as_i].byte & 0xFF).to_int64
|
82
|
+
end
|
83
|
+
v = digest_as_int64(k0, k1, s.to_java_bytes_unsafe)
|
84
|
+
if v < 0
|
85
|
+
return v.new_fixnum & 0xFFFFFFFFFFFFFFFF
|
86
|
+
end
|
87
|
+
return v.new_fixnum
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/siphash-ir.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.platform = "ruby"
|
3
|
+
s.name = "siphash-ir"
|
4
|
+
s.version = "0.1.0"
|
5
|
+
s.licenses = ["MIT"]
|
6
|
+
s.author = "InfraRuby Vision"
|
7
|
+
s.email = "rubygems@infraruby.com"
|
8
|
+
s.homepage = "http://infraruby.com/"
|
9
|
+
s.summary = "InfraRuby SipHash implementation"
|
10
|
+
s.description = "InfraRuby SipHash implementation"
|
11
|
+
s.executables = ["siphash-digest"]
|
12
|
+
s.files = Dir["**/*"]
|
13
|
+
s.add_runtime_dependency "infraruby-shim", "~> 3.6"
|
14
|
+
s.add_development_dependency "infraruby-task", "~> 3.6"
|
15
|
+
s.add_development_dependency "rspec", "~> 3.0"
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "siphash-ir"
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: siphash-ir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- InfraRuby Vision
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: infraruby-shim
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: infraruby-task
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: InfraRuby SipHash implementation
|
56
|
+
email: rubygems@infraruby.com
|
57
|
+
executables:
|
58
|
+
- siphash-digest
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- MIT-LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- bin/siphash-digest
|
67
|
+
- lib/siphash-ir.rb
|
68
|
+
- pool/siphash-ir.cut
|
69
|
+
- pool/siphash-ir.jar
|
70
|
+
- ruby/SipHash.rb
|
71
|
+
- siphash-ir.gemspec
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: http://infraruby.com/
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: InfraRuby SipHash implementation
|
97
|
+
test_files: []
|