cryptovault-py 0.2.0__tar.gz
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.
- cryptovault_py-0.2.0/LICENSE-APACHE +201 -0
- cryptovault_py-0.2.0/LICENSE-MIT +21 -0
- cryptovault_py-0.2.0/PKG-INFO +259 -0
- cryptovault_py-0.2.0/README.md +236 -0
- cryptovault_py-0.2.0/pyproject.toml +130 -0
- cryptovault_py-0.2.0/pyproject.toml.orig +81 -0
- cryptovault_py-0.2.0/src/cryptovault/__init__.py +97 -0
- cryptovault_py-0.2.0/src/cryptovault/_blob.py +63 -0
- cryptovault_py-0.2.0/src/cryptovault/cipher.py +138 -0
- cryptovault_py-0.2.0/src/cryptovault/constants.py +85 -0
- cryptovault_py-0.2.0/src/cryptovault/error.py +76 -0
- cryptovault_py-0.2.0/src/cryptovault/fec/__init__.py +285 -0
- cryptovault_py-0.2.0/src/cryptovault/fec/_reedsolomon.py +302 -0
- cryptovault_py-0.2.0/src/cryptovault/fec/_viterbi.py +163 -0
- cryptovault_py-0.2.0/src/cryptovault/fec/interleaver.py +266 -0
- cryptovault_py-0.2.0/src/cryptovault/fec/rs.py +87 -0
- cryptovault_py-0.2.0/src/cryptovault/fec/viterbi.py +154 -0
- cryptovault_py-0.2.0/src/cryptovault/kdf.py +120 -0
- cryptovault_py-0.2.0/src/cryptovault/py.typed +0 -0
- cryptovault_py-0.2.0/src/cryptovault/vault.py +458 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file name or class name and description of purpose be included on
|
|
186
|
+
the same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Julian Bolivar
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Julian Bolivar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cryptovault-py
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Authenticated encryption byte-compatible with the cryptovault Rust crate: AES-256-GCM-SIV over Argon2id/HKDF.
|
|
5
|
+
Keywords: cryptography,aead,encryption,aes-gcm-siv,argon2
|
|
6
|
+
Author: Julian Bolivar
|
|
7
|
+
Author-email: Julian Bolivar <jbolivarg@gmail.com>
|
|
8
|
+
License-Expression: MIT OR Apache-2.0
|
|
9
|
+
License-File: LICENSE-APACHE
|
|
10
|
+
License-File: LICENSE-MIT
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Security :: Cryptography
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: cryptography>=45.0.1
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Project-URL: Repository, https://github.com/BolivarTech/CryptoVault-Python
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# CryptoVault-Python
|
|
25
|
+
|
|
26
|
+
**A Python implementation of the [`cryptovault`](https://github.com/BolivarTech/cryptovault)
|
|
27
|
+
blob format, byte-compatible with the Rust crate.** AES-256-GCM-SIV under an HKDF-SHA256 key,
|
|
28
|
+
Argon2id key derivation and DEK/KEK key wrapping, followed by the crate's forward-error
|
|
29
|
+
correction: Reed-Solomon, an interleaver and a Viterbi code, or no FEC at all.
|
|
30
|
+
|
|
31
|
+
> **Status: 0.2.0, alpha.** Every FEC strategy of `cryptovault` 0.3.0 is implemented and
|
|
32
|
+
> checked in both directions against the crate.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## What it does
|
|
37
|
+
|
|
38
|
+
Two services that share a 32-byte key can encrypt and authenticate messages for each other.
|
|
39
|
+
A blob made on either side opens on the other, Rust → Python and Python → Rust. The package
|
|
40
|
+
opens no connections and knows nothing about transports: it turns text or key material into
|
|
41
|
+
a blob and back, and the caller moves the blob.
|
|
42
|
+
|
|
43
|
+
The Rust crate stacks two independent layers: an AEAD that provides all of the security,
|
|
44
|
+
then an FEC that adds channel resilience and no security. Both are implemented here, with
|
|
45
|
+
the same four FEC strategies as the crate.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
pip install cryptovault-py
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The import name is `cryptovault`. [Requirements](#requirements) lists the supported Python versions and the `cryptography` and
|
|
54
|
+
OpenSSL floor.
|
|
55
|
+
|
|
56
|
+
## Quick start
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
>>> from cryptovault import CryptoVault, generate_dek, generate_salt
|
|
60
|
+
>>> vault = CryptoVault.default() # Argon2id + AES-256-GCM-SIV + concatenated FEC
|
|
61
|
+
|
|
62
|
+
>>> key = generate_dek() # or vault.derive_key(password, salt)
|
|
63
|
+
>>> blob = vault.encrypt_with_key(key, "sk-secret")
|
|
64
|
+
>>> vault.decrypt_with_key(key, blob)
|
|
65
|
+
'sk-secret'
|
|
66
|
+
|
|
67
|
+
>>> salt = generate_salt() # one per context, kept by the caller
|
|
68
|
+
>>> kek = generate_dek()
|
|
69
|
+
>>> dek = generate_dek()
|
|
70
|
+
>>> wrapped = vault.wrap_key(kek, salt, dek) # the salt is bound as AAD
|
|
71
|
+
>>> vault.unwrap_key(kek, salt, wrapped) == dek
|
|
72
|
+
True
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`CryptoVault.default()` matches `CryptoVault::default()` in Rust. To pick another FEC
|
|
77
|
+
strategy, compose the vault yourself; the constructor has no defaults:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
>>> from cryptovault import Aes256GcmSivCipher, Argon2Kdf, NoFec
|
|
81
|
+
>>> aead_only = CryptoVault(Argon2Kdf(), Aes256GcmSivCipher(), NoFec())
|
|
82
|
+
>>> aead_only.decrypt_with_key(key, aead_only.encrypt_with_key(key, "hi"))
|
|
83
|
+
'hi'
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`derive_key(password, salt)` runs Argon2id with the crate's OWASP-2025 profile (64 MiB, three
|
|
88
|
+
passes, four lanes). Call it once per session and keep the key.
|
|
89
|
+
|
|
90
|
+
### Blob layout
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
blob = base64( fec.encode( header ‖ nonce(12 B) ‖ ciphertext ‖ tag(16 B) ) ) standard, padded
|
|
94
|
+
header = version (0x01) ‖ plaintext_len (u32, little-endian)
|
|
95
|
+
key = HKDF-SHA256( salt = none, ikm = 32-byte master key, info = "cryptovault:v1:aead", L = 32 )
|
|
96
|
+
AAD = purpose ‖ header ‖ aad_extra
|
|
97
|
+
purpose = 0x01 data · 0x02 wrapped key
|
|
98
|
+
extra = empty for data · the salt for a wrapped key (authenticated, never stored)
|
|
99
|
+
cipher = AES-256-GCM-SIV, fresh random 12-byte nonce per message
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The header is bound as associated data, so changing any bit of it fails authentication. The purpose byte keeps a data blob from opening as a wrapped key, and
|
|
103
|
+
the other way round. As for the version byte, it leaves room for the format to evolve; today
|
|
104
|
+
only `0x01` is accepted.
|
|
105
|
+
|
|
106
|
+
## FEC strategies
|
|
107
|
+
|
|
108
|
+
The FEC layer sits after the AEAD and only helps a blob survive a noisy channel. Correction
|
|
109
|
+
is all or nothing. Within capacity the blob comes back exact; past it, decryption fails with
|
|
110
|
+
a typed error and never returns wrong plaintext, because the AEAD tag checks the result.
|
|
111
|
+
|
|
112
|
+
| Strategy | Pipeline | Corrects | Size of a 1 KiB message |
|
|
113
|
+
|---|---|---|---|
|
|
114
|
+
| `ConcatenatedFec.default()` | RS(255, 223) → depth-5 block interleaver → Viterbi K=7 R=1/2 | scattered bit errors and bursts | 3404 B |
|
|
115
|
+
| `ConcatenatedFec.with_csprng_from_master(master, depth)` | the same, plus a keyed shuffle per window | as above, weaker burst spreading | 3404 B |
|
|
116
|
+
| `ViterbiOnlyFec()` | Viterbi K=7 R=1/2 | scattered bit errors | 2824 B |
|
|
117
|
+
| `ReedSolomonCodec()` | RS(255, 223) | up to 16 bad bytes per 255-byte codeword | 1700 B |
|
|
118
|
+
| `NoFec()` | none | nothing; any change fails authentication | 1412 B |
|
|
119
|
+
|
|
120
|
+
The CSPRNG variant derives its seed from the master key with HKDF (`info =
|
|
121
|
+
"cryptovault:v1:interleaver"`), and both ends must build it from the same master and depth.
|
|
122
|
+
It is obfuscation, not security.
|
|
123
|
+
|
|
124
|
+
The codecs are pure Python, so they are much slower than the Rust crate. Measured with
|
|
125
|
+
CPython 3.11 on Windows:
|
|
126
|
+
|
|
127
|
+
| Strategy | Encrypt 128 KiB | Decrypt 128 KiB | Decrypt 128 KiB, one flipped bit | Decrypt 1 KiB, one flipped bit |
|
|
128
|
+
|---|---|---|---|---|
|
|
129
|
+
| `ConcatenatedFec` | 1.4 s | 1.7 s | 15.6 s | 0.16 s |
|
|
130
|
+
| `ViterbiOnlyFec` | 0.25 s | 0.66 s | 14.3 s | 0.12 s |
|
|
131
|
+
| `ReedSolomonCodec` | 1.1 s | 1.0 s | 0.82 s | 0.01 s |
|
|
132
|
+
| `NoFec` | < 0.01 s | < 0.01 s | fails, < 0.01 s | fails, < 0.01 s |
|
|
133
|
+
|
|
134
|
+
A clean Viterbi sub-block decodes directly. One with channel errors runs the full trellis,
|
|
135
|
+
which in Python costs about 12 µs per coded bit pair, or about 12 s for a full 124 950-byte
|
|
136
|
+
sub-block. Noisy channels carrying large messages pay that price.
|
|
137
|
+
|
|
138
|
+
## Security model
|
|
139
|
+
|
|
140
|
+
| Property | Mechanism | Level |
|
|
141
|
+
|---|---|---|
|
|
142
|
+
| Confidentiality | AES-256-GCM-SIV (RFC 8452) | 256-bit key |
|
|
143
|
+
| Integrity / authenticity | 128-bit GCM-SIV tag, header bound as AAD | forgery ≤ 2⁻¹²⁸ per message |
|
|
144
|
+
| Nonce-misuse resistance | SIV construction | a nonce collision reveals only plaintext equality |
|
|
145
|
+
| Key separation | HKDF-SHA256 with a fixed `info` label | the AEAD key is never the raw master key |
|
|
146
|
+
| Password hardening | Argon2id v1.3, m = 64 MiB, t = 3, p = 4 | OWASP 2025 profile |
|
|
147
|
+
| Context binding | salt and purpose bound as AAD on wrapped keys | wrong salt or purpose fails authentication |
|
|
148
|
+
| Typed failures | one exception class per failing stage, fixed messages | no input echoed in an error |
|
|
149
|
+
| Secret hygiene | no key, secret, blob or plaintext in errors, logs or `repr` | — |
|
|
150
|
+
|
|
151
|
+
All cryptographic primitives come from the [`cryptography`](https://cryptography.io/)
|
|
152
|
+
package. Nothing here is home-rolled crypto.
|
|
153
|
+
|
|
154
|
+
### Out of scope (what it does NOT defend against)
|
|
155
|
+
|
|
156
|
+
- **Weak passwords.** Argon2id slows guessing down; it does not make a weak password strong.
|
|
157
|
+
- **Replay.** A valid blob stays valid. Detecting repeats is the caller's protocol concern.
|
|
158
|
+
- **Traffic analysis.** The header carries the plaintext length in the clear, and the blob
|
|
159
|
+
size follows from it.
|
|
160
|
+
- **Channel errors past the FEC capacity.** The blob fails closed and never decrypts to
|
|
161
|
+
something wrong. With `NoFec`, a single flipped bit is enough.
|
|
162
|
+
- **Memory disclosure.** The crate wipes secrets from memory; Python's immutable `str` and
|
|
163
|
+
`bytes` cannot promise that, and this package does not try.
|
|
164
|
+
- **Host compromise.** A key in process memory is as safe as the process.
|
|
165
|
+
|
|
166
|
+
### Operational contracts (the caller must honor)
|
|
167
|
+
|
|
168
|
+
- **Use exactly 32 bytes of key.** A shorter or longer key is an error, not something the
|
|
169
|
+
package pads or truncates.
|
|
170
|
+
- **Use a fresh salt per context**, from `generate_salt()`. The same password and salt give
|
|
171
|
+
the same key.
|
|
172
|
+
- **Rate-limit `derive_key` for untrusted callers.** Each call costs 64 MiB and noticeable
|
|
173
|
+
CPU.
|
|
174
|
+
- **Rekey before ~2⁴⁸ messages per key.** That is the birthday bound for random 96-bit
|
|
175
|
+
nonces.
|
|
176
|
+
- **Decode with the same FEC strategy you encoded with.** A blob from a default Rust vault
|
|
177
|
+
opens with `CryptoVault.default()`; one from a `NoFec` vault needs a `NoFec` vault here.
|
|
178
|
+
- **Bound decrypt input from untrusted sources.** `with_max_blob_len(cap)` returns a vault
|
|
179
|
+
that rejects larger blobs before any decryption work. With FEC this also bounds the decode
|
|
180
|
+
time, which grows with the number of corrupted Viterbi sub-blocks.
|
|
181
|
+
- **One blob, one message.** Framing and delivery belong to the caller.
|
|
182
|
+
|
|
183
|
+
## Errors
|
|
184
|
+
|
|
185
|
+
Every failure is a `CryptoVaultError`. The subclass names the stage that failed, and `str()`
|
|
186
|
+
matches the crate's `Display` for the same input, word for word:
|
|
187
|
+
|
|
188
|
+
| Class | Raised for |
|
|
189
|
+
|---|---|
|
|
190
|
+
| `InvalidInputError` | wrong key, salt or seed length, empty password, interleave depth out of range, oversized input, malformed blob, unknown version |
|
|
191
|
+
| `EncodingError` | non-canonical base64, text that is not valid UTF-8 |
|
|
192
|
+
| `CipherError` | a tag that does not verify (wrong key, salt or purpose, any tampering) |
|
|
193
|
+
| `KeyDerivationError` | Argon2id failure, or no OS entropy for a salt or DEK |
|
|
194
|
+
| `ErrorCorrectionError` | corruption beyond the Reed-Solomon capacity, or no ChaCha20 in the backend for the CSPRNG layer |
|
|
195
|
+
|
|
196
|
+
## Compatibility testing
|
|
197
|
+
|
|
198
|
+
The test suite replays reference data that the crate itself produced. For `NoFec`: its
|
|
199
|
+
constants, data blobs up to 128 KiB, wrapped keys, Argon2id outputs, and the exact error for
|
|
200
|
+
358 adversarial inputs (every single-bit flip of a blob, truncations, bad versions and
|
|
201
|
+
lengths, non-canonical base64, wrong keys and salts, invalid UTF-8). For the FEC layer: the
|
|
202
|
+
Reed-Solomon codewords and the outcome of 146 corrupted decodes, the interleaver
|
|
203
|
+
permutations (the CSPRNG layer included), Viterbi encodings and 26 corrupted decodes down to
|
|
204
|
+
the wrong bytes a heavily damaged stream decodes to, and 335 adversarial blobs under three
|
|
205
|
+
strategies (sampled bit flips, bursts, truncation, rewritten headers, wrong keys and salts).
|
|
206
|
+
In the other direction, a second test hands the crate blobs made in Python under every
|
|
207
|
+
strategy and checks that it opens each one. The generator lives in `interop/rust`:
|
|
208
|
+
|
|
209
|
+
```sh
|
|
210
|
+
uv run pytest # full suite, Rust fixtures included
|
|
211
|
+
uv run pytest -m interop # Python → Rust; needs the Rust toolchain
|
|
212
|
+
cargo run --release --manifest-path interop/rust/Cargo.toml -- fixtures \
|
|
213
|
+
> tests/fixtures/rust_nofec.json # regenerate the NoFec fixtures
|
|
214
|
+
cargo run --release --manifest-path interop/rust/Cargo.toml -- fec-fixtures \
|
|
215
|
+
> tests/fixtures/rust_fec.json # regenerate the FEC fixtures
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Requirements
|
|
219
|
+
|
|
220
|
+
- **Python 3.11** or newer. Tested on Linux and Windows with 3.11 and 3.14.
|
|
221
|
+
- **`cryptography` 45.0.1 or newer**, linked against **OpenSSL 3.2 or newer** (AES-GCM-SIV and
|
|
222
|
+
Argon2id need it; the CSPRNG layer also uses its ChaCha20). Releases before 45.0.1 reject an empty plaintext, which the crate allows.
|
|
223
|
+
The official wheels qualify.
|
|
224
|
+
|
|
225
|
+
## Development
|
|
226
|
+
|
|
227
|
+
```sh
|
|
228
|
+
uv sync --locked
|
|
229
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy . && uv run pytest
|
|
230
|
+
uv run pip-audit
|
|
231
|
+
uv build
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Roadmap
|
|
235
|
+
|
|
236
|
+
1. **`NoFec` blob format, Argon2id and key wrapping.** Implemented and cross-checked against
|
|
237
|
+
the crate in both directions.
|
|
238
|
+
2. **The FEC strategies.** Reed-Solomon, the interleaver and Viterbi, so any `cryptovault`
|
|
239
|
+
blob can be read from Python. Implemented and cross-checked in both directions.
|
|
240
|
+
3. **A compiled FEC accelerator.** The codecs are pure Python, and a damaged sub-block runs
|
|
241
|
+
the full Viterbi trellis at about 12 µs per stage: a 128 KiB blob with one flipped bit takes
|
|
242
|
+
about 15 s to decrypt. The plan is an optional Rust extension (PyO3) that wraps the same
|
|
243
|
+
`reedsolomon` and `viterbi` crates the reference crate uses, with the pure-Python codecs
|
|
244
|
+
kept as the fallback where no wheel exists. The crate fixtures stay as its parity check.
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
Licensed under either of
|
|
249
|
+
|
|
250
|
+
- **MIT** license ([LICENSE-MIT](LICENSE-MIT)), or
|
|
251
|
+
- **Apache License, Version 2.0** ([LICENSE-APACHE](LICENSE-APACHE))
|
|
252
|
+
|
|
253
|
+
at your option.
|
|
254
|
+
|
|
255
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted for
|
|
256
|
+
inclusion in this package by you, as defined in the Apache-2.0 license, shall be
|
|
257
|
+
dual-licensed as above, without any additional terms or conditions.
|
|
258
|
+
|
|
259
|
+
Copyright © 2026 Julian Bolivar / BolivarTech.
|