295 lines
9.7 KiB
C
295 lines
9.7 KiB
C
#pragma once
|
|
#include <stdio.h>
|
|
#include "os_adapt.h"
|
|
|
|
#ifdef _WINDOWS
|
|
#define DLLEXPORT __declspec(dllexport)
|
|
#else
|
|
#define DLLEXPORT
|
|
#endif
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
enum {
|
|
CRYPT_TB_ERROR_NONE = 0,
|
|
CRYPT_TB_ERROR_INVALID_ARGUMENT,
|
|
CRYPT_TB_ERROR_ENC_INFO,
|
|
CRYPT_TB_ERROR_VERIFY_KEY,
|
|
CRYPT_TB_ERROR_IO_OPEN_FILE,
|
|
CRYPT_TB_ERROR_IO_READ,
|
|
CRYPT_TB_ERROR_IO_REACH_EOF,
|
|
CRYPT_TB_ERROR_OUT_OF_MEMORY,
|
|
CRYPT_TB_ERROR_BYTE_ALIGN,
|
|
};
|
|
|
|
/**
|
|
* @brief Get crypt library version
|
|
*
|
|
* @return unsigned int : Modification count
|
|
*/
|
|
DLLEXPORT unsigned int tb_version(void);
|
|
|
|
|
|
/**
|
|
* @brief Get sha256 hash data
|
|
*
|
|
* @param source : [in]
|
|
* @param src_size : [in]
|
|
* @param out_hash : [out] 32 Bytes Heximal SHA256HASH data
|
|
*/
|
|
DLLEXPORT void tb_sha256_sum(char* source, unsigned int src_size, char* out_hash) ;
|
|
|
|
|
|
/**
|
|
* @brief Get encrypted data for authentication password
|
|
*
|
|
* @param passwd : [in]
|
|
* @param passwd_sz : [in]
|
|
* @param enc_data : [out] This buffer should be freed by manually
|
|
* @param enc_data_sz : [out]
|
|
* @return int : Fail(negative value), Success(0)
|
|
*/
|
|
DLLEXPORT int tb_encrypt_auth_passwd(unsigned char* passwd, unsigned int passwd_sz, void** enc_data, unsigned int* enc_data_sz);
|
|
|
|
/**
|
|
* @brief Verify encrypted data for authentication password
|
|
*
|
|
* @param passwd : [in]
|
|
* @param passwd_sz : [in]
|
|
* @param enc_data : [in]
|
|
* @param enc_data_sz : [in]
|
|
* @return int : Fail(negative value), Success(0)
|
|
*/
|
|
DLLEXPORT int tb_verify_auth_passwd(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz);
|
|
|
|
/**
|
|
* @brief Encrypts data amount data_sz
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param enc_data : [out] This buffer should be freed by manually
|
|
* @param enc_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_encrypt_data(void* data, unsigned int data_sz, void* priv_key, void** enc_data, unsigned int* enc_sz);
|
|
DLLEXPORT int tb_encrypt_data_aes256ctr(void* data, unsigned int data_sz, void* priv_key, void** enc_data, unsigned int* enc_sz);
|
|
|
|
/**
|
|
* @brief Decrypts data
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param dec_data : [out] This buffer should be freed by manually
|
|
* @param dec_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_decrypt_data(void* data, unsigned int data_sz, void* priv_key, void** dec_data, unsigned int* dec_sz);
|
|
DLLEXPORT int tb_decrypt_data_aes256ctr(void* data, unsigned int data_sz, void* priv_key, void** dec_data, unsigned int* dec_sz);
|
|
|
|
/**
|
|
* @brief Encrypts data amount data_sz
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param enc_data : [out] This buffer should be freed by manually
|
|
* @param enc_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_encrypt_data_aes256cbc(void* data, unsigned int data_sz, void* priv_key, void** enc_data, unsigned int* enc_sz);
|
|
|
|
/**
|
|
* @brief Decrypts data
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param dec_data : [out] This buffer should be freed by manually
|
|
* @param dec_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_decrypt_data_aes256cbc(void* data, unsigned int data_sz, void* priv_key, void** dec_data, unsigned int* dec_sz);
|
|
|
|
/**
|
|
* @brief Encrypts data amount data_sz
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param enc_data : [out] This buffer should be freed by manually
|
|
* @param enc_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_encrypt_data_aria256ctr(void* data, unsigned int data_sz, void* priv_key, void** enc_data, unsigned int* enc_sz);
|
|
|
|
/**
|
|
* @brief Decrypts data
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param dec_data : [out] This buffer should be freed by manually
|
|
* @param dec_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_decrypt_data_aria256ctr(void* data, unsigned int data_sz, void* priv_key, void** dec_data, unsigned int* dec_sz);
|
|
|
|
/**
|
|
* @brief Encrypts data amount data_sz
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param enc_data : [out] This buffer should be freed by manually
|
|
* @param enc_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_encrypt_data_aria256cbc(void* data, unsigned int data_sz, void* priv_key, void** enc_data, unsigned int* enc_sz);
|
|
|
|
/**
|
|
* @brief Decrypts data
|
|
*
|
|
* @param data : [in]
|
|
* @param data_sz : [in]
|
|
* @param priv_key : [in] private key from got the devices
|
|
* @param dec_data : [out] This buffer should be freed by manually
|
|
* @param dec_sz : [out]
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_decrypt_data_aria256cbc(void* data, unsigned int data_sz, void* priv_key, void** dec_data, unsigned int* dec_sz);
|
|
|
|
/**
|
|
* @brief Decrypt as mp4 file
|
|
*
|
|
* @param enc_file : [in] source file path
|
|
* @param dec_file : [in] output file path after decrypted
|
|
* @param passwd : [in] Raw string data of password
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_decrypt_mp4(const char* enc_file, const char* dec_file, unsigned char* passwd);
|
|
|
|
/**
|
|
* @brief Verify encrypted media file
|
|
*
|
|
* @param enc_file : [in] source file path
|
|
* @param passwd : [in] Raw string data of password
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_verify_media(const char* enc_file, unsigned char* passwd);
|
|
|
|
|
|
/**
|
|
* @brief Extract gps information
|
|
*
|
|
* @param dec_file : [in] source file path
|
|
* @param gps_file : [in] gps extracted file path
|
|
* @param passwd : [in] Raw string data of password
|
|
* @return int
|
|
*/
|
|
DLLEXPORT int tb_extract_gps(const char* dec_file, const char* gps_file, unsigned char* passwd);
|
|
|
|
/**
|
|
* @brief Decrypt @enc_data to @dec_data amount @enc_data_sz by AES 256bit CTR.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_decrypt(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz, void* dec_data); //old version
|
|
DLLEXPORT int tb_decrypt_aes256ctr(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz, void* dec_data);
|
|
|
|
/**
|
|
* @brief Encrypt @plain_data to @enc_data amount @plane_data_sz by AES 256bit CTR.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_encrypt(unsigned char* passwd, unsigned int passwd_sz, void* plain_data, unsigned int plane_data_sz, void* enc_data); //old version
|
|
DLLEXPORT int tb_encrypt_aes256ctr(unsigned char* passwd, unsigned int passwd_sz, void* plain_data, unsigned int plane_data_sz, void* enc_data);
|
|
|
|
/**
|
|
* @brief Decrypt @enc_data to @dec_data amount @enc_data_sz by AES 256bit CBC.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_decrypt_aes256cbc(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz, void* dec_data);
|
|
|
|
/**
|
|
* @brief Encrypt @plain_data to @enc_data amount @plane_data_sz by AES 256bit CBC.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_encrypt_aes256cbc(unsigned char* passwd, unsigned int passwd_sz, void* plain_data, unsigned int plane_data_sz, void* enc_data);
|
|
|
|
/**
|
|
* @brief Decrypt @enc_data to @dec_data amount @enc_data_sz by ARIA 256bit CTR.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_decrypt_aria256ctr(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz, void* dec_data);
|
|
|
|
/**
|
|
* @brief Encrypt @src_data to @enc_data amount @enc_data_sz by ARIA 256bit CTR.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_encrypt_aria256ctr(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz, void* dec_data);
|
|
|
|
/**
|
|
* @brief Decrypt @enc_data to @dec_data amount @enc_data_sz by ARIA 256bit CTR.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_decrypt_aria256cbc(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz, void* dec_data);
|
|
|
|
/**
|
|
* @brief Encrypt @src_data to @enc_data amount @enc_data_sz by ARIA 256bit CBC.
|
|
*
|
|
* @param passwd : [in] password
|
|
* @param passwd_sz : [in] length of password
|
|
* @param enc_data : [in] buffer to decrypt
|
|
* @param enc_data_sz : [in] size of buffer to decrypt
|
|
* @param dec_data : [out] decrypted data buffer
|
|
* @return DLLEXPORT
|
|
*/
|
|
DLLEXPORT int tb_encrypt_aria256cbc(unsigned char* passwd, unsigned int passwd_sz, void* enc_data, unsigned int enc_data_sz, void* dec_data);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif |