ruby-chacha20 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/Rakefile +5 -0
- data/ext/chacha20/chacha20_bindings.c +9 -6
- data/lib/chacha20/chacha20.rb +4 -4
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 061d9c24c329984525f22fd468f5bea38c1aee9e4c9e660da96514697db5e8ef
|
4
|
+
data.tar.gz: 25bf1a1ccddac6fae6f2b133b2dd570cd0cc070eea91e8338f12e029fe5b14a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77226764ab9a757bd6fc5ddfe9057ec0f9c8e0312530a0420da4c6dd9b0615d098ddeef77d0bd97bded09c29881e61874bc6c6c5af572505bf6abff9b2f886b1
|
7
|
+
data.tar.gz: 9e5afca4c6194838959a25d07b8b47db542f6afd95fde18c12c883f59982dd9ec0c958d6ad41f5a2eb7e90fcf7a765a614f9a8ebb67aefbaec62a123cd3acd3b
|
data/README.md
CHANGED
@@ -8,7 +8,11 @@ only, it does not provide any kind of message authentication or integrity checki
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
Add this Gem to your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "ruby-chacha20"
|
15
|
+
```
|
12
16
|
|
13
17
|
## Usage
|
14
18
|
|
data/Rakefile
CHANGED
@@ -13,6 +13,7 @@ task default: :test
|
|
13
13
|
task benchmark: :compile do
|
14
14
|
$LOAD_PATH.unshift File.expand_path("lib", __dir__)
|
15
15
|
require "benchmark"
|
16
|
+
require "memory_profiler"
|
16
17
|
require "ruby-chacha20"
|
17
18
|
|
18
19
|
def read_hex(inp)
|
@@ -27,4 +28,8 @@ task benchmark: :compile do
|
|
27
28
|
Benchmark.bm do |bm|
|
28
29
|
bm.report("ChaCha20#encrypt") { ChaCha20.new(key, nonce).encrypt("\x00".b * bytesize) }
|
29
30
|
end
|
31
|
+
|
32
|
+
MemoryProfiler.report do
|
33
|
+
ChaCha20.new(key, nonce).encrypt("\x00".b * bytesize)
|
34
|
+
end.pretty_print
|
30
35
|
end
|
@@ -71,18 +71,21 @@ static VALUE rb_chacha20_get_counter(VALUE self) {
|
|
71
71
|
return rb_ull2inum(((unsigned LONG_LONG)(ctx->input[13]) << 32) | (unsigned LONG_LONG)(ctx->input[12]));
|
72
72
|
}
|
73
73
|
|
74
|
-
static VALUE rb_chacha20_encrypt_or_decrypt(VALUE self, VALUE input) {
|
75
|
-
VALUE output;
|
74
|
+
static VALUE rb_chacha20_encrypt_or_decrypt(VALUE self, VALUE input, VALUE outbuf) {
|
76
75
|
ECRYPT_ctx *ctx;
|
77
76
|
|
78
77
|
Check_Type(input, RUBY_T_STRING);
|
78
|
+
Check_Type(outbuf, RUBY_T_STRING);
|
79
|
+
|
80
|
+
if (RSTRING_LEN(outbuf) != RSTRING_LEN(input)) {
|
81
|
+
rb_raise(rb_eArgError, "Output buffer must have the same size as the input");
|
82
|
+
}
|
79
83
|
|
80
84
|
Data_Get_Struct(self, ECRYPT_ctx, ctx);
|
81
85
|
|
82
|
-
|
83
|
-
ECRYPT_encrypt_bytes(ctx, (const unsigned char*)RSTRING_PTR(input), (unsigned char*)RSTRING_PTR(output), (unsigned int)RSTRING_LEN(input));
|
86
|
+
ECRYPT_encrypt_bytes(ctx, (const unsigned char*)RSTRING_PTR(input), (unsigned char*)RSTRING_PTR(outbuf), (unsigned int)RSTRING_LEN(input));
|
84
87
|
|
85
|
-
return
|
88
|
+
return outbuf;
|
86
89
|
}
|
87
90
|
|
88
91
|
void Init_chacha20_bindings() {
|
@@ -95,5 +98,5 @@ void Init_chacha20_bindings() {
|
|
95
98
|
rb_define_private_method(cChaCha20, "get_nonce", rb_chacha20_get_nonce, 0);
|
96
99
|
rb_define_private_method(cChaCha20, "set_counter", rb_chacha20_set_counter, 1);
|
97
100
|
rb_define_private_method(cChaCha20, "get_counter", rb_chacha20_get_counter, 0);
|
98
|
-
rb_define_private_method(cChaCha20, "encrypt_or_decrypt", rb_chacha20_encrypt_or_decrypt,
|
101
|
+
rb_define_private_method(cChaCha20, "encrypt_or_decrypt", rb_chacha20_encrypt_or_decrypt, 2);
|
99
102
|
}
|
data/lib/chacha20/chacha20.rb
CHANGED
@@ -50,14 +50,14 @@ class ChaCha20
|
|
50
50
|
|
51
51
|
length = input.bytesize
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
buffer = "\x00".b * @block_offset + input
|
54
|
+
buffer = encrypt_or_decrypt(buffer, buffer)
|
55
|
+
buffer.slice!(0, @block_offset)
|
56
56
|
|
57
57
|
@block_offset = (@block_offset + length) % 64
|
58
58
|
set_counter(get_counter - 1) unless @block_offset.zero?
|
59
59
|
|
60
|
-
|
60
|
+
buffer
|
61
61
|
end
|
62
62
|
|
63
63
|
alias_method :decrypt, :encrypt
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-chacha20
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Gitter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: memory_profiler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- contact@agitter.de
|