blob: f29bbe0bfeb576e9275bb0d2a632423a94294109 [file] [log] [blame]
// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sha_test_vectors.h"
#include <base/logging.h>
namespace cryptohome {
const char* ShaTestVectors::kMultiBlockMessage =
"abcdbcdecdefdefgefghfghighijhijkijkl"
"jklmklmnlmnomnopnopq";
const char* ShaTestVectors::kOneBlockMessage = "abc";
const uint8_t ShaTestVectors::kSha1Results[][SHA_DIGEST_LENGTH] = {
{
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
}
};
const uint8_t ShaTestVectors::kSha256Results[][SHA256_DIGEST_LENGTH] = {
{
0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea,
0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23,
0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c,
0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad
},
{
0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8,
0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39,
0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67,
0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1
},
{
0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92,
0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67,
0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e,
0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0
}
};
ShaTestVectors::ShaTestVectors(int type) {
// Since we don't do 512+, we can prep here for all types and
// don't need to get fancy.
input_[0].resize(strlen(kOneBlockMessage));
memcpy(&(input_[0][0]), kOneBlockMessage, input_[0].size());
input_[1].resize(strlen(kMultiBlockMessage));
memcpy(&input_[1][0], kMultiBlockMessage, input_[1].size());
input_[2].assign(1000000, 'a');
switch (type) {
case 1:
for (size_t i = 0; i < count(); ++i) {
output_[i].resize(SHA_DIGEST_LENGTH);
memcpy(output_[i].data(), kSha1Results[i], output_[i].size());
}
break;
case 256:
for (size_t i = 0; i < count(); ++i) {
output_[i].resize(SHA256_DIGEST_LENGTH);
memcpy(output_[i].data(), kSha256Results[i], output_[i].size());
}
break;
default:
CHECK(false) << "Only SHA-256 and SHA-1 are supported";
}
}
} // namespace cryptohome