vcpe/srcs/libs/include/crypto.h

98 lines
3.1 KiB
C
Raw Permalink Normal View History

2022-05-10 06:43:27 +00:00
//
// Created by xajhu on 2021/7/2 0002.
//
#ifndef DAEMON_AGENT_CRYPTO_CRYPTO_H
#define DAEMON_AGENT_CRYPTO_CRYPTO_H
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
DES3_ECB_PKCS7PADDING = 0,
DES3_CBC_PKCS7PADDING,
DES3_OFB_PKCS7PADDING,
AES128_ECB_PKCS7PADDING,
AES128_ECB_PKCS7PADDING_SHA1PRNG,
AES128_CBC_PKCS7PADDING,
AES128_OFB_PKCS7PADDING,
AES192_ECB_PKCS7PADDING,
AES192_CBC_PKCS7PADDING,
AES192_OFB_PKCS7PADDING,
AES256_ECB_PKCS7PADDING,
AES256_CBC_PKCS7PADDING,
AES256_OFB_PKCS7PADDING,
} AES_TYPE;
typedef enum {
CRYPTO_AES_ENCRYPT = 0,
CRYPTO_AES_DECRYPT,
CRYPTO_BASE64_ENCODE,
CRYPTO_BASE64_DECODE,
CRYPTO_MD5_FILE,
} CRYPTO_TYPE;
typedef enum {
HASH_TYPE_MD5 = 0,
HASH_TYPE_SHA1 = 1,
HASH_TYPE_SHA256 = 2,
} HASH_TYPE;
2022-12-02 06:42:15 +00:00
typedef void (*on_evp_crypto)(CRYPTO_TYPE type,
const unsigned char *pData,
unsigned int iSize,
const unsigned char *pSrcData,
int iError);
2022-05-10 06:43:27 +00:00
//*****************************************************
// AES
//*****************************************************
2022-12-02 06:42:15 +00:00
int symmetric_encrypto(AES_TYPE algorithmType,
unsigned char *pInBuf,
unsigned int inSize,
unsigned char **pOutBuf,
int *pOutSize,
const char *pKey);
int symmetric_decrypto(AES_TYPE algorithmType,
unsigned char *pInBuf,
unsigned int inSize,
unsigned char **pOutBuf,
int *pOutSize,
const char *pKey);
2022-05-10 06:43:27 +00:00
//*****************************************************
// BASE64
//*****************************************************
#if 0
const char *base64_encode(unsigned char *pSrc, unsigned int sLen);
unsigned char * base64_decode(const char *pBase64);
#endif
const char *base64_encode(unsigned char *pSrc, unsigned int sLen);
unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize);
//*****************************************************
// MD5
//*****************************************************
int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValue);
2022-12-02 06:42:15 +00:00
int hash_digest_mem(HASH_TYPE hashType,
const unsigned char *pBuf,
unsigned int iBufLen,
unsigned char **pHashValue,
unsigned int *pOutSize);
2022-05-10 06:43:27 +00:00
//*****************************************************
// Async Engine
//*****************************************************
2022-12-02 06:42:15 +00:00
int evp_add_crypto_task(CRYPTO_TYPE type,
unsigned char *pInBuf,
unsigned int iSize,
unsigned char *pOutBuf,
char *pKey,
on_evp_crypto onEvpCryptCb);
2022-05-10 06:43:27 +00:00
void evp_system_init(void);
#ifdef __cplusplus
}
#endif
2022-12-02 06:42:15 +00:00
#endif //DAEMON_AGENT_CRYPTO_CRYPTO_H