rbnacl 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,17 +2,17 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Crypto::PublicKey do
5
- let(:alicepk) { Crypto::TestVectors[:alice_public] }
6
- let(:alicepk_raw) { Crypto::Encoder[:hex].decode(alicepk) }
5
+ let(:alicepk) { test_vector :alice_public }
6
+ let(:alicepk_hex) { bytes2hex alicepk }
7
7
 
8
- subject { Crypto::PublicKey.new(alicepk, :hex) }
8
+ subject { Crypto::PublicKey.new(alicepk) }
9
9
 
10
10
  context "new" do
11
11
  it "accepts a valid key" do
12
- expect { Crypto::PublicKey.new(alicepk_raw) }.not_to raise_error
12
+ expect { Crypto::PublicKey.new(alicepk) }.not_to raise_error
13
13
  end
14
14
  it "accepts a valid key in hex" do
15
- expect { Crypto::PublicKey.new(alicepk, :hex) }.not_to raise_error
15
+ expect { Crypto::PublicKey.new(alicepk_hex, :hex) }.not_to raise_error
16
16
  end
17
17
  it "rejects a nil key" do
18
18
  expect { Crypto::PublicKey.new(nil) }.to raise_error(ArgumentError)
@@ -24,22 +24,22 @@ describe Crypto::PublicKey do
24
24
 
25
25
  context "#to_bytes" do
26
26
  it "returns the bytes of the key" do
27
- subject.to_bytes.should eq alicepk_raw
27
+ subject.to_bytes.should eq alicepk
28
28
  end
29
29
  end
30
30
 
31
31
  context "#to_s" do
32
32
  it "returns the bytes of the key" do
33
- subject.to_s.should eq alicepk_raw
33
+ subject.to_s.should eq alicepk
34
34
  end
35
35
  it "returns the bytes of the key hex encoded" do
36
- subject.to_s(:hex).should eq alicepk
36
+ subject.to_s(:hex).should eq alicepk_hex
37
37
  end
38
38
  end
39
-
39
+
40
40
  include_examples "key equality" do
41
41
  let(:key) { subject }
42
42
  let(:key_bytes) { subject.to_bytes }
43
- let(:other_key) { described_class.new(alicepk_raw.succ) }
43
+ let(:other_key) { described_class.new(alicepk.succ) }
44
44
  end
45
45
  end
@@ -2,38 +2,37 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Crypto::SigningKey do
5
- let(:signing_key) { Crypto::TestVectors[:sign_private] }
6
- let(:signing_key_raw) { Crypto::Encoder[:hex].decode(signing_key) }
5
+ let(:signing_key_hex) { hex_vector :sign_private }
6
+ let(:signing_key) { hex2bytes signing_key_hex }
7
7
 
8
- let(:message) { Crypto::Encoder[:hex].decode(Crypto::TestVectors[:sign_message]) }
9
- let(:signature) { Crypto::TestVectors[:sign_signature] }
10
- let(:signature_raw) { Crypto::Encoder[:hex].decode(signature) }
8
+ let(:message) { test_vector :sign_message }
9
+ let(:signature) { test_vector :sign_signature }
11
10
 
12
11
  # NOTE: this implicitly covers testing initialization from bytes
13
- subject { described_class.new(signing_key, :hex) }
12
+ subject { described_class.new(signing_key_hex, :hex) }
14
13
 
15
14
  it "generates keys" do
16
15
  described_class.generate.should be_a described_class
17
16
  end
18
17
 
19
18
  it "signs messages as bytes" do
20
- subject.sign(message).should eq signature_raw
19
+ subject.sign(message).should eq signature
21
20
  end
22
21
 
23
22
  it "signs messages as hex" do
24
- subject.sign(message, :hex).should eq signature
23
+ subject.sign(message, :hex).should eq bytes2hex signature
25
24
  end
26
25
 
27
26
  it "serializes to hex" do
28
- subject.to_s(:hex).should eq signing_key
27
+ subject.to_s(:hex).should eq signing_key_hex
29
28
  end
30
29
 
31
30
  it "serializes to bytes" do
32
- subject.to_bytes.should eq signing_key_raw
31
+ subject.to_bytes.should eq signing_key
33
32
  end
34
-
33
+
35
34
  include_examples "key equality" do
36
- let(:key_bytes) { signing_key_raw }
35
+ let(:key_bytes) { signing_key }
37
36
  let(:key) { described_class.new(key_bytes) }
38
37
  let(:other_key) { described_class.new("B"*32) }
39
38
  end
@@ -1,12 +1,12 @@
1
1
  # encoding: binary
2
2
  describe Crypto::VerifyKey do
3
- let(:signing_key) { Crypto::TestVectors[:sign_private] }
4
- let(:verify_key) { Crypto::TestVectors[:sign_public] }
5
- let(:verify_key_raw) { Crypto::Encoder[:hex].decode(verify_key) }
3
+ let(:signing_key) { hex_vector :sign_private }
4
+ let(:verify_key) { hex_vector :sign_public }
5
+ let(:verify_key_raw) { hex2bytes verify_key }
6
6
 
7
- let(:message) { Crypto::Encoder[:hex].decode(Crypto::TestVectors[:sign_message]) }
8
- let(:signature) { Crypto::TestVectors[:sign_signature] }
9
- let(:signature_raw) { Crypto::Encoder[:hex].decode(signature) }
7
+ let(:message) { test_vector :sign_message }
8
+ let(:signature) { hex_vector :sign_signature }
9
+ let(:signature_raw) { hex2bytes signature }
10
10
  let(:bad_signature) { sig = signature.dup; sig[0] = (sig[0].ord + 1).chr; sig }
11
11
 
12
12
  subject { Crypto::SigningKey.new(signing_key, :hex).verify_key }
@@ -2,28 +2,28 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Crypto::Point do
5
- let(:alice_private) { Crypto::TestVectors[:alice_private] }
6
- let(:alice_public) { Crypto::TestVectors[:alice_public] }
5
+ let(:alice_private) { test_vector :alice_private }
6
+ let(:alice_public) { test_vector :alice_public }
7
7
 
8
- let(:bob_public) { Crypto::TestVectors[:bob_public] }
8
+ let(:bob_public) { test_vector :bob_public }
9
9
 
10
- let(:alice_mult_bob) { Crypto::TestVectors[:alice_mult_bob] }
10
+ let(:alice_mult_bob) { test_vector :alice_mult_bob }
11
11
 
12
- subject { described_class.new(bob_public, :hex) }
12
+ subject { described_class.new(bob_public) }
13
13
 
14
14
  it "multiplies integers with the base point" do
15
- described_class.base.mult(alice_private, :hex).to_s(:hex).should eq alice_public
15
+ described_class.base.mult(alice_private).to_s.should eq alice_public
16
16
  end
17
17
 
18
18
  it "multiplies integers with arbitrary points" do
19
- described_class.new(bob_public, :hex).mult(alice_private, :hex).to_s(:hex).should eq alice_mult_bob
19
+ described_class.new(bob_public).mult(alice_private).to_s.should eq alice_mult_bob
20
20
  end
21
21
 
22
22
  it "serializes to bytes" do
23
- subject.to_bytes.should eq Crypto::Encoder[:hex].decode(bob_public)
23
+ subject.to_bytes.should eq bob_public
24
24
  end
25
25
 
26
26
  it "serializes to hex" do
27
- subject.to_s(:hex).should eq bob_public
27
+ subject.to_s(:hex).should eq bytes2hex bob_public
28
28
  end
29
- end
29
+ end
@@ -2,13 +2,10 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Crypto::RandomNonceBox do
5
- let (:secret_key) {
6
- [0x1b,0x27,0x55,0x64,0x73,0xe9,0x85,0xd4,0x62,0xcd,0x51,0x19,0x7a,0x9a,0x46,0xc7,
7
- 0x60,0x09,0x54,0x9e,0xac,0x64,0x74,0xf2,0x06,0xc4,0xee,0x08,0x44,0xf6,0x83,0x89].pack('c*')
8
- } # from the nacl distribution
5
+ let (:secret_key) { test_vector :secret_key }
9
6
  let(:secret_box) { Crypto::SecretBox.new(secret_key) }
10
- let (:alicepk) { "\x85 \xF0\t\x890\xA7Tt\x8B}\xDC\xB4>\xF7Z\r\xBF:\r&8\x1A\xF4\xEB\xA4\xA9\x8E\xAA\x9BNj" } # from the nacl distribution
11
- let (:bobsk) { "]\xAB\b~bJ\x8AKy\xE1\x7F\x8B\x83\x80\x0E\xE6o;\xB1)&\x18\xB6\xFD\x1C/\x8B'\xFF\x88\xE0\xEB" } # from the nacl distribution
7
+ let (:alicepk) { test_vector :alice_public }
8
+ let (:bobsk) { test_vector :bob_private }
12
9
 
13
10
  context "instantiation" do
14
11
  it "can be instantiated from an already existing box" do
@@ -32,30 +29,9 @@ describe Crypto::RandomNonceBox do
32
29
 
33
30
 
34
31
  context "cryptography" do
35
- let(:nonce) { "iin\xE9U\xB6+s\xCDb\xBD\xA8u\xFCs\xD6\x82\x19\xE0\x03kz\v7" } # from nacl distribution
36
- let(:message) { # from nacl distribution
37
- [0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5,0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b,
38
- 0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4,0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc,
39
- 0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a,0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29,
40
- 0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4,0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31,
41
- 0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d,0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57,
42
- 0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a,0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde,
43
- 0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd,0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52,
44
- 0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64,
45
- 0x5e,0x07,0x05].pack('c*')
46
- }
47
- let(:ciphertext) { # from nacl distribution
48
- [0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9,
49
- 0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce,
50
- 0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a,
51
- 0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72,
52
- 0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38,
53
- 0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae,
54
- 0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda,
55
- 0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3,
56
- 0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74,
57
- 0xe3,0x55,0xa5].pack('c*')
58
- }
32
+ let(:nonce) { test_vector :box_nonce }
33
+ let(:message) { test_vector :box_message }
34
+ let(:ciphertext) { test_vector :box_ciphertext }
59
35
  let(:random_box) { Crypto::RandomNonceBox.from_keypair(alicepk, bobsk) }
60
36
  let(:enciphered_message) { random_box.box(message) }
61
37
  let(:enciphered_message_hex) { random_box.box(message, :hex) }
@@ -2,11 +2,11 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Crypto::SecretBox do
5
- let (:key) { Crypto::TestVectors[:secret_key] }
5
+ let (:key) { test_vector :secret_key }
6
6
 
7
7
  context "new" do
8
8
  it "accepts strings" do
9
- expect { Crypto::SecretBox.new(key, :hex) }.to_not raise_error(Exception)
9
+ expect { Crypto::SecretBox.new(key) }.to_not raise_error(Exception)
10
10
  end
11
11
 
12
12
  it "raises on a nil key" do
@@ -19,6 +19,6 @@ describe Crypto::SecretBox do
19
19
  end
20
20
 
21
21
  include_examples "box" do
22
- let(:box) { Crypto::SecretBox.new(key, :hex) }
22
+ let(:box) { Crypto::SecretBox.new(key) }
23
23
  end
24
24
  end
@@ -1,10 +1,10 @@
1
1
  # encoding: binary
2
2
  shared_examples "authenticator" do
3
- let (:hex_key) { Crypto::TestVectors[:auth_key] }
4
- let (:key) { Crypto::Encoder[:hex].decode(hex_key) }
5
- let (:message) { Crypto::Encoder[:hex].decode(Crypto::TestVectors[:auth_message]) }
6
- let(:tag) { Crypto::Encoder[:hex].decode(hex_tag) }
7
-
3
+ let (:hex_key) { hex_vector :auth_key }
4
+ let (:key) { test_vector :auth_key }
5
+ let (:message) { test_vector :auth_message }
6
+ let (:tag) { hex2bytes hex_tag }
7
+
8
8
  context ".new" do
9
9
  it "accepts a key" do
10
10
  expect { described_class.new(key) }.to_not raise_error(ArgumentError)
data/spec/shared/box.rb CHANGED
@@ -3,11 +3,11 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  shared_examples "box" do
6
- let(:nonce) { hex2bytes(Crypto::TestVectors[:box_nonce]) }
6
+ let(:nonce) { test_vector :box_nonce }
7
7
  let(:invalid_nonce) { nonce[0,12] } # too short!
8
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]) }
9
+ let(:message) { test_vector :box_message }
10
+ let(:ciphertext) { test_vector :box_ciphertext }
11
11
  let (:nonce_error_regex) { /Nonce.*(Expected #{Crypto::NaCl::NONCEBYTES})/ }
12
12
  let(:corrupt_ciphertext) { ciphertext[80] = " " } # picked at random by fair diceroll
13
13
 
data/spec/spec_helper.rb CHANGED
@@ -12,3 +12,15 @@ Coveralls.wear!
12
12
  def hex2bytes(hex)
13
13
  Crypto::Encoder[:hex].decode(hex)
14
14
  end
15
+
16
+ def bytes2hex(bytes)
17
+ Crypto::Encoder[:hex].encode(bytes)
18
+ end
19
+
20
+ def test_vector(name)
21
+ hex2bytes(hex_vector(name))
22
+ end
23
+
24
+ def hex_vector(name)
25
+ Crypto::TestVectors[name]
26
+ end
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbnacl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
+ - Jonathan Stott
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain:
@@ -30,7 +31,7 @@ cert_chain:
30
31
  3L/NVZQttSvxjd+WF6mA9yeCjpomboQMP36GRIZ30SoOVPMGvZ/+QpW52QU7mJW5
31
32
  GzWyf92p0uscgUZVTYixjg==
32
33
  -----END CERTIFICATE-----
33
- date: 2013-03-08 00:00:00.000000000 Z
34
+ date: 2013-04-19 00:00:00.000000000 Z
34
35
  dependencies:
35
36
  - !ruby/object:Gem::Dependency
36
37
  name: ffi
@@ -77,6 +78,7 @@ dependencies:
77
78
  description: Ruby binding to the Networking and Cryptography (NaCl) library
78
79
  email:
79
80
  - tony.arcieri@gmail.com
81
+ - jonathan.stott@gmail.com
80
82
  executables: []
81
83
  extensions: []
82
84
  extra_rdoc_files: []
@@ -91,6 +93,7 @@ files:
91
93
  - LICENSE.txt
92
94
  - README.md
93
95
  - Rakefile
96
+ - bascule.cert
94
97
  - images/dragons.png
95
98
  - images/ed25519.png
96
99
  - images/hash.png
metadata.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- �����$�Z���]��ޤ�R-]e��ڮ���
2
- ����:�T����SO�Œ������R.� d45hک`]&ӕ��=���E1M����eP"c��@-���j�p? `A�n:�G�Ҿ��W���wj#�pJU�& U@���� `��cӜO���9�؅�1�p 퉼�ǡ�Fl:>�%k
1
+ Ea���E?�&rL}:�!�`��uB�\�$GP�>�: ����݋)cv"H*�#��4���ei��*�&�pjk#*�芚$��I�_����:��oC����W��h �=���ƕʗZ��K��Oc{����<P�~G�(���M���
2
+ ��X�V���>'XA'� Cy Tvjq� SX�����