sk-pqc 0.1.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.
- sk_pqc-0.1.0/.gitignore +7 -0
- sk_pqc-0.1.0/LICENSE +202 -0
- sk_pqc-0.1.0/PKG-INFO +161 -0
- sk_pqc-0.1.0/README.md +133 -0
- sk_pqc-0.1.0/pyproject.toml +65 -0
- sk_pqc-0.1.0/src/sk_pqc/__init__.py +169 -0
- sk_pqc-0.1.0/src/sk_pqc/anon_queue.py +229 -0
- sk_pqc-0.1.0/src/sk_pqc/crypto_suites.py +316 -0
- sk_pqc-0.1.0/src/sk_pqc/dm_ratchet.py +268 -0
- sk_pqc-0.1.0/src/sk_pqc/group_ratchet.py +312 -0
- sk_pqc-0.1.0/src/sk_pqc/pqdm.py +374 -0
- sk_pqc-0.1.0/src/sk_pqc/pqkem.py +346 -0
- sk_pqc-0.1.0/src/sk_pqc/pqroute.py +332 -0
- sk_pqc-0.1.0/tests/conftest.py +16 -0
- sk_pqc-0.1.0/tests/test_anon_queue.py +145 -0
- sk_pqc-0.1.0/tests/test_crypto_suites.py +89 -0
- sk_pqc-0.1.0/tests/test_dm_ratchet.py +132 -0
- sk_pqc-0.1.0/tests/test_group_ratchet.py +152 -0
- sk_pqc-0.1.0/tests/test_pqdm.py +140 -0
- sk_pqc-0.1.0/tests/test_pqkem.py +294 -0
- sk_pqc-0.1.0/tests/test_pqroute.py +168 -0
- sk_pqc-0.1.0/tests/vectors/hybrid_kem_x25519_mlkem768.json +41 -0
sk_pqc-0.1.0/.gitignore
ADDED
sk_pqc-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
sk_pqc-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sk-pqc
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sovereign, app-agnostic hybrid post-quantum crypto primitives: hybrid X25519+ML-KEM-768 KEM (FIPS 203), PQXDH-style seal, metadata-sealing routing envelope, epoch ratchets, crypto-agility registry. Python sibling of the Dart sk_pqc.
|
|
5
|
+
Project-URL: Homepage, https://github.com/smilinTux/sk-pqc-py
|
|
6
|
+
Project-URL: Dart sibling, https://github.com/smilinTux/sk_pqc
|
|
7
|
+
Project-URL: Standards, https://github.com/smilinTux/sk-standards
|
|
8
|
+
Author: smilinTux / SKWorld
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: FIPS-203,ML-KEM,crypto-agility,hybrid,post-quantum,ratchet,sovereign
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Security :: Cryptography
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: cryptography>=42.0
|
|
22
|
+
Provides-Extra: pq
|
|
23
|
+
Requires-Dist: liboqs-python>=0.12; extra == 'pq'
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: liboqs-python>=0.12; extra == 'test'
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'test'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# sk-pqc (Python)
|
|
30
|
+
|
|
31
|
+
> ⚠️ **Experimental · pre-1.0 · NOT independently security-audited.** This is a clean-room
|
|
32
|
+
> **reference implementation** — tested and cross-impl-parity-verified against our Rust
|
|
33
|
+
> (`sk-core`) and Dart (`sk_pqc`) builds, but it has had **no third-party security audit,
|
|
34
|
+
> fuzzing, or formal review**. Primitives bind vetted libraries (`liboqs`/ML-KEM,
|
|
35
|
+
> `cryptography`); the original code is the wiring. **Review it yourself before production
|
|
36
|
+
> use.** We apply our own honest-claims discipline to the library itself: don't trust it
|
|
37
|
+
> beyond the evidence.
|
|
38
|
+
|
|
39
|
+
**`sk-pqc` is a small, app-agnostic Python library of vetted *hybrid post-quantum* cryptographic primitives.**
|
|
40
|
+
**Use it to add hybrid X25519 + ML-KEM-768 (FIPS 203) confidentiality to any app — without dragging in a messaging framework.**
|
|
41
|
+
|
|
42
|
+
It is the Python sibling of the public Dart [`sk_pqc`](https://github.com/smilinTux/sk_pqc) package and is **byte-for-byte interoperable** with it (shared cross-impl KAT vector). Import name `sk_pqc`; PyPI name `sk-pqc`.
|
|
43
|
+
|
|
44
|
+
- **Maturity tier:** T2 — Hybrid KEM (key exchange/wrap is `HKDF(X25519 ‖ ML-KEM-768)`; signatures stay classical/optional-hybrid). Per [sk-standards CRYPTOGRAPHY_STANDARD](https://github.com/smilinTux/sk-standards).
|
|
45
|
+
- **License:** Apache-2.0 · **Python:** ≥ 3.10 · **Version:** 0.1.0
|
|
46
|
+
|
|
47
|
+
> **Honest claim.** "Hybrid" means a derived secret is confidential if **EITHER** the classical X25519 leg **OR** the ML-KEM-768 leg holds — it survives a future cryptographically-relevant quantum computer breaking X25519, and it survives a classical break of ML-KEM. It is **not** "quantum-proof", "quantum-safe", or "unbreakable". AES-256-GCM (the bulk cipher) is symmetric / Grover-only and already quantum-acceptable. Citations: **FIPS 203** (ML-KEM), **FIPS 204** (ML-DSA, registry only), RFC 7748 (X25519), RFC 5869 (HKDF), SP 800-38D (AES-GCM).
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## What's in the box
|
|
52
|
+
|
|
53
|
+
| Module | Primitive | What it gives you |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `sk_pqc.pqkem` | **Hybrid KEM** `x25519-mlkem768` | `hybrid_keypair / hybrid_encap / hybrid_decap`. ML-KEM-768 leg = liboqs (`oqs`), X25519 leg + HKDF combiner = pyca `cryptography`. The combiner is the only original crypto: `HKDF-SHA256(X25519_ss ‖ MLKEM768_ss)` — **concat-then-KDF, never XOR, never pure-PQ**. |
|
|
56
|
+
| `sk_pqc.pqdm` | **PQXDH-style seal** | `seal / open_sealed` a body to a recipient's published hybrid prekey (`PrekeyBundle`), AES-256-GCM under a KEM-derived key, with a **downgrade-lock AAD** that makes silent classical downgrade detectable. |
|
|
57
|
+
| `sk_pqc.pqroute` | **Metadata-sealing routing envelope** `pqroute1` | `seal_routed / open_routed / read_route_header`. Splits a plaintext next-hop header (a relay reads it, but it is AEAD-bound / tamper-evident) from a hybrid-sealed inner (final destination + content) a relay cannot read. |
|
|
58
|
+
| `sk_pqc.group_ratchet` | **Group epoch ratchet** | Per-epoch secret distributed once via the hybrid KEM; per-message keys derived symmetrically + index-addressable (loss/reorder tolerant). Forward secrecy across epochs, post-compromise security from independent epoch secrets. |
|
|
59
|
+
| `sk_pqc.dm_ratchet` | **1:1 DM epoch ratchet** | The pairwise analogue of the group ratchet (distinct HKDF domain labels — a DM key can never collide with a group key). |
|
|
60
|
+
| `sk_pqc.anon_queue` | **Anon-queue addressing + deniable auth** | `new_queue_pair` (uncorrelated recipient/sender ids), the `aqid:` address codec, and a repudiable `HMAC-SHA256` authenticator. Addressing + deniable-auth **only** — not a transport. |
|
|
61
|
+
| `sk_pqc.crypto_suites` | **Crypto-agility registry** | Machine-readable suite-ids → primitives + quantum-resistance status + FIPS refs. The honest predicate `is_quantum_resistant(suite_id)` no caller should hand-roll. |
|
|
62
|
+
|
|
63
|
+
**Never silently downgrades.** If the liboqs backend is missing, hybrid operations raise `PqKemUnavailable` (a hard error). The pure-pyca pieces — combiner KAT, suite registry, anon-queue codec/MAC, key derivation — work with no PQ backend at all.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Architecture
|
|
68
|
+
|
|
69
|
+
```mermaid
|
|
70
|
+
flowchart TD
|
|
71
|
+
subgraph backends["Vetted backends — no hand-rolled math"]
|
|
72
|
+
OQS["liboqs (oqs)<br/>ML-KEM-768 · FIPS 203"]
|
|
73
|
+
PYCA["pyca/cryptography<br/>X25519 · HKDF-SHA256 · AES-256-GCM"]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
OQS --> KEM
|
|
77
|
+
PYCA --> KEM
|
|
78
|
+
|
|
79
|
+
KEM["pqkem<br/>hybrid X25519 ‖ ML-KEM-768 KEM<br/>HKDF(X25519_ss ‖ MLKEM_ss)"]
|
|
80
|
+
|
|
81
|
+
KEM --> DM["pqdm<br/>PQXDH-style seal<br/>(downgrade-lock AAD)"]
|
|
82
|
+
KEM --> ROUTE["pqroute1<br/>metadata-sealing<br/>routing envelope"]
|
|
83
|
+
KEM --> GR["group_ratchet<br/>per-epoch group keys"]
|
|
84
|
+
KEM --> DMR["dm_ratchet<br/>per-epoch 1:1 DM keys"]
|
|
85
|
+
|
|
86
|
+
REG["crypto_suites<br/>agility registry<br/>+ honest self-report"]
|
|
87
|
+
AQ["anon_queue<br/>aqid: addressing<br/>+ deniable HMAC auth"]
|
|
88
|
+
|
|
89
|
+
REG -. "describes / status" .-> KEM
|
|
90
|
+
REG -. "describes / status" .-> DM
|
|
91
|
+
|
|
92
|
+
KEM --> VEC{{"cross-impl KAT vector<br/>↔ Dart sk_pqc"}}
|
|
93
|
+
|
|
94
|
+
classDef prim fill:#e6f0ff,stroke:#369;
|
|
95
|
+
classDef be fill:#eee,stroke:#999;
|
|
96
|
+
class KEM,DM,ROUTE,GR,DMR,REG,AQ prim;
|
|
97
|
+
class OQS,PYCA be;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Install
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Core (pure-pyca pieces work; hybrid KEM needs the pq extra)
|
|
106
|
+
pip install sk-pqc
|
|
107
|
+
|
|
108
|
+
# With the post-quantum (ML-KEM-768) leg via liboqs
|
|
109
|
+
pip install "sk-pqc[pq]"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
> The ML-KEM leg uses [`liboqs-python`](https://github.com/open-quantum-safe/liboqs-python) (import name `oqs`), which binds the native liboqs. Point `oqs` at a prebuilt `liboqs.so` with `OQS_INSTALL_PATH` (or `SK_PQC_LIBOQS`) to avoid a source build — `sk_pqc.pqkem.ensure_liboqs_path()` applies this best-effort on import.
|
|
113
|
+
|
|
114
|
+
## Quickstart
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from sk_pqc import hybrid_keypair, hybrid_encap, hybrid_decap
|
|
118
|
+
|
|
119
|
+
kp = hybrid_keypair() # 1216 B pub, 2432 B priv
|
|
120
|
+
ct, ss_sender = hybrid_encap(kp.public_key) # 1120 B ciphertext + 32 B secret
|
|
121
|
+
ss_recipient = hybrid_decap(ct, kp.private_key)
|
|
122
|
+
assert ss_sender == ss_recipient # secure if EITHER leg holds
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from sk_pqc import PrekeyBundle, seal, open_sealed, SUITE_ID
|
|
127
|
+
|
|
128
|
+
bundle = PrekeyBundle(suite=SUITE_ID, hybrid_public_hex=kp.public_key.hex())
|
|
129
|
+
blob = seal(b"top secret", bundle, sender="alice", recipient="bob")
|
|
130
|
+
assert open_sealed(blob, kp.private_key, sender="alice", recipient="bob") == b"top secret"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Test
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# From a checkout (run from HOME to avoid local-namespace collisions)
|
|
137
|
+
cd ~ && python -m pytest /path/to/sk-pqc-py/tests -q
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The cross-implementation interop gate (`test_pqkem.py::test_cross_impl_vector_matches_sk_pqc`) decapsulates the shared Dart/Python KAT vector and asserts the recorded shared secret — this is what proves the two implementations agree byte-for-byte. PQ tests skip cleanly if liboqs is unavailable; the pure-pyca combiner KAT + registry tests always run.
|
|
141
|
+
|
|
142
|
+
## Self-report (claim evidence)
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from sk_pqc import get_suite, is_quantum_resistant
|
|
146
|
+
s = get_suite("x25519-mlkem768")
|
|
147
|
+
print(s.status.value, s.fips_refs, is_quantum_resistant("x25519-mlkem768"))
|
|
148
|
+
# hybrid-pq ('FIPS 203', 'RFC 7748', 'RFC 5869') True
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Provenance / clean-room
|
|
152
|
+
|
|
153
|
+
The `pqroute1` routing split and the `anon_queue` addressing are inspired by the *shape* of mix/relay designs (incl. SimpleX, AGPL-3.0) — **clean-room: no third-party code was copied or translated**, only the protocol idea. The wire formats, codecs, and MAC constructions are original and built solely on the vetted backends above.
|
|
154
|
+
|
|
155
|
+
## Related projects / See also
|
|
156
|
+
|
|
157
|
+
- ↔️ **Sibling:** [sk_pqc](https://github.com/smilinTux/sk_pqc) — the Dart hybrid-KEM companion this package interoperates with (shared KAT vector).
|
|
158
|
+
- ⬇️ **Used by:** [skcomms](https://github.com/smilinTux/skcomms) — sovereign multi-transport comms (envelope payload + routing seal).
|
|
159
|
+
- ⬇️ **Used by:** [skchat](https://github.com/smilinTux/skchat) — AI-native encrypted chat (group + 1:1 DM ratchets).
|
|
160
|
+
- ↔️ **Sibling:** [sk_pgp](https://github.com/smilinTux/sk_pgp) — sovereign OpenPGP-PQC signing library (the signature counterpart).
|
|
161
|
+
- 📐 **Standards:** [sk-standards](https://github.com/smilinTux/sk-standards) — crypto, data-flow, version, and doc/SOP standards this repo conforms to.
|
sk_pqc-0.1.0/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# sk-pqc (Python)
|
|
2
|
+
|
|
3
|
+
> ⚠️ **Experimental · pre-1.0 · NOT independently security-audited.** This is a clean-room
|
|
4
|
+
> **reference implementation** — tested and cross-impl-parity-verified against our Rust
|
|
5
|
+
> (`sk-core`) and Dart (`sk_pqc`) builds, but it has had **no third-party security audit,
|
|
6
|
+
> fuzzing, or formal review**. Primitives bind vetted libraries (`liboqs`/ML-KEM,
|
|
7
|
+
> `cryptography`); the original code is the wiring. **Review it yourself before production
|
|
8
|
+
> use.** We apply our own honest-claims discipline to the library itself: don't trust it
|
|
9
|
+
> beyond the evidence.
|
|
10
|
+
|
|
11
|
+
**`sk-pqc` is a small, app-agnostic Python library of vetted *hybrid post-quantum* cryptographic primitives.**
|
|
12
|
+
**Use it to add hybrid X25519 + ML-KEM-768 (FIPS 203) confidentiality to any app — without dragging in a messaging framework.**
|
|
13
|
+
|
|
14
|
+
It is the Python sibling of the public Dart [`sk_pqc`](https://github.com/smilinTux/sk_pqc) package and is **byte-for-byte interoperable** with it (shared cross-impl KAT vector). Import name `sk_pqc`; PyPI name `sk-pqc`.
|
|
15
|
+
|
|
16
|
+
- **Maturity tier:** T2 — Hybrid KEM (key exchange/wrap is `HKDF(X25519 ‖ ML-KEM-768)`; signatures stay classical/optional-hybrid). Per [sk-standards CRYPTOGRAPHY_STANDARD](https://github.com/smilinTux/sk-standards).
|
|
17
|
+
- **License:** Apache-2.0 · **Python:** ≥ 3.10 · **Version:** 0.1.0
|
|
18
|
+
|
|
19
|
+
> **Honest claim.** "Hybrid" means a derived secret is confidential if **EITHER** the classical X25519 leg **OR** the ML-KEM-768 leg holds — it survives a future cryptographically-relevant quantum computer breaking X25519, and it survives a classical break of ML-KEM. It is **not** "quantum-proof", "quantum-safe", or "unbreakable". AES-256-GCM (the bulk cipher) is symmetric / Grover-only and already quantum-acceptable. Citations: **FIPS 203** (ML-KEM), **FIPS 204** (ML-DSA, registry only), RFC 7748 (X25519), RFC 5869 (HKDF), SP 800-38D (AES-GCM).
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## What's in the box
|
|
24
|
+
|
|
25
|
+
| Module | Primitive | What it gives you |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `sk_pqc.pqkem` | **Hybrid KEM** `x25519-mlkem768` | `hybrid_keypair / hybrid_encap / hybrid_decap`. ML-KEM-768 leg = liboqs (`oqs`), X25519 leg + HKDF combiner = pyca `cryptography`. The combiner is the only original crypto: `HKDF-SHA256(X25519_ss ‖ MLKEM768_ss)` — **concat-then-KDF, never XOR, never pure-PQ**. |
|
|
28
|
+
| `sk_pqc.pqdm` | **PQXDH-style seal** | `seal / open_sealed` a body to a recipient's published hybrid prekey (`PrekeyBundle`), AES-256-GCM under a KEM-derived key, with a **downgrade-lock AAD** that makes silent classical downgrade detectable. |
|
|
29
|
+
| `sk_pqc.pqroute` | **Metadata-sealing routing envelope** `pqroute1` | `seal_routed / open_routed / read_route_header`. Splits a plaintext next-hop header (a relay reads it, but it is AEAD-bound / tamper-evident) from a hybrid-sealed inner (final destination + content) a relay cannot read. |
|
|
30
|
+
| `sk_pqc.group_ratchet` | **Group epoch ratchet** | Per-epoch secret distributed once via the hybrid KEM; per-message keys derived symmetrically + index-addressable (loss/reorder tolerant). Forward secrecy across epochs, post-compromise security from independent epoch secrets. |
|
|
31
|
+
| `sk_pqc.dm_ratchet` | **1:1 DM epoch ratchet** | The pairwise analogue of the group ratchet (distinct HKDF domain labels — a DM key can never collide with a group key). |
|
|
32
|
+
| `sk_pqc.anon_queue` | **Anon-queue addressing + deniable auth** | `new_queue_pair` (uncorrelated recipient/sender ids), the `aqid:` address codec, and a repudiable `HMAC-SHA256` authenticator. Addressing + deniable-auth **only** — not a transport. |
|
|
33
|
+
| `sk_pqc.crypto_suites` | **Crypto-agility registry** | Machine-readable suite-ids → primitives + quantum-resistance status + FIPS refs. The honest predicate `is_quantum_resistant(suite_id)` no caller should hand-roll. |
|
|
34
|
+
|
|
35
|
+
**Never silently downgrades.** If the liboqs backend is missing, hybrid operations raise `PqKemUnavailable` (a hard error). The pure-pyca pieces — combiner KAT, suite registry, anon-queue codec/MAC, key derivation — work with no PQ backend at all.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Architecture
|
|
40
|
+
|
|
41
|
+
```mermaid
|
|
42
|
+
flowchart TD
|
|
43
|
+
subgraph backends["Vetted backends — no hand-rolled math"]
|
|
44
|
+
OQS["liboqs (oqs)<br/>ML-KEM-768 · FIPS 203"]
|
|
45
|
+
PYCA["pyca/cryptography<br/>X25519 · HKDF-SHA256 · AES-256-GCM"]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
OQS --> KEM
|
|
49
|
+
PYCA --> KEM
|
|
50
|
+
|
|
51
|
+
KEM["pqkem<br/>hybrid X25519 ‖ ML-KEM-768 KEM<br/>HKDF(X25519_ss ‖ MLKEM_ss)"]
|
|
52
|
+
|
|
53
|
+
KEM --> DM["pqdm<br/>PQXDH-style seal<br/>(downgrade-lock AAD)"]
|
|
54
|
+
KEM --> ROUTE["pqroute1<br/>metadata-sealing<br/>routing envelope"]
|
|
55
|
+
KEM --> GR["group_ratchet<br/>per-epoch group keys"]
|
|
56
|
+
KEM --> DMR["dm_ratchet<br/>per-epoch 1:1 DM keys"]
|
|
57
|
+
|
|
58
|
+
REG["crypto_suites<br/>agility registry<br/>+ honest self-report"]
|
|
59
|
+
AQ["anon_queue<br/>aqid: addressing<br/>+ deniable HMAC auth"]
|
|
60
|
+
|
|
61
|
+
REG -. "describes / status" .-> KEM
|
|
62
|
+
REG -. "describes / status" .-> DM
|
|
63
|
+
|
|
64
|
+
KEM --> VEC{{"cross-impl KAT vector<br/>↔ Dart sk_pqc"}}
|
|
65
|
+
|
|
66
|
+
classDef prim fill:#e6f0ff,stroke:#369;
|
|
67
|
+
classDef be fill:#eee,stroke:#999;
|
|
68
|
+
class KEM,DM,ROUTE,GR,DMR,REG,AQ prim;
|
|
69
|
+
class OQS,PYCA be;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Install
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Core (pure-pyca pieces work; hybrid KEM needs the pq extra)
|
|
78
|
+
pip install sk-pqc
|
|
79
|
+
|
|
80
|
+
# With the post-quantum (ML-KEM-768) leg via liboqs
|
|
81
|
+
pip install "sk-pqc[pq]"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
> The ML-KEM leg uses [`liboqs-python`](https://github.com/open-quantum-safe/liboqs-python) (import name `oqs`), which binds the native liboqs. Point `oqs` at a prebuilt `liboqs.so` with `OQS_INSTALL_PATH` (or `SK_PQC_LIBOQS`) to avoid a source build — `sk_pqc.pqkem.ensure_liboqs_path()` applies this best-effort on import.
|
|
85
|
+
|
|
86
|
+
## Quickstart
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from sk_pqc import hybrid_keypair, hybrid_encap, hybrid_decap
|
|
90
|
+
|
|
91
|
+
kp = hybrid_keypair() # 1216 B pub, 2432 B priv
|
|
92
|
+
ct, ss_sender = hybrid_encap(kp.public_key) # 1120 B ciphertext + 32 B secret
|
|
93
|
+
ss_recipient = hybrid_decap(ct, kp.private_key)
|
|
94
|
+
assert ss_sender == ss_recipient # secure if EITHER leg holds
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from sk_pqc import PrekeyBundle, seal, open_sealed, SUITE_ID
|
|
99
|
+
|
|
100
|
+
bundle = PrekeyBundle(suite=SUITE_ID, hybrid_public_hex=kp.public_key.hex())
|
|
101
|
+
blob = seal(b"top secret", bundle, sender="alice", recipient="bob")
|
|
102
|
+
assert open_sealed(blob, kp.private_key, sender="alice", recipient="bob") == b"top secret"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Test
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# From a checkout (run from HOME to avoid local-namespace collisions)
|
|
109
|
+
cd ~ && python -m pytest /path/to/sk-pqc-py/tests -q
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The cross-implementation interop gate (`test_pqkem.py::test_cross_impl_vector_matches_sk_pqc`) decapsulates the shared Dart/Python KAT vector and asserts the recorded shared secret — this is what proves the two implementations agree byte-for-byte. PQ tests skip cleanly if liboqs is unavailable; the pure-pyca combiner KAT + registry tests always run.
|
|
113
|
+
|
|
114
|
+
## Self-report (claim evidence)
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from sk_pqc import get_suite, is_quantum_resistant
|
|
118
|
+
s = get_suite("x25519-mlkem768")
|
|
119
|
+
print(s.status.value, s.fips_refs, is_quantum_resistant("x25519-mlkem768"))
|
|
120
|
+
# hybrid-pq ('FIPS 203', 'RFC 7748', 'RFC 5869') True
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Provenance / clean-room
|
|
124
|
+
|
|
125
|
+
The `pqroute1` routing split and the `anon_queue` addressing are inspired by the *shape* of mix/relay designs (incl. SimpleX, AGPL-3.0) — **clean-room: no third-party code was copied or translated**, only the protocol idea. The wire formats, codecs, and MAC constructions are original and built solely on the vetted backends above.
|
|
126
|
+
|
|
127
|
+
## Related projects / See also
|
|
128
|
+
|
|
129
|
+
- ↔️ **Sibling:** [sk_pqc](https://github.com/smilinTux/sk_pqc) — the Dart hybrid-KEM companion this package interoperates with (shared KAT vector).
|
|
130
|
+
- ⬇️ **Used by:** [skcomms](https://github.com/smilinTux/skcomms) — sovereign multi-transport comms (envelope payload + routing seal).
|
|
131
|
+
- ⬇️ **Used by:** [skchat](https://github.com/smilinTux/skchat) — AI-native encrypted chat (group + 1:1 DM ratchets).
|
|
132
|
+
- ↔️ **Sibling:** [sk_pgp](https://github.com/smilinTux/sk_pgp) — sovereign OpenPGP-PQC signing library (the signature counterpart).
|
|
133
|
+
- 📐 **Standards:** [sk-standards](https://github.com/smilinTux/sk-standards) — crypto, data-flow, version, and doc/SOP standards this repo conforms to.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sk-pqc"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Sovereign, app-agnostic hybrid post-quantum crypto primitives: hybrid X25519+ML-KEM-768 KEM (FIPS 203), PQXDH-style seal, metadata-sealing routing envelope, epoch ratchets, crypto-agility registry. Python sibling of the Dart sk_pqc."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
authors = [{ name = "smilinTux / SKWorld" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"post-quantum",
|
|
15
|
+
"ML-KEM",
|
|
16
|
+
"FIPS-203",
|
|
17
|
+
"hybrid",
|
|
18
|
+
"ratchet",
|
|
19
|
+
"crypto-agility",
|
|
20
|
+
"sovereign",
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 3 - Alpha",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"License :: OSI Approved :: Apache Software License",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.10",
|
|
28
|
+
"Programming Language :: Python :: 3.11",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Topic :: Security :: Cryptography",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
# Core dependency: pyca/cryptography supplies the X25519 leg, HKDF combiner, and
|
|
34
|
+
# AES-256-GCM bulk cipher. The ML-KEM-768 leg needs liboqs (via the `oqs` import
|
|
35
|
+
# from `liboqs-python`) — installed via the `pq` extra below, since it pulls a
|
|
36
|
+
# native library. Without it the pure-pyca pieces (combiner, suite registry,
|
|
37
|
+
# anon-queue codec/MAC, key derivation) still work; hybrid KEM operations raise
|
|
38
|
+
# PqKemUnavailable (a hard error — never a silent classical downgrade).
|
|
39
|
+
dependencies = [
|
|
40
|
+
"cryptography>=42.0",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
# Enables the post-quantum (ML-KEM-768) leg. `liboqs-python` exposes the `oqs`
|
|
45
|
+
# import name and binds liboqs (FIPS 203).
|
|
46
|
+
pq = ["liboqs-python>=0.12"]
|
|
47
|
+
test = [
|
|
48
|
+
"pytest>=8.0",
|
|
49
|
+
"liboqs-python>=0.12",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/smilinTux/sk-pqc-py"
|
|
54
|
+
"Dart sibling" = "https://github.com/smilinTux/sk_pqc"
|
|
55
|
+
Standards = "https://github.com/smilinTux/sk-standards"
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.wheel]
|
|
58
|
+
packages = ["src/sk_pqc"]
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build.targets.sdist]
|
|
61
|
+
include = ["src/sk_pqc", "tests", "README.md", "LICENSE"]
|
|
62
|
+
|
|
63
|
+
[tool.pytest.ini_options]
|
|
64
|
+
testpaths = ["tests"]
|
|
65
|
+
addopts = "-q"
|