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.
Files changed (27) hide show
  1. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/Cargo.lock +1 -1
  2. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/Cargo.toml +1 -1
  3. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/PKG-INFO +2 -1
  4. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/README.md +1 -0
  5. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/pyproject.toml +1 -1
  6. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/src/lib.rs +33 -1
  7. python_swoosh-0.1.1/swoosh/__init__.py +6 -0
  8. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/swoosh/__init__.pyi +8 -0
  9. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/lib.rs +18 -5
  10. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/sysA.rs +1 -1
  11. python_swoosh-0.1.0/swoosh/__init__.py +0 -6
  12. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/LICENSE +0 -0
  13. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/Cargo.toml +0 -0
  14. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/build.rs +0 -0
  15. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/aesenc-int.c +0 -0
  16. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/fq.rs +0 -0
  17. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/fq.s +0 -0
  18. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/mod.rs +0 -0
  19. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/params.rs +0 -0
  20. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/poly.rs +0 -0
  21. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/polyvec.rs +0 -0
  22. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/arithmetic/zetas.rs +0 -0
  23. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/bin/bench_full.rs +0 -0
  24. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/bin/bench_scheme.rs +0 -0
  25. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/bin/swoosh.rs +0 -0
  26. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/sys_param.rs +0 -0
  27. {python_swoosh-0.1.0 → python_swoosh-0.1.1}/vendor/ref0/src/util.rs +0 -0
@@ -321,7 +321,7 @@ checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891"
321
321
 
322
322
  [[package]]
323
323
  name = "swoosh"
324
- version = "0.1.0"
324
+ version = "0.1.1"
325
325
  dependencies = [
326
326
  "pyo3",
327
327
  "ref0",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "swoosh"
3
- version = "0.1.0"
3
+ version = "0.1.1"
4
4
  edition = "2021"
5
5
  description = "Python bindings for the SWOOSH lattice-based NIKE reference implementation"
6
6
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-swoosh
3
- Version: 0.1.0
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
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "python-swoosh"
7
- version = "0.1.0"
7
+ version = "0.1.1"
8
8
  description = "Python bindings for the SWOOSH lattice-based NIKE reference implementation"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -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
  }
@@ -0,0 +1,6 @@
1
+ """Python bindings for the SWOOSH lattice-based NIKE."""
2
+
3
+ from ._swoosh import derive_shared_secret, keygen, keygen_seeded
4
+
5
+ __version__ = "0.1.1"
6
+ __all__ = ["keygen", "keygen_seeded", "derive_shared_secret"]
@@ -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
- let mut s: PolyVec = getnoise(&noiseseed, nonce);
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(&noiseseed, nonce);
71
+ let mut e: PolyVec = getnoise(noiseseed, nonce);
59
72
 
60
73
  let pk: PolyVec = gen_pk(a, &mut s, &mut e);
61
74
 
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
- name: python_swoosh-0.1.0/vendor/ref0/src/sysA.rs
2
+ name: python_swoosh-0.1.1/vendor/ref0/src/sysA.rs
3
3
  size: 39287679 bytes
4
4
  sha256: 5714d2f2ac7f1c75d73f191069eb628e15aefa47a8ea7cb7d6c805f5be036fe1
@@ -1,6 +0,0 @@
1
- """Python bindings for the SWOOSH lattice-based NIKE."""
2
-
3
- from ._swoosh import derive_shared_secret, keygen
4
-
5
- __version__ = "0.1.0"
6
- __all__ = ["keygen", "derive_shared_secret"]
File without changes