alt-sha1.cpp revision 2b114c590cf5a19f8047cd7bde9c7e5ae00aa22b
/* $Id$ */
/** @file
* IPRT - SHA-1 hash functions, Alternative Implementation.
*/
/*
* Copyright (C) 2009-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The SHA-1 block size (in bytes). */
#define RTSHA1_BLOCK_SIZE 64U
/** Enables the unrolled code. */
#define RTSHA1_UNROLLED 1
/*******************************************************************************
* Header Files *
*******************************************************************************/
/** Our private context structure. */
typedef struct RTSHA1ALTPRIVATECTX
{
/** The W array.
* Buffering happens in the first 16 words, converted from big endian to host
* endian immediately before processing. The amount of buffered data is kept
* in the 6 least significant bits of cbMessage. */
/** The message length (in bytes). */
/** The 5 hash values. */
#define RT_SHA1_PRIVATE_ALT_CONTEXT
{
}
/**
* Initializes the auW array from the specfied input block.
*
* @param pCtx The SHA1 context.
* @param pbBlock The block. Must be 32-bit aligned.
*/
{
#ifdef RTSHA1_UNROLLED
/* Copy and byte-swap the block. Initializing the rest of the Ws are done
in the processing loop. */
# ifdef RT_LITTLE_ENDIAN
# else
# endif
#else /* !RTSHA1_UNROLLED */
unsigned iWord;
{
}
#endif /* !RTSHA1_UNROLLED */
}
/**
* Initializes the auW array from data buffered in the first part of the array.
*
* @param pCtx The SHA1 context.
*/
{
#ifdef RTSHA1_UNROLLED
/* Do the byte swap if necessary. Initializing the rest of the Ws are done
in the processing loop. */
# ifdef RT_LITTLE_ENDIAN
# endif
#else /* !RTSHA1_UNROLLED_INIT */
unsigned iWord;
{
}
#endif /* !RTSHA1_UNROLLED_INIT */
}
/** Function 4.1, Ch(x,y,z). */
{
#if 1
/* Optimization that saves one operation and probably a temporary variable. */
return uResult;
#else
/* The original. */
return uResult;
#endif
}
/** Function 4.1, Parity(x,y,z). */
{
return uResult;
}
/** Function 4.1, Maj(x,y,z). */
{
#if 1
/* Optimization that save one operation and probably a temporary variable. */
return uResult;
#else
/* The original. */
return uResult;
#endif
}
/**
* Process the current block.
*
* Requires one of the rtSha1BlockInit functions to be called first.
*
* @param pCtx The SHA1 context.
*/
{
#ifdef RTSHA1_UNROLLED
/* This fully unrolled version will avoid the variable rotation by
embedding it into the loop unrolling. */
do { \
if (a_iWord < 16) \
else \
{ \
} \
} while (0)
do { \
} while (0)
do { \
} while (0)
unsigned iWord = 0;
{ \
uTemp += (a_uExprBCD); \
\
} do { } while (0)
#else /* Dead simple implementation. */
{
if (iWord <= 19)
{
}
else if (iWord <= 39)
{
}
else if (iWord <= 59)
{
}
else
{
}
}
#endif
}
{
/*
* Deal with buffered bytes first.
*/
if (cbBuffered)
{
{
}
else
{
return;
}
}
{
/*
* Process full blocks directly from the input buffer.
*/
while (cbBuf >= RTSHA1_BLOCK_SIZE)
{
}
}
else
{
/*
* Unaligned input, so buffer it.
*/
while (cbBuf >= RTSHA1_BLOCK_SIZE)
{
}
}
/*
* Stash any remaining bytes into the context buffer.
*/
if (cbBuf > 0)
{
}
}
{
/*
* Complete the message by adding a single bit (0x80), padding till
* the next 448-bit boundrary, the add the message length.
*/
unsigned cbMissing = RTSHA1_BLOCK_SIZE - ((unsigned)pCtx->AltPrivate.cbMessage & (RTSHA1_BLOCK_SIZE - 1U));
/* Less than 64+8 bits left in the current block, force a new block. */
else
/*
* Process the last buffered block constructed/completed above.
*/
/*
* Convert the byte order of the hash words and we're done.
*/
}
{
RTSha1Init(&Ctx);
}