ISAL-Crypto
view release on metacpan or search on metacpan
isa-l_crypto/mh_sha1/mh_sha1_ref.c view on Meta::CPAN
/**********************************************************************
Copyright(c) 2011-2016 Intel Corporation All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
OWNER OR 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.
**********************************************************************/
#include <string.h>
#include "mh_sha1_internal.h"
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Macros and sub-functions which already exist in source code file
// (sha1_for_mh_sha1.c) is part of ISA-L library as internal functions.
// The reason why writing them twice is the linking issue caused by
// mh_sha1_ref(). mh_sha1_ref() needs these macros and sub-functions
// without linking ISA-L library. So mh_sha1_ref() includes them in
// order to contain essential sub-functions in its own object file.
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
#define W(x) w[(x) & 15]
#define step00_19(i,a,b,c,d,e) \
if (i>15) W(i) = rol32(W(i-3)^W(i-8)^W(i-14)^W(i-16), 1); \
else W(i) = bswap(ww[i]); \
e += rol32(a,5) + F1(b,c,d) + 0x5A827999 + W(i); \
b = rol32(b,30)
#define step20_39(i,a,b,c,d,e) \
W(i) = rol32(W(i-3)^W(i-8)^W(i-14)^W(i-16), 1); \
e += rol32(a,5) + F2(b,c,d) + 0x6ED9EBA1 + W(i); \
b = rol32(b,30)
#define step40_59(i,a,b,c,d,e) \
W(i) = rol32(W(i-3)^W(i-8)^W(i-14)^W(i-16), 1); \
e += rol32(a,5) + F3(b,c,d) + 0x8F1BBCDC + W(i); \
b = rol32(b,30)
#define step60_79(i,a,b,c,d,e) \
W(i) = rol32(W(i-3)^W(i-8)^W(i-14)^W(i-16), 1); \
e += rol32(a,5) + F4(b,c,d) + 0xCA62C1D6 + W(i); \
b = rol32(b,30)
void sha1_single_for_mh_sha1_ref(const uint8_t * data, uint32_t digest[])
{
uint32_t a, b, c, d, e;
uint32_t w[16] = { 0 };
uint32_t *ww = (uint32_t *) data;
a = digest[0];
b = digest[1];
c = digest[2];
d = digest[3];
e = digest[4];
step00_19(0, a, b, c, d, e);
step00_19(1, e, a, b, c, d);
step00_19(2, d, e, a, b, c);
step00_19(3, c, d, e, a, b);
step00_19(4, b, c, d, e, a);
step00_19(5, a, b, c, d, e);
step00_19(6, e, a, b, c, d);
step00_19(7, d, e, a, b, c);
step00_19(8, c, d, e, a, b);
step00_19(9, b, c, d, e, a);
step00_19(10, a, b, c, d, e);
step00_19(11, e, a, b, c, d);
step00_19(12, d, e, a, b, c);
step00_19(13, c, d, e, a, b);
step00_19(14, b, c, d, e, a);
step00_19(15, a, b, c, d, e);
step00_19(16, e, a, b, c, d);
( run in 0.549 second using v1.01-cache-2.11-cpan-ceb78f64989 )