beaconcrypt 0.3.6__tar.gz → 0.3.9__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 (42) hide show
  1. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/.github/workflows/go.yml +6 -5
  2. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/.github/workflows/python.yml +17 -7
  3. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/.github/workflows/release.yml +46 -4
  4. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/.github/workflows/rust.yml +2 -0
  5. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/Cargo.lock +3 -3
  6. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/Cargo.toml +2 -1
  7. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/PKG-INFO +1 -1
  8. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/README.md +2 -2
  9. beaconcrypt-0.3.9/beaconcrypt.pyi +33 -0
  10. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/bindings.h +0 -9
  11. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/pyproject.toml +1 -0
  12. beaconcrypt-0.3.9/scripts/generate_python_stubs.py +48 -0
  13. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/beacon.rs +13 -17
  14. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/lib.rs +1 -1
  15. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/server.rs +11 -11
  16. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/shared.rs +5 -14
  17. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/.cargo/config.toml +0 -0
  18. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/.github/workflows/codeql.yml +0 -0
  19. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/.gitignore +0 -0
  20. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/LICENSE +0 -0
  21. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/beaconcrypt.go +0 -0
  22. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/beaconcrypt_test.go +0 -0
  23. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/build.rs +0 -0
  24. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/clippy.toml +0 -0
  25. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/doc/protocol.md +0 -0
  26. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/doc/rationale.md +0 -0
  27. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/doc/threat_model.md +0 -0
  28. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/go.mod +0 -0
  29. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/rustfmt.toml +0 -0
  30. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/cnsa2.rs +0 -0
  31. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/error.rs +0 -0
  32. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/pqxdh.rs +0 -0
  33. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/schema/cryptoframe.capnp +0 -0
  34. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/schema/phase1.capnp +0 -0
  35. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/schema/phase2.capnp +0 -0
  36. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/src/schema/protogram.capnp +0 -0
  37. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/tests/beacon.rs +0 -0
  38. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/tests/protocol.rs +0 -0
  39. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/tests/server.rs +0 -0
  40. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/tests/test_encryption.py +0 -0
  41. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/tests/test_registration.py +0 -0
  42. {beaconcrypt-0.3.6 → beaconcrypt-0.3.9}/uv.lock +0 -0
@@ -5,7 +5,7 @@ on:
5
5
  branches:
6
6
  - main
7
7
  tags:
8
- - "[0-9]*.[0-9]*.[0-9]*"
8
+ - "v[0-9]*.[0-9]*.[0-9]*"
9
9
 
10
10
  permissions:
11
11
  contents: read
@@ -19,6 +19,8 @@ jobs:
19
19
  test:
20
20
  name: Test Go module on ${{ matrix.os }}
21
21
  runs-on: ${{ matrix.os }}
22
+ permissions:
23
+ contents: read
22
24
  strategy:
23
25
  fail-fast: false
24
26
  matrix:
@@ -61,7 +63,7 @@ jobs:
61
63
 
62
64
  - name: Build native library
63
65
  if: runner.os != 'Windows'
64
- run: cargo build --verbose
66
+ run: cargo build --verbose --features gobinds
65
67
 
66
68
  - name: Build native library on Windows
67
69
  if: runner.os == 'Windows'
@@ -69,7 +71,7 @@ jobs:
69
71
  CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: gcc
70
72
  run: |
71
73
  rustup target add x86_64-pc-windows-gnu
72
- cargo build --verbose --target x86_64-pc-windows-gnu
74
+ cargo build --verbose --target x86_64-pc-windows-gnu --features gobinds
73
75
 
74
76
  - name: Test Go module
75
77
  if: runner.os != 'Windows'
@@ -105,8 +107,7 @@ jobs:
105
107
  - name: Publish module to Go proxy
106
108
  run: |
107
109
  module_path="$(go list -m)"
108
- version="${GITHUB_REF_NAME}"
109
- go_version="v${version}"
110
+ go_version="${GITHUB_REF_NAME}"
110
111
 
111
112
  git fetch origin "refs/tags/${go_version}:refs/tags/${go_version}" || true
112
113
  if ! git rev-parse --verify --quiet "refs/tags/${go_version}" >/dev/null; then
@@ -13,7 +13,7 @@ on:
13
13
  branches:
14
14
  - main
15
15
  tags:
16
- - "[0-9]*.[0-9]*.[0-9]*"
16
+ - "v[0-9]*.[0-9]*.[0-9]*"
17
17
 
18
18
  permissions:
19
19
  contents: read
@@ -21,6 +21,8 @@ permissions:
21
21
  jobs:
22
22
  test:
23
23
  runs-on: ubuntu-latest
24
+ permissions:
25
+ contents: read
24
26
 
25
27
  steps:
26
28
  - uses: actions/checkout@v7
@@ -38,10 +40,15 @@ jobs:
38
40
  uv run maturin develop --uv
39
41
  uv run pytest tests
40
42
 
43
+ - name: Generate Python stubs
44
+ run: uv run python scripts/generate_python_stubs.py
45
+
41
46
  sdist:
42
47
  if: startsWith(github.ref, 'refs/tags/')
43
48
  needs: test
44
49
  runs-on: ubuntu-latest
50
+ permissions:
51
+ deployments: read
45
52
 
46
53
  steps:
47
54
  - uses: actions/checkout@v7
@@ -54,11 +61,14 @@ jobs:
54
61
  run: |
55
62
  sudo apt install capnproto
56
63
 
64
+ - name: Generate Python stubs
65
+ run: uv run python scripts/generate_python_stubs.py
66
+
57
67
  - name: Build source distribution
58
- run: uvx maturin sdist --out dist
68
+ run: uv run maturin sdist --out dist
59
69
 
60
70
  - name: Upload source distribution
61
- uses: actions/upload-artifact@v4
71
+ uses: actions/upload-artifact@v7
62
72
  with:
63
73
  name: release-sdist
64
74
  path: dist/
@@ -68,6 +78,8 @@ jobs:
68
78
  needs: test
69
79
  name: Build wheels on ${{ matrix.os }}
70
80
  runs-on: ${{ matrix.os }}
81
+ permissions:
82
+ deployments: read
71
83
  strategy:
72
84
  fail-fast: false
73
85
  matrix:
@@ -88,7 +100,7 @@ jobs:
88
100
  output-dir: dist/
89
101
 
90
102
  - name: Upload wheels
91
- uses: actions/upload-artifact@v4
103
+ uses: actions/upload-artifact@v7
92
104
  with:
93
105
  name: release-wheels-${{ matrix.os }}
94
106
  path: dist/
@@ -107,9 +119,7 @@ jobs:
107
119
  # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
108
120
  environment:
109
121
  name: pypi
110
- # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
111
- # url: https://pypi.org/p/YOURPROJECT
112
- url: https://pypi.org/project/beaconcrypt/${{ github.ref_name }}
122
+ url: https://pypi.org/project/beaconcrypt/
113
123
 
114
124
  steps:
115
125
  - name: Retrieve release distributions
@@ -3,7 +3,7 @@ name: Release
3
3
  on:
4
4
  push:
5
5
  tags:
6
- - "[0-9]*.[0-9]*.[0-9]*"
6
+ - "v[0-9]*.[0-9]*.[0-9]*"
7
7
 
8
8
  env:
9
9
  CARGO_TERM_COLOR: always
@@ -14,6 +14,8 @@ jobs:
14
14
  matrix:
15
15
  os: [ubuntu-latest, ubuntu-24.04-arm]
16
16
  runs-on: ${{ matrix.os }}
17
+ permissions:
18
+ contents: read
17
19
 
18
20
  steps:
19
21
  - uses: actions/checkout@v7
@@ -28,7 +30,7 @@ jobs:
28
30
  - name: Build
29
31
  run: |
30
32
  rustup component add rust-src --toolchain nightly
31
- cargo +nightly rustc --release -Z build-std=std,panic_abort --crate-type=staticlib
33
+ cargo +nightly rustc --release -Z build-std=std,panic_abort --no-default-features --features beacon,server,pqxdh --crate-type=staticlib
32
34
  - name: Run tests
33
35
  run: cargo test --verbose
34
36
  - name: Rename
@@ -45,6 +47,8 @@ jobs:
45
47
  matrix:
46
48
  os: [windows-latest]
47
49
  runs-on: ${{ matrix.os }}
50
+ permissions:
51
+ contents: read
48
52
 
49
53
  steps:
50
54
  - uses: actions/checkout@v7
@@ -56,7 +60,7 @@ jobs:
56
60
  run: |
57
61
  $env:Path = "$env:Path;$(join-path $pwd '\capnproto-c++-win32-1.5.0\capnproto-tools-win32-1.5.0')"
58
62
  rustup component add rust-src --toolchain nightly-msvc
59
- cargo +nightly rustc --release -Z build-std=std,panic_abort --crate-type=staticlib
63
+ cargo +nightly rustc --release -Z build-std=std,panic_abort --no-default-features --features beacon,server,pqxdh --crate-type=staticlib
60
64
  ls target/release
61
65
  - name: Run tests
62
66
  run: |
@@ -71,8 +75,46 @@ jobs:
71
75
  path: target/release/beaconcrypt-${{ matrix.os }}.lib
72
76
  retention-days: 7
73
77
 
78
+ windows-mingw-build:
79
+ runs-on: windows-latest
80
+ permissions:
81
+ contents: read
82
+
83
+ steps:
84
+ - uses: actions/checkout@v7
85
+ - name: Set up MinGW
86
+ uses: msys2/setup-msys2@v2
87
+ with:
88
+ install: mingw-w64-x86_64-gcc
89
+ - name: Install cap'n proto
90
+ run: |
91
+ "C:\msys64\mingw64\bin" >> $env:GITHUB_PATH
92
+ curl.exe -O https://capnproto.org/capnproto-c++-win32-1.5.0.zip
93
+ Expand-Archive capnproto-c++-win32-1.5.0.zip
94
+ "$pwd\capnproto-c++-win32-1.5.0\capnproto-tools-win32-1.5.0" >> $env:GITHUB_PATH
95
+ - name: Build
96
+ env:
97
+ CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: gcc
98
+ run: |
99
+ rustup target add x86_64-pc-windows-gnu --toolchain nightly
100
+ rustup component add rust-src --toolchain nightly
101
+ cargo +nightly rustc --release -Z build-std=std,panic_abort --target x86_64-pc-windows-gnu --no-default-features --features beacon,server,pqxdh --crate-type=staticlib
102
+ ls target/x86_64-pc-windows-gnu/release
103
+ - name: Run tests
104
+ env:
105
+ CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: gcc
106
+ run: cargo test --verbose --target x86_64-pc-windows-gnu
107
+ - name: Rename
108
+ run: mv target/x86_64-pc-windows-gnu/release/libbeaconcrypt.a target/x86_64-pc-windows-gnu/release/libbeaconcrypt-windows-mingw-x86_64.a
109
+ - name: Upload release artifact
110
+ uses: actions/upload-artifact@v7
111
+ with:
112
+ name: beaconcrypt-static-windows-mingw-x86_64
113
+ path: target/x86_64-pc-windows-gnu/release/libbeaconcrypt-windows-mingw-x86_64.a
114
+ retention-days: 7
115
+
74
116
  release:
75
- needs: [ubuntu-build, windows-build]
117
+ needs: [ubuntu-build, windows-build, windows-mingw-build]
76
118
  runs-on: ubuntu-latest
77
119
  permissions:
78
120
  contents: write
@@ -13,6 +13,8 @@ jobs:
13
13
  build:
14
14
 
15
15
  runs-on: ubuntu-latest
16
+ permissions:
17
+ contents: read
16
18
 
17
19
  steps:
18
20
  - uses: actions/checkout@v7
@@ -84,7 +84,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
84
84
 
85
85
  [[package]]
86
86
  name = "beaconcrypt"
87
- version = "0.3.6"
87
+ version = "0.3.9"
88
88
  dependencies = [
89
89
  "capnp",
90
90
  "capnpc",
@@ -769,9 +769,9 @@ checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
769
769
 
770
770
  [[package]]
771
771
  name = "portable-atomic"
772
- version = "1.13.1"
772
+ version = "1.14.0"
773
773
  source = "registry+https://github.com/rust-lang/crates.io-index"
774
- checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
774
+ checksum = "3d20d5497ef88037a52ff98267d066e7f11fcc5e99bbfbd58a42336193aacec3"
775
775
 
776
776
  [[package]]
777
777
  name = "proc-macro-error-attr2"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "beaconcrypt"
3
- version = "0.3.6"
3
+ version = "0.3.9"
4
4
  edition = "2024"
5
5
  license-file = "LICENSE"
6
6
  readme = "README.md"
@@ -31,6 +31,7 @@ server = []
31
31
  beacon = []
32
32
  cnsa2 = ["dep:libcrux-ml-dsa", "dep:libcrux-ml-kem", "dep:libcrux-aesgcm"]
33
33
  pqxdh = []
34
+ gobinds = ["beacon", "server", "pqxdh"]
34
35
  pybinds = ["dep:pyo3"]
35
36
 
36
37
  [profile.release]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beaconcrypt
3
- Version: 0.3.6
3
+ Version: 0.3.9
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -58,7 +58,7 @@ For windows, I prefer building with stable-gnu for normal usage, and nightly-gnu
58
58
  Build and run all tests:
59
59
  ```bash
60
60
  cargo test
61
- cargo build --target x86_64-pc-windows-gnu
61
+ cargo build --features gobinds --target x86_64-pc-windows-gnu
62
62
  go test ./...
63
63
  uv run maturin develop --uv
64
64
  uv run pytest tests
@@ -72,7 +72,7 @@ The reference implementation has two profiles: `PQXDH` and `CNSA2`. Profiles are
72
72
  ## Usage
73
73
  The reference implementation is a library that can currently be used either from rust or through C FFI. The C interface is currently not tested.
74
74
 
75
- From rust, usage is mostly just instanciating `CryptoProvider` objects. When using the C FFI, the library creates a global `CryptoProvider` object, whose methods are wrapped by the various functions in the interface. Look at tests for examples.
75
+ From rust, usage is mostly just instanciating `CryptoProvider` objects. When using the C FFI, the library creates a global `CryptoProvider` object, whose methods are wrapped by the various functions in the interface. When using the C FFI, the caller is responsible for the buffers passed into the library. Assume the library does not do any copies, except for initialization functions, and never frees the buffers it is passed.
76
76
 
77
77
  # Copyright
78
78
  This work is dedicated to the public domain.
@@ -0,0 +1,33 @@
1
+ from collections.abc import Sequence
2
+ from typing import final
3
+
4
+ @final
5
+ class BeaconCryptBeacon:
6
+ def __new__(cls, /, server_kid: int, server_id_pk: bytes) -> BeaconCryptBeacon: ...
7
+ def decrypt_server_message(self, /, data: Sequence[int]) -> bytes |None: ...
8
+ def decrypt_server_message_signed(self, /, data: Sequence[int]) -> bytes |None: ...
9
+ def encrypt_message_to_server(self, /, data: Sequence[int]) -> bytes |None: ...
10
+ def encrypt_to_server_signed(self, /, data: Sequence[int]) -> bytes |None: ...
11
+ def generate_registration(self, /) -> bytes |None:
12
+ """
13
+ Begin the beacon registration process. The output buffer should be sent as-is over the network.
14
+ """
15
+ def process_initial_message(self, /, data: Sequence[int]) -> bytes |None:
16
+ """
17
+ Process the registration response and optional initial data. The raw buffer sent by the server must be passed as-is as `data`. The response contains the contents of the initial message, or nothing if there was none. Once this function returns, the beacon is registered
18
+ """
19
+
20
+ @final
21
+ class BeaconCryptServer:
22
+ def __new__(cls, /, kid: int, id_seed: bytes |None) -> BeaconCryptServer: ...
23
+ def decrypt_beacon_message(self, /, data: Sequence[int], kid: int) -> bytes |None: ...
24
+ def decrypt_beacon_message_signed(self, /, data: Sequence[int]) -> bytes |None: ...
25
+ def encrypt_to_beacon(self, /, data: Sequence[int], kid: int) -> bytes |None: ...
26
+ def encrypt_to_beacon_signed(self, /, data: Sequence[int], kid: int) -> bytes |None: ...
27
+ def id_pk(self, /) -> bytes: ...
28
+ def register_beacon(self, /, reg_buffer: bytes, initial_message: bytes |None) -> RegResponse |None: ...
29
+
30
+ @final
31
+ class RegResponse:
32
+ def key_id(self, /) -> int: ...
33
+ def serialized(self, /) -> bytes: ...
@@ -358,15 +358,6 @@ int32_t encrypt_to_beacon_signed(uint64_t key_id,
358
358
  */
359
359
  void init(bool is_beacon, uint64_t server_kid);
360
360
 
361
- /**
362
- * # Safety
363
- * * This function MUST only be called to clean up byte buffers returned by this library, do NOT use as a general `free`
364
- * * `ptr` should NOT be null and should point to a byte buffer of `len` length, in bytes.
365
- */
366
- void free_vec(uint8_t *ptr,
367
- uintptr_t len,
368
- uintptr_t capa);
369
-
370
361
  /**
371
362
  * # Safety
372
363
  * * `bytes` should NOT be null and should point to a byte buffer of `bytes_len` length, in bytes.
@@ -15,6 +15,7 @@ dynamic = ["version"]
15
15
  [tool.maturin]
16
16
  bindings = "pyo3"
17
17
  features = ["pybinds"]
18
+ include = ["beaconcrypt.pyi"]
18
19
 
19
20
  [tool.uv]
20
21
  # `maturin develop` owns the native extension installed in the development
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env python3
2
+ """Generate Python stubs for the PyO3 extension."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import shutil
7
+ import subprocess
8
+ import sys
9
+ from pathlib import Path
10
+
11
+
12
+ ROOT = Path(__file__).resolve().parents[1]
13
+ STUB_NAME = "beaconcrypt.pyi"
14
+
15
+
16
+ def main() -> int:
17
+ maturin = shutil.which("maturin")
18
+ if maturin is None:
19
+ print("maturin was not found on PATH", file=sys.stderr)
20
+ return 1
21
+
22
+ out_dir = ROOT / "target" / "generated-stubs"
23
+ out_dir.mkdir(parents=True, exist_ok=True)
24
+ subprocess.run(
25
+ [
26
+ maturin,
27
+ "generate-stubs",
28
+ "--features",
29
+ "pybinds",
30
+ "--out",
31
+ str(out_dir),
32
+ ],
33
+ cwd=ROOT,
34
+ check=True,
35
+ )
36
+
37
+ generated = out_dir / STUB_NAME
38
+ if not generated.is_file():
39
+ print(f"expected stub was not generated: {generated}", file=sys.stderr)
40
+ return 1
41
+
42
+ shutil.copyfile(generated, ROOT / STUB_NAME)
43
+
44
+ return 0
45
+
46
+
47
+ if __name__ == "__main__":
48
+ raise SystemExit(main())
@@ -2,7 +2,7 @@
2
2
 
3
3
  use crate::shared::{CryptoProvider, INITIALIZED, Provider, STATE};
4
4
  use libsodium_rs::crypto_sign;
5
- use std::{mem, ptr::slice_from_raw_parts, sync::atomic::Ordering, vec};
5
+ use std::{mem, ptr::slice_from_raw_parts, slice::from_raw_parts, sync::atomic::Ordering, vec};
6
6
 
7
7
  pub trait ProviderBeacon {
8
8
  fn get_registration_bundle(&self) -> Option<Vec<u8>>;
@@ -24,11 +24,9 @@ pub unsafe extern "C" fn process_initial_message(
24
24
  if bytes.is_null() || bytes_len == 0 {
25
25
  return -1;
26
26
  }
27
- let mut net_vec = vec![0u8; bytes_len];
28
- let net_slice = slice_from_raw_parts(bytes, bytes_len);
29
- net_vec.copy_from_slice(unsafe { net_slice.as_ref().unwrap() });
27
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
30
28
  let mut state = STATE.lock().unwrap();
31
- match state.finish_registration(net_vec.as_slice()) {
29
+ match state.finish_registration(data_slice) {
32
30
  Some(mut plaintext) => {
33
31
  unsafe {
34
32
  *_out = plaintext.as_mut_ptr();
@@ -57,12 +55,10 @@ pub unsafe extern "C" fn process_initial_message_signed(
57
55
  if bytes.is_null() || bytes_len == 0 {
58
56
  return -1;
59
57
  }
60
- let mut net_vec = vec![0u8; bytes_len];
61
- let net_slice = slice_from_raw_parts(bytes, bytes_len);
62
- net_vec.copy_from_slice(unsafe { net_slice.as_ref().unwrap() });
58
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
63
59
 
64
60
  let mut state = STATE.lock().unwrap();
65
- match state.verify_signature(net_vec.as_slice()) {
61
+ match state.verify_signature(data_slice) {
66
62
  Some(verified) => match state.finish_registration(&verified.data) {
67
63
  Some(mut plaintext) => {
68
64
  unsafe {
@@ -105,10 +101,10 @@ pub unsafe extern "C" fn decrypt_server_message(
105
101
  return -1;
106
102
  }
107
103
  let mut state = STATE.lock().unwrap();
108
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
104
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
109
105
 
110
106
  let srv_kid = state.server_kid();
111
- match state.decrypt_message(&data_vec, srv_kid) {
107
+ match state.decrypt_message(data_slice, srv_kid) {
112
108
  Some(mut plaintext) => {
113
109
  unsafe {
114
110
  *_out = plaintext.as_mut_ptr();
@@ -148,9 +144,9 @@ pub unsafe extern "C" fn decrypt_server_message_signed(
148
144
  return -1;
149
145
  }
150
146
  let mut state = STATE.lock().unwrap();
151
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
147
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
152
148
 
153
- match state.verify_signature(data_vec.as_slice()) {
149
+ match state.verify_signature(data_slice) {
154
150
  Some(verified) => {
155
151
  let srv_kid = state.server_kid();
156
152
  match state.decrypt_message(&verified.data, srv_kid) {
@@ -196,9 +192,9 @@ pub unsafe extern "C" fn encrypt_to_server(
196
192
  return -1;
197
193
  }
198
194
  let mut state = STATE.lock().unwrap();
199
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
195
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
200
196
  let srv_kid = state.server_kid();
201
- match state.encrypt_message(data_vec.as_slice(), srv_kid) {
197
+ match state.encrypt_message(data_slice, srv_kid) {
202
198
  Some(mut ciphertext) => {
203
199
  unsafe {
204
200
  *_out = ciphertext.as_mut_ptr();
@@ -238,9 +234,9 @@ pub unsafe extern "C" fn encrypt_to_server_signed(
238
234
  return -1;
239
235
  }
240
236
  let mut state = STATE.lock().unwrap();
241
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
237
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
242
238
  let srv_kid = state.server_kid();
243
- match state.encrypt_message(data_vec.as_slice(), srv_kid) {
239
+ match state.encrypt_message(data_slice, srv_kid) {
244
240
  Some(ciphertext) => match state.sign_message(ciphertext.as_slice()) {
245
241
  Some(mut signed) => {
246
242
  unsafe {
@@ -74,7 +74,7 @@ capnp::generated_code!(pub mod protogram_capnp);
74
74
  #[cfg(feature = "pybinds")]
75
75
  use pyo3::prelude::*;
76
76
 
77
- #[cfg(feature = "pqxdh")]
77
+ #[cfg(feature = "gobinds")]
78
78
  mod gobinds {
79
79
  use crate::{BeaconCryptPqxdh, CryptoProvider, ProviderBeacon, ProviderServer};
80
80
  use std::mem;
@@ -10,7 +10,7 @@ use libsodium_rs::{crypto_kem, crypto_kx, crypto_sign};
10
10
  use crate::shared::{CryptoProvider, KexDerivedSecret, STATE};
11
11
  #[cfg(feature = "cnsa2")]
12
12
  use std::marker::PhantomData;
13
- use std::{mem, slice::from_raw_parts, vec};
13
+ use std::{mem, slice::from_raw_parts};
14
14
 
15
15
  #[cfg(feature = "pqxdh")]
16
16
  type KemCiphertext = crypto_kem::mlkem768::Ciphertext;
@@ -83,9 +83,9 @@ pub unsafe extern "C" fn register_beacon(
83
83
  if bytes.is_null() || bytes_len == 0 {
84
84
  return -1;
85
85
  }
86
- let bytes_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
87
86
  let mut state = STATE.lock().unwrap();
88
- match state.get_shared_secret(bytes_vec.as_slice()) {
87
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
88
+ match state.get_shared_secret(data_slice) {
89
89
  Some(secrets) => {
90
90
  let to_encrypt = if data.is_null() || data_len == 0 {
91
91
  None
@@ -145,9 +145,9 @@ pub unsafe extern "C" fn decrypt_beacon_message(
145
145
  return -1;
146
146
  }
147
147
  let mut state = STATE.lock().unwrap();
148
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
148
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
149
149
 
150
- match state.decrypt_message(&data_vec, key_id) {
150
+ match state.decrypt_message(data_slice, key_id) {
151
151
  Some(mut plaintext) => {
152
152
  unsafe {
153
153
  *_out = plaintext.as_mut_ptr();
@@ -188,9 +188,9 @@ pub unsafe extern "C" fn decrypt_beacon_message_signed(
188
188
  return -1;
189
189
  }
190
190
  let mut state = STATE.lock().unwrap();
191
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
191
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
192
192
 
193
- match state.verify_signature(data_vec.as_slice()) {
193
+ match state.verify_signature(data_slice) {
194
194
  Some(verified) => match state.decrypt_message(&verified.data, verified.key_id) {
195
195
  Some(mut plaintext) => {
196
196
  unsafe {
@@ -236,8 +236,8 @@ pub unsafe extern "C" fn encrypt_to_beacon(
236
236
  return -1;
237
237
  }
238
238
  let mut state = STATE.lock().unwrap();
239
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
240
- match state.encrypt_message(data_vec.as_slice(), key_id) {
239
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
240
+ match state.encrypt_message(data_slice, key_id) {
241
241
  Some(mut ciphertext) => {
242
242
  unsafe {
243
243
  *_out = ciphertext.as_mut_ptr();
@@ -280,8 +280,8 @@ pub unsafe extern "C" fn encrypt_to_beacon_signed(
280
280
  return -1;
281
281
  }
282
282
  let mut state = STATE.lock().unwrap();
283
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
284
- match state.encrypt_message(data_vec.as_slice(), key_id) {
283
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
284
+ match state.encrypt_message(data_slice, key_id) {
285
285
  Some(ciphertext) => match state.sign_message(ciphertext.as_slice()) {
286
286
  Some(mut signed) => {
287
287
  unsafe {
@@ -10,6 +10,7 @@ use capnp::message::{ReaderOptions, TypedBuilder, TypedReader};
10
10
  use libsodium_rs::{crypto_aead, crypto_kdf};
11
11
  use std::collections::HashMap;
12
12
  use std::marker::PhantomData;
13
+ use std::slice::from_raw_parts;
13
14
  use std::sync::atomic::{AtomicBool, Ordering};
14
15
  use std::sync::{LazyLock, Mutex};
15
16
  use std::{mem, vec};
@@ -631,16 +632,6 @@ pub trait CryptoProvider {
631
632
  }
632
633
  }
633
634
 
634
- /// # Safety
635
- /// * This function MUST only be called to clean up byte buffers returned by this library, do NOT use as a general `free`
636
- /// * `ptr` should NOT be null and should point to a byte buffer of `len` length, in bytes.
637
- #[unsafe(no_mangle)]
638
- pub unsafe extern "C" fn free_vec(ptr: *mut u8, len: usize, capa: usize) {
639
- if !ptr.is_null() {
640
- unsafe { Vec::from_raw_parts(ptr, len, capa) };
641
- }
642
- }
643
-
644
635
  pub fn create_protogram_reader(
645
636
  data: &[u8],
646
637
  ) -> Option<TypedReader<capnp::serialize::OwnedSegments, protogram_capnp::proto_gram::Owned>> {
@@ -686,9 +677,9 @@ pub unsafe extern "C" fn verify_signature(
686
677
  if bytes.is_null() || bytes_len == 0 {
687
678
  return -1;
688
679
  }
689
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
680
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
690
681
  let state = STATE.lock().unwrap();
691
- match state.verify_signature(data_vec.as_slice()) {
682
+ match state.verify_signature(data_slice) {
692
683
  Some(mut verified) => {
693
684
  unsafe {
694
685
  _out = verified.data.as_mut_ptr();
@@ -728,9 +719,9 @@ pub unsafe extern "C" fn sign_message(
728
719
  if bytes.is_null() || bytes_len == 0 {
729
720
  return -1;
730
721
  }
731
- let data_vec = unsafe { vec::Vec::from_raw_parts(bytes.cast_mut(), bytes_len, bytes_len) };
722
+ let data_slice = unsafe { from_raw_parts(bytes, bytes_len) };
732
723
  let state = STATE.lock().unwrap();
733
- match state.sign_message(data_vec.as_slice()) {
724
+ match state.sign_message(data_slice) {
734
725
  Some(mut signed) => {
735
726
  unsafe {
736
727
  _out = signed.as_mut_ptr();
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