Skip to content

Commit

Permalink
Applied updates and code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Apr 8, 2023
1 parent 5fddc76 commit 4f75057
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Files to ignore by git
#
# Version: 20200912
# Version: 20230405

# Generic auto-generated build files
*~
Expand Down Expand Up @@ -82,6 +82,7 @@ stamp-h[1-9]
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/nls.m4
/m4/pkg.m4
/m4/po.m4
/m4/printf-posix.m4
/m4/progtest.m4
Expand Down
4 changes: 2 additions & 2 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# Script to generate ./configure using the autotools
#
# Version: 20220709
# Version: 20230405

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
Expand Down Expand Up @@ -133,7 +133,7 @@ else
exit $?;
fi

${ACLOCAL} --force -I m4;
${ACLOCAL} --force --install -I m4;
if test $? -ne 0;
then
exit $?;
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ([2.71])

AC_INIT(
[libhmac],
[20230205],
[20230407],
[[email protected]])

AC_CONFIG_SRCDIR(
Expand Down
13 changes: 11 additions & 2 deletions libhmac/libhmac_md5_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@

#if !defined( LIBHMAC_HAVE_MD5_SUPPORT )

#define LIBHMAC_MD5_BLOCK_SIZE 64

/* RFC 1321 based MD5 functions
*/

Expand Down Expand Up @@ -857,6 +855,17 @@ int libhmac_md5_context_update(
}
if( internal_context->block_offset > 0 )
{
if( internal_context->block_offset >= LIBHMAC_MD5_BLOCK_SIZE )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid context - block offset value out of bounds.",
function );

return( -1 );
}
remaining_block_size = LIBHMAC_MD5_BLOCK_SIZE - internal_context->block_offset;

if( remaining_block_size > size )
Expand Down
4 changes: 3 additions & 1 deletion libhmac/libhmac_md5_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern "C" {

#endif

#define LIBHMAC_MD5_BLOCK_SIZE 64

typedef struct libhmac_internal_md5_context libhmac_internal_md5_context_t;

struct libhmac_internal_md5_context
Expand Down Expand Up @@ -81,7 +83,7 @@ struct libhmac_internal_md5_context

/* The (data) block
*/
uint8_t block[ 128 ];
uint8_t block[ 2 * LIBHMAC_MD5_BLOCK_SIZE ];

#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_MD5_H ) && defined( MD5_DIGEST_LENGTH ) */
};
Expand Down
13 changes: 11 additions & 2 deletions libhmac/libhmac_sha1_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

#if !defined( LIBHMAC_HAVE_SHA1_SUPPORT )

#define LIBHMAC_SHA1_BLOCK_SIZE 64

/* RFC 3174/FIPS 180-1 based SHA-1 functions
*/

Expand Down Expand Up @@ -930,6 +928,17 @@ int libhmac_sha1_context_update(
}
if( internal_context->block_offset > 0 )
{
if( internal_context->block_offset >= LIBHMAC_SHA1_BLOCK_SIZE )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid context - block offset value out of bounds.",
function );

return( -1 );
}
remaining_block_size = LIBHMAC_SHA1_BLOCK_SIZE - internal_context->block_offset;

if( remaining_block_size > size )
Expand Down
4 changes: 3 additions & 1 deletion libhmac/libhmac_sha1_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern "C" {

#endif

#define LIBHMAC_SHA1_BLOCK_SIZE 64

typedef struct libhmac_internal_sha1_context libhmac_internal_sha1_context_t;

struct libhmac_internal_sha1_context
Expand Down Expand Up @@ -81,7 +83,7 @@ struct libhmac_internal_sha1_context

/* The (data) block
*/
uint8_t block[ 128 ];
uint8_t block[ 2 * LIBHMAC_SHA1_BLOCK_SIZE ];

#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_SHA_H ) && defined( SHA_DIGEST_LENGTH ) */
};
Expand Down
13 changes: 11 additions & 2 deletions libhmac/libhmac_sha224_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

#if !defined( LIBHMAC_HAVE_SHA224_SUPPORT )

#define LIBHMAC_SHA224_BLOCK_SIZE 64

/* FIPS 180-2 based SHA-224 functions
*/

Expand Down Expand Up @@ -889,6 +887,17 @@ int libhmac_sha224_context_update(
}
if( internal_context->block_offset > 0 )
{
if( internal_context->block_offset >= LIBHMAC_SHA224_BLOCK_SIZE )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid context - block offset value out of bounds.",
function );

return( -1 );
}
remaining_block_size = LIBHMAC_SHA224_BLOCK_SIZE - internal_context->block_offset;

if( remaining_block_size > size )
Expand Down
4 changes: 3 additions & 1 deletion libhmac/libhmac_sha224_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern "C" {

#endif

#define LIBHMAC_SHA224_BLOCK_SIZE 64

typedef struct libhmac_internal_sha224_context libhmac_internal_sha224_context_t;

struct libhmac_internal_sha224_context
Expand Down Expand Up @@ -81,7 +83,7 @@ struct libhmac_internal_sha224_context

/* The (data) block
*/
uint8_t block[ 128 ];
uint8_t block[ 2 * LIBHMAC_SHA224_BLOCK_SIZE ];

#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_SHA_H ) && defined( SHA224_DIGEST_LENGTH ) */
};
Expand Down
13 changes: 11 additions & 2 deletions libhmac/libhmac_sha256_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

#if !defined( LIBHMAC_HAVE_SHA256_SUPPORT )

#define LIBHMAC_SHA256_BLOCK_SIZE 64

/* FIPS 180-2 based SHA-256 functions
*/

Expand Down Expand Up @@ -889,6 +887,17 @@ int libhmac_sha256_context_update(
}
if( internal_context->block_offset > 0 )
{
if( internal_context->block_offset >= LIBHMAC_SHA256_BLOCK_SIZE )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid context - block offset value out of bounds.",
function );

return( -1 );
}
remaining_block_size = LIBHMAC_SHA256_BLOCK_SIZE - internal_context->block_offset;

if( remaining_block_size > size )
Expand Down
4 changes: 3 additions & 1 deletion libhmac/libhmac_sha256_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern "C" {

#endif

#define LIBHMAC_SHA256_BLOCK_SIZE 64

typedef struct libhmac_internal_sha256_context libhmac_internal_sha256_context_t;

struct libhmac_internal_sha256_context
Expand Down Expand Up @@ -81,7 +83,7 @@ struct libhmac_internal_sha256_context

/* The (data) block
*/
uint8_t block[ 128 ];
uint8_t block[ 2 * LIBHMAC_SHA256_BLOCK_SIZE ];

#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_SHA_H ) && defined( SHA256_DIGEST_LENGTH ) */
};
Expand Down
13 changes: 11 additions & 2 deletions libhmac/libhmac_sha512_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

#if !defined( LIBHMAC_HAVE_SHA512_SUPPORT )

#define LIBHMAC_SHA512_BLOCK_SIZE 128

/* FIPS 180-2 based SHA-512 functions
*/

Expand Down Expand Up @@ -925,6 +923,17 @@ int libhmac_sha512_context_update(
}
if( internal_context->block_offset > 0 )
{
if( internal_context->block_offset >= LIBHMAC_SHA512_BLOCK_SIZE )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid context - block offset value out of bounds.",
function );

return( -1 );
}
remaining_block_size = LIBHMAC_SHA512_BLOCK_SIZE - internal_context->block_offset;

if( remaining_block_size > size )
Expand Down
4 changes: 3 additions & 1 deletion libhmac/libhmac_sha512_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern "C" {

#endif

#define LIBHMAC_SHA512_BLOCK_SIZE 128

typedef struct libhmac_internal_sha512_context libhmac_internal_sha512_context_t;

struct libhmac_internal_sha512_context
Expand Down Expand Up @@ -81,7 +83,7 @@ struct libhmac_internal_sha512_context

/* The (data) block
*/
uint8_t block[ 128 ];
uint8_t block[ 2 * LIBHMAC_SHA512_BLOCK_SIZE ];

#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_SHA_H ) && defined( SHA512_DIGEST_LENGTH ) */
};
Expand Down
4 changes: 2 additions & 2 deletions manuals/libhmac.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Dd February 5, 2023
.Dd April 7, 2023
.Dt libhmac 3
.Os libhmac
.Sh NAME
Expand Down Expand Up @@ -55,7 +55,7 @@ SHA1 functions
.Ft int
.Fn libhmac_sha1_calculate_hmac "const uint8_t *key" "size_t key_size" "const uint8_t *buffer" "size_t size" "uint8_t *hmac" "size_t hmac_size" "libhmac_error_t **error"
.Pp
SHA-224 functions
SHA-224 context functions
.Ft int
.Fn libhmac_sha224_context_initialize "libhmac_sha224_context_t **context" "libhmac_error_t **error"
.Ft int
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
license_files = COPYING COPYING.LESSER
6 changes: 3 additions & 3 deletions tests/test_md5sum.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Sum tool testing script
#
# Version: 20200821
# Version: 20230408

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
Expand All @@ -21,7 +21,7 @@ test_callback()
shift 5;
local ARGUMENTS=("$@");

run_test_with_input_and_arguments "${TEST_EXECUTABLE}" "-d md5" "${INPUT_FILE}" > ${TMPDIR}/hmacsum;
run_test_with_input_and_arguments "${TEST_EXECUTABLE}" "${INPUT_FILE}" -dmd5 > ${TMPDIR}/hmacsum;
local RESULT=$?;

# Note that the $'' string notation is needed for Mac OS to correctly interpret the tabs.
Expand All @@ -35,7 +35,7 @@ test_callback()
else
VERIFICATION_DIGEST_HASH=`md5sum ${INPUT_FILE} | sed 's/[ ][ ]*[^ ][^ ]*$//'`;
fi
if test ${DIGEST_HASH} != ${VERIFICATION_DIGEST_HASH};
if test "${DIGEST_HASH}" != "${VERIFICATION_DIGEST_HASH}";
then
RESULT=${EXIT_FAILURE};
fi
Expand Down
8 changes: 5 additions & 3 deletions tests/test_sha1sum.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Sum tool testing script
#
# Version: 20200821
# Version: 20230408

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
Expand All @@ -21,11 +21,13 @@ test_callback()
shift 5;
local ARGUMENTS=("$@");

run_test_with_input_and_arguments "${TEST_EXECUTABLE}" "-d sha1" "${INPUT_FILE}" > ${TMPDIR}/hmacsum;
run_test_with_input_and_arguments "${TEST_EXECUTABLE}" "${INPUT_FILE}" -dsha1 > ${TMPDIR}/hmacsum;
local RESULT=$?;

DIGEST_HASH=`cat ${TMPDIR}/hmacsum | grep "SHA1" | sed 's/^[^:]*[:][\t][\t]*//'`;

cp ${TMPDIR}/hmacsum /tmp/

if test ${RESULT} -eq ${EXIT_SUCCESS};
then
if test "${PLATFORM}" = "Darwin";
Expand All @@ -34,7 +36,7 @@ test_callback()
else
VERIFICATION_DIGEST_HASH=`sha1sum ${INPUT_FILE} | sed 's/[ ][ ]*[^ ][^ ]*$//'`;
fi
if test ${DIGEST_HASH} != ${VERIFICATION_DIGEST_HASH};
if test "${DIGEST_HASH}" != "${VERIFICATION_DIGEST_HASH}";
then
RESULT=${EXIT_FAILURE};
fi
Expand Down
10 changes: 5 additions & 5 deletions tests/test_sha2sum.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Sum tool testing script
#
# Version: 20200821
# Version: 20230408

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
Expand All @@ -21,7 +21,7 @@ test_callback()
shift 5;
local ARGUMENTS=("$@");

run_test_with_input_and_arguments "${TEST_EXECUTABLE}" "-d sha224,sha256,sha512" "${INPUT_FILE}" > ${TMPDIR}/hmacsum;
run_test_with_input_and_arguments "${TEST_EXECUTABLE}" "${INPUT_FILE}" -dsha224,sha256,sha512 > ${TMPDIR}/hmacsum;
local RESULT=$?;

DIGEST_HASH=`cat ${TMPDIR}/hmacsum | grep "SHA224" | sed 's/^[^:]*[:][\t][\t]*//'`;
Expand All @@ -34,7 +34,7 @@ test_callback()
else
VERIFICATION_DIGEST_HASH=`sha224sum ${INPUT_FILE} | sed 's/[ ][ ]*[^ ][^ ]*$//'`;
fi
if test ${DIGEST_HASH} != ${VERIFICATION_DIGEST_HASH};
if test "${DIGEST_HASH}" != "${VERIFICATION_DIGEST_HASH}";
then
RESULT=${EXIT_FAILURE};
fi
Expand All @@ -50,7 +50,7 @@ test_callback()
else
VERIFICATION_DIGEST_HASH=`sha256sum ${INPUT_FILE} | sed 's/[ ][ ]*[^ ][^ ]*$//'`;
fi
if test ${DIGEST_HASH} != ${VERIFICATION_DIGEST_HASH};
if test "${DIGEST_HASH}" != "${VERIFICATION_DIGEST_HASH}";
then
RESULT=${EXIT_FAILURE};
fi
Expand All @@ -66,7 +66,7 @@ test_callback()
else
VERIFICATION_DIGEST_HASH=`sha512sum ${INPUT_FILE} | sed 's/[ ][ ]*[^ ][^ ]*$//'`;
fi
if test ${DIGEST_HASH} != ${VERIFICATION_DIGEST_HASH};
if test "${DIGEST_HASH}" != "${VERIFICATION_DIGEST_HASH}";
then
RESULT=${EXIT_FAILURE};
fi
Expand Down
Loading

0 comments on commit 4f75057

Please sign in to comment.