/*
* Copyright (C) 2005-2007, 2009, 2011-2018 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/*
* This code implements the HMAC-SHA1, HMAC-SHA224, HMAC-SHA256, HMAC-SHA384
* and HMAC-SHA512 keyed hash algorithm described in RFC 2104 and
*/
#include "config.h"
#include <isc/assertions.h>
#include <isc/platform.h>
#if PKCS11CRYPTO
#include <pk11/internal.h>
#endif
#ifdef ISC_PLATFORM_OPENSSLHASH
#endif
void
unsigned int len)
{
}
void
return;
}
void
unsigned int len)
{
}
void
}
void
unsigned int len)
{
}
void
return;
}
void
unsigned int len)
{
}
void
}
void
unsigned int len)
{
}
void
return;
}
void
unsigned int len)
{
}
void
}
void
unsigned int len)
{
}
void
return;
}
void
unsigned int len)
{
}
void
}
void
unsigned int len)
{
}
void
return;
}
void
unsigned int len)
{
}
void
}
#if defined(PK11_SHA_1_HMAC_REPLACE) || \
defined(PK11_SHA224_HMAC_REPLACE) || \
defined(PK11_SHA256_HMAC_REPLACE) || \
defined(PK11_SHA384_HMAC_REPLACE) || \
defined(PK11_SHA512_HMAC_REPLACE)
#endif
#if !defined(PK11_SHA_1_HMAC_REPLACE) && \
!defined(PK11_SHA224_HMAC_REPLACE) && \
!defined(PK11_SHA256_HMAC_REPLACE) && \
!defined(PK11_SHA384_HMAC_REPLACE) && \
!defined(PK11_SHA512_HMAC_REPLACE)
#endif
#ifndef PK11_SHA_1_HMAC_REPLACE
void
unsigned int len)
{
{
};
#ifdef PK11_PAD_HMAC_KEYS
if (len < ISC_SHA1_DIGESTLENGTH) {
} else
#else
#endif
}
void
return;
}
void
unsigned int len)
{
}
void
}
#else
void
unsigned int len)
{
unsigned int i;
!= NULL);
if (len > ISC_SHA1_BLOCK_LENGTH) {
} else
for (i = 0; i < ISC_SHA1_BLOCK_LENGTH; i++)
}
void
}
void
unsigned int len)
{
}
void
unsigned int i;
for (i = 0; i < ISC_SHA1_BLOCK_LENGTH; i++)
}
#endif
#ifndef PK11_SHA224_HMAC_REPLACE
void
unsigned int len)
{
{
};
#ifdef PK11_PAD_HMAC_KEYS
if (len < ISC_SHA224_DIGESTLENGTH) {
} else
#else
#endif
}
void
return;
}
void
unsigned int len)
{
}
void
}
#else
void
unsigned int len)
{
unsigned int i;
!= NULL);
if (len > ISC_SHA224_BLOCK_LENGTH) {
} else
for (i = 0; i < ISC_SHA224_BLOCK_LENGTH; i++)
}
void
}
void
unsigned int len)
{
}
void
unsigned int i;
for (i = 0; i < ISC_SHA224_BLOCK_LENGTH; i++)
}
#endif
#ifndef PK11_SHA256_HMAC_REPLACE
void
unsigned int len)
{
{
};
#ifdef PK11_PAD_HMAC_KEYS
if (len < ISC_SHA256_DIGESTLENGTH) {
} else
#else
#endif
}
void
return;
}
void
unsigned int len)
{
}
void
}
#else
void
unsigned int len)
{
unsigned int i;
!= NULL);
if (len > ISC_SHA256_BLOCK_LENGTH) {
} else
for (i = 0; i < ISC_SHA256_BLOCK_LENGTH; i++)
}
void
}
void
unsigned int len)
{
}
void
unsigned int i;
for (i = 0; i < ISC_SHA256_BLOCK_LENGTH; i++)
}
#endif
#ifndef PK11_SHA384_HMAC_REPLACE
void
unsigned int len)
{
{
};
#ifdef PK11_PAD_HMAC_KEYS
if (len < ISC_SHA384_DIGESTLENGTH) {
} else
#else
#endif
}
void
return;
}
void
unsigned int len)
{
}
void
}
#else
void
unsigned int len)
{
unsigned int i;
!= NULL);
if (len > ISC_SHA384_BLOCK_LENGTH) {
} else
for (i = 0; i < ISC_SHA384_BLOCK_LENGTH; i++)
}
void
}
void
unsigned int len)
{
}
void
unsigned int i;
for (i = 0; i < ISC_SHA384_BLOCK_LENGTH; i++)
}
#endif
#ifndef PK11_SHA512_HMAC_REPLACE
void
unsigned int len)
{
{
};
#ifdef PK11_PAD_HMAC_KEYS
if (len < ISC_SHA512_DIGESTLENGTH) {
} else
#else
#endif
}
void
return;
}
void
unsigned int len)
{
}
void
}
#else
void
unsigned int len)
{
unsigned int i;
!= NULL);
if (len > ISC_SHA512_BLOCK_LENGTH) {
} else
for (i = 0; i < ISC_SHA512_BLOCK_LENGTH; i++)
}
void
}
void
unsigned int len)
{
}
void
unsigned int i;
for (i = 0; i < ISC_SHA512_BLOCK_LENGTH; i++)
}
#endif
#else
/*
* Start HMAC-SHA1 process. Initialize an sha1 context and digest the key.
*/
void
unsigned int len)
{
unsigned int i;
} else
for (i = 0; i < ISC_SHA1_BLOCK_LENGTH; i++)
}
void
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
unsigned int len)
{
}
/*
* Compute signature - finalize SHA1 operation and reapply SHA1.
*/
void
unsigned int i;
for (i = 0; i < ISC_SHA1_BLOCK_LENGTH; i++)
}
/*
* Start HMAC-SHA224 process. Initialize an sha224 context and digest the key.
*/
void
unsigned int len)
{
unsigned int i;
} else
for (i = 0; i < ISC_SHA224_BLOCK_LENGTH; i++)
}
void
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
unsigned int len)
{
}
/*
* Compute signature - finalize SHA224 operation and reapply SHA224.
*/
void
unsigned int i;
for (i = 0; i < ISC_SHA224_BLOCK_LENGTH; i++)
}
/*
* Start HMAC-SHA256 process. Initialize an sha256 context and digest the key.
*/
void
unsigned int len)
{
unsigned int i;
} else
for (i = 0; i < ISC_SHA256_BLOCK_LENGTH; i++)
}
void
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
unsigned int len)
{
}
/*
* Compute signature - finalize SHA256 operation and reapply SHA256.
*/
void
unsigned int i;
for (i = 0; i < ISC_SHA256_BLOCK_LENGTH; i++)
}
/*
* Start HMAC-SHA384 process. Initialize an sha384 context and digest the key.
*/
void
unsigned int len)
{
unsigned int i;
} else
for (i = 0; i < ISC_SHA384_BLOCK_LENGTH; i++)
}
void
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
unsigned int len)
{
}
/*
* Compute signature - finalize SHA384 operation and reapply SHA384.
*/
void
unsigned int i;
for (i = 0; i < ISC_SHA384_BLOCK_LENGTH; i++)
}
/*
* Start HMAC-SHA512 process. Initialize an sha512 context and digest the key.
*/
void
unsigned int len)
{
unsigned int i;
} else
for (i = 0; i < ISC_SHA512_BLOCK_LENGTH; i++)
}
void
}
/*
* Update context to reflect the concatenation of another buffer full
* of bytes.
*/
void
unsigned int len)
{
}
/*
* Compute signature - finalize SHA512 operation and reapply SHA512.
*/
void
unsigned int i;
for (i = 0; i < ISC_SHA512_BLOCK_LENGTH; i++)
}
#endif /* !ISC_PLATFORM_OPENSSLHASH */
/*
* Verify signature - finalize SHA1 operation and reapply SHA1, then
* compare to the supplied digest.
*/
}
/*
* Verify signature - finalize SHA224 operation and reapply SHA224, then
* compare to the supplied digest.
*/
}
/*
* Verify signature - finalize SHA256 operation and reapply SHA256, then
* compare to the supplied digest.
*/
}
/*
* Verify signature - finalize SHA384 operation and reapply SHA384, then
* compare to the supplied digest.
*/
}
/*
* Verify signature - finalize SHA512 operation and reapply SHA512, then
* compare to the supplied digest.
*/
}
/*
* Check for SHA-1 support; if it does not work, raise a fatal error.
*
* Use the first test vector from RFC 2104, with a second round using
* a too-short key.
*
* Standard use is testing 0 and expecting result true.
* Testing use is testing 1..4 and expecting result false.
*/
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b
};
0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65
};
unsigned char expected[] = {
0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64,
0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e,
0xf1, 0x46, 0xbe, 0x00
};
unsigned char expected2[] = {
0xa0, 0x75, 0xe0, 0x5f, 0x7f, 0x17, 0x9d, 0x34,
0xb2, 0xab, 0xc5, 0x19, 0x8f, 0x38, 0x62, 0x36,
0x42, 0xbd, 0xec, 0xde
};
/*
* Introduce a fault for testing.
*/
switch (testing) {
case 0:
default:
break;
case 1:
key[0] ^= 0x01;
break;
case 2:
input[0] ^= 0x01;
break;
case 3:
expected[0] ^= 0x01;
break;
case 4:
expected2[0] ^= 0x01;
break;
}
/*
* These functions do not return anything; any failure will be fatal.
*/
if (!result) {
return (result);
}
/* Second round using a byte key */
}