python-swoosh 0.1.0__tar.gz → 0.1.1__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.
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/Cargo.lock +1 -1
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/Cargo.toml +1 -1
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/PKG-INFO +2 -1
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/README.md +1 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/pyproject.toml +1 -1
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/src/lib.rs +33 -1
- python_swoosh-0.1.1/swoosh/__init__.py +6 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/swoosh/__init__.pyi +8 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/lib.rs +18 -5
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/sysA.rs +1 -1
- python_swoosh-0.1.0/swoosh/__init__.py +0 -6
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/LICENSE +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/Cargo.toml +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/build.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/aesenc-int.c +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/fq.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/fq.s +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/mod.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/params.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/poly.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/polyvec.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/zetas.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/bin/bench_full.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/bin/bench_scheme.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/bin/swoosh.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/sys_param.rs +0 -0
- {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/util.rs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-swoosh
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
@@ -52,6 +52,7 @@ shared secrets are 32 bytes.
|
|
|
52
52
|
## API
|
|
53
53
|
|
|
54
54
|
- `keygen(is_party_a: bool) -> (secret_key: bytes, public_key: bytes)`
|
|
55
|
+
- `keygen_seeded(is_party_a: bool, seed: bytes) -> (secret_key: bytes, public_key: bytes)` — deterministic; `seed` must be 32 bytes. Same seed + same party gives the same keypair. Never reuse seeds in production.
|
|
55
56
|
- `derive_shared_secret(own_pk: bytes, other_pk: bytes, sk: bytes, is_party_a: bool) -> bytes`
|
|
56
57
|
|
|
57
58
|
## Building from source
|
|
@@ -37,6 +37,7 @@ shared secrets are 32 bytes.
|
|
|
37
37
|
## API
|
|
38
38
|
|
|
39
39
|
- `keygen(is_party_a: bool) -> (secret_key: bytes, public_key: bytes)`
|
|
40
|
+
- `keygen_seeded(is_party_a: bool, seed: bytes) -> (secret_key: bytes, public_key: bytes)` — deterministic; `seed` must be 32 bytes. Same seed + same party gives the same keypair. Never reuse seeds in production.
|
|
40
41
|
- `derive_shared_secret(own_pk: bytes, other_pk: bytes, sk: bytes, is_party_a: bool) -> bytes`
|
|
41
42
|
|
|
42
43
|
## Building from source
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
use pyo3::prelude::*;
|
|
2
2
|
use pyo3::types::PyBytes;
|
|
3
3
|
use pyo3::exceptions::{PyRuntimeError, PyValueError};
|
|
4
|
-
use ref0::{pswoosh_keygen, pswoosh_skey_deriv, sysA, SYMBYTES, PUBLICKEY_BYTES, SECRETKEY_BYTES};
|
|
4
|
+
use ref0::{pswoosh_keygen, pswoosh_keygen_seeded, pswoosh_skey_deriv, sysA, SYMBYTES, PUBLICKEY_BYTES, SECRETKEY_BYTES};
|
|
5
5
|
|
|
6
6
|
/// Stack size for the worker thread.
|
|
7
7
|
///
|
|
@@ -53,6 +53,37 @@ fn keygen<'py>(py: Python<'py>, is_party_a: bool) -> PyResult<(&'py PyBytes, &'p
|
|
|
53
53
|
Ok((PyBytes::new(py, &keys.0), PyBytes::new(py, &keys.1)))
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/// Deterministically generates a (secret_key, public_key) tuple from a 32-byte seed.
|
|
57
|
+
/// Same seed + same party => same keypair. Useful for tests and reproducibility.
|
|
58
|
+
/// Pass is_party_a=True for Party A, or False for Party B.
|
|
59
|
+
///
|
|
60
|
+
/// WARNING: reusing a seed reuses the secret key. In production, use a fresh,
|
|
61
|
+
/// secret seed every time (or just `keygen`, which samples from the OS RNG).
|
|
62
|
+
#[pyfunction]
|
|
63
|
+
fn keygen_seeded<'py>(
|
|
64
|
+
py: Python<'py>,
|
|
65
|
+
is_party_a: bool,
|
|
66
|
+
seed: &[u8],
|
|
67
|
+
) -> PyResult<(&'py PyBytes, &'py PyBytes)> {
|
|
68
|
+
let seed: &[u8; SYMBYTES] = seed.try_into().map_err(|_| {
|
|
69
|
+
PyValueError::new_err(format!("seed must be exactly {SYMBYTES} bytes"))
|
|
70
|
+
})?;
|
|
71
|
+
let seed = Box::new(*seed);
|
|
72
|
+
|
|
73
|
+
let keys = py.allow_threads(move || {
|
|
74
|
+
run_isolated(move || {
|
|
75
|
+
let (sk, pk) = if is_party_a {
|
|
76
|
+
pswoosh_keygen_seeded(&sysA::A, true, &seed)
|
|
77
|
+
} else {
|
|
78
|
+
pswoosh_keygen_seeded(&sysA::At, false, &seed)
|
|
79
|
+
};
|
|
80
|
+
Box::new((sk, pk))
|
|
81
|
+
})
|
|
82
|
+
})?;
|
|
83
|
+
|
|
84
|
+
Ok((PyBytes::new(py, &keys.0), PyBytes::new(py, &keys.1)))
|
|
85
|
+
}
|
|
86
|
+
|
|
56
87
|
/// Derives the 32-byte shared secret given (pk1, pk2, sk, is_party_a)
|
|
57
88
|
#[pyfunction]
|
|
58
89
|
fn derive_shared_secret<'py>(
|
|
@@ -88,6 +119,7 @@ fn derive_shared_secret<'py>(
|
|
|
88
119
|
#[pymodule]
|
|
89
120
|
fn _swoosh(_py: Python, m: &PyModule) -> PyResult<()> {
|
|
90
121
|
m.add_function(wrap_pyfunction!(keygen, m)?)?;
|
|
122
|
+
m.add_function(wrap_pyfunction!(keygen_seeded, m)?)?;
|
|
91
123
|
m.add_function(wrap_pyfunction!(derive_shared_secret, m)?)?;
|
|
92
124
|
Ok(())
|
|
93
125
|
}
|
|
@@ -8,6 +8,14 @@ def keygen(is_party_a: bool) -> tuple[bytes, bytes]:
|
|
|
8
8
|
"""
|
|
9
9
|
...
|
|
10
10
|
|
|
11
|
+
def keygen_seeded(is_party_a: bool, seed: bytes) -> tuple[bytes, bytes]:
|
|
12
|
+
"""Deterministically generate a (secret_key, public_key) pair from a 32-byte seed.
|
|
13
|
+
|
|
14
|
+
Same seed + same party => same keypair. WARNING: reusing a seed reuses
|
|
15
|
+
the secret key; use a fresh secret seed (or plain `keygen`) in production.
|
|
16
|
+
"""
|
|
17
|
+
...
|
|
18
|
+
|
|
11
19
|
def derive_shared_secret(
|
|
12
20
|
own_pk: bytes,
|
|
13
21
|
other_pk: bytes,
|
|
@@ -41,21 +41,34 @@ pub fn pswoosh_keygen(a: &Matrix, f:bool) -> ([u8; SECRETKEY_BYTES], [u8; PUBLIC
|
|
|
41
41
|
kg(a, f)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/*
|
|
45
|
+
* Seeded key generation wrapper (deterministic: same seed => same keypair).
|
|
46
|
+
* The seed must be 32 bytes, fresh and secret in production use.
|
|
47
|
+
*/
|
|
48
|
+
pub fn pswoosh_keygen_seeded(a: &Matrix, f: bool, noiseseed: &[u8; SYMBYTES]) -> ([u8; SECRETKEY_BYTES], [u8; PUBLICKEY_BYTES]) {
|
|
49
|
+
kg_seeded(a, f, noiseseed)
|
|
50
|
+
}
|
|
51
|
+
|
|
44
52
|
|
|
45
53
|
/*
|
|
46
54
|
* Generate secret and error vectors and compute public key
|
|
47
55
|
*/
|
|
48
56
|
fn kg(a: &Matrix, _f: bool) -> ([u8; SECRETKEY_BYTES], [u8; PUBLICKEY_BYTES]) {
|
|
49
|
-
let mut nonce: u8 = 0;
|
|
50
57
|
let mut noiseseed: [u8; SYMBYTES] = [0; SYMBYTES];
|
|
51
|
-
let skv: [u8; SECRETKEY_BYTES];
|
|
52
|
-
let pkv: [u8; PUBLICKEY_BYTES];
|
|
53
58
|
|
|
54
59
|
getrandom::getrandom(&mut noiseseed).expect("getrandom failed");
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
kg_seeded(a, _f, &noiseseed)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fn kg_seeded(a: &Matrix, _f: bool, noiseseed: &[u8; SYMBYTES]) -> ([u8; SECRETKEY_BYTES], [u8; PUBLICKEY_BYTES]) {
|
|
65
|
+
let mut nonce: u8 = 0;
|
|
66
|
+
let skv: [u8; SECRETKEY_BYTES];
|
|
67
|
+
let pkv: [u8; PUBLICKEY_BYTES];
|
|
68
|
+
|
|
69
|
+
let mut s: PolyVec = getnoise(noiseseed, nonce);
|
|
57
70
|
nonce += 1;
|
|
58
|
-
let mut e: PolyVec = getnoise(
|
|
71
|
+
let mut e: PolyVec = getnoise(noiseseed, nonce);
|
|
59
72
|
|
|
60
73
|
let pk: PolyVec = gen_pk(a, &mut s, &mut e);
|
|
61
74
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|