|
1 | 1 | //! Pure Rust implementation of the Advanced Encryption Standard |
2 | 2 | //! (a.k.a. Rijndael) |
3 | 3 | //! |
4 | | -//! It provides two different backends based on what target features |
5 | | -//! are specified: |
| 4 | +//! # Supported platforms |
| 5 | +//! |
| 6 | +//! This crate provides two different backends based on what target features |
| 7 | +//! are available: |
6 | 8 | //! |
7 | 9 | //! - "soft" portable constant-time implementation based on [fixslicing]. |
8 | 10 | //! Enabling the `compact` Cargo feature will reduce the code size of this |
|
12 | 14 | //! architectures with `target-feature=+aes`, as well as an accelerated |
13 | 15 | //! AES-CTR implementation with `target-feature=+aes,+ssse3` |
14 | 16 | //! |
15 | | -//! Crate switches between implementations automatically at compile time. |
16 | | -//! (i.e. it does not use run-time feature detection) |
| 17 | +//! By default this crate uses runtime detection on `i686`/`x86_64` targets |
| 18 | +//! in order to determine if AES-NI is available, and if it is not, it will |
| 19 | +//! fallback to using a constant-time software implementation. |
| 20 | +//! |
| 21 | +//! Passing `RUSTFLAGS=-Ctarget-feature=+aes,+ssse3` explicitly at compile-time |
| 22 | +//! will override runtime detection and ensure that AES-NI is always used. |
| 23 | +//! Programs built in this manner will crash with an illegal instruction on |
| 24 | +//! CPUs which do not have AES-NI enabled. |
17 | 25 | //! |
18 | 26 | //! # Usage example |
19 | 27 | //! ``` |
|
26 | 34 | //! let key = GenericArray::from_slice(&[0u8; 16]); |
27 | 35 | //! let mut block = GenericArray::clone_from_slice(&[0u8; 16]); |
28 | 36 | //! let mut block8 = GenericArray::clone_from_slice(&[block; 8]); |
| 37 | +//! |
29 | 38 | //! // Initialize cipher |
30 | 39 | //! let cipher = Aes128::new(&key); |
31 | 40 | //! |
32 | 41 | //! let block_copy = block.clone(); |
| 42 | +//! |
33 | 43 | //! // Encrypt block in-place |
34 | 44 | //! cipher.encrypt_block(&mut block); |
| 45 | +//! |
35 | 46 | //! // And decrypt it back |
36 | 47 | //! cipher.decrypt_block(&mut block); |
37 | 48 | //! assert_eq!(block, block_copy); |
|
0 commit comments