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

Side by Side Diff: net/quic/crypto/channel_id_openssl.cc

Issue 15937012: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small bug fixes Created 7 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) 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 "net/quic/crypto/channel_id.h"
6
7 #include <openssl/bn.h>
8 #include <openssl/ec.h>
9 #include <openssl/ecdsa.h>
10 #include <openssl/obj_mac.h>
11 #include <openssl/sha.h>
12
13 #include "crypto/openssl_util.h"
14
15 using base::StringPiece;
16
17 namespace net {
18
19 // static
20 bool ChannelIDVerifier::Verify(StringPiece key,
21 StringPiece signed_data,
22 StringPiece signature) {
23 if (key.size() != 32 * 2 ||
24 signature.size() != 32 * 2) {
25 return false;
26 }
27
28 crypto::ScopedOpenSSL<EC_GROUP, EC_GROUP_free> p256(
29 EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
30 if (p256.get() == NULL) {
31 return false;
32 }
33
34 crypto::ScopedOpenSSL<BIGNUM, BN_free> x(BN_new()), y(BN_new()),
35 r(BN_new()), s(BN_new());
36
37 ECDSA_SIG sig;
38 sig.r = r.get();
39 sig.s = s.get();
40
41 const uint8* key_bytes = reinterpret_cast<const uint8*>(key.data());
42 const uint8* proof_bytes = reinterpret_cast<const uint8*>(signature.data());
43
44 if (BN_bin2bn(key_bytes + 0, 32, x.get()) == NULL ||
45 BN_bin2bn(key_bytes + 32, 32, y.get()) == NULL ||
46 BN_bin2bn(proof_bytes + 0, 32, sig.r) == NULL ||
47 BN_bin2bn(proof_bytes + 32, 32, sig.s) == NULL) {
48 return false;
49 }
50
51 crypto::ScopedOpenSSL<EC_POINT, EC_POINT_free> point(
52 EC_POINT_new(p256.get()));
53 if (point.get() == NULL ||
54 !EC_POINT_set_affine_coordinates_GFp(p256.get(), point.get(), x.get(),
55 y.get(), NULL)) {
56 return false;
57 }
58
59 crypto::ScopedOpenSSL<EC_KEY, EC_KEY_free> ecdsa_key(EC_KEY_new());
60 if (ecdsa_key.get() == NULL ||
61 !EC_KEY_set_group(ecdsa_key.get(), p256.get()) ||
62 !EC_KEY_set_public_key(ecdsa_key.get(), point.get())) {
63 return false;
64 }
65
66 SHA256_CTX sha256;
67 SHA256_Init(&sha256);
68 SHA256_Update(&sha256, ChannelIDVerifier::kContextStr,
69 strlen(ChannelIDVerifier::kContextStr) + 1);
70 SHA256_Update(&sha256, ChannelIDVerifier::kClientToServerStr,
71 strlen(ChannelIDVerifier::kClientToServerStr) + 1);
72 SHA256_Update(&sha256, signed_data.data(), signed_data.size());
73
74 unsigned char digest[SHA256_DIGEST_LENGTH];
75 SHA256_Final(digest, &sha256);
76
77 return ECDSA_do_verify(digest, sizeof(digest), &sig, ecdsa_key.get()) == 1;
78 }
79
80 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698