1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _NANOHUB_AES_H_
18 #define _NANOHUB_AES_H_
19 
20 #include <stdint.h>
21 
22 struct AesContext {
23     uint32_t K[64];
24 };
25 
26 struct AesSetupTempWorksSpace { //unsed temporarily for aesInitForDecr() only, not used after, need not be live
27     struct AesContext tmpCtx;
28 };
29 
30 #define AES_KEY_WORDS     8
31 #define AES_BLOCK_WORDS   4
32 #define AES_BLOCK_SIZE    16 // in bytes
33 
34 //basic AES block ops
35 void aesInitForEncr(struct AesContext *ctx, const uint32_t *k);
36 void aesInitForDecr(struct AesContext *ctx, struct AesSetupTempWorksSpace *tmpSpace, const uint32_t *k);
37 void aesEncr(struct AesContext *ctx, const uint32_t *src, uint32_t *dst); //encrypts AES_BLOCK_WORDS words
38 void aesDecr(struct AesContext *ctx, const uint32_t *src, uint32_t *dst); //deencrypts AES_BLOCK_WORDS words
39 
40 //AES-CBC
41 struct AesCbcContext {
42     struct AesContext aes;
43     uint32_t iv[AES_BLOCK_WORDS];
44 };
45 
46 void aesCbcInitForEncr(struct AesCbcContext *ctx, const uint32_t *k, const uint32_t *iv);
47 void aesCbcInitForDecr(struct AesCbcContext *ctx, const uint32_t *k, const uint32_t *iv);
48 void aesCbcEncr(struct AesCbcContext *ctx, const uint32_t *src, uint32_t *dst); //encrypts AES_BLOCK_WORDS words
49 void aesCbcDecr(struct AesCbcContext *ctx, const uint32_t *src, uint32_t *dst); //encrypts AES_BLOCK_WORDS words
50 
51 
52 
53 
54 #endif // _NANOHUB_AES_H_
55 
56