collect sha256

compute sha256

sha collector - build system
0.96
aCaB 16 years ago
parent 247fe3aeb4
commit 16b28d07ec
  1. 3
      clamav-config.h.in
  2. 63
      configure
  3. 6
      configure.in
  4. 4
      libclamav/Makefile.am
  5. 17
      libclamav/Makefile.in
  6. 35
      libclamav/matcher.c
  7. 4
      libclamav/others.h
  8. 18
      libclamav/pe.c
  9. 23
      libclamav/scanners.c
  10. 626
      libclamav/sha1.c
  11. 72
      libclamav/sha1.h

@ -404,6 +404,9 @@
/* This value is set to 1 to indicate that the system argz facility works */
#undef HAVE_WORKING_ARGZ
/* For internal use only - DO NOT DEFINE */
#undef HAVE__INTERNAL__SHA_COLLECT
/* "Full library version number" */
#undef LIBCLAMAV_FULLVER

63
configure vendored

@ -754,6 +754,8 @@ am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
BUILD_SHA1_FALSE
BUILD_SHA1_TRUE
subdirs
HAVE_CURSES_FALSE
HAVE_CURSES_TRUE
@ -985,6 +987,7 @@ with_libncurses_prefix
with_libpdcurses_prefix
enable_distcheck_werror
enable_llvm
enable_sha_collector_for_internal_use
'
ac_precious_vars='build_alias
host_alias
@ -1660,6 +1663,7 @@ Optional Features:
enable warnings as error for distcheck [default=no]
--enable-llvm Enable 'llvm' JIT/verifier support [default=auto]
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
@ -5167,13 +5171,13 @@ if test "${lt_cv_nm_interface+set}" = set; then :
else
lt_cv_nm_interface="BSD nm"
echo "int some_variable = 0;" > conftest.$ac_ext
(eval echo "\"\$as_me:5170: $ac_compile\"" >&5)
(eval echo "\"\$as_me:5174: $ac_compile\"" >&5)
(eval "$ac_compile" 2>conftest.err)
cat conftest.err >&5
(eval echo "\"\$as_me:5173: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval echo "\"\$as_me:5177: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
cat conftest.err >&5
(eval echo "\"\$as_me:5176: output\"" >&5)
(eval echo "\"\$as_me:5180: output\"" >&5)
cat conftest.out >&5
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
lt_cv_nm_interface="MS dumpbin"
@ -6368,7 +6372,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
echo '#line 6371 "configure"' > conftest.$ac_ext
echo '#line 6375 "configure"' > conftest.$ac_ext
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
(eval $ac_compile) 2>&5
ac_status=$?
@ -7896,11 +7900,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:7899: $lt_compile\"" >&5)
(eval echo "\"\$as_me:7903: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:7903: \$? = $ac_status" >&5
echo "$as_me:7907: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -8235,11 +8239,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:8238: $lt_compile\"" >&5)
(eval echo "\"\$as_me:8242: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
echo "$as_me:8242: \$? = $ac_status" >&5
echo "$as_me:8246: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@ -8340,11 +8344,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:8343: $lt_compile\"" >&5)
(eval echo "\"\$as_me:8347: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:8347: \$? = $ac_status" >&5
echo "$as_me:8351: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@ -8395,11 +8399,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
(eval echo "\"\$as_me:8398: $lt_compile\"" >&5)
(eval echo "\"\$as_me:8402: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
echo "$as_me:8402: \$? = $ac_status" >&5
echo "$as_me:8406: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@ -10779,7 +10783,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 10782 "configure"
#line 10786 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -10875,7 +10879,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 10878 "configure"
#line 10882 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -11547,7 +11551,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11550 "configure"
#line 11554 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@ -19878,6 +19882,27 @@ subdirs="$subdirs libclamav/c++"
fi
# Check whether --enable-sha-collector-for-internal-use was given.
if test "${enable_sha_collector_for_internal_use+set}" = set; then :
enableval=$enable_sha_collector_for_internal_use; enable_sha_collector="yes"
else
enable_sha_collector="no"
fi
if test "$enable_sha_collector" != "no"; then
$as_echo "#define HAVE__INTERNAL__SHA_COLLECT 1" >>confdefs.h
fi
if test "$enable_sha_collector" != "no"; then
BUILD_SHA1_TRUE=
BUILD_SHA1_FALSE='#'
else
BUILD_SHA1_TRUE='#'
BUILD_SHA1_FALSE=
fi
ac_config_files="$ac_config_files clamscan/Makefile database/Makefile docs/Makefile clamd/Makefile clamdscan/Makefile clamav-milter/Makefile freshclam/Makefile sigtool/Makefile clamconf/Makefile etc/Makefile test/Makefile unit_tests/Makefile clamdtop/Makefile clambc/Makefile Makefile clamav-config libclamav.pc platform.h docs/man/clamav-milter.8 docs/man/clamconf.1 docs/man/clamd.8 docs/man/clamd.conf.5 docs/man/clamdscan.1 docs/man/clamscan.1 docs/man/freshclam.1 docs/man/freshclam.conf.5 docs/man/sigtool.1 docs/man/clamdtop.1"
cat >confcache <<\_ACEOF
@ -20055,6 +20080,10 @@ if test -z "${HAVE_CURSES_TRUE}" && test -z "${HAVE_CURSES_FALSE}"; then
as_fn_error "conditional \"HAVE_CURSES\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${BUILD_SHA1_TRUE}" && test -z "${BUILD_SHA1_FALSE}"; then
as_fn_error "conditional \"BUILD_SHA1\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
: ${CONFIG_STATUS=./config.status}
ac_write_fail=0
@ -22630,6 +22659,10 @@ if test -z "${HAVE_CURSES_TRUE}" && test -z "${HAVE_CURSES_FALSE}"; then
as_fn_error "conditional \"HAVE_CURSES\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${BUILD_SHA1_TRUE}" && test -z "${BUILD_SHA1_FALSE}"; then
as_fn_error "conditional \"BUILD_SHA1\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${am__EXEEXT_TRUE}" && test -z "${am__EXEEXT_FALSE}"; then
as_fn_error "conditional \"am__EXEEXT\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5

@ -1579,6 +1579,12 @@ if test "$enable_llvm" != "no"; then
AC_CONFIG_SUBDIRS_OPTIONAL([libclamav/c++])
fi
AC_ARG_ENABLE([sha-collector-for-internal-use], [], [enable_sha_collector="yes"], [enable_sha_collector="no"])
if test "$enable_sha_collector" != "no"; then
AC_DEFINE([HAVE__INTERNAL__SHA_COLLECT], 1, [For internal use only - DO NOT DEFINE])
fi
AM_CONDITIONAL([BUILD_SHA1],[test "$enable_sha_collector" != "no"])
AC_OUTPUT([
clamscan/Makefile
database/Makefile

@ -360,6 +360,10 @@ libclamav_la_SOURCES += bignum.c \
bignum_class.h
endif
if BUILD_SHA1
libclamav_la_SOURCES += sha1.c sha1.h
endif
.PHONY: version.h.tmp
version.c: version.h
version.h: version.h.tmp

@ -66,6 +66,7 @@ target_triplet = @target@
@LINK_TOMMATH_FALSE@am__append_7 = bignum.c \
@LINK_TOMMATH_FALSE@ bignum_class.h
@BUILD_SHA1_TRUE@am__append_8 = sha1.c sha1.h
subdir = libclamav
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
@ -156,8 +157,9 @@ am__libclamav_la_SOURCES_DIST = clamav.h matcher-ac.c matcher-ac.h \
clambc.h cpio.c cpio.h macho.c macho.h ishield.c ishield.h \
type_desc.h bcfeatures.h bytecode_api.c bytecode_api_decl.c \
bytecode_api.h bytecode_api_impl.h bytecode_hooks.h cache.c \
cache.h bignum.c bignum_class.h
cache.h bignum.c bignum_class.h sha1.c sha1.h
@LINK_TOMMATH_FALSE@am__objects_1 = libclamav_la-bignum.lo
@BUILD_SHA1_TRUE@am__objects_2 = libclamav_la-sha1.lo
am_libclamav_la_OBJECTS = libclamav_la-matcher-ac.lo \
libclamav_la-matcher-bm.lo libclamav_la-matcher.lo \
libclamav_la-others.lo libclamav_la-readdb.lo \
@ -206,7 +208,7 @@ am_libclamav_la_OBJECTS = libclamav_la-matcher-ac.lo \
libclamav_la-bytecode_vm.lo libclamav_la-cpio.lo \
libclamav_la-macho.lo libclamav_la-ishield.lo \
libclamav_la-bytecode_api.lo libclamav_la-bytecode_api_decl.lo \
libclamav_la-cache.lo $(am__objects_1)
libclamav_la-cache.lo $(am__objects_1) $(am__objects_2)
libclamav_la_OBJECTS = $(am_libclamav_la_OBJECTS)
AM_V_lt = $(am__v_lt_$(V))
am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
@ -656,7 +658,7 @@ libclamav_la_SOURCES = clamav.h matcher-ac.c matcher-ac.h matcher-bm.c \
clambc.h cpio.c cpio.h macho.c macho.h ishield.c ishield.h \
type_desc.h bcfeatures.h bytecode_api.c bytecode_api_decl.c \
bytecode_api.h bytecode_api_impl.h bytecode_hooks.h cache.c \
cache.h $(am__append_7)
cache.h $(am__append_7) $(am__append_8)
noinst_LTLIBRARIES = libclamav_internal_utils.la libclamav_internal_utils_nothreads.la libclamav_nocxx.la
COMMON_CLEANFILES = version.h version.h.tmp *.gcda *.gcno
@MAINTAINER_MODE_TRUE@BUILT_SOURCES = jsparse/generated/operators.h jsparse/generated/keywords.h jsparse-keywords.gperf
@ -853,6 +855,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_la-regex_suffix.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_la-rtf.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_la-scanners.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_la-sha1.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_la-sha256.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_la-sis.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_la-special.Plo@am__quote@
@ -1692,6 +1695,14 @@ libclamav_la-bignum.lo: bignum.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_la_CFLAGS) $(CFLAGS) -c -o libclamav_la-bignum.lo `test -f 'bignum.c' || echo '$(srcdir)/'`bignum.c
libclamav_la-sha1.lo: sha1.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_la_CFLAGS) $(CFLAGS) -MT libclamav_la-sha1.lo -MD -MP -MF $(DEPDIR)/libclamav_la-sha1.Tpo -c -o libclamav_la-sha1.lo `test -f 'sha1.c' || echo '$(srcdir)/'`sha1.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libclamav_la-sha1.Tpo $(DEPDIR)/libclamav_la-sha1.Plo
@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='sha1.c' object='libclamav_la-sha1.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_la_CFLAGS) $(CFLAGS) -c -o libclamav_la-sha1.lo `test -f 'sha1.c' || echo '$(srcdir)/'`sha1.c
libclamav_internal_utils_la-str.lo: str.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_la-str.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_la-str.Tpo -c -o libclamav_internal_utils_la-str.lo `test -f 'str.c' || echo '$(srcdir)/'`str.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libclamav_internal_utils_la-str.Tpo $(DEPDIR)/libclamav_internal_utils_la-str.Plo

@ -51,6 +51,11 @@
#include "filtering.h"
#include "perflogging.h"
#ifdef HAVE__INTERNAL__SHA_COLLECT
#include "sha256.h"
#include "sha1.h"
#endif
#ifdef CLI_PERF_LOGGING
static inline void PERF_LOG_FILTER(int32_t pos, int32_t length, int8_t trie)
@ -387,6 +392,36 @@ int cli_checkfp(unsigned char *digest, size_t size, cli_ctx *ctx)
sprintf(md5 + i * 2, "%02x", digest[i]);
md5[32] = 0;
cli_dbgmsg("FP SIGNATURE: %s:%u:%s\n", md5, (unsigned int) size, *ctx->virname ? *ctx->virname : "Name");
#ifdef HAVE__INTERNAL__SHA_COLLECT
if(ctx->sha_collect>0) {
SHA1Context sha1;
SHA256_CTX sha256;
fmap_t *map = *ctx->fmap;
char *ptr;
uint8_t shash1[SHA1_HASH_SIZE*2+1];
uint8_t shash256[SHA256_HASH_SIZE*2+1];
if((ptr = fmap_need_off_once(map, 0, size))) {
sha256_init(&sha256);
sha256_update(&sha256, ptr, size);
sha256_final(&sha256, &shash256[SHA256_HASH_SIZE]);
for(i=0; i<SHA256_HASH_SIZE; i++)
sprintf((char *)shash256+i*2, "%02x", shash256[SHA256_HASH_SIZE+i]);
SHA1Init(&sha1);
SHA1Update(&sha1, ptr, size);
SHA1Final(&sha1, &shash1[SHA1_HASH_SIZE]);
for(i=0; i<SHA1_HASH_SIZE; i++)
sprintf((char *)shash1+i*2, "%02x", shash1[SHA1_HASH_SIZE+i]);
cli_errmsg("COLLECT:%s:%s:%u:%s:%s\n", shash256, shash1, size, *ctx->virname, ctx->entry_filename);
} else
cli_errmsg("can't compute sha\n!");
ctx->sha_collect = -1;
}
#endif
return CL_VIRUS;
}

@ -122,6 +122,10 @@ typedef struct cli_ctx_tag {
struct cli_dconf *dconf;
fmap_t **fmap;
bitset_t* hook_lsig_matches;
#ifdef HAVE__INTERNAL__SHA_COLLECT
char entry_filename[2048];
int sha_collect;
#endif
} cli_ctx;

@ -108,6 +108,14 @@ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
} \
}
#ifdef HAVE__INTERNAL__SHA_COLLECT
#define SHA_OFF do { ctx->sha_collect = -1; } while(0)
#define SHA_RESET do { ctx->sha_collect = sha_collect; } while(0)
#else
#define SHA_OFF do {} while(0)
#define SHA_RESET do {} while(0)
#endif
#define FSGCASE(NAME,FREESEC) \
case 0: /* Unpacked and NOT rebuilt */ \
cli_dbgmsg(NAME": Successfully decompressed\n"); \
@ -148,12 +156,15 @@ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
free(exe_sections); \
lseek(ndesc, 0, SEEK_SET); \
cli_dbgmsg("***** Scanning rebuilt PE file *****\n"); \
SHA_OFF; \
if(cli_magic_scandesc(ndesc, ctx) == CL_VIRUS) { \
close(ndesc); \
CLI_TMPUNLK(); \
free(tempfile); \
SHA_RESET; \
return CL_VIRUS; \
} \
SHA_RESET; \
close(ndesc); \
CLI_TMPUNLK(); \
free(tempfile); \
@ -519,7 +530,9 @@ int cli_scanpe(cli_ctx *ctx, icon_groupset *iconset)
struct cli_bc_ctx *bc_ctx;
fmap_t *map;
struct cli_pe_hook_data pedata;
#ifdef HAVE__INTERNAL__SHA_COLLECT
int sha_collect = ctx->sha_collect;
#endif
if(!ctx) {
cli_errmsg("cli_scanpe: ctx == NULL\n");
@ -1922,13 +1935,16 @@ int cli_scanpe(cli_ctx *ctx, icon_groupset *iconset)
cli_dbgmsg("UPX/FSG: Decompressed data saved in %s\n", tempfile);
cli_dbgmsg("***** Scanning decompressed file *****\n");
SHA_OFF;
if((ret = cli_magic_scandesc(ndesc, ctx)) == CL_VIRUS) {
close(ndesc);
CLI_TMPUNLK();
free(tempfile);
SHA_RESET;
return CL_VIRUS;
}
SHA_RESET;
close(ndesc);
CLI_TMPUNLK();
free(tempfile);

@ -1905,6 +1905,10 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
unsigned char hash[16];
bitset_t *old_hook_lsig_matches;
#ifdef HAVE__INTERNAL__SHA_COLLECT
if(ctx->sha_collect>0) ctx->sha_collect = 0;
#endif
cli_dbgmsg("in cli_magic_scandesc (reclevel: %u/%u)\n", ctx->recursion, ctx->engine->maxreclevel);
if(ctx->engine->maxreclevel && ctx->recursion > ctx->engine->maxreclevel) {
cli_dbgmsg("cli_magic_scandesc: Archive recursion limit exceeded (%u, max: %u)\n", ctx->recursion, ctx->engine->maxreclevel);
@ -1982,6 +1986,10 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
ctx->hook_lsig_matches = old_hook_lsig_matches;
ret_from_magicscan(CL_EREAD);
}
#ifdef HAVE__INTERNAL__SHA_COLLECT
if(!ctx->sha_collect && type==CL_TYPE_MSEXE) ctx->sha_collect = 1;
#endif
lseek(desc, 0, SEEK_SET); /* FIXMEFMAP: remove ? */
ctx->hook_lsig_matches = cli_bitset_init();
@ -2336,6 +2344,21 @@ int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, cons
return CL_EMEM;
ctx.hook_lsig_matches = cli_bitset_init();
#ifdef HAVE__INTERNAL__SHA_COLLECT
do {
char link[32];
ssize_t linksz;
snprintf(link, sizeof(link), "/proc/self/fd/%u", desc);
link[sizeof(link)-1]='\0';
if((linksz=readlink(link, ctx.entry_filename, sizeof(ctx.entry_filename)))==-1) {
cli_errmsg("failed to resolve filename for descriptor %d (%s)\n", desc, link);
strcpy(ctx.entry_filename, "NO_IDEA");
} else
ctx.entry_filename[linksz]='\0';
} while(0);
#endif
rc = cli_magic_scandesc(desc, &ctx);
cli_bitset_free(ctx.hook_lsig_matches);

@ -0,0 +1,626 @@
/*-
* Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL ALLAN SADDI OR HIS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: sha1.c 680 2003-07-25 21:57:38Z asaddi $
*/
/*
* Define WORDS_BIGENDIAN if compiling on a big-endian architecture.
*
* Define SHA1_TEST to test the implementation using the NIST's
* sample messages. The output should be:
*
* a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
* 84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1
* 34aa973c d4c4daa4 f61eeb2b dbad2731 6534016f
*/
#ifdef HAVE_CONFIG_H
#include "clamav-config.h"
#endif /* HAVE_CONFIG_H */
#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
# if HAVE_STDINT_H
# include <stdint.h>
# endif
#endif
#include <string.h>
#include "sha1.h"
#ifndef lint
static const char rcsid[] =
"$Id: sha1.c 680 2003-07-25 21:57:38Z asaddi $";
#endif /* !lint */
#define ROTL(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
#define ROTR(x, n) (((x) >> (n)) | ((x) << (32 - (n))))
#define F_0_19(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
#define F_20_39(x, y, z) ((x) ^ (y) ^ (z))
#define F_40_59(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
#define F_60_79(x, y, z) ((x) ^ (y) ^ (z))
#define DO_ROUND(F, K) { \
temp = ROTL(a, 5) + F(b, c, d) + e + *(W++) + K; \
e = d; \
d = c; \
c = ROTL(b, 30); \
b = a; \
a = temp; \
}
#define K_0_19 0x5a827999L
#define K_20_39 0x6ed9eba1L
#define K_40_59 0x8f1bbcdcL
#define K_60_79 0xca62c1d6L
#ifndef RUNTIME_ENDIAN
#if WORDS_BIGENDIAN == 1
#define BYTESWAP(x) (x)
#define BYTESWAP64(x) (x)
#else /* WORDS_BIGENDIAN */
#define BYTESWAP(x) ((ROTR((x), 8) & 0xff00ff00L) | \
(ROTL((x), 8) & 0x00ff00ffL))
#define BYTESWAP64(x) _byteswap64(x)
static inline uint64_t _byteswap64(uint64_t x)
{
uint32_t a = x >> 32;
uint32_t b = (uint32_t) x;
return ((uint64_t) BYTESWAP(b) << 32) | (uint64_t) BYTESWAP(a);
}
#endif /* WORDS_BIGENDIAN */
#else /* !RUNTIME_ENDIAN */
#define BYTESWAP(x) _byteswap(sc->littleEndian, x)
#define BYTESWAP64(x) _byteswap64(sc->littleEndian, x)
#define _BYTESWAP(x) ((ROTR((x), 8) & 0xff00ff00L) | \
(ROTL((x), 8) & 0x00ff00ffL))
#define _BYTESWAP64(x) __byteswap64(x)
static inline uint64_t __byteswap64(uint64_t x)
{
uint32_t a = x >> 32;
uint32_t b = (uint32_t) x;
return ((uint64_t) _BYTESWAP(b) << 32) | (uint64_t) _BYTESWAP(a);
}
static inline uint32_t _byteswap(int littleEndian, uint32_t x)
{
if (!littleEndian)
return x;
else
return _BYTESWAP(x);
}
static inline uint64_t _byteswap64(int littleEndian, uint64_t x)
{
if (!littleEndian)
return x;
else
return _BYTESWAP64(x);
}
static inline void setEndian(int *littleEndianp)
{
union {
uint32_t w;
uint8_t b[4];
} endian;
endian.w = 1L;
*littleEndianp = endian.b[0] != 0;
}
#endif /* !RUNTIME_ENDIAN */
static const uint8_t padding[64] = {
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void
SHA1Init (SHA1Context *sc)
{
#ifdef RUNTIME_ENDIAN
setEndian (&sc->littleEndian);
#endif /* RUNTIME_ENDIAN */
sc->totalLength = 0LL;
sc->hash[0] = 0x67452301L;
sc->hash[1] = 0xefcdab89L;
sc->hash[2] = 0x98badcfeL;
sc->hash[3] = 0x10325476L;
sc->hash[4] = 0xc3d2e1f0L;
sc->bufferLength = 0L;
}
static void
burnStack (int size)
{
char buf[128];
memset (buf, 0, sizeof (buf));
size -= sizeof (buf);
if (size > 0)
burnStack (size);
}
static void
SHA1Guts (SHA1Context *sc, const uint32_t *cbuf)
{
uint32_t buf[80];
uint32_t *W, *W3, *W8, *W14, *W16;
uint32_t a, b, c, d, e, temp;
int i;
W = buf;
for (i = 15; i >= 0; i--) {
*(W++) = BYTESWAP(*cbuf);
cbuf++;
}
W16 = &buf[0];
W14 = &buf[2];
W8 = &buf[8];
W3 = &buf[13];
for (i = 63; i >= 0; i--) {
*W = *(W3++) ^ *(W8++) ^ *(W14++) ^ *(W16++);
*W = ROTL(*W, 1);
W++;
}
a = sc->hash[0];
b = sc->hash[1];
c = sc->hash[2];
d = sc->hash[3];
e = sc->hash[4];
W = buf;
#ifndef SHA1_UNROLL
#define SHA1_UNROLL 20
#endif /* !SHA1_UNROLL */
#if SHA1_UNROLL == 1
for (i = 19; i >= 0; i--)
DO_ROUND(F_0_19, K_0_19);
for (i = 19; i >= 0; i--)
DO_ROUND(F_20_39, K_20_39);
for (i = 19; i >= 0; i--)
DO_ROUND(F_40_59, K_40_59);
for (i = 19; i >= 0; i--)
DO_ROUND(F_60_79, K_60_79);
#elif SHA1_UNROLL == 2
for (i = 9; i >= 0; i--) {
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
}
for (i = 9; i >= 0; i--) {
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
}
for (i = 9; i >= 0; i--) {
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
}
for (i = 9; i >= 0; i--) {
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
}
#elif SHA1_UNROLL == 4
for (i = 4; i >= 0; i--) {
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
}
for (i = 4; i >= 0; i--) {
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
}
for (i = 4; i >= 0; i--) {
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
}
for (i = 4; i >= 0; i--) {
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
}
#elif SHA1_UNROLL == 5
for (i = 3; i >= 0; i--) {
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
}
for (i = 3; i >= 0; i--) {
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
}
for (i = 3; i >= 0; i--) {
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
}
for (i = 3; i >= 0; i--) {
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
}
#elif SHA1_UNROLL == 10
for (i = 1; i >= 0; i--) {
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
}
for (i = 1; i >= 0; i--) {
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
}
for (i = 1; i >= 0; i--) {
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
}
for (i = 1; i >= 0; i--) {
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
}
#elif SHA1_UNROLL == 20
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_0_19, K_0_19);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_20_39, K_20_39);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_40_59, K_40_59);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
DO_ROUND(F_60_79, K_60_79);
#else /* SHA1_UNROLL */
#error SHA1_UNROLL must be 1, 2, 4, 5, 10 or 20!
#endif
sc->hash[0] += a;
sc->hash[1] += b;
sc->hash[2] += c;
sc->hash[3] += d;
sc->hash[4] += e;
}
void
SHA1Update (SHA1Context *sc, const void *vdata, uint32_t len)
{
const uint8_t *data = vdata;
uint32_t bufferBytesLeft;
uint32_t bytesToCopy;
int needBurn = 0;
#ifdef SHA1_FAST_COPY
if (sc->bufferLength) {
bufferBytesLeft = 64L - sc->bufferLength;
bytesToCopy = bufferBytesLeft;
if (bytesToCopy > len)
bytesToCopy = len;
memcpy (&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
sc->totalLength += bytesToCopy * 8L;
sc->bufferLength += bytesToCopy;
data += bytesToCopy;
len -= bytesToCopy;
if (sc->bufferLength == 64L) {
SHA1Guts (sc, sc->buffer.words);
needBurn = 1;
sc->bufferLength = 0L;
}
}
while (len > 63) {
sc->totalLength += 512L;
SHA1Guts (sc, data);
needBurn = 1;
data += 64L;
len -= 64L;
}
if (len) {
memcpy (&sc->buffer.bytes[sc->bufferLength], data, len);
sc->totalLength += len * 8L;
sc->bufferLength += len;
}
#else /* SHA1_FAST_COPY */
while (len) {
bufferBytesLeft = 64L - sc->bufferLength;
bytesToCopy = bufferBytesLeft;
if (bytesToCopy > len)
bytesToCopy = len;
memcpy (&sc->buffer.bytes[sc->bufferLength], data, bytesToCopy);
sc->totalLength += bytesToCopy * 8L;
sc->bufferLength += bytesToCopy;
data += bytesToCopy;
len -= bytesToCopy;
if (sc->bufferLength == 64L) {
SHA1Guts (sc, sc->buffer.words);
needBurn = 1;
sc->bufferLength = 0L;
}
}
#endif /* SHA1_FAST_COPY */
if (needBurn)
burnStack (sizeof (uint32_t[86]) + sizeof (uint32_t *[5]) + sizeof (int));
}
void
SHA1Final (SHA1Context *sc, uint8_t hash[SHA1_HASH_SIZE])
{
uint32_t bytesToPad;
uint64_t lengthPad;
int i;
bytesToPad = 120L - sc->bufferLength;
if (bytesToPad > 64L)
bytesToPad -= 64L;
lengthPad = BYTESWAP64(sc->totalLength);
SHA1Update (sc, padding, bytesToPad);
SHA1Update (sc, &lengthPad, 8L);
if (hash) {
for (i = 0; i < SHA1_HASH_WORDS; i++) {
#ifdef SHA1_FAST_COPY
*((uint32_t *) hash) = BYTESWAP(sc->hash[i]);
#else /* SHA1_FAST_COPY */
hash[0] = (uint8_t) (sc->hash[i] >> 24);
hash[1] = (uint8_t) (sc->hash[i] >> 16);
hash[2] = (uint8_t) (sc->hash[i] >> 8);
hash[3] = (uint8_t) sc->hash[i];
#endif /* SHA1_FAST_COPY */
hash += 4;
}
}
}
#ifdef SHA1_TEST
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main (int argc, char *argv[])
{
SHA1Context foo;
uint8_t hash[SHA1_HASH_SIZE];
char buf[1000];
int i;
SHA1Init (&foo);
SHA1Update (&foo, "abc", 3);
SHA1Final (&foo, hash);
for (i = 0; i < SHA1_HASH_SIZE;) {
printf ("%02x", hash[i++]);
if (!(i % 4))
printf (" ");
}
printf ("\n");
SHA1Init (&foo);
SHA1Update (&foo,
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
56);
SHA1Final (&foo, hash);
for (i = 0; i < SHA1_HASH_SIZE;) {
printf ("%02x", hash[i++]);
if (!(i % 4))
printf (" ");
}
printf ("\n");
SHA1Init (&foo);
memset (buf, 'a', sizeof (buf));
for (i = 0; i < 1000; i++)
SHA1Update (&foo, buf, sizeof (buf));
SHA1Final (&foo, hash);
for (i = 0; i < SHA1_HASH_SIZE;) {
printf ("%02x", hash[i++]);
if (!(i % 4))
printf (" ");
}
printf ("\n");
exit (0);
}
#endif /* SHA1_TEST */

@ -0,0 +1,72 @@
/*-
* Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL ALLAN SADDI OR HIS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: sha1.h 347 2003-02-23 22:11:49Z asaddi $
*/
#ifndef _SHA1_H
#define _SHA1_H
#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
# if HAVE_STDINT_H
# include <stdint.h>
# endif
#endif
#define SHA1_HASH_SIZE 20
/* Hash size in 32-bit words */
#define SHA1_HASH_WORDS 5
struct _SHA1Context {
uint64_t totalLength;
uint32_t hash[SHA1_HASH_WORDS];
uint32_t bufferLength;
union {
uint32_t words[16];
uint8_t bytes[64];
} buffer;
#ifdef RUNTIME_ENDIAN
int littleEndian;
#endif /* RUNTIME_ENDIAN */
};
typedef struct _SHA1Context SHA1Context;
#ifdef __cplusplus
extern "C" {
#endif
void SHA1Init (SHA1Context *sc);
void SHA1Update (SHA1Context *sc, const void *data, uint32_t len);
void SHA1Final (SHA1Context *sc, uint8_t hash[SHA1_HASH_SIZE]);
#ifdef __cplusplus
}
#endif
#endif /* _SHA1_H */
Loading…
Cancel
Save