Skip to content

Commit

Permalink
Merge pull request #5 from sheroz/sheroz-docs
Browse files Browse the repository at this point in the history
fixed documentation formatting issues
  • Loading branch information
sheroz authored Jul 7, 2023
2 parents 05c75fb + be63c57 commit 6bd5a45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cipher_magma"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = ["Sheroz Khaydarov"]
description = "Block Cipher Magma (GOST R 34.12-2015, former GOST 28147-89)"
Expand Down
24 changes: 16 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Block Cipher "Magma"
//! **Block Cipher "Magma"**
//!
//! Implemented and tested according to specifications:
//! 1. [RFC 8891](https://datatracker.ietf.org/doc/html/rfc8891.html) a.k.a GOST R 34.12-2015
Expand All @@ -13,20 +13,18 @@ pub struct Magma {

/// Cipher mode
///
/// Only ECB mode is currently implemented.
/// Only **ECB** mode is currently implemented.
///
/// CTR, CFB, MAC modes are not implemented yet.
/// **CTR**, **CFB**, **MAC** modes **are not implemented** yet.
pub enum CipherMode {
/// Electronic Codebook Mode
ECB,

/*
/// Counter Encryption Mode
CTR,
/// CipherFeedback Mode
CFB,
/// Message Authentication Code
MAC,
*/
Expand All @@ -35,6 +33,7 @@ pub enum CipherMode {
impl Magma {

/// Substitution Box (S-Box) data according to [Appendix C. RFC7836](https://datatracker.ietf.org/doc/html/rfc7836#appendix-C)
///
/// Parameter set: id-tc26-gost-28147-param-Z
pub const SUBSTITUTION_BOX_RFC7836: [u8;128] = [
0xC, 0x4, 0x6, 0x2, 0xA, 0x5, 0xB, 0x9, 0xE, 0x8, 0xD, 0x7, 0x0, 0x3, 0xF, 0x1,
Expand All @@ -48,8 +47,10 @@ impl Magma {
];

/// Substitution Box (S-Box) data according to [RFC5831](https://datatracker.ietf.org/doc/html/rfc5831#section-7.1)
///
/// As per [Appendix B of RFC8891](https://datatracker.ietf.org/doc/html/rfc8891.html#section-appendix.b) data values converted
/// from little-endian to big-endian format.
///
/// OID: 1.2.643.2.2.30.0
pub const SUBSTITUTION_BOX_RFC5831: [u8;128] = [
0x4, 0xA, 0x9, 0x2, 0xD, 0x8, 0x0, 0xE, 0x6, 0xB, 0x1, 0xC, 0x7, 0xF, 0x5, 0x3,
Expand Down Expand Up @@ -134,7 +135,7 @@ impl Magma {
self.prepare_round_keys();
}

/// Prepares [round keys](https://datatracker.ietf.org/doc/html/rfc8891.html#section-4.3) from the cipher key according
/// Prepares [round keys](https://datatracker.ietf.org/doc/html/rfc8891.html#section-4.3) from the cipher key
fn prepare_round_keys(&mut self) {
const ROUND_KEY_POSITION: [u8;32] = [
0, 1, 2, 3, 4, 5, 6, 7,
Expand All @@ -150,6 +151,7 @@ impl Magma {
}

/// [Transformation](https://datatracker.ietf.org/doc/html/rfc8891.html#section-4.2)
///
/// `t: V_32 -> V_32`
#[inline]
fn transformation_t(&self, a: u32) -> u32 {
Expand All @@ -165,6 +167,7 @@ impl Magma {
}

/// [Transformation](https://datatracker.ietf.org/doc/html/rfc8891.html#section-4.2)
///
/// `g[k]: V_32 -> V_32`
#[inline]
fn transformation_g(&self, k: u32, a: u32) -> u32 {
Expand All @@ -173,6 +176,7 @@ impl Magma {
}

/// [Transformation](https://datatracker.ietf.org/doc/html/rfc8891.html#section-4.2)
///
/// `G[k]: V_32[*]V_32 -> V_32[*]V_32`
#[inline]
fn transformation_big_g(&self, k: u32, a_1: u32, a_0: u32) -> (u32, u32) {
Expand All @@ -189,7 +193,8 @@ impl Magma {
((a_0 as u64) << 32) | (a_1 as u64)
}

/// Returns [encrypted block](https://datatracker.ietf.org/doc/html/rfc8891.html#section-5.1) as a u64 value
/// Returns [encrypted block](https://datatracker.ietf.org/doc/html/rfc8891.html#section-5.1) as `u64` value
///
/// # Arguments
///
/// * `block_u64` - A `u64` value
Expand All @@ -208,7 +213,8 @@ impl Magma {
Magma::u64_join(a_1, a_0)
}

/// Returns [decrypted block](https://datatracker.ietf.org/doc/html/rfc8891.html#section-5.2) as a u64 value
/// Returns [decrypted block](https://datatracker.ietf.org/doc/html/rfc8891.html#section-5.2) as `u64` value
///
/// # Arguments
///
/// * `block_u64` - A `u64` value
Expand All @@ -228,6 +234,7 @@ impl Magma {
}

/// Returns encrypted buffer as `Vec<u8>`
///
/// # Arguments
///
/// * `buf` - A plaintext as `&[u8]` slice
Expand All @@ -239,6 +246,7 @@ impl Magma {
}

/// Returns decrypted buffer as `Vec<u8>`
///
/// # Arguments
///
/// * `buf` - A ciphertext as `&[u8]` slice
Expand Down

0 comments on commit 6bd5a45

Please sign in to comment.