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

Side by Side Diff: crypto/curve25519_unittest.cc

Issue 12457004: Curve25519-donna changes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 9 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) 2013 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/curve25519.h"
6
7 #include <string>
8
9 #include "crypto/random.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 using std::string;
wtc 2013/03/06 19:21:07 I would avoid this using statement. Is this file s
ramant (doing other things) 2013/03/06 20:03:12 Done.
13
14 namespace crypto {
15
16 // SharedKey just tests that the basic key exchange identity holds: that both
17 // parties end up with the same key.
18 TEST(Curve25519, SharedKey) {
19 for (int i = 0; i < 5; i++) {
20 uint8 alice_secret[curve25519::kCryptoScalarMultCurve25519ScalarBytes];
21 crypto::RandBytes(alice_secret, sizeof(alice_secret));
22 EXPECT_TRUE(curve25519::ConvertToPrivateKey(alice_secret,
23 sizeof(alice_secret)));
24 string alice_key(reinterpret_cast<char*>(alice_secret),
25 sizeof(alice_secret));
26
27 uint8 alice_public_key[curve25519::kCryptoScalarMultCurve25519Bytes];
28 uint8 alice_private_key[curve25519::kCryptoScalarMultCurve25519ScalarBytes];
29 ASSERT_EQ(static_cast<size_t>(
30 curve25519::kCryptoScalarMultCurve25519ScalarBytes), alice_key.size());
31 memcpy(alice_private_key, alice_key.data(), alice_key.size());
32 curve25519::ScalarBaseMult(alice_private_key, alice_public_key);
33
34 uint8 bob_secret[curve25519::kCryptoScalarMultCurve25519ScalarBytes];
35 crypto::RandBytes(bob_secret, sizeof(bob_secret));
36 EXPECT_TRUE(curve25519::ConvertToPrivateKey(bob_secret,
37 sizeof(bob_secret)));
38 string bob_key(reinterpret_cast<char*>(bob_secret), sizeof(bob_secret));
39
40 uint8 bob_public_key[curve25519::kCryptoScalarMultCurve25519Bytes];
41 uint8 bob_private_key[curve25519::kCryptoScalarMultCurve25519ScalarBytes];
42 ASSERT_EQ(static_cast<size_t>(
43 curve25519::kCryptoScalarMultCurve25519ScalarBytes), bob_key.size());
44 memcpy(bob_private_key, bob_key.data(), bob_key.size());
45 curve25519::ScalarBaseMult(bob_private_key, bob_public_key);
46
47 uint8 alice_shared_key[curve25519::kCryptoScalarMultCurve25519Bytes];
48 curve25519::ScalarMult(alice_private_key, bob_public_key, alice_shared_key);
49 string alice_shared;
50 alice_shared.assign(reinterpret_cast<char*>(alice_shared_key),
51 sizeof(alice_shared_key));
52
53 uint8 bob_shared_key[curve25519::kCryptoScalarMultCurve25519Bytes];
54 curve25519::ScalarMult(bob_private_key, alice_public_key, bob_shared_key);
55 string bob_shared;
56 bob_shared.assign(reinterpret_cast<char*>(bob_shared_key),
57 sizeof(bob_shared_key));
58
59 ASSERT_EQ(alice_shared, bob_shared);
60 }
61 }
62
63 } // namespace crypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698