2014-03-27 16:34:17 +01:00
|
|
|
#ifndef R2_CRYPTO_H
|
|
|
|
#define R2_CRYPTO_H
|
2009-09-15 01:51:28 +02:00
|
|
|
|
|
|
|
#include <r_types.h>
|
2016-03-07 02:38:50 +01:00
|
|
|
#include <r_list.h>
|
2009-09-15 01:51:28 +02:00
|
|
|
|
2013-06-18 12:09:23 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-06-14 02:51:33 +02:00
|
|
|
R_LIB_VERSION_HEADER(r_crypto);
|
|
|
|
|
2009-09-15 01:51:28 +02: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,
|
|
|
|
};
|
|
|
|
|
2010-01-04 01:25:52 +01:00
|
|
|
typedef struct r_crypto_t {
|
2010-05-26 01:42:22 +02:00
|
|
|
struct r_crypto_plugin_t* h;
|
2009-09-15 01:51:28 +02:00
|
|
|
ut8 *key;
|
|
|
|
ut8 *iv;
|
|
|
|
int key_len;
|
|
|
|
ut8 *output;
|
|
|
|
int output_len;
|
|
|
|
int output_size;
|
|
|
|
void *user;
|
2016-03-07 02:38:50 +01:00
|
|
|
RList *plugins;
|
2010-01-26 01:28:33 +01:00
|
|
|
} RCrypto;
|
2009-09-15 01:51:28 +02:00
|
|
|
|
2010-05-26 01:42:22 +02:00
|
|
|
typedef struct r_crypto_plugin_t {
|
2009-09-15 01:51:28 +02:00
|
|
|
const char *name;
|
2012-07-21 14:11:21 +04:00
|
|
|
int (*get_key_size)(RCrypto *cry);
|
2016-04-15 01:09:45 +05:30
|
|
|
int (*set_iv)(RCrypto *cry, const ut8 *iv, int ivlen);
|
2016-03-07 02:38:50 +01:00
|
|
|
int (*set_key)(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction);
|
2016-04-13 23:42:09 +05:30
|
|
|
int (*update)(RCrypto *cry, const ut8 *buf, int len);
|
|
|
|
int (*final)(RCrypto *cry, const ut8 *buf, int len);
|
2016-03-07 02:38:50 +01:00
|
|
|
bool (*use)(const char *algo);
|
2012-07-21 14:11:21 +04:00
|
|
|
int (*fini)(RCrypto *cry);
|
2010-05-26 01:42:22 +02:00
|
|
|
} RCryptoPlugin;
|
2009-09-15 01:51:28 +02:00
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
#ifdef R_API
|
2012-07-21 14:11:21 +04: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);
|
2015-01-13 03:40:01 +01:00
|
|
|
R_API RCrypto *r_crypto_new(void);
|
2012-07-21 14:11:21 +04:00
|
|
|
R_API RCrypto *r_crypto_free(RCrypto *cry);
|
2016-03-07 02:38:50 +01:00
|
|
|
R_API bool r_crypto_use(RCrypto *cry, const char *algo);
|
|
|
|
R_API int r_crypto_set_key(RCrypto *cry, const ut8* key, int keylen, int mode, int direction);
|
2016-04-15 01:09:45 +05:30
|
|
|
R_API int r_crypto_set_iv(RCrypto *cry, const ut8 *iv, int ivlen);
|
2016-04-13 23:42:09 +05:30
|
|
|
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 14:11:21 +04:00
|
|
|
R_API int r_crypto_append(RCrypto *cry, const ut8 *buf, int len);
|
2016-03-07 02:38:50 +01:00
|
|
|
R_API ut8 *r_crypto_get_output(RCrypto *cry, int *size);
|
2016-05-12 01:55:54 +05:30
|
|
|
R_API const char *r_crypto_name(ut64 bit);
|
2009-12-24 03:17:53 +01:00
|
|
|
#endif
|
2009-09-15 01:51:28 +02:00
|
|
|
|
|
|
|
/* plugin pointers */
|
2012-07-21 14:11:21 +04:00
|
|
|
extern RCryptoPlugin r_crypto_plugin_aes;
|
2016-03-07 02:38:50 +01:00
|
|
|
extern RCryptoPlugin r_crypto_plugin_rc4;
|
2016-03-09 03:54:31 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_xor;
|
2016-03-08 20:39:35 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_blowfish;
|
2016-03-08 04:55:22 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_rc2;
|
2016-04-09 15:48:03 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_rot;
|
2016-04-09 22:56:28 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_rol;
|
|
|
|
extern RCryptoPlugin r_crypto_plugin_ror;
|
2016-04-12 22:25:16 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_base64;
|
|
|
|
extern RCryptoPlugin r_crypto_plugin_base91;
|
2016-04-15 01:09:45 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_aes_cbc;
|
2016-05-07 16:01:13 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_punycode;
|
2016-05-09 20:21:26 +05:30
|
|
|
extern RCryptoPlugin r_crypto_plugin_rc6;
|
2009-12-24 03:17:53 +01:00
|
|
|
|
2016-05-12 01:55:54 +05:30
|
|
|
#define R_CRYPTO_NONE 0
|
|
|
|
#define R_CRYPTO_RC2 1
|
|
|
|
#define R_CRYPTO_RC4 2
|
|
|
|
#define R_CRYPTO_RC6 4
|
|
|
|
#define R_CRYPTO_AES_ECB 8
|
|
|
|
#define R_CRYPTO_AES_CBC 16
|
|
|
|
#define R_CRYPTO_ROR 32
|
|
|
|
#define R_CRYPTO_ROL 64
|
|
|
|
#define R_CRYPTO_ROT 128
|
|
|
|
#define R_CRYPTO_BLOWFISH 256
|
|
|
|
#define R_CRYPTO_ALL 0xFFFF
|
|
|
|
|
2013-06-18 12:09:23 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-15 01:51:28 +02:00
|
|
|
#endif
|