forked from telosprotocol/xbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xaes.h
executable file
·58 lines (49 loc) · 4.2 KB
/
xaes.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
// Copyright (c) 2018-2020 Telos Foundation & contributors
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <string>
#include <vector>
#include "xmem.h"
namespace top
{
namespace base
{
class xaes_t
{
public: //AES-CBC Mode,return < 0 if fail,otherwise return the data size of encrypted or decrypted
static int aes_cbc_encrypt_128bit(xmemh_t & in_output,uint8_t aes_key[16],uint8_t aes_iv[16]);
static int aes_cbc_encrypt_128bit(xbuffer_t & in_output,uint8_t aes_key[16],uint8_t aes_iv[16]);
//data_size must be alignment as 16bytes,otherwise it may return fail
static int aes_cbc_encrypt_128bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[16],uint8_t aes_iv[16]);
static int aes_cbc_decrypt_128bit(xmemh_t & in_output,uint8_t aes_key[16],uint8_t aes_iv[16]);
static int aes_cbc_decrypt_128bit(xbuffer_t & in_output,uint8_t aes_key[16],uint8_t aes_iv[16]);
//data_size must be alignment as 16bytes,otherwise it may return fail
static int aes_cbc_decrypt_128bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[16],uint8_t aes_iv[16]);
//note:256bit aes still using 128bit block to hold data,so the init iv must be 16 bytes length
static int aes_cbc_encrypt_256bit(xmemh_t & in_output,uint8_t aes_key[32],uint8_t aes_iv[16]);
static int aes_cbc_encrypt_256bit(xbuffer_t & in_output,uint8_t aes_key[32],uint8_t aes_iv[16]);
//data_size must be alignment as 16bytes,otherwise it may return fail
static int aes_cbc_encrypt_256bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[32],uint8_t aes_iv[16]);
static int aes_cbc_decrypt_256bit(xmemh_t & in_output,uint8_t aes_key[32],uint8_t aes_iv[16]);
static int aes_cbc_decrypt_256bit(xbuffer_t & in_output,uint8_t aes_key[32],uint8_t aes_iv[16]);
//data_size must be alignment as 16bytes,otherwise it may return fail
static int aes_cbc_decrypt_256bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[32],uint8_t aes_iv[16]);
public://AES-CTR Mode,return < 0 if fail,otherwise return the size of encrypted or decrypted
//CTR mode has better performance,and very good for streaming data because it dose not need padding
static int aes_ctr_encrypt_128bit(xmemh_t & in_output,uint8_t aes_key[16],uint8_t aes_nounce[16]);
static int aes_ctr_encrypt_128bit(xbuffer_t & in_output,uint8_t aes_key[16],uint8_t aes_nounce[16]);
static int aes_ctr_encrypt_128bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[16],uint8_t aes_nounce[16]);
static int aes_ctr_decrypt_128bit(xmemh_t & in_output,uint8_t aes_key[16],uint8_t aes_nounce[16]);
static int aes_ctr_decrypt_128bit(xbuffer_t & in_output,uint8_t aes_key[16],uint8_t aes_nounce[16]);
static int aes_ctr_decrypt_128bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[16],uint8_t aes_nounce[16]);
//note:256bit aes still using 128bit block to hold data,so the init iv must be 16 bytes length
static int aes_ctr_encrypt_256bit(xmemh_t & in_output,uint8_t aes_key[32],uint8_t aes_nounce[16]);
static int aes_ctr_encrypt_256bit(xbuffer_t & in_output,uint8_t aes_key[32],uint8_t aes_nounce[16]);
static int aes_ctr_encrypt_256bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[32],uint8_t aes_nounce[16]);
static int aes_ctr_decrypt_256bit(xmemh_t & in_output,uint8_t aes_key[32],uint8_t aes_nounce[16]);
static int aes_ctr_decrypt_256bit(xbuffer_t & in_output,uint8_t aes_key[32],uint8_t aes_nounce[16]);
static int aes_ctr_decrypt_256bit(const uint8_t* in_output_data,const int32_t data_size,uint8_t aes_key[32],uint8_t aes_nounce[16]);
};
}
};