QTfrontend/sha1.cpp
author unc0rr
Fri, 16 Dec 2005 20:57:14 +0000
changeset 27 c374fe590272
parent 21 dff476dcaaa3
child 33 d6363050cad0
permissions -rw-r--r--
- improve land generation - don't use themes with no objects
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     1
/*
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     2
 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     3
 * All rights reserved.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     4
 *
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     5
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     6
 *
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     7
 * Redistribution and use in source and binary forms, with or without
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     8
 * modification, are permitted provided that the following conditions
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
     9
 * are met:
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    10
 * 1. Redistributions of source code must retain the above copyright
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    11
 *    notice, this list of conditions and the following disclaimer.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    12
 * 2. Redistributions in binary form must reproduce the above copyright
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    13
 *    notice, this list of conditions and the following disclaimer in the
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    14
 *    documentation and/or other materials provided with the distribution.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    15
 * 3. Neither the name of the project nor the names of its contributors
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    16
 *    may be used to endorse or promote products derived from this software
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    17
 *    without specific prior written permission.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    18
 *
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    20
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    22
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    23
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    24
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    26
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    27
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    28
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    29
 * SUCH DAMAGE.
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    30
 */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    31
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    32
/*
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    33
 * FIPS pub 180-1: Secure Hash Algorithm (SHA-1)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    34
 * based on: http://csrc.nist.gov/fips/fip180-1.txt
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    35
 * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    36
 */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    37
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    38
#include "sha1.h"
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    39
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    40
/* constant table */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    41
static quint32 _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    42
#define	K(t)	_K[(t) / 20]
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    43
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    44
#define	F0(b, c, d)	(((b) & (c)) | ((~(b)) & (d)))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    45
#define	F1(b, c, d)	(((b) ^ (c)) ^ (d))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    46
#define	F2(b, c, d)	(((b) & (c)) | ((b) & (d)) | ((c) & (d)))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    47
#define	F3(b, c, d)	(((b) ^ (c)) ^ (d))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    48
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    49
#define	S(n, x)		(((x) << (n)) | ((x) >> (32 - n)))
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    50
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    51
#define	H(n)	(ctxt->h.b32[(n)])
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    52
#define	COUNT	(ctxt->count)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    53
#define	BCOUNT	(ctxt->c.b64[0] / 8)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    54
#define	W(n)	(ctxt->m.b32[(n)])
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    55
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    56
#define	PUTBYTE(x)	{ \
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    57
	ctxt->m.b8[(COUNT % 64)] = (x);		\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    58
	COUNT++;				\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    59
	COUNT %= 64;				\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    60
	ctxt->c.b64[0] += 8;			\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    61
	if (COUNT % 64 == 0)			\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    62
		sha1_step(ctxt);		\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    63
     }
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    64
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    65
#define	PUTPAD(x)	{ \
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    66
	ctxt->m.b8[(COUNT % 64)] = (x);		\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    67
	COUNT++;				\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    68
	COUNT %= 64;				\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    69
	if (COUNT % 64 == 0)			\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    70
		sha1_step(ctxt);		\
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    71
     }
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    72
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    73
static void sha1_step(struct sha1_ctxt *);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    74
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    75
static void
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    76
sha1_step(struct sha1_ctxt *ctxt)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    77
{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    78
	quint32	a, b, c, d, e;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    79
	size_t t, s;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    80
	quint32	tmp;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    81
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    82
	a = H(0); b = H(1); c = H(2); d = H(3); e = H(4);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    83
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    84
	for (t = 0; t < 20; t++) {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    85
		s = t & 0x0f;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    86
		if (t >= 16) {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    87
			W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    88
		}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    89
		tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    90
		e = d; d = c; c = S(30, b); b = a; a = tmp;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    91
	}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    92
	for (t = 20; t < 40; t++) {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    93
		s = t & 0x0f;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    94
		W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    95
		tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    96
		e = d; d = c; c = S(30, b); b = a; a = tmp;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    97
	}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    98
	for (t = 40; t < 60; t++) {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
    99
		s = t & 0x0f;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   100
		W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   101
		tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   102
		e = d; d = c; c = S(30, b); b = a; a = tmp;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   103
	}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   104
	for (t = 60; t < 80; t++) {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   105
		s = t & 0x0f;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   106
		W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   107
		tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   108
		e = d; d = c; c = S(30, b); b = a; a = tmp;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   109
	}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   110
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   111
	H(0) = H(0) + a;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   112
	H(1) = H(1) + b;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   113
	H(2) = H(2) + c;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   114
	H(3) = H(3) + d;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   115
	H(4) = H(4) + e;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   116
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   117
	qMemSet(&ctxt->m.b8[0], 0, 64);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   118
}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   119
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   120
/*------------------------------------------------------------*/
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   121
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   122
void sha1_init(struct sha1_ctxt *ctxt)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   123
{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   124
	qMemSet(ctxt, 0, sizeof(struct sha1_ctxt));
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   125
	H(0) = 0x67452301;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   126
	H(1) = 0xefcdab89;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   127
	H(2) = 0x98badcfe;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   128
	H(3) = 0x10325476;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   129
	H(4) = 0xc3d2e1f0;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   130
}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   131
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   132
void sha1_pad(struct sha1_ctxt *ctxt)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   133
{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   134
	size_t padlen;		/*pad length in bytes*/
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   135
	size_t padstart;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   136
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   137
	PUTPAD(0x80);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   138
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   139
	padstart = COUNT % 64;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   140
	padlen = 64 - padstart;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   141
	if (padlen < 8) {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   142
		qMemSet(&ctxt->m.b8[padstart], 0, padlen);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   143
		COUNT += padlen;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   144
		COUNT %= 64;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   145
		sha1_step(ctxt);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   146
		padstart = COUNT % 64;	/* should be 0 */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   147
		padlen = 64 - padstart;	/* should be 64 */
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   148
	}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   149
	qMemSet(&ctxt->m.b8[padstart], 0, padlen - 8);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   150
	COUNT += (padlen - 8);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   151
	COUNT %= 64;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   152
	PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   153
	PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   154
	PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   155
	PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   156
}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   157
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   158
void sha1_loop(struct sha1_ctxt *ctxt, const quint8 *input, size_t len)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   159
{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   160
	size_t gaplen;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   161
	size_t gapstart;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   162
	size_t off;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   163
	size_t copysiz;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   164
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   165
	off = 0;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   166
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   167
	while (off < len) {
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   168
		gapstart = COUNT % 64;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   169
		gaplen = 64 - gapstart;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   170
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   171
		copysiz = (gaplen < len - off) ? gaplen : len - off;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   172
		qMemCopy(&ctxt->m.b8[gapstart], &input[off], copysiz);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   173
		COUNT += copysiz;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   174
		COUNT %= 64;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   175
		ctxt->c.b64[0] += copysiz * 8;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   176
		if (COUNT % 64 == 0)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   177
			sha1_step(ctxt);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   178
		off += copysiz;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   179
	}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   180
}
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   181
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   182
void sha1_result(struct sha1_ctxt *ctxt, caddr_t digest0)
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   183
{
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   184
	quint8 *digest;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   185
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   186
	digest = (quint8 *)digest0;
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   187
	sha1_pad(ctxt);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   188
	qMemCopy(digest, &ctxt->h.b8[0], 20);
dff476dcaaa3 - Many improvements to frontend
unc0rr
parents:
diff changeset
   189
}