rbnacl 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.coveralls.yml +1 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +4 -0
  4. data/.travis.yml +21 -0
  5. data/.yardopts +1 -0
  6. data/CHANGES.md +4 -0
  7. data/Gemfile +9 -0
  8. data/LICENSE.txt +23 -0
  9. data/README.md +179 -0
  10. data/Rakefile +5 -0
  11. data/images/dragons.png +0 -0
  12. data/images/ed25519.png +0 -0
  13. data/images/logo.png +0 -0
  14. data/lib/rbnacl.rb +46 -0
  15. data/lib/rbnacl/auth.rb +78 -0
  16. data/lib/rbnacl/auth/one_time.rb +38 -0
  17. data/lib/rbnacl/box.rb +141 -0
  18. data/lib/rbnacl/encoder.rb +44 -0
  19. data/lib/rbnacl/encoders/base32.rb +33 -0
  20. data/lib/rbnacl/encoders/base64.rb +30 -0
  21. data/lib/rbnacl/encoders/hex.rb +30 -0
  22. data/lib/rbnacl/encoders/raw.rb +12 -0
  23. data/lib/rbnacl/hash.rb +48 -0
  24. data/lib/rbnacl/hmac/sha256.rb +32 -0
  25. data/lib/rbnacl/hmac/sha512256.rb +35 -0
  26. data/lib/rbnacl/keys/key_comparator.rb +59 -0
  27. data/lib/rbnacl/keys/private_key.rb +62 -0
  28. data/lib/rbnacl/keys/public_key.rb +38 -0
  29. data/lib/rbnacl/keys/signing_key.rb +74 -0
  30. data/lib/rbnacl/keys/verify_key.rb +76 -0
  31. data/lib/rbnacl/nacl.rb +132 -0
  32. data/lib/rbnacl/point.rb +67 -0
  33. data/lib/rbnacl/rake_tasks.rb +56 -0
  34. data/lib/rbnacl/random.rb +19 -0
  35. data/lib/rbnacl/random_nonce_box.rb +109 -0
  36. data/lib/rbnacl/secret_box.rb +86 -0
  37. data/lib/rbnacl/self_test.rb +118 -0
  38. data/lib/rbnacl/serializable.rb +23 -0
  39. data/lib/rbnacl/test_vectors.rb +69 -0
  40. data/lib/rbnacl/util.rb +137 -0
  41. data/lib/rbnacl/version.rb +5 -0
  42. data/rbnacl.gemspec +28 -0
  43. data/rbnacl.gpg +30 -0
  44. data/spec/rbnacl/auth/one_time_spec.rb +8 -0
  45. data/spec/rbnacl/box_spec.rb +42 -0
  46. data/spec/rbnacl/encoder_spec.rb +14 -0
  47. data/spec/rbnacl/encoders/base32_spec.rb +16 -0
  48. data/spec/rbnacl/encoders/base64_spec.rb +15 -0
  49. data/spec/rbnacl/encoders/hex_spec.rb +15 -0
  50. data/spec/rbnacl/hash_spec.rb +52 -0
  51. data/spec/rbnacl/hmac/sha256_spec.rb +8 -0
  52. data/spec/rbnacl/hmac/sha512256_spec.rb +8 -0
  53. data/spec/rbnacl/keys/private_key_spec.rb +68 -0
  54. data/spec/rbnacl/keys/public_key_spec.rb +45 -0
  55. data/spec/rbnacl/keys/signing_key_spec.rb +40 -0
  56. data/spec/rbnacl/keys/verify_key_spec.rb +51 -0
  57. data/spec/rbnacl/point_spec.rb +29 -0
  58. data/spec/rbnacl/random_nonce_box_spec.rb +78 -0
  59. data/spec/rbnacl/random_spec.rb +9 -0
  60. data/spec/rbnacl/secret_box_spec.rb +24 -0
  61. data/spec/rbnacl/util_spec.rb +119 -0
  62. data/spec/shared/authenticator.rb +114 -0
  63. data/spec/shared/box.rb +51 -0
  64. data/spec/shared/key_equality.rb +26 -0
  65. data/spec/spec_helper.rb +14 -0
  66. data/tasks/ci.rake +11 -0
  67. data/tasks/rspec.rake +7 -0
  68. metadata +187 -0
@@ -0,0 +1,51 @@
1
+ # encoding: binary
2
+
3
+ require 'spec_helper'
4
+
5
+ shared_examples "box" do
6
+ let(:nonce) { hex2bytes(Crypto::TestVectors[:box_nonce]) }
7
+ let(:invalid_nonce) { nonce[0,12] } # too short!
8
+ let(:invalid_nonce_long) { nonce + nonce } # too long!
9
+ let(:message) { hex2bytes(Crypto::TestVectors[:box_message]) }
10
+ let(:ciphertext) { hex2bytes(Crypto::TestVectors[:box_ciphertext]) }
11
+ let (:nonce_error_regex) { /Nonce.*(Expected #{Crypto::NaCl::NONCEBYTES})/ }
12
+ let(:corrupt_ciphertext) { ciphertext[80] = " " } # picked at random by fair diceroll
13
+
14
+ context "box" do
15
+
16
+ it "encrypts a message" do
17
+ box.box(nonce, message).should eq ciphertext
18
+ end
19
+
20
+ it "raises on a short nonce" do
21
+ expect { box.box(invalid_nonce, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
22
+ end
23
+
24
+ it "raises on a long nonce" do
25
+ expect { box.box(invalid_nonce_long, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
26
+ end
27
+ end
28
+
29
+ context "open" do
30
+
31
+ it "decrypts a message" do
32
+ box.open(nonce, ciphertext).should eq message
33
+ end
34
+
35
+ it "raises on a truncated message to decrypt" do
36
+ expect { box.open(nonce, ciphertext[0, 64]) }.to raise_error(Crypto::CryptoError, /Decryption failed. Ciphertext failed verification./)
37
+ end
38
+
39
+ it "raises on a corrupt ciphertext" do
40
+ expect { box.open(nonce, corrupt_ciphertext) }.to raise_error(Crypto::CryptoError, /Decryption failed. Ciphertext failed verification./)
41
+ end
42
+
43
+ it "raises on a short nonce" do
44
+ expect { box.open(invalid_nonce, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
45
+ end
46
+
47
+ it "raises on a long nonce" do
48
+ expect { box.open(invalid_nonce_long, message) }.to raise_error(Crypto::LengthError, nonce_error_regex)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: binary
2
+ shared_examples "key equality" do
3
+ context "equality" do
4
+ it "equal keys are equal" do
5
+ (described_class.new(key_bytes) == key).should be true
6
+ end
7
+ it "equal keys are equal to the string" do
8
+ (key == key_bytes).should be true
9
+ end
10
+ it "keys are not equal to zero" do
11
+ (key == Crypto::Util.zeros(32)).should be false
12
+ end
13
+ it "keys are not equal to another key" do
14
+ (key == other_key).should be false
15
+ end
16
+ end
17
+
18
+ context "lexicographic sorting" do
19
+ it "can be compared lexicographically to a key smaller than it" do
20
+ (key > Crypto::Util.zeros(32)).should be true
21
+ end
22
+ it "can be compared lexicographically to a key larger than it" do
23
+ (described_class.new(Crypto::Util.zeros(32)) < key).should be true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: binary
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'rbnacl'
5
+ require 'shared/box'
6
+ require 'shared/authenticator'
7
+ require 'shared/key_equality'
8
+ require 'coveralls'
9
+
10
+ Coveralls.wear!
11
+
12
+ def hex2bytes(hex)
13
+ Crypto::Encoder[:hex].decode(hex)
14
+ end
@@ -0,0 +1,11 @@
1
+ require "rake/clean"
2
+
3
+ file "lib/libsodium.so" => :build_libsodium do
4
+ cp $LIBSODIUM_PATH, "lib/libsodium.so"
5
+ end
6
+
7
+ task "ci:sodium" => "lib/libsodium.so"
8
+
9
+ task :ci => %w(ci:sodium spec)
10
+
11
+ CLEAN.add "lib/libsodium.*"
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbnacl
3
+ version: !ruby/object:Gem::Version
4
+ version: !binary |-
5
+ MS4wLjAucHJl
6
+ prerelease: 6
7
+ platform: ruby
8
+ authors:
9
+ - Tony Arcieri
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-03-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ffi
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ description: Ruby binding to the Networking and Cryptography (NaCl) library
64
+ email:
65
+ - tony.arcieri@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .coveralls.yml
71
+ - .gitignore
72
+ - .rspec
73
+ - .travis.yml
74
+ - .yardopts
75
+ - CHANGES.md
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - images/dragons.png
81
+ - images/ed25519.png
82
+ - images/logo.png
83
+ - lib/rbnacl.rb
84
+ - lib/rbnacl/auth.rb
85
+ - lib/rbnacl/auth/one_time.rb
86
+ - lib/rbnacl/box.rb
87
+ - lib/rbnacl/encoder.rb
88
+ - lib/rbnacl/encoders/base32.rb
89
+ - lib/rbnacl/encoders/base64.rb
90
+ - lib/rbnacl/encoders/hex.rb
91
+ - lib/rbnacl/encoders/raw.rb
92
+ - lib/rbnacl/hash.rb
93
+ - lib/rbnacl/hmac/sha256.rb
94
+ - lib/rbnacl/hmac/sha512256.rb
95
+ - lib/rbnacl/keys/key_comparator.rb
96
+ - lib/rbnacl/keys/private_key.rb
97
+ - lib/rbnacl/keys/public_key.rb
98
+ - lib/rbnacl/keys/signing_key.rb
99
+ - lib/rbnacl/keys/verify_key.rb
100
+ - lib/rbnacl/nacl.rb
101
+ - lib/rbnacl/point.rb
102
+ - lib/rbnacl/rake_tasks.rb
103
+ - lib/rbnacl/random.rb
104
+ - lib/rbnacl/random_nonce_box.rb
105
+ - lib/rbnacl/secret_box.rb
106
+ - lib/rbnacl/self_test.rb
107
+ - lib/rbnacl/serializable.rb
108
+ - lib/rbnacl/test_vectors.rb
109
+ - lib/rbnacl/util.rb
110
+ - lib/rbnacl/version.rb
111
+ - rbnacl.gemspec
112
+ - rbnacl.gpg
113
+ - spec/rbnacl/auth/one_time_spec.rb
114
+ - spec/rbnacl/box_spec.rb
115
+ - spec/rbnacl/encoder_spec.rb
116
+ - spec/rbnacl/encoders/base32_spec.rb
117
+ - spec/rbnacl/encoders/base64_spec.rb
118
+ - spec/rbnacl/encoders/hex_spec.rb
119
+ - spec/rbnacl/hash_spec.rb
120
+ - spec/rbnacl/hmac/sha256_spec.rb
121
+ - spec/rbnacl/hmac/sha512256_spec.rb
122
+ - spec/rbnacl/keys/private_key_spec.rb
123
+ - spec/rbnacl/keys/public_key_spec.rb
124
+ - spec/rbnacl/keys/signing_key_spec.rb
125
+ - spec/rbnacl/keys/verify_key_spec.rb
126
+ - spec/rbnacl/point_spec.rb
127
+ - spec/rbnacl/random_nonce_box_spec.rb
128
+ - spec/rbnacl/random_spec.rb
129
+ - spec/rbnacl/secret_box_spec.rb
130
+ - spec/rbnacl/util_spec.rb
131
+ - spec/shared/authenticator.rb
132
+ - spec/shared/box.rb
133
+ - spec/shared/key_equality.rb
134
+ - spec/spec_helper.rb
135
+ - tasks/ci.rake
136
+ - tasks/rspec.rake
137
+ homepage: https://github.com/tarcieri/rbnacl
138
+ licenses: []
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ segments:
150
+ - 0
151
+ hash: 3830560762407570994
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>'
156
+ - !ruby/object:Gem::Version
157
+ version: 1.3.1
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 1.8.25
161
+ signing_key:
162
+ specification_version: 3
163
+ summary: The Networking and Cryptography (NaCl) library provides a high-level toolkit
164
+ for building cryptographic systems and protocols
165
+ test_files:
166
+ - spec/rbnacl/auth/one_time_spec.rb
167
+ - spec/rbnacl/box_spec.rb
168
+ - spec/rbnacl/encoder_spec.rb
169
+ - spec/rbnacl/encoders/base32_spec.rb
170
+ - spec/rbnacl/encoders/base64_spec.rb
171
+ - spec/rbnacl/encoders/hex_spec.rb
172
+ - spec/rbnacl/hash_spec.rb
173
+ - spec/rbnacl/hmac/sha256_spec.rb
174
+ - spec/rbnacl/hmac/sha512256_spec.rb
175
+ - spec/rbnacl/keys/private_key_spec.rb
176
+ - spec/rbnacl/keys/public_key_spec.rb
177
+ - spec/rbnacl/keys/signing_key_spec.rb
178
+ - spec/rbnacl/keys/verify_key_spec.rb
179
+ - spec/rbnacl/point_spec.rb
180
+ - spec/rbnacl/random_nonce_box_spec.rb
181
+ - spec/rbnacl/random_spec.rb
182
+ - spec/rbnacl/secret_box_spec.rb
183
+ - spec/rbnacl/util_spec.rb
184
+ - spec/shared/authenticator.rb
185
+ - spec/shared/box.rb
186
+ - spec/shared/key_equality.rb
187
+ - spec/spec_helper.rb