/src/mozilla-central/security/manager/ssl/tests/gtest/MD4Test.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | // This file tests the md4.c implementation. |
8 | | |
9 | | #include "gtest/gtest.h" |
10 | | #include "md4.h" |
11 | | #include "mozilla/ArrayUtils.h" |
12 | | #include "mozilla/Casting.h" |
13 | | |
14 | | struct RFC1320TestParams |
15 | | { |
16 | | const char* data; |
17 | | const uint8_t expectedHash[16]; |
18 | | }; |
19 | | |
20 | | static const RFC1320TestParams RFC1320_TEST_PARAMS[] = |
21 | | { |
22 | | { |
23 | | "", |
24 | | { 0x31, 0xd6, 0xcf, 0xe0, 0xd1, 0x6a, 0xe9, 0x31, |
25 | | 0xb7, 0x3c, 0x59, 0xd7, 0xe0, 0xc0, 0x89, 0xc0 } |
26 | | }, |
27 | | { |
28 | | "a", |
29 | | { 0xbd, 0xe5, 0x2c, 0xb3, 0x1d, 0xe3, 0x3e, 0x46, |
30 | | 0x24, 0x5e, 0x05, 0xfb, 0xdb, 0xd6, 0xfb, 0x24 } |
31 | | }, |
32 | | { |
33 | | "abc", |
34 | | { 0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52, |
35 | | 0x5f, 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d } |
36 | | }, |
37 | | { |
38 | | "message digest", |
39 | | { 0xd9, 0x13, 0x0a, 0x81, 0x64, 0x54, 0x9f, 0xe8, |
40 | | 0x18, 0x87, 0x48, 0x06, 0xe1, 0xc7, 0x01, 0x4b } |
41 | | }, |
42 | | { |
43 | | "abcdefghijklmnopqrstuvwxyz", |
44 | | { 0xd7, 0x9e, 0x1c, 0x30, 0x8a, 0xa5, 0xbb, 0xcd, |
45 | | 0xee, 0xa8, 0xed, 0x63, 0xdf, 0x41, 0x2d, 0xa9 }, |
46 | | }, |
47 | | { |
48 | | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", |
49 | | { 0x04, 0x3f, 0x85, 0x82, 0xf2, 0x41, 0xdb, 0x35, |
50 | | 0x1c, 0xe6, 0x27, 0xe1, 0x53, 0xe7, 0xf0, 0xe4 }, |
51 | | }, |
52 | | { |
53 | | "12345678901234567890123456789012345678901234567890123456789012345678901234567890", |
54 | | { 0xe3, 0x3b, 0x4d, 0xdc, 0x9c, 0x38, 0xf2, 0x19, |
55 | | 0x9c, 0x3e, 0x7b, 0x16, 0x4f, 0xcc, 0x05, 0x36 }, |
56 | | } |
57 | | }; |
58 | | |
59 | | class psm_MD4 |
60 | | : public ::testing::Test |
61 | | , public ::testing::WithParamInterface<RFC1320TestParams> |
62 | | { |
63 | | }; |
64 | | |
65 | | TEST_P(psm_MD4, RFC1320TestValues) |
66 | 0 | { |
67 | 0 | const RFC1320TestParams& params(GetParam()); |
68 | 0 | uint8_t actualHash[16]; |
69 | 0 | md4sum(mozilla::BitwiseCast<const uint8_t*, const char*>(params.data), |
70 | 0 | strlen(params.data), actualHash); |
71 | 0 | EXPECT_TRUE(mozilla::ArrayEqual(actualHash, params.expectedHash)) |
72 | 0 | << "MD4 hashes aren't equal for input: '" << params.data << "'"; |
73 | 0 | } |
74 | | |
75 | | INSTANTIATE_TEST_CASE_P(psm_MD4, psm_MD4, |
76 | | testing::ValuesIn(RFC1320_TEST_PARAMS)); |