-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaes.h
64 lines (54 loc) · 2.53 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef SRC_AES_H_
#define SRC_AES_H_
#include <stdint.h>
/**
* @brief encrypt_file_aes128 encrypts files using aes128 standard
* @param FILE * plain_file is the file that will be encrypted
* @param FILE * encrypted_file is the encrypted output file
* @param char * key is the encryption key. Length must be from 1 to 16 Bytes
* if the key length is less than 16, zeros padding is added.
*/
int encrypt_file_aes128(FILE * plain_file, FILE * encrypted_file, char * key);
/**
* @brief aes128 encrypts a block of 16 bytes (128 bits)
* @param uint8_t txt[16] is the input block to be encrypted
* @param uint8_t key[16] is the encryption key.
*/
void aes128(uint8_t txt[16], uint8_t key[16]);
/**
* @brief s is a transformation that maps an 8-bit input, c, to an 8-bit output according to the S-Box.
* the S-Box is a lookup table that represents the The Rijndael substitution box.
* @param c is the input
* @return s returns the transformation value
*/
uint8_t s(uint8_t c);
/**
* @brief expand_key generates the next key in the key schedule
* @param uint8_t previous_key[16] is the starting key
* @param uint8_t next_key[16] is the newly generated key from the previous_key
* @param uint8_t round is the round number in the AES algorithm. values = 1-10
*
*/
void expand_key(uint8_t previous_key[16],uint8_t round);
/**
* @brief shift_rows does a circular left shift on the rows of the input 4x4 matrix.
* 1st row is not shifted, 2nd row is shifted 1 element, 3d row is shifted 2 elements, 4th row is shifted 3 elements.
* @param uint8_t block[16] The 16 bytes length input is regarded as a 4x4 matrix. The rows of this matrix will be shifted as described in the brief section.
*/
void shift_rows(uint8_t block[16]);
/**
* @brief mix_column performs a linear transformation on every column in the 4x4 input matrix. Every column is multiplied
* by the matrix below:
* 0x02, 0x03, 0x01, 0x01
* 0x01, 0x02, 0x03, 0x01
* 0x01, 0x01, 0x02, 0x03
* 0x03, 0x01, 0x01, 0x02
* The multiplication is an operation in GF(2^8) which means it is not a simple multiplication of natural numbers.
* since there is only multiplication by 0x01, 0x02, and 0x03, a lookup table containing all the results of multiplying the values
* [0-256] by 0x02 and 0x03 is pre-calculated and initialized.. Multiplication by 0x01 results in the same value.
* @param uint8_t block[16] The 16 bytes length input is regarded as a 4x4 matrix.
*/
void mix_columns(uint8_t block[16]);
uint8_t _mult(uint8_t a, uint8_t b);
void display_block(uint8_t b[16]);
#endif /* SRC_AES_H_ */