Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AES Hardware Abstraction for MAX78000 HAL #9

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Sandvoxel
Copy link

This pull request introduces an AES hardware abstraction layer for the MAX78000 HAL. The new module provides functionality for configuring and using the AES peripheral, including support for key management, encryption, and decryption in 16-byte blocks.


Key Features

  1. AES Key Management:

    • Supports 128-bit, 192-bit, and 256-bit keys using the Key enum.
    • Hardware initialization and key flushing handled automatically.
  2. Encryption and Decryption:

    • Configurable cipher modes for encryption and decryption.
    • Processes data in 16-byte chunks through the AES FIFO interface.
  3. FIFO Operations:

    • Reads and writes to the AES hardware FIFOs for efficient block-based data processing.

Added Files

  • aes.rs: Contains the AES hardware abstraction implementation.

Code Example

use crate::aes::{AES, CipherType, Key};

fn example(aes: &mut AES) {
    // Initialize a 128-bit AES key
    let key = Key::Bits128(&[0x00; 16]);
    aes.set_key(&key);

    // Prepare data to encrypt
    let plaintext = [0x01; 32]; // 32 bytes of plaintext
    let mut ciphertext = [0u8; 32];

    // Encrypt the data
    aes.set_cipher_type(CipherType::Encrypt);
    aes.write_data_to_fifo(&plaintext);
    aes.read_data_from_fifo(&mut ciphertext);

    // Decrypt the data
    aes.set_cipher_type(CipherType::Decrypt);
    aes.write_data_to_fifo(&ciphertext);
    aes.read_data_from_fifo(&mut ciphertext);
}

@WhiteHoodHacker WhiteHoodHacker self-assigned this Jan 28, 2025
@WhiteHoodHacker WhiteHoodHacker self-requested a review January 28, 2025 07:07
@henopied
Copy link
Contributor

Any chance of exposing a RustCrypto compatible interface here? There seem to be some rough edges around the current interface.

@Sandvoxel
Copy link
Author

I feel that would outside the scope of a embedded hal. plus I dont know if I would have time to completed that. Feel free to add this if you would like.

@Sandvoxel
Copy link
Author

Sandvoxel commented Jan 31, 2025

Any chance of exposing a RustCrypto compatible interface here? There seem to be some rough edges around the current interface.

Done tested with AesGcm there is a catch you cannot use the new keyword from AesGcm because cannot pass the setup objects into the constructor. It has to be used like this.

let aes = Aes128Hardware::new_with_key(p.aes, &mut gcr.reg, Key::<Aes128Hardware>::default());


let cipher: AesGcm<Aes128Hardware, U12, U16> = AesGcm::from(aes);
let nonce = Nonce::<U12>::from_slice(&[0u8; 12]);

loop {
    let mut data = [0u8; 16];
  
    console.read_bytes(&mut data);
    console.write_bytes(&data);
  
    let result = cipher.encrypt(&nonce, &data[..]).unwrap();
  
    console.write_bytes(result.as_slice());
  
    let result = cipher.decrypt(&nonce, &result[..]).unwrap();
  
    console.write_bytes(result.as_slice());
}
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants