radare2/libr/include/r_crypto.h

103 lines
2.7 KiB
C
Raw Normal View History

2014-03-27 15:34:17 +00:00
#ifndef R2_CRYPTO_H
#define R2_CRYPTO_H
2009-09-14 23:51:28 +00:00
#include <r_types.h>
#include <r_list.h>
2009-09-14 23:51:28 +00:00
#ifdef __cplusplus
extern "C" {
#endif
R_LIB_VERSION_HEADER(r_crypto);
2009-09-14 23:51:28 +00:00
enum {
R_CRYPTO_MODE_ECB,
R_CRYPTO_MODE_CBC,
R_CRYPTO_MODE_OFB,
R_CRYPTO_MODE_CFB,
};
enum {
R_CRYPTO_DIR_CIPHER,
R_CRYPTO_DIR_DECIPHER,
};
typedef struct r_crypto_t {
struct r_crypto_plugin_t* h;
2009-09-14 23:51:28 +00:00
ut8 *key;
ut8 *iv;
int key_len;
ut8 *output;
int output_len;
int output_size;
int dir;
2009-09-14 23:51:28 +00:00
void *user;
RList *plugins;
} RCrypto;
2009-09-14 23:51:28 +00:00
typedef struct r_crypto_plugin_t {
2009-09-14 23:51:28 +00:00
const char *name;
const char *license;
2012-07-21 10:11:21 +00:00
int (*get_key_size)(RCrypto *cry);
2017-01-29 22:05:02 +00:00
bool (*set_iv)(RCrypto *cry, const ut8 *iv, int ivlen);
bool (*set_key)(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction);
bool (*update)(RCrypto *cry, const ut8 *buf, int len);
bool (*final)(RCrypto *cry, const ut8 *buf, int len);
bool (*use)(const char *algo);
2012-07-21 10:11:21 +00:00
int (*fini)(RCrypto *cry);
} RCryptoPlugin;
2009-09-14 23:51:28 +00:00
#ifdef R_API
2012-07-21 10:11:21 +00:00
R_API RCrypto *r_crypto_init(RCrypto *cry, int hard);
R_API RCrypto *r_crypto_as_new(RCrypto *cry);
R_API int r_crypto_add(RCrypto *cry, RCryptoPlugin *h);
R_API RCrypto *r_crypto_new(void);
2012-07-21 10:11:21 +00:00
R_API RCrypto *r_crypto_free(RCrypto *cry);
R_API bool r_crypto_use(RCrypto *cry, const char *algo);
R_API bool r_crypto_set_key(RCrypto *cry, const ut8* key, int keylen, int mode, int direction);
R_API bool r_crypto_set_iv(RCrypto *cry, const ut8 *iv, int ivlen);
R_API int r_crypto_update(RCrypto *cry, const ut8 *buf, int len);
R_API int r_crypto_final(RCrypto *cry, const ut8 *buf, int len);
2012-07-21 10:11:21 +00:00
R_API int r_crypto_append(RCrypto *cry, const ut8 *buf, int len);
R_API ut8 *r_crypto_get_output(RCrypto *cry, int *size);
R_API const char *r_crypto_name(ut64 bit);
#endif
2009-09-14 23:51:28 +00:00
/* plugin pointers */
2012-07-21 10:11:21 +00:00
extern RCryptoPlugin r_crypto_plugin_aes;
2017-01-28 11:52:39 +00:00
extern RCryptoPlugin r_crypto_plugin_des;
extern RCryptoPlugin r_crypto_plugin_rc4;
2016-03-08 22:24:31 +00:00
extern RCryptoPlugin r_crypto_plugin_xor;
extern RCryptoPlugin r_crypto_plugin_blowfish;
2016-03-07 23:25:22 +00:00
extern RCryptoPlugin r_crypto_plugin_rc2;
extern RCryptoPlugin r_crypto_plugin_rot;
2016-04-09 17:26:28 +00:00
extern RCryptoPlugin r_crypto_plugin_rol;
extern RCryptoPlugin r_crypto_plugin_ror;
extern RCryptoPlugin r_crypto_plugin_base64;
extern RCryptoPlugin r_crypto_plugin_base91;
extern RCryptoPlugin r_crypto_plugin_aes_cbc;
extern RCryptoPlugin r_crypto_plugin_punycode;
2016-05-09 14:51:26 +00:00
extern RCryptoPlugin r_crypto_plugin_rc6;
2016-08-01 15:31:36 +00:00
extern RCryptoPlugin r_crypto_plugin_cps2;
#define R_CRYPTO_NONE 0
#define R_CRYPTO_RC2 1
2016-08-01 15:31:36 +00:00
#define R_CRYPTO_RC4 1<<1
#define R_CRYPTO_RC6 1<<2
#define R_CRYPTO_AES_ECB 1<<3
#define R_CRYPTO_AES_CBC 1<<4
#define R_CRYPTO_ROR 1<<5
#define R_CRYPTO_ROL 1<<6
#define R_CRYPTO_ROT 1<<7
#define R_CRYPTO_BLOWFISH 1<<8
#define R_CRYPTO_CPS2 1<<9
2017-01-28 11:52:39 +00:00
#define R_CRYPTO_DES_ECB 1<<10
#define R_CRYPTO_XOR 1<<11
#define R_CRYPTO_ALL 0xFFFF
#ifdef __cplusplus
}
#endif
2009-09-14 23:51:28 +00:00
#endif