Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: crypto/openpgp_symmetric_encryption_test_openssl.cc

Issue 7247005: crypto: add OpenPGP symmetric encryption for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "crypto/openpgp_symmetric_encryption.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace crypto {
10
11 // AES-128, GPG
Greg Spencer (Chromium) 2011/06/23 20:55:00 Are these "official" test vectors? If so, it migh
agl 2011/06/27 20:42:53 Done.
12 static const uint8 kTestMessage1[] = {
13 0x8c, 0x0d, 0x04, 0x07, 0x03, 0x02, 0x69, 0x24, 0xaf, 0xbf, 0x0b, 0x31, 0x98,
14 0x6d, 0x60, 0xd2, 0x3d, 0x01, 0xc4, 0x29, 0xab, 0xec, 0x1b, 0xdf, 0xfa, 0x90,
15 0x86, 0x92, 0x94, 0xc7, 0xa5, 0xe7, 0xd8, 0x80, 0x0a, 0x55, 0x3e, 0xbd, 0x10,
16 0xef, 0x40, 0xfe, 0xb7, 0x39, 0x83, 0x4e, 0x5e, 0x77, 0x9d, 0x57, 0x94, 0xb6,
17 0xe4, 0x59, 0xa7, 0x32, 0x76, 0x22, 0x48, 0xed, 0x37, 0xe8, 0x6f, 0xf9, 0x80,
18 0x04, 0xa1, 0xe4, 0xbf, 0x40, 0xa6, 0x9b, 0xd1, 0x3e, 0xba, 0xaa, 0x52, 0xd0,
19 };
20
21 // AES-256, GPG
22 static const uint8 kTestMessage2[] = {
23 0x8c, 0x0d, 0x04, 0x09, 0x03, 0x02, 0xd6, 0xb0, 0x34, 0xa0, 0xb8, 0x6c, 0x15,
24 0xb8, 0x60, 0xd2, 0x3d, 0x01, 0x97, 0xe4, 0x46, 0x56, 0xc5, 0xc9, 0xc7, 0x81,
25 0xd1, 0x09, 0xf3, 0xa0, 0x5d, 0x3b, 0xa7, 0xe3, 0x68, 0xb4, 0x19, 0xd2, 0x76,
26 0x83, 0x38, 0x13, 0x98, 0xb8, 0xaf, 0x54, 0x51, 0x52, 0xbb, 0xc5, 0x7d, 0x8a,
27 0x70, 0x66, 0x40, 0x0b, 0xb5, 0x92, 0xc3, 0xd3, 0x51, 0x63, 0x5d, 0x99, 0x9b,
28 0x96, 0x82, 0xe1, 0xfe, 0xac, 0xa8, 0xa5, 0x87, 0x8b, 0x3f, 0xd1, 0x90, 0x70,
29 };
30
31 // AES-128, Go
32 static const uint8 kTestMessage3[] = {
33 0xc3, 0x1e, 0x04, 0x07, 0x03, 0x02, 0x74, 0x1e, 0x2d, 0x7d, 0x2e, 0xdf, 0x20,
34 0xdb, 0x60, 0xb1, 0x22, 0xca, 0x39, 0x74, 0x2f, 0xe8, 0x2f, 0x09, 0xf8, 0xa4,
35 0x13, 0x76, 0x14, 0x65, 0x6e, 0xb9, 0xd2, 0xe0, 0x01, 0xe4, 0x40, 0x83, 0x90,
36 0x3c, 0x76, 0xac, 0x23, 0x3e, 0xd2, 0xb0, 0xb2, 0x1c, 0x9d, 0x24, 0xcb, 0x7b,
37 0xe1, 0x0c, 0x6b, 0xe0, 0x86, 0xe0, 0x22, 0xe1, 0xf2, 0xcb, 0xe0, 0xf3, 0xe2,
38 0xbf, 0xdd, 0x89, 0xda, 0xe0, 0x83, 0xe3, 0xd9, 0x34, 0xf9, 0xaa, 0x17, 0x96,
39 0x6a, 0x28, 0xe0, 0xca, 0xe2, 0x78, 0xca, 0x0e, 0x7d, 0xe0, 0xeb, 0xe4, 0xca,
40 0xe6, 0xf0, 0x90, 0x4f, 0x22, 0x91, 0xf9, 0xb2, 0xbb, 0x19, 0x0b, 0x45, 0xc0,
41 0x16, 0x9e, 0xe2, 0xdb, 0x30, 0xad, 0xbb, 0xe1, 0xb8, 0x12, 0x00,
42 };
43
44 // AES-128, salted S2K, GPG
45 static const uint8 kTestMessage4[] = {
46 0x8c, 0x0c, 0x04, 0x07, 0x01, 0x02, 0xf8, 0x42, 0x78, 0x07, 0x04, 0xaa, 0x54,
47 0xcc, 0xd2, 0x3d, 0x01, 0xcf, 0xb7, 0x30, 0xe1, 0xed, 0xb2, 0x53, 0x6e, 0x4a,
48 0xbc, 0x49, 0x27, 0x45, 0xde, 0x1d, 0x5b, 0xe2, 0x17, 0x43, 0x39, 0x79, 0xdc,
49 0xa5, 0xb7, 0x1a, 0x1b, 0xb7, 0x29, 0x9c, 0xb5, 0x69, 0x2f, 0x42, 0xc5, 0xe5,
50 0x0c, 0x78, 0x57, 0x16, 0xa6, 0x46, 0x22, 0x18, 0x0c, 0xa2, 0xb3, 0x8c, 0xee,
51 0xa1, 0xde, 0x38, 0xf1, 0xca, 0x73, 0xd3, 0xd6, 0xa3, 0x61, 0x47, 0xe2,
52 };
53
54 TEST(OpenPGPSymmetricEncrytionTest, AES128GPG) {
55 base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage1),
56 sizeof(kTestMessage1));
57 std::string out;
58
59 OpenPGPSymmetricEncrytion::Result r =
60 OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
61 EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
62 EXPECT_EQ("Hello world\n", out);
63 }
64
65 TEST(OpenPGPSymmetricEncrytionTest, AES256GPG) {
66 base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage2),
67 sizeof(kTestMessage2));
68 std::string out;
69
70 OpenPGPSymmetricEncrytion::Result r =
71 OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
72 EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
73 EXPECT_EQ("Hello world\n", out);
74 }
75
76 TEST(OpenPGPSymmetricEncrytionTest, AES128Go) {
77 base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage3),
78 sizeof(kTestMessage3));
79 std::string out;
80
81 OpenPGPSymmetricEncrytion::Result r =
82 OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
83 EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
84 EXPECT_EQ("Hello world\n", out);
85 }
86
87 TEST(OpenPGPSymmetricEncrytionTest, SaltedS2K) {
88 base::StringPiece encrypted(reinterpret_cast<const char*>(kTestMessage4),
89 sizeof(kTestMessage4));
90 std::string out;
91
92 OpenPGPSymmetricEncrytion::Result r =
93 OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
94 EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
95 EXPECT_EQ("Hello world\n", out);
96 }
97
98 TEST(OpenPGPSymmetricEncrytionTest, Encrypt) {
99 for (unsigned i = 0; i < 16; i++) {
100 std::string encrypted =
101 OpenPGPSymmetricEncrytion::Encrypt("Hello world\n", "testing");
102
103 std::string out;
104 OpenPGPSymmetricEncrytion::Result r =
105 OpenPGPSymmetricEncrytion::Decrypt(encrypted, "testing", &out);
106 EXPECT_EQ(OpenPGPSymmetricEncrytion::OK, r);
107 EXPECT_EQ("Hello world\n", out);
108 }
109 }
110
111 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698