#aes #rijndael #encryption #x86-64 #platform-independent #crypto

no-std aes_crypto

A platform-agnostic library for the AES cipher (Rijndael)

8 releases (4 stable)

new 1.3.0 Oct 29, 2024
1.2.1 Jul 20, 2024
1.2.0 May 19, 2024
0.2.3 May 13, 2024
0.1.0 Apr 21, 2024

#408 in Cryptography

Download history 103/week @ 2024-07-15 23/week @ 2024-07-22 9/week @ 2024-07-29 6/week @ 2024-08-19 23/week @ 2024-09-23 2/week @ 2024-10-14 125/week @ 2024-10-28

127 downloads per month

MIT license

140KB
3K SLoC

This is a pure-Rust platform-agnostic AES library, that is focused on reusability and optimal performance.

This library guarantees the best performance on the target_cpu (if correctly specified). This currently has 7 implementations, among which it automatically decides the best (most performant) using Cargo's target_feature flags.

The implementations and their requirements are:

  • AES-NI (with Vector AES for 2- and 4- blocks) => requires a Nightly Compiler, the nightly feature to be enabled, and compiling for x86(64) with the avx512f and vaes target_feature flags set.
  • AES-NI (with Vector AES for 2-blocks) => requires a Nightly Compiler, the nightly feature to be enabled, and compiling for x86(64) with the vaes target_feature flag set.
  • AES-NI => requires compiling for x86(64) with the sse4.1 and aes target_feature flags set.
  • AES-Neon => requires compiling for AArch64 or ARM64EC or ARM-v8 with the aes target_feature flag set (ARM-v8 requires a Nightly compiler and the nightly feature to be enabled) .
  • AES-RV => Requires a Nightly compiler, the nightly feature to be enabled and compiling for RISC-V RV64 or RV32 with the zkne and zknd target-features enabled (performance considerably improves with the unaligned-scalar-mem target-feature enabled)
  • Software AES => fallback implementation based on Rijmen and Daemen's optimized implementation (available on their website)
  • Constant-time Software AES => Much slower than Software AES, but is constant-time, which can be important in some scenarios. Enabled by the constant-time feature. It is worth noting that all the accelerated AES implementations are constant-time, so this only comes into play when no accelerated version is found.

If you are unsure about the target_feature flags to set, use target_cpu=native (if not cross-compiling) in the RUSTFLAGS environment variable, and use the nightly feature only if you are using a nightly compiler.

Warning

Using the wrong target_feature flags may lead to the binary crashing due to an "Unknown Instruction" error. This library uses these flags to use the CPU intrinsics to maximize performance. If you are unsure what target_features are supported on your CPU, use the command

    rustc --print cfg -C target-cpu=native

Using the nightly feature when not using a nightly compiler can lead to compile failures, so use this only if you are using a nightly compiler.

Dependencies