Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yasmf #3

Merged
merged 4 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# bamboo-blake3-rs
# bamboo-rs-ed25519-yasmf

> Rust implementation of [bamboo-blake3](https://github.com/bamboo-rs/bamboo-blake3).

## Docs
[Rust docs](https://pietgeursen.github.io/bamboo-rs/bamboo_rs_core/index.html)
> Rust implementation of [bamboo-ed25519-yasmf](https://github.com/bamboo-rs/bamboo-ed25519-yasmf).

## About

`bamboo-rs` aspires to be portable, fast and correct.
`bamboo-rs-ed25519-yasmf` aspires to be portable, fast and correct.

### Portable

`bamboo-rs-core` supports compilation with `no_std` and uses crypto libraries that support this too. [Anywhere rust can go](https://forge.rust-lang.org/release/platform-support.html), bamboo can go too, including microcontrollers, mobile and in the browser via web assembly.
`bamboo-rs-core-ed25519-yasmf` supports compilation with `no_std` and uses crypto libraries that support this too. [Anywhere rust can go](https://forge.rust-lang.org/release/platform-support.html), bamboo can go too, including microcontrollers, mobile and in the browser via web assembly.

Bamboo releases target 29 different architectures. Releases of the bamboo_core library expose a c api so you can build bindings to many other languages.
Bamboo releases target many different architectures. Releases of the bamboo_core library expose a c api so you can build bindings to many other languages.

### Fast

Expand Down
6 changes: 3 additions & 3 deletions bamboo-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ crate-type = ["cdylib", "staticlib"]
[features]
default = ["std", "u64_backend"]
std = ["ed25519-dalek/std"]
u32_backend = ["bamboo-rs-core/u32_backend", "ed25519-dalek/u32_backend"]
u64_backend = ["bamboo-rs-core/u64_backend", "ed25519-dalek/u64_backend"]
u32_backend = ["bamboo-rs-core-ed25519-yasmf/u32_backend", "ed25519-dalek/u32_backend"]
u64_backend = ["bamboo-rs-core-ed25519-yasmf/u64_backend", "ed25519-dalek/u64_backend"]

[dependencies]
bamboo-rs-core = {path = "../bamboo-rs-core", default_features = false}
bamboo-rs-core-ed25519-yasmf = {path = "../bamboo-rs-core", default_features = false}
ed25519-dalek = { version = "1.0.1", default-features = false}
4 changes: 2 additions & 2 deletions bamboo-c/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ language = "C"
[parse]
parse_deps = true
clean = true
extra_bindings = ["bamboo-rs-core", "yamf-hash", "ed25519-dalek"]
include = ["bamboo-rs-core", "yamf-hash", "ed25519-dalek"]
extra_bindings = ["bamboo-rs-core-ed25519-yasmf", "yamf-hash", "ed25519-dalek"]
include = ["bamboo-rs-core-ed25519-yasmf", "yamf-hash", "ed25519-dalek"]
exclude = ["typenum", "syn"]
[parse.expand]
features = []
2 changes: 1 addition & 1 deletion bamboo-c/src/decode/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bamboo_rs_core::entry::decode::Error as BambooDecodeError;
use bamboo_rs_core_ed25519_yasmf::entry::decode::Error as BambooDecodeError;

#[repr(C)]
/// cbindgen:prefix-with-name=true
Expand Down
18 changes: 9 additions & 9 deletions bamboo-c/src/decode/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bamboo_rs_core::entry::decode;
use bamboo_rs_core::signature::ED25519_SIGNATURE_SIZE;
use bamboo_rs_core::yamf_hash::{YamfHash, BLAKE2B_HASH_SIZE};
use bamboo_rs_core_ed25519_yasmf::entry::decode;
use bamboo_rs_core_ed25519_yasmf::signature::ED25519_SIGNATURE_SIZE;
use bamboo_rs_core_ed25519_yasmf::yasmf_hash::{YasmfHash, BLAKE3_HASH_SIZE};
use core::slice;
use ed25519_dalek::PUBLIC_KEY_LENGTH;

Expand All @@ -11,13 +11,13 @@ use error::DecodeError;
pub struct CEntry {
pub log_id: u64,
pub is_end_of_feed: bool,
pub payload_hash_bytes: [u8; BLAKE2B_HASH_SIZE],
pub payload_hash_bytes: [u8; BLAKE3_HASH_SIZE],
pub payload_length: u64,
pub author: [u8; PUBLIC_KEY_LENGTH],
pub seq_num: u64,
pub backlink: [u8; BLAKE2B_HASH_SIZE],
pub backlink: [u8; BLAKE3_HASH_SIZE],
pub has_backlink: bool,
pub lipmaa_link: [u8; BLAKE2B_HASH_SIZE],
pub lipmaa_link: [u8; BLAKE3_HASH_SIZE],
pub has_lipmaa_link: bool,
pub sig: [u8; ED25519_SIGNATURE_SIZE],
}
Expand Down Expand Up @@ -54,19 +54,19 @@ pub extern "C" fn decode_ed25519_blake2b_entry(
});

entry.lipmaa_link.map(|lipmaa_link| match lipmaa_link {
YamfHash::Blake2b(bytes) => {
YasmfHash::Blake3(bytes) => {
args.out_decoded_entry.lipmaa_link[..].copy_from_slice(&bytes[..]);
}
});

entry.backlink.map(|backlink| match backlink {
YamfHash::Blake2b(bytes) => {
YasmfHash::Blake3(bytes) => {
args.out_decoded_entry.backlink[..].copy_from_slice(&bytes[..]);
}
});

match entry.payload_hash {
YamfHash::Blake2b(bytes) => {
YasmfHash::Blake3(bytes) => {
args.out_decoded_entry.payload_hash_bytes[..].copy_from_slice(&bytes[..]);
}
};
Expand Down
2 changes: 1 addition & 1 deletion bamboo-c/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use snafu::Snafu;
use bamboo_rs_core::entry::decode::Error as DecodeError;
use bamboo_rs_core_ed25519_yasmf::entry::decode::Error as DecodeError;

#[derive(Debug, Snafu)]
#[snafu(visibility = "pub(crate)")]
Expand Down
2 changes: 1 addition & 1 deletion bamboo-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ pub mod decode;
pub mod publish;
pub mod verify;

pub use bamboo_rs_core::BLAKE2B_HASH_SIZE;
pub use bamboo_rs_core_ed25519_yasmf::BLAKE3_HASH_SIZE;
2 changes: 1 addition & 1 deletion bamboo-c/src/publish/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bamboo_rs_core::entry::publish::Error as BambooPublishError;
use bamboo_rs_core_ed25519_yasmf::entry::publish::Error as BambooPublishError;

#[repr(C)]
/// cbindgen:prefix-with-name=true
Expand Down
8 changes: 4 additions & 4 deletions bamboo-c/src/publish/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use bamboo_rs_core::entry::publish;
use bamboo_rs_core::Keypair;
use bamboo_rs_core_ed25519_yasmf::entry::publish;
use bamboo_rs_core_ed25519_yasmf::Keypair;
use ed25519_dalek::{KEYPAIR_LENGTH, SECRET_KEY_LENGTH};

use core::slice;
pub mod error;
pub use error::PublishError;

#[repr(C)]
pub struct PublishEd25519Blake2bEntryArgs<'a> {
pub struct PublishEd25519Blake3EntryArgs<'a> {
pub out: &'a mut u8,
pub out_length: usize,
pub payload_bytes: &'a u8,
Expand All @@ -27,7 +27,7 @@ pub struct PublishEd25519Blake2bEntryArgs<'a> {

#[no_mangle]
pub extern "C" fn publish_ed25519_blake2b_entry(
args: &mut PublishEd25519Blake2bEntryArgs,
args: &mut PublishEd25519Blake3EntryArgs,
) -> PublishError {
let out: &mut [u8] = unsafe { slice::from_raw_parts_mut(args.out, args.out_length) };
let payload: &[u8] = unsafe { slice::from_raw_parts(args.payload_bytes, args.payload_length) };
Expand Down
2 changes: 1 addition & 1 deletion bamboo-c/src/verify/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bamboo_rs_core::entry::verify::Error as BambooVerifyError;
use bamboo_rs_core_ed25519_yasmf::entry::verify::Error as BambooVerifyError;

#[repr(C)]
/// cbindgen:prefix-with-name=true
Expand Down
6 changes: 3 additions & 3 deletions bamboo-c/src/verify/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use bamboo_rs_core::entry::verify;
use bamboo_rs_core_ed25519_yasmf::entry::verify;
use core::slice;

mod error;
pub use error::VerifyError;

#[repr(C)]
pub struct VerifyEd25519Blake2bEntryArgs<'a> {
pub struct VerifyEd25519Blake3EntryArgs<'a> {
pub entry_bytes: &'a u8,
pub entry_length: usize,
pub payload_bytes: &'a u8,
Expand All @@ -18,7 +18,7 @@ pub struct VerifyEd25519Blake2bEntryArgs<'a> {

#[no_mangle]
pub extern "C" fn verify_ed25519_blake2b_entry(
args: &mut VerifyEd25519Blake2bEntryArgs,
args: &mut VerifyEd25519Blake3EntryArgs,
) -> VerifyError {
let lipmaalink_slice =
unsafe { slice::from_raw_parts(args.lipmaalink_bytes, args.lipmaalink_length) };
Expand Down
2 changes: 1 addition & 1 deletion bamboo-rs-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Piet Geursen <[email protected]>"]
edition = "2018"

[dependencies]
bamboo-rs-core = {path = "../bamboo-rs-core"}
bamboo-rs-core-ed25519-yasmf = {path = "../bamboo-rs-core"}
blake2b_simd = { version = "0.5"}
rand = "0.7.0"
serde_json = "1.0.40"
Expand Down
4 changes: 2 additions & 2 deletions bamboo-rs-cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ pub enum Error {
ParseLogId { source: std::num::ParseIntError },
#[snafu(display("Could not decode entry: {:?}", error))]
DecodeEntry {
error: bamboo_rs_core::entry::decode::Error,
error: bamboo_rs_core_ed25519_yasmf::entry::decode::Error,
},
#[snafu(display("Could not decode previous entry: {:?}", error))]
DecodePreviousEntry {
error: bamboo_rs_core::entry::decode::Error,
error: bamboo_rs_core_ed25519_yasmf::entry::decode::Error,
},
}

Expand Down
12 changes: 6 additions & 6 deletions bamboo-rs-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bamboo_rs_core::entry::MAX_ENTRY_SIZE;
use bamboo_rs_core::{decode, lipmaa, publish, verify, Keypair, YamfHash};
use bamboo_rs_core_ed25519_yasmf::entry::MAX_ENTRY_SIZE;
use bamboo_rs_core_ed25519_yasmf::{decode, lipmaa, publish, verify, Keypair, YasmfHash};
use blake2b_simd::blake2b;
use rand::rngs::OsRng;
use snafu::ResultExt;
Expand Down Expand Up @@ -164,11 +164,11 @@ fn main() -> Result<()> {
Opts::Hash { file } => {
let bytes = read_file(&file).context(DecodeEntryFile { filename: file })?;
let hash = blake2b(&bytes);
let yamf_hash = YamfHash::Blake2b(hash.as_bytes());
let mut yamf_hash_bytes = Vec::new();
yamf_hash.encode_write(&mut yamf_hash_bytes).unwrap();
let yasmf_hash = YasmfHash::Blake3(hash.as_bytes());
let mut yasmf_hash_bytes = Vec::new();
yasmf_hash.encode_write(&mut yasmf_hash_bytes).unwrap();

std::io::stdout().write_all(&yamf_hash_bytes).unwrap();
std::io::stdout().write_all(&yasmf_hash_bytes).unwrap();
}
};
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions bamboo-rs-core-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ authors = ["Piet Geursen <[email protected]>"]
edition = "2018"

[dependencies]
bamboo-rs-core = {path = "../bamboo-rs-core"}
bamboo-rs-core-ed25519-yasmf = {path = "../bamboo-rs-core"}

[dev-dependencies]
bamboo-rs-core = {path = "../bamboo-rs-core"}
bamboo-rs-core-ed25519-yasmf = {path = "../bamboo-rs-core"}
bamboo-rs-log = {path = "../bamboo-rs-log"}
arrayvec = { version = "0.5.1", default-features = false}
serde = { version = "1.0.94", default-features = false , features = ["derive"] }
Expand Down
14 changes: 7 additions & 7 deletions bamboo-rs-core-test/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
extern crate criterion;
extern crate varu64;

use bamboo_rs_core::entry::decode;
use bamboo_rs_core::entry::publish;
use bamboo_rs_core::entry::verify::batch::verify_batch_signatures;
use bamboo_rs_core::entry::verify::Error as VerifyError;
use bamboo_rs_core::entry::verify_batch;
use bamboo_rs_core::verify;
use bamboo_rs_core_ed25519_yasmf::entry::decode;
use bamboo_rs_core_ed25519_yasmf::entry::publish;
use bamboo_rs_core_ed25519_yasmf::entry::verify::batch::verify_batch_signatures;
use bamboo_rs_core_ed25519_yasmf::entry::verify::Error as VerifyError;
use bamboo_rs_core_ed25519_yasmf::entry::verify_batch;
use bamboo_rs_core_ed25519_yasmf::verify;
use bamboo_rs_log::entry_store::MemoryEntryStore;
use bamboo_rs_log::*;

Expand Down Expand Up @@ -163,7 +163,7 @@ fn verify_entries_benches(c: &mut Criterion) {
.enumerate()
.map(|(index, (entry, payload))| {
let seq_num = index + 1;
let lipmaa_num = bamboo_rs_core::lipmaa(seq_num as u64) - 1;
let lipmaa_num = bamboo_rs_core_ed25519_yasmf::lipmaa(seq_num as u64) - 1;

let lipmaa_link = entries
.get(lipmaa_num as usize)
Expand Down
4 changes: 2 additions & 2 deletions bamboo-rs-core-test/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ cargo-fuzz = true

[dependencies]

[dependencies.bamboo-rs-core]
path = "../../bamboo-rs-core"
[dependencies.bamboo-rs-core-ed25519-yasmf]
path = "../../bamboo-rs-core-ed25519-yasmf"

[dependencies.libfuzzer-sys]
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
Expand Down
4 changes: 2 additions & 2 deletions bamboo-rs-core-test/fuzz/fuzz_targets/fuzz_entry_decode.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate bamboo_rs_core;
extern crate bamboo_rs_core_ed25519_yasmf;

use bamboo_rs_core::entry::decode;
use bamboo_rs_core_ed25519_yasmf::entry::decode;

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
Expand Down
28 changes: 14 additions & 14 deletions bamboo-rs-core-test/src/entry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#[cfg(test)]
mod tests {
use bamboo_rs_core::entry::decode;
use bamboo_rs_core::entry::publish::Error as PublishError;
use bamboo_rs_core::entry::verify::batch::verify_batch_signatures;
use bamboo_rs_core::entry::verify::Error as VerifyError;
use bamboo_rs_core::entry::verify_batch;
use bamboo_rs_core::signature::ED25519_SIGNATURE_SIZE;
use bamboo_rs_core::yamf_hash::BLAKE2B_HASH_SIZE;
use bamboo_rs_core::{publish, verify, Entry, Signature, YamfHash};
use bamboo_rs_core_ed25519_yasmf::entry::decode;
use bamboo_rs_core_ed25519_yasmf::entry::publish::Error as PublishError;
use bamboo_rs_core_ed25519_yasmf::entry::verify::batch::verify_batch_signatures;
use bamboo_rs_core_ed25519_yasmf::entry::verify::Error as VerifyError;
use bamboo_rs_core_ed25519_yasmf::entry::verify_batch;
use bamboo_rs_core_ed25519_yasmf::signature::ED25519_SIGNATURE_SIZE;
use bamboo_rs_core_ed25519_yasmf::yasmf_hash::BLAKE3_HASH_SIZE;
use bamboo_rs_core_ed25519_yasmf::{publish, verify, Entry, Signature, YasmfHash};
use ed25519_dalek::{Keypair, PublicKey};
use rand::rngs::OsRng;
use std::io::Write;
use varu64::encode_write as varu64_encode_write;

#[test]
fn encode_write_decode_entry() {
let backlink_bytes = [0xAA; BLAKE2B_HASH_SIZE];
let backlink = YamfHash::<&[u8]>::Blake2b(backlink_bytes[..].into());
let payload_hash_bytes = [0xAB; BLAKE2B_HASH_SIZE];
let payload_hash = YamfHash::<&[u8]>::Blake2b(payload_hash_bytes[..].into());
let backlink_bytes = [0xAA; BLAKE3_HASH_SIZE];
let backlink = YasmfHash::<&[u8]>::Blake3(backlink_bytes[..].into());
let payload_hash_bytes = [0xAB; BLAKE3_HASH_SIZE];
let payload_hash = YasmfHash::<&[u8]>::Blake3(payload_hash_bytes[..].into());
let payload_size = 512;
let seq_num = 2;
let log_id = 333;
Expand All @@ -42,13 +42,13 @@ mod tests {
let entry = decode(&entry_vec).unwrap();

match entry.payload_hash {
YamfHash::Blake2b(ref hash) => {
YasmfHash::Blake3(ref hash) => {
assert_eq!(hash.as_ref(), &payload_hash_bytes[..]);
}
}

match entry.backlink {
Some(YamfHash::Blake2b(ref hash)) => {
Some(YasmfHash::Blake3(ref hash)) => {
assert_eq!(hash.as_ref(), &backlink_bytes[..]);
}
_ => panic!(),
Expand Down
2 changes: 1 addition & 1 deletion bamboo-rs-core-test/src/signature/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(test)]
mod tests {
use bamboo_rs_core::signature::{Error, Signature, ED25519_SIGNATURE_SIZE};
use bamboo_rs_core_ed25519_yasmf::signature::{Error, Signature, ED25519_SIGNATURE_SIZE};

#[test]
fn decode_signature() {
Expand Down
6 changes: 3 additions & 3 deletions bamboo-rs-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bamboo-rs-core"
name = "bamboo-rs-core-ed25519-yasmf"
version = "0.1.0"
authors = ["Piet Geursen <[email protected]>"]
edition = "2018"
Expand All @@ -9,7 +9,7 @@ description = "Publish and verify signed hash chains of bamboo messages."

[features]
default = ["std", "u64_backend"]
std = ["varu64/std", "hex/std", "rayon", "snafu/std", "ed25519-dalek/serde", "ed25519-dalek/std", "ed25519-dalek/batch", "yamf-hash/std"]
std = ["varu64/std", "hex/std", "rayon", "snafu/std", "ed25519-dalek/serde", "ed25519-dalek/std", "ed25519-dalek/batch", "yasmf-hash/std"]
u64_backend = ["ed25519-dalek/u64_backend"]
u32_backend = ["ed25519-dalek/u32_backend"]

Expand All @@ -25,7 +25,7 @@ serde_derive = { version = "1.0", default-features = false }
snafu = { version = "0.6.10", default-features = false }
static_assertions = "0.3"
varu64 = { version ="0.6.2", default-features = false }
yamf-hash = { version = "0.1.2", default-features = false }
yasmf-hash = { version = "0.1.0", default-features = false }

[dev-dependencies]
rand = {version = "0.7.0", default-features = false}
Loading