From d471bd6da2cfaa5ff11cfa22fff694108a69beef Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 16 Feb 2011 14:18:31 +0100 Subject: [PATCH] * Handle entropy hash type from rahash2 --- binr/rahash2/rahash2.c | 2 +- libr/hash/calc.c | 4 ++++ libr/hash/hash.c | 12 +++++------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/binr/rahash2/rahash2.c b/binr/rahash2/rahash2.c index acd2b9b508..8864c07ce3 100644 --- a/binr/rahash2/rahash2.c +++ b/binr/rahash2/rahash2.c @@ -56,7 +56,7 @@ static int do_help(int line) { } 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; int c, buf_len = 0; int bsize = 0; diff --git a/libr/hash/calc.c b/libr/hash/calc.c index 2c6a57be38..21db771683 100644 --- a/libr/hash/calc.c +++ b/libr/hash/calc.c @@ -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); return 1; } + if (algobit & R_HASH_ENTROPY) { + ctx->digest[0] = (ut8)r_hash_entropy (buf, len); + return 1; + } if (algobit & R_HASH_XOR) { ctx->digest[0] = r_hash_xor(buf, len); return 1; diff --git a/libr/hash/hash.c b/libr/hash/hash.c index 09789d3576..477ea5a364 100644 --- a/libr/hash/hash.c +++ b/libr/hash/hash.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2007-2010 pancake<@nopcode.org> */ +/* radare - LGPL - Copyright 2007-2011 pancake<@nopcode.org> */ #include "r_hash.h" @@ -6,11 +6,9 @@ R_API int r_hash_pcprint(const ut8 *buffer, ut64 len) { const ut8 *end = buffer + len; int n; - for(n=0; buffer>=1;len--;b=b+1) + for (len>>=1;len--;b=b+1) result^=b[0]; 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) { - int i, c = 0; - len--; - for (i = 0; i < len; i++) + int i, c; + for (c = i = 0, --len; i < len; i++) c += R_ABS (b[i+1] - b[i]); 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_SHA512) return "sha512"; 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_XORPAIR) return "xorpair"; if (bit & R_HASH_MOD255) return "mod255";