-
Notifications
You must be signed in to change notification settings - Fork 7
/
aes.h
48 lines (42 loc) · 1.49 KB
/
aes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
*
* Chinese Academy of Sciences
* State Key Laboratory of Information Security
* Institute of Information Engineering
*
* Copyright (C) 2016 Chinese Academy of Sciences
*
* LuoPeng, [email protected]
* Updated in May 2016
*
*/
#ifndef AES_128_H
#define AES_128_H
#include <stdio.h>
#include <stdint.h>
#define AES_BLOCK_SIZE 16
#define AES_ROUNDS 10 // 12, 14
#define AES_ROUND_KEY_SIZE 176 // AES-128 has 10 rounds, and there is a AddRoundKey before first round. (10+1)x16=176.
/**
* @purpose: Key schedule for AES-128
* @par[in]key: 16 bytes of master keys
* @par[out]roundkeys: 176 bytes of round keys
*/
void aes_key_schedule_128(const uint8_t *key, uint8_t *roundkeys);
/**
* @purpose: Encryption. The length of plain and cipher should be one block (16 bytes).
* The plaintext and ciphertext may point to the same memory
* @par[in]roundkeys: round keys
* @par[in]plaintext: plain text
* @par[out]ciphertext: cipher text
*/
void aes_encrypt_128(const uint8_t *roundkeys, const uint8_t *plaintext, uint8_t *ciphertext);
/**
* @purpose: Decryption. The length of plain and cipher should be one block (16 bytes).
* The ciphertext and plaintext may point to the same memory
* @par[in]roundkeys: round keys
* @par[in]ciphertext: cipher text
* @par[out]plaintext: plain text
*/
void aes_decrypt_128(const uint8_t *roundkeys, const uint8_t *ciphertext, uint8_t *plaintext);
#endif