Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ mutants.out*/
.idea/
.vscode/

# editor swap / backup files
*.swp
*.swo
*~

# Claude Code: ignore personal/local state, but share team tooling
# (skills, slash commands, subagents, and project settings.json).
.claude/*
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = "0.1.3"

# *** Internal Dependencies ***
bouncycastle = { path = "./" }
bouncycastle-aes-lowmemory = { path = "./crypto/aes-lowmemory" }
bouncycastle-aes = { path = "./crypto/aes" }
bouncycastle-base64 = { path = "./crypto/base64" }
bouncycastle-modes = { path = "./crypto/modes" }
bouncycastle-core = { path = "crypto/core" }
Expand Down Expand Up @@ -45,7 +45,7 @@ version.workspace = true
edition.workspace = true

[dependencies]
bouncycastle-aes-lowmemory.workspace = true
bouncycastle-aes.workspace = true
bouncycastle-base64.workspace = true
bouncycastle-core.workspace = true
bouncycastle-factory.workspace = true
Expand Down
11 changes: 10 additions & 1 deletion QUALITY_AND_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ which parts were done for a very specific reason and should not be changed on a

## Naming Conventions

All normal rust naming convensions from clippy apply. In addition, some library-specific naming conventions:
All normal rust naming conventions from clippy apply, with one exception:

* Where a type, constant or variable corresponds to something a specification (FIPS, RFC, etc) names, keep the
specification's spelling and capitalization, and `#[allow(non_camel_case_types)]`, `#[allow(non_snake_case)]` or
`#[allow(non_upper_case_globals)]` the item locally. So the FIPS 197 cipher is `AES_128`, not `Aes128`, its CBC
mode is `AES_CBC_128`, not `AesCbc128`, and if a specification writes `A` for a matrix and `a` for a vector then
`let A = ...; let a = ...;` is the right thing to do. The point is that a reviewer with the specification open can
match names by eye; that matters more here than rust convention.

In addition, some library-specific naming conventions:

* In constants, "LEN" is the length of a value in bytes (typically used for sizing arrays), whereas "SIZE" is a value in
bits (typically used as a security parameter). For example SHA256 could have constants `HASH_SIZE = 256` and
Expand Down
8 changes: 4 additions & 4 deletions cli/src/aes_cbc_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! separately.

use crate::block_mode_cmd::{BLOCK_LEN, BlockModeAction, decrypt_stream, encrypt_stream, load_key};
use bouncycastle::aes_lowmemory::{Aes128, Aes192, Aes256};
use bouncycastle::aes::{AES_128, AES_192, AES_256};
use bouncycastle::core::key_material::KeyMaterial;
use bouncycastle::core::traits::ElectronicCodeBook;
use bouncycastle::modes::{Cbc, Decrypting, Encrypting};
Expand All @@ -24,7 +24,7 @@ pub(crate) fn aes128_cbc_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
run::<AES_128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
}

pub(crate) fn aes192_cbc_cmd(
Expand All @@ -33,7 +33,7 @@ pub(crate) fn aes192_cbc_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
run::<AES_192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
}

pub(crate) fn aes256_cbc_cmd(
Expand All @@ -42,7 +42,7 @@ pub(crate) fn aes256_cbc_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
run::<AES_256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
}

/// Dispatches to the shared streaming loops with `Cbc` filled in as the mode.
Expand Down
8 changes: 4 additions & 4 deletions cli/src/aes_cfb8_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

use crate::block_mode_cmd::{BLOCK_LEN, BlockModeAction, load_key};
use crate::stream_mode_cmd::run_stream_mode;
use bouncycastle::aes_lowmemory::{Aes128, Aes192, Aes256};
use bouncycastle::aes::{AES_128, AES_192, AES_256};
use bouncycastle::core::key_material::KeyMaterial;
use bouncycastle::core::traits::ElectronicCodeBook;
use bouncycastle::modes::{Cfb8, Decrypting, Encrypting};
Expand All @@ -38,7 +38,7 @@ pub(crate) fn aes128_cfb8_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
run::<AES_128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
}

pub(crate) fn aes192_cfb8_cmd(
Expand All @@ -47,7 +47,7 @@ pub(crate) fn aes192_cfb8_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
run::<AES_192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
}

pub(crate) fn aes256_cfb8_cmd(
Expand All @@ -56,7 +56,7 @@ pub(crate) fn aes256_cfb8_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
run::<AES_256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
}

/// Dispatches to the shared streaming loops with `Cfb8` filled in as the mode.
Expand Down
8 changes: 4 additions & 4 deletions cli/src/aes_cfb_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

use crate::block_mode_cmd::{BLOCK_LEN, BlockModeAction, load_key};
use crate::stream_mode_cmd::run_stream_mode;
use bouncycastle::aes_lowmemory::{Aes128, Aes192, Aes256};
use bouncycastle::aes::{AES_128, AES_192, AES_256};
use bouncycastle::core::key_material::KeyMaterial;
use bouncycastle::core::traits::ElectronicCodeBook;
use bouncycastle::modes::{Cfb, Decrypting, Encrypting};
Expand All @@ -39,7 +39,7 @@ pub(crate) fn aes128_cfb_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
run::<AES_128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
}

pub(crate) fn aes192_cfb_cmd(
Expand All @@ -48,7 +48,7 @@ pub(crate) fn aes192_cfb_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
run::<AES_192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
}

pub(crate) fn aes256_cfb_cmd(
Expand All @@ -57,7 +57,7 @@ pub(crate) fn aes256_cfb_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
run::<AES_256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
}

/// Dispatches to the shared streaming loops with `Cfb` filled in as the mode.
Expand Down
8 changes: 4 additions & 4 deletions cli/src/aes_ctr_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

use crate::block_mode_cmd::{BLOCK_LEN, BlockModeAction, load_key};
use crate::stream_mode_cmd::run_stream_mode;
use bouncycastle::aes_lowmemory::{Aes128, Aes192, Aes256, CTR_NONCE_LEN};
use bouncycastle::aes::{AES_128, AES_192, AES_256, CTR_NONCE_LEN};
use bouncycastle::core::key_material::KeyMaterial;
use bouncycastle::core::traits::ElectronicCodeBook;
use bouncycastle::modes::{Ctr, Decrypting, Encrypting};
Expand All @@ -46,7 +46,7 @@ pub(crate) fn aes128_ctr_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
run::<AES_128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
}

pub(crate) fn aes192_ctr_cmd(
Expand All @@ -55,7 +55,7 @@ pub(crate) fn aes192_ctr_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
run::<AES_192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
}

pub(crate) fn aes256_ctr_cmd(
Expand All @@ -64,7 +64,7 @@ pub(crate) fn aes256_ctr_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
run::<AES_256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
}

/// Dispatches to the shared streaming loops with `Ctr` filled in as the mode.
Expand Down
8 changes: 4 additions & 4 deletions cli/src/aes_ecb_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! `aes*-cbc` or `aes*-cfb` under separate authentication, or better an AEAD.

use crate::block_mode_cmd::{BLOCK_LEN, BlockModeAction, decrypt_stream, encrypt_stream, load_key};
use bouncycastle::aes_lowmemory::{Aes128, Aes192, Aes256};
use bouncycastle::aes::{AES_128, AES_192, AES_256};
use bouncycastle::core::key_material::KeyMaterial;
use bouncycastle::core::traits::ElectronicCodeBook;
use bouncycastle::modes::{Decrypting, Ecb, Encrypting};
Expand All @@ -30,7 +30,7 @@ pub(crate) fn aes128_ecb_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
run::<AES_128, 16>(action, &load_key::<16>(key, key_file, "AES-128"), output_hex);
}

pub(crate) fn aes192_ecb_cmd(
Expand All @@ -39,7 +39,7 @@ pub(crate) fn aes192_ecb_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
run::<AES_192, 24>(action, &load_key::<24>(key, key_file, "AES-192"), output_hex);
}

pub(crate) fn aes256_ecb_cmd(
Expand All @@ -48,7 +48,7 @@ pub(crate) fn aes256_ecb_cmd(
key_file: &Option<String>,
output_hex: bool,
) {
run::<Aes256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
run::<AES_256, 32>(action, &load_key::<32>(key, key_file, "AES-256"), output_hex);
}

/// Dispatches to the shared streaming loops with `Ecb` filled in as the mode. `INIT_DATA_LEN` is 0,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/aes_cfb_cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ fn an_unaligned_message_matches_the_library() {
use bouncycastle::core::traits::StreamCipherDecryptor;
use bouncycastle::modes::{Cfb, Decrypting};

type Aes128Cfb<Dir> = Cfb<bouncycastle::aes_lowmemory::Aes128, Dir, 16, 16>;
type Aes128Cfb<Dir> = Cfb<bouncycastle::aes::AES_128, Dir, 16, 16>;

for len in [5usize, 17, 1000, 1024, 1025, 4099] {
let plaintext = pseudo_random(len, len as u32);
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/aes_ecb_cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ fn encrypt_then_decrypt_round_trips_with_no_iv() {
}
}

/// Round trips at sizes that straddle the 1 KiB streaming chunk, the eight-block batch and the
/// block boundary: 128 is one eight; 144 is an eight plus one block; 1040 is a chunk plus a block.
/// Round trips at sizes that straddle the 1 KiB streaming chunk, the four-block batch and the
/// block boundary: 128 is two fours; 144 is two fours plus one block; 1040 is a chunk plus a block.
#[test]
fn round_trips_across_chunk_and_batch_boundaries() {
for size in [16usize, 32, 128, 144, 1024, 1040, 4096, 4112, 65536] {
Expand Down
Loading
Loading