| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string.h> | 5 #include <string.h> |
| 6 | 6 |
| 7 #include "net/http/des.h" | 7 #include "net/http/des.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 // This test vector comes from the NSS FIPS power-up self-test. | 12 // This test vector comes from the NSS FIPS power-up self-test. |
| 13 TEST(DESTest, KnownAnswerTest1) { | 13 TEST(DESTest, KnownAnswerTest1) { |
| 14 // DES known key (56-bits). | 14 // DES known key (56-bits). |
| 15 static const uint8 des_known_key[] = "ANSI DES"; | 15 static const uint8_t des_known_key[] = "ANSI DES"; |
| 16 | 16 |
| 17 // DES known plaintext (64-bits). | 17 // DES known plaintext (64-bits). |
| 18 static const uint8 des_ecb_known_plaintext[] = "Netscape"; | 18 static const uint8_t des_ecb_known_plaintext[] = "Netscape"; |
| 19 | 19 |
| 20 // DES known ciphertext (64-bits). | 20 // DES known ciphertext (64-bits). |
| 21 static const uint8 des_ecb_known_ciphertext[] = { | 21 static const uint8_t des_ecb_known_ciphertext[] = {0x26, 0x14, 0xe9, 0xc3, |
| 22 0x26, 0x14, 0xe9, 0xc3, 0x28, 0x80, 0x50, 0xb0 | 22 0x28, 0x80, 0x50, 0xb0}; |
| 23 }; | |
| 24 | 23 |
| 25 uint8 ciphertext[8]; | 24 uint8_t ciphertext[8]; |
| 26 memset(ciphertext, 0xaf, sizeof(ciphertext)); | 25 memset(ciphertext, 0xaf, sizeof(ciphertext)); |
| 27 | 26 |
| 28 DESEncrypt(des_known_key, des_ecb_known_plaintext, ciphertext); | 27 DESEncrypt(des_known_key, des_ecb_known_plaintext, ciphertext); |
| 29 EXPECT_EQ(0, memcmp(ciphertext, des_ecb_known_ciphertext, 8)); | 28 EXPECT_EQ(0, memcmp(ciphertext, des_ecb_known_ciphertext, 8)); |
| 30 } | 29 } |
| 31 | 30 |
| 32 // This test vector comes from NIST Special Publication 800-17, Modes of | 31 // This test vector comes from NIST Special Publication 800-17, Modes of |
| 33 // Operation Validation System (MOVS): Requirements and Procedures, Appendix | 32 // Operation Validation System (MOVS): Requirements and Procedures, Appendix |
| 34 // A, page 124. | 33 // A, page 124. |
| 35 TEST(DESTest, KnownAnswerTest2) { | 34 TEST(DESTest, KnownAnswerTest2) { |
| 36 static const uint8 key[] = { | 35 static const uint8_t key[] = {0x10, 0x31, 0x6e, 0x02, 0x8c, 0x8f, 0x3b, 0x4a}; |
| 37 0x10, 0x31, 0x6e, 0x02, 0x8c, 0x8f, 0x3b, 0x4a | 36 static const uint8_t plaintext[] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 38 }; | 37 static const uint8_t known_ciphertext[] = {0x82, 0xdc, 0xba, 0xfb, |
| 39 static const uint8 plaintext[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | 38 0xde, 0xab, 0x66, 0x02}; |
| 40 static const uint8 known_ciphertext[] = { | 39 uint8_t ciphertext[8]; |
| 41 0x82, 0xdc, 0xba, 0xfb, 0xde, 0xab, 0x66, 0x02 | |
| 42 }; | |
| 43 uint8 ciphertext[8]; | |
| 44 memset(ciphertext, 0xaf, sizeof(ciphertext)); | 40 memset(ciphertext, 0xaf, sizeof(ciphertext)); |
| 45 | 41 |
| 46 DESEncrypt(key, plaintext, ciphertext); | 42 DESEncrypt(key, plaintext, ciphertext); |
| 47 EXPECT_EQ(0, memcmp(ciphertext, known_ciphertext, 8)); | 43 EXPECT_EQ(0, memcmp(ciphertext, known_ciphertext, 8)); |
| 48 } | 44 } |
| 49 | 45 |
| 50 } // namespace net | 46 } // namespace net |
| OLD | NEW |