tweetnacl 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +9 -1
- data/README.md +100 -13
- data/Rakefile +1 -1
- data/ext/tweetnacl/rbext.c +262 -63
- data/lib/tweet_na_cl.rb +2 -0
- data/lib/tweetnacl/crypto_box.rb +17 -0
- data/lib/tweetnacl/crypto_sign.rb +17 -0
- data/lib/tweetnacl/key_pair.rb +9 -0
- data/test/test_helper.rb +6 -0
- data/test/tweetnacl/crypto_box_test.rb +30 -0
- data/test/tweetnacl/crypto_sign_test.rb +25 -0
- data/test/tweetnacl/key_pair_test.rb +17 -0
- data/test/tweetnacl_alias_test.rb +18 -0
- data/test/tweetnacl_constants_test.rb +172 -0
- data/test/tweetnacl_crypto_box_key_pair_test.rb +1 -7
- data/test/tweetnacl_crypto_box_open_test.rb +9 -35
- data/test/tweetnacl_crypto_box_test.rb +6 -36
- data/test/tweetnacl_crypto_secretbox_open_test.rb +15 -0
- data/test/tweetnacl_crypto_secretbox_test.rb +29 -0
- data/test/tweetnacl_crypto_sign_key_pair_test.rb +10 -0
- data/test/tweetnacl_crypto_sign_open_test.rb +13 -0
- data/test/tweetnacl_crypto_sign_test.rb +26 -0
- data/tweetnacl.gemspec +1 -1
- metadata +26 -8
- data/test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_keypair_test.rb +0 -16
- data/test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_open_test.rb +0 -49
- data/test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_test.rb +0 -64
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TweetNaClCryptoSecretboxOpenTest < MiniTest::Test
|
4
|
+
def test_crypto_box_secretbox_open_require_cipher_to_decrypt
|
5
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_secretbox_open(nil, nil, nil) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_crypto_secretbox_open_require_secret_key
|
9
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_secretbox_open("foo", "foo", nil) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_crypto_secretbox_open_nonce_not_correct_length
|
13
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_secretbox_open("foo", "bar", "k") }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TweetNaClCryptoSecretTest < MiniTest::Test
|
4
|
+
def test_crypto_secretbox
|
5
|
+
input = "hello world"
|
6
|
+
nonce = "*" * 24
|
7
|
+
expected_cipher = "00000000000000002A9612E32BCC4E836B3D46463B7C1546EA8BC752A1B6AE6DE"
|
8
|
+
k = "\x60\xF0\x23\x07\xDF\xB6\x8B\xBB\x15\xE2\x92\x59\x05\x1B\x2D\xF8\xC8\x59\xDB\x5B\xDE\x97\xFA\xE8\x9B\x5F\xE5\x62\x63\x11\xD6\x56"
|
9
|
+
|
10
|
+
cipher = TweetNaCl.crypto_secretbox(input, nonce, k)
|
11
|
+
|
12
|
+
output = TweetNaCl.crypto_secretbox_open(cipher, nonce, k)
|
13
|
+
|
14
|
+
assert_equal input, output
|
15
|
+
assert_equal expected_cipher, cipher.hd
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_crypto_secretbox_require_message_to_cipher
|
19
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_secretbox(nil, "bar", "k") }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_crypto_secretbox_require_secret_key
|
23
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_secretbox("foo", "bar", "k") }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_crypto_secretbox_nonce_not_correct_length
|
27
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_secretbox("foo", "bar", "k") }
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TweetNaClCryptoSignOpenTest < MiniTest::Test
|
4
|
+
def test_crypto_sign_open_require_message_to_verify
|
5
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_sign_open(nil, nil) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_crypto_sign_open_require_public_key
|
9
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_sign_open("foo", nil) }
|
10
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_sign_open("foo", "too_short_public_key") }
|
11
|
+
assert_raises(RuntimeError) { TweetNaCl.crypto_sign_open("foo", "an incorrect 32 bit.............") }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TweetNaClCryptoSignTest < MiniTest::Test
|
4
|
+
def test_crypto_sign
|
5
|
+
input = "hello world"
|
6
|
+
expected_cipher = "948CC9261D32D928AA3E5321F54EFE80B19AA8DE985A2FE5F0CDA0669FE253499051F8E54F0F4767646ECA13D75CCF49AD4802536331B3AB8BF427A5D43CA868656C6C6F20776F726C64"
|
7
|
+
pk = "\x8B\x1B\xA8\xF3\xCB\xD6\x2C\x4F\x40\xAA\x96\x53\x06\x5B\x2F\x02\x52\x4B\x35\x34\x39\x32\xE2\x02\xC0\xA7\x5F\x9D\x4B\x5B\x07\xCF"
|
8
|
+
sk = "\xC3\x51\x77\xB0\x8D\x93\xC3\x09\x37\x06\xCA\x65\x98\x9A\x53\x80\x92\xA4\x9C\x9B\x7A\x57\x19\x6D\xF8\x01\x5C\x0F\x81\x6E\xA3\xEF\x8B\x1B\xA8\xF3\xCB\xD6\x2C\x4F\x40\xAA\x96\x53\x06\x5B\x2F\x02\x52\x4B\x35\x34\x39\x32\xE2\x02\xC0\xA7\x5F\x9D\x4B\x5B\x07\xCF"
|
9
|
+
|
10
|
+
cipher = TweetNaCl.crypto_sign(input, sk)
|
11
|
+
|
12
|
+
output = TweetNaCl.crypto_sign_open(cipher, pk)
|
13
|
+
|
14
|
+
assert_equal input, output
|
15
|
+
assert_equal expected_cipher, cipher.hd
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_crypto_sign_require_message_to_sign
|
19
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_sign(nil, nil) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_crypto_sign_require_public_key
|
23
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_sign("foo", nil) }
|
24
|
+
assert_raises(ArgumentError) { TweetNaCl.crypto_sign("foo", "too_short_public_key") }
|
25
|
+
end
|
26
|
+
end
|
data/tweetnacl.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tweetnacl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franck Verrot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -87,13 +87,24 @@ files:
|
|
87
87
|
- ext/tweetnacl/rbext.c
|
88
88
|
- ext/tweetnacl/tweetnacl.c
|
89
89
|
- ext/tweetnacl/tweetnacl.h
|
90
|
+
- lib/tweet_na_cl.rb
|
91
|
+
- lib/tweetnacl/crypto_box.rb
|
92
|
+
- lib/tweetnacl/crypto_sign.rb
|
93
|
+
- lib/tweetnacl/key_pair.rb
|
90
94
|
- test/test_helper.rb
|
91
|
-
- test/
|
92
|
-
- test/
|
93
|
-
- test/
|
95
|
+
- test/tweetnacl/crypto_box_test.rb
|
96
|
+
- test/tweetnacl/crypto_sign_test.rb
|
97
|
+
- test/tweetnacl/key_pair_test.rb
|
98
|
+
- test/tweetnacl_alias_test.rb
|
99
|
+
- test/tweetnacl_constants_test.rb
|
94
100
|
- test/tweetnacl_crypto_box_key_pair_test.rb
|
95
101
|
- test/tweetnacl_crypto_box_open_test.rb
|
96
102
|
- test/tweetnacl_crypto_box_test.rb
|
103
|
+
- test/tweetnacl_crypto_secretbox_open_test.rb
|
104
|
+
- test/tweetnacl_crypto_secretbox_test.rb
|
105
|
+
- test/tweetnacl_crypto_sign_key_pair_test.rb
|
106
|
+
- test/tweetnacl_crypto_sign_open_test.rb
|
107
|
+
- test/tweetnacl_crypto_sign_test.rb
|
97
108
|
- tweetnacl.gemspec
|
98
109
|
homepage: https://github.com/franckverrot/tweetnacl
|
99
110
|
licenses:
|
@@ -121,10 +132,17 @@ specification_version: 4
|
|
121
132
|
summary: TweetNaCl for Ruby
|
122
133
|
test_files:
|
123
134
|
- test/test_helper.rb
|
124
|
-
- test/
|
125
|
-
- test/
|
126
|
-
- test/
|
135
|
+
- test/tweetnacl/crypto_box_test.rb
|
136
|
+
- test/tweetnacl/crypto_sign_test.rb
|
137
|
+
- test/tweetnacl/key_pair_test.rb
|
138
|
+
- test/tweetnacl_alias_test.rb
|
139
|
+
- test/tweetnacl_constants_test.rb
|
127
140
|
- test/tweetnacl_crypto_box_key_pair_test.rb
|
128
141
|
- test/tweetnacl_crypto_box_open_test.rb
|
129
142
|
- test/tweetnacl_crypto_box_test.rb
|
143
|
+
- test/tweetnacl_crypto_secretbox_open_test.rb
|
144
|
+
- test/tweetnacl_crypto_secretbox_test.rb
|
145
|
+
- test/tweetnacl_crypto_sign_key_pair_test.rb
|
146
|
+
- test/tweetnacl_crypto_sign_open_test.rb
|
147
|
+
- test/tweetnacl_crypto_sign_test.rb
|
130
148
|
has_rdoc:
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TweetNaClCryptoBoxCurve25519XSalsa20Poly1305KeyPairTest < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
@t = TweetNaCl.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown; end
|
9
|
-
|
10
|
-
def test_generate_a_keypair
|
11
|
-
pk, sk = @t.crypto_box_curve25519xsalsa20poly1305_keypair
|
12
|
-
|
13
|
-
assert_equal 32, pk.length
|
14
|
-
assert_equal 32, sk.length
|
15
|
-
end
|
16
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TweetNaClCryptoBoxCurve25519XSalsa20Poly1305OpenTest < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
@t = TweetNaCl.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown; end
|
9
|
-
|
10
|
-
def test_crypto_box_curve25519xsalsa20poly1305_open_require_cipher_to_decrypt
|
11
|
-
set = false
|
12
|
-
begin
|
13
|
-
@t.crypto_box_curve25519xsalsa20poly1305_open(nil, nil, nil, nil)
|
14
|
-
rescue Exception => e
|
15
|
-
set = true
|
16
|
-
end
|
17
|
-
assert set, "A cipher is required"
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_crypto_box_curve25519xsalsa20poly1305_open_require_public_key
|
21
|
-
set = false
|
22
|
-
begin
|
23
|
-
@t.crypto_box_curve25519xsalsa20poly1305_open("foo", nil, "foo", nil)
|
24
|
-
rescue ArgumentError => e
|
25
|
-
set = true
|
26
|
-
end
|
27
|
-
assert set, "A public key is required"
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_crypto_box_curve25519xsalsa20poly1305_open_require_secret_key
|
31
|
-
set = false
|
32
|
-
begin
|
33
|
-
@t.crypto_box_curve25519xsalsa20poly1305_open("foo", "foo", "foo", nil)
|
34
|
-
rescue ArgumentError => e
|
35
|
-
set = true
|
36
|
-
end
|
37
|
-
assert set, "A secret key is required"
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_crypto_box_curve25519xsalsa20poly1305_open_nonce_not_correct_length
|
41
|
-
set = false
|
42
|
-
begin
|
43
|
-
@t.crypto_box_curve25519xsalsa20poly1305_open("foo", "bar", "pk", "sk")
|
44
|
-
rescue ArgumentError => e
|
45
|
-
set = true
|
46
|
-
end
|
47
|
-
assert set, "Incorrect nonce length should have raised ArgumentError"
|
48
|
-
end
|
49
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TweetNaClCryptoBoxCurve25519XSalsa20Poly1305Test < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
@t = TweetNaCl.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown; end
|
9
|
-
|
10
|
-
def test_crypto_box_curve25519xsalsa20poly1305
|
11
|
-
input = "hello world"
|
12
|
-
nonce = "*" * 24
|
13
|
-
expected_cipher = "0000000000000000FBC937C3F136E09FA8A45C58C15E801394F5BB74CE8D538FE3D726"
|
14
|
-
pk = "\x60\xF0\x23\x07\xDF\xB6\x8B\xBB\x15\xE2\x92\x59\x05\x1B\x2D\xF8\xC8\x59\xDB\x5B\xDE\x97\xFA\xE8\x9B\x5F\xE5\x62\x63\x11\xD6\x56"
|
15
|
-
sk = "\xBE\x38\x7C\x59\xD1\x81\x0B\xCC\x8E\xD8\x90\xDB\x3D\xF9\x80\x63\x9E\xD2\x54\x44\xFB\x4D\xD1\x92\xB6\xC6\x75\x53\xF9\x76\x9F\xCF"
|
16
|
-
|
17
|
-
cipher = @t.crypto_box_curve25519xsalsa20poly1305(input, nonce, pk, sk)
|
18
|
-
|
19
|
-
output = @t.crypto_box_curve25519xsalsa20poly1305_open(cipher, nonce, pk, sk)
|
20
|
-
|
21
|
-
assert_equal input, output
|
22
|
-
assert_equal expected_cipher, cipher.hd
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_crypto_box_curve25519xsalsa20poly1305_require_message_to_cipher
|
26
|
-
set = false
|
27
|
-
begin
|
28
|
-
@t.crypto_box_curve25519xsalsa20poly1305(nil, "bar", "pk", "sk")
|
29
|
-
rescue ArgumentError => e
|
30
|
-
set = true
|
31
|
-
end
|
32
|
-
assert set, "A message is required"
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_crypto_box_curve25519xsalsa20poly1305_require_public_key
|
36
|
-
set = false
|
37
|
-
begin
|
38
|
-
@t.crypto_box_curve25519xsalsa20poly1305("foo", "bar", nil, "sk")
|
39
|
-
rescue ArgumentError => e
|
40
|
-
set = true
|
41
|
-
end
|
42
|
-
assert set, "A public key is required"
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_crypto_box_curve25519xsalsa20poly1305_require_secret_key
|
46
|
-
set = false
|
47
|
-
begin
|
48
|
-
@t.crypto_box_curve25519xsalsa20poly1305("foo", "bar", "pk", nil)
|
49
|
-
rescue ArgumentError => e
|
50
|
-
set = true
|
51
|
-
end
|
52
|
-
assert set, "A secret key is required"
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_crypto_box_curve25519xsalsa20poly1305_nonce_not_correct_length
|
56
|
-
set = false
|
57
|
-
begin
|
58
|
-
@t.crypto_box_curve25519xsalsa20poly1305("foo", "bar", "pk", "sk")
|
59
|
-
rescue ArgumentError => e
|
60
|
-
set = true
|
61
|
-
end
|
62
|
-
assert set, "Incorrect nonce length should have raised ArgumentError"
|
63
|
-
end
|
64
|
-
end
|