tweetnacl 0.0.1 → 0.2.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: 1bad39ace9be8f8a7eb1d0663e4408afafbf1380
4
- data.tar.gz: aa4d5a4dbbe7c17a22bceb16f04b46761cc1daf9
3
+ metadata.gz: deaf1ed99efeefb3138a1b0c78e43e7cb1c1699e
4
+ data.tar.gz: 73a15e0587d64171ef60723f879ed0f7e65631e8
5
5
  SHA512:
6
- metadata.gz: 7efecffbd00db486ba676dc8c9f41d7e0a6c81e8573b55b8ad83ad008e96e42352838ae8b1230b3b747a8edee9c2a70f51db48133a364a70adb05a75f0d25284
7
- data.tar.gz: d250ea717d974607a11a6baffcfadc84c81564c69fdd33f1f5fdabf2dec6f6d5f6e7005a68cf20c533e641e6c765cf61707fe8318c273696619d8cc71c7057f5
6
+ metadata.gz: 048804948082736c35a551cfe6c54a1756330f8603ac2bc4eef8f9c31fdf3c42b2a7a2c48775132a4a99d0e899136aa5ce8ba44e23718183f61d847f7d28e4bc
7
+ data.tar.gz: 378798dffd4d8761e4f43447379ae7a2c14acc26f1d01efded7cddd50c99dd97c283c5d934d8862a8a659e2cbbcd03ce1991bb277003da92a609c7c55b215e1d
@@ -0,0 +1,13 @@
1
+ # Releases
2
+
3
+ ## UNRELEASED
4
+
5
+ ## 0.2.0
6
+
7
+ * Implemented the crypto\_box\_curve25519xsalsa20poly1305 functions
8
+ * Added a CHANGELOG file
9
+
10
+ ## 0.0.1
11
+
12
+ * Initial release
13
+ * Implemented the crypto\_box functions
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # TweetNaCl for Ruby
2
2
 
3
- # SUMMARY
3
+ ## SUMMARY
4
4
 
5
5
  TweetNaCl is a C-extension for Ruby built on top of the official TweetNacl
6
6
  distribution. It exposes the basic functions using Ruby objects.
7
7
 
8
8
  For a detailed explanation of TweetNaCl, [here's the research paper associated with it][paper]
9
9
 
10
- # INSTALL
10
+ ## INSTALL
11
11
 
12
12
  gem install tweetnacl
13
13
 
@@ -16,6 +16,8 @@ For a detailed explanation of TweetNaCl, [here's the research paper associated w
16
16
  input = "<text to cipher>"
17
17
  nonce = "<a 24-char string>"
18
18
 
19
+ @t = TweetNaCl.new
20
+
19
21
  pk, sk = @t.crypto_box_keypair # This generates a pair of public and secret keys
20
22
 
21
23
  cipher = @t.crypto_box(input, nonce, pk, sk) # Encrypt !
@@ -43,6 +45,9 @@ Decrypt and verify the signature of the ciphered message given the other paramet
43
45
  * [x] crypto_box_keypair
44
46
  * [x] crypto_box
45
47
  * [x] crypto_box_open
48
+ * [x] crypto_box_curve25519xsalsa20poly1305_keypair
49
+ * [x] crypto_box_curve25519xsalsa20poly1305
50
+ * [x] crypto_box_curve25519xsalsa20poly1305_open
46
51
  * [ ] All the other functions !
47
52
  * [ ] Use high-level objects
48
53
 
@@ -76,7 +76,62 @@ VALUE m_crypto_box_open(VALUE self, VALUE _c, VALUE _n, VALUE _pk, VALUE _sk) {
76
76
  char * message = calloc(padded_mlen, sizeof(char));
77
77
 
78
78
  int res = crypto_box_open(message, c, padded_mlen, nonce, pk, sk);
79
- if (0 != res) { rb_raise(rb_eRuntimeError, "la putain"); }
79
+ if (0 != res) { rb_raise(rb_eRuntimeError, "crypto_box_open did not work"); }
80
+
81
+ return rb_str_new2(message + PADDING_LEN);
82
+ }
83
+
84
+ VALUE m_crypto_box_curve25519xsalsa20poly1305_keypair(VALUE self) {
85
+ VALUE ary = rb_ary_new2(2);
86
+ char *pk = calloc(crypto_box_curve25519xsalsa20poly1305_tweet_PUBLICKEYBYTES, sizeof(unsigned char));
87
+ char *sk = calloc(crypto_box_curve25519xsalsa20poly1305_tweet_SECRETKEYBYTES, sizeof(unsigned char));
88
+ int res = crypto_box_curve25519xsalsa20poly1305_keypair(pk, sk);
89
+ pk[crypto_box_curve25519xsalsa20poly1305_tweet_PUBLICKEYBYTES] = 0;
90
+ sk[crypto_box_curve25519xsalsa20poly1305_tweet_SECRETKEYBYTES] = 0;
91
+ rb_ary_store(ary, 0, rb_str_new(pk, crypto_box_curve25519xsalsa20poly1305_tweet_PUBLICKEYBYTES));
92
+ rb_ary_store(ary, 1, rb_str_new(sk, crypto_box_curve25519xsalsa20poly1305_tweet_SECRETKEYBYTES));
93
+ return ary;
94
+ }
95
+
96
+ VALUE m_crypto_box_curve25519xsalsa20poly1305(VALUE self, VALUE _m, VALUE _n, VALUE _pk, VALUE _sk) {
97
+ if(_m == Qnil) { rb_raise(rb_eArgError, "A message should have been given"); }
98
+ if(_pk == Qnil) { rb_raise(rb_eArgError, "Public key should have been given"); }
99
+ if(_sk == Qnil) { rb_raise(rb_eArgError, "Secret key should have been given"); }
100
+ if (RSTRING_LEN(_n) != 24) { rb_raise(rb_eArgError, "nonce should be 24-byte long"); }
101
+ if (RSTRING_LEN(_pk) != 32) { rb_raise(rb_eArgError, "public key should be 24-byte long"); }
102
+ if (RSTRING_LEN(_sk) != 32) { rb_raise(rb_eArgError, "secret key should be 24-byte long"); }
103
+
104
+ char * message = RSTRING_PTR(_m);
105
+ char * nonce = RSTRING_PTR(_n);
106
+ char * pk = RSTRING_PTR(_pk);
107
+ char * sk = RSTRING_PTR(_sk);
108
+ int len = strlen(message);
109
+ char * padded_message = (char*)calloc(sizeof(char), len + PADDING_LEN);
110
+ memcpy(padded_message + PADDING_LEN, message, strlen(message));
111
+ char * c = malloc(strlen(message) + PADDING_LEN);
112
+ int res = crypto_box_curve25519xsalsa20poly1305(c, padded_message, len + PADDING_LEN, nonce, pk, sk);
113
+ if (0 != res) { fprintf(stderr, "Something went wrong\n"); exit(res); }
114
+ VALUE ret = rb_str_new(c, len + PADDING_LEN);
115
+ return ret;
116
+ }
117
+
118
+ VALUE m_crypto_box_curve25519xsalsa20poly1305_open(VALUE self, VALUE _c, VALUE _n, VALUE _pk, VALUE _sk) {
119
+ if(_c == Qnil) { rb_raise(rb_eArgError, "A cipher should have been given"); }
120
+ if(_pk == Qnil) { rb_raise(rb_eArgError, "Public key should have been given"); }
121
+ if(_sk == Qnil) { rb_raise(rb_eArgError, "Secret key should have been given"); }
122
+ if (RSTRING_LEN(_n) != 24) { rb_raise(rb_eArgError, "nonce should be 24-byte long"); }
123
+ if (RSTRING_LEN(_pk) != 32) { rb_raise(rb_eArgError, "public key should be 24-byte long"); }
124
+ if (RSTRING_LEN(_sk) != 32) { rb_raise(rb_eArgError, "secret key should be 24-byte long"); }
125
+
126
+ unsigned char * c = RSTRING_PTR(_c);
127
+ char * nonce = RSTRING_PTR(_n);
128
+ char * pk = RSTRING_PTR(_pk);
129
+ char * sk = RSTRING_PTR(_sk);
130
+ int padded_mlen = rb_str_strlen(_c);
131
+ char * message = calloc(padded_mlen, sizeof(char));
132
+
133
+ int res = crypto_box_curve25519xsalsa20poly1305_open(message, c, padded_mlen, nonce, pk, sk);
134
+ if (0 != res) { rb_raise(rb_eRuntimeError, "crypto_box_open did not work"); }
80
135
 
81
136
  return rb_str_new2(message + PADDING_LEN);
82
137
  }
@@ -89,4 +144,7 @@ void Init_tweetnacl() {
89
144
  rb_define_method(c, "crypto_box_keypair", RUBY_METHOD_FUNC(m_crypto_box_keypair), 0);
90
145
  rb_define_method(c, "crypto_box", RUBY_METHOD_FUNC(m_crypto_box), 4);
91
146
  rb_define_method(c, "crypto_box_open", RUBY_METHOD_FUNC(m_crypto_box_open), 4);
147
+ rb_define_method(c, "crypto_box_curve25519xsalsa20poly1305_keypair", RUBY_METHOD_FUNC(m_crypto_box_curve25519xsalsa20poly1305_keypair), 0);
148
+ rb_define_method(c, "crypto_box_curve25519xsalsa20poly1305", RUBY_METHOD_FUNC(m_crypto_box_curve25519xsalsa20poly1305), 4);
149
+ rb_define_method(c, "crypto_box_curve25519xsalsa20poly1305_open", RUBY_METHOD_FUNC(m_crypto_box_curve25519xsalsa20poly1305_open), 4);
92
150
  }
@@ -235,8 +235,6 @@ int crypto_onetimeauth(u8 *out,const u8 *m,u64 n,const u8 *k)
235
235
  return 0;
236
236
  }
237
237
 
238
- #include <stdio.h>
239
- extern void hexdump(char*,int);
240
238
  int crypto_onetimeauth_verify(const u8 *h,const u8 *m,u64 n,const u8 *k)
241
239
  {
242
240
  u8 x[16];
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,49 @@
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
@@ -0,0 +1,64 @@
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
@@ -7,11 +7,6 @@ class TweetNaClCryptoBoxOpenTest < MiniTest::Test
7
7
 
8
8
  def teardown; end
9
9
 
10
- def test_foo
11
- assert true
12
- end
13
-
14
-
15
10
  def test_crypto_box_open_require_cipher_to_decrypt
16
11
  set = false
17
12
  begin
@@ -1,20 +1,19 @@
1
1
  # coding: utf-8
2
2
  $:<< 'lib'
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "tweetnacl"
5
- spec.version = "0.0.1"
6
- spec.authors = ["Franck Verrot"]
7
- spec.email = ["franck@verrot.fr"]
8
- spec.homepage = "https://github.com/franckverrot/clamav-client"
9
- spec.license = "GPLv3"
4
+ spec.name = "tweetnacl"
5
+ spec.version = "0.2.0"
6
+ spec.authors = ["Franck Verrot"]
7
+ spec.email = ["franck@verrot.fr"]
8
+ spec.homepage = "https://github.com/franckverrot/tweetnacl"
9
+ spec.license = "GPLv3"
10
10
 
11
- spec.summary = "TweetNaCl for Ruby"
11
+ spec.summary = "TweetNaCl for Ruby"
12
12
  spec.description = "TweetNaCl is a C-extension built on top of the official TweetNaCl distribution"
13
- spec.files = `git ls-files -z`.split("\x0")
13
+ spec.files = `git ls-files -z`.split("\x0")
14
14
 
15
15
  spec.extensions << "ext/tweetnacl/extconf.rb"
16
16
 
17
-
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetnacl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franck Verrot
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".travis.yml"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md
@@ -87,11 +88,14 @@ files:
87
88
  - ext/tweetnacl/tweetnacl.c
88
89
  - ext/tweetnacl/tweetnacl.h
89
90
  - test/test_helper.rb
91
+ - test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_keypair_test.rb
92
+ - test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_open_test.rb
93
+ - test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_test.rb
90
94
  - test/tweetnacl_crypto_box_key_pair_test.rb
91
95
  - test/tweetnacl_crypto_box_open_test.rb
92
96
  - test/tweetnacl_crypto_box_test.rb
93
97
  - tweetnacl.gemspec
94
- homepage: https://github.com/franckverrot/clamav-client
98
+ homepage: https://github.com/franckverrot/tweetnacl
95
99
  licenses:
96
100
  - GPLv3
97
101
  metadata: {}
@@ -117,6 +121,9 @@ specification_version: 4
117
121
  summary: TweetNaCl for Ruby
118
122
  test_files:
119
123
  - test/test_helper.rb
124
+ - test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_keypair_test.rb
125
+ - test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_open_test.rb
126
+ - test/tweetnacl_crypto_box_curve25519xsalsa20poly1305_test.rb
120
127
  - test/tweetnacl_crypto_box_key_pair_test.rb
121
128
  - test/tweetnacl_crypto_box_open_test.rb
122
129
  - test/tweetnacl_crypto_box_test.rb