beaconcrypt 0.3.7__tar.gz → 0.3.10__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.
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/.github/workflows/go.yml +4 -3
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/.github/workflows/python.yml +17 -7
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/.github/workflows/release.yml +7 -1
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/.github/workflows/rust.yml +2 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/Cargo.lock +3 -3
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/Cargo.toml +4 -2
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/PKG-INFO +1 -1
- beaconcrypt-0.3.10/beaconcrypt.pyi +2 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/bindings.h +75 -0
- beaconcrypt-0.3.10/examples/c/CMakeLists.txt +70 -0
- beaconcrypt-0.3.10/examples/c/README.md +16 -0
- beaconcrypt-0.3.10/examples/c/main.c +308 -0
- beaconcrypt-0.3.10/examples/go/README.md +6 -0
- beaconcrypt-0.3.10/examples/go/go.mod +7 -0
- beaconcrypt-0.3.10/examples/go/go.sum +2 -0
- beaconcrypt-0.3.10/examples/go/main.go +152 -0
- beaconcrypt-0.3.10/examples/python/.gitignore +1 -0
- beaconcrypt-0.3.10/examples/python/README.md +4 -0
- beaconcrypt-0.3.10/examples/python/main.py +58 -0
- beaconcrypt-0.3.10/examples/python/pyproject.toml +11 -0
- beaconcrypt-0.3.10/examples/python/uv.lock +176 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/pyproject.toml +1 -0
- beaconcrypt-0.3.10/scripts/generate_python_stubs.py +48 -0
- beaconcrypt-0.3.10/src/cbinds.rs +340 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/error.rs +22 -5
- beaconcrypt-0.3.10/src/gobinds.rs +340 -0
- beaconcrypt-0.3.10/src/lib.rs +87 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/pqxdh.rs +178 -2
- beaconcrypt-0.3.10/src/pybinds.rs +137 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/shared.rs +217 -1
- beaconcrypt-0.3.7/src/lib.rs +0 -551
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/.cargo/config.toml +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/.github/workflows/codeql.yml +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/.gitignore +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/LICENSE +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/README.md +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/beaconcrypt.go +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/beaconcrypt_test.go +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/build.rs +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/clippy.toml +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/doc/protocol.md +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/doc/rationale.md +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/doc/threat_model.md +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/go.mod +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/rustfmt.toml +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/beacon.rs +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/cnsa2.rs +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/schema/cryptoframe.capnp +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/schema/phase1.capnp +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/schema/phase2.capnp +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/schema/protogram.capnp +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/src/server.rs +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/tests/beacon.rs +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/tests/protocol.rs +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/tests/server.rs +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/tests/test_encryption.py +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/tests/test_registration.py +0 -0
- {beaconcrypt-0.3.7 → beaconcrypt-0.3.10}/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:
|
|
@@ -105,8 +107,7 @@ jobs:
|
|
|
105
107
|
- name: Publish module to Go proxy
|
|
106
108
|
run: |
|
|
107
109
|
module_path="$(go list -m)"
|
|
108
|
-
|
|
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:
|
|
68
|
+
run: uv run maturin sdist --out dist
|
|
59
69
|
|
|
60
70
|
- name: Upload source distribution
|
|
61
|
-
uses: actions/upload-artifact@
|
|
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@
|
|
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
|
-
|
|
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
|
|
@@ -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
|
|
@@ -73,6 +77,8 @@ jobs:
|
|
|
73
77
|
|
|
74
78
|
windows-mingw-build:
|
|
75
79
|
runs-on: windows-latest
|
|
80
|
+
permissions:
|
|
81
|
+
contents: read
|
|
76
82
|
|
|
77
83
|
steps:
|
|
78
84
|
- uses: actions/checkout@v7
|
|
@@ -84,7 +84,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
|
|
84
84
|
|
|
85
85
|
[[package]]
|
|
86
86
|
name = "beaconcrypt"
|
|
87
|
-
version = "0.3.
|
|
87
|
+
version = "0.3.10"
|
|
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.
|
|
772
|
+
version = "1.14.0"
|
|
773
773
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
774
|
-
checksum = "
|
|
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.
|
|
3
|
+
version = "0.3.10"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
license-file = "LICENSE"
|
|
6
6
|
readme = "README.md"
|
|
@@ -32,7 +32,9 @@ beacon = []
|
|
|
32
32
|
cnsa2 = ["dep:libcrux-ml-dsa", "dep:libcrux-ml-kem", "dep:libcrux-aesgcm"]
|
|
33
33
|
pqxdh = []
|
|
34
34
|
gobinds = ["beacon", "server", "pqxdh"]
|
|
35
|
-
|
|
35
|
+
cbinds = ["beacon", "server", "pqxdh"]
|
|
36
|
+
pybinds = ["dep:pyo3", "beacon", "server", "pqxdh"]
|
|
37
|
+
all = ["gobinds", "pybinds", "cbinds"]
|
|
36
38
|
|
|
37
39
|
[profile.release]
|
|
38
40
|
strip = true
|
|
@@ -61,6 +61,18 @@ typedef struct beaconcrypt_GoRegistrationResponse {
|
|
|
61
61
|
uint64_t key_id;
|
|
62
62
|
} beaconcrypt_GoRegistrationResponse;
|
|
63
63
|
|
|
64
|
+
typedef struct beaconcrypt_Buffer {
|
|
65
|
+
uint8_t *ptr;
|
|
66
|
+
uintptr_t len;
|
|
67
|
+
uintptr_t cap;
|
|
68
|
+
} beaconcrypt_Buffer;
|
|
69
|
+
|
|
70
|
+
typedef struct beaconcrypt_RegistrationResponse {
|
|
71
|
+
struct beaconcrypt_Buffer response;
|
|
72
|
+
struct beaconcrypt_Buffer beacon_pk;
|
|
73
|
+
uint64_t key_id;
|
|
74
|
+
} beaconcrypt_RegistrationResponse;
|
|
75
|
+
|
|
64
76
|
#ifdef __cplusplus
|
|
65
77
|
extern "C" {
|
|
66
78
|
#endif // __cplusplus
|
|
@@ -466,6 +478,69 @@ struct beaconcrypt_GoBuffer beaconcrypt_go_decrypt_server_message_signed(struct
|
|
|
466
478
|
const uint8_t *ptr,
|
|
467
479
|
uintptr_t len);
|
|
468
480
|
|
|
481
|
+
void beaconcrypt_free_buffer(struct beaconcrypt_Buffer buffer);
|
|
482
|
+
|
|
483
|
+
struct beaconcrypt_BeaconCryptPqxdh *beaconcrypt_server_new(uint64_t server_kid);
|
|
484
|
+
|
|
485
|
+
struct beaconcrypt_BeaconCryptPqxdh *beaconcrypt_server_new_from_seed(uint64_t server_kid,
|
|
486
|
+
const uint8_t *seed_ptr,
|
|
487
|
+
uintptr_t seed_len);
|
|
488
|
+
|
|
489
|
+
struct beaconcrypt_BeaconCryptPqxdh *beaconcrypt_beacon_new(uint64_t server_kid,
|
|
490
|
+
const uint8_t *server_pk_ptr,
|
|
491
|
+
uintptr_t server_pk_len);
|
|
492
|
+
|
|
493
|
+
void beaconcrypt_free(struct beaconcrypt_BeaconCryptPqxdh *handle);
|
|
494
|
+
|
|
495
|
+
struct beaconcrypt_Buffer beaconcrypt_identity_pk(const struct beaconcrypt_BeaconCryptPqxdh *handle);
|
|
496
|
+
|
|
497
|
+
struct beaconcrypt_Buffer beaconcrypt_generate_registration(struct beaconcrypt_BeaconCryptPqxdh *handle);
|
|
498
|
+
|
|
499
|
+
struct beaconcrypt_RegistrationResponse beaconcrypt_register_beacon(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
500
|
+
const uint8_t *reg_ptr,
|
|
501
|
+
uintptr_t reg_len,
|
|
502
|
+
const uint8_t *msg_ptr,
|
|
503
|
+
uintptr_t msg_len);
|
|
504
|
+
|
|
505
|
+
struct beaconcrypt_Buffer beaconcrypt_process_initial_message(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
506
|
+
const uint8_t *ptr,
|
|
507
|
+
uintptr_t len);
|
|
508
|
+
|
|
509
|
+
struct beaconcrypt_Buffer beaconcrypt_encrypt_to_beacon(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
510
|
+
uint64_t key_id,
|
|
511
|
+
const uint8_t *ptr,
|
|
512
|
+
uintptr_t len);
|
|
513
|
+
|
|
514
|
+
struct beaconcrypt_Buffer beaconcrypt_encrypt_to_beacon_signed(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
515
|
+
uint64_t key_id,
|
|
516
|
+
const uint8_t *ptr,
|
|
517
|
+
uintptr_t len);
|
|
518
|
+
|
|
519
|
+
struct beaconcrypt_Buffer beaconcrypt_decrypt_beacon_message(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
520
|
+
uint64_t key_id,
|
|
521
|
+
const uint8_t *ptr,
|
|
522
|
+
uintptr_t len);
|
|
523
|
+
|
|
524
|
+
struct beaconcrypt_Buffer beaconcrypt_decrypt_beacon_message_signed(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
525
|
+
const uint8_t *ptr,
|
|
526
|
+
uintptr_t len);
|
|
527
|
+
|
|
528
|
+
struct beaconcrypt_Buffer beaconcrypt_encrypt_to_server(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
529
|
+
const uint8_t *ptr,
|
|
530
|
+
uintptr_t len);
|
|
531
|
+
|
|
532
|
+
struct beaconcrypt_Buffer beaconcrypt_encrypt_to_server_signed(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
533
|
+
const uint8_t *ptr,
|
|
534
|
+
uintptr_t len);
|
|
535
|
+
|
|
536
|
+
struct beaconcrypt_Buffer beaconcrypt_decrypt_server_message(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
537
|
+
const uint8_t *ptr,
|
|
538
|
+
uintptr_t len);
|
|
539
|
+
|
|
540
|
+
struct beaconcrypt_Buffer beaconcrypt_decrypt_server_message_signed(struct beaconcrypt_BeaconCryptPqxdh *handle,
|
|
541
|
+
const uint8_t *ptr,
|
|
542
|
+
uintptr_t len);
|
|
543
|
+
|
|
469
544
|
#ifdef __cplusplus
|
|
470
545
|
} // extern "C"
|
|
471
546
|
#endif // __cplusplus
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
|
|
3
|
+
project(beaconcrypt_c_example C)
|
|
4
|
+
|
|
5
|
+
set(CMAKE_C_STANDARD 11)
|
|
6
|
+
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
7
|
+
set(CMAKE_C_EXTENSIONS OFF)
|
|
8
|
+
|
|
9
|
+
get_filename_component(BEACONCRYPT_REPO_ROOT "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
|
|
10
|
+
|
|
11
|
+
find_program(CARGO_EXECUTABLE cargo REQUIRED)
|
|
12
|
+
|
|
13
|
+
option(BEACONCRYPT_CARGO_RELEASE "Build beaconcrypt with Cargo's release profile" OFF)
|
|
14
|
+
|
|
15
|
+
set(BEACONCRYPT_CARGO_PROFILE debug)
|
|
16
|
+
set(BEACONCRYPT_CARGO_ARGS build --features cbinds)
|
|
17
|
+
if(BEACONCRYPT_CARGO_RELEASE)
|
|
18
|
+
set(BEACONCRYPT_CARGO_PROFILE release)
|
|
19
|
+
list(APPEND BEACONCRYPT_CARGO_ARGS --release)
|
|
20
|
+
endif()
|
|
21
|
+
|
|
22
|
+
set(BEACONCRYPT_CARGO_TARGET_DIR "${BEACONCRYPT_REPO_ROOT}/target/${BEACONCRYPT_CARGO_PROFILE}")
|
|
23
|
+
|
|
24
|
+
if(WIN32)
|
|
25
|
+
set(BEACONCRYPT_SHARED_LIBRARY "${BEACONCRYPT_CARGO_TARGET_DIR}/beaconcrypt.dll")
|
|
26
|
+
if(MSVC)
|
|
27
|
+
set(BEACONCRYPT_IMPORT_LIBRARY "${BEACONCRYPT_CARGO_TARGET_DIR}/beaconcrypt.dll.lib")
|
|
28
|
+
else()
|
|
29
|
+
set(BEACONCRYPT_IMPORT_LIBRARY "${BEACONCRYPT_CARGO_TARGET_DIR}/libbeaconcrypt.dll.a")
|
|
30
|
+
endif()
|
|
31
|
+
elseif(APPLE)
|
|
32
|
+
set(BEACONCRYPT_SHARED_LIBRARY "${BEACONCRYPT_CARGO_TARGET_DIR}/libbeaconcrypt.dylib")
|
|
33
|
+
set(BEACONCRYPT_IMPORT_LIBRARY "${BEACONCRYPT_SHARED_LIBRARY}")
|
|
34
|
+
else()
|
|
35
|
+
set(BEACONCRYPT_SHARED_LIBRARY "${BEACONCRYPT_CARGO_TARGET_DIR}/libbeaconcrypt.so")
|
|
36
|
+
set(BEACONCRYPT_IMPORT_LIBRARY "${BEACONCRYPT_SHARED_LIBRARY}")
|
|
37
|
+
endif()
|
|
38
|
+
|
|
39
|
+
add_custom_target(beaconcrypt_rust
|
|
40
|
+
COMMAND "${CARGO_EXECUTABLE}" ${BEACONCRYPT_CARGO_ARGS}
|
|
41
|
+
WORKING_DIRECTORY "${BEACONCRYPT_REPO_ROOT}"
|
|
42
|
+
BYPRODUCTS "${BEACONCRYPT_SHARED_LIBRARY}" "${BEACONCRYPT_IMPORT_LIBRARY}"
|
|
43
|
+
VERBATIM
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
add_library(beaconcrypt_shared SHARED IMPORTED GLOBAL)
|
|
47
|
+
set_target_properties(beaconcrypt_shared PROPERTIES
|
|
48
|
+
IMPORTED_LOCATION "${BEACONCRYPT_SHARED_LIBRARY}"
|
|
49
|
+
)
|
|
50
|
+
if(WIN32)
|
|
51
|
+
set_target_properties(beaconcrypt_shared PROPERTIES
|
|
52
|
+
IMPORTED_IMPLIB "${BEACONCRYPT_IMPORT_LIBRARY}"
|
|
53
|
+
)
|
|
54
|
+
endif()
|
|
55
|
+
|
|
56
|
+
add_executable(beaconcrypt_c_example main.c)
|
|
57
|
+
add_dependencies(beaconcrypt_c_example beaconcrypt_rust)
|
|
58
|
+
target_include_directories(beaconcrypt_c_example PRIVATE "${BEACONCRYPT_REPO_ROOT}")
|
|
59
|
+
target_link_libraries(beaconcrypt_c_example PRIVATE beaconcrypt_shared)
|
|
60
|
+
|
|
61
|
+
if(WIN32)
|
|
62
|
+
target_link_libraries(beaconcrypt_c_example PRIVATE bcrypt)
|
|
63
|
+
endif()
|
|
64
|
+
|
|
65
|
+
add_custom_command(TARGET beaconcrypt_c_example POST_BUILD
|
|
66
|
+
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
|
|
67
|
+
"${BEACONCRYPT_SHARED_LIBRARY}"
|
|
68
|
+
"$<TARGET_FILE_DIR:beaconcrypt_c_example>"
|
|
69
|
+
VERBATIM
|
|
70
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Small demo of how to use the beaconcrypt library from C with CMake. Run with:
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
cmake -S . -B build
|
|
5
|
+
cmake --build build
|
|
6
|
+
./build/beaconcrypt_c_example
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
On Windows, the executable may be under a configuration directory:
|
|
10
|
+
|
|
11
|
+
```powershell
|
|
12
|
+
.\build\Debug\beaconcrypt_c_example.exe
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If you build with the Visual Studio/MSVC CMake toolchain, use the Rust MSVC
|
|
16
|
+
toolchain too. If you build with MinGW, use the Rust GNU toolchain.
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// SPDX-License-Identifier: 0BSD
|
|
2
|
+
|
|
3
|
+
#include "bindings.h"
|
|
4
|
+
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
#ifdef _WIN32
|
|
11
|
+
#include <windows.h>
|
|
12
|
+
|
|
13
|
+
#include <bcrypt.h>
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#define SERVER_KID 0
|
|
17
|
+
#define TRANSPORT_PATH "transport"
|
|
18
|
+
|
|
19
|
+
static const uint8_t REGISTRATION_MESSAGE[] = "registration ok";
|
|
20
|
+
|
|
21
|
+
static void free_buffer(beaconcrypt_Buffer *buffer) {
|
|
22
|
+
if (buffer != NULL && buffer->ptr != NULL) {
|
|
23
|
+
beaconcrypt_free_buffer(*buffer);
|
|
24
|
+
buffer->ptr = NULL;
|
|
25
|
+
buffer->len = 0;
|
|
26
|
+
buffer->cap = 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static void
|
|
31
|
+
free_registration_response(beaconcrypt_RegistrationResponse *response) {
|
|
32
|
+
if (response != NULL) {
|
|
33
|
+
free_buffer(&response->response);
|
|
34
|
+
free_buffer(&response->beacon_pk);
|
|
35
|
+
response->key_id = 0;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static int buffer_is_empty(beaconcrypt_Buffer buffer) {
|
|
40
|
+
return buffer.ptr == NULL;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static int fill_random(uint8_t *buffer, size_t len) {
|
|
44
|
+
#ifdef _WIN32
|
|
45
|
+
return BCryptGenRandom(NULL, buffer, (ULONG)len,
|
|
46
|
+
BCRYPT_USE_SYSTEM_PREFERRED_RNG) == 0
|
|
47
|
+
? 0
|
|
48
|
+
: -1;
|
|
49
|
+
#else
|
|
50
|
+
FILE *file = fopen("/dev/urandom", "rb");
|
|
51
|
+
if (file == NULL) {
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
size_t read_len = fread(buffer, 1, len, file);
|
|
55
|
+
int close_result = fclose(file);
|
|
56
|
+
return read_len == len && close_result == 0 ? 0 : -1;
|
|
57
|
+
#endif
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static int write_transport(const uint8_t *data, size_t len) {
|
|
61
|
+
FILE *file = fopen(TRANSPORT_PATH, "wb");
|
|
62
|
+
if (file == NULL) {
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
65
|
+
size_t written = fwrite(data, 1, len, file);
|
|
66
|
+
int close_result = fclose(file);
|
|
67
|
+
return written == len && close_result == 0 ? 0 : -1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static int read_transport(uint8_t **out, size_t *out_len) {
|
|
71
|
+
*out = NULL;
|
|
72
|
+
*out_len = 0;
|
|
73
|
+
|
|
74
|
+
FILE *file = fopen(TRANSPORT_PATH, "rb");
|
|
75
|
+
if (file == NULL) {
|
|
76
|
+
return -1;
|
|
77
|
+
}
|
|
78
|
+
if (fseek(file, 0, SEEK_END) != 0) {
|
|
79
|
+
fclose(file);
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
long file_len = ftell(file);
|
|
83
|
+
if (file_len <= 0 || fseek(file, 0, SEEK_SET) != 0) {
|
|
84
|
+
fclose(file);
|
|
85
|
+
return -1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
uint8_t *buffer = malloc((size_t)file_len);
|
|
89
|
+
if (buffer == NULL) {
|
|
90
|
+
fclose(file);
|
|
91
|
+
return -1;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
size_t read_len = fread(buffer, 1, (size_t)file_len, file);
|
|
95
|
+
int close_result = fclose(file);
|
|
96
|
+
if (read_len != (size_t)file_len || close_result != 0) {
|
|
97
|
+
free(buffer);
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
*out = buffer;
|
|
102
|
+
*out_len = (size_t)file_len;
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static void print_text(const char *label, beaconcrypt_Buffer buffer) {
|
|
107
|
+
printf("%s: %.*s\n", label, (int)buffer.len, (const char *)buffer.ptr);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static int run(void) {
|
|
111
|
+
int result = 1;
|
|
112
|
+
uint8_t server_seed[32];
|
|
113
|
+
uint8_t *transport = NULL;
|
|
114
|
+
size_t transport_len = 0;
|
|
115
|
+
|
|
116
|
+
beaconcrypt_BeaconCryptPqxdh *server = NULL;
|
|
117
|
+
beaconcrypt_BeaconCryptPqxdh *beacon = NULL;
|
|
118
|
+
beaconcrypt_Buffer server_pk = {0};
|
|
119
|
+
beaconcrypt_Buffer b_reg_1 = {0};
|
|
120
|
+
beaconcrypt_RegistrationResponse s_reg_resp = {0};
|
|
121
|
+
beaconcrypt_Buffer first_message = {0};
|
|
122
|
+
beaconcrypt_Buffer b_ping = {0};
|
|
123
|
+
beaconcrypt_Buffer ping = {0};
|
|
124
|
+
beaconcrypt_Buffer s_task_0 = {0};
|
|
125
|
+
beaconcrypt_Buffer task_0 = {0};
|
|
126
|
+
beaconcrypt_Buffer b_task_1 = {0};
|
|
127
|
+
beaconcrypt_Buffer task_1 = {0};
|
|
128
|
+
|
|
129
|
+
if (fill_random(server_seed, sizeof(server_seed)) != 0) {
|
|
130
|
+
fprintf(stderr, "error: failed to generate server seed\n");
|
|
131
|
+
goto cleanup;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
server = beaconcrypt_server_new_from_seed(SERVER_KID, server_seed,
|
|
135
|
+
sizeof(server_seed));
|
|
136
|
+
if (server == NULL) {
|
|
137
|
+
fprintf(stderr, "error: failed to create server\n");
|
|
138
|
+
goto cleanup;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* It is assumed that the server's public key is compiled into beacons. */
|
|
142
|
+
server_pk = beaconcrypt_identity_pk(server);
|
|
143
|
+
if (buffer_is_empty(server_pk)) {
|
|
144
|
+
fprintf(stderr, "error: failed to get server public key\n");
|
|
145
|
+
goto cleanup;
|
|
146
|
+
}
|
|
147
|
+
beacon = beaconcrypt_beacon_new(SERVER_KID, server_pk.ptr, server_pk.len);
|
|
148
|
+
if (beacon == NULL) {
|
|
149
|
+
fprintf(stderr, "error: failed to create beacon\n");
|
|
150
|
+
goto cleanup;
|
|
151
|
+
}
|
|
152
|
+
free_buffer(&server_pk);
|
|
153
|
+
|
|
154
|
+
/* The beacon is run and registers. */
|
|
155
|
+
b_reg_1 = beaconcrypt_generate_registration(beacon);
|
|
156
|
+
if (buffer_is_empty(b_reg_1)) {
|
|
157
|
+
fprintf(stderr, "error: failed to generate registration\n");
|
|
158
|
+
goto cleanup;
|
|
159
|
+
}
|
|
160
|
+
/* Ship the registration bytes over whichever transport you like. */
|
|
161
|
+
if (write_transport(b_reg_1.ptr, b_reg_1.len) != 0) {
|
|
162
|
+
fprintf(stderr, "error: failed to write registration transport\n");
|
|
163
|
+
goto cleanup;
|
|
164
|
+
}
|
|
165
|
+
free_buffer(&b_reg_1);
|
|
166
|
+
|
|
167
|
+
if (read_transport(&transport, &transport_len) != 0) {
|
|
168
|
+
fprintf(stderr, "error: failed to read registration transport\n");
|
|
169
|
+
goto cleanup;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* Now the server has the registration message and can send an initial message
|
|
173
|
+
* if needed. */
|
|
174
|
+
s_reg_resp = beaconcrypt_register_beacon(server, transport, transport_len,
|
|
175
|
+
REGISTRATION_MESSAGE,
|
|
176
|
+
sizeof(REGISTRATION_MESSAGE) - 1);
|
|
177
|
+
free(transport);
|
|
178
|
+
transport = NULL;
|
|
179
|
+
transport_len = 0;
|
|
180
|
+
if (buffer_is_empty(s_reg_resp.response)) {
|
|
181
|
+
fprintf(stderr, "error: failed to register beacon\n");
|
|
182
|
+
goto cleanup;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* Ship the response back over your transport. */
|
|
186
|
+
if (write_transport(s_reg_resp.response.ptr, s_reg_resp.response.len) != 0) {
|
|
187
|
+
fprintf(stderr, "error: failed to write registration response transport\n");
|
|
188
|
+
goto cleanup;
|
|
189
|
+
}
|
|
190
|
+
if (read_transport(&transport, &transport_len) != 0) {
|
|
191
|
+
fprintf(stderr, "error: failed to read registration response transport\n");
|
|
192
|
+
goto cleanup;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* Do whatever you like with the initial message. */
|
|
196
|
+
first_message =
|
|
197
|
+
beaconcrypt_process_initial_message(beacon, transport, transport_len);
|
|
198
|
+
free(transport);
|
|
199
|
+
transport = NULL;
|
|
200
|
+
transport_len = 0;
|
|
201
|
+
if (buffer_is_empty(first_message)) {
|
|
202
|
+
fprintf(stderr, "error: failed to process initial message\n");
|
|
203
|
+
goto cleanup;
|
|
204
|
+
}
|
|
205
|
+
print_text("Beacon got initial message", first_message);
|
|
206
|
+
free_buffer(&first_message);
|
|
207
|
+
|
|
208
|
+
b_ping =
|
|
209
|
+
beaconcrypt_encrypt_to_server_signed(beacon, (const uint8_t *)"ping", 4);
|
|
210
|
+
if (buffer_is_empty(b_ping) || write_transport(b_ping.ptr, b_ping.len) != 0) {
|
|
211
|
+
fprintf(stderr, "error: failed to send ping\n");
|
|
212
|
+
goto cleanup;
|
|
213
|
+
}
|
|
214
|
+
free_buffer(&b_ping);
|
|
215
|
+
if (read_transport(&transport, &transport_len) != 0) {
|
|
216
|
+
fprintf(stderr, "error: failed to read ping transport\n");
|
|
217
|
+
goto cleanup;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Got the ping, maybe there's a task to send now. */
|
|
221
|
+
ping = beaconcrypt_decrypt_beacon_message_signed(server, transport,
|
|
222
|
+
transport_len);
|
|
223
|
+
free(transport);
|
|
224
|
+
transport = NULL;
|
|
225
|
+
transport_len = 0;
|
|
226
|
+
if (buffer_is_empty(ping)) {
|
|
227
|
+
fprintf(stderr, "error: failed to decrypt ping\n");
|
|
228
|
+
goto cleanup;
|
|
229
|
+
}
|
|
230
|
+
print_text("Server got ping", ping);
|
|
231
|
+
free_buffer(&ping);
|
|
232
|
+
|
|
233
|
+
/* The C2 needs to know what the beacon's ID is so it can encrypt to it. */
|
|
234
|
+
s_task_0 = beaconcrypt_encrypt_to_beacon_signed(
|
|
235
|
+
server, s_reg_resp.key_id, (const uint8_t *)"task contents", 13);
|
|
236
|
+
if (buffer_is_empty(s_task_0) ||
|
|
237
|
+
write_transport(s_task_0.ptr, s_task_0.len) != 0) {
|
|
238
|
+
fprintf(stderr, "error: failed to send first task\n");
|
|
239
|
+
goto cleanup;
|
|
240
|
+
}
|
|
241
|
+
free_buffer(&s_task_0);
|
|
242
|
+
if (read_transport(&transport, &transport_len) != 0) {
|
|
243
|
+
fprintf(stderr, "error: failed to read first task transport\n");
|
|
244
|
+
goto cleanup;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
task_0 = beaconcrypt_decrypt_server_message_signed(beacon, transport,
|
|
248
|
+
transport_len);
|
|
249
|
+
free(transport);
|
|
250
|
+
transport = NULL;
|
|
251
|
+
transport_len = 0;
|
|
252
|
+
if (buffer_is_empty(task_0)) {
|
|
253
|
+
fprintf(stderr, "error: failed to decrypt first task\n");
|
|
254
|
+
goto cleanup;
|
|
255
|
+
}
|
|
256
|
+
print_text("Beacon got first task", task_0);
|
|
257
|
+
free_buffer(&task_0);
|
|
258
|
+
|
|
259
|
+
/* Process task and send the response. */
|
|
260
|
+
b_task_1 = beaconcrypt_encrypt_to_server_signed(
|
|
261
|
+
beacon, (const uint8_t *)"task response", 13);
|
|
262
|
+
if (buffer_is_empty(b_task_1) ||
|
|
263
|
+
write_transport(b_task_1.ptr, b_task_1.len) != 0) {
|
|
264
|
+
fprintf(stderr, "error: failed to send task response\n");
|
|
265
|
+
goto cleanup;
|
|
266
|
+
}
|
|
267
|
+
free_buffer(&b_task_1);
|
|
268
|
+
if (read_transport(&transport, &transport_len) != 0) {
|
|
269
|
+
fprintf(stderr, "error: failed to read task response transport\n");
|
|
270
|
+
goto cleanup;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
task_1 = beaconcrypt_decrypt_beacon_message_signed(server, transport,
|
|
274
|
+
transport_len);
|
|
275
|
+
free(transport);
|
|
276
|
+
transport = NULL;
|
|
277
|
+
transport_len = 0;
|
|
278
|
+
if (buffer_is_empty(task_1)) {
|
|
279
|
+
fprintf(stderr, "error: failed to decrypt task response\n");
|
|
280
|
+
goto cleanup;
|
|
281
|
+
}
|
|
282
|
+
print_text("Server got response to first task", task_1);
|
|
283
|
+
|
|
284
|
+
result = 0;
|
|
285
|
+
|
|
286
|
+
cleanup:
|
|
287
|
+
free(transport);
|
|
288
|
+
free_buffer(&server_pk);
|
|
289
|
+
free_buffer(&b_reg_1);
|
|
290
|
+
free_registration_response(&s_reg_resp);
|
|
291
|
+
free_buffer(&first_message);
|
|
292
|
+
free_buffer(&b_ping);
|
|
293
|
+
free_buffer(&ping);
|
|
294
|
+
free_buffer(&s_task_0);
|
|
295
|
+
free_buffer(&task_0);
|
|
296
|
+
free_buffer(&b_task_1);
|
|
297
|
+
free_buffer(&task_1);
|
|
298
|
+
if (beacon != NULL) {
|
|
299
|
+
beaconcrypt_free(beacon);
|
|
300
|
+
}
|
|
301
|
+
if (server != NULL) {
|
|
302
|
+
beaconcrypt_free(server);
|
|
303
|
+
}
|
|
304
|
+
remove(TRANSPORT_PATH);
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
int main(void) { return run(); }
|