self_crypto 0.0.7 → 0.0.8

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
  SHA256:
3
- metadata.gz: c80522a003146eb903859a9fc2007546dc76ff94e599b3eaceccbe328b753fbb
4
- data.tar.gz: a1a7eb743ed6b4c22d0a9b70c33f9aba491d6bf88a02bba32dbbb4659c570621
3
+ metadata.gz: 3db3da86cb87d90e72ce0f69a682872a8e2b092b9828e67d1a7641b1952fed59
4
+ data.tar.gz: e3319c2d1c8f34854500f4f4d723007b89d9c1ac312ae6d271c74d953c22548d
5
5
  SHA512:
6
- metadata.gz: c8bf46420a38dda34c0574ecbc9ee785290dd2d3bcd94db3513547e65fe750c9cec0c835da24043224fb3d08bb318b47263e5753ff43d6ab55569cafd8ae4f3b
7
- data.tar.gz: 785ee198c7345c1fa6ead3df9211181de418045cc33979c414b2f150d73f43b8303edc0be6469179c3f03e4acbe262d33834be3fcec5ba371fee41fada314ef7
6
+ metadata.gz: cb42f2dd7f586324bd638583c89a867b1858ae4d2da836f15392f851eb36e624f59648c71f5f0fff12fce922cca1b18f37fe2e6019bfda72131af60fa855e3b3
7
+ data.tar.gz: 770c20da2afea5e5dbd1cf8291584640b1ce1db395bbe916a340c67b429aa1998acfb3aa0d0f56f0f0e05bcd13bd27ef995fcf6866bebb8917c1e80051fcff79
@@ -1,3 +1,5 @@
1
+ // Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  #include "sodium.h"
2
4
  #include "self_olm/olm.h"
3
5
  #include "self_omemo.h"
@@ -24,6 +24,117 @@ static VALUE ed25519_verify(VALUE self, VALUE data, VALUE key, VALUE signature)
24
24
  return retval;
25
25
  }
26
26
 
27
+ static VALUE random_bytes(VALUE self, VALUE size)
28
+ {
29
+ void *nonce;
30
+
31
+ if((nonce = malloc(NUM2SIZET(size))) == NULL){
32
+ rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
33
+ }
34
+
35
+ randombytes_buf(nonce, NUM2SIZET(size));
36
+
37
+ VALUE n = rb_str_new(nonce, NUM2SIZET(size));
38
+
39
+ free(nonce);
40
+
41
+ return n;
42
+ }
43
+
44
+ static VALUE aead_xchacha20poly1305_ietf_nonce(VALUE self)
45
+ {
46
+ void *nonce;
47
+
48
+ if((nonce = malloc(crypto_aead_xchacha20poly1305_ietf_NPUBBYTES)) == NULL){
49
+ rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
50
+ }
51
+
52
+ randombytes_buf(nonce, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
53
+
54
+ VALUE n = rb_str_new(nonce, crypto_aead_xchacha20poly1305_ietf_NPUBBYTES);
55
+
56
+ free(nonce);
57
+
58
+ return n;
59
+ }
60
+
61
+ static VALUE aead_xchacha20poly1305_ietf_keygen(VALUE self)
62
+ {
63
+ void *key;
64
+
65
+ if((key = malloc(crypto_aead_xchacha20poly1305_ietf_KEYBYTES)) == NULL){
66
+ rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
67
+ }
68
+
69
+ crypto_aead_xchacha20poly1305_ietf_keygen(key);
70
+
71
+ VALUE k = rb_str_new(key, crypto_aead_xchacha20poly1305_ietf_KEYBYTES);
72
+
73
+ free(key);
74
+
75
+ return k;
76
+ }
77
+
78
+ static VALUE aead_xchacha20poly1305_ietf_encrypt(VALUE self, VALUE key, VALUE nonce, VALUE plaintext)
79
+ {
80
+ void *ciphertext;
81
+ unsigned long long ciphertext_len;
82
+
83
+ if((ciphertext = malloc(RSTRING_LEN(plaintext) + crypto_aead_xchacha20poly1305_ietf_ABYTES)) == NULL){
84
+ rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
85
+ }
86
+
87
+ crypto_aead_xchacha20poly1305_ietf_encrypt(
88
+ ciphertext,
89
+ &ciphertext_len,
90
+ RSTRING_PTR(plaintext),
91
+ RSTRING_LEN(plaintext),
92
+ NULL,
93
+ 0,
94
+ NULL,
95
+ RSTRING_PTR(nonce),
96
+ RSTRING_PTR(key)
97
+ );
98
+
99
+ VALUE ct = rb_str_new(ciphertext, ciphertext_len);
100
+
101
+ free(ciphertext);
102
+
103
+ return ct;
104
+ }
105
+
106
+ static VALUE aead_xchacha20poly1305_ietf_decrypt(VALUE self, VALUE key, VALUE nonce, VALUE ciphertext)
107
+ {
108
+ void *plaintext;
109
+ unsigned long long plaintext_len;
110
+
111
+ if((plaintext = malloc(RSTRING_LEN(ciphertext))) == NULL){
112
+ rb_raise(rb_eNoMemError, "%s()", __FUNCTION__);
113
+ }
114
+
115
+ int status = crypto_aead_xchacha20poly1305_ietf_decrypt(
116
+ plaintext,
117
+ &plaintext_len,
118
+ NULL,
119
+ RSTRING_PTR(ciphertext),
120
+ RSTRING_LEN(ciphertext),
121
+ NULL,
122
+ 0,
123
+ RSTRING_PTR(nonce),
124
+ RSTRING_PTR(key)
125
+ );
126
+
127
+ if (status != 0) {
128
+ rb_raise(rb_eStandardError, "could not authenticate encrypted message");
129
+ }
130
+
131
+ VALUE pt = rb_str_new(plaintext, plaintext_len);
132
+
133
+ free(plaintext);
134
+
135
+ return pt;
136
+ }
137
+
27
138
  static VALUE ed25519_pk_to_curve25519(VALUE self, VALUE ed25519_pk)
28
139
  {
29
140
  VALUE curve25519_sk;
@@ -140,4 +251,9 @@ void utility_init(void)
140
251
  rb_define_method(cUtility, "sha256", sha256, 1);
141
252
  rb_define_method(cUtility, "ed25519_verify", ed25519_verify, 3);
142
253
  rb_define_module_function(cUtil, "ed25519_pk_to_curve25519", ed25519_pk_to_curve25519, 1);
254
+ rb_define_module_function(cUtil, "random_bytes", random_bytes, 1);
255
+ rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_keygen", aead_xchacha20poly1305_ietf_keygen, 0);
256
+ rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_nonce", aead_xchacha20poly1305_ietf_nonce, 0);
257
+ rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_encrypt", aead_xchacha20poly1305_ietf_encrypt, 3);
258
+ rb_define_module_function(cUtil, "aead_xchacha20poly1305_ietf_decrypt", aead_xchacha20poly1305_ietf_decrypt, 3);
143
259
  }
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  require 'base64'
2
4
 
3
5
  module SelfCrypto
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  require 'base64'
2
4
 
3
5
  module SelfCrypto
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  module SelfCrypto
2
4
 
3
5
  module Util
@@ -1,5 +1,7 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  module SelfCrypto
2
4
 
3
- VERSION="0.0.7"
5
+ VERSION="0.0.8"
4
6
 
5
7
  end
data/lib/self_crypto.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  require 'self_crypto/version'
2
4
  require 'self_crypto/self_crypto'
3
5
  require 'self_crypto/account'
@@ -96,13 +96,13 @@ describe "Account" do
96
96
  end
97
97
 
98
98
  describe "#inbound_session from pickled account" do
99
-
99
+
100
100
  let(:remote_session){ remote.outbound_session(account.ik['curve25519'], account.otk['curve25519'].values.first) }
101
101
  let(:remote_message){ remote_session.encrypt("hello") }
102
102
  let(:pickled_account){ account.to_pickle("test") }
103
103
  let(:unpickled_account){ SelfCrypto::Account.from_pickle(pickled_account, "test") }
104
104
  it("creates session") { _(unpickled_account.inbound_session(remote_message, remote.ik['curve25519'])).must_be_kind_of SelfCrypto::Session }
105
-
105
+
106
106
  end
107
107
 
108
108
  end
@@ -14,4 +14,16 @@ describe "Util" do
14
14
  it("should convert"){ _(account.ik['curve25519']).must_equal curve25519_pk }
15
15
  end
16
16
 
17
+ describe "xchacha20_poly1305_itef" do
18
+ message = "something"
19
+
20
+ key = SelfCrypto::Util.aead_xchacha20poly1305_ietf_keygen
21
+ nonce = SelfCrypto::Util.aead_xchacha20poly1305_ietf_nonce
22
+
23
+ ct = SelfCrypto::Util.aead_xchacha20poly1305_ietf_encrypt(key, nonce, message)
24
+ pt = SelfCrypto::Util.aead_xchacha20poly1305_ietf_decrypt(key, nonce, ct)
25
+
26
+ it('should decrypt'){ _(pt).must_equal message}
27
+ end
28
+
17
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: self_crypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Bevan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-10-21 00:00:00.000000000 Z
12
+ date: 2022-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
@@ -124,13 +124,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.1.2
127
+ rubygems_version: 3.2.5
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Group end to end encryption for self
131
131
  test_files:
132
132
  - test/unit/test_account_methods.rb
133
- - test/examples/test_exchange.rb
134
133
  - test/examples/test_bob_no_answer.rb
135
- - test/spec/test_util.rb
134
+ - test/examples/test_exchange.rb
136
135
  - test/spec/test_account.rb
136
+ - test/spec/test_util.rb