annotate lib/sha1.c @ 37245:135e82dafbea

md5, sha1, sha256, sha512: use openssl routines if available --with-openssl the libcrypto md5, sha1, sha224, sha256, sha384, sha256 routines will be used if available, requiring apps to link @LIB_CRYPTO@ * lib/gl_openssl.h: Provide wrappers for specified openssl hash. * m4/gl-openssl.m4 (gl_CRYPTO_CHECK): New function to lookup libcrypto in the standard system location. * m4/sha1.m4: Call gl_CRYPTO_CHECK() for SHA1. * m4/sha256.m4: Likewise with SHA256. * m4/sha512.m4: Likewise with SHA512. * m4/md5.m4: Likewise with MD5. * m4/gc.m4: Ensure @LIB_CRYPTO@ set for tests. * lib/sha1.h: Include wrappers if HAVE_OPENSSL_SHA1. * lib/sha256.h: Likewise with SHA256. * lib/sha512.h: Likewise with SHA512. * lib/md5.h: Likewise with MD5. * lib/sha1.c: Exlude functionality if HAVE_OPENSSL_SHA1. * lib/sha256.c: Likewise with SHA256. * lib/sha512.c: Likewise with SHA512. * lib/md5.c: Likewise with MD5. * modules/crypto/sha1 (Link:): Add the new optional lib. (Depends-on:): Add dependency on extern-inline. * modules/crypto/sha256: Likewise. * modules/crypto/sha512: Likewise. * modules/crypto/md5: Likewise. * modules/crypto/sha1-tests: Reference the lib here too. * modules/crypto/md5-tests: Likewise. * modules/crypto/gc-des-tests: Likewise. * modules/crypto/gc-hmac-md5-tests: Likewise. * modules/crypto/gc-hmac-sha1-tests: Likewise. * modules/crypto/gc-hmac-sha256-tests: Likewise. * modules/crypto/gc-hmac-sha512-tests: Likewise. * modules/crypto/gc-md5-tests: Likewise. * modules/crypto/gc-pbkdf2-sha1-tests: Likewise. * modules/crypto/gc-sha1-tests: Likewise. * modules/crypto/gc-tests: Likewise. * modules/crypto/hmac-md5-tests: Likewise. * modules/crypto/hmac-sha1-tests: Likewise. * modules/crypto/hmac-sha256-tests: Likewise. * modules/crypto/hmac-sha512-tests: Likewise.
author Pádraig Brady <P@draigBrady.com>
date Sat, 30 Nov 2013 05:19:32 +0000
parents c741bc27922a
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
1 /* sha1.c - Functions to compute SHA1 message digest of files or
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
2 memory blocks according to the NIST specification FIPS-180-1.
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
3
36940
c741bc27922a maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 36874
diff changeset
4 Copyright (C) 2000-2001, 2003-2006, 2008-2013 Free Software Foundation, Inc.
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
5
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
6 This program is free software; you can redistribute it and/or modify it
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9 later version.
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14 GNU General Public License for more details.
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
36057
81b1562e3d8b maint: replace FSF snail-mail addresses with URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 35892
diff changeset
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
18
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19 /* Written by Scott G. Miller
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
20 Credits:
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
21 Robert Klep <robert@ilse.nl> -- Expansion function fix
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
22 */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
23
26993
8aa31e5d3ec4 * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 26478
diff changeset
24 #include <config.h>
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
25
37245
135e82dafbea md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents: 36940
diff changeset
26 #if HAVE_OPENSSL_SHA1
135e82dafbea md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents: 36940
diff changeset
27 # define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
135e82dafbea md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents: 36940
diff changeset
28 #endif
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
29 #include "sha1.h"
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
30
35688
5fe530331127 crypto libraries: use stdalign
Paul Eggert <eggert@cs.ucla.edu>
parents: 33770
diff changeset
31 #include <stdalign.h>
5fe530331127 crypto libraries: use stdalign
Paul Eggert <eggert@cs.ucla.edu>
parents: 33770
diff changeset
32 #include <stdint.h>
31889
59a9e6ad38f8 digests, copy-file: increase the IO buffer size from 4KiB to 32KiB
Pádraig Brady <P@draigBrady.com>
parents: 29487
diff changeset
33 #include <stdlib.h>
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
34 #include <string.h>
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
35
25009
ea3c229c77ea Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents: 24856
diff changeset
36 #if USE_UNLOCKED_IO
ea3c229c77ea Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents: 24856
diff changeset
37 # include "unlocked-io.h"
ea3c229c77ea Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents: 24856
diff changeset
38 #endif
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
39
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
40 #ifdef WORDS_BIGENDIAN
25913
299e806d4eb9 Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents: 25539
diff changeset
41 # define SWAP(n) (n)
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
42 #else
25913
299e806d4eb9 Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents: 25539
diff changeset
43 # define SWAP(n) \
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
44 (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
45 #endif
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
46
31889
59a9e6ad38f8 digests, copy-file: increase the IO buffer size from 4KiB to 32KiB
Pádraig Brady <P@draigBrady.com>
parents: 29487
diff changeset
47 #define BLOCKSIZE 32768
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
48 #if BLOCKSIZE % 64 != 0
25913
299e806d4eb9 Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents: 25539
diff changeset
49 # error "invalid BLOCKSIZE"
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
50 #endif
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
51
37245
135e82dafbea md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents: 36940
diff changeset
52 #if ! HAVE_OPENSSL_SHA1
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
53 /* This array contains the bytes used to pad the buffer to the next
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
54 64-byte boundary. (RFC 1321, 3.1: Step 1) */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
55 static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
56
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
57
26244
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
58 /* Take a pointer to a 160 bit block of data (five 32 bit ints) and
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
59 initialize it to the start constants of the SHA1 algorithm. This
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
60 must be called before using hash in the call to sha1_hash. */
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
61 void
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
62 sha1_init_ctx (struct sha1_ctx *ctx)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
63 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
64 ctx->A = 0x67452301;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
65 ctx->B = 0xefcdab89;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
66 ctx->C = 0x98badcfe;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
67 ctx->D = 0x10325476;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
68 ctx->E = 0xc3d2e1f0;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
69
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
70 ctx->total[0] = ctx->total[1] = 0;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
71 ctx->buflen = 0;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
72 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
73
29347
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
74 /* Copy the 4 byte value from v into the memory location pointed to by *cp,
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
75 If your architecture allows unaligned access this is equivalent to
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
76 * (uint32_t *) cp = v */
36874
024e48bc0b1d arctwo, md4, md5, sha1, sha256, sha512: no 'static inline'
Paul Eggert <eggert@cs.ucla.edu>
parents: 36551
diff changeset
77 static void
29347
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
78 set_uint32 (char *cp, uint32_t v)
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
79 {
29353
f9475e9874b4 Prefer "sizeof v" over the equivalent "4".
Jim Meyering <meyering@redhat.com>
parents: 29351
diff changeset
80 memcpy (cp, &v, sizeof v);
29347
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
81 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
82
29347
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
83 /* Put result from CTX in first 20 bytes following RESBUF. The result
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
84 must be in little endian byte order. */
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
85 void *
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
86 sha1_read_ctx (const struct sha1_ctx *ctx, void *resbuf)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
87 {
29347
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
88 char *r = resbuf;
29357
e7c097072524 Use "sizeof VAR", rather than a literal "4".
Jim Meyering <meyering@redhat.com>
parents: 29353
diff changeset
89 set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
e7c097072524 Use "sizeof VAR", rather than a literal "4".
Jim Meyering <meyering@redhat.com>
parents: 29353
diff changeset
90 set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B));
e7c097072524 Use "sizeof VAR", rather than a literal "4".
Jim Meyering <meyering@redhat.com>
parents: 29353
diff changeset
91 set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C));
e7c097072524 Use "sizeof VAR", rather than a literal "4".
Jim Meyering <meyering@redhat.com>
parents: 29353
diff changeset
92 set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D));
e7c097072524 Use "sizeof VAR", rather than a literal "4".
Jim Meyering <meyering@redhat.com>
parents: 29353
diff changeset
93 set_uint32 (r + 4 * sizeof ctx->E, SWAP (ctx->E));
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
94
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
95 return resbuf;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
96 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
97
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
98 /* Process the remaining bytes in the internal buffer and the usual
29347
49c64d003ba6 sha1: remove the result buffer alignment constraint
Peter Palfrader <weasel@debian.org>
parents: 26993
diff changeset
99 prolog according to the standard and write the result to RESBUF. */
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
100 void *
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
101 sha1_finish_ctx (struct sha1_ctx *ctx, void *resbuf)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
102 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
103 /* Take yet unprocessed bytes into account. */
26072
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
104 uint32_t bytes = ctx->buflen;
26244
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
105 size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
106
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
107 /* Now count remaining bytes. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
108 ctx->total[0] += bytes;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
109 if (ctx->total[0] < bytes)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
110 ++ctx->total[1];
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
111
26244
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
112 /* Put the 64-bit file length in *bits* at the end of the buffer. */
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
113 ctx->buffer[size - 2] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
114 ctx->buffer[size - 1] = SWAP (ctx->total[0] << 3);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
115
26244
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
116 memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
117
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
118 /* Process last bytes. */
26244
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
119 sha1_process_block (ctx->buffer, size * 4, ctx);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
120
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
121 return sha1_read_ctx (ctx, resbuf);
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
122 }
37245
135e82dafbea md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents: 36940
diff changeset
123 #endif
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
124
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
125 /* Compute SHA1 message digest for bytes read from STREAM. The
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
126 resulting message digest number will be written into the 16 bytes
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
127 beginning at RESBLOCK. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
128 int
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
129 sha1_stream (FILE *stream, void *resblock)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
130 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
131 struct sha1_ctx ctx;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
132 size_t sum;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
133
31889
59a9e6ad38f8 digests, copy-file: increase the IO buffer size from 4KiB to 32KiB
Pádraig Brady <P@draigBrady.com>
parents: 29487
diff changeset
134 char *buffer = malloc (BLOCKSIZE + 72);
59a9e6ad38f8 digests, copy-file: increase the IO buffer size from 4KiB to 32KiB
Pádraig Brady <P@draigBrady.com>
parents: 29487
diff changeset
135 if (!buffer)
59a9e6ad38f8 digests, copy-file: increase the IO buffer size from 4KiB to 32KiB
Pádraig Brady <P@draigBrady.com>
parents: 29487
diff changeset
136 return 1;
59a9e6ad38f8 digests, copy-file: increase the IO buffer size from 4KiB to 32KiB
Pádraig Brady <P@draigBrady.com>
parents: 29487
diff changeset
137
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
138 /* Initialize the computation context. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
139 sha1_init_ctx (&ctx);
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
140
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
141 /* Iterate over full file contents. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
142 while (1)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
143 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
144 /* We read the file in blocks of BLOCKSIZE bytes. One call of the
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
145 computation function processes the whole buffer so that with the
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
146 next round of the loop another block can be read. */
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
147 size_t n;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
148 sum = 0;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
149
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
150 /* Read block. Take care for partial reads. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
151 while (1)
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
152 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
153 n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
154
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
155 sum += n;
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
156
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
157 if (sum == BLOCKSIZE)
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
158 break;
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
159
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
160 if (n == 0)
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
161 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
162 /* Check for the error flag IFF N == 0, so that we don't
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
163 exit the loop after a partial read due to e.g., EAGAIN
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
164 or EWOULDBLOCK. */
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
165 if (ferror (stream))
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
166 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
167 free (buffer);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
168 return 1;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
169 }
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
170 goto process_partial_block;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
171 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
172
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
173 /* We've read at least one byte, so ignore errors. But always
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
174 check for EOF, since feof may be true even though N > 0.
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
175 Otherwise, we could end up calling fread after EOF. */
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
176 if (feof (stream))
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
177 goto process_partial_block;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
178 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
179
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
180 /* Process buffer with BLOCKSIZE bytes. Note that
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
181 BLOCKSIZE % 64 == 0
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
182 */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
183 sha1_process_block (buffer, BLOCKSIZE, &ctx);
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
184 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
185
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
186 process_partial_block:;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
187
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
188 /* Process any remaining bytes. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
189 if (sum > 0)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
190 sha1_process_bytes (buffer, sum, &ctx);
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
191
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
192 /* Construct result in desired memory. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
193 sha1_finish_ctx (&ctx, resblock);
31889
59a9e6ad38f8 digests, copy-file: increase the IO buffer size from 4KiB to 32KiB
Pádraig Brady <P@draigBrady.com>
parents: 29487
diff changeset
194 free (buffer);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
195 return 0;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
196 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
197
37245
135e82dafbea md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents: 36940
diff changeset
198 #if ! HAVE_OPENSSL_SHA1
26478
e0a5d2c96f89 sha1.c (sha1_buffer): Correct comment: s/MD5/SHA1/. From James Lemley.
Jim Meyering <jim@meyering.net>
parents: 26475
diff changeset
199 /* Compute SHA1 message digest for LEN bytes beginning at BUFFER. The
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
200 result is always in little endian byte order, so that a byte-wise
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
201 output yields to the wanted ASCII representation of the message
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
202 digest. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
203 void *
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
204 sha1_buffer (const char *buffer, size_t len, void *resblock)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
205 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
206 struct sha1_ctx ctx;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
207
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
208 /* Initialize the computation context. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
209 sha1_init_ctx (&ctx);
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
210
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
211 /* Process whole buffer but last len % 64 bytes. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
212 sha1_process_bytes (buffer, len, &ctx);
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
213
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
214 /* Put result in desired memory area. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
215 return sha1_finish_ctx (&ctx, resblock);
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
216 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
217
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
218 void
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
219 sha1_process_bytes (const void *buffer, size_t len, struct sha1_ctx *ctx)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
220 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
221 /* When we already have some bits in our internal buffer concatenate
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
222 both inputs first. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
223 if (ctx->buflen != 0)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
224 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
225 size_t left_over = ctx->buflen;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
226 size_t add = 128 - left_over > len ? len : 128 - left_over;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
227
26244
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
228 memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
229 ctx->buflen += add;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
230
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
231 if (ctx->buflen > 64)
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
232 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
233 sha1_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
29487
6852b588fd27 Undo last change.
Jim Meyering <meyering@redhat.com>
parents: 29486
diff changeset
234
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
235 ctx->buflen &= 63;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
236 /* The regions in the following copy operation cannot overlap. */
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
237 memcpy (ctx->buffer,
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
238 &((char *) ctx->buffer)[(left_over + add) & ~63],
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
239 ctx->buflen);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
240 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
241
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
242 buffer = (const char *) buffer + add;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
243 len -= add;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
244 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
245
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
246 /* Process available complete blocks. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
247 if (len >= 64)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
248 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
249 #if !_STRING_ARCH_unaligned
35688
5fe530331127 crypto libraries: use stdalign
Paul Eggert <eggert@cs.ucla.edu>
parents: 33770
diff changeset
250 # define UNALIGNED_P(p) ((uintptr_t) (p) % alignof (uint32_t) != 0)
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
251 if (UNALIGNED_P (buffer))
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
252 while (len > 64)
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
253 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
254 sha1_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
255 buffer = (const char *) buffer + 64;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
256 len -= 64;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
257 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
258 else
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
259 #endif
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
260 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
261 sha1_process_block (buffer, len & ~63, ctx);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
262 buffer = (const char *) buffer + (len & ~63);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
263 len &= 63;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
264 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
265 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
266
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
267 /* Move remaining bytes in internal buffer. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
268 if (len > 0)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
269 {
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
270 size_t left_over = ctx->buflen;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
271
26244
3655e550b688 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 26231
diff changeset
272 memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
273 left_over += len;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
274 if (left_over >= 64)
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
275 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
276 sha1_process_block (ctx->buffer, 64, ctx);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
277 left_over -= 64;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
278 memcpy (ctx->buffer, &ctx->buffer[16], left_over);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
279 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
280 ctx->buflen = left_over;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
281 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
282 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
283
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
284 /* --- Code below is the primary difference between md5.c and sha1.c --- */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
285
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
286 /* SHA1 round constants */
26475
61306c7a6237 2006-05-10 Paul Eggert <eggert@cs.ucla.edu>
Simon Josefsson <simon@josefsson.org>
parents: 26244
diff changeset
287 #define K1 0x5a827999
61306c7a6237 2006-05-10 Paul Eggert <eggert@cs.ucla.edu>
Simon Josefsson <simon@josefsson.org>
parents: 26244
diff changeset
288 #define K2 0x6ed9eba1
61306c7a6237 2006-05-10 Paul Eggert <eggert@cs.ucla.edu>
Simon Josefsson <simon@josefsson.org>
parents: 26244
diff changeset
289 #define K3 0x8f1bbcdc
61306c7a6237 2006-05-10 Paul Eggert <eggert@cs.ucla.edu>
Simon Josefsson <simon@josefsson.org>
parents: 26244
diff changeset
290 #define K4 0xca62c1d6
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
291
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
292 /* Round functions. Note that F2 is the same as F4. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
293 #define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
294 #define F2(B,C,D) (B ^ C ^ D)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
295 #define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
296 #define F4(B,C,D) (B ^ C ^ D)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
297
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
298 /* Process LEN bytes of BUFFER, accumulating context into CTX.
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
299 It is assumed that LEN % 64 == 0.
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
300 Most of this code comes from GnuPG's cipher/sha1.c. */
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
301
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
302 void
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
303 sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
304 {
26072
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
305 const uint32_t *words = buffer;
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
306 size_t nwords = len / sizeof (uint32_t);
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
307 const uint32_t *endp = words + nwords;
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
308 uint32_t x[16];
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
309 uint32_t a = ctx->A;
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
310 uint32_t b = ctx->B;
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
311 uint32_t c = ctx->C;
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
312 uint32_t d = ctx->D;
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
313 uint32_t e = ctx->E;
36551
e44534a69277 crypto: fix bug in large buffer handling
Paul Eggert <eggert@cs.ucla.edu>
parents: 36057
diff changeset
314 uint32_t lolen = len;
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
315
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
316 /* First increment the byte count. RFC 1321 specifies the possible
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
317 length of the file up to 2^64 bits. Here we only compute the
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
318 number of bytes. Do a double word increment. */
36551
e44534a69277 crypto: fix bug in large buffer handling
Paul Eggert <eggert@cs.ucla.edu>
parents: 36057
diff changeset
319 ctx->total[0] += lolen;
e44534a69277 crypto: fix bug in large buffer handling
Paul Eggert <eggert@cs.ucla.edu>
parents: 36057
diff changeset
320 ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen);
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
321
26475
61306c7a6237 2006-05-10 Paul Eggert <eggert@cs.ucla.edu>
Simon Josefsson <simon@josefsson.org>
parents: 26244
diff changeset
322 #define rol(x, n) (((x) << (n)) | ((uint32_t) (x) >> (32 - (n))))
25913
299e806d4eb9 Merge glibc and coreutils changes into gnulib, plus a few
Paul Eggert <eggert@cs.ucla.edu>
parents: 25539
diff changeset
323
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
324 #define M(I) ( tm = x[I&0x0f] ^ x[(I-14)&0x0f] \
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
325 ^ x[(I-8)&0x0f] ^ x[(I-3)&0x0f] \
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
326 , (x[I&0x0f] = rol(tm, 1)) )
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
327
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
328 #define R(A,B,C,D,E,F,K,M) do { E += rol( A, 5 ) \
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
329 + F( B, C, D ) \
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
330 + K \
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
331 + M; \
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
332 B = rol( B, 30 ); \
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
333 } while(0)
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
334
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
335 while (words < endp)
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
336 {
26072
56e6483a97ab Separate sha1 from md5. Use stdint.h in both modules.
Simon Josefsson <simon@josefsson.org>
parents: 25913
diff changeset
337 uint32_t tm;
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
338 int t;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
339 for (t = 0; t < 16; t++)
32112
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
340 {
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
341 x[t] = SWAP (*words);
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
342 words++;
dc7644a1c024 Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 31889
diff changeset
343 }
24856
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
344
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
345 R( a, b, c, d, e, F1, K1, x[ 0] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
346 R( e, a, b, c, d, F1, K1, x[ 1] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
347 R( d, e, a, b, c, F1, K1, x[ 2] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
348 R( c, d, e, a, b, F1, K1, x[ 3] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
349 R( b, c, d, e, a, F1, K1, x[ 4] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
350 R( a, b, c, d, e, F1, K1, x[ 5] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
351 R( e, a, b, c, d, F1, K1, x[ 6] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
352 R( d, e, a, b, c, F1, K1, x[ 7] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
353 R( c, d, e, a, b, F1, K1, x[ 8] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
354 R( b, c, d, e, a, F1, K1, x[ 9] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
355 R( a, b, c, d, e, F1, K1, x[10] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
356 R( e, a, b, c, d, F1, K1, x[11] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
357 R( d, e, a, b, c, F1, K1, x[12] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
358 R( c, d, e, a, b, F1, K1, x[13] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
359 R( b, c, d, e, a, F1, K1, x[14] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
360 R( a, b, c, d, e, F1, K1, x[15] );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
361 R( e, a, b, c, d, F1, K1, M(16) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
362 R( d, e, a, b, c, F1, K1, M(17) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
363 R( c, d, e, a, b, F1, K1, M(18) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
364 R( b, c, d, e, a, F1, K1, M(19) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
365 R( a, b, c, d, e, F2, K2, M(20) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
366 R( e, a, b, c, d, F2, K2, M(21) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
367 R( d, e, a, b, c, F2, K2, M(22) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
368 R( c, d, e, a, b, F2, K2, M(23) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
369 R( b, c, d, e, a, F2, K2, M(24) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
370 R( a, b, c, d, e, F2, K2, M(25) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
371 R( e, a, b, c, d, F2, K2, M(26) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
372 R( d, e, a, b, c, F2, K2, M(27) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
373 R( c, d, e, a, b, F2, K2, M(28) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
374 R( b, c, d, e, a, F2, K2, M(29) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
375 R( a, b, c, d, e, F2, K2, M(30) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
376 R( e, a, b, c, d, F2, K2, M(31) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
377 R( d, e, a, b, c, F2, K2, M(32) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
378 R( c, d, e, a, b, F2, K2, M(33) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
379 R( b, c, d, e, a, F2, K2, M(34) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
380 R( a, b, c, d, e, F2, K2, M(35) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
381 R( e, a, b, c, d, F2, K2, M(36) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
382 R( d, e, a, b, c, F2, K2, M(37) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
383 R( c, d, e, a, b, F2, K2, M(38) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
384 R( b, c, d, e, a, F2, K2, M(39) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
385 R( a, b, c, d, e, F3, K3, M(40) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
386 R( e, a, b, c, d, F3, K3, M(41) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
387 R( d, e, a, b, c, F3, K3, M(42) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
388 R( c, d, e, a, b, F3, K3, M(43) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
389 R( b, c, d, e, a, F3, K3, M(44) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
390 R( a, b, c, d, e, F3, K3, M(45) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
391 R( e, a, b, c, d, F3, K3, M(46) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
392 R( d, e, a, b, c, F3, K3, M(47) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
393 R( c, d, e, a, b, F3, K3, M(48) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
394 R( b, c, d, e, a, F3, K3, M(49) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
395 R( a, b, c, d, e, F3, K3, M(50) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
396 R( e, a, b, c, d, F3, K3, M(51) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
397 R( d, e, a, b, c, F3, K3, M(52) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
398 R( c, d, e, a, b, F3, K3, M(53) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
399 R( b, c, d, e, a, F3, K3, M(54) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
400 R( a, b, c, d, e, F3, K3, M(55) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
401 R( e, a, b, c, d, F3, K3, M(56) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
402 R( d, e, a, b, c, F3, K3, M(57) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
403 R( c, d, e, a, b, F3, K3, M(58) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
404 R( b, c, d, e, a, F3, K3, M(59) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
405 R( a, b, c, d, e, F4, K4, M(60) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
406 R( e, a, b, c, d, F4, K4, M(61) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
407 R( d, e, a, b, c, F4, K4, M(62) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
408 R( c, d, e, a, b, F4, K4, M(63) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
409 R( b, c, d, e, a, F4, K4, M(64) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
410 R( a, b, c, d, e, F4, K4, M(65) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
411 R( e, a, b, c, d, F4, K4, M(66) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
412 R( d, e, a, b, c, F4, K4, M(67) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
413 R( c, d, e, a, b, F4, K4, M(68) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
414 R( b, c, d, e, a, F4, K4, M(69) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
415 R( a, b, c, d, e, F4, K4, M(70) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
416 R( e, a, b, c, d, F4, K4, M(71) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
417 R( d, e, a, b, c, F4, K4, M(72) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
418 R( c, d, e, a, b, F4, K4, M(73) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
419 R( b, c, d, e, a, F4, K4, M(74) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
420 R( a, b, c, d, e, F4, K4, M(75) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
421 R( e, a, b, c, d, F4, K4, M(76) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
422 R( d, e, a, b, c, F4, K4, M(77) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
423 R( c, d, e, a, b, F4, K4, M(78) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
424 R( b, c, d, e, a, F4, K4, M(79) );
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
425
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
426 a = ctx->A += a;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
427 b = ctx->B += b;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
428 c = ctx->C += c;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
429 d = ctx->D += d;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
430 e = ctx->E += e;
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
431 }
d1bd730b77d7 Add uint32_t.m4, uintptr_t.m4, and finish renaming sha->sha1.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
432 }
37245
135e82dafbea md5, sha1, sha256, sha512: use openssl routines if available
Pádraig Brady <P@draigBrady.com>
parents: 36940
diff changeset
433 #endif