libnx  v4.7.0
aes.h
Go to the documentation of this file.
1 /**
2  * @file aes.h
3  * @brief Hardware accelerated AES-ECB implementation.
4  * @copyright libnx Authors
5  */
6 #pragma once
7 #include "../types.h"
8 
9 #ifndef AES_BLOCK_SIZE
10 #define AES_BLOCK_SIZE 0x10
11 #endif
12 #ifndef AES_128_KEY_SIZE
13 #define AES_128_KEY_SIZE 0x10
14 #endif
15 #ifndef AES_128_U32_PER_KEY
16 #define AES_128_U32_PER_KEY (AES_128_KEY_SIZE / sizeof(u32))
17 #endif
18 #ifndef AES_128_NUM_ROUNDS
19 #define AES_128_NUM_ROUNDS 10
20 #endif
21 #ifndef AES_192_KEY_SIZE
22 #define AES_192_KEY_SIZE 0x18
23 #endif
24 #ifndef AES_192_U32_PER_KEY
25 #define AES_192_U32_PER_KEY (AES_192_KEY_SIZE / sizeof(u32))
26 #endif
27 #ifndef AES_192_NUM_ROUNDS
28 #define AES_192_NUM_ROUNDS 12
29 #endif
30 #ifndef AES_256_KEY_SIZE
31 #define AES_256_KEY_SIZE 0x20
32 #endif
33 #ifndef AES_256_U32_PER_KEY
34 #define AES_256_U32_PER_KEY (AES_256_KEY_SIZE / sizeof(u32))
35 #endif
36 #ifndef AES_256_NUM_ROUNDS
37 #define AES_256_NUM_ROUNDS 14
38 #endif
39 
40 /// Context for AES-128 operations.
41 typedef struct {
42  u8 round_keys[AES_128_NUM_ROUNDS+1][AES_BLOCK_SIZE];
44 
45 /// Context for AES-192 operations.
46 typedef struct {
47  u8 round_keys[AES_192_NUM_ROUNDS+1][AES_BLOCK_SIZE];
49 
50 /// Context for AES-256 operations.
51 typedef struct {
52  u8 round_keys[AES_256_NUM_ROUNDS+1][AES_BLOCK_SIZE];
54 
55 /// Initialize a 128-bit AES context.
56 void aes128ContextCreate(Aes128Context *out, const void *key, bool is_encryptor);
57 /// Encrypt using an AES context (Requires is_encryptor when initializing)
58 void aes128EncryptBlock(const Aes128Context *ctx, void *dst, const void *src);
59 /// Decrypt using an AES context (Requires !is_encryptor when initializing)
60 void aes128DecryptBlock(const Aes128Context *ctx, void *dst, const void *src);
61 
62 /// Initialize a 192-bit AES context.
63 void aes192ContextCreate(Aes192Context *out, const void *key, bool is_encryptor);
64 /// Encrypt using an AES context (Requires is_encryptor when initializing)
65 void aes192EncryptBlock(const Aes192Context *ctx, void *dst, const void *src);
66 /// Decrypt using an AES context (Requires !is_encryptor when initializing)
67 void aes192DecryptBlock(const Aes192Context *ctx, void *dst, const void *src);
68 
69 /// Initialize a 256-bit AES context.
70 void aes256ContextCreate(Aes256Context *out, const void *key, bool is_encryptor);
71 /// Encrypt using an AES context (Requires is_encryptor when initializing)
72 void aes256EncryptBlock(const Aes256Context *ctx, void *dst, const void *src);
73 /// Decrypt using an AES context (Requires !is_encryptor when initializing)
74 void aes256DecryptBlock(const Aes256Context *ctx, void *dst, const void *src);
void aes128EncryptBlock(const Aes128Context *ctx, void *dst, const void *src)
Encrypt using an AES context (Requires is_encryptor when initializing)
void aes256ContextCreate(Aes256Context *out, const void *key, bool is_encryptor)
Initialize a 256-bit AES context.
void aes256EncryptBlock(const Aes256Context *ctx, void *dst, const void *src)
Encrypt using an AES context (Requires is_encryptor when initializing)
void aes192DecryptBlock(const Aes192Context *ctx, void *dst, const void *src)
Decrypt using an AES context (Requires !is_encryptor when initializing)
void aes192ContextCreate(Aes192Context *out, const void *key, bool is_encryptor)
Initialize a 192-bit AES context.
void aes128ContextCreate(Aes128Context *out, const void *key, bool is_encryptor)
Initialize a 128-bit AES context.
void aes128DecryptBlock(const Aes128Context *ctx, void *dst, const void *src)
Decrypt using an AES context (Requires !is_encryptor when initializing)
void aes192EncryptBlock(const Aes192Context *ctx, void *dst, const void *src)
Encrypt using an AES context (Requires is_encryptor when initializing)
void aes256DecryptBlock(const Aes256Context *ctx, void *dst, const void *src)
Decrypt using an AES context (Requires !is_encryptor when initializing)
Context for AES-128 operations.
Definition: aes.h:41
Context for AES-192 operations.
Definition: aes.h:46
Context for AES-256 operations.
Definition: aes.h:51
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19