1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
5 #include "aes_core.h"
6
7
8
rk_crypto_ecb128_encrypt(const unsigned char * in,unsigned long length,unsigned char * out,const RK_AES_KEY * ks,const int enc)9 static int rk_crypto_ecb128_encrypt(const unsigned char *in, unsigned long length, unsigned char *out,
10 const RK_AES_KEY *ks, const int enc)
11 {
12 unsigned long i = 0;
13
14 for(i=0; i<length/16; i++){
15 if (enc)
16 rk_aes_encrypt(in+i*16, out+i*16, ks);
17 else
18 rk_aes_decrypt(in+i*16, out+i*16, ks);
19
20 };
21 return 0;
22 }
23
rk_aes_ecb_encrypt(const unsigned char * in,unsigned char * out,unsigned long length,const unsigned char * key,const int key_len,const int enc)24 int rk_aes_ecb_encrypt(const unsigned char *in, unsigned char *out,
25 unsigned long length, const unsigned char *key, const int key_len,
26 const int enc)
27 {
28 RK_AES_KEY ks;
29
30 if (in == NULL || out ==NULL || key == NULL)
31 return -1;
32
33 if (key_len != 128/8 && key_len != 192/8 && key_len != 256/8)
34 return -2;
35
36 if(length % 16 != 0)
37 return -3;
38
39 if (enc) {
40 rk_aes_set_encrypt_key(key, key_len * 8, &ks);
41 } else {
42 rk_aes_set_decrypt_key(key, key_len * 8, &ks);
43 }
44
45 rk_crypto_ecb128_encrypt(in, length, out, &ks, enc);
46 return 0;
47 }
48
49
50