AN-1394: AES Encryption and Decryption for the ADF7023 and ADF7023-J
Introduction
This application note describes the advanced encryption standard (AES) firmware module available for the ADF7023 and ADF7023-J transceivers (for the remainder of this application note, references to the ADF7023 also pertain to the ADF7023-J). The downloadable AES firmware module supports 128-bit block encryption and decryption with key sizes of 128 bits, 192 bits, and 256 bits. Two modes are supported: electronic codebook (ECB) mode and Cipher Block Chaining (CBC) Mode 1.
ECB mode encrypts and decrypts on a 128-bit block by block with a single secret key as illustrated in Figure 1. CBC Mode 1 encrypts after first adding (via Modulo 2 arithmetic) a 128-bit user supplied initialization vector. The resulting cipher text is used as the initialization vector for the next block and so forth, as illustrated in Figure 2.
Decryption provides the inverse functionality. The firmware takes advantage of an on-chip hardware accelerator module to enhance throughput and minimize the latency of the AES processing.
Commands and Packet Random Access Memory Register Locations
Register Address1 | Register Name | Description |
0x001 | VAR_NUM_BLOCKS | Number of 16-byte blocks to encrypt/decrypt |
0x010 | VAR_C_PTR | Pointer to the data to be encrypted/decrypted |
0x011 | VAR_W_PTR | Pointer to the 32-byte AES workspace |
0x012 | VAR_WINV_PTR | Pointer to the inverse key |
0x013 | VAR_WFOR_PTR | Pointer to the secret key |
0x014 | VAR_KEYSIZE | Set to 0x0C for a 128-bit key, 0x14 for a 192-bit key, or 0x1C for a 256-bit key |
0x016 | VAR_AES_MODE | Set to 0x00 for ECB mode or 0x01 for CBC Mode 1 |
0x017 | VAR_ECV_PTR | Pointer to the 128-bit initialization vector used for encryption with CBC Mode 1 |
0x018 | VAR_DCV_PTR | Pointer to the 128-bit initialization vector used for decryption with CBC Mode 1 |
0x019 | VAR_CIPHERBUF_PTR | Pointer to the 128-bit storage location required when decrypting using CBC Mode 1 |
1These register definitions are specific to the firmware module and are not applicable to normal operation of the ADF7023.
AES configuration variables, keys, and data are stored in the packet random access memory (RAM).
The commands shown in Table 2 are necessary to perform an AES encryption, generate the inverse key, or perform an AES decryption. See the AES Procedures section for additional information regarding AES encryption and decryption procedures.
Due to the use of pointers, different key sizes, and two different modes, the implementation of AES on the ADF7023 is highly configurable. Figure 3 shows an example configuration.
Command | Code | Description |
CMD_AES_ENCRYPT | 0xD0 | Command used to encrypt a block of data |
CMD_AES_DECRYPT_INIT | 0xD1 | Command used to generate the inverse key |
CMD_AES_DECRYPT | 0xD2 | Command used to decrypt a block of data |
AES Procedures Writing the AES Firmware Module to the ADF7023
Prior to using the AES firmware module, the user must write the module to the program RAM of the ADF7023. The following steps detail how to write the AES firmware module to the program RAM:
- Ensure that the ADF7023 is in the PHY_OFF state.
- Issue the CMD_RAM_LOAD_INIT command (Address 0xBF).
- Write the module to program RAM using a serial peripheral interface (SPI) memory block write (0x1E00 (firmware module); see the ADF7023 data sheet for more information on block writing).
- Issue the CMD_RAM_LOAD_DONE command (Address 0xC7).
The firmware module is now stored in program RAM.
AES Encryption Procedure
The following steps detail how to perform an AES encryption:
- Write the start address of the AES workspace to VAR_W_PTR.
- Write to VAR_KEYSIZE to set the size of the key.
- Write to VAR_AES_MODE to select between ECB mode and CBC Mode 1.
-
If using CBC Mode 1 (skip this step if using ECB mode),
- Write the start address of the encryption initialization vector to VAR_ECV_PTR.
- Write the initialization vector to the location specified by VAR_ECV_PTR.
- Write the address of the secret key to VAR_WFOR_PTR.
- Write the secret key to the location specified by VAR_WFOR_PTR.
- Write the number of 16-byte blocks to encrypt to VAR_NUM_BLOCKS.
- Write the address of the data to be encrypted to VAR_C_PTR.
- Write the data to be encrypted to the location specified by VAR_C_PTR.
- Issue CMD_AES_ENCRYPT (0xD0). The data to be encrypted is overwritten with the encrypted data.
- Wait for the command to finish.
Example of AES Encryption
In the following example of an AES encryption, the SPI commands are written to the ADF7023:
- Write 0x18112A. VAR_W_PTR is set to 0x2A. The 32-byte workspace for the algorithm begins at Address 0x02A.
- Write 0x18140C. A key size of 128 bits is selected via VAR_KEYSIZE.
- Write 0x181600. ECB mode is selected via VAR_AES_MODE.
- CBC Mode 1 is not being used; therefore, skip Step 4.
- Write 0x18136A. VAR_WFOR_PTR is set to 0x6A. The secret key begins at Address 0x06A.
- Write the secret key to the packet RAM starting at Address 0x06A.
- Write 0x180101. VAR_NUM_BLOCKS is set to 0x01. One block of 16 bytes is then encrypted.
- Write 0x18108A. Set VAR_C_PTR to 0x8A. The data to be encrypted begins at Address 0x08A.
- Write the data to be encrypted to the packet RAM starting at Address 0x08A.
- Write 0xD0. CMD_AES_ENCRYPT is issued.
- Wait for the command to finish.
AES Decryption Procedure
The following steps detail how to perform an AES decryption:
- Write the start address of the AES workspace to VAR_W_PTR.
- Write to VAR_KEYSIZE to set the size of the key.
- Write to VAR_AES_MODE to select between ECB mode and CBC Mode 1.
- Write the address of the secret key to VAR_WFOR_PTR.
- Write the secret key to the location specified by VAR_WFOR_PTR.
- Write the address of the inverse key to VAR_WINV_PTR.
-
If using CBC Mode 1 (skip this step if using ECB mode),
- Write the address of the decryption initialization vector to VAR_DCV_PTR.
- Write the initialization vector to the location specified by VAR_DCV_PTR.
- Write the address of the reserved storage required when decrypting to VAR_CIPHERBUF_PTR.
- Issue CMD_AES_DECRYPT_INIT (0xD1). This command generates and saves the inverse key.
- Wait for the command to finish.
- Write the number of 16-byte blocks to decrypt to VAR_NUM_BLOCKS.
- Write the address of the data to be decrypted to VAR_C_PTR.
- Write the data to be decrypted to the location specified by VAR_C_PTR.
- Issue CMD_AES_DECRYPT (0xD2). The data to be decrypted is overwritten with the decrypted data.
- Wait for the command to finish.
Example of AES Decryption
In the following example of an AES decryption, the SPI commands are written to the ADF7023:
- Write 0x18112A. VAR_W_PTR is set to 0x2A. The 32-byte workspace for the algorithm begins at Address 0x02A.
- Write 0x18140C. A key size of 128 bits is selected via VAR_KEYSIZE.
- Write 0x181600. ECB mode is selected via VAR_AES_MODE.
- Write 0x18136A. VAR_WFOR_PTR is set to 0x6A. The secret key begins at Address 0x06A.
- Write the secret key to the packet RAM starting at Address 0x06A.
- Write 0x18124A. VAR_WINV_PTR is set to 0x4A. The inverse key begins at Address 0x04A.
- CBC Mode 1 is not being used; therefore, skip Step 7.
- Write 0xD1. CMD_AES_DECRYPT_INIT is issued. This command generates and saves the inverse key starting at Address 0x04A.
- Wait for the command to finish.
- Write 0x180101. VAR_NUM_BLOCKS is set to 0x01. One block of 16 bytes is then decrypted.
- Write 0x18108A. Set VAR_C_PTR to 0x8A. The data to be decrypted begins at Address 0x08A.
- Write the data to be decrypted to the packet RAM starting at Address 0x08A.
- Write 0xD2. CMD_AES_DECRYPT is issued.
- Wait for the command to finish.
Determining When AES Commands Are Complete
Use the CMD_FINISHED interrupt to determine when the CMD_AES_ENCRYPT, CMD_AES_DECRYPT_INIT, and CMD_AES_DECRYPT commands are complete. To enable this interrupt, set Bit 0 (CMD_FINISHED) of the INTERRUPT_ MASK_1 register (Address 0x101). When this mask bit is set, the interrupt pin (IRQ_GP3) of the ADF7023 is asserted upon completion of any command. The interrupt is cleared by writing Logic 1 to Bit 0 of INTERRUPT_SOURCE_1 (Address 0x337). See the ADF7023 data sheet for more information on interrupt generation.
AES Encryption and Decryption Times
Typical AES execution times are listed in Table 3.
Data Length (Bytes) | Key Size (Bits) | Initialize Decryption (ms) | Encryption (ms) | Decryption (ms) |
16 | 128 | 1.08 | 1.07 | 1.22 |
192 | 1.27 | 1.27 | 1.47 | |
256 | 1.47 | 1.46 | 1.69 | |
32 | 128 | 1.08 | 2.13 | 2.42 |
192 | 1.27 | 2.51 | 2.88 | |
256 | 1.46 | 2.87 | 3.37 | |
48 | 128 | 1.08 | 3.19 | 3.61 |
192 | 1.27 | 3.76 | 4.63 | |
256 | 1.46 | 4.3 | 5.05 | |
64 | 128 | 1.08 | 4.24 | 4.82 |
192 | 1.27 | 5.02 | 5.82 | |
256 | 1.46 | 5.76 | 6.72 |