annotate src/fftw-3.3.3/kernel/md5.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 37bf6b4a2645
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21 /*
Chris@10 22 independent implementation of Ron Rivest's MD5 message-digest
Chris@10 23 algorithm, based on rfc 1321.
Chris@10 24
Chris@10 25 Optimized for small code size, not speed. Works as long as
Chris@10 26 sizeof(md5uint) >= 4.
Chris@10 27 */
Chris@10 28
Chris@10 29 #include "ifftw.h"
Chris@10 30
Chris@10 31 /* sintab[i] = 4294967296.0 * abs(sin((double)(i + 1))) */
Chris@10 32 static const md5uint sintab[64] = {
Chris@10 33 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
Chris@10 34 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
Chris@10 35 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
Chris@10 36 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
Chris@10 37 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
Chris@10 38 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
Chris@10 39 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
Chris@10 40 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
Chris@10 41 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
Chris@10 42 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
Chris@10 43 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
Chris@10 44 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
Chris@10 45 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
Chris@10 46 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
Chris@10 47 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
Chris@10 48 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391
Chris@10 49 };
Chris@10 50
Chris@10 51 /* see rfc 1321 section 3.4 */
Chris@10 52 static const struct roundtab {
Chris@10 53 char k;
Chris@10 54 char s;
Chris@10 55 } roundtab[64] = {
Chris@10 56 { 0, 7}, { 1, 12}, { 2, 17}, { 3, 22},
Chris@10 57 { 4, 7}, { 5, 12}, { 6, 17}, { 7, 22},
Chris@10 58 { 8, 7}, { 9, 12}, { 10, 17}, { 11, 22},
Chris@10 59 { 12, 7}, { 13, 12}, { 14, 17}, { 15, 22},
Chris@10 60 { 1, 5}, { 6, 9}, { 11, 14}, { 0, 20},
Chris@10 61 { 5, 5}, { 10, 9}, { 15, 14}, { 4, 20},
Chris@10 62 { 9, 5}, { 14, 9}, { 3, 14}, { 8, 20},
Chris@10 63 { 13, 5}, { 2, 9}, { 7, 14}, { 12, 20},
Chris@10 64 { 5, 4}, { 8, 11}, { 11, 16}, { 14, 23},
Chris@10 65 { 1, 4}, { 4, 11}, { 7, 16}, { 10, 23},
Chris@10 66 { 13, 4}, { 0, 11}, { 3, 16}, { 6, 23},
Chris@10 67 { 9, 4}, { 12, 11}, { 15, 16}, { 2, 23},
Chris@10 68 { 0, 6}, { 7, 10}, { 14, 15}, { 5, 21},
Chris@10 69 { 12, 6}, { 3, 10}, { 10, 15}, { 1, 21},
Chris@10 70 { 8, 6}, { 15, 10}, { 6, 15}, { 13, 21},
Chris@10 71 { 4, 6}, { 11, 10}, { 2, 15}, { 9, 21}
Chris@10 72 };
Chris@10 73
Chris@10 74 #define rol(a, s) ((a << (int)(s)) | (a >> (32 - (int)(s))))
Chris@10 75
Chris@10 76 static void doblock(md5sig state, const unsigned char *data)
Chris@10 77 {
Chris@10 78 md5uint a, b, c, d, t, x[16];
Chris@10 79 const md5uint msk = (md5uint)0xffffffffUL;
Chris@10 80 int i;
Chris@10 81
Chris@10 82 /* encode input bytes into md5uint */
Chris@10 83 for (i = 0; i < 16; ++i) {
Chris@10 84 const unsigned char *p = data + 4 * i;
Chris@10 85 x[i] = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
Chris@10 86 }
Chris@10 87
Chris@10 88 a = state[0]; b = state[1]; c = state[2]; d = state[3];
Chris@10 89 for (i = 0; i < 64; ++i) {
Chris@10 90 const struct roundtab *p = roundtab + i;
Chris@10 91 switch (i >> 4) {
Chris@10 92 case 0: a += (b & c) | (~b & d); break;
Chris@10 93 case 1: a += (b & d) | (c & ~d); break;
Chris@10 94 case 2: a += b ^ c ^ d; break;
Chris@10 95 case 3: a += c ^ (b | ~d); break;
Chris@10 96 }
Chris@10 97 a += sintab[i];
Chris@10 98 a += x[(int)(p->k)];
Chris@10 99 a &= msk;
Chris@10 100 t = b + rol(a, p->s);
Chris@10 101 a = d; d = c; c = b; b = t;
Chris@10 102 }
Chris@10 103 state[0] = (state[0] + a) & msk;
Chris@10 104 state[1] = (state[1] + b) & msk;
Chris@10 105 state[2] = (state[2] + c) & msk;
Chris@10 106 state[3] = (state[3] + d) & msk;
Chris@10 107 }
Chris@10 108
Chris@10 109
Chris@10 110 void X(md5begin)(md5 *p)
Chris@10 111 {
Chris@10 112 p->s[0] = 0x67452301;
Chris@10 113 p->s[1] = 0xefcdab89;
Chris@10 114 p->s[2] = 0x98badcfe;
Chris@10 115 p->s[3] = 0x10325476;
Chris@10 116 p->l = 0;
Chris@10 117 }
Chris@10 118
Chris@10 119 void X(md5putc)(md5 *p, unsigned char c)
Chris@10 120 {
Chris@10 121 p->c[p->l % 64] = c;
Chris@10 122 if (((++p->l) % 64) == 0) doblock(p->s, p->c);
Chris@10 123 }
Chris@10 124
Chris@10 125 void X(md5end)(md5 *p)
Chris@10 126 {
Chris@10 127 unsigned l, i;
Chris@10 128
Chris@10 129 l = 8 * p->l; /* length before padding, in bits */
Chris@10 130
Chris@10 131 /* rfc 1321 section 3.1: padding */
Chris@10 132 X(md5putc)(p, 0x80);
Chris@10 133 while ((p->l % 64) != 56) X(md5putc)(p, 0x00);
Chris@10 134
Chris@10 135 /* rfc 1321 section 3.2: length (little endian) */
Chris@10 136 for (i = 0; i < 8; ++i) {
Chris@10 137 X(md5putc)(p, l & 0xFF);
Chris@10 138 l = l >> 8;
Chris@10 139 }
Chris@10 140
Chris@10 141 /* Now p->l % 64 == 0 and signature is in p->s */
Chris@10 142 }