add ROT to rahash2

fix indentation

remove unnecessary header inclusion
This commit is contained in:
Rakholiya Jenish 2016-04-09 15:48:03 +05:30 committed by pancake
parent 85419d7356
commit 4c1c17f90a
6 changed files with 95 additions and 2 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;
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;
lib r_crypto : $(OBJS) : <include>../include <library>../util ;

View File

@ -0,0 +1,82 @@
#include <r_lib.h>
#include <r_crypto.h>
int mod(int a, int b) {
if (b < 0) {
return mod (-a, -b);
}
int ret = a % b;
if (ret < 0) {
ret += b;
}
return ret;
}
static bool rot_init(ut8 *rotkey, const ut8 *key, int keylen) {
if (!rotkey || !key) {
return false;
}
int i = atoi(key);
*rotkey = (ut8)mod(i, 26);
return true;
}
static void rot_crypt(ut8 key, const ut8 *inbuf, ut8 *outbuf, int buflen) {
int i;
for (i = 0; i < buflen; i++) {
outbuf[i] = inbuf[i];
if ((inbuf[i] < 'a' || inbuf[i] > 'z') && (inbuf[i] < 'A' || inbuf[i] > 'Z')) {
continue;
}
outbuf[i] += key;
outbuf[i] -= (inbuf[i] >= 'a' && inbuf[i] <= 'z') ? 'a' : 'A';
outbuf[i] = mod (outbuf[i], 26);
outbuf[i] += (inbuf[i] >= 'a' && inbuf[i] <= 'z') ? 'a' : 'A';
}
}
static ut8 rot_key;
static int rot_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) {
return rot_init (&rot_key, key, keylen);
}
static int rot_get_key_size(RCrypto *cry) {
//Returning number of bytes occupied by ut8
return 1;
}
static bool rot_use(const char *algo) {
return !strcmp (algo, "rot");
}
static int update(RCrypto *cry, const ut8 *buf, int len) {
ut8 *obuf = calloc (1, len);
if (!obuf) return false;
rot_crypt (rot_key, 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_rot = {
.name = "rot",
.set_key = rot_set_key,
.get_key_size = rot_get_key_size,
.use = rot_use,
.update = update,
.final = final
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_CRYPTO,
.data = &r_crypto_plugin_rot,
.version = R2_VERSION
};
#endif

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

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

View File

@ -66,6 +66,7 @@ extern RCryptoPlugin r_crypto_plugin_rc4;
extern RCryptoPlugin r_crypto_plugin_xor;
extern RCryptoPlugin r_crypto_plugin_blowfish;
extern RCryptoPlugin r_crypto_plugin_rc2;
extern RCryptoPlugin r_crypto_plugin_rot;
#ifdef __cplusplus
}

View File

@ -41,7 +41,7 @@ Decode base64 string or file
.It Fl e
Use little endian to display checksums
.It Fl E Ar algo
Encrypt instead of hash using the given algorithm (rc4, aes, xor, blowfish)
Encrypt instead of hash using the given algorithm (rc4, aes, xor, blowfish, rot)
.It Fl i Ar iters
Apply the hash Iters times to itself+seed
.It Fl j

View File

@ -153,6 +153,7 @@ crypto.rc4
crypto.xor
crypto.blowfish
crypto.rc2
crypto.rot
debug.bf
debug.esil
debug.gdb