digest-siphash 0.0.1 → 1.0.0

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
  SHA1:
3
- metadata.gz: c27f151cfd6e1509a0b7b8086b872f697faa1da9
4
- data.tar.gz: 24c64c35d7be6a31e1099f272e79d638778f1e8f
3
+ metadata.gz: cc0ecdf1ed635eda8af63f049c68245e9a4e3874
4
+ data.tar.gz: 1d249556827c6649878931206361e3a861eaf77b
5
5
  SHA512:
6
- metadata.gz: e073e6bdc4e2d985eb7ab22fb253d2460120bcda4fc71f4fd033ee52e473abf06f5ffbffe2e64b7aef9ea652e867815a468b9f9125f2068ef52125b77dd7f263
7
- data.tar.gz: ade5bfd91c2b4403d7463f5d4d934e80d0e41a5abba1ca9fe5944797dd1ba7a3d28dd192c4e8f96c4ae86193c154c26380bdae4af0006f9076fce8991d6f257b
6
+ metadata.gz: d80408d9eff05f9ddd1627e51ff18eb4462c96a92c556987d36d254ca6ce610bc59667236c6e2aac0869ebf45a883c246a43b4693cdbf39d12832128ce4b43f4
7
+ data.tar.gz: 103adac3d2c95a8d6be607eb9c6a8de5ba9c5d3d0af3b3d4595f12ca3631d6dedc29d86e2e5391693036563010a71c6d34d11622f7d621747d556bc3294d8d6b
@@ -3,4 +3,3 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.0
6
- - 2.2.0
data/README.md CHANGED
@@ -27,11 +27,11 @@ and other way. instance use.
27
27
  ```ruby
28
28
  siphash = Digest::SipHash.new
29
29
  siphash.update "siphash"
30
- p siphash.digest #=> "\x88\x27\x68\x57\x0d\xc7\x1c\x92"
30
+ p siphash.hexdigest #=> "59caaeb90d542464"
31
31
 
32
32
  # of course, can change seed value.
33
33
  siphash.seed = (0..0x0f).to_a.pack("C16")
34
- p siphash.hexdigest "siphash" #=> "882768570dc71c92"
34
+ p siphash.hexdigest #=> "882768570dc71c92"
35
35
  ```
36
36
 
37
37
  ## Installation
@@ -2,11 +2,13 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
+ require 'digest/siphash'
6
+
5
7
  Gem::Specification.new do |spec|
6
8
  spec.name = "digest-siphash"
7
- spec.version = "0.0.1"
8
- spec.authors = "ksss"
9
- spec.email = "co000ri@gmail.com"
9
+ spec.version = Digest::SipHash::VERSION
10
+ spec.authors = ["ksss"]
11
+ spec.email = ["co000ri@gmail.com"]
10
12
  spec.summary = %q{Digest::SipHash is a class of message digest use algorithm SipHash.}
11
13
  spec.description = %q{Digest::SipHash is a class of message digest use algorithm SipHash.}
12
14
  spec.homepage = ""
@@ -18,9 +20,9 @@ Gem::Specification.new do |spec|
18
20
  spec.require_paths = ["lib"]
19
21
  spec.extensions = ["ext/digest/siphash/extconf.rb"]
20
22
 
21
- spec.add_runtime_dependency "digest-stringbuffer", ["~> 0.0.2"]
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_runtime_dependency "digest-simple"
24
+ spec.add_development_dependency "bundler"
23
25
  spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec", ['~> 2.11']
26
+ spec.add_development_dependency "rspec"
25
27
  spec.add_development_dependency "rake-compiler", ["~> 0.8.3"]
26
28
  end
@@ -2,30 +2,11 @@
2
2
  #include "siphash.h"
3
3
 
4
4
  #define siphash crypto_auth
5
- #define DEFAULT_SEED "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
6
5
 
7
6
  VALUE cDigest_SipHash;
8
7
  ID id_DEFAULT_SEED;
9
- ID id_seed;
10
-
11
- static VALUE
12
- siphash_seed_get(VALUE self)
13
- {
14
- if (!rb_ivar_defined(self, id_seed)) {
15
- rb_ivar_set(self, id_seed, rb_usascii_str_new(DEFAULT_SEED, 16));
16
- }
17
- return rb_ivar_get(self, id_seed);
18
- }
19
-
20
- static VALUE
21
- siphash_seed_set(VALUE self, VALUE obj)
22
- {
23
- StringValue(obj);
24
- if (RSTRING_LEN(obj) != 16) {
25
- rb_raise(rb_eArgError, "seed string should 128 bit chars");
26
- }
27
- return rb_ivar_set(self, id_seed, obj);
28
- }
8
+ ID iv_seed;
9
+ ID iv_buffer;
29
10
 
30
11
  static void
31
12
  _siphash_s_digest(uint8_t* digest, int argc, VALUE *argv)
@@ -57,11 +38,11 @@ static inline void
57
38
  _siphash_finish(uint8_t *digest, VALUE self)
58
39
  {
59
40
  const unsigned char *seed;
60
- buffer_t *ptr;
41
+ VALUE buffer;
61
42
 
62
- Data_Get_Struct(self, buffer_t, ptr);
63
- seed = (const unsigned char *) RSTRING_PTR(siphash_seed_get(self));
64
- siphash(digest, (const unsigned char *) ptr->buffer, ptr->p - ptr->buffer, seed);
43
+ buffer = rb_ivar_get(self, iv_buffer);
44
+ seed = (const unsigned char *) RSTRING_PTR(rb_ivar_get(self, iv_seed));
45
+ siphash(digest, (const unsigned char *) RSTRING_PTR(buffer), RSTRING_LEN(buffer), seed);
65
46
  }
66
47
 
67
48
  static VALUE
@@ -82,14 +63,6 @@ siphash_finish(VALUE self)
82
63
  return rb_str_new((const char*) digest, 8);
83
64
  }
84
65
 
85
- static VALUE
86
- siphash_to_i(VALUE self)
87
- {
88
- uint8_t digest[8];
89
- _siphash_finish(digest, self);
90
- return ULL2NUM(*(uint64_t *) digest);
91
- }
92
-
93
66
  static VALUE
94
67
  siphash_s_digest(int argc, VALUE *argv, VALUE klass)
95
68
  {
@@ -108,40 +81,33 @@ siphash_s_digest(int argc, VALUE *argv, VALUE klass)
108
81
  return rb_str_new((const char*) digest, 8);
109
82
  }
110
83
 
111
- static VALUE
112
- siphash_s_hexdigest(int argc, VALUE *argv, VALUE klass)
113
- {
114
- return hexencode_str_new(siphash_s_digest(argc, argv, klass));
115
- }
116
-
117
84
  static VALUE
118
85
  siphash_s_rawdigest(int argc, VALUE *argv, VALUE klass)
119
86
  {
120
87
  uint8_t digest[8];
88
+ #if LITTLE_ENDIAN
89
+ uint8_t roll[8];
90
+ int i;
91
+ #endif
121
92
  _siphash_s_digest(digest, argc, argv);
93
+ #if LITTLE_ENDIAN
94
+ for (i = 0; i < 8; i++) {
95
+ roll[i] = digest[7 - i];
96
+ }
97
+ memcpy(digest, roll, 8);
98
+ #endif
122
99
  return ULL2NUM(*(uint64_t *) digest);
123
100
  }
124
101
 
125
102
  void
126
103
  Init_siphash(void)
127
104
  {
128
- VALUE mDigest, cDigest_StringBuffer;
129
-
130
105
  id_DEFAULT_SEED = rb_intern("DEFAULT_SEED");
131
- id_seed = rb_intern("seed");
132
-
133
- /* Digest::SipHash is require that Digest::StringBuffer */
134
- mDigest = rb_path2class("Digest");
135
- cDigest_StringBuffer = rb_path2class("Digest::StringBuffer");
106
+ iv_buffer = rb_intern("@buffer");
107
+ iv_seed = rb_intern("@seed");
136
108
 
137
- /* class Digest::SipHash < Digest::StringBuffer */
138
- cDigest_SipHash = rb_define_class_under(mDigest, "SipHash", cDigest_StringBuffer);
109
+ cDigest_SipHash = rb_path2class("Digest::SipHash");
139
110
  rb_define_private_method(cDigest_SipHash, "finish", siphash_finish, 0);
140
- rb_define_method(cDigest_SipHash, "to_i", siphash_to_i, 0);
141
- rb_define_method(cDigest_SipHash, "seed", siphash_seed_get, 0);
142
- rb_define_method(cDigest_SipHash, "seed=", siphash_seed_set, 1);
143
- rb_define_const(cDigest_SipHash, "DEFAULT_SEED", rb_usascii_str_new(DEFAULT_SEED, 16));
144
111
  rb_define_singleton_method(cDigest_SipHash, "digest", siphash_s_digest, -1);
145
- rb_define_singleton_method(cDigest_SipHash, "hexdigest", siphash_s_hexdigest, -1);
146
112
  rb_define_singleton_method(cDigest_SipHash, "rawdigest", siphash_s_rawdigest, -1);
147
113
  }
@@ -20,49 +20,4 @@
20
20
  # define LITTLE_ENDIAN 0
21
21
  #endif
22
22
 
23
- /* should be same type structure to digest/stringbuffer */
24
- typedef struct {
25
- char* buffer;
26
- char* p;
27
- size_t memsize;
28
- } buffer_t;
29
-
30
- /*
31
- * from https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.c
32
- * Copyright (C) 1995-2001 Yukihiro Matsumoto
33
- * Copyright (C) 2001-2006 Akinori MUSHA
34
- */
35
- static VALUE
36
- hexencode_str_new(VALUE str_digest)
37
- {
38
- char *digest;
39
- size_t digest_len;
40
- size_t i;
41
- VALUE str;
42
- char *p;
43
- static const char hex[] = {
44
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
45
- 'a', 'b', 'c', 'd', 'e', 'f'
46
- };
47
-
48
- StringValue(str_digest);
49
- digest = RSTRING_PTR(str_digest);
50
- digest_len = RSTRING_LEN(str_digest);
51
-
52
- if (LONG_MAX / 2 < digest_len) {
53
- rb_raise(rb_eRuntimeError, "digest string too long");
54
- }
55
-
56
- str = rb_usascii_str_new(0, digest_len * 2);
57
-
58
- for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) {
59
- unsigned char byte = digest[i];
60
-
61
- p[i + i] = hex[byte >> 4];
62
- p[i + i + 1] = hex[byte & 0x0f];
63
- }
64
-
65
- return str;
66
- }
67
-
68
23
  #endif /* ifndef SIPHASH_INCLUDED */
@@ -1,6 +1,29 @@
1
- require "digest/stringbuffer"
2
- begin
3
- require "digest/siphash/#{RUBY_VERSION[/\d+.\d+/]}/siphash"
4
- rescue LoadError
5
- require "digest/siphash/siphash"
1
+ require 'digest'
2
+ require "digest/simple"
3
+
4
+ module Digest
5
+ class SipHash < Simple
6
+ VERSION = "1.0.0"
7
+ DEFAULT_SEED = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".encode('ASCII-8BIT')
8
+
9
+ def initialize
10
+ @seed = DEFAULT_SEED
11
+ super
12
+ end
13
+
14
+ def seed
15
+ @seed
16
+ end
17
+
18
+ def seed=(s)
19
+ fail ArgumentError, "seed string should 128 bit chars" if s.bytesize != 16
20
+ @seed = s
21
+ end
22
+
23
+ def to_i
24
+ finish.unpack("Q")[0]
25
+ end
26
+ end
6
27
  end
28
+
29
+ require "digest/siphash/siphash"
@@ -7,7 +7,7 @@ describe Digest::SipHash do
7
7
  end
8
8
 
9
9
  it "initialize" do
10
- expect(SipHash.new).to be_a_kind_of(StringBuffer)
10
+ expect(SipHash.new).to be_a_kind_of(Digest::Class)
11
11
  end
12
12
 
13
13
  it "DEFAULT_SEED" do
@@ -40,21 +40,21 @@ describe Digest::SipHash do
40
40
  end
41
41
 
42
42
  it "rawdigest" do
43
- expect(SipHash.rawdigest("")).to eq(0x1e924b9d737700d7)
44
- expect(SipHash.rawdigest("", seed)).to eq(0x726fdb47dd0e0e31)
45
- expect(SipHash.rawdigest("\x00", seed)).to eq(0x74f839c593dc67fd)
46
- expect(SipHash.rawdigest("\x00\x01", seed)).to eq(0x0d6c8009d9a94f5a)
43
+ expect(SipHash.rawdigest("")).to eq(0xd70077739d4b921e)
44
+ expect(SipHash.rawdigest("", seed)).to eq(0x310e0edd47db6f72)
45
+ expect(SipHash.rawdigest("\x00", seed)).to eq(0xfd67dc93c539f874)
46
+ expect(SipHash.rawdigest("\x00\x01", seed)).to eq(0x5a4fa9d909806c0d)
47
47
  end
48
48
 
49
49
  it "instance digest" do
50
50
  sip = SipHash.new
51
51
  sip.update ""
52
52
  expect(sip.digest).to eq("\x1e\x92\x4b\x9d\x73\x77\x00\xd7")
53
- expect(sip.to_i).to eq(0x1e924b9d737700d7)
54
-
53
+ expect(sip.to_i).to eq(0xd70077739d4b921e)
54
+
55
55
  sip.seed = seed
56
56
  expect(sip.digest).to eq("\x72\x6f\xdb\x47\xdd\x0e\x0e\x31")
57
- expect(sip.to_i).to eq(0x726fdb47dd0e0e31)
57
+ expect(sip.to_i).to eq(0x310e0edd47db6f72)
58
58
  end
59
59
  end
60
60
 
metadata CHANGED
@@ -1,94 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digest-siphash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-01 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: digest-stringbuffer
14
+ name: digest-simple
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.2
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.2
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2.11'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '2.11'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake-compiler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.8.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.8.3
83
83
  description: Digest::SipHash is a class of message digest use algorithm SipHash.
84
- email: co000ri@gmail.com
84
+ email:
85
+ - co000ri@gmail.com
85
86
  executables: []
86
87
  extensions:
87
88
  - ext/digest/siphash/extconf.rb
88
89
  extra_rdoc_files: []
89
90
  files:
90
- - .gitignore
91
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".travis.yml"
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md
@@ -113,17 +114,17 @@ require_paths:
113
114
  - lib
114
115
  required_ruby_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
- - - '>='
117
+ - - ">="
117
118
  - !ruby/object:Gem::Version
118
119
  version: '0'
119
120
  required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
- - - '>='
122
+ - - ">="
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
126
  rubyforge_project:
126
- rubygems_version: 2.1.11
127
+ rubygems_version: 2.2.0
127
128
  signing_key:
128
129
  specification_version: 4
129
130
  summary: Digest::SipHash is a class of message digest use algorithm SipHash.