iPXE
aes.h
Go to the documentation of this file.
1#ifndef _IPXE_AES_H
2#define _IPXE_AES_H
3
4/** @file
5 *
6 * AES algorithm
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <ipxe/crypto.h>
15
16/** AES blocksize */
17#define AES_BLOCKSIZE 16
18
19/** Maximum number of AES rounds */
20#define AES_MAX_ROUNDS 15
21
22/** AES matrix */
24 /** Viewed as an array of bytes */
25 uint8_t byte[16];
26 /** Viewed as an array of four-byte columns */
28} __attribute__ (( packed ));
29
30/** AES round keys */
32 /** Round keys */
34};
35
36/** AES context */
38 /** Encryption keys */
40 /** Decryption keys */
42 /** Number of rounds */
44} __attribute__ (( aligned ( AES_BLOCKSIZE ) ));
45
46/** AES context size (including alignment padding) */
47#define AES_CTX_SIZE ( sizeof ( struct aes_context ) + AES_BLOCKSIZE - 1 )
48
49/**
50 * Align AES context
51 *
52 * @v ctx Context
53 * @ret aes AES context
54 */
55static inline struct aes_context * aes_context ( void *ctx ) {
56
57 return ( ( struct aes_context * )
58 ( ( ( ( intptr_t ) ctx ) + AES_BLOCKSIZE - 1 ) &
59 ~( AES_BLOCKSIZE - 1 ) ) );
60}
61
66
67/* Allow for architecture-specific hardware acceleration */
68#include <bits/aes.h>
69
70void aes_accelerate ( void );
71extern void aes_decelerate ( void );
72extern int aes_is_accelerated ( void );
73
74int aes_wrap ( const void *kek, const void *src, void *dest, int nblk );
75int aes_unwrap ( const void *kek, const void *src, void *dest, int nblk );
76
77#endif /* _IPXE_AES_H */
struct golan_eq_context ctx
Definition CIB_PRM.h:0
struct cipher_algorithm aes_algorithm
Basic AES algorithm.
Definition aes.c:847
unsigned long intptr_t
Definition stdint.h:21
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
AES acceleration.
void aes_accelerate(void)
Enable hardware acceleration (if supported).
Definition aesni.c:211
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
static const void * src
Definition string.h:48
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define __attribute__(x)
Definition compiler.h:10
int aes_is_accelerated(void)
Check if hardware acceleration is currently enabled (for testing).
Definition aes.c:840
#define AES_MAX_ROUNDS
Maximum number of AES rounds.
Definition aes.h:20
struct cipher_algorithm aes_ecb_algorithm
struct cipher_algorithm aes_cbc_algorithm
int aes_wrap(const void *kek, const void *src, void *dest, int nblk)
Wrap a key or other data using AES Key Wrap (RFC 3394).
Definition aes_wrap.c:38
void aes_decelerate(void)
Disable hardware acceleration (for testing).
Definition aes.c:824
static struct aes_context * aes_context(void *ctx)
Align AES context.
Definition aes.h:55
struct cipher_algorithm aes_gcm_algorithm
int aes_unwrap(const void *kek, const void *src, void *dest, int nblk)
Unwrap a key or other data using AES Key Wrap (RFC 3394).
Definition aes_wrap.c:85
#define AES_BLOCKSIZE
AES blocksize.
Definition aes.h:17
Cryptographic API.
AES context.
Definition aes.h:37
struct aes_round_keys decrypt
Decryption keys.
Definition aes.h:41
uint8_t rounds
Number of rounds.
Definition aes.h:43
struct aes_round_keys encrypt
Encryption keys.
Definition aes.h:39
AES round keys.
Definition aes.h:31
union aes_matrix key[AES_MAX_ROUNDS]
Round keys.
Definition aes.h:33
A cipher algorithm.
Definition crypto.h:58
AES matrix.
Definition aes.h:23
uint32_t column[4]
Viewed as an array of four-byte columns.
Definition aes.h:27
u8 kek[WPA_KEK_LEN]
EAPOL-Key Key Encryption Key (KEK).
Definition wpa.h:4