Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
08d7a7e
add belt-dwp
makavity May 18, 2024
35c591d
cargo fmt
makavity May 18, 2024
f91b95c
rm cargo.lock
makavity May 18, 2024
d005883
fix features
makavity May 18, 2024
9197ed7
add beltdwp bench
makavity May 18, 2024
f3453d4
fix dwp
makavity May 18, 2024
893fcd7
make ghash public
makavity May 19, 2024
0f8ecb4
fix belt-dwp tests
makavity May 19, 2024
6bb004d
fix belt-dwp tests
makavity May 19, 2024
d783635
fix belt-dwp tests
makavity May 19, 2024
a3c7434
update belt-dwp to prerelease
makavity Mar 5, 2025
c0ac13a
add belt-dwp to benches
makavity Mar 5, 2025
5b771fc
fix tests
makavity Mar 5, 2025
6a955f7
fixes for belt-dwp + rebase
makavity Mar 26, 2025
d1d3e6f
Fix tests
makavity Mar 26, 2025
854d183
Fix tests
makavity Mar 26, 2025
c806f30
Add zeroize + edition to 2024 + msrv 1.85
makavity Mar 26, 2025
54b3208
cargo fmt
makavity Mar 27, 2025
547f19a
Fixes for review
makavity Mar 28, 2025
b8c8c00
fix cargo.toml
makavity Mar 28, 2025
360216f
More readable
makavity Mar 28, 2025
669aee7
Store BetlBlock instead of raw key
makavity Mar 28, 2025
8fe1573
Fix zeroize
makavity Mar 28, 2025
1bb3d47
fix get_sizes_block
makavity Mar 28, 2025
989ca57
Move initialization to trait implementation
makavity Mar 28, 2025
32ac38a
BeltDwp is generic now
makavity Mar 28, 2025
46e01d3
cargo fmt
makavity Mar 28, 2025
2e5a142
Remove type alias from examples
makavity Mar 28, 2025
a198446
Impl InnerInit instead of KeySizeUser
makavity Mar 28, 2025
f95b3f6
Fixes for generic, type alias
makavity Mar 28, 2025
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
69 changes: 69 additions & 0 deletions .github/workflows/belt-dwp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: belt-dwp

on:
pull_request:
paths:
- ".github/workflows/belt-dwp.yml"
- "belt-dwp/**"
- "Cargo.*"
push:
branches: master

defaults:
run:
working-directory: belt-dwp

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-Dwarnings"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.85.0 # MSRV
- stable
target:
- armv7a-none-eabi
- thumbv7em-none-eabi
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo build --no-default-features --release --target ${{ matrix.target }}

test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.85.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.85.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: ${{ matrix.deps }}
- run: cargo test --target ${{ matrix.target }} --release --no-default-features --lib
- run: cargo test --target ${{ matrix.target }} --release
- run: cargo test --target ${{ matrix.target }} --release --features heapless
- run: cargo test --target ${{ matrix.target }} --release --all-features
- run: cargo build --target ${{ matrix.target }} --benches
52 changes: 46 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"aes-gcm-siv",
"aes-siv",
"ascon-aead",
"belt-dwp",
"ccm",
"chacha20poly1305",
"deoxys",
Expand All @@ -28,3 +29,5 @@ ctr = { git = "https://github.com/RustCrypto/block-modes.git" }
ghash = { git = "https://github.com/RustCrypto/universal-hashes.git" }

pmac = { git = "https://github.com/RustCrypto/MACs.git" }

belt-ctr = { git = "https://github.com/RustCrypto/block-modes.git" }
39 changes: 39 additions & 0 deletions belt-dwp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "belt-dwp"
version = "0.1.0"
description = "Pure Rust implementation of the Belt-DWP authenticated encryption algorithm (STB 34.101.31-2020)"
edition = "2024"
license = "Apache-2.0 OR MIT"
readme = "README.md"
documentation = "https://docs.rs/belt-dwp"
repository = "https://github.com/RustCrypto/AEADs/tree/master/belt-dwp"
keywords = ["aead", "belt-dwp"]
categories = ["cryptography", "no-std"]
rust-version = "1.85"

[dependencies]
aead = { version = "0.6.0-rc.0", default-features = false }
zeroize = { version = "1.7", default-features = false, optional = true }
universal-hash = { version = "0.6.0-rc.0" }
opaque-debug = { version = "0.3" }
subtle = { version = "2", default-features = false }

belt-block = { version = "0.2.0-pre.2" }
belt-ctr = { version = "0.2.0-pre" }

[dev-dependencies]
hex-literal = "1"

[features]
default = ["alloc", "os_rng"]
alloc = ["aead/alloc"]
arrayvec = ["aead/arrayvec"]
bytes = ["aead/bytes"]
os_rng = ["aead/os_rng", "rand_core"]
heapless = ["aead/heapless"]
rand_core = ["aead/rand_core"]
reduced-round = []
zeroize = ["dep:zeroize", "belt-ctr/zeroize"]

[package.metadata.docs.rs]
all-features = true
57 changes: 57 additions & 0 deletions belt-dwp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# RustCrypto: BeltDwp

[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
![Apache2/MIT licensed][license-image]
![Rust Version][rustc-image]
[![Project Chat][chat-image]][chat-link]
[![Build Status][build-image]][build-link]

Pure Rust implementation of **BeltDwp** ([STB 34.101.31-2020][1]): an
[Authenticated Encryption with Associated Data (AEAD)][2].

## About

BeltDwp is republic of Belarus standard for authenticated encryption with associated data.

## Security Notes

No security audits of this crate have ever been performed, and it has not been thoroughly assessed to ensure its operation is constant-time on common CPU architectures.

USE AT YOUR OWN RISK!

## License

Licensed under either of:

* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

[//]: # (badges)

[crate-image]: https://buildstats.info/crate/belt-dwp
[crate-link]: https://crates.io/crates/belt-dwp
[docs-image]: https://docs.rs/belt-dwp/badge.svg
[docs-link]: https://docs.rs/belt-dwp/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260038-AEADs
[downloads-image]: https://img.shields.io/crates/d/chacha20poly1305.svg
[build-image]: https://github.com/RustCrypto/AEADs/workflows/belt-dwp/badge.svg?branch=master&event=push
[build-link]: https://github.com/RustCrypto/AEADs/actions

[//]: # (general links)

[1]: https://apmi.bsu.by/assets/files/std/belt-spec372.pdf
[2]: https://en.wikipedia.org/wiki/Authenticated_encryption
[3]: https://github.com/RustCrypto/stream-ciphers/tree/master/belt-dwp
[4]: https://github.com/RustCrypto/universal-hashes/tree/master/belt-dwp
46 changes: 46 additions & 0 deletions belt-dwp/src/gf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use aead::array::{Array, ArraySize};

mod utils;

pub(crate) mod gf128_soft64;

pub trait GfElement {
type N: ArraySize;

fn new() -> Self;
fn into_bytes(self) -> Array<u8, Self::N>;
fn mul_sum(&mut self, a: &Array<u8, Self::N>, b: &Array<u8, Self::N>);
}

/// Tests from Appendix A, table 18 of [STB 34.101.31-2020](https://apmi.bsu.by/assets/files/std/belt-spec372.pdf)
#[test]
fn test_a18() {
use crate::gf::gf128_soft64::Element;
use aead::consts::U16;
use hex_literal::hex;

type Block = Array<u8, U16>;

let test_vectors = [
(
hex!("34904055 11BE3297 1343724C 5AB793E9"),
hex!("22481783 8761A9D6 E3EC9689 110FB0F3"),
hex!("0001D107 FC67DE40 04DC2C80 3DFD95C3"),
),
(
hex!("703FCCF0 95EE8DF1 C1ABF8EE 8DF1C1AB"),
hex!("2055704E 2EDB48FE 87E74075 A5E77EB1"),
hex!("4A5C9593 8B3FE8F6 74D59BC1 EB356079"),
),
];
for (u, v, w) in test_vectors {
let a = Block::try_from(&u[..]).unwrap();
let b = Block::try_from(&v[..]).unwrap();
let c = Block::try_from(&w[..]).unwrap();

let mut elem = Element::new();
elem.mul_sum(&a, &b);

assert_eq!(c, elem.into_bytes());
}
}
Loading