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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/quic/crypto/channel_id.h" 5 #include "net/quic/crypto/channel_id.h"
6 6
7 #include <openssl/bn.h> 7 #include <openssl/bn.h>
8 #include <openssl/ec.h> 8 #include <openssl/ec.h>
9 #include <openssl/ecdsa.h> 9 #include <openssl/ecdsa.h>
10 #include <openssl/obj_mac.h> 10 #include <openssl/obj_mac.h>
(...skipping 10 matching lines...) Expand all
21 StringPiece signed_data, 21 StringPiece signed_data,
22 StringPiece signature) { 22 StringPiece signature) {
23 return VerifyRaw(key, signed_data, signature, true); 23 return VerifyRaw(key, signed_data, signature, true);
24 } 24 }
25 25
26 // static 26 // static
27 bool ChannelIDVerifier::VerifyRaw(StringPiece key, 27 bool ChannelIDVerifier::VerifyRaw(StringPiece key,
28 StringPiece signed_data, 28 StringPiece signed_data,
29 StringPiece signature, 29 StringPiece signature,
30 bool is_channel_id_signature) { 30 bool is_channel_id_signature) {
31 if (key.size() != 32 * 2 || 31 if (key.size() != 32 * 2 || signature.size() != 32 * 2) {
32 signature.size() != 32 * 2) {
33 return false; 32 return false;
34 } 33 }
35 34
36 crypto::ScopedOpenSSL<EC_GROUP, EC_GROUP_free> p256( 35 crypto::ScopedOpenSSL<EC_GROUP, EC_GROUP_free> p256(
37 EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1)); 36 EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
38 if (p256.get() == NULL) { 37 if (p256.get() == NULL) {
39 return false; 38 return false;
40 } 39 }
41 40
42 crypto::ScopedOpenSSL<BIGNUM, BN_free> x(BN_new()), y(BN_new()), 41 crypto::ScopedOpenSSL<BIGNUM, BN_free> x(BN_new()), y(BN_new()), r(BN_new()),
43 r(BN_new()), s(BN_new()); 42 s(BN_new());
44 43
45 ECDSA_SIG sig; 44 ECDSA_SIG sig;
46 sig.r = r.get(); 45 sig.r = r.get();
47 sig.s = s.get(); 46 sig.s = s.get();
48 47
49 const uint8* key_bytes = reinterpret_cast<const uint8*>(key.data()); 48 const uint8* key_bytes = reinterpret_cast<const uint8*>(key.data());
50 const uint8* signature_bytes = 49 const uint8* signature_bytes =
51 reinterpret_cast<const uint8*>(signature.data()); 50 reinterpret_cast<const uint8*>(signature.data());
52 51
53 if (BN_bin2bn(key_bytes + 0, 32, x.get()) == NULL || 52 if (BN_bin2bn(key_bytes + 0, 32, x.get()) == NULL ||
54 BN_bin2bn(key_bytes + 32, 32, y.get()) == NULL || 53 BN_bin2bn(key_bytes + 32, 32, y.get()) == NULL ||
55 BN_bin2bn(signature_bytes + 0, 32, sig.r) == NULL || 54 BN_bin2bn(signature_bytes + 0, 32, sig.r) == NULL ||
56 BN_bin2bn(signature_bytes + 32, 32, sig.s) == NULL) { 55 BN_bin2bn(signature_bytes + 32, 32, sig.s) == NULL) {
57 return false; 56 return false;
58 } 57 }
59 58
60 crypto::ScopedOpenSSL<EC_POINT, EC_POINT_free> point( 59 crypto::ScopedOpenSSL<EC_POINT, EC_POINT_free> point(
61 EC_POINT_new(p256.get())); 60 EC_POINT_new(p256.get()));
62 if (point.get() == NULL || 61 if (point.get() == NULL ||
63 !EC_POINT_set_affine_coordinates_GFp(p256.get(), point.get(), x.get(), 62 !EC_POINT_set_affine_coordinates_GFp(
64 y.get(), NULL)) { 63 p256.get(), point.get(), x.get(), y.get(), NULL)) {
65 return false; 64 return false;
66 } 65 }
67 66
68 crypto::ScopedOpenSSL<EC_KEY, EC_KEY_free> ecdsa_key(EC_KEY_new()); 67 crypto::ScopedOpenSSL<EC_KEY, EC_KEY_free> ecdsa_key(EC_KEY_new());
69 if (ecdsa_key.get() == NULL || 68 if (ecdsa_key.get() == NULL ||
70 !EC_KEY_set_group(ecdsa_key.get(), p256.get()) || 69 !EC_KEY_set_group(ecdsa_key.get(), p256.get()) ||
71 !EC_KEY_set_public_key(ecdsa_key.get(), point.get())) { 70 !EC_KEY_set_public_key(ecdsa_key.get(), point.get())) {
72 return false; 71 return false;
73 } 72 }
74 73
75 SHA256_CTX sha256; 74 SHA256_CTX sha256;
76 SHA256_Init(&sha256); 75 SHA256_Init(&sha256);
77 if (is_channel_id_signature) { 76 if (is_channel_id_signature) {
78 SHA256_Update(&sha256, kContextStr, strlen(kContextStr) + 1); 77 SHA256_Update(&sha256, kContextStr, strlen(kContextStr) + 1);
79 SHA256_Update(&sha256, kClientToServerStr, strlen(kClientToServerStr) + 1); 78 SHA256_Update(&sha256, kClientToServerStr, strlen(kClientToServerStr) + 1);
80 } 79 }
81 SHA256_Update(&sha256, signed_data.data(), signed_data.size()); 80 SHA256_Update(&sha256, signed_data.data(), signed_data.size());
82 81
83 unsigned char digest[SHA256_DIGEST_LENGTH]; 82 unsigned char digest[SHA256_DIGEST_LENGTH];
84 SHA256_Final(digest, &sha256); 83 SHA256_Final(digest, &sha256);
85 84
86 return ECDSA_do_verify(digest, sizeof(digest), &sig, ecdsa_key.get()) == 1; 85 return ECDSA_do_verify(digest, sizeof(digest), &sig, ecdsa_key.get()) == 1;
87 } 86 }
88 87
89 } // namespace net 88 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698