From: Richard Russon Date: Thu, 29 Aug 2019 09:56:13 +0000 (+0100) Subject: drop: unused sha1 code X-Git-Tag: 2019-10-25~71^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2184cccdbbcb536d3601b5c587dfc3078cadb8e5;p=neomutt drop: unused sha1 code --- diff --git a/Makefile.autosetup b/Makefile.autosetup index 107638f7a..275703a2f 100644 --- a/Makefile.autosetup +++ b/Makefile.autosetup @@ -289,7 +289,7 @@ LIBMUTTOBJS= mutt/base64.o mutt/buffer.o mutt/charset.o mutt/date.o \ mutt/history.o mutt/list.o mutt/logging.o mutt/mapping.o \ mutt/mbyte.o mutt/md5.o mutt/memory.o mutt/notify.o \ mutt/path.o mutt/pool.o \ - mutt/regex.o mutt/sha1.o mutt/slist.o mutt/signal.o mutt/string.o + mutt/regex.o mutt/slist.o mutt/signal.o mutt/string.o CLEANFILES+= $(LIBMUTT) $(LIBMUTTOBJS) MUTTLIBS+= $(LIBMUTT) ALLOBJS+= $(LIBMUTTOBJS) diff --git a/mutt/mutt.h b/mutt/mutt.h index 37c2d7bac..abb8def80 100644 --- a/mutt/mutt.h +++ b/mutt/mutt.h @@ -47,7 +47,6 @@ * | mutt/path.c | @subpage path | * | mutt/pool.c | @subpage pool | * | mutt/regex.c | @subpage regex | - * | mutt/sha1.c | @subpage sha1 | * | mutt/slist.c | @subpage slist | * | mutt/signal.c | @subpage signal | * | mutt/string.c | @subpage string | @@ -82,7 +81,6 @@ #include "path.h" #include "pool.h" #include "regex3.h" -#include "sha1.h" #include "signal2.h" #include "slist.h" #include "string2.h" diff --git a/mutt/sha1.c b/mutt/sha1.c deleted file mode 100644 index f790287ce..000000000 --- a/mutt/sha1.c +++ /dev/null @@ -1,270 +0,0 @@ -/** - * @file - * Calculate the SHA1 checksum of a buffer - * - * @authors - * Steve Reid - * Thomas Roessler - * - * @copyright - * Public Domain - */ - -/** - * @page sha1 Calculate the SHA1 checksum of a buffer - * - * Calculate the SHA1 cryptographic hash of a string, according to RFC3174. - * - * Test Vectors (from FIPS PUB 180-1): - * - "abc" yields `A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D` - * - "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" yields `84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1` - * - A million repetitions of "a" yields `34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F` - */ - -#include "config.h" -#include -#include "sha1.h" - -#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) - -/* blk0() and blk() perform the initial expand. */ -/* I got the idea of expanding during the round function from SSLeay */ -#ifdef WORDS_BIGENDIAN -#define blk0(i) block->l[i] -#else -#define blk0(i) \ - (block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) | (rol(block->l[i], 8) & 0x00FF00FF)) -#endif - -#define blk(i) \ - (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] ^ \ - block->l[(i + 2) & 15] ^ block->l[i & 15], \ - 1)) - -/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define R0(v, w, x, y, z, i) \ - z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \ - w = rol(w, 30); -#define R1(v, w, x, y, z, i) \ - z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \ - w = rol(w, 30); -#define R2(v, w, x, y, z, i) \ - z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); \ - w = rol(w, 30); -#define R3(v, w, x, y, z, i) \ - z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \ - w = rol(w, 30); -#define R4(v, w, x, y, z, i) \ - z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \ - w = rol(w, 30); - -/** - * mutt_sha1_transform - Hash a single 512-bit block - * @param state Internal state of the transform - * @param buffer Data to transform - * - * This is the core of the algorithm. - */ -void mutt_sha1_transform(uint32_t state[5], const unsigned char buffer[64]) -{ - if (!state || !buffer) - return; - - uint32_t a, b, c, d, e; - typedef union { - unsigned char c[64]; - uint32_t l[16]; - } CHAR64LONG16; - CHAR64LONG16 block[1]; /* use array to appear as a pointer */ - memcpy(block, buffer, 64); - /* Copy sha1ctx->state[] to working vars */ - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a, b, c, d, e, 0); - R0(e, a, b, c, d, 1); - R0(d, e, a, b, c, 2); - R0(c, d, e, a, b, 3); - R0(b, c, d, e, a, 4); - R0(a, b, c, d, e, 5); - R0(e, a, b, c, d, 6); - R0(d, e, a, b, c, 7); - R0(c, d, e, a, b, 8); - R0(b, c, d, e, a, 9); - R0(a, b, c, d, e, 10); - R0(e, a, b, c, d, 11); - R0(d, e, a, b, c, 12); - R0(c, d, e, a, b, 13); - R0(b, c, d, e, a, 14); - R0(a, b, c, d, e, 15); - R1(e, a, b, c, d, 16); - R1(d, e, a, b, c, 17); - R1(c, d, e, a, b, 18); - R1(b, c, d, e, a, 19); - R2(a, b, c, d, e, 20); - R2(e, a, b, c, d, 21); - R2(d, e, a, b, c, 22); - R2(c, d, e, a, b, 23); - R2(b, c, d, e, a, 24); - R2(a, b, c, d, e, 25); - R2(e, a, b, c, d, 26); - R2(d, e, a, b, c, 27); - R2(c, d, e, a, b, 28); - R2(b, c, d, e, a, 29); - R2(a, b, c, d, e, 30); - R2(e, a, b, c, d, 31); - R2(d, e, a, b, c, 32); - R2(c, d, e, a, b, 33); - R2(b, c, d, e, a, 34); - R2(a, b, c, d, e, 35); - R2(e, a, b, c, d, 36); - R2(d, e, a, b, c, 37); - R2(c, d, e, a, b, 38); - R2(b, c, d, e, a, 39); - R3(a, b, c, d, e, 40); - R3(e, a, b, c, d, 41); - R3(d, e, a, b, c, 42); - R3(c, d, e, a, b, 43); - R3(b, c, d, e, a, 44); - R3(a, b, c, d, e, 45); - R3(e, a, b, c, d, 46); - R3(d, e, a, b, c, 47); - R3(c, d, e, a, b, 48); - R3(b, c, d, e, a, 49); - R3(a, b, c, d, e, 50); - R3(e, a, b, c, d, 51); - R3(d, e, a, b, c, 52); - R3(c, d, e, a, b, 53); - R3(b, c, d, e, a, 54); - R3(a, b, c, d, e, 55); - R3(e, a, b, c, d, 56); - R3(d, e, a, b, c, 57); - R3(c, d, e, a, b, 58); - R3(b, c, d, e, a, 59); - R4(a, b, c, d, e, 60); - R4(e, a, b, c, d, 61); - R4(d, e, a, b, c, 62); - R4(c, d, e, a, b, 63); - R4(b, c, d, e, a, 64); - R4(a, b, c, d, e, 65); - R4(e, a, b, c, d, 66); - R4(d, e, a, b, c, 67); - R4(c, d, e, a, b, 68); - R4(b, c, d, e, a, 69); - R4(a, b, c, d, e, 70); - R4(e, a, b, c, d, 71); - R4(d, e, a, b, c, 72); - R4(c, d, e, a, b, 73); - R4(b, c, d, e, a, 74); - R4(a, b, c, d, e, 75); - R4(e, a, b, c, d, 76); - R4(d, e, a, b, c, 77); - R4(c, d, e, a, b, 78); - R4(b, c, d, e, a, 79); - /* Add the working vars back into sha1ctx.state[] */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - /* Wipe variables */ - a = 0; - b = 0; - c = 0; - d = 0; - e = 0; - memset(block, '\0', sizeof(block)); -} - -/** - * mutt_sha1_init - Initialize new context - * @param sha1ctx SHA1 context - */ -void mutt_sha1_init(struct Sha1Ctx *sha1ctx) -{ - if (!sha1ctx) - return; - - /* SHA1 initialization constants */ - sha1ctx->state[0] = 0x67452301; - sha1ctx->state[1] = 0xEFCDAB89; - sha1ctx->state[2] = 0x98BADCFE; - sha1ctx->state[3] = 0x10325476; - sha1ctx->state[4] = 0xC3D2E1F0; - sha1ctx->count[0] = 0; - sha1ctx->count[1] = 0; -} - -/** - * mutt_sha1_update - Run your data through this - * @param sha1ctx SHA1 context - * @param data Data to be hashed - * @param len Length of data - */ -void mutt_sha1_update(struct Sha1Ctx *sha1ctx, const unsigned char *data, uint32_t len) -{ - if (!sha1ctx || !data) - return; - - uint32_t i; - uint32_t j; - - j = sha1ctx->count[0]; - if ((sha1ctx->count[0] += len << 3) < j) - sha1ctx->count[1]++; - sha1ctx->count[1] += (len >> 29); - j = (j >> 3) & 63; - if ((j + len) > 63) - { - memcpy(&sha1ctx->buffer[j], data, (i = 64 - j)); - mutt_sha1_transform(sha1ctx->state, sha1ctx->buffer); - for (; i + 63 < len; i += 64) - { - mutt_sha1_transform(sha1ctx->state, &data[i]); - } - j = 0; - } - else - i = 0; - memcpy(&sha1ctx->buffer[j], &data[i], len - i); -} - -/** - * mutt_sha1_final - Add padding and return the message digest - * @param[out] digest Message digest (SHA1 sum) - * @param[in] sha1ctx SHA1 context - */ -void mutt_sha1_final(unsigned char digest[20], struct Sha1Ctx *sha1ctx) -{ - if (!digest || !sha1ctx) - return; - - unsigned char finalcount[8]; - unsigned char c; - - for (unsigned int i = 0; i < 8; i++) - { - finalcount[i] = - (unsigned char) ((sha1ctx->count[((i >= 4) ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & - 255); /* Endian independent */ - } - - c = 0200; - mutt_sha1_update(sha1ctx, &c, 1); - while ((sha1ctx->count[0] & 504) != 448) - { - c = 0000; - mutt_sha1_update(sha1ctx, &c, 1); - } - mutt_sha1_update(sha1ctx, finalcount, 8); /* Should cause a mutt_sha1_transform() */ - for (unsigned int i = 0; i < 20; i++) - { - digest[i] = (unsigned char) ((sha1ctx->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); - } - /* Wipe variables */ - memset(sha1ctx, '\0', sizeof(*sha1ctx)); - memset(&finalcount, '\0', sizeof(finalcount)); -} diff --git a/mutt/sha1.h b/mutt/sha1.h deleted file mode 100644 index bb4bdeb93..000000000 --- a/mutt/sha1.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @file - * Calculate the SHA1 checksum of a buffer - * - * @authors - * Copyright (C) 2000 Steve Reid - * Copyright (C) 2000 Thomas Roessler - * Copyright (C) 2017 Richard Russon - * - * @copyright - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#ifndef MUTT_LIB_SHA1_H -#define MUTT_LIB_SHA1_H - -#include - -/** - * struct Sha1Ctx - Cursor for the SHA1 hashing - */ -struct Sha1Ctx -{ - uint32_t state[5]; - uint32_t count[2]; - unsigned char buffer[64]; -}; - -void mutt_sha1_final(unsigned char digest[20], struct Sha1Ctx *sha1ctx); -void mutt_sha1_init(struct Sha1Ctx *sha1ctx); -void mutt_sha1_transform(uint32_t state[5], const unsigned char buffer[64]); -void mutt_sha1_update(struct Sha1Ctx *sha1ctx, const unsigned char *data, uint32_t len); - -#endif /* MUTT_LIB_SHA1_H */ diff --git a/test/Makefile.autosetup b/test/Makefile.autosetup index 87776a957..ddfbf1876 100644 --- a/test/Makefile.autosetup +++ b/test/Makefile.autosetup @@ -349,11 +349,6 @@ RFC2047_OBJS = test/rfc2047/common.o \ RFC2231_OBJS = test/rfc2231/rfc2231_encode_string.o \ test/rfc2231/rfc2231_decode_parameters.o -SHA1_OBJS = test/sha1/mutt_sha1_final.o \ - test/sha1/mutt_sha1_init.o \ - test/sha1/mutt_sha1_transform.o \ - test/sha1/mutt_sha1_update.o - SIGNAL_OBJS = test/signal/mutt_sig_allow_interrupt.o \ test/signal/mutt_sig_block.o \ test/signal/mutt_sig_block_system.o \ @@ -441,8 +436,8 @@ BUILD_DIRS = $(PWD)/test/address $(PWD)/test/attach $(PWD)/test/base64 \ $(PWD)/test/md5 $(PWD)/test/memory $(PWD)/test/parameter \ $(PWD)/test/parse $(PWD)/test/path $(PWD)/test/pattern \ $(PWD)/test/regex $(PWD)/test/rfc2047 $(PWD)/test/rfc2231 \ - $(PWD)/test/sha1 $(PWD)/test/signal $(PWD)/test/string \ - $(PWD)/test/tags $(PWD)/test/thread $(PWD)/test/url + $(PWD)/test/signal $(PWD)/test/string $(PWD)/test/tags \ + $(PWD)/test/thread $(PWD)/test/url TEST_OBJS = test/main.o \ $(ADDRESS_OBJS) \ @@ -475,7 +470,6 @@ TEST_OBJS = test/main.o \ $(REGEX_OBJS) \ $(RFC2047_OBJS) \ $(RFC2231_OBJS) \ - $(SHA1_OBJS) \ $(SIGNAL_OBJS) \ $(STRING_OBJS) \ $(TAGS_OBJS) \ diff --git a/test/main.c b/test/main.c index 20b6b9bc1..5e66fe25c 100644 --- a/test/main.c +++ b/test/main.c @@ -337,10 +337,6 @@ NEOMUTT_TEST_ITEM(test_rfc2047_encode_envelope) \ NEOMUTT_TEST_ITEM(test_rfc2231_decode_parameters) \ NEOMUTT_TEST_ITEM(test_rfc2231_encode_string) \ - NEOMUTT_TEST_ITEM(test_mutt_sha1_final) \ - NEOMUTT_TEST_ITEM(test_mutt_sha1_init) \ - NEOMUTT_TEST_ITEM(test_mutt_sha1_transform) \ - NEOMUTT_TEST_ITEM(test_mutt_sha1_update) \ NEOMUTT_TEST_ITEM(test_mutt_sig_allow_interrupt) \ NEOMUTT_TEST_ITEM(test_mutt_sig_block) \ NEOMUTT_TEST_ITEM(test_mutt_sig_block_system) \ diff --git a/test/sha1/mutt_sha1_final.c b/test/sha1/mutt_sha1_final.c deleted file mode 100644 index ffe290326..000000000 --- a/test/sha1/mutt_sha1_final.c +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file - * Test code for mutt_sha1_final() - * - * @authors - * Copyright (C) 2019 Richard Russon - * - * @copyright - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#define TEST_NO_MAIN -#include "acutest.h" -#include "config.h" -#include "mutt/mutt.h" - -void test_mutt_sha1_final(void) -{ - // void mutt_sha1_final(unsigned char digest[20], struct Sha1Ctx *sha1ctx); - - { - struct Sha1Ctx sha1ctx; - mutt_sha1_init(&sha1ctx); - mutt_sha1_final(NULL, &sha1ctx); - TEST_CHECK_(1, "mutt_sha1_final(NULL, &sha1ctx)"); - } - - { - unsigned char digest[20]; - mutt_sha1_final(digest, NULL); - TEST_CHECK_(1, "mutt_sha1_final(&digest, NULL)"); - } -} diff --git a/test/sha1/mutt_sha1_init.c b/test/sha1/mutt_sha1_init.c deleted file mode 100644 index dad2b4ebb..000000000 --- a/test/sha1/mutt_sha1_init.c +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file - * Test code for mutt_sha1_init() - * - * @authors - * Copyright (C) 2019 Richard Russon - * - * @copyright - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#define TEST_NO_MAIN -#include "acutest.h" -#include "config.h" -#include "mutt/mutt.h" - -void test_mutt_sha1_init(void) -{ - // void mutt_sha1_init(struct Sha1Ctx *sha1ctx); - - { - mutt_sha1_init(NULL); - TEST_CHECK_(1, "mutt_sha1_init(NULL)"); - } -} diff --git a/test/sha1/mutt_sha1_transform.c b/test/sha1/mutt_sha1_transform.c deleted file mode 100644 index 7db5f9ed1..000000000 --- a/test/sha1/mutt_sha1_transform.c +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @file - * Test code for mutt_sha1_transform() - * - * @authors - * Copyright (C) 2019 Richard Russon - * - * @copyright - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#define TEST_NO_MAIN -#include "acutest.h" -#include "config.h" -#include "mutt/mutt.h" - -void test_mutt_sha1_transform(void) -{ - // void mutt_sha1_transform(uint32_t state[5], const unsigned char buffer[64]); - - { - unsigned char buf[64] = { 0 }; - mutt_sha1_transform(NULL, buf); - TEST_CHECK_(1, "mutt_sha1_transform(NULL, &buf)"); - } - - { - uint32_t buf[64] = { 0 }; - mutt_sha1_transform(buf, NULL); - TEST_CHECK_(1, "mutt_sha1_transform(&buf, NULL)"); - } -} diff --git a/test/sha1/mutt_sha1_update.c b/test/sha1/mutt_sha1_update.c deleted file mode 100644 index 82ca75ba5..000000000 --- a/test/sha1/mutt_sha1_update.c +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file - * Test code for mutt_sha1_update() - * - * @authors - * Copyright (C) 2019 Richard Russon - * - * @copyright - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#define TEST_NO_MAIN -#include "acutest.h" -#include "config.h" -#include "mutt/mutt.h" - -void test_mutt_sha1_update(void) -{ - // void mutt_sha1_update(struct Sha1Ctx *sha1ctx, const unsigned char *data, uint32_t len); - - { - unsigned char buf[32] = "apple"; - mutt_sha1_update(NULL, buf, 0); - TEST_CHECK_(1, "mutt_sha1_update(NULL, buf, 0)"); - } - - { - struct Sha1Ctx sha1ctx; - mutt_sha1_init(&sha1ctx); - mutt_sha1_update(&sha1ctx, NULL, 0); - TEST_CHECK_(1, "mutt_sha1_update(&sha1ctx, NULL, 0)"); - } -}