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

[TR3-FIR-155] Finalize AES HW accelerator drivers for embassy #11

Merged
merged 22 commits into from
Jun 12, 2024

Conversation

grochowski-withintent
Copy link

@grochowski-withintent grochowski-withintent commented Jun 7, 2024

Overview

This change brings drivers for AES hardware accelerator. At this point, only AES CCM is supported.

Methodology and resources

At first, I have taken cryp.rs module from embassy-stm32, and then reworked it to the point of containing ~90% authored code. There was a lot of modifications due to cryp hardware being singnificantly different, as well as removals for the sake of simplifying the interface for us.

All algorithms are build upon RM0434 AES chapter as closely as possible. Currently DMA is the used way of moving payloads around. It is possible to move to polling/interrupts but not possible to choose at this point (though there are tools in place to easily allow that in the future).

Testing

The AES drivers have been proven to work right against several test vectors from RFC3610, and represents same results as currently used software AES. I plan to do automated tests directly at the repository where these will be applied.

Open points

  • This code contains multiple panic invocations in case thing are unbearable for the AES engine.
    I have tried to make them compile-time checks, but unfortunately Rust tools for that are too prototype-y at the moment.
    My understanding is not complying to them would make talking to the application impossible, hence panics are reasonable. @mattcaron-token please let me know if this conforms to your methodology.

  • Due to how DMA works, the input slices for the algorithms must be u32, aligned, even though they are [u8]. There's also no compile time check assuring that, I can only make these panic when this condition is met. Does this work for us?

@grochowski-withintent grochowski-withintent force-pushed the tr3fir-155-finalize-AES-drivers branch 5 times, most recently from 12a08d7 to 8c0080e Compare June 7, 2024 19:02
@grochowski-withintent grochowski-withintent force-pushed the tr3fir-155-finalize-AES-drivers branch from 8c0080e to ffef90c Compare June 7, 2024 19:05
@grochowski-withintent grochowski-withintent requested review from a team June 7, 2024 19:18
@grochowski-withintent grochowski-withintent marked this pull request as ready for review June 7, 2024 19:19
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, let's see what @mattcaron-token has to say about all the copy_from_slice.

Copy link

@mattcaron-token mattcaron-token left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One serious question about the stm32-metapac version.

The rest are piddly things.

Overall, it seems fine, with the caveat that I did not review any of the documents for the AES hardware, so I did not verify that the code is doing what it should per the docs.

Splitting it into a new module was the correct choice here - that way it won't conflict with upstream changes. Good call.

I'll respond to other questions individually.

embassy-stm32/src/aes/mod.rs Outdated Show resolved Hide resolved
embassy-stm32/Cargo.toml Outdated Show resolved Hide resolved
embassy-stm32/Cargo.toml Outdated Show resolved Hide resolved
@mattcaron-token
Copy link

Looks good to me, let's see what @mattcaron-token has to say about all the copy_from_slice.

(matt@spider) ~/workspace/code/embassy (main)$ grep -Ir copy_from_slice * | wc -l
208

I would say that it is consistent with the existing code.

If we want to clean up embassy so it doesn't implicitly panic, we can do that later.

@mattcaron-token
Copy link

Open points

* This code contains multiple `panic` invocations in case thing are unbearable for the AES engine.

Which is consistent with the original code - it does the same thing.

(matt@spider) ~/workspace/code/embassy (main)$ grep -Ir panic * | wc -l
1090

There are many panics on the codebase.

  My understanding is not complying to them would make talking to the application impossible, hence panics are reasonable. @mattcaron-token please let me know if this conforms to your methodology.

I don't like them, but it is consistent with the existing code. Going through and reworking embassy to not panic is a different project altogether.

* Due to how DMA works, the input slices for the algorithms **must** be u32, aligned, even though they are `[u8]`. There's also no compile time check assuring that, I can only make these panic when this condition is met. Does this work for us?

Yes. At least, for now.

@grochowski-withintent grochowski-withintent changed the title Tr3fir 155 finalize aes drivers [TR3-FIR-155] Finalize AES HW accelerator drivers for embassy Jun 11, 2024
Copy link

@mattcaron-token mattcaron-token left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still good with this.

@grochowski-withintent grochowski-withintent merged commit f1f086c into token-main Jun 12, 2024
1 check passed
@ghost ghost deleted the tr3fir-155-finalize-AES-drivers branch July 8, 2024 13:22
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.

2 participants