Crate aes_crypto

Crate aes_crypto 

Source
Expand description

Actions Status

A pure-Rust platform-agnostic AES library, focused on reusability and optimal performance.

This library guarantees the best performance on the target_cpu (if correctly specified). This currently has quite a few implementations, among which it automatically decides the best (most performant) using rustc’s target_feature flags.

§The implementations and their requirements

Nightly-only means a Nightly compiler is required, and the nightly crate feature must be enabled.

All the implementations are well-tested, but it is still possible for bugs to creep through, especially for the Nightly-only implementations, as those are on the bleeding edge of the compiler. In case you discover a bug, please feel free to file an issue at my repository.

§For Scalar AES (1 block at a time)

ImplementationArchitectureTarget Feature
AES-NIx86/x86_64aes
AES-Neonaarch64/arm64ecaes
armv8+aesNightly-only
AES-RVriscv32/riscv64zkne+zkndNightly-only
AES-PPCpowerpc/powerpc64power8-cryptoNightly-only
Constant-time Software AESNoneNoneRequires the constant-time crate feature
Table-based Software AESNoneNoneBased on Rijmen and Daemen’s optimized implementation (available on their website)

The Constant-time Software AES implementation guards against side-channel attacks, at the cost of some speed. This will only be used if no accelerated AES implementation is found, and the constant-time crate feature is enabled (because all hardware-accelerated AES implementations are always constant-time).

§For X2 Vector AES (2 blocks in parallel)

ImplementationArchitectureTarget Feature
AES-NIx86/x86_64vaesNightly-only

§For X4 Vector AES (4 blocks in parallel)

ImplementationArchitectureTarget Feature
AES-NIx86/x86_64vaes+avx512fNightly-only

For Vector AES, if no accelerated version is found, then a tuple-based implementation is used. That is, if an x86_64 machine has vaes, but not avx512f, then AesBlockX4 will be represented as a wrapper over (AesBlockX2, AesBlockX2) (which still benefits from the X2 parallelism offered by vaes).

If you are unsure, use target_cpu=native (if not cross-compiling; otherwise you can use target_cpu=<CPU of your target machine> with the appropriate target triple) in the RUSTFLAGS environment variable, and use the nightly feature only if you are using a nightly compiler.

§Minimum Supported Rust version

I typically don’t maintain a strict MSRV. Normally, it would be the latest stable at the time of release if the nightly crate feature is not enabled, otherwise it would be the latest nightly at the time of release.

§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.

This is a low-level crate, and is supposed to be used as a cryptographic primitive. This crate only implements AES-ECB, which is NOT a secure cipher. Rather, this crate should be used as a building block for implementing higher-level algorithms in a platform-independent and performant way.

Structs§

Aes128Dec
Aes128DecX2
Aes128DecX4
Aes128Enc
Aes128EncX2
Aes128EncX4
Aes192Dec
Aes192DecX2
Aes192DecX4
Aes192Enc
Aes192EncX2
Aes192EncX4
Aes256Dec
Aes256DecX2
Aes256DecX4
Aes256Enc
Aes256EncX2
Aes256EncX4
AesBlock
AesBlockX2
AesBlockX4

Traits§

AesDecrypt
AesDecryptX2
AesDecryptX4
AesEncrypt
AesEncryptX2
AesEncryptX4