* Handle entropy hash type from rahash2

This commit is contained in:
pancake 2011-02-16 14:18:31 +01:00
parent 4fad96ecbb
commit d471bd6da2
3 changed files with 10 additions and 8 deletions

View File

@ -56,7 +56,7 @@ static int do_help(int line) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
char *algo = "md5,sha1"; /* default hashing algorithm */ const char *algo = "md5,sha1"; /* default hashing algorithm */
const ut8 *buf = NULL; const ut8 *buf = NULL;
int c, buf_len = 0; int c, buf_len = 0;
int bsize = 0; int bsize = 0;

View File

@ -46,6 +46,10 @@ R_API int r_hash_calculate(struct r_hash_t *ctx, int algobit, const ut8 *buf, ut
ctx->digest[0] = r_hash_parity(buf, len); ctx->digest[0] = r_hash_parity(buf, len);
return 1; return 1;
} }
if (algobit & R_HASH_ENTROPY) {
ctx->digest[0] = (ut8)r_hash_entropy (buf, len);
return 1;
}
if (algobit & R_HASH_XOR) { if (algobit & R_HASH_XOR) {
ctx->digest[0] = r_hash_xor(buf, len); ctx->digest[0] = r_hash_xor(buf, len);
return 1; return 1;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2007-2010 pancake<@nopcode.org> */ /* radare - LGPL - Copyright 2007-2011 pancake<@nopcode.org> */
#include "r_hash.h" #include "r_hash.h"
@ -6,11 +6,9 @@
R_API int r_hash_pcprint(const ut8 *buffer, ut64 len) { R_API int r_hash_pcprint(const ut8 *buffer, ut64 len) {
const ut8 *end = buffer + len; const ut8 *end = buffer + len;
int n; int n;
for(n=0; buffer<end; buffer = buffer + 1) for(n=0; buffer<end; buffer = buffer + 1)
if (IS_PRINTABLE(buffer[0])) if (IS_PRINTABLE(buffer[0]))
n++; n++;
return ((100*n)/len); return ((100*n)/len);
} }
@ -30,7 +28,7 @@ R_API int r_hash_parity(const ut8 *buf, ut64 len) {
R_API ut16 r_hash_xorpair(const ut8 *a, ut64 len) { R_API ut16 r_hash_xorpair(const ut8 *a, ut64 len) {
ut16 *b = (ut16 *)a; ut16 *b = (ut16 *)a;
ut16 result = 0; ut16 result = 0;
for(len>>=1;len--;b=b+1) for (len>>=1;len--;b=b+1)
result^=b[0]; result^=b[0];
return result; return result;
} }
@ -51,9 +49,8 @@ R_API ut8 r_hash_mod255(const ut8 *b, ut64 len) {
} }
R_API ut8 r_hash_deviation(const ut8 *b, ut64 len) { R_API ut8 r_hash_deviation(const ut8 *b, ut64 len) {
int i, c = 0; int i, c;
len--; for (c = i = 0, --len; i < len; i++)
for (i = 0; i < len; i++)
c += R_ABS (b[i+1] - b[i]); c += R_ABS (b[i+1] - b[i]);
return c; return c;
} }
@ -67,6 +64,7 @@ R_API const char *r_hash_name(int bit) {
if (bit & R_HASH_SHA384) return "sha384"; if (bit & R_HASH_SHA384) return "sha384";
if (bit & R_HASH_SHA512) return "sha512"; if (bit & R_HASH_SHA512) return "sha512";
if (bit & R_HASH_PARITY) return "parity"; if (bit & R_HASH_PARITY) return "parity";
if (bit & R_HASH_ENTROPY) return "entropy";
if (bit & R_HASH_XOR) return "xor"; if (bit & R_HASH_XOR) return "xor";
if (bit & R_HASH_XORPAIR) return "xorpair"; if (bit & R_HASH_XORPAIR) return "xorpair";
if (bit & R_HASH_MOD255) return "mod255"; if (bit & R_HASH_MOD255) return "mod255";