Skip to content

Commit 8ac1145

Browse files
authored
Merge pull request #19 from mrf345/testing
Move encryption to `argon2id` and `chacha20poly1305`
2 parents 5061f39 + 552d9c9 commit 8ac1145

24 files changed

+334
-337
lines changed

README.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ safelock-cli
99
</a>
1010
</h1>
1111

12-
Fast files encryption (AES-GCM) package and command-line tool built for speed with Go and [Archiver](https://github.com/mholt/archiver)
12+
Fast files encryption package and command-line tool built for speed with Go and [Archiver](https://github.com/mholt/archiver)
13+
14+
Utilizing `argon2id` and `chacha20poly1305` for encryption, see [default options](#options).
15+
1316

1417
### Install
1518

@@ -27,6 +30,7 @@ go get https://github.com/mrf345/safelock-cli@latest
2730

2831
Or using one of the latest release binaries [here](https://github.com/mrf345/safelock-cli/releases)
2932

33+
3034
### Examples
3135

3236
Encrypt a path with default options
@@ -48,10 +52,21 @@ echo "password123456" | safelock-cli encrypt path_to_encrypt encrypted_file_path
4852

4953
You can find interactive examples of using it as a package to [encrypt](https://pkg.go.dev/github.com/mrf345/safelock-cli/safelock#example-Safelock.Encrypt) and [decrypt](https://pkg.go.dev/github.com/mrf345/safelock-cli/safelock#example-Safelock.Decrypt).
5054

51-
### Performance
5255

53-
- Encryption should be about **20.2** times faster than `gpgtar`, and the decryption **3.3** times.
54-
- Encryption should be about **9.1** times faster than `7zip`, and the decryption **9.5** times.
56+
### Options
57+
58+
Following the default options remanded by [RFC9106](https://datatracker.ietf.org/doc/html/rfc9106#section-7.4) and [crypto/argon2](https://pkg.go.dev/golang.org/x/crypto/argon2#IDKey)
59+
60+
| Option | Value |
61+
|-------------------------|---------------------------------------------|
62+
| Iterations | 3 |
63+
| Memory size | 64 Megabytes |
64+
| Key length | 32 |
65+
| Threads | Number of available cores `runtime.NumCPU()`|
66+
| Minimum password length | 8 |
67+
68+
69+
### Performance
5570

5671
> [!NOTE]
5772
> You can reproduce the results by running [bench_and_plot.py](benchmark/bench_and_plot.py) (based on [Matplotlib](https://github.com/matplotlib/matplotlib) and [Hyperfine](https://github.com/sharkdp/hyperfine))

benchmark/bench_and_plot.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
output_dir = "safelock_dump"
1414
runs = 3
1515
figure_width = 14
16-
figure_height = 3
16+
figure_height = 2.5
1717
bar_width = 0.6
1818
measure = "Seconds"
1919
root = os.getcwd()
@@ -22,8 +22,7 @@ def get_label(i, clean=False, key="command"):
2222
matchers = [
2323
('gpg', 'gpgtar',),
2424
('7z', '7zip (fastest)',),
25-
('256', 'safelock --sha256',),
26-
('512', 'safelock --sha512',),
25+
('age', 'age (tar-zstd)'),
2726
('safelock', 'safelock',),
2827
]
2928
label = next((v for m, v in matchers if m in i[key]))
@@ -39,8 +38,7 @@ def get_name(i):
3938
matchers = [
4039
('gpg', f'{output_name}.gpg',),
4140
('7z', f'{output_name}.7z',),
42-
('256', f'{output_name}_sha256.sla',),
43-
('512', f'{output_name}_sha512.sla',),
41+
('age', f'{output_name}.age'),
4442
('safelock', f'{output_name}.sla',),
4543
]
4644

@@ -51,8 +49,7 @@ def encrypt():
5149
f"hyperfine --runs {runs} --prepare "
5250
f"'sleep {rest}' "
5351
f"'echo \"{pwd}\" | {safelock_cmd} encrypt {input_path} {get_name('safelock')} --quiet' "
54-
f"'echo \"{pwd}\" | {safelock_cmd} encrypt {input_path} {get_name('256')} --quiet --sha256' "
55-
f"'echo \"{pwd}\" | {safelock_cmd} encrypt {input_path} {get_name('512')} --quiet --sha512' "
52+
f"'tar cv --zstd {input_path} | . {root}/pipe_age_password.sh | age -e -p -o {get_name('age')}' "
5653
f"'7z a -p{pwd} -mx1 {get_name('7z')} {input_path}' "
5754
f"'gpgtar -e -o {get_name('gpg')} -c --yes --batch --gpg-args \"--passphrase {pwd}\" {input_path}' "
5855
f"--export-json {root}/encryption.json"
@@ -66,8 +63,7 @@ def decrypt():
6663
f"hyperfine --runs {runs} --prepare "
6764
f"'rm -rf {output_dir} {output_name}_*_ && mkdir {output_dir} && sleep {rest}' "
6865
f"'echo \"{pwd}\" | {safelock_cmd} decrypt {get_name('safelock')} {output_dir} --quiet' "
69-
f"'echo \"{pwd}\" | {safelock_cmd} decrypt {get_name('256')} {output_dir} --quiet --sha256' "
70-
f"'echo \"{pwd}\" | {safelock_cmd} decrypt {get_name('512')} {output_dir} --quiet --sha512' "
66+
f"'sleep 0.05; xdotool type \"{pwd}\"; xdotool key \"Return\" | age --decrypt {get_name('age')} | tar x --zstd -f - -C {output_dir}' "
7167
f"'7z e -y -p{pwd} -mx1 {get_name('7z')} -o{output_dir}' "
7268
f"'gpgtar -d --yes --batch --gpg-args \"--passphrase {pwd}\" {get_name('gpg')}' "
7369
f"--export-json {root}/decryption.json"
@@ -77,8 +73,8 @@ def decrypt():
7773
exit(err)
7874

7975
os.chdir(os.path.expanduser("~"))
80-
encrypt()
81-
decrypt()
76+
# encrypt()
77+
# decrypt()
8278
os.chdir(root)
8379
plt.margins(3.5)
8480

@@ -95,7 +91,10 @@ def decrypt():
9591
fig, ax = plt.subplots()
9692
ax.set_title('Encryption Time')
9793
ax.set_xlabel(measure)
98-
ax.barh(labels, scores, bar_width, color=colors)
94+
ax.yaxis.set_label_position('right')
95+
ax.set_ylabel('lower is better')
96+
ax.grid(zorder=0, axis='x', color='black')
97+
ax.barh(labels, scores, bar_width, color=colors, zorder=3)
9998
fig.set_size_inches(w=figure_width, h=figure_height)
10099
fig.tight_layout()
101100
fig.savefig("encryption-time.webp", transparent=True, format="webp")
@@ -112,7 +111,10 @@ def decrypt():
112111
fig, ax = plt.subplots()
113112
ax.set_title('Decryption Time')
114113
ax.set_xlabel(measure)
115-
ax.barh(labels, decryption, bar_width, color=colors)
114+
ax.yaxis.set_label_position('right')
115+
ax.set_ylabel('lower is better')
116+
ax.grid(zorder=0, axis='x', color='black')
117+
ax.barh(labels, decryption, bar_width, color=colors, zorder=3)
116118
fig.set_size_inches(w=figure_width, h=figure_height)
117119
fig.tight_layout()
118120
fig.savefig("decryption-time.webp", transparent=True, format="webp")
@@ -134,7 +136,10 @@ def decrypt():
134136
fig, ax = plt.subplots()
135137
ax.set_title('File Size')
136138
ax.set_xlabel("Megabytes")
137-
ax.barh(labels, sizes, bar_width, color=colors)
139+
ax.yaxis.set_label_position('right')
140+
ax.set_ylabel('lower is better')
141+
ax.grid(zorder=0, axis='x', color='black')
142+
ax.barh(labels, sizes, bar_width, color=colors, zorder=3)
138143
fig.set_size_inches(w=figure_width, h=figure_height)
139144
fig.tight_layout()
140145
fig.savefig("file-size.webp", transparent=True, format="webp")

benchmark/decryption-time.webp

1.14 KB
Binary file not shown.

benchmark/decryption.json

+41-61
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
"results": [
33
{
44
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli decrypt test.sla safelock_dump --quiet",
5-
"mean": 2.1295176539933336,
6-
"stddev": 0.03361454776096437,
7-
"median": 2.13093239266,
8-
"user": 2.5876522466666665,
9-
"system": 1.88427306,
10-
"min": 2.0952180726600003,
11-
"max": 2.16240249666,
5+
"mean": 1.8276349158133336,
6+
"stddev": 0.14566191806696024,
7+
"median": 1.9042654354800002,
8+
"user": 2.309450346666667,
9+
"system": 1.9107805599999999,
10+
"min": 1.6596538664800002,
11+
"max": 1.9189854454800002,
1212
"times": [
13-
2.16240249666,
14-
2.13093239266,
15-
2.0952180726600003
13+
1.9189854454800002,
14+
1.9042654354800002,
15+
1.6596538664800002
1616
],
1717
"exit_codes": [
1818
0,
@@ -21,38 +21,18 @@
2121
]
2222
},
2323
{
24-
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli decrypt test_sha256.sla safelock_dump --quiet --sha256",
25-
"mean": 1.8789916449933333,
26-
"stddev": 0.17816416646803604,
27-
"median": 1.98184108566,
28-
"user": 2.0644982466666666,
29-
"system": 1.776121393333333,
30-
"min": 1.67326538666,
31-
"max": 1.9818684626599998,
24+
"command": "sleep 0.05; xdotool type \"123456789\"; xdotool key \"Return\" | age --decrypt test.age | tar x --zstd -f - -C safelock_dump",
25+
"mean": 2.816656686146667,
26+
"stddev": 0.2702910723941267,
27+
"median": 2.9378343294800002,
28+
"user": 2.6122993466666666,
29+
"system": 5.240392226666667,
30+
"min": 2.50698103648,
31+
"max": 3.00515469248,
3232
"times": [
33-
1.67326538666,
34-
1.98184108566,
35-
1.9818684626599998
36-
],
37-
"exit_codes": [
38-
0,
39-
0,
40-
0
41-
]
42-
},
43-
{
44-
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli decrypt test_sha512.sla safelock_dump --quiet --sha512",
45-
"mean": 2.123450407993334,
46-
"stddev": 0.1763774710740607,
47-
"median": 2.1136010126600002,
48-
"user": 2.5975039133333335,
49-
"system": 1.7468127266666666,
50-
"min": 1.95220401166,
51-
"max": 2.3045461996600003,
52-
"times": [
53-
2.3045461996600003,
54-
2.1136010126600002,
55-
1.95220401166
33+
3.00515469248,
34+
2.9378343294800002,
35+
2.50698103648
5636
],
5737
"exit_codes": [
5838
0,
@@ -62,17 +42,17 @@
6242
},
6343
{
6444
"command": "7z e -y -p123456789 -mx1 test.7z -osafelock_dump",
65-
"mean": 17.944166026326666,
66-
"stddev": 0.03535223844853417,
67-
"median": 17.95858265166,
68-
"user": 19.665792913333334,
69-
"system": 1.4092493933333332,
70-
"min": 17.90388353266,
71-
"max": 17.97003189466,
45+
"mean": 18.76303972514667,
46+
"stddev": 0.10991428273642811,
47+
"median": 18.72587103648,
48+
"user": 20.692533679999997,
49+
"system": 1.3673248933333333,
50+
"min": 18.67652879848,
51+
"max": 18.886719340480003,
7252
"times": [
73-
17.97003189466,
74-
17.90388353266,
75-
17.95858265166
53+
18.67652879848,
54+
18.886719340480003,
55+
18.72587103648
7656
],
7757
"exit_codes": [
7858
0,
@@ -82,17 +62,17 @@
8262
},
8363
{
8464
"command": "gpgtar -d --yes --batch --gpg-args \"--passphrase 123456789\" test.gpg",
85-
"mean": 6.240754918993335,
86-
"stddev": 0.18841334623779463,
87-
"median": 6.18021860166,
88-
"user": 0.17699391333333328,
89-
"system": 1.4514090599999998,
90-
"min": 6.09005041466,
91-
"max": 6.45199574066,
65+
"mean": 6.573486912813334,
66+
"stddev": 0.3839886822791872,
67+
"median": 6.52200845048,
68+
"user": 0.21511468,
69+
"system": 1.4525625599999998,
70+
"min": 6.21783424048,
71+
"max": 6.98061804748,
9272
"times": [
93-
6.45199574066,
94-
6.18021860166,
95-
6.09005041466
73+
6.98061804748,
74+
6.52200845048,
75+
6.21783424048
9676
],
9777
"exit_codes": [
9878
0,

benchmark/encryption-time.webp

1.28 KB
Binary file not shown.

0 commit comments

Comments
 (0)