wirekx 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.
@@ -0,0 +1,27 @@
1
+ name: Publish to PyPI
2
+ on:
3
+ release:
4
+ types: [published]
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ - uses: actions/setup-python@v5
12
+ with: { python-version: "3.12" }
13
+ - run: pip install build
14
+ - run: python -m build
15
+ - uses: actions/upload-artifact@v4
16
+ with: { name: dist, path: dist/ }
17
+
18
+ publish:
19
+ needs: build
20
+ runs-on: ubuntu-latest
21
+ environment: pypi
22
+ permissions:
23
+ id-token: write # required for OIDC trusted publishing
24
+ steps:
25
+ - uses: actions/download-artifact@v4
26
+ with: { name: dist, path: dist/ }
27
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,26 @@
1
+ name: tests
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: ["main"]
7
+
8
+ jobs:
9
+ pytest:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.11", "3.12"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+
22
+ - name: Install
23
+ run: python -m pip install -e ".[dev]"
24
+
25
+ - name: Test
26
+ run: python -m pytest
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ .DS_Store
11
+ pub_pypi/
@@ -0,0 +1,26 @@
1
+ # Contributing
2
+
3
+ Thanks for considering a contribution to wirekx.
4
+
5
+ ## Development setup
6
+
7
+ ```bash
8
+ python3 -m venv .venv
9
+ .venv/bin/python -m pip install -e ".[dev]"
10
+ ```
11
+
12
+ ## Tests
13
+
14
+ ```bash
15
+ .venv/bin/python -m pytest
16
+ ```
17
+
18
+ ## Security scope
19
+
20
+ wirekx v1 anonymous mode is experimental and opportunistic. It does not
21
+ authenticate peers and is not production-ready. Please do not submit changes
22
+ that describe v1 anonymous mode as a replacement for TLS, mTLS, service mesh
23
+ security, or audited production cryptography.
24
+
25
+ Security improvements are welcome, especially authenticated modes, replay
26
+ protection, and well-tested payload encryption APIs.
wirekx-0.1.0/LICENSE ADDED
@@ -0,0 +1,185 @@
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, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work (an example is provided in the Appendix
36
+ below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
39
+ is based on (or derived from) the Work and for which the editorial revisions,
40
+ annotations, elaborations, or other modifications represent, as a whole, an
41
+ original work of authorship. For the purposes of this License, Derivative Works
42
+ shall not include works that remain separable from, or merely link (or bind by
43
+ name) to the interfaces of, the Work and Derivative Works thereof.
44
+
45
+ "Contribution" shall mean any work of authorship, including the original version
46
+ of the Work and any modifications or additions to that Work or Derivative Works
47
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
48
+ by the copyright owner or by an individual or Legal Entity authorized to submit
49
+ on behalf of the copyright owner. For the purposes of this definition,
50
+ "submitted" means any form of electronic, verbal, or written communication sent
51
+ to the Licensor or its representatives, including but not limited to
52
+ communication on electronic mailing lists, source code control systems, and
53
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
54
+ the purpose of discussing and improving the Work, but excluding communication
55
+ that is conspicuously marked or otherwise designated in writing by the copyright
56
+ owner as "Not a Contribution."
57
+
58
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
59
+ of whom a Contribution has been received by Licensor and subsequently
60
+ incorporated within the Work.
61
+
62
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
63
+ License, each Contributor hereby grants to You a perpetual, worldwide,
64
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
65
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
66
+ sublicense, and distribute the Work and such Derivative Works in Source or
67
+ Object form.
68
+
69
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
70
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
71
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
72
+ license to make, have made, use, offer to sell, sell, import, and otherwise
73
+ transfer the Work, where such license applies only to those patent claims
74
+ licensable by such Contributor that are necessarily infringed by their
75
+ Contribution(s) alone or by combination of their Contribution(s) with the Work
76
+ to which such Contribution(s) was submitted. If You institute patent litigation
77
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
78
+ alleging that the Work or a Contribution incorporated within the Work
79
+ constitutes direct or contributory patent infringement, then any patent licenses
80
+ granted to You under this License for that Work shall terminate as of the date
81
+ such litigation is filed.
82
+
83
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
84
+ Derivative Works thereof in any medium, with or without modifications, and in
85
+ Source or Object form, provided that You meet the following conditions:
86
+
87
+ (a) You must give any other recipients of the Work or Derivative Works a copy
88
+ of this License; and
89
+
90
+ (b) You must cause any modified files to carry prominent notices stating that
91
+ You changed the files; and
92
+
93
+ (c) You must retain, in the Source form of any Derivative Works that You
94
+ distribute, all copyright, patent, trademark, and attribution notices
95
+ from the Source form of the Work, excluding those notices that do not
96
+ pertain to any part of the Derivative Works; and
97
+
98
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
99
+ then any Derivative Works that You distribute must include a readable copy
100
+ of the attribution notices contained within such NOTICE file, excluding
101
+ those notices that do not pertain to any part of the Derivative Works, in
102
+ at least one of the following places: within a NOTICE text file
103
+ distributed as part of the Derivative Works; within the Source form or
104
+ documentation, if provided along with the Derivative Works; or, within a
105
+ display generated by the Derivative Works, if and wherever such
106
+ third-party notices normally appear. The contents of the NOTICE file are
107
+ for informational purposes only and do not modify the License. You may add
108
+ Your own attribution notices within Derivative Works that You distribute,
109
+ alongside or as an addendum to the NOTICE text from the Work, provided
110
+ that such additional attribution notices cannot be construed as modifying
111
+ the License.
112
+
113
+ You may add Your own copyright statement to Your modifications and may provide
114
+ additional or different license terms and conditions for use, reproduction, or
115
+ distribution of Your modifications, or for any such Derivative Works as a whole,
116
+ provided Your use, reproduction, and distribution of the Work otherwise complies
117
+ with the conditions stated in this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
120
+ Contribution intentionally submitted for inclusion in the Work by You to the
121
+ Licensor shall be under the terms and conditions of this License, without any
122
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
123
+ supersede or modify the terms of any separate license agreement you may have
124
+ executed with Licensor regarding such Contributions.
125
+
126
+ 6. Trademarks. This License does not grant permission to use the trade names,
127
+ trademarks, service marks, or product names of the Licensor, except as required
128
+ for reasonable and customary use in describing the origin of the Work and
129
+ reproducing the content of the NOTICE file.
130
+
131
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
132
+ writing, Licensor provides the Work (and each Contributor provides its
133
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
134
+ KIND, either express or implied, including, without limitation, any warranties or
135
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
136
+ PARTICULAR PURPOSE. You are solely responsible for determining the
137
+ appropriateness of using or redistributing the Work and assume any risks
138
+ associated with Your exercise of permissions under this License.
139
+
140
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
141
+ tort (including negligence), contract, or otherwise, unless required by
142
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
143
+ writing, shall any Contributor be liable to You for damages, including any
144
+ direct, indirect, special, incidental, or consequential damages of any character
145
+ arising as a result of this License or out of the use or inability to use the
146
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
147
+ computer failure or malfunction, or any and all other commercial damages or
148
+ losses), even if such Contributor has been advised of the possibility of such
149
+ damages.
150
+
151
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
152
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
153
+ acceptance of support, warranty, indemnity, or other liability obligations
154
+ and/or rights consistent with this License. However, in accepting such
155
+ obligations, You may act only on Your own behalf and on Your sole
156
+ responsibility, not on behalf of any other Contributor, and only if You agree to
157
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
158
+ by, or claims asserted against, such Contributor by reason of your accepting any
159
+ such warranty or additional liability.
160
+
161
+ END OF TERMS AND CONDITIONS
162
+
163
+ APPENDIX: How to apply the Apache License to your work.
164
+
165
+ To apply the Apache License to your work, attach the following boilerplate
166
+ notice, with the fields enclosed by brackets "[]" replaced with your own
167
+ identifying information. Do not include the brackets. The text should be
168
+ enclosed in the appropriate comment syntax for the file format. We also
169
+ recommend that a file or class name and description of purpose be included on
170
+ the same "printed page" as the copyright notice for easier identification
171
+ within third-party archives.
172
+
173
+ Copyright 2026 wirekx contributors
174
+
175
+ Licensed under the Apache License, Version 2.0 (the "License");
176
+ you may not use this file except in compliance with the License.
177
+ You may obtain a copy of the License at
178
+
179
+ http://www.apache.org/licenses/LICENSE-2.0
180
+
181
+ Unless required by applicable law or agreed to in writing, software
182
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
183
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
184
+ License for the specific language governing permissions and limitations under
185
+ the License.
wirekx-0.1.0/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ wirekx
2
+ Copyright 2026 wirekx contributors
3
+
4
+ This product includes wirekx, an anonymous X25519 key exchange
5
+ library and wire format.
6
+
7
+ Project: https://github.com/wirekx/wirekx
wirekx-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: wirekx
3
+ Version: 0.1.0
4
+ Summary: Experimental anonymous X25519 key exchange wire format.
5
+ Project-URL: Homepage, https://github.com/wirekx/wirekx
6
+ Project-URL: Repository, https://github.com/wirekx/wirekx
7
+ Project-URL: Issues, https://github.com/wirekx/wirekx/issues
8
+ Author: wirekx contributors
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Keywords: cryptography,experimental,key-exchange,x25519
13
+ Classifier: Development Status :: 2 - Pre-Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Security :: Cryptography
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: cryptography>=49.0.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
24
+ Description-Content-Type: text/markdown
25
+
26
+ ```text
27
+ * * __ __ ___ ____ _____ _ __ __ __
28
+ \ / \ \ / / |_ _|| _ \ | ____|| |/ / \ \/ /
29
+ ^/ | \^ \ \ /\ / / | | | |_) || _| | ' / \ /
30
+ | o:1 | \ V V / | | | _ < | |___ | . \ / \
31
+ -| 1:o |- \_/\_/ |___||_| \_\|_____||_|\_\ /_/\_\
32
+ / \_|_/ \
33
+ ```
34
+
35
+ Python library and wire format for anonymous X25519 key exchange.
36
+
37
+ > **wirekx v1 performs the following:**
38
+ >
39
+ > - Opportunistic key agreement for anonymous handshake
40
+ >
41
+ > **V1 caveat:** Since this is an anonymous handshake, MITM is undetectable.
42
+ >
43
+ > **Use cases:**
44
+ >
45
+ > - Derive symmetric key for payload encryption between trusted services
46
+ >
47
+ > **Future releases:**
48
+ >
49
+ > - publicCA validation for anonymous handshake
50
+ > - Pre-shared fingerprint validation
51
+ > - Quantum-safe encryption
52
+
53
+ ## Install for development
54
+
55
+ ```bash
56
+ python3 -m venv .venv
57
+ .venv/bin/python -m pip install -e ".[dev]"
58
+ ```
59
+
60
+ Run the manual example:
61
+
62
+ ```bash
63
+ .venv/bin/python testrun.py
64
+ ```
65
+
66
+ Run tests:
67
+
68
+ ```bash
69
+ .venv/bin/python -m pytest
70
+ ```
71
+
72
+ Use as a library:
73
+
74
+ ```python
75
+ from wirekx import InitiatorHandshake, ResponderHandshake
76
+
77
+ initiator = InitiatorHandshake()
78
+ responder = ResponderHandshake()
79
+
80
+ hello = initiator.create_hello()
81
+ responder.receive_hello(hello)
82
+
83
+ hello_back = responder.create_hello_back()
84
+ initiator.receive_hello_back(hello_back)
85
+
86
+ initiator_confirm = initiator.create_confirm()
87
+ responder.receive_confirm(initiator_confirm)
88
+
89
+ responder_confirm = responder.create_confirm()
90
+ initiator.receive_confirm(responder_confirm)
91
+
92
+ result = initiator.result()
93
+ print(result.symmetric_key.hex())
94
+ ```
95
+
96
+ ## Open source contribution flow
97
+
98
+ 1. Fork the repository on GitHub.
99
+ 2. Create a branch for your change.
100
+ 3. Install development dependencies with `.venv/bin/python -m pip install -e ".[dev]"`.
101
+ 4. Add or update tests in `tests/`.
102
+ 5. Run `.venv/bin/python -m pytest`.
103
+ 6. Open a pull request.
104
+
105
+ ## License
106
+
107
+ wirekx is licensed under the Apache License, Version 2.0. See `LICENSE`.
108
+
109
+ Redistributions should preserve the attribution notices in `NOTICE`. If you use
110
+ wirekx in a public project, a README or documentation mention is appreciated.
111
+
112
+ ## wirekx wire format (v1, anonymous mode)
113
+
114
+ Two parties run a handshake and end up holding the same 32-byte symmetric key.
115
+ This document specifies the bytes that go on the wire.
116
+
117
+ ## Envelope
118
+
119
+ Every message starts with a 4-byte header followed by its payload.
120
+
121
+ ```
122
+ ┌─────────┬──────────┬─────────────┬──────────────┐
123
+ │ version │ msg_type │ payload_len │ payload │
124
+ │ 1 byte │ 1 byte │ 2 bytes BE │ payload_len │
125
+ └─────────┴──────────┴─────────────┴──────────────┘
126
+ ```
127
+
128
+ `version` = `0x01`. Multi-byte integers are big-endian.
129
+
130
+ ## Messages
131
+
132
+ | Code | Name | From | Payload |
133
+ |--------|--------------|-----------|-----------------------------------|
134
+ | `0x01` | `HELLO` | initiator | `eph_pub_a` (32) + `nonce_a` (32) |
135
+ | `0x02` | `HELLO_BACK` | responder | `eph_pub_b` (32) + `nonce_b` (32) |
136
+ | `0x03` | `CONFIRM` | both | `verify_data` (32) |
137
+
138
+ `eph_pub_*` is an X25519 public key. `nonce_*` is 32 random bytes.
139
+
140
+ ## Cryptography
141
+
142
+ ```
143
+ shared_secret = X25519(own_eph_priv, peer_eph_pub)
144
+
145
+ symmetric_key = HKDF-SHA256(
146
+ ikm = shared_secret,
147
+ salt = nonce_a || nonce_b,
148
+ info = "wirekx v1 session key",
149
+ length = 32)
150
+
151
+ transcript = SHA-256(HELLO_bytes || HELLO_BACK_bytes)
152
+
153
+ verify_data = HMAC-SHA256(
154
+ key = symmetric_key,
155
+ data = "wirekx v1 <role> confirm" || transcript)
156
+ ```
157
+
158
+ `<role>` is `initiator` or `responder` depending on who sent the `CONFIRM`.
159
+ Compare received `verify_data` with constant-time equality. Mismatch = abort.
160
+
161
+ ## Flow
162
+
163
+ ```
164
+ initiator responder
165
+ │ │
166
+ │ HELLO (eph_pub_a, nonce_a) │
167
+ │ ────────────────────────────────────► │
168
+ │ │
169
+ │ HELLO_BACK (eph_pub_b, nonce_b) │
170
+ │ ◄──────────────────────────────────── │
171
+ │ │
172
+ │ derive symmetric_key, transcript │
173
+ │ CONFIRM (verify_data_initiator) │
174
+ │ ────────────────────────────────────► │
175
+ │ │
176
+ │ │ verify, then:
177
+ │ CONFIRM (verify_data_responder) │
178
+ │ ◄──────────────────────────────────── │
179
+ │ │
180
+ │ verify │
181
+ │ COMPLETE │ COMPLETE
182
+ ```
183
+
184
+ On any malformed message, unexpected type, or verification mismatch: abort,
185
+ discard state, do not return the key.
186
+
187
+ ## Output
188
+
189
+ After both `CONFIRM` messages verify, return to the caller:
190
+
191
+ - `symmetric_key` — 32 bytes
192
+ - `transcript_hash` — 32 bytes
193
+ - `protection_level` = `"opportunistic"`
194
+ - `peer_identity` = `null`
195
+
196
+ ## Notes
197
+
198
+ - `transcript_hash` is unique per handshake.
199
+ - Possible values for `protection_level` are `"opportunistic"` and `"authenticated"`. Opportunistic means anonymous players, active MITM is undetectable. Authenticated means you have verified peer's identity by exchanging certificate via an external channel.
200
+ - Ephemeral keys are fresh per handshake and discarded after use.
201
+ - No version negotiation. Different versions cannot interoperate.
202
+ - Authenticated modes (`fingerprint`, `shared`, `publicCA`) will be built in future.
wirekx-0.1.0/README.md ADDED
@@ -0,0 +1,177 @@
1
+ ```text
2
+ * * __ __ ___ ____ _____ _ __ __ __
3
+ \ / \ \ / / |_ _|| _ \ | ____|| |/ / \ \/ /
4
+ ^/ | \^ \ \ /\ / / | | | |_) || _| | ' / \ /
5
+ | o:1 | \ V V / | | | _ < | |___ | . \ / \
6
+ -| 1:o |- \_/\_/ |___||_| \_\|_____||_|\_\ /_/\_\
7
+ / \_|_/ \
8
+ ```
9
+
10
+ Python library and wire format for anonymous X25519 key exchange.
11
+
12
+ > **wirekx v1 performs the following:**
13
+ >
14
+ > - Opportunistic key agreement for anonymous handshake
15
+ >
16
+ > **V1 caveat:** Since this is an anonymous handshake, MITM is undetectable.
17
+ >
18
+ > **Use cases:**
19
+ >
20
+ > - Derive symmetric key for payload encryption between trusted services
21
+ >
22
+ > **Future releases:**
23
+ >
24
+ > - publicCA validation for anonymous handshake
25
+ > - Pre-shared fingerprint validation
26
+ > - Quantum-safe encryption
27
+
28
+ ## Install for development
29
+
30
+ ```bash
31
+ python3 -m venv .venv
32
+ .venv/bin/python -m pip install -e ".[dev]"
33
+ ```
34
+
35
+ Run the manual example:
36
+
37
+ ```bash
38
+ .venv/bin/python testrun.py
39
+ ```
40
+
41
+ Run tests:
42
+
43
+ ```bash
44
+ .venv/bin/python -m pytest
45
+ ```
46
+
47
+ Use as a library:
48
+
49
+ ```python
50
+ from wirekx import InitiatorHandshake, ResponderHandshake
51
+
52
+ initiator = InitiatorHandshake()
53
+ responder = ResponderHandshake()
54
+
55
+ hello = initiator.create_hello()
56
+ responder.receive_hello(hello)
57
+
58
+ hello_back = responder.create_hello_back()
59
+ initiator.receive_hello_back(hello_back)
60
+
61
+ initiator_confirm = initiator.create_confirm()
62
+ responder.receive_confirm(initiator_confirm)
63
+
64
+ responder_confirm = responder.create_confirm()
65
+ initiator.receive_confirm(responder_confirm)
66
+
67
+ result = initiator.result()
68
+ print(result.symmetric_key.hex())
69
+ ```
70
+
71
+ ## Open source contribution flow
72
+
73
+ 1. Fork the repository on GitHub.
74
+ 2. Create a branch for your change.
75
+ 3. Install development dependencies with `.venv/bin/python -m pip install -e ".[dev]"`.
76
+ 4. Add or update tests in `tests/`.
77
+ 5. Run `.venv/bin/python -m pytest`.
78
+ 6. Open a pull request.
79
+
80
+ ## License
81
+
82
+ wirekx is licensed under the Apache License, Version 2.0. See `LICENSE`.
83
+
84
+ Redistributions should preserve the attribution notices in `NOTICE`. If you use
85
+ wirekx in a public project, a README or documentation mention is appreciated.
86
+
87
+ ## wirekx wire format (v1, anonymous mode)
88
+
89
+ Two parties run a handshake and end up holding the same 32-byte symmetric key.
90
+ This document specifies the bytes that go on the wire.
91
+
92
+ ## Envelope
93
+
94
+ Every message starts with a 4-byte header followed by its payload.
95
+
96
+ ```
97
+ ┌─────────┬──────────┬─────────────┬──────────────┐
98
+ │ version │ msg_type │ payload_len │ payload │
99
+ │ 1 byte │ 1 byte │ 2 bytes BE │ payload_len │
100
+ └─────────┴──────────┴─────────────┴──────────────┘
101
+ ```
102
+
103
+ `version` = `0x01`. Multi-byte integers are big-endian.
104
+
105
+ ## Messages
106
+
107
+ | Code | Name | From | Payload |
108
+ |--------|--------------|-----------|-----------------------------------|
109
+ | `0x01` | `HELLO` | initiator | `eph_pub_a` (32) + `nonce_a` (32) |
110
+ | `0x02` | `HELLO_BACK` | responder | `eph_pub_b` (32) + `nonce_b` (32) |
111
+ | `0x03` | `CONFIRM` | both | `verify_data` (32) |
112
+
113
+ `eph_pub_*` is an X25519 public key. `nonce_*` is 32 random bytes.
114
+
115
+ ## Cryptography
116
+
117
+ ```
118
+ shared_secret = X25519(own_eph_priv, peer_eph_pub)
119
+
120
+ symmetric_key = HKDF-SHA256(
121
+ ikm = shared_secret,
122
+ salt = nonce_a || nonce_b,
123
+ info = "wirekx v1 session key",
124
+ length = 32)
125
+
126
+ transcript = SHA-256(HELLO_bytes || HELLO_BACK_bytes)
127
+
128
+ verify_data = HMAC-SHA256(
129
+ key = symmetric_key,
130
+ data = "wirekx v1 <role> confirm" || transcript)
131
+ ```
132
+
133
+ `<role>` is `initiator` or `responder` depending on who sent the `CONFIRM`.
134
+ Compare received `verify_data` with constant-time equality. Mismatch = abort.
135
+
136
+ ## Flow
137
+
138
+ ```
139
+ initiator responder
140
+ │ │
141
+ │ HELLO (eph_pub_a, nonce_a) │
142
+ │ ────────────────────────────────────► │
143
+ │ │
144
+ │ HELLO_BACK (eph_pub_b, nonce_b) │
145
+ │ ◄──────────────────────────────────── │
146
+ │ │
147
+ │ derive symmetric_key, transcript │
148
+ │ CONFIRM (verify_data_initiator) │
149
+ │ ────────────────────────────────────► │
150
+ │ │
151
+ │ │ verify, then:
152
+ │ CONFIRM (verify_data_responder) │
153
+ │ ◄──────────────────────────────────── │
154
+ │ │
155
+ │ verify │
156
+ │ COMPLETE │ COMPLETE
157
+ ```
158
+
159
+ On any malformed message, unexpected type, or verification mismatch: abort,
160
+ discard state, do not return the key.
161
+
162
+ ## Output
163
+
164
+ After both `CONFIRM` messages verify, return to the caller:
165
+
166
+ - `symmetric_key` — 32 bytes
167
+ - `transcript_hash` — 32 bytes
168
+ - `protection_level` = `"opportunistic"`
169
+ - `peer_identity` = `null`
170
+
171
+ ## Notes
172
+
173
+ - `transcript_hash` is unique per handshake.
174
+ - Possible values for `protection_level` are `"opportunistic"` and `"authenticated"`. Opportunistic means anonymous players, active MITM is undetectable. Authenticated means you have verified peer's identity by exchanging certificate via an external channel.
175
+ - Ephemeral keys are fresh per handshake and discarded after use.
176
+ - No version negotiation. Different versions cannot interoperate.
177
+ - Authenticated modes (`fingerprint`, `shared`, `publicCA`) will be built in future.