Skip to content

Commit 514f88e

Browse files
Add BLAKE3 hashing to okapi (#350)
1 parent 501f02f commit 514f88e

File tree

12 files changed

+283
-20
lines changed

12 files changed

+283
-20
lines changed

include/okapi.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ void didcomm_string_free(char *s);
7878
void okapi_bytebuffer_free(struct ByteBuffer v);
7979

8080
void okapi_string_free(char *s);
81+
82+
int32_t blake3_hash(struct ByteBuffer request,
83+
struct ByteBuffer *response,
84+
struct ExternError *err);
85+
86+
int32_t blake3_keyed_hash(struct ByteBuffer request,
87+
struct ByteBuffer *response,
88+
struct ExternError *err);
89+
90+
int32_t blake3_derive_key(struct ByteBuffer request,
91+
struct ByteBuffer *response,
92+
struct ExternError *err);

native/Cargo.lock

Lines changed: 80 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ edition = "2018"
66
# ensure this is not checked in as "true" as it will
77
# cause vendored libraries to fail compilation due
88
# to dependency on protoc compiler
9+
# if you need to compile .proto files, use this line:
10+
#build = "build.rs"
911
build = false
1012

1113
[dependencies]
@@ -22,6 +24,7 @@ serde = "1.0"
2224
serde_json = "1.0"
2325
serde_jcs = "0.1"
2426
sha2 = { version = "0.9", default-features = false }
27+
blake3 = "1.3.1"
2528
bs58 = "0.3"
2629
oberon = { git = "https://github.com/mikelodder7/oberon", branch = "main" }
2730
rand = "0.8"
@@ -32,12 +35,13 @@ name = "okapi"
3235
crate-type = [ "lib", "cdylib", "staticlib" ]
3336

3437
[features]
35-
default = ["ffi"]
38+
default = ["ffi", "hashing"]
3639
ffi = []
40+
hashing = []
3741

3842
[build-dependencies]
3943
prost-build = "0.8"
40-
cbindgen = "0.19.0"
44+
cbindgen = "0.20.0"
4145

4246
[dev-dependencies]
4347
fluid = "0.4"

native/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fn compile_protobuf_files() {
4141
&[
4242
"../proto/okapi/transport/v1/transport.proto",
4343
"../proto/okapi/examples/v1/examples.proto",
44+
"../proto/okapi/hashing/v1/hashing.proto",
4445
"../proto/okapi/keys/v1/keys.proto",
4546
"../proto/okapi/proofs/v1/proofs.proto",
4647
"../proto/okapi/security/v1/security.proto",
@@ -51,13 +52,15 @@ fn compile_protobuf_files() {
5152

5253
copy("okapi.examples.v1.rs", "./src/proto/okapi/okapi_examples.rs").unwrap();
5354
copy("okapi.keys.v1.rs", "./src/proto/okapi/okapi_keys.rs").unwrap();
55+
copy("okapi.hashing.v1.rs", "./src/proto/okapi/okapi_hashing.rs").unwrap();
5456
copy("okapi.transport.v1.rs", "./src/proto/okapi/okapi_transport.rs").unwrap();
5557
copy("okapi.proofs.v1.rs", "./src/proto/okapi/okapi_proofs.rs").unwrap();
5658
copy("okapi.security.v1.rs", "./src/proto/okapi/okapi_security.rs").unwrap();
5759
copy("google.protobuf.rs", "./src/proto/google_protobuf.rs").unwrap();
5860
copy("pbmse.v1.rs", "./src/proto/pbmse.rs").unwrap();
5961
remove_file("okapi.examples.v1.rs").unwrap();
6062
remove_file("okapi.keys.v1.rs").unwrap();
63+
remove_file("okapi.hashing.v1.rs").unwrap();
6164
remove_file("okapi.transport.v1.rs").unwrap();
6265
remove_file("okapi.proofs.v1.rs").unwrap();
6366
remove_file("okapi.security.v1.rs").unwrap();

native/src/ffi/hashing.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::{proto::hashing::*, *};
2+
use ffi_support::{ByteBuffer, ExternError};
3+
4+
#[no_mangle]
5+
pub extern "C" fn blake3_hash(request: ByteBuffer, response: &mut ByteBuffer, err: &mut ExternError) -> i32 {
6+
c_impl!(Blake3HashRequest, Hashing, blake3_hash, request, response, err)
7+
}
8+
9+
#[no_mangle]
10+
pub extern "C" fn blake3_keyed_hash(request: ByteBuffer, response: &mut ByteBuffer, err: &mut ExternError) -> i32 {
11+
c_impl!(Blake3HashRequest, Hashing, blake3_keyed_hash, request, response, err)
12+
}
13+
14+
#[no_mangle]
15+
pub extern "C" fn blake3_derive_key(request: ByteBuffer, response: &mut ByteBuffer, err: &mut ExternError) -> i32 {
16+
c_impl!(Blake3DeriveKeyRequest, Hashing, blake3_derive_key, request, response, err)
17+
}

native/src/ffi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ pub mod didkey;
33
pub mod ldproofs;
44
pub mod oberon;
55
pub mod utils;
6+
pub mod hashing;

0 commit comments

Comments
 (0)