Skip to content

Commit

Permalink
magma: use const fn for S-Box expansion (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Aug 6, 2023
1 parent a8daf37 commit bfd2f36
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 465 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

8 changes: 8 additions & 0 deletions magma/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.9.0 (2023-08-06)
### Breaking changes
- API of the `Sbox` trait is changed, S-Box expansion is now performed
internally, helper methods are removed. Most users of the crate should not be
affected by this change. ([#376])

[#376]: https://github.com/RustCrypto/block-ciphers/pull/376

## 0.8.1 (2022-02-17)
### Fixed
- Minimal versions build ([#303])
Expand Down
2 changes: 1 addition & 1 deletion magma/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "magma"
version = "0.8.1"
version = "0.9.0"
description = "Magma (GOST R 34.12-2015) block cipher"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
Expand Down
32 changes: 25 additions & 7 deletions magma/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ mod sboxes;

pub use sboxes::Sbox;

use sboxes::SboxExt;

/// Block cipher defined in GOST 28147-89 generic over S-box
#[derive(Clone)]
pub struct Gost89<S: Sbox> {
key: [u32; 8],
_p: PhantomData<S>,
Expand All @@ -88,19 +89,36 @@ impl<S: Sbox> KeyInit for Gost89<S> {
}
}

impl<S: Sbox> Clone for Gost89<S> {
fn clone(&self) -> Self {
Self {
key: self.key,
_p: PhantomData,
}
}
}

impl<S: Sbox> fmt::Debug for Gost89<S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Gost89<")?;
f.write_str(S::NAME)?;
f.write_str("> { ... }")
if S::NAME == "Tc26" {
f.write_str("Magma { ... }")
} else {
f.write_str("Gost89<")?;
f.write_str(S::NAME)?;
f.write_str("> { ... }")
}
}
}

impl<S: Sbox> AlgorithmName for Gost89<S> {
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Gost89<")?;
f.write_str(S::NAME)?;
f.write_str("> { ... }")
if S::NAME == "Tc26" {
f.write_str("Magma { ... }")
} else {
f.write_str("Gost89<")?;
f.write_str(S::NAME)?;
f.write_str("> { ... }")
}
}
}

Expand Down
Loading

0 comments on commit bfd2f36

Please sign in to comment.