add ROL and ROR support

This commit is contained in:
Rakholiya Jenish 2016-04-09 22:56:28 +05:30 committed by pancake
parent 4c1c17f90a
commit 8ea2e80354
7 changed files with 167 additions and 1 deletions

View File

@ -1,4 +1,4 @@
OBJS = crypto.c ;
OBJS += p/crypto_aes.c p/crypto_aes_algo.c p/crypto_xor.c p/crypto_blowfish.c p/crypto_rc2.c p/crypto_rot.c;
OBJS += p/crypto_aes.c p/crypto_aes_algo.c p/crypto_xor.c p/crypto_blowfish.c p/crypto_rc2.c p/crypto_rot.c p/crypto_rol.c p/crypto_ror.c;
lib r_crypto : $(OBJS) : <include>../include <library>../util ;

View File

@ -0,0 +1,72 @@
#include <r_lib.h>
#include <r_crypto.h>
#define MAX_rol_KEY_SIZE 32768
struct rol_state {
ut8 key[MAX_rol_KEY_SIZE];
int key_size;
};
static bool rol_init(struct rol_state *const state, const ut8 *key, int keylen) {
if (!state || !key || keylen < 1 || keylen > MAX_rol_KEY_SIZE) {
return false;
}
int i;
state->key_size = keylen;
for (i = 0; i < keylen; i++) {
state->key[i] = key[i];
}
return true;
}
static void rol_crypt(struct rol_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen) {
int i;
for (i = 0; i < buflen; i++) {
outbuf[i] = inbuf[i] << state->key[i%state->key_size];
}
}
static struct rol_state st;
static int rol_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) {
return rol_init (&st, key, keylen);
}
static int rol_get_key_size(RCrypto *cry) {
return st.key_size;
}
static bool rol_use(const char *algo) {
return !strcmp (algo, "rol");
}
static int update(RCrypto *cry, const ut8 *buf, int len) {
ut8 *obuf = calloc (1, len);
if (!obuf) return false;
rol_crypt (&st, buf, obuf, len);
r_crypto_append (cry, obuf, len);
free (obuf);
return 0;
}
static int final(RCrypto *cry, const ut8 *buf, int len) {
return update (cry, buf, len);
}
RCryptoPlugin r_crypto_plugin_rol = {
.name = "rol",
.set_key = rol_set_key,
.get_key_size = rol_get_key_size,
.use = rol_use,
.update = update,
.final = final
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_CRYPTO,
.data = &r_crypto_plugin_rol,
.version = R2_VERSION
};
#endif

View File

@ -0,0 +1,72 @@
#include <r_lib.h>
#include <r_crypto.h>
#define MAX_ror_KEY_SIZE 32768
struct ror_state {
ut8 key[MAX_ror_KEY_SIZE];
int key_size;
};
static bool ror_init(struct ror_state *const state, const ut8 *key, int keylen) {
if (!state || !key || keylen < 1 || keylen > MAX_ror_KEY_SIZE) {
return false;
}
int i;
state->key_size = keylen;
for (i = 0; i < keylen; i++) {
state->key[i] = key[i];
}
return true;
}
static void ror_crypt(struct ror_state *const state, const ut8 *inbuf, ut8 *outbuf, int buflen) {
int i;
for (i = 0; i < buflen; i++) {
outbuf[i] = inbuf[i] >> state->key[i%state->key_size];
}
}
static struct ror_state st;
static int ror_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) {
return ror_init (&st, key, keylen);
}
static int ror_get_key_size(RCrypto *cry) {
return st.key_size;
}
static bool ror_use(const char *algo) {
return !strcmp (algo, "ror");
}
static int update(RCrypto *cry, const ut8 *buf, int len) {
ut8 *obuf = calloc (1, len);
if (!obuf) return false;
ror_crypt (&st, buf, obuf, len);
r_crypto_append (cry, obuf, len);
free (obuf);
return 0;
}
static int final(RCrypto *cry, const ut8 *buf, int len) {
return update (cry, buf, len);
}
RCryptoPlugin r_crypto_plugin_ror = {
.name = "ror",
.set_key = ror_set_key,
.get_key_size = ror_get_key_size,
.use = ror_use,
.update = update,
.final = final
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_CRYPTO,
.data = &r_crypto_plugin_ror,
.version = R2_VERSION
};
#endif

9
libr/crypto/p/rol.mk Normal file
View File

@ -0,0 +1,9 @@
OBJ_ROL=crypto_rol.o
STATIC_OBJ+=${OBJ_ROL}
TARGET_ROL=crypto_rol.${EXT_SO}
ALL_TARGETS+=${TARGET_ROL}
${TARGET_ROL}: ${OBJ_ROL}
${CC} $(call libname,crypto_rol) ${LDFLAGS} ${CFLAGS} -o ${TARGET_ROL} ${OBJ_ROL}

9
libr/crypto/p/ror.mk Normal file
View File

@ -0,0 +1,9 @@
OBJ_ROR=crypto_ror.o
STATIC_OBJ+=${OBJ_ROR}
TARGET_ROR=crypto_ror.${EXT_SO}
ALL_TARGETS+=${TARGET_ROR}
${TARGET_ROR}: ${OBJ_ROR}
${CC} $(call libname,crypto_ror) ${LDFLAGS} ${CFLAGS} -o ${TARGET_ROR} ${OBJ_ROR}

View File

@ -67,6 +67,8 @@ extern RCryptoPlugin r_crypto_plugin_xor;
extern RCryptoPlugin r_crypto_plugin_blowfish;
extern RCryptoPlugin r_crypto_plugin_rc2;
extern RCryptoPlugin r_crypto_plugin_rot;
extern RCryptoPlugin r_crypto_plugin_rol;
extern RCryptoPlugin r_crypto_plugin_ror;
#ifdef __cplusplus
}

View File

@ -154,6 +154,8 @@ crypto.xor
crypto.blowfish
crypto.rc2
crypto.rot
crypto.rol
crypto.ror
debug.bf
debug.esil
debug.gdb