diff options
| author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-14 14:43:53 +0200 |
|---|---|---|
| committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-14 14:43:53 +0200 |
| commit | e91273875bcb8774042c9950b45145ebc000f07c (patch) | |
| tree | 2523ab3b63d0f1b92abf93f85a5709e5e9b8454c /lib/plugins | |
| parent | 3b7fd8d97a4fbd1baa5e6b2f3827c430fb07a9a1 (diff) | |
| download | abrt-e91273875bcb8774042c9950b45145ebc000f07c.tar.gz abrt-e91273875bcb8774042c9950b45145ebc000f07c.tar.xz abrt-e91273875bcb8774042c9950b45145ebc000f07c.zip | |
move sha1 to lib/utils; remove small bit of related C++isms in CCpp.cpp
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'lib/plugins')
| -rw-r--r-- | lib/plugins/CCpp.cpp | 64 | ||||
| -rw-r--r-- | lib/plugins/CCpp_sha1.cpp | 214 | ||||
| -rw-r--r-- | lib/plugins/CCpp_sha1.h | 32 | ||||
| -rw-r--r-- | lib/plugins/Makefile.am | 2 |
4 files changed, 18 insertions, 294 deletions
diff --git a/lib/plugins/CCpp.cpp b/lib/plugins/CCpp.cpp index 4b1590e5..b5181832 100644 --- a/lib/plugins/CCpp.cpp +++ b/lib/plugins/CCpp.cpp @@ -26,7 +26,6 @@ #include "comm_layer_inner.h" #include "Polkit.h" #include "backtrace.h" -#include "CCpp_sha1.h" using namespace std; @@ -53,42 +52,12 @@ CAnalyzerCCpp::CAnalyzerCCpp() : m_nGdbTimeoutSec(60) {} -static string create_hash(const char *pInput) +static void create_hash(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *pInput) { - unsigned int len; - -#if 0 -{ - char hash_str[SHA1_LENGTH*2 + 1]; - unsigned char hash[SHA1_LENGTH]; - HASHContext *hc; - hc = HASH_Create(HASH_AlgSHA1); - if (!hc) - { - error_msg_and_die("HASH_Create(HASH_AlgSHA1) failed"); /* paranoia */ - } - HASH_Begin(hc); - HASH_Update(hc, (const unsigned char*)pInput, strlen(pInput)); - HASH_End(hc, hash, &len, sizeof(hash)); - HASH_Destroy(hc); - - char *d = hash_str; - unsigned char *s = hash; - while (len) - { - *d++ = "0123456789abcdef"[*s >> 4]; - *d++ = "0123456789abcdef"[*s & 0xf]; - s++; - len--; - } - *d = '\0'; -//log("hash1:%s str:'%s'", hash_str, pInput); -} -#endif - - char hash_str[SHA1_RESULT_LEN*2 + 1]; + unsigned len; unsigned char hash2[SHA1_RESULT_LEN]; sha1_ctx_t sha1ctx; + sha1_begin(&sha1ctx); sha1_hash(pInput, strlen(pInput), &sha1ctx); sha1_end(hash2, &sha1ctx); @@ -104,9 +73,7 @@ static string create_hash(const char *pInput) len--; } *d = '\0'; -//log("hash2:%s str:'%s'", hash_str, pInput); - - return hash_str; + //log("hash2:%s str:'%s'", hash_str, pInput); } /** @@ -297,8 +264,6 @@ static char *get_backtrace(const char *pDebugDumpDir, const char *pDebugInfoDirs bt_depth = 256; full = ""; } - free(bt); - free(args[9]); } free(uid); free(args[5]); @@ -363,7 +328,7 @@ static char* run_unstrip_n(const char *pDebugDumpDir, unsigned timeout_sec) /* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668 * It is slated to be in F12/RHEL6. * - * returened value must be freed + * returned value must be freed */ static char *install_debug_infos(const char *pDebugDumpDir, const char *debuginfo_dirs) { @@ -581,10 +546,11 @@ string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) free(package); free(executable); - string hash = create_hash(hash_str); + char hash_str2[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str2, hash_str); free(hash_str); - return hash; + return hash_str2; } string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) @@ -720,10 +686,11 @@ string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) free(package); free(executable); - string hash = create_hash(hash_str); + char hash_str2[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str2, hash_str); free(hash_str); - return hash; + return hash_str2; } } @@ -870,10 +837,11 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) struct strbuf *bt = backtrace_tree_as_str(backtrace, false); strbuf_prepend_str(bt, executable); strbuf_prepend_str(bt, package); - dd_save_text(dd, FILENAME_GLOBAL_UUID, create_hash(bt->buf).c_str()); + char hash_str[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str, bt->buf); + dd_save_text(dd, FILENAME_GLOBAL_UUID, hash_str); strbuf_free(bt); - /* Compute and store backtrace rating. */ /* Compute and store backtrace rating. The crash frame is more important that the others. The frames around the crash are more important than the rest. */ @@ -910,7 +878,9 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) struct strbuf *ibt = independent_backtrace(backtrace_str); strbuf_prepend_str(ibt, executable); strbuf_prepend_str(ibt, package); - dd_save_text(dd, FILENAME_GLOBAL_UUID, create_hash(ibt->buf).c_str()); + char hash_str[SHA1_RESULT_LEN*2 + 1]; + create_hash(hash_str, ibt->buf); + dd_save_text(dd, FILENAME_GLOBAL_UUID, hash_str); strbuf_free(ibt); /* Compute and store backtrace rating. */ diff --git a/lib/plugins/CCpp_sha1.cpp b/lib/plugins/CCpp_sha1.cpp deleted file mode 100644 index 86a9e831..00000000 --- a/lib/plugins/CCpp_sha1.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Based on shasum from http://www.netsw.org/crypto/hash/ - * Majorly hacked up to use Dr Brian Gladman's sha1 code - * - * Copyright (C) 2002 Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. - * Copyright (C) 2003 Glenn L. McGrath - * Copyright (C) 2003 Erik Andersen - * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. - * - * --------------------------------------------------------------------------- - * Issue Date: 10/11/2002 - * - * This is a byte oriented version of SHA1 that operates on arrays of bytes - * stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor - * - * --------------------------------------------------------------------------- - */ -#include "abrtlib.h" -#include "CCpp_sha1.h" - -#if defined(__BIG_ENDIAN__) && __BIG_ENDIAN__ -# define SHA1_BIG_ENDIAN 1 -# define SHA1_LITTLE_ENDIAN 0 -#elif __BYTE_ORDER == __BIG_ENDIAN -# define SHA1_BIG_ENDIAN 1 -# define SHA1_LITTLE_ENDIAN 0 -#elif __BYTE_ORDER == __LITTLE_ENDIAN -# define SHA1_BIG_ENDIAN 0 -# define SHA1_LITTLE_ENDIAN 1 -#else -# error "Can't determine endianness" -#endif - - -#define rotl32(x,n) (((x) << (n)) | ((x) >> (32 - (n)))) -#define rotr32(x,n) (((x) >> (n)) | ((x) << (32 - (n)))) -/* for sha512: */ -#define rotr64(x,n) (((x) >> (n)) | ((x) << (64 - (n)))) -#if SHA1_LITTLE_ENDIAN -static inline uint64_t hton64(uint64_t v) -{ - return (((uint64_t)htonl(v)) << 32) | htonl(v >> 32); -} -#else -#define hton64(v) (v) -#endif -#define ntoh64(v) hton64(v) - -/* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -#if defined(__GNUC__) && __GNUC__ >= 2 -# define UNALIGNED_P(p,type) (((uintptr_t) p) % __alignof__(type) != 0) -#else -# define UNALIGNED_P(p,type) (((uintptr_t) p) % sizeof(type) != 0) -#endif - - -/* Some arch headers have conflicting defines */ -#undef ch -#undef parity -#undef maj -#undef rnd - -static void sha1_process_block64(sha1_ctx_t *ctx) -{ - unsigned t; - uint32_t W[80], a, b, c, d, e; - const uint32_t *words = (uint32_t*) ctx->wbuffer; - - for (t = 0; t < 16; ++t) { - W[t] = ntohl(*words); - words++; - } - - for (/*t = 16*/; t < 80; ++t) { - uint32_t T = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]; - W[t] = rotl32(T, 1); - } - - a = ctx->hash[0]; - b = ctx->hash[1]; - c = ctx->hash[2]; - d = ctx->hash[3]; - e = ctx->hash[4]; - -/* Reverse byte order in 32-bit words */ -#define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) -#define parity(x,y,z) ((x) ^ (y) ^ (z)) -#define maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) -/* A normal version as set out in the FIPS. This version uses */ -/* partial loop unrolling and is optimised for the Pentium 4 */ -#define rnd(f,k) \ - do { \ - uint32_t T = a; \ - a = rotl32(a, 5) + f(b, c, d) + e + k + W[t]; \ - e = d; \ - d = c; \ - c = rotl32(b, 30); \ - b = T; \ - } while (0) - - for (t = 0; t < 20; ++t) - rnd(ch, 0x5a827999); - - for (/*t = 20*/; t < 40; ++t) - rnd(parity, 0x6ed9eba1); - - for (/*t = 40*/; t < 60; ++t) - rnd(maj, 0x8f1bbcdc); - - for (/*t = 60*/; t < 80; ++t) - rnd(parity, 0xca62c1d6); -#undef ch -#undef parity -#undef maj -#undef rnd - - ctx->hash[0] += a; - ctx->hash[1] += b; - ctx->hash[2] += c; - ctx->hash[3] += d; - ctx->hash[4] += e; -} - -void sha1_begin(sha1_ctx_t *ctx) -{ - ctx->hash[0] = 0x67452301; - ctx->hash[1] = 0xefcdab89; - ctx->hash[2] = 0x98badcfe; - ctx->hash[3] = 0x10325476; - ctx->hash[4] = 0xc3d2e1f0; - ctx->total64 = 0; - ctx->process_block = sha1_process_block64; -} - -static const uint32_t init256[] = { - 0x6a09e667, - 0xbb67ae85, - 0x3c6ef372, - 0xa54ff53a, - 0x510e527f, - 0x9b05688c, - 0x1f83d9ab, - 0x5be0cd19 -}; -static const uint32_t init512_lo[] = { - 0xf3bcc908, - 0x84caa73b, - 0xfe94f82b, - 0x5f1d36f1, - 0xade682d1, - 0x2b3e6c1f, - 0xfb41bd6b, - 0x137e2179 -}; - -/* Used also for sha256 */ -void sha1_hash(const void *buffer, size_t len, sha1_ctx_t *ctx) -{ - unsigned in_buf = ctx->total64 & 63; - unsigned add = 64 - in_buf; - - ctx->total64 += len; - - while (len >= add) { /* transfer whole blocks while possible */ - memcpy(ctx->wbuffer + in_buf, buffer, add); - buffer = (const char *)buffer + add; - len -= add; - add = 64; - in_buf = 0; - ctx->process_block(ctx); - } - - memcpy(ctx->wbuffer + in_buf, buffer, len); -} - -/* Used also for sha256 */ -void sha1_end(void *resbuf, sha1_ctx_t *ctx) -{ - unsigned pad, in_buf; - - in_buf = ctx->total64 & 63; - /* Pad the buffer to the next 64-byte boundary with 0x80,0,0,0... */ - ctx->wbuffer[in_buf++] = 0x80; - - /* This loop iterates either once or twice, no more, no less */ - while (1) { - pad = 64 - in_buf; - memset(ctx->wbuffer + in_buf, 0, pad); - in_buf = 0; - /* Do we have enough space for the length count? */ - if (pad >= 8) { - /* Store the 64-bit counter of bits in the buffer in BE format */ - uint64_t t = ctx->total64 << 3; - t = hton64(t); - /* wbuffer is suitably aligned for this */ - *(uint64_t *) (&ctx->wbuffer[64 - 8]) = t; - } - ctx->process_block(ctx); - if (pad >= 8) - break; - } - - in_buf = (ctx->process_block == sha1_process_block64) ? 5 : 8; - /* This way we do not impose alignment constraints on resbuf: */ - if (SHA1_LITTLE_ENDIAN) { - unsigned i; - for (i = 0; i < in_buf; ++i) - ctx->hash[i] = htonl(ctx->hash[i]); - } - memcpy(resbuf, ctx->hash, sizeof(ctx->hash[0]) * in_buf); -} diff --git a/lib/plugins/CCpp_sha1.h b/lib/plugins/CCpp_sha1.h deleted file mode 100644 index abadfd92..00000000 --- a/lib/plugins/CCpp_sha1.h +++ /dev/null @@ -1,32 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Based on shasum from http://www.netsw.org/crypto/hash/ - * Majorly hacked up to use Dr Brian Gladman's sha1 code - * - * Copyright (C) 2002 Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. - * Copyright (C) 2003 Glenn L. McGrath - * Copyright (C) 2003 Erik Andersen - * - * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. - * - * --------------------------------------------------------------------------- - * Issue Date: 10/11/2002 - * - * This is a byte oriented version of SHA1 that operates on arrays of bytes - * stored in memory. It runs at 22 cycles per byte on a Pentium P4 processor - * - * --------------------------------------------------------------------------- - */ - -#define SHA1_RESULT_LEN (5 * 4) - -typedef struct sha1_ctx_t { - uint32_t hash[8]; /* 5, +3 elements for sha256 */ - uint64_t total64; - uint8_t wbuffer[64]; /* NB: always correctly aligned for uint64_t */ - void (*process_block)(struct sha1_ctx_t*); -} sha1_ctx_t; - -void sha1_begin(sha1_ctx_t *ctx); -void sha1_hash(const void *buffer, size_t len, sha1_ctx_t *ctx); -void sha1_end(void *resbuf, sha1_ctx_t *ctx); diff --git a/lib/plugins/Makefile.am b/lib/plugins/Makefile.am index ca874e1b..ffdfa332 100644 --- a/lib/plugins/Makefile.am +++ b/lib/plugins/Makefile.am @@ -64,7 +64,7 @@ INC_PATH=$(srcdir)/../../inc UTILS_PATH=$(srcdir)/../utils # CCpp -libCCpp_la_SOURCES = CCpp.cpp CCpp.h CCpp_sha1.cpp CCpp_sha1.h +libCCpp_la_SOURCES = CCpp.cpp CCpp.h libCCpp_la_LDFLAGS = -avoid-version #libCCpp_la_LIBADD = libCCpp_la_CPPFLAGS = -Wall -Werror \ |
