Skip to content

Commit

Permalink
Merge pull request #10 from franziskuskiefer/0.0.4
Browse files Browse the repository at this point in the history
0.0.4
  • Loading branch information
franziskuskiefer authored Dec 18, 2020
2 parents fd0de82 + 988b3a8 commit 4403db2
Show file tree
Hide file tree
Showing 11 changed files with 149,747 additions and 7,118 deletions.
32 changes: 32 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
kind: pipeline
type: docker
name: arm64

platform:
arch: arm64

steps:
- name: test
image: rust:latest
commands:
- apt-get update -qq --yes && apt-get install -qq --yes clang
- git submodule update --init --recursive
- cargo build --verbose
- cargo test --verbose --all-features

---
kind: pipeline
type: docker
name: arm

platform:
arch: arm

steps:
- name: test
image: rust:latest
commands:
- apt-get update -qq --yes && apt-get install -qq --yes clang
- git submodule update --init --recursive
- cargo build --verbose
- cargo test --verbose --all-features
2 changes: 2 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

- name: Run cargo-tarpaulin
uses: actions-rs/[email protected]
with:
timeout: 300

- name: Upload to codecov.io
uses: codecov/codecov-action@v1
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ jobs:
os:
- macos-latest
- ubuntu-latest
# - windows-latest
- windows-latest

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose
- name: Build Release
run: cargo build --release --verbose
- name: Run tests
# Always enabling rust crypto AES for now.
run: cargo test --verbose --features rust-crypto
- name: Run tests all features
# Always enabling rust crypto AES for now.
run: cargo test --verbose --all-features
# Release
- name: Build Release
run: cargo build --release --verbose
- name: Run tests all features
# Always enabling rust crypto AES for now.
run: cargo test --release --verbose --all-features
Expand Down
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "hpke-rs"
version = "0.0.3"
version = "0.0.4"
authors = ["Franziskus Kiefer <[email protected]>"]
edition = "2018"
license = "MPL-2.0"
documentation = "https://docs.rs/hpke-rs"
documentation = "https://www.franziskuskiefer.de/hpke-rs"
description = "HPKE Implementation using Evercrypt"
readme = "README.md"
repository = "https://github.com/franziskuskiefer/hpke-rs"

[dependencies]
evercrypt = { version = "0.0.5" }
evercrypt = "0.0.6"
serde_json = { version = "1.0", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }

Expand Down
7 changes: 6 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
An implementation of [HPKE](https://cfrg.github.io/draft-irtf-cfrg-hpke/draft-irtf-cfrg-hpke.html) using [Evercrypt](https://github.com/franziskuskiefer/evercrypt-rust/tree/master/evercrypt-rs).


![Build & Test](https://github.com/franziskuskiefer/hpke-rs/workflows/Build%20&%20Test/badge.svg)
[![Docs](https://img.shields.io/badge/docs-master-blue.svg)](https://www.franziskuskiefer.de/hpke-rs/hpke_rs/index.html)
[![codecov](https://codecov.io/gh/franziskuskiefer/hpke-rs/branch/master/graph/badge.svg?token=RO2Q0YTSNY)](https://codecov.io/gh/franziskuskiefer/hpke-rs/)
![Beta](https://img.shields.io/badge/maturity-beta-orange.svg)
[![crates.io](https://img.shields.io/crates/v/hpke-rs.svg)](https://crates.io/crates/hpke-rs)

An implementation of [HPKE](https://cfrg.github.io/draft-irtf-cfrg-hpke/draft-irtf-cfrg-hpke.html) using [Evercrypt](https://github.com/franziskuskiefer/evercrypt-rust/tree/master/evercrypt-rs).

This version is compatible with draft-07.
5 changes: 5 additions & 0 deletions src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub enum Mode {

/// ChaCha20 Poly1305
ChaCha20Poly1305 = 0x0003,

/// Export-only
Export = 0xFFFF,
}

impl std::fmt::Display for Mode {
Expand All @@ -33,6 +36,7 @@ impl std::convert::TryFrom<u16> for Mode {
0x0001 => Ok(Mode::AesGcm128),
0x0002 => Ok(Mode::AesGcm256),
0x0003 => Ok(Mode::ChaCha20Poly1305),
0xFFFF => Ok(Mode::Export),
_ => Err(Error::UnknownMode),
}
}
Expand Down Expand Up @@ -112,6 +116,7 @@ fn get_aead_object(mode: Mode) -> Box<dyn AeadTrait> {
Mode::AesGcm128 => Box::new(AesGcm128::new()),
Mode::AesGcm256 => Box::new(AesGcm256::new()),
Mode::ChaCha20Poly1305 => Box::new(ChaCha20Poly1305::new()),
Mode::Export => panic!("Exporter only interface is not implemented yet."),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dh_kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl KemTrait for DhKem {
impl From<EcdhError> for Error {
fn from(e: EcdhError) -> Self {
match e {
EcdhError::UnkownAlgorithm => Self::UnknownMode,
EcdhError::UnknownAlgorithm => Self::UnknownMode,
_ => Self::CryptoError,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/kdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Kdf {
label: &str,
ikm: &[u8],
) -> Vec<u8> {
let labeled_ikm = concat(&[b"HPKE-06", suite_id, &label.as_bytes(), ikm]);
let labeled_ikm = concat(&[b"HPKE-07", suite_id, &label.as_bytes(), ikm]);
self.kdf.extract(salt, &labeled_ikm)
}

Expand All @@ -115,7 +115,7 @@ impl Kdf {
) -> Vec<u8> {
assert!(len < 256);
let len_bytes = (len as u16).to_be_bytes();
let labeled_info = concat(&[&len_bytes, b"HPKE-06", suite_id, &label.as_bytes(), info]);
let labeled_info = concat(&[&len_bytes, b"HPKE-07", suite_id, &label.as_bytes(), info]);
self.kdf.expand(prk, &labeled_info, len)
}

Expand Down
17 changes: 11 additions & 6 deletions tests/test_hpke_kat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ struct CiphertextKAT {
#[derive(Serialize, Deserialize, Debug, Clone)]
#[allow(non_snake_case)]
struct ExportsKAT {
exportContext: String,
exportLength: usize,
exportValue: String,
exporter_context: String,
L: usize,
exported_value: String,
}

#[test]
Expand All @@ -74,6 +74,11 @@ fn test_kat() {
let kdf_id: HpkeKdfMode = test.kdf_id.try_into().unwrap();
let aead_id: HpkeAeadMode = test.aead_id.try_into().unwrap();

if aead_id == HpkeAeadMode::Export {
print!("Exporter only AEAD is not implemented yet.");
continue;
}

if kem_id != HpkeKemMode::DhKem25519 && kem_id != HpkeKemMode::DhKemP256 {
println!(" > KEM {:?} not implemented yet", kem_id);
continue;
Expand Down Expand Up @@ -199,9 +204,9 @@ fn test_kat() {
// Test KAT on direct_ctx for exporters
for (i, export) in test.exports.iter().enumerate() {
println!("Test exporter {} ...", i);
let export_context = hex_to_bytes(&export.exportContext);
let export_value = hex_to_bytes(&export.exportValue);
let length = export.exportLength;
let export_context = hex_to_bytes(&export.exporter_context);
let export_value = hex_to_bytes(&export.exported_value);
let length = export.L;

let exported_secret = direct_ctx.export(&export_context, length);
assert_eq!(export_value, exported_secret);
Expand Down
Loading

0 comments on commit 4403db2

Please sign in to comment.