blob: f15f5813121cd2aad1e4e0cb147a4a5128737a65 [file] [log] [blame]
/*
*
* Copyright (c) 2013-2017 Nest Labs, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file implements interface to Weave Crypto SHA Tests library.
*
*/
#include <string.h>
#include <nltest.h>
#include <Weave/Support/crypto/HashAlgos.h>
#include <Weave/Support/crypto/CTRMode.h>
#include "WeaveCryptoTests.h"
using namespace nl::Weave::Crypto;
using namespace nl::Weave::Platform::Security;
static void Check_SHA1_Test1(nlTestSuite *inSuite, void *inContext)
{
// This code implements the SHA1 test driver from RFC-3174.
#define TEST1 "abc"
#define TEST2a "abcdbcdecdefdefgefghfghighijhi"
#define TEST2b "jkijkljklmklmnlmnomnopnopq"
#define TEST2 TEST2a TEST2b
#define TEST3 "a"
#define TEST4a "01234567012345670123456701234567"
#define TEST4b "01234567012345670123456701234567"
#define TEST4 TEST4a TEST4b
static const char *testarray[4] =
{
TEST1,
TEST2,
TEST3,
TEST4
};
static long int repeatcount[4] = { 1, 1, 1000000, 10 };
static uint8_t resultarray[][SHA1::kHashLength] =
{
{ 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D },
{ 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 },
{ 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E, 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F },
{ 0xDE, 0xA3, 0x56, 0xA2, 0xCD, 0xDD, 0x90, 0xC7, 0xA7, 0xEC, 0xED, 0xC5, 0xEB, 0xB5, 0x63, 0x93, 0x4F, 0x46, 0x04, 0x52 }
};
nl::Weave::Platform::Security::SHA1 sha1;
uint8_t hashBuf[SHA1::kHashLength];
for (int j = 0; j < 4; ++j)
{
sha1.Begin();
for (int i = 0; i < repeatcount[j]; ++i)
sha1.AddData((const uint8_t *) testarray[j], strlen(testarray[j]));
sha1.Finish(hashBuf);
// Invalid SHA1 result
NL_TEST_ASSERT(inSuite, memcmp(hashBuf, resultarray[j], SHA1::kHashLength) == 0);
}
}
#if WEAVE_WITH_OPENSSL
void GenBigNumHashes(nlTestSuite *inSuite, const uint8_t *numData, size_t numDataLen, bool negative, uint8_t *expectedHashBuf, uint8_t *actualHashBuf)
{
nl::Weave::Platform::Security::SHA1 sha1;
BIGNUM *bn = NULL;
static uint8_t positiveSignByte = 0;
static uint8_t negativeSignByte = 0xFF;
bn = BN_new();
NL_TEST_ASSERT(inSuite, bn != NULL);
BN_bin2bn(numData, numDataLen, bn);
if (BN_is_zero(bn))
negative = false;
else if (negative)
BN_set_negative(bn, 1);
sha1.Begin();
if (negative)
sha1.AddData(&negativeSignByte, 1);
else
sha1.AddData(&positiveSignByte, 1);
sha1.AddData(numData, numDataLen);
sha1.Finish(expectedHashBuf);
sha1.Begin();
sha1.AddData(*bn);
sha1.Finish(actualHashBuf);
BN_free(bn);
}
static void Check_SHA1_Test2(nlTestSuite *inSuite, void *inContext)
{
// Tests hashing of BIGNUMs.
uint8_t expectedHashBuf[SHA1::kHashLength];
uint8_t actualHashBuf[SHA1::kHashLength];
static uint8_t testValue1[] = { 0x0 };
static uint8_t testValue2[] = { 0x42 };
static uint8_t testValue3[] = { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E, 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F };
GenBigNumHashes(inSuite, testValue1, sizeof(testValue1), false, expectedHashBuf, actualHashBuf);
// Invalid SHA1 hash of BIGNUM (testValue1)
NL_TEST_ASSERT(inSuite, memcmp(actualHashBuf, expectedHashBuf, SHA1::kHashLength) == 0);
GenBigNumHashes(inSuite, testValue1, sizeof(testValue1), true, expectedHashBuf, actualHashBuf);
// Invalid SHA1 hash of BIGNUM (testValue1 negative)
NL_TEST_ASSERT(inSuite, memcmp(actualHashBuf, expectedHashBuf, SHA1::kHashLength) == 0);
GenBigNumHashes(inSuite, testValue2, sizeof(testValue2), false, expectedHashBuf, actualHashBuf);
// Invalid SHA1 hash of BIGNUM (testValue2)
NL_TEST_ASSERT(inSuite, memcmp(actualHashBuf, expectedHashBuf, SHA1::kHashLength) == 0);
GenBigNumHashes(inSuite, testValue2, sizeof(testValue2), true, expectedHashBuf, actualHashBuf);
// Invalid SHA1 hash of BIGNUM (testValue2 negative)
NL_TEST_ASSERT(inSuite, memcmp(actualHashBuf, expectedHashBuf, SHA1::kHashLength) == 0);
GenBigNumHashes(inSuite, testValue3, sizeof(testValue3), false, expectedHashBuf, actualHashBuf);
// Invalid SHA1 hash of BIGNUM (testValue3)
NL_TEST_ASSERT(inSuite, memcmp(actualHashBuf, expectedHashBuf, SHA1::kHashLength) == 0);
GenBigNumHashes(inSuite, testValue3, sizeof(testValue3), true, expectedHashBuf, actualHashBuf);
// Invalid SHA1 hash of BIGNUM (testValue3 negative)
NL_TEST_ASSERT(inSuite, memcmp(actualHashBuf, expectedHashBuf, SHA1::kHashLength) == 0);
}
#endif // WEAVE_WITH_OPENSSL
static void Check_SHA1_Test3(nlTestSuite *inSuite, void *inContext)
{
// This code implements selected tests from NIST Cryptographic Algorithm Validation Program (CAVP)
// "SHA Test Vectors for Hashing Byte-Oriented Messages" (http://csrc.nist.gov/groups/STM/cavp/index.html).
// SHA-1 ShortMsg 8
static const uint8_t ShortMsg8[] =
{
0x36
};
static const uint8_t ShortMsg8Result[] =
{
0xc1, 0xdf, 0xd9, 0x6e, 0xea, 0x8c, 0xc2, 0xb6, 0x27, 0x85, 0x27, 0x5b, 0xca, 0x38, 0xac, 0x26, 0x12, 0x56, 0xe2, 0x78
};
// SHA-1 ShortMsg 72
static const uint8_t ShortMsg72[] =
{
0x9e, 0x61, 0xe5, 0x5d, 0x9e, 0xd3, 0x7b, 0x1c, 0x20
};
static const uint8_t ShortMsg72Result[] =
{
0x41, 0x1c, 0xce, 0xe1, 0xf6, 0xe3, 0x67, 0x7d, 0xf1, 0x26, 0x98, 0x41, 0x1e, 0xb0, 0x9d, 0x3f, 0xf5, 0x80, 0xaf, 0x97
};
// SHA-1 ShortMsg 168
static const uint8_t ShortMsg168[] =
{
0x87, 0x5a, 0x90, 0x90, 0x9a, 0x8a, 0xfc, 0x92, 0xfb, 0x70, 0x70, 0x04, 0x7e, 0x9d, 0x08, 0x1e, 0xc9, 0x2f, 0x3d, 0x08,
0xb8
};
static const uint8_t ShortMsg168Result[] =
{
0xb4, 0x86, 0xf8, 0x7f, 0xb8, 0x33, 0xeb, 0xf0, 0x32, 0x83, 0x93, 0x12, 0x86, 0x46, 0xa6, 0xf6, 0xe6, 0x60, 0xfc, 0xb1
};
// SHA-1 ShortMsg 512
static const uint8_t ShortMsg512[] =
{
0x45, 0x92, 0x7e, 0x32, 0xdd, 0xf8, 0x01, 0xca, 0xf3, 0x5e, 0x18, 0xe7, 0xb5, 0x07, 0x8b, 0x7f, 0x54, 0x35, 0x27, 0x82,
0x12, 0xec, 0x6b, 0xb9, 0x9d, 0xf8, 0x84, 0xf4, 0x9b, 0x32, 0x7c, 0x64, 0x86, 0xfe, 0xae, 0x46, 0xba, 0x18, 0x7d, 0xc1,
0xcc, 0x91, 0x45, 0x12, 0x1e, 0x14, 0x92, 0xe6, 0xb0, 0x6e, 0x90, 0x07, 0x39, 0x4d, 0xc3, 0x3b, 0x77, 0x48, 0xf8, 0x6a,
0xc3, 0x20, 0x7c, 0xfe
};
static const uint8_t ShortMsg512Result[] =
{
0xa7, 0x0c, 0xfb, 0xfe, 0x75, 0x63, 0xdd, 0x0e, 0x66, 0x5c, 0x7c, 0x67, 0x15, 0xa9, 0x6a, 0x8d, 0x75, 0x69, 0x50, 0xc0
};
// SHA-1 LongMsg 1304
static const uint8_t LongMsg1304[] =
{
0x7c, 0x9c, 0x67, 0x32, 0x3a, 0x1d, 0xf1, 0xad, 0xbf, 0xe5, 0xce, 0xb4, 0x15, 0xea, 0xef, 0x01, 0x55, 0xec, 0xe2, 0x82,
0x0f, 0x4d, 0x50, 0xc1, 0xec, 0x22, 0xcb, 0xa4, 0x92, 0x8a, 0xc6, 0x56, 0xc8, 0x3f, 0xe5, 0x85, 0xdb, 0x6a, 0x78, 0xce,
0x40, 0xbc, 0x42, 0x75, 0x7a, 0xba, 0x7e, 0x5a, 0x3f, 0x58, 0x24, 0x28, 0xd6, 0xca, 0x68, 0xd0, 0xc3, 0x97, 0x83, 0x36,
0xa6, 0xef, 0xb7, 0x29, 0x61, 0x3e, 0x8d, 0x99, 0x79, 0x01, 0x62, 0x04, 0xbf, 0xd9, 0x21, 0x32, 0x2f, 0xdd, 0x52, 0x22,
0x18, 0x35, 0x54, 0x44, 0x7d, 0xe5, 0xe6, 0xe9, 0xbb, 0xe6, 0xed, 0xf7, 0x6d, 0x7b, 0x71, 0xe1, 0x8d, 0xc2, 0xe8, 0xd6,
0xdc, 0x89, 0xb7, 0x39, 0x83, 0x64, 0xf6, 0x52, 0xfa, 0xfc, 0x73, 0x43, 0x29, 0xaa, 0xfa, 0x3d, 0xcd, 0x45, 0xd4, 0xf3,
0x1e, 0x38, 0x8e, 0x4f, 0xaf, 0xd7, 0xfc, 0x64, 0x95, 0xf3, 0x7c, 0xa5, 0xcb, 0xab, 0x7f, 0x54, 0xd5, 0x86, 0x46, 0x3d,
0xa4, 0xbf, 0xea, 0xa3, 0xba, 0xe0, 0x9f, 0x7b, 0x8e, 0x92, 0x39, 0xd8, 0x32, 0xb4, 0xf0, 0xa7, 0x33, 0xaa, 0x60, 0x9c,
0xc1, 0xf8, 0xd4
};
static const uint8_t LongMsg1304Result[] =
{
0xd8, 0xfd, 0x6a, 0x91, 0xef, 0x3b, 0x6c, 0xed, 0x05, 0xb9, 0x83, 0x58, 0xa9, 0x91, 0x07, 0xc1, 0xfa, 0xc8, 0xc8, 0x07
};
// SHA-1 LongMsg 6056
static const uint8_t LongMsg6056[] =
{
0xa5, 0x04, 0x5d, 0x24, 0xd0, 0x75, 0x78, 0xca, 0x31, 0x98, 0x7d, 0xb3, 0xd2, 0xe2, 0x5e, 0x12, 0xea, 0x38, 0xbb, 0x1d,
0xa7, 0xa8, 0xbd, 0x64, 0x2a, 0x57, 0x42, 0x61, 0xd4, 0xba, 0x3a, 0x50, 0xc0, 0x09, 0x50, 0x41, 0x90, 0xf1, 0xce, 0x6b,
0x6d, 0x8a, 0xba, 0xc3, 0x49, 0x88, 0x45, 0xcd, 0x67, 0xb5, 0x67, 0xb2, 0x1e, 0x9f, 0xc3, 0x94, 0xda, 0x8d, 0xd0, 0x1e,
0x63, 0xb8, 0x3a, 0x5f, 0x62, 0xb8, 0x86, 0xd8, 0x21, 0x3d, 0xf6, 0xd3, 0x92, 0xff, 0xac, 0xf7, 0x93, 0xf8, 0x11, 0x1a,
0x70, 0xd0, 0x78, 0x56, 0xa9, 0x99, 0xff, 0x5f, 0xf6, 0xbc, 0xb6, 0x13, 0x89, 0x33, 0x04, 0x53, 0x93, 0xf9, 0x46, 0x12,
0x09, 0xbf, 0xb8, 0xab, 0xa8, 0xe1, 0x99, 0x78, 0x37, 0x98, 0x8a, 0xa0, 0x0c, 0x71, 0x38, 0x30, 0xd1, 0xfe, 0x3a, 0x6e,
0x88, 0xcb, 0x3d, 0x6a, 0xcd, 0x93, 0x5e, 0xd5, 0x5b, 0xb4, 0xd7, 0x16, 0xd2, 0xe1, 0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c8, 0x17, 0xa3, 0x07, 0x70, 0x67, 0x1b, 0xa7, 0xbd, 0x39, 0xbb, 0xc7, 0xa0, 0x0b, 0x18,
0x77, 0x77, 0x10, 0xa8, 0x26, 0x84, 0xd5, 0xd6, 0x69, 0x9e, 0x24, 0x52, 0xf8, 0x26, 0x29, 0xab, 0xf9, 0x3d, 0xd3, 0x1f,
0x82, 0x34, 0x7d, 0xb2, 0x59, 0x44, 0xce, 0x7d, 0xfe, 0x80, 0xdd, 0x49, 0xeb, 0x07, 0x99, 0x5c, 0x1a, 0x7e, 0x69, 0x93,
0xc8, 0xbe, 0x0f, 0xb1, 0x79, 0xc9, 0xd2, 0xf7, 0x3c, 0x03, 0xdc, 0xf5, 0x30, 0x9f, 0xe1, 0x9f, 0x47
};
static const uint8_t LongMsg6056Result[] =
{
0xdd, 0x43, 0x74, 0xe2, 0x9b, 0x17, 0xe2, 0xec, 0x53, 0x38, 0x13, 0xfe, 0xdd, 0xc5, 0x25, 0x37, 0x65, 0xcd, 0x37, 0xac
};
nl::Weave::Platform::Security::SHA1 sha1;
uint8_t hashBuf[SHA1::kHashLength];
sha1.Begin();
sha1.AddData(ShortMsg8, sizeof(ShortMsg8));
sha1.Finish(hashBuf);
// Invalid SHA1 result (ShortMsg8)
NL_TEST_ASSERT(inSuite, memcmp(hashBuf, ShortMsg8Result, SHA1::kHashLength) == 0);
sha1.Begin();
sha1.AddData(ShortMsg72, sizeof(ShortMsg72));
sha1.Finish(hashBuf);
// Invalid SHA1 result (ShortMsg72)
NL_TEST_ASSERT(inSuite, memcmp(hashBuf, ShortMsg72Result, SHA1::kHashLength) == 0);
sha1.Begin();
sha1.AddData(ShortMsg168, sizeof(ShortMsg168));
sha1.Finish(hashBuf);
// Invalid SHA1 result (ShortMsg168)
NL_TEST_ASSERT(inSuite, memcmp(hashBuf, ShortMsg168Result, SHA1::kHashLength) == 0);
sha1.Begin();
sha1.AddData(ShortMsg512, sizeof(ShortMsg512));
sha1.Finish(hashBuf);
// Invalid SHA1 result (ShortMsg512)
NL_TEST_ASSERT(inSuite, memcmp(hashBuf, ShortMsg512Result, SHA1::kHashLength) == 0);
sha1.Begin();
sha1.AddData(LongMsg1304, sizeof(LongMsg1304));
sha1.Finish(hashBuf);
// Invalid SHA1 result (LongMsg1304)
NL_TEST_ASSERT(inSuite, memcmp(hashBuf, LongMsg1304Result, SHA1::kHashLength) == 0);
sha1.Begin();
sha1.AddData(LongMsg6056, sizeof(LongMsg6056));
sha1.Finish(hashBuf);
// Invalid SHA1 result (LongMsg6056)
NL_TEST_ASSERT(inSuite, memcmp(hashBuf, LongMsg6056Result, SHA1::kHashLength) == 0);
}
static const nlTest sTests[] = {
NL_TEST_DEF("SHA1 Test1", Check_SHA1_Test1),
#if WEAVE_WITH_OPENSSL
NL_TEST_DEF("SHA1 Test2", Check_SHA1_Test2),
#endif
NL_TEST_DEF("SHA1 Test3", Check_SHA1_Test3),
NL_TEST_SENTINEL()
};
int WeaveCryptoSHATests(void)
{
nlTestSuite theSuite = {
"Weave Crypto SHA Tests",
&sTests[0]
};
nl_test_set_output_style(OUTPUT_CSV);
nlTestRunner(&theSuite, NULL);
return nlTestRunnerStats(&theSuite);
}