X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fhash.c;h=f1a6c4096f81ed1a4e6c77f248f9fdbff3e25fdc;hb=2f6c7b1aa0bf4a675d0ec95646b27f5c71bf06c2;hp=1e25bdbe18269b9d9be9261d3518b49c50f1555a;hpb=9c29c48f8327fc20b3840ce2fb4dad4a6c8003b2;p=exim.git diff --git a/src/src/hash.c b/src/src/hash.c index 1e25bdbe1..f1a6c4096 100644 --- a/src/src/hash.c +++ b/src/src/hash.c @@ -1,8 +1,8 @@ /* * Exim - an Internet mail transport agent * - * Copyright (C) 2017 Exim maintainers - * Copyright (c) University of Cambridge 1995 - 2017 + * Copyright (C) 2010 - 2018 Exim maintainers + * Copyright (c) University of Cambridge 1995 - 2009 * * Hash interface functions */ @@ -33,7 +33,6 @@ sha1; BOOL exim_sha_init(hctx * h, hashmethod m) { -/*XXX extend for sha512 */ switch (h->method = m) { case HASH_SHA1: h->hashlen = 20; SHA1_Init (&h->u.sha1); break; @@ -85,7 +84,8 @@ switch (h->method) void exim_sha_finish(hctx * h, blob * b) { -b->data = store_get(b->len = h->hashlen); +/* Hashing is sufficient to purify any tainted input */ +b->data = store_get(b->len = h->hashlen, FALSE); switch (h->method) { case HASH_SHA1: SHA1_Final (b->data, &h->u.sha1); break; @@ -110,7 +110,6 @@ switch (h->method) BOOL exim_sha_init(hctx * h, hashmethod m) { -/*XXX extend for sha512 */ switch (h->method = m) { case HASH_SHA1: h->hashlen = 20; gnutls_hash_init(&h->sha, GNUTLS_DIG_SHA1); break; @@ -139,7 +138,7 @@ gnutls_hash(h->sha, data, len); void exim_sha_finish(hctx * h, blob * b) { -b->data = store_get(b->len = h->hashlen); +b->data = store_get(b->len = h->hashlen, FALSE); gnutls_hash_output(h->sha, b->data); } @@ -151,7 +150,6 @@ gnutls_hash_output(h->sha, b->data); BOOL exim_sha_init(hctx * h, hashmethod m) { -/*XXX extend for sha512 */ switch (h->method = m) { case HASH_SHA1: h->hashlen = 20; gcry_md_open(&h->sha, GCRY_MD_SHA1, 0); break; @@ -177,7 +175,7 @@ gcry_md_write(h->sha, data, len); void exim_sha_finish(hctx * h, blob * b) { -b->data = store_get(b->len = h->hashlen); +b->data = store_get(b->len = h->hashlen, FALSE); memcpy(b->data, gcry_md_read(h->sha, 0), h->hashlen); } @@ -215,7 +213,7 @@ switch (h->method) void exim_sha_finish(hctx * h, blob * b) { -b->data = store_get(b->len = h->hashlen); +b->data = store_get(b->len = h->hashlen, FALSE); switch (h->method) { case HASH_SHA1: sha1_finish(h->u.sha1, b->data); break; @@ -268,19 +266,18 @@ Returns: nothing static void native_sha1_mid(sha1 *base, const uschar *text) { -int i; uint A, B, C, D, E; uint W[80]; base->length += 64; -for (i = 0; i < 16; i++) +for (int i = 0; i < 16; i++) { W[i] = ((uint)text[0] << 24) | (text[1] << 16) | (text[2] << 8) | text[3]; text += 4; } -for (i = 16; i < 80; i++) +for (int i = 16; i < 80; i++) { register unsigned int x = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16]; W[i] = (x << 1) | (x >> 31); @@ -292,7 +289,7 @@ C = base->H[2]; D = base->H[3]; E = base->H[4]; -for (i = 0; i < 20; i++) +for (int i = 0; i < 20; i++) { unsigned int T; T = ((A << 5) | (A >> 27)) + ((B & C) | ((~B) & D)) + E + W[i] + 0x5a827999; @@ -303,7 +300,7 @@ for (i = 0; i < 20; i++) A = T; } -for (i = 20; i < 40; i++) +for (int i = 20; i < 40; i++) { unsigned int T; T = ((A << 5) | (A >> 27)) + (B ^ C ^ D) + E + W[i] + 0x6ed9eba1; @@ -314,7 +311,7 @@ for (i = 20; i < 40; i++) A = T; } -for (i = 40; i < 60; i++) +for (int i = 40; i < 60; i++) { unsigned int T; T = ((A << 5) | (A >> 27)) + ((B & C) | (B & D) | (C & D)) + E + W[i] + @@ -326,7 +323,7 @@ for (i = 40; i < 60; i++) A = T; } -for (i = 60; i < 80; i++) +for (int i = 60; i < 80; i++) { unsigned int T; T = ((A << 5) | (A >> 27)) + (B ^ C ^ D) + E + W[i] + 0xca62c1d6; @@ -367,7 +364,6 @@ Returns: nothing static void native_sha1_end(sha1 *base, const uschar *text, int length, uschar *digest) { -int i; uschar work[64]; /* Process in chunks of 64 until we have less than 64 bytes left. */ @@ -420,7 +416,7 @@ native_sha1_mid(base, work); /* Pass back the result, high-order byte first in each word. */ -for (i = 0; i < 5; i++) +for (int i = 0; i < 5; i++) { register int x = base->H[i]; *digest++ = (x >> 24) & 0xff; @@ -455,7 +451,7 @@ native_sha1_mid(&h->sha1, US data); /* implicit size always 64 */ void exim_sha_finish(hctx * h, blob * b) { -b->data = store_get(b->len = h->hashlen); +b->data = store_get(b->len = h->hashlen, FALSE); native_sha1_end(&h->sha1, NULL, 0, b->data); }