2000-07-04 18:24:11 +00:00
|
|
|
/* Functions to compute MD5 message digest of files or memory blocks.
|
1996-12-15 02:15:29 +00:00
|
|
|
according to the definition of MD5 in RFC 1321 from April 1992.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 1995-2023 Free Software Foundation, Inc.
|
1996-12-15 02:15:29 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1996-12-15 02:15:29 +00:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1996-12-15 02:15:29 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
1996-12-15 02:15:29 +00:00
|
|
|
|
|
|
|
/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#if STDC_HEADERS || defined _LIBC
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <string.h>
|
|
|
|
#else
|
|
|
|
# ifndef HAVE_MEMCPY
|
2005-05-02 20:15:34 +00:00
|
|
|
# define memcpy(d, s, n) (bcopy ((s), (d), (n)), (d))
|
1996-12-15 02:15:29 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "md5.h"
|
|
|
|
|
|
|
|
#ifdef _LIBC
|
|
|
|
# include <endian.h>
|
|
|
|
# if __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
# define WORDS_BIGENDIAN 1
|
|
|
|
# endif
|
Update.
1997-06-03 23:42 Ulrich Drepper <drepper@cygnus.com>
* elf/dl-support.c: Define and initialize _dl_verbose used in
dl-machine.h.
* io/ftw.c: Expand stat/lstat calls.
* manual/intro.texi: Also refer to ISO 9945.
Update info about SVID.
Add description for XPG.
* md5-crypt/md5-crypt.c: Namespace cleanups.
* md5-crypt/md5.c: Likewise.
* md5-crypt/md5.h: Likewise.
* sysdeps/generic/crypt-entry.c: Likewise.
* posix/unistd.h (_POSIX2_C_VERSION): Set to 199209L.
* stdlib/fmtmsg.h: Declare addseverity only if __USE_SVID is
defined.
* sunrpc/rpc_scan.c (findkind): Declare `token' as const.
* sunrpc/rpc_util.c (toktostr): Declare `token' as const.
* time/Makefile: Make tzselect dependen of config.make.
1997-06-01 15:01 Miles Bader <miles@gnu.ai.mit.edu>
* manual/string.texi (String and Array Utilities): Add `Argz and
Envz Vectors' to the menu.
(Argz and Envz Vectors, Argz Functions, Envz Functions): New nodes.
1997-05-31 20:59 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* login/Makefile (utmpd-routines): Add utmpd.
(extra-objs): Add utmpd objects to get dependencies.
(distribute): Add sources for utmpd.
(subdir-dirs): Define.
1997-06-02 16:28 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/wordsize-32/inttypes.h: Include features.h and use
__CONCAT instead of defined __CONCAT__ ourself.
* sysdeps/wordsize-64/inttypes.h: Likewise.
1997-06-01 19:11 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/wordsize-64/inttypes.h (INTMAX_C): Use `l' suffix, not
`ll'.
(PRIdFAST, PRIoFAST, PRIxFAST, PRIuFAST, SCNdFAST, SCNiFAST,
SCNoFAST, SCNxFAST): Correct format specifiers.
1997-06-02 04:23 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/syscalls.list: Make fchdir weak alias for __fchdir.
1997-06-01 19:17 Ulrich Drepper <drepper@cygnus.com>
* md5-crypt/Makefile: Correct libmd5crypt file to really generate
DES free libcrypt.
* md5-crypt/onlymd5-entry.c: New file. Wrapper around
sysdeps/generic/crypt-entry.c.
1997-06-01 12:48 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/sysv/linux/alpha/gnu/types.h (__fd_mask): Change
type to `unsigned long int'.
Patch by Richard Henderson <richard@twiddle.rth.home>.
1997-05-30 17:34 Andreas Jaeger <aj@arthur.rhein-neckar.de>
* sysdeps/generic/bb_init_func.c (__bb_init_func): Use ISO C
declaration style.
* nss/nss_files/files-hosts.c: Delete inclusion of
"../resolv/mapv4v6hostent.h".
1997-06-03 21:53:09 +00:00
|
|
|
/* We need to keep the namespace clean so define the MD5 function
|
1999-10-25 20:18:27 +00:00
|
|
|
protected using leading __ . */
|
Update.
1997-06-03 23:42 Ulrich Drepper <drepper@cygnus.com>
* elf/dl-support.c: Define and initialize _dl_verbose used in
dl-machine.h.
* io/ftw.c: Expand stat/lstat calls.
* manual/intro.texi: Also refer to ISO 9945.
Update info about SVID.
Add description for XPG.
* md5-crypt/md5-crypt.c: Namespace cleanups.
* md5-crypt/md5.c: Likewise.
* md5-crypt/md5.h: Likewise.
* sysdeps/generic/crypt-entry.c: Likewise.
* posix/unistd.h (_POSIX2_C_VERSION): Set to 199209L.
* stdlib/fmtmsg.h: Declare addseverity only if __USE_SVID is
defined.
* sunrpc/rpc_scan.c (findkind): Declare `token' as const.
* sunrpc/rpc_util.c (toktostr): Declare `token' as const.
* time/Makefile: Make tzselect dependen of config.make.
1997-06-01 15:01 Miles Bader <miles@gnu.ai.mit.edu>
* manual/string.texi (String and Array Utilities): Add `Argz and
Envz Vectors' to the menu.
(Argz and Envz Vectors, Argz Functions, Envz Functions): New nodes.
1997-05-31 20:59 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* login/Makefile (utmpd-routines): Add utmpd.
(extra-objs): Add utmpd objects to get dependencies.
(distribute): Add sources for utmpd.
(subdir-dirs): Define.
1997-06-02 16:28 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/wordsize-32/inttypes.h: Include features.h and use
__CONCAT instead of defined __CONCAT__ ourself.
* sysdeps/wordsize-64/inttypes.h: Likewise.
1997-06-01 19:11 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/wordsize-64/inttypes.h (INTMAX_C): Use `l' suffix, not
`ll'.
(PRIdFAST, PRIoFAST, PRIxFAST, PRIuFAST, SCNdFAST, SCNiFAST,
SCNoFAST, SCNxFAST): Correct format specifiers.
1997-06-02 04:23 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/syscalls.list: Make fchdir weak alias for __fchdir.
1997-06-01 19:17 Ulrich Drepper <drepper@cygnus.com>
* md5-crypt/Makefile: Correct libmd5crypt file to really generate
DES free libcrypt.
* md5-crypt/onlymd5-entry.c: New file. Wrapper around
sysdeps/generic/crypt-entry.c.
1997-06-01 12:48 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/sysv/linux/alpha/gnu/types.h (__fd_mask): Change
type to `unsigned long int'.
Patch by Richard Henderson <richard@twiddle.rth.home>.
1997-05-30 17:34 Andreas Jaeger <aj@arthur.rhein-neckar.de>
* sysdeps/generic/bb_init_func.c (__bb_init_func): Use ISO C
declaration style.
* nss/nss_files/files-hosts.c: Delete inclusion of
"../resolv/mapv4v6hostent.h".
1997-06-03 21:53:09 +00:00
|
|
|
# define md5_init_ctx __md5_init_ctx
|
|
|
|
# define md5_process_bytes __md5_process_bytes
|
|
|
|
# define md5_finish_ctx __md5_finish_ctx
|
|
|
|
# define md5_read_ctx __md5_read_ctx
|
|
|
|
# define md5_stream __md5_stream
|
|
|
|
# define md5_buffer __md5_buffer
|
1996-12-15 02:15:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
# define SWAP(n) \
|
|
|
|
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
|
|
|
|
#else
|
|
|
|
# define SWAP(n) (n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* This array contains the bytes used to pad the buffer to the next
|
|
|
|
64-byte boundary. (RFC 1321, 3.1: Step 1) */
|
|
|
|
static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize structure containing state of computation.
|
|
|
|
(RFC 1321, 3.3: Step 3) */
|
|
|
|
void
|
2015-10-16 20:21:49 +00:00
|
|
|
md5_init_ctx (struct md5_ctx *ctx)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
|
|
|
ctx->A = 0x67452301;
|
|
|
|
ctx->B = 0xefcdab89;
|
|
|
|
ctx->C = 0x98badcfe;
|
|
|
|
ctx->D = 0x10325476;
|
|
|
|
|
|
|
|
ctx->total[0] = ctx->total[1] = 0;
|
|
|
|
ctx->buflen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put result from CTX in first 16 bytes following RESBUF. The result
|
|
|
|
must be in little endian byte order.
|
|
|
|
|
|
|
|
IMPORTANT: On some systems it is required that RESBUF is correctly
|
|
|
|
aligned for a 32 bits value. */
|
|
|
|
void *
|
2015-10-16 20:21:49 +00:00
|
|
|
md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
|
|
|
((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
|
|
|
|
((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
|
|
|
|
((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
|
|
|
|
((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
|
|
|
|
|
|
|
|
return resbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process the remaining bytes in the internal buffer and the usual
|
|
|
|
prolog according to the standard and write the result to RESBUF.
|
|
|
|
|
|
|
|
IMPORTANT: On some systems it is required that RESBUF is correctly
|
|
|
|
aligned for a 32 bits value. */
|
|
|
|
void *
|
2015-10-16 20:21:49 +00:00
|
|
|
md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
|
|
|
/* Take yet unprocessed bytes into account. */
|
|
|
|
md5_uint32 bytes = ctx->buflen;
|
|
|
|
size_t pad;
|
|
|
|
|
|
|
|
/* Now count remaining bytes. */
|
|
|
|
ctx->total[0] += bytes;
|
|
|
|
if (ctx->total[0] < bytes)
|
|
|
|
++ctx->total[1];
|
|
|
|
|
|
|
|
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
|
|
|
|
memcpy (&ctx->buffer[bytes], fillbuf, pad);
|
|
|
|
|
|
|
|
/* Put the 64-bit file length in *bits* at the end of the buffer. */
|
2011-07-19 20:53:43 +00:00
|
|
|
ctx->buffer32[(bytes + pad) / 4] = SWAP (ctx->total[0] << 3);
|
Break some lines before not after operators.
The GNU Coding Standards specify that line breaks in expressions
should go before an operator, not after one. This patch fixes various
code to do this. It only changes code that appears to be mostly
following GNU style anyway, not files and directories with
substantially different formatting. It is not exhaustive even for
files using GNU style (for example, changes to sysdeps files are
deferred for subsequent cleanups). Some files changed are shared with
gnulib, but most are specific to glibc. Changes were made manually,
with places to change found by grep (so some cases, e.g. where the
operator was followed by a comment at end of line, are particularly
liable to have been missed by grep, but I did include cases where the
operator was followed by backslash-newline).
This patch generally does not attempt to address other coding style
issues in the expressions changed (for example, missing spaces before
'(', or lack of parentheses to ensure indentation of continuation
lines properly reflects operator precedence).
Tested for x86_64, and with build-many-glibcs.py.
* benchtests/bench-memmem.c (simple_memmem): Break lines before
rather than after operators.
* benchtests/bench-skeleton.c (TIMESPEC_AFTER): Likewise.
* crypt/md5.c (md5_finish_ctx): Likewise.
* crypt/sha256.c (__sha256_finish_ctx): Likewise.
* crypt/sha512.c (__sha512_finish_ctx): Likewise.
* elf/cache.c (load_aux_cache): Likewise.
* elf/dl-load.c (open_verify): Likewise.
* elf/get-dynamic-info.h (elf_get_dynamic_info): Likewise.
* elf/readelflib.c (process_elf_file): Likewise.
* elf/rtld.c (dl_main): Likewise.
* elf/sprof.c (generate_call_graph): Likewise.
* hurd/ctty-input.c (_hurd_ctty_input): Likewise.
* hurd/ctty-output.c (_hurd_ctty_output): Likewise.
* hurd/dtable.c (reauth_dtable): Likewise.
* hurd/getdport.c (__getdport): Likewise.
* hurd/hurd/signal.h (_hurd_interrupted_rpc_timeout): Likewise.
* hurd/hurd/sigpreempt.h (HURD_PREEMPT_SIGNAL_P): Likewise.
* hurd/hurdfault.c (_hurdsig_fault_catch_exception_raise):
Likewise.
* hurd/hurdioctl.c (fioctl): Likewise.
* hurd/hurdselect.c (_hurd_select): Likewise.
* hurd/hurdsig.c (_hurdsig_abort_rpcs): Likewise.
(STOPSIGS): Likewise.
* hurd/hurdstartup.c (_hurd_startup): Likewise.
* hurd/intr-msg.c (_hurd_intr_rpc_mach_msg): Likewise.
* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Likewise.
* hurd/msgportdemux.c (msgport_server): Likewise.
* hurd/setauth.c (_hurd_setauth): Likewise.
* include/features.h (__GLIBC_USE_DEPRECATED_SCANF): Likewise.
* libio/libioP.h [IO_DEBUG] (CHECK_FILE): Likewise.
* locale/programs/ld-ctype.c (set_class_defaults): Likewise.
* localedata/tests-mbwc/tst_swscanf.c (tst_swscanf): Likewise.
* login/tst-utmp.c (do_check): Likewise.
(simulate_login): Likewise.
* mach/lowlevellock.h (lll_lock): Likewise.
(lll_trylock): Likewise.
* math/test-fenv.c (ALL_EXC): Likewise.
* math/test-fenvinline.c (ALL_EXC): Likewise.
* misc/sys/cdefs.h (__attribute_deprecated_msg__): Likewise.
* nis/nis_call.c (__do_niscall3): Likewise.
* nis/nis_callback.c (cb_prog_1): Likewise.
* nis/nis_defaults.c (searchaccess): Likewise.
* nis/nis_findserv.c (__nis_findfastest_with_timeout): Likewise.
* nis/nis_ismember.c (internal_ismember): Likewise.
* nis/nis_local_names.c (nis_local_principal): Likewise.
* nis/nss_nis/nis-rpc.c (_nss_nis_getrpcbyname_r): Likewise.
* nis/nss_nisplus/nisplus-netgrp.c (_nss_nisplus_getnetgrent_r):
Likewise.
* nis/ypclnt.c (yp_match): Likewise.
(yp_first): Likewise.
(yp_next): Likewise.
(yp_master): Likewise.
(yp_order): Likewise.
* nscd/hstcache.c (cache_addhst): Likewise.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* nss/nss_compat/compat-pwd.c (copy_pwd_changes): Likewise.
(internal_getpwuid_r): Likewise.
* nss/nss_compat/compat-spwd.c (copy_spwd_changes): Likewise.
* posix/glob.h (__GLOB_FLAGS): Likewise.
* posix/regcomp.c (peek_token): Likewise.
(peek_token_bracket): Likewise.
(parse_expression): Likewise.
* posix/regexec.c (sift_states_iter_mb): Likewise.
(check_node_accept_bytes): Likewise.
* posix/tst-spawn3.c (do_test): Likewise.
* posix/wordexp-test.c (testit): Likewise.
* posix/wordexp.c (parse_tilde): Likewise.
(exec_comm): Likewise.
* posix/wordexp.h (__WRDE_FLAGS): Likewise.
* resource/vtimes.c (TIMEVAL_TO_VTIMES): Likewise.
* setjmp/sigjmp.c (__sigjmp_save): Likewise.
* stdio-common/printf_fp.c (__printf_fp_l): Likewise.
* stdio-common/tst-fileno.c (do_test): Likewise.
* stdio-common/vfprintf-internal.c (vfprintf): Likewise.
* stdlib/strfmon_l.c (__vstrfmon_l_internal): Likewise.
* stdlib/strtod_l.c (round_and_return): Likewise.
(____STRTOF_INTERNAL): Likewise.
* stdlib/tst-strfrom.h (TEST_STRFROM): Likewise.
* string/strcspn.c (STRCSPN): Likewise.
* string/test-memmem.c (simple_memmem): Likewise.
* termios/tcsetattr.c (tcsetattr): Likewise.
* time/alt_digit.c (_nl_parse_alt_digit): Likewise.
* time/asctime.c (asctime_internal): Likewise.
* time/strptime_l.c (__strptime_internal): Likewise.
* time/sys/time.h (timercmp): Likewise.
* time/tzfile.c (__tzfile_compute): Likewise.
2019-02-22 01:32:36 +00:00
|
|
|
ctx->buffer32[(bytes + pad + 4) / 4] = SWAP ((ctx->total[1] << 3)
|
|
|
|
| (ctx->total[0] >> 29));
|
1996-12-15 02:15:29 +00:00
|
|
|
|
|
|
|
/* Process last bytes. */
|
2012-11-12 23:17:31 +00:00
|
|
|
__md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
|
1996-12-15 02:15:29 +00:00
|
|
|
|
|
|
|
return md5_read_ctx (ctx, resbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute MD5 message digest for bytes read from STREAM. The
|
|
|
|
resulting message digest number will be written into the 16 bytes
|
|
|
|
beginning at RESBLOCK. */
|
|
|
|
int
|
2015-10-16 20:21:49 +00:00
|
|
|
md5_stream (FILE *stream, void *resblock)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
|
|
|
/* Important: BLOCKSIZE must be a multiple of 64. */
|
|
|
|
#define BLOCKSIZE 4096
|
|
|
|
struct md5_ctx ctx;
|
|
|
|
char buffer[BLOCKSIZE + 72];
|
|
|
|
size_t sum;
|
|
|
|
|
|
|
|
/* Initialize the computation context. */
|
|
|
|
md5_init_ctx (&ctx);
|
|
|
|
|
|
|
|
/* Iterate over full file contents. */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* We read the file in blocks of BLOCKSIZE bytes. One call of the
|
|
|
|
computation function processes the whole buffer so that with the
|
|
|
|
next round of the loop another block can be read. */
|
|
|
|
size_t n;
|
|
|
|
sum = 0;
|
|
|
|
|
|
|
|
/* Read block. Take care for partial reads. */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
|
|
|
|
|
|
|
|
sum += n;
|
|
|
|
}
|
|
|
|
while (sum < BLOCKSIZE && n != 0);
|
|
|
|
if (n == 0 && ferror (stream))
|
2011-07-19 20:53:43 +00:00
|
|
|
return 1;
|
1996-12-15 02:15:29 +00:00
|
|
|
|
|
|
|
/* If end of file is reached, end the loop. */
|
|
|
|
if (n == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Process buffer with BLOCKSIZE bytes. Note that
|
|
|
|
BLOCKSIZE % 64 == 0
|
|
|
|
*/
|
2012-11-12 23:17:31 +00:00
|
|
|
__md5_process_block (buffer, BLOCKSIZE, &ctx);
|
1996-12-15 02:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the last bytes if necessary. */
|
|
|
|
if (sum > 0)
|
|
|
|
md5_process_bytes (buffer, sum, &ctx);
|
|
|
|
|
|
|
|
/* Construct result in desired memory. */
|
|
|
|
md5_finish_ctx (&ctx, resblock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
|
|
|
|
result is always in little endian byte order, so that a byte-wise
|
|
|
|
output yields to the wanted ASCII representation of the message
|
|
|
|
digest. */
|
|
|
|
void *
|
2015-10-16 20:21:49 +00:00
|
|
|
md5_buffer (const char *buffer, size_t len, void *resblock)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
|
|
|
struct md5_ctx ctx;
|
|
|
|
|
|
|
|
/* Initialize the computation context. */
|
|
|
|
md5_init_ctx (&ctx);
|
|
|
|
|
|
|
|
/* Process whole buffer but last len % 64 bytes. */
|
|
|
|
md5_process_bytes (buffer, len, &ctx);
|
|
|
|
|
|
|
|
/* Put result in desired memory area. */
|
|
|
|
return md5_finish_ctx (&ctx, resblock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2015-10-16 20:21:49 +00:00
|
|
|
md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
|
|
|
/* When we already have some bits in our internal buffer concatenate
|
|
|
|
both inputs first. */
|
|
|
|
if (ctx->buflen != 0)
|
|
|
|
{
|
|
|
|
size_t left_over = ctx->buflen;
|
|
|
|
size_t add = 128 - left_over > len ? len : 128 - left_over;
|
|
|
|
|
|
|
|
memcpy (&ctx->buffer[left_over], buffer, add);
|
|
|
|
ctx->buflen += add;
|
|
|
|
|
2000-07-04 18:24:11 +00:00
|
|
|
if (ctx->buflen > 64)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
2012-11-12 23:17:31 +00:00
|
|
|
__md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
|
2000-07-04 18:24:11 +00:00
|
|
|
|
|
|
|
ctx->buflen &= 63;
|
1996-12-15 02:15:29 +00:00
|
|
|
/* The regions in the following copy operation cannot overlap. */
|
|
|
|
memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
|
2000-07-04 18:24:11 +00:00
|
|
|
ctx->buflen);
|
1996-12-15 02:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer = (const char *) buffer + add;
|
|
|
|
len -= add;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process available complete blocks. */
|
2001-12-14 06:33:57 +00:00
|
|
|
if (len >= 64)
|
1996-12-15 02:15:29 +00:00
|
|
|
{
|
2023-02-09 13:26:43 +00:00
|
|
|
while (len > 64)
|
2001-12-14 06:33:57 +00:00
|
|
|
{
|
2023-02-09 13:26:43 +00:00
|
|
|
__md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
|
|
|
|
buffer = (const char *) buffer + 64;
|
|
|
|
len -= 64;
|
2001-12-14 06:33:57 +00:00
|
|
|
}
|
1996-12-15 02:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Move remaining bytes in internal buffer. */
|
|
|
|
if (len > 0)
|
|
|
|
{
|
2000-07-04 18:24:11 +00:00
|
|
|
size_t left_over = ctx->buflen;
|
|
|
|
|
|
|
|
memcpy (&ctx->buffer[left_over], buffer, len);
|
|
|
|
left_over += len;
|
|
|
|
if (left_over >= 64)
|
|
|
|
{
|
2012-11-12 23:17:31 +00:00
|
|
|
__md5_process_block (ctx->buffer, 64, ctx);
|
2000-07-04 18:24:11 +00:00
|
|
|
left_over -= 64;
|
|
|
|
memcpy (ctx->buffer, &ctx->buffer[64], left_over);
|
|
|
|
}
|
|
|
|
ctx->buflen = left_over;
|
1996-12-15 02:15:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-12 23:17:31 +00:00
|
|
|
#include <md5-block.c>
|