gibberish 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ ### v1.2.0
2
+ * Added digest support for SHA224/384 and HMAC SHA224/384/512. [Pull request #5](https://github.com/mdp/gibberish/pull/5)
3
+
1
4
  ### v1.1.0
2
5
 
3
- Add SHA512 support
6
+ * Add SHA512 support
@@ -59,11 +59,16 @@ Gibberish AES is fully compatible with default OpenSSL on the command line
59
59
 
60
60
  ## HMAC
61
61
 
62
- Defaults to 128 bit digest
62
+ Defaults to 128 bit digest and SHA1
63
63
 
64
64
  Gibberish::HMAC("key", "some data")
65
65
  #=> 521677c580722c5c52fa15d978e8656341c4f3c5
66
66
 
67
+ Other digests can be used
68
+
69
+ Gibberish::HMAC("key", "some data", :digest => :sha256)
70
+ #=> 01add3f98ce4d49403d98362a046c6cca2c79d778426282c53e4f628f648c12b
71
+
67
72
  [Find out more](http://mdp.github.com/gibberish/Gibberish/HMAC.html)
68
73
 
69
74
  ## Digests
@@ -74,9 +79,15 @@ Defaults to 128 bit digest
74
79
  Gibberish::SHA1("somedata")
75
80
  #=> efaa311ae448a7374c122061bfed952d940e9e37
76
81
 
82
+ Gibberish::SHA224("somedata")
83
+ #=> a39b86d838273f5ff4879c26f85e3cb333bb44d73b24f275bad1a6c6
84
+
77
85
  Gibberish::SHA256("somedata")
78
86
  #=> 87d149cb424c0387656f211d2589fb5b1e16229921309e98588419ccca8a7362
79
87
 
88
+ Gibberish::SHA384("somedata")
89
+ #=> b6800736973cc061e3efb66a34f8bda8fa946804c6cc4f26a6b9b3950211078801709d0d82707c569a07c8f63c804c87
90
+
80
91
  Gibberish::SHA512("somedata")
81
92
  #=> a053441b6de662599ecb14c580d6637dcb856a66b2a40a952d39df772e47e98ea22f9e105b31463c5cf2472feae7649464fe89d99ceb6b0bc398a6926926f416
82
93
 
@@ -5,20 +5,26 @@ module Gibberish
5
5
  #
6
6
  # Gibberish::MD5("data") #=> 8d777f385d3dfec8815d20f7496026dc
7
7
  # Gibberish::SHA1("data") #=> a17c9aaa61e80a1bf71d0d850af4e5baa9800bbd
8
+ # Gibberish::SHA224("data") #=> f4739673acc03c424343b452787ee23dd62999a8a9f14f4250995769
8
9
  # Gibberish::SHA256("data") #=> 3a6eb0790f39ac87c94f3856b2dd2c5d110e6811602261a9a923d3bb23adc8b7
10
+ # Gibberish::SHA384("data") #=> 2039e0f0b92728499fb88e23ebc3cfd0554b28400b0ed7b753055c88b5865c3c2aa72c6a1a9ae0a755d87900a4a6ff41
9
11
  # Gibberish::SHA512("data") #=> 77c7ce9a5d86bb386d443bb96390faa120633158699c8844c30b13ab0bf92760b7e4416aea397db91b4ac0e5dd56b8ef7e4b066162ab1fdc088319ce6defc876
10
12
  #
11
13
  # ## OpenSSL CLI Interop
12
14
  #
13
15
  # echo -n 'data' | openssl dgst -sha1
16
+ # echo -n 'data' | openssl dgst -sha224
14
17
  # echo -n 'data' | openssl dgst -sha256
18
+ # echo -n 'data' | openssl dgst -sha384
15
19
  # echo -n 'data' | openssl dgst -sha512
16
20
  # echo -n 'data' | openssl dgst -md5
17
21
  #
18
22
  # is the same as
19
23
  #
20
24
  # Gibberish::SHA1("data")
25
+ # Gibberish::SHA224("data")
21
26
  # Gibberish::SHA256("data")
27
+ # Gibberish::SHA384("data")
22
28
  # Gibberish::SHA512("data")
23
29
  # Gibberish::MD5("data")
24
30
  #
@@ -41,6 +47,23 @@ module Gibberish
41
47
  end
42
48
  end
43
49
 
50
+ # Returns the SHA224 digest for the data
51
+ #
52
+ # Shorcut alias: Gibberish::SHA224(data)
53
+ #
54
+ # @param [String] key
55
+ # @param [#to_s] data
56
+ # @param [Hash] options
57
+ # @option opts [Boolean] :binary (false) encode the data in binary, not Base64
58
+ def self.sha224(data, opts={})
59
+ data = data.to_s
60
+ if opts[:binary]
61
+ OpenSSL::Digest::SHA224.digest(data)
62
+ else
63
+ OpenSSL::Digest::SHA224.hexdigest(data)
64
+ end
65
+ end
66
+
44
67
  # Returns the SHA256 digest for the data
45
68
  #
46
69
  # Shorcut alias: Gibberish::SHA256(data)
@@ -58,6 +81,23 @@ module Gibberish
58
81
  end
59
82
  end
60
83
 
84
+ # Returns the SHA384 digest for the data
85
+ #
86
+ # Shorcut alias: Gibberish::SHA384(data)
87
+ #
88
+ # @param [String] key
89
+ # @param [#to_s] data
90
+ # @param [Hash] options
91
+ # @option opts [Boolean] :binary (false) encode the data in binary, not Base64
92
+ def self.sha384(data, opts={})
93
+ data = data.to_s
94
+ if opts[:binary]
95
+ OpenSSL::Digest::SHA384.digest(data)
96
+ else
97
+ OpenSSL::Digest::SHA384.hexdigest(data)
98
+ end
99
+ end
100
+
61
101
  # Returns the SHA512 digest for the data
62
102
  #
63
103
  # Shorcut alias: Gibberish::SHA512(data)
@@ -97,10 +137,18 @@ module Gibberish
97
137
  Digest.sha1(data,opts)
98
138
  end
99
139
 
140
+ def self.SHA224(data, opts={})
141
+ Digest.sha224(data,opts)
142
+ end
143
+
100
144
  def self.SHA256(data, opts={})
101
145
  Digest.sha256(data,opts)
102
146
  end
103
147
 
148
+ def self.SHA384(data, opts={})
149
+ Digest.sha384(data,opts)
150
+ end
151
+
104
152
  def self.SHA512(data, opts={})
105
153
  Digest.sha512(data,opts)
106
154
  end
@@ -4,8 +4,16 @@ module Gibberish
4
4
  # ## Example
5
5
  #
6
6
  # Gibberish::HMAC('key', 'data') #=> 104152c5bfdca07bc633eebd46199f0255c9f49d
7
+ # Gibberish::HMAC('key', 'data', :digest => :sha224)
8
+ # #=> 19424d4210e50d7a4521b5f0d54b4b0cff3060deddccfd894fda5b3b
7
9
  # Gibberish::HMAC('key', 'data', :digest => :sha256)
8
10
  # #=> 5031fe3d989c6d1537a013fa6e739da23463fdaec3b70137d828e36ace221bd0
11
+ # Gibberish::HMAC('key', 'data', :digest => :sha384)
12
+ # #=> c5f97ad9fd1020c174d7dc02cf83c4c1bf15ee20ec555b690ad58e62da8a00ee
13
+ # 44ccdb65cb8c80acfd127ebee568958a
14
+ # Gibberish::HMAC('key', 'data', :digest => :sha512)
15
+ # #=> 3c5953a18f7303ec653ba170ae334fafa08e3846f2efe317b87efce82376253c
16
+ # b52a8c31ddcde5a3a2eee183c2b34cb91f85e64ddbc325f7692b199473579c58
9
17
  #
10
18
  # ## OpenSSL CLI Interop
11
19
  #
@@ -18,7 +26,10 @@ module Gibberish
18
26
  class HMAC
19
27
  DIGEST = {
20
28
  :sha1 => OpenSSL::Digest::Digest.new('sha1'),
21
- :sha256 => OpenSSL::Digest::Digest.new('sha256')
29
+ :sha224 => OpenSSL::Digest::Digest.new('sha224'),
30
+ :sha256 => OpenSSL::Digest::Digest.new('sha256'),
31
+ :sha384 => OpenSSL::Digest::Digest.new('sha384'),
32
+ :sha512 => OpenSSL::Digest::Digest.new('sha512')
22
33
  }
23
34
 
24
35
  # Returns the HMAC for the key and data
@@ -1,3 +1,3 @@
1
1
  module Gibberish
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -10,10 +10,18 @@ describe "A variety of digest methods" do
10
10
  Gibberish::SHA1("password").must_equal("5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8")
11
11
  end
12
12
 
13
+ it "should work with SHA224" do
14
+ Gibberish::SHA224("password").must_equal("d63dc919e201d7bc4c825630d2cf25fdc93d4b2f0d46706d29038d01")
15
+ end
16
+
13
17
  it "should work with SHA256" do
14
18
  Gibberish::SHA256("password").must_equal("5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8")
15
19
  end
16
20
 
21
+ it "should work with SHA384" do
22
+ Gibberish::SHA384("password").must_equal("a8b64babd0aca91a59bdbb7761b421d4f2bb38280d3a75ba0f21f2bebc45583d446c598660c94ce680c47d19c30783a7")
23
+ end
24
+
17
25
  it "should work with SHA512" do
18
26
  Gibberish::SHA512("password").must_equal("b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86")
19
27
  end
@@ -12,4 +12,47 @@ describe "HMAC" do
12
12
  hmac.must_equal(o_hmac.chomp)
13
13
  end
14
14
 
15
+ it "should hopefully work for sha224" do
16
+ Gibberish::HMAC("password", "data", :digest => :sha224).must_equal(
17
+ "f66aa39e91d003f7d3fc1205f77bd4947af51735a49e197fbd478728")
18
+ end
19
+
20
+ it "should work with OpenSSL HMAC for sha224" do
21
+ hmac = Gibberish::HMAC("password", "data\n", :digest => :sha224)
22
+ o_hmac = `echo "data" | openssl dgst -sha224 -hmac 'password'`
23
+ hmac.must_equal(o_hmac.chomp)
24
+ end
25
+
26
+ it "should hopefully work for sha256" do
27
+ Gibberish::HMAC("password", "data", :digest => :sha256).must_equal(
28
+ "cccf6f0334130a7010d62332c75b53e7d8cea715e52692b06e9cd41b05644be3")
29
+ end
30
+
31
+ it "should work with OpenSSL HMAC for sha256" do
32
+ hmac = Gibberish::HMAC("password", "data\n", :digest => :sha256)
33
+ o_hmac = `echo "data" | openssl dgst -sha256 -hmac 'password'`
34
+ hmac.must_equal(o_hmac.chomp)
35
+ end
36
+
37
+ it "should hopefully work for sha384" do
38
+ Gibberish::HMAC("password", "data", :digest => :sha384).must_equal(
39
+ "2ed475691214fb85d086577d8d525c609b92520ebd793a74856b3ffd8d3477eaaf0b06ef9e06c8aa81cf29f95078aca6")
40
+ end
41
+
42
+ it "should work with OpenSSL HMAC for sha384" do
43
+ hmac = Gibberish::HMAC("password", "data\n", :digest => :sha384)
44
+ o_hmac = `echo "data" | openssl dgst -sha384 -hmac 'password'`
45
+ hmac.must_equal(o_hmac.chomp)
46
+ end
47
+
48
+ it "should hopefully work for sha512" do
49
+ Gibberish::HMAC("password", "data", :digest => :sha512).must_equal("abf85192282b501874f4803ea08672f2c9d6e656c57801023a0b1f4dd9492ba960efdb560a8618ec783327d6dc31577422651a4cf7eaf722d2caefbc04038c6e")
50
+ end
51
+
52
+ it "should work with OpenSSL HMAC for sha512" do
53
+ hmac = Gibberish::HMAC("password", "data\n", :digest => :sha512)
54
+ o_hmac = `echo "data" | openssl dgst -sha512 -hmac 'password'`
55
+ hmac.must_equal(o_hmac.chomp)
56
+ end
57
+
15
58
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gibberish
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mark Percival
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-12 00:00:00 -08:00
18
+ date: 2011-12-09 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21