kiosk-pow-argon2id 0.5.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +33 -0
- data/LICENSE.txt +202 -0
- data/README.md +168 -0
- data/lib/kiosk/pow/argon2id/version.rb +9 -0
- data/lib/kiosk/pow/argon2id.rb +55 -0
- data/requirements.txt +1 -0
- data/solve.py +88 -0
- metadata +108 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 709ee4dba79e300408bf97a52dda423b9b4e20a5d7833c8f91bae88869dbf177
|
|
4
|
+
data.tar.gz: e77cb6aef216454e9b134c6d82c670005f2f8b84bda22cbcfd39c84eaf298d1b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9a7ba3f796b69a89162bbe4a7d215defefdedd6416c8575a07a34b2451daee6ec3e2317158a3b569768fd81144f8e524a32048034eb2d3c263a0d9c27538471e
|
|
7
|
+
data.tar.gz: 3cab71fce366c4fe540ee26694010552a881ac65c38179aa513f6a875e07f3a32e958446cdf04541d703c2926e271f12e2167097fcfc227deaebb3b35bf0394d
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
How to write an entry, and what a release section means: `CHANGELOG-RULE.md` at
|
|
6
|
+
the root of this repository —
|
|
7
|
+
<https://github.com/kiosk-hq/kiosk/blob/main/CHANGELOG-RULE.md>. In short: under
|
|
8
|
+
200 characters, one or two sentences, the essence rather than the content; write it
|
|
9
|
+
under `## [Unreleased]`; a cut renames that heading to
|
|
10
|
+
`## [MAJOR.MINOR.PATCH] — <date>` and opens a fresh empty one above it; nothing
|
|
11
|
+
already written is edited.
|
|
12
|
+
|
|
13
|
+
## [Unreleased]
|
|
14
|
+
|
|
15
|
+
## [0.5.20] — 2026-10-20
|
|
16
|
+
|
|
17
|
+
- 2026-10-20: Version 0.5.20, the tree cut that matches skill 0.5.20.
|
|
18
|
+
|
|
19
|
+
## [0.5.19] — 2026-10-20
|
|
20
|
+
|
|
21
|
+
- 2026-10-20: Version 0.5.19, the tree cut that matches skill 0.5.19.
|
|
22
|
+
|
|
23
|
+
## [0.5.18] — 2026-10-18
|
|
24
|
+
|
|
25
|
+
- 2026-10-18: Version 0.5.18, the tree cut that matches skill 0.5.18.
|
|
26
|
+
|
|
27
|
+
## [0.5.17] — 2026-10-18
|
|
28
|
+
|
|
29
|
+
- 2026-10-18: Version 0.5.17, the tree cut that matches skill 0.5.17.
|
|
30
|
+
|
|
31
|
+
## [0.5.16] — 2026-10-18
|
|
32
|
+
|
|
33
|
+
- 2026-10-18: The Argon2id backend moves here from kiosk-pow, as `Kiosk::Pow::Argon2id`. It is built on kiosk-pow.
|
data/LICENSE.txt
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# kiosk-pow-argon2id
|
|
2
|
+
|
|
3
|
+
Argon2id memory-hard proof-of-work backend for the [Kiosk](https://kiosk.tech) framework.
|
|
4
|
+
|
|
5
|
+
> **Retired / optional.** The shipped default PoW backend is
|
|
6
|
+
> [`kiosk-pow-equihash`](https://github.com/kiosk-hq/kiosk/tree/main/kiosk-pow-equihash) — one PoW backend, Equihash.
|
|
7
|
+
> Argon2id's `verify` costs one `m`-sized eval (~64 MiB),
|
|
8
|
+
> so a flood of bad proofs is a DoS on the *verifier* — the exact failure the
|
|
9
|
+
> asymmetric-verify goal exists to prevent. This gem stays in the repo as an
|
|
10
|
+
> opt-in backend and reference; no demo, harness or deploy runbook wires it.
|
|
11
|
+
|
|
12
|
+
## What it is
|
|
13
|
+
|
|
14
|
+
`kiosk-pow-argon2id` implements a
|
|
15
|
+
**search-form Argon2id PoW**: a client finds the smallest nonce `n ≥ 0` such
|
|
16
|
+
that `Argon2id(password=str(n), salt=raw_salt, ...)` has ≥ `d` leading zero
|
|
17
|
+
bits. The provider verifies by computing **one** Argon2id eval — the solve:verify
|
|
18
|
+
lever is exactly `2^d`.
|
|
19
|
+
|
|
20
|
+
Providers can demand this PoW on any query or action endpoint
|
|
21
|
+
(`GET /kiosk/<query-name>`, `POST /kiosk/<action-name>`) — and, as an optional
|
|
22
|
+
registration toll, on `/kiosk/auth/register` — at their discretion, via
|
|
23
|
+
`kiosk-reputation`'s policy layer. `pay` is tolled the same way, so it may
|
|
24
|
+
answer `402 pow_required`; it answers `402 payment_setup_required` when the
|
|
25
|
+
customer has no saved card. `kiosk-pow-argon2id` ships both sides:
|
|
26
|
+
|
|
27
|
+
- **Ruby verify** (`Kiosk::Pow::Argon2id.verify`) — one Argon2id eval, no loop.
|
|
28
|
+
- **Python solver** (`solve.py`) — an assistant runs this in its sandbox when
|
|
29
|
+
it receives a `pow_required` challenge. Pure `argon2-cffi`, no exotic deps.
|
|
30
|
+
|
|
31
|
+
Both sides produce byte-identical Argon2id digests (verified by `rake parity`).
|
|
32
|
+
|
|
33
|
+
## Ruby API
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
# Challenge params for a difficulty tier:
|
|
37
|
+
Kiosk::Pow::Argon2id.params(d: 8)
|
|
38
|
+
# => { m: 65_536, t: 1, p: 1, d: 8 }
|
|
39
|
+
|
|
40
|
+
# Check one proof (one Argon2id eval — no loop):
|
|
41
|
+
Kiosk::Pow::Argon2id.verify(salt: raw_bytes, params: { m: 65_536, t: 1, p: 1, d: 8 }, nonce: "73821")
|
|
42
|
+
# => true / false
|
|
43
|
+
|
|
44
|
+
# Raw 32-byte digest:
|
|
45
|
+
Kiosk::Pow::Argon2id.digest(salt: raw_bytes, params: { m: 65_536, t: 1, p: 1, d: 8 }, nonce: "0")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Constants and defaults
|
|
49
|
+
|
|
50
|
+
| Symbol | Value | Meaning |
|
|
51
|
+
|--------|-------|---------|
|
|
52
|
+
| `Kiosk::Pow::Argon2id::NAME` | `"argon2id"` | Algorithm name advertised in the wire challenge |
|
|
53
|
+
| `m` default | `65_536` KiB (64 MiB) | ASIC-resistance knob; sets verify cost and solve cost equally |
|
|
54
|
+
| `t` default | `1` | Iterations |
|
|
55
|
+
| `p` default | `1` | Parallelism |
|
|
56
|
+
| `d` | provider-chosen | Required leading zero bits; escalation knob; solve ≈ `2^d` evals |
|
|
57
|
+
|
|
58
|
+
## The canonical PoW computation
|
|
59
|
+
|
|
60
|
+
Both the Ruby verifier and the Python solver compute the same primitive:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
Argon2id(
|
|
64
|
+
password = str(nonce), # decimal ASCII string, e.g. "0", "73821"
|
|
65
|
+
salt = raw_salt_bytes, # ≥ 8 raw bytes; wire base64 decoded upstream
|
|
66
|
+
m_cost = params[:m], # memory in KiB (default 65 536 = 64 MiB)
|
|
67
|
+
t_cost = params[:t], # iterations (default 1)
|
|
68
|
+
p = params[:p], # parallelism (default 1)
|
|
69
|
+
version = 0x13, # ARGON2_VERSION_13 (19) — hardcoded both sides
|
|
70
|
+
hash_len = 32 # 32-byte output
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A nonce is valid iff `leading_zero_bits(digest) >= params[:d]`.
|
|
75
|
+
|
|
76
|
+
Ruby uses `Argon2::Ext.argon2id_hash_raw` (libargon2, always version `0x13`).
|
|
77
|
+
Python uses `argon2.low_level.hash_secret_raw(..., version=19)` (`argon2-cffi`).
|
|
78
|
+
Version `19` decimal == `0x13` hex — byte-identical output.
|
|
79
|
+
|
|
80
|
+
## Wire challenge params
|
|
81
|
+
|
|
82
|
+
The `params` object in the challenge carries exactly four integer keys:
|
|
83
|
+
|
|
84
|
+
| Key | Type | Meaning |
|
|
85
|
+
|-----|------|---------|
|
|
86
|
+
| `m` | Integer | Memory in KiB |
|
|
87
|
+
| `t` | Integer | Iterations |
|
|
88
|
+
| `p` | Integer | Parallelism |
|
|
89
|
+
| `d` | Integer | Required leading zero bits |
|
|
90
|
+
|
|
91
|
+
## Python solver
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install argon2-cffi
|
|
95
|
+
|
|
96
|
+
python3 solve.py '{"salt":"<base64>","params":{"m":65536,"t":1,"p":1,"d":8}}'
|
|
97
|
+
# stdout: {"nonce": "73821"}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`solve.py` accepts the challenge JSON as `sys.argv[1]` or reads it from stdin.
|
|
101
|
+
It only reads `"salt"` and `"params"` from the challenge — the other fields
|
|
102
|
+
(`id`, `alg`, `exp`, `sig`) are ignored, so the full challenge object is safe
|
|
103
|
+
to pass directly.
|
|
104
|
+
|
|
105
|
+
Agent-facing guidance is **not** duplicated in this gem. The canonical skill is
|
|
106
|
+
[kiosk.tech/skill.md](https://kiosk.tech/skill.md); it teaches the `402
|
|
107
|
+
pow_required` retry — the same request body, unchanged, with the proof(s) in a
|
|
108
|
+
`Kiosk-PoW` request header as raw JSON — and it teaches it for the
|
|
109
|
+
shipped Equihash default, not for this legacy backend. An operator that opts
|
|
110
|
+
back into Argon2id is off that path: it must tell its own assistants to run the
|
|
111
|
+
`solve.py` above and echo the challenge verbatim in the `Kiosk-PoW` header.
|
|
112
|
+
|
|
113
|
+
## Difficulty tiers (guidance)
|
|
114
|
+
|
|
115
|
+
Solve time depends on `m` and the assistant's hardware. Defaults: `m = 65 536`
|
|
116
|
+
KiB (64 MiB), `t = 1`, `p = 1`.
|
|
117
|
+
|
|
118
|
+
| `d` | Expected solve time | Typical use |
|
|
119
|
+
|----:|:-------------------:|:------------|
|
|
120
|
+
| 0 | instant | no challenge (policy returns nil) |
|
|
121
|
+
| 5–6 | 2–4 s | light friction for unproven principals |
|
|
122
|
+
| 8 | 20–40 s | medium throttle |
|
|
123
|
+
| 11 | 3–6 min | hard throttle for high-suspicion/high-rate |
|
|
124
|
+
|
|
125
|
+
These are guidance on server-class compute; actual times vary.
|
|
126
|
+
|
|
127
|
+
## Cross-implementation parity check
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
bundle exec rake parity
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Computes the same Argon2id digest in Ruby and Python, asserts hex-equal, then
|
|
134
|
+
runs `solve.py` on a small challenge and asserts Ruby `verify` accepts the
|
|
135
|
+
result. Run this after any change to either implementation.
|
|
136
|
+
|
|
137
|
+
## Installation
|
|
138
|
+
|
|
139
|
+
> **Not on RubyGems yet** — so every `gem` line below carries `github: "kiosk-hq/kiosk"`, which is what makes it copy-pasteable today. Publication status and the canonical install are stated once, in the monorepo README's [Install](https://github.com/kiosk-hq/kiosk#install) section.
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
gem "kiosk-pow-argon2id", github: "kiosk-hq/kiosk"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```ruby
|
|
146
|
+
require "kiosk/pow/argon2id"
|
|
147
|
+
|
|
148
|
+
# Register with kiosk-reputation (if using the policy layer):
|
|
149
|
+
Kiosk::Reputation::Backends.register("argon2id", Kiosk::Pow::Argon2id)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Honesty / guardrails
|
|
153
|
+
|
|
154
|
+
- **PoW is economic friction, not a wall.** A determined ASIC attacker still
|
|
155
|
+
gets in; the point is to make free-riding cost more than buying. Combine with
|
|
156
|
+
`kiosk-reputation` for the full picture.
|
|
157
|
+
- **The provider mandates `alg` + `params`.** Clients comply or are denied.
|
|
158
|
+
There is no negotiation path — do not add one.
|
|
159
|
+
- **Default verify costs `m` KiB of memory** — one full Argon2id eval.
|
|
160
|
+
Only challenge on suspicion/rate, not on every cheap call. The challenge
|
|
161
|
+
should protect a value worth more than the verify cost.
|
|
162
|
+
- **`m` is the ASIC-resistance knob; `d` is the difficulty knob.** Raising `m`
|
|
163
|
+
raises solve and verify equally (lever unchanged). Raising `d` raises solve
|
|
164
|
+
exponentially while verify stays one eval.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Apache-2.0. See [LICENSE.txt](LICENSE.txt).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ffi'
|
|
4
|
+
require 'argon2'
|
|
5
|
+
|
|
6
|
+
require 'kiosk/pow'
|
|
7
|
+
require_relative 'argon2id/version'
|
|
8
|
+
|
|
9
|
+
module Kiosk
|
|
10
|
+
module Pow
|
|
11
|
+
# Argon2id memory-hard proof-of-work backend, dispatched by kiosk-reputation for "argon2id".
|
|
12
|
+
# A nonce is valid iff leading_zero_bits(Argon2id(nonce.to_s, salt, m, t, p, v=0x13, 32 bytes)) >= d,
|
|
13
|
+
# byte-identical to the Python solver.
|
|
14
|
+
module Argon2id
|
|
15
|
+
NAME = 'argon2id'
|
|
16
|
+
DIGEST_BYTES = 32
|
|
17
|
+
|
|
18
|
+
# d: required leading zero bits; m: memory in KiB.
|
|
19
|
+
def self.params(d:, m: 65_536, t: 1, p: 1) # rubocop:disable Naming/MethodParameterName -- m, t, p and d are the wire params keys.
|
|
20
|
+
{ m:, t:, p:, d: }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.digest(salt:, params:, nonce:)
|
|
24
|
+
buffer = FFI::MemoryPointer.new(:char, DIGEST_BYTES)
|
|
25
|
+
argon2id_hash_raw(salt, params, nonce.to_s.b, buffer)
|
|
26
|
+
buffer.read_string(DIGEST_BYTES)
|
|
27
|
+
ensure
|
|
28
|
+
buffer&.free
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Raw libargon2 call: the Password API would turn m_cost into a power-of-two exponent.
|
|
32
|
+
def self.argon2id_hash_raw(salt, params, password, buffer)
|
|
33
|
+
memory, time, lanes = params.values_at(:m, :t, :p).map { Integer(it) }
|
|
34
|
+
ret = Argon2::Ext.argon2id_hash_raw(time, memory, lanes, password, password.bytesize,
|
|
35
|
+
salt, salt.bytesize, buffer, DIGEST_BYTES)
|
|
36
|
+
raise "Argon2id evaluation failed (code #{ret})" unless ret.zero?
|
|
37
|
+
end
|
|
38
|
+
private_class_method :argon2id_hash_raw
|
|
39
|
+
|
|
40
|
+
def self.verify(salt:, params:, nonce:) # rubocop:disable Naming/PredicateMethod -- the PoW backend interface name.
|
|
41
|
+
leading_zero_bits(digest(salt:, params:, nonce:)) >= params[:d]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.leading_zero_bits(bytes)
|
|
45
|
+
count = 0
|
|
46
|
+
bytes.each_byte do |byte|
|
|
47
|
+
return count + 8 - byte.bit_length unless byte.zero?
|
|
48
|
+
|
|
49
|
+
count += 8
|
|
50
|
+
end
|
|
51
|
+
count
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
argon2-cffi
|
data/solve.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Kiosk-shipped Argon2id proof-of-work solver.
|
|
4
|
+
|
|
5
|
+
This script is invoked by an assistant when it receives a `pow_required`
|
|
6
|
+
challenge from a Kiosk provider. It finds the smallest nonce n ≥ 0 such that
|
|
7
|
+
|
|
8
|
+
Argon2id(password=str(n), salt=base64decode(challenge.salt),
|
|
9
|
+
m_cost=m, t_cost=t, parallelism=p, hash_len=32, version=19)
|
|
10
|
+
|
|
11
|
+
has at least `d` leading zero bits, then prints {"nonce": "<n>"}.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
python3 solve.py '<challenge json>'
|
|
15
|
+
python3 solve.py # reads challenge JSON from stdin if no argument given
|
|
16
|
+
|
|
17
|
+
Challenge JSON schema:
|
|
18
|
+
{
|
|
19
|
+
"salt": "<base64-encoded raw salt, ≥ 8 bytes>",
|
|
20
|
+
"params": { "m": <KiB>, "t": <iters>, "p": <parallelism>, "d": <bits> }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Dependencies:
|
|
24
|
+
pip install argon2-cffi
|
|
25
|
+
|
|
26
|
+
The Ruby provider verifies with the same parameters (Argon2::Ext.argon2id_hash_raw
|
|
27
|
+
via libargon2, version 0x13). Both sides produce byte-identical digests —
|
|
28
|
+
`bundle exec rake parity`, in the kiosk monorepo, runs that comparison by hand;
|
|
29
|
+
the Rakefile it lives in is not packaged with this gem.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
import argon2.low_level
|
|
33
|
+
import base64
|
|
34
|
+
import json
|
|
35
|
+
import sys
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def leading_zero_bits(data: bytes) -> int:
|
|
39
|
+
"""Count leading zero bits from the MSB of byte 0, spanning bytes."""
|
|
40
|
+
count = 0
|
|
41
|
+
for b in data:
|
|
42
|
+
if b == 0:
|
|
43
|
+
count += 8
|
|
44
|
+
else:
|
|
45
|
+
count += 8 - b.bit_length()
|
|
46
|
+
break
|
|
47
|
+
return count
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def solve(challenge: dict) -> str:
|
|
51
|
+
"""Return the decimal nonce string that satisfies the challenge."""
|
|
52
|
+
salt = base64.b64decode(challenge["salt"])
|
|
53
|
+
params = challenge["params"]
|
|
54
|
+
m = int(params["m"])
|
|
55
|
+
t = int(params["t"])
|
|
56
|
+
p = int(params["p"])
|
|
57
|
+
d = int(params["d"])
|
|
58
|
+
|
|
59
|
+
nonce = 0
|
|
60
|
+
while True:
|
|
61
|
+
secret = str(nonce).encode("ascii")
|
|
62
|
+
digest = argon2.low_level.hash_secret_raw(
|
|
63
|
+
secret=secret,
|
|
64
|
+
salt=salt,
|
|
65
|
+
time_cost=t,
|
|
66
|
+
memory_cost=m,
|
|
67
|
+
parallelism=p,
|
|
68
|
+
hash_len=32,
|
|
69
|
+
type=argon2.low_level.Type.ID,
|
|
70
|
+
version=19,
|
|
71
|
+
)
|
|
72
|
+
if leading_zero_bits(digest) >= d:
|
|
73
|
+
return str(nonce)
|
|
74
|
+
nonce += 1
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def main():
|
|
78
|
+
if len(sys.argv) > 1:
|
|
79
|
+
challenge = json.loads(sys.argv[1])
|
|
80
|
+
else:
|
|
81
|
+
challenge = json.load(sys.stdin)
|
|
82
|
+
|
|
83
|
+
nonce = solve(challenge)
|
|
84
|
+
print(json.dumps({"nonce": nonce}))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
main()
|
metadata
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kiosk-pow-argon2id
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.20
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Phil Pirozhkov
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: argon2
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.3'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.3'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: ffi
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '1.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: kiosk-pow
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.5.0
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 0.5.0
|
|
54
|
+
description: |
|
|
55
|
+
kiosk-pow-argon2id is the legacy proof-of-work backend for the Kiosk
|
|
56
|
+
framework: an Argon2id search-form proof of work. The shipped default is
|
|
57
|
+
Equihash (kiosk-pow-equihash). Argon2id stays a legacy backend because its
|
|
58
|
+
64 MiB verify is too expensive for a gateway.
|
|
59
|
+
|
|
60
|
+
Ships the operator-side Ruby verify (one Argon2id evaluation, no loop) and
|
|
61
|
+
a Python solver (solve.py, argon2-cffi). The Ruby verify and the Python
|
|
62
|
+
solver produce byte-identical Argon2id digests. The gem's `:parity` spec
|
|
63
|
+
examples check this, and so does the `rake parity` task. Neither the
|
|
64
|
+
Rakefile nor spec/ is in the package.
|
|
65
|
+
|
|
66
|
+
Built on kiosk-pow. kiosk-reputation reaches it when a host registers it
|
|
67
|
+
under "argon2id"; it does not register itself. Does not depend on
|
|
68
|
+
kiosk-core or Rails: pure Ruby and libargon2 through FFI.
|
|
69
|
+
email:
|
|
70
|
+
- hello@fili.pp.ru
|
|
71
|
+
executables: []
|
|
72
|
+
extensions: []
|
|
73
|
+
extra_rdoc_files: []
|
|
74
|
+
files:
|
|
75
|
+
- CHANGELOG.md
|
|
76
|
+
- LICENSE.txt
|
|
77
|
+
- README.md
|
|
78
|
+
- lib/kiosk/pow/argon2id.rb
|
|
79
|
+
- lib/kiosk/pow/argon2id/version.rb
|
|
80
|
+
- requirements.txt
|
|
81
|
+
- solve.py
|
|
82
|
+
homepage: https://kiosk.tech
|
|
83
|
+
licenses:
|
|
84
|
+
- Apache-2.0
|
|
85
|
+
metadata:
|
|
86
|
+
homepage_uri: https://kiosk.tech
|
|
87
|
+
source_code_uri: https://github.com/kiosk-hq/kiosk
|
|
88
|
+
changelog_uri: https://github.com/kiosk-hq/kiosk/blob/main/kiosk-pow-argon2id/CHANGELOG.md
|
|
89
|
+
bug_tracker_uri: https://github.com/kiosk-hq/kiosk/issues
|
|
90
|
+
rubygems_mfa_required: 'true'
|
|
91
|
+
rdoc_options: []
|
|
92
|
+
require_paths:
|
|
93
|
+
- lib
|
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
|
+
requirements:
|
|
96
|
+
- - ">="
|
|
97
|
+
- !ruby/object:Gem::Version
|
|
98
|
+
version: '4.0'
|
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
requirements: []
|
|
105
|
+
rubygems_version: 4.0.3
|
|
106
|
+
specification_version: 4
|
|
107
|
+
summary: Argon2id memory-hard proof-of-work backend for Kiosk (legacy)
|
|
108
|
+
test_files: []
|