• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef AES_H
16 #define AES_H
17 
18 #include "common.h"
19 
20 // Main Functions
21 unsigned char* aes_128_encrypt(const unsigned char* in, unsigned char* out, const unsigned char* key);
22 unsigned char* aes_128_decrypt(const unsigned char* in, unsigned char* out, const unsigned char* key);
23 unsigned char* aes_192_encrypt(const unsigned char* in, unsigned char* out, const unsigned char* key);
24 unsigned char* aes_192_decrypt(const unsigned char* in, unsigned char* out, const unsigned char* key);
25 unsigned char* aes_256_encrypt(const unsigned char* in, unsigned char* out, const unsigned char* key);
26 unsigned char* aes_256_decrypt(const unsigned char* in, unsigned char* out, const unsigned char* key);
27 
28 // The Cipher
29 void Cipher(const unsigned char* in, unsigned char* out, unsigned char* w, unsigned char Nk, unsigned char Nr);
30 void InvCipher(const unsigned char* in, unsigned char* out, unsigned char* w, unsigned char Nk, unsigned char Nr);
31 
32 // KeyExpansion
33 void KeyExpansion(const unsigned char* key, unsigned char* w, unsigned char Nk, unsigned char Nr);
34 unsigned char* SubWord(unsigned char* word);
35 unsigned char* RotWord(unsigned char* word);
36 
37 // Round Ops
38 void SubBytes(unsigned char state[4][4]);
39 void ShiftRows(unsigned char state[4][4]);
40 void MixColumns(unsigned char state[4][4]);
41 void AddRoundKey(unsigned char state[4][4], unsigned char* key);
42 unsigned char mul(unsigned char a, unsigned char b);
43 
44 // Inv Round Ops
45 void InvSubBytes(unsigned char state[4][4]);
46 void InvShiftRows(unsigned char state[4][4]);
47 void InvMixColumns(unsigned char state[4][4]);
48 void InvAddRoundKey(unsigned char state[4][4], unsigned char* key);
49 
50 #endif // !AES_H
51