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

Side by Side Diff: crypto/p224_spake_unittest.cc

Issue 8903001: Simplify SPAKE2 implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years 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
« no previous file with comments | « crypto/p224_spake.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 <crypto/p224_spake.h> 5 #include <crypto/p224_spake.h>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using namespace crypto; 10 using namespace crypto;
(...skipping 25 matching lines...) Expand all
36 server_result == P224EncryptedKeyExchange::kResultSuccess) { 36 server_result == P224EncryptedKeyExchange::kResultSuccess) {
37 return true; 37 return true;
38 } 38 }
39 39
40 CHECK_EQ(P224EncryptedKeyExchange::kResultPending, client_result); 40 CHECK_EQ(P224EncryptedKeyExchange::kResultPending, client_result);
41 CHECK_EQ(P224EncryptedKeyExchange::kResultPending, server_result); 41 CHECK_EQ(P224EncryptedKeyExchange::kResultPending, server_result);
42 } 42 }
43 } 43 }
44 44
45 static const char kPassword[] = "foo"; 45 static const char kPassword[] = "foo";
46 static const char kSession[] = "bar";
47 46
48 TEST(MutualAuth, CorrectAuth) { 47 TEST(MutualAuth, CorrectAuth) {
49 P224EncryptedKeyExchange client( 48 P224EncryptedKeyExchange client(
50 P224EncryptedKeyExchange::kPeerTypeClient, 49 P224EncryptedKeyExchange::kPeerTypeClient, kPassword);
51 kPassword, kSession);
52 P224EncryptedKeyExchange server( 50 P224EncryptedKeyExchange server(
53 P224EncryptedKeyExchange::kPeerTypeServer, 51 P224EncryptedKeyExchange::kPeerTypeServer, kPassword);
54 kPassword, kSession);
55 52
56 EXPECT_TRUE(RunExchange(&client, &server)); 53 EXPECT_TRUE(RunExchange(&client, &server));
54 EXPECT_EQ(client.GetKey(), server.GetKey());
57 } 55 }
58 56
59 TEST(MutualAuth, IncorrectPassword) { 57 TEST(MutualAuth, IncorrectPassword) {
60 P224EncryptedKeyExchange client( 58 P224EncryptedKeyExchange client(
61 P224EncryptedKeyExchange::kPeerTypeClient, 59 P224EncryptedKeyExchange::kPeerTypeClient,
62 kPassword, kSession); 60 kPassword);
63 P224EncryptedKeyExchange server( 61 P224EncryptedKeyExchange server(
64 P224EncryptedKeyExchange::kPeerTypeServer, 62 P224EncryptedKeyExchange::kPeerTypeServer,
65 "wrongpassword", kSession); 63 "wrongpassword");
66 64
67 EXPECT_FALSE(RunExchange(&client, &server)); 65 EXPECT_FALSE(RunExchange(&client, &server));
68 } 66 }
69
70 TEST(MutualAuth, IncorrectSession) {
71 P224EncryptedKeyExchange client(
72 P224EncryptedKeyExchange::kPeerTypeClient,
73 kPassword, kSession);
74 P224EncryptedKeyExchange server(
75 P224EncryptedKeyExchange::kPeerTypeServer,
76 kPassword, "wrongsession");
77
78 EXPECT_FALSE(RunExchange(&client, &server));
79 }
80 67
81 TEST(MutualAuth, Fuzz) { 68 TEST(MutualAuth, Fuzz) {
82 static const unsigned kIterations = 40; 69 static const unsigned kIterations = 40;
83 70
84 for (unsigned i = 0; i < kIterations; i++) { 71 for (unsigned i = 0; i < kIterations; i++) {
85 P224EncryptedKeyExchange client( 72 P224EncryptedKeyExchange client(
86 P224EncryptedKeyExchange::kPeerTypeClient, 73 P224EncryptedKeyExchange::kPeerTypeClient, kPassword);
87 kPassword, kSession);
88 P224EncryptedKeyExchange server( 74 P224EncryptedKeyExchange server(
89 P224EncryptedKeyExchange::kPeerTypeServer, 75 P224EncryptedKeyExchange::kPeerTypeServer, kPassword);
90 kPassword, kSession);
91 76
92 // We'll only be testing small values of i, but we don't want that to bias 77 // We'll only be testing small values of i, but we don't want that to bias
93 // the test coverage. So we disperse the value of i by multiplying by the 78 // the test coverage. So we disperse the value of i by multiplying by the
94 // FNV, 32-bit prime, producing a poor-man's PRNG. 79 // FNV, 32-bit prime, producing a poor-man's PRNG.
95 const uint32 rand = i * 16777619; 80 const uint32 rand = i * 16777619;
96 81
97 for (unsigned round = 0;; round++) { 82 for (unsigned round = 0;; round++) {
98 std::string client_message, server_message; 83 std::string client_message, server_message;
99 client_message = client.GetMessage(); 84 client_message = client.GetMessage();
100 server_message = server.GetMessage(); 85 server_message = server.GetMessage();
(...skipping 29 matching lines...) Expand all
130 break; 115 break;
131 } 116 }
132 117
133 ASSERT_EQ(P224EncryptedKeyExchange::kResultPending, 118 ASSERT_EQ(P224EncryptedKeyExchange::kResultPending,
134 client_result); 119 client_result);
135 ASSERT_EQ(P224EncryptedKeyExchange::kResultPending, 120 ASSERT_EQ(P224EncryptedKeyExchange::kResultPending,
136 server_result); 121 server_result);
137 } 122 }
138 } 123 }
139 } 124 }
OLDNEW
« no previous file with comments | « crypto/p224_spake.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698