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

Side by Side Diff: net/quic/test_tools/crypto_test_utils_openssl.cc

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 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
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/test_tools/crypto_test_utils.h" 5 #include "net/quic/test_tools/crypto_test_utils.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/evp.h> 10 #include <openssl/evp.h>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 strlen(ChannelIDVerifier::kContextStr) + 1); 42 strlen(ChannelIDVerifier::kContextStr) + 1);
43 EVP_DigestUpdate(md_ctx.get(), ChannelIDVerifier::kClientToServerStr, 43 EVP_DigestUpdate(md_ctx.get(), ChannelIDVerifier::kClientToServerStr,
44 strlen(ChannelIDVerifier::kClientToServerStr) + 1); 44 strlen(ChannelIDVerifier::kClientToServerStr) + 1);
45 EVP_DigestUpdate(md_ctx.get(), signed_data.data(), signed_data.size()); 45 EVP_DigestUpdate(md_ctx.get(), signed_data.data(), signed_data.size());
46 46
47 size_t sig_len; 47 size_t sig_len;
48 if (!EVP_DigestSignFinal(md_ctx.get(), nullptr, &sig_len)) { 48 if (!EVP_DigestSignFinal(md_ctx.get(), nullptr, &sig_len)) {
49 return false; 49 return false;
50 } 50 }
51 51
52 scoped_ptr<uint8[]> der_sig(new uint8[sig_len]); 52 scoped_ptr<uint8_t[]> der_sig(new uint8_t[sig_len]);
53 if (!EVP_DigestSignFinal(md_ctx.get(), der_sig.get(), &sig_len)) { 53 if (!EVP_DigestSignFinal(md_ctx.get(), der_sig.get(), &sig_len)) {
54 return false; 54 return false;
55 } 55 }
56 56
57 uint8* derp = der_sig.get(); 57 uint8_t* derp = der_sig.get();
58 crypto::ScopedECDSA_SIG sig( 58 crypto::ScopedECDSA_SIG sig(
59 d2i_ECDSA_SIG(nullptr, const_cast<const uint8**>(&derp), sig_len)); 59 d2i_ECDSA_SIG(nullptr, const_cast<const uint8_t**>(&derp), sig_len));
60 if (sig.get() == nullptr) { 60 if (sig.get() == nullptr) {
61 return false; 61 return false;
62 } 62 }
63 63
64 // The signature consists of a pair of 32-byte numbers. 64 // The signature consists of a pair of 32-byte numbers.
65 static const size_t kSignatureLength = 32 * 2; 65 static const size_t kSignatureLength = 32 * 2;
66 scoped_ptr<uint8[]> signature(new uint8[kSignatureLength]); 66 scoped_ptr<uint8_t[]> signature(new uint8_t[kSignatureLength]);
67 if (!BN_bn2bin_padded(&signature[0], 32, sig->r) || 67 if (!BN_bn2bin_padded(&signature[0], 32, sig->r) ||
68 !BN_bn2bin_padded(&signature[32], 32, sig->s)) { 68 !BN_bn2bin_padded(&signature[32], 32, sig->s)) {
69 return false; 69 return false;
70 } 70 }
71 71
72 *out_signature = 72 *out_signature =
73 string(reinterpret_cast<char*>(signature.get()), kSignatureLength); 73 string(reinterpret_cast<char*>(signature.get()), kSignatureLength);
74 74
75 return true; 75 return true;
76 } 76 }
77 77
78 string SerializeKey() const override { 78 string SerializeKey() const override {
79 // i2d_PublicKey will produce an ANSI X9.62 public key which, for a P-256 79 // i2d_PublicKey will produce an ANSI X9.62 public key which, for a P-256
80 // key, is 0x04 (meaning uncompressed) followed by the x and y field 80 // key, is 0x04 (meaning uncompressed) followed by the x and y field
81 // elements as 32-byte, big-endian numbers. 81 // elements as 32-byte, big-endian numbers.
82 static const int kExpectedKeyLength = 65; 82 static const int kExpectedKeyLength = 65;
83 83
84 int len = i2d_PublicKey(ecdsa_key_.get(), nullptr); 84 int len = i2d_PublicKey(ecdsa_key_.get(), nullptr);
85 if (len != kExpectedKeyLength) { 85 if (len != kExpectedKeyLength) {
86 return ""; 86 return "";
87 } 87 }
88 88
89 uint8 buf[kExpectedKeyLength]; 89 uint8_t buf[kExpectedKeyLength];
90 uint8* derp = buf; 90 uint8_t* derp = buf;
91 i2d_PublicKey(ecdsa_key_.get(), &derp); 91 i2d_PublicKey(ecdsa_key_.get(), &derp);
92 92
93 return string(reinterpret_cast<char*>(buf + 1), kExpectedKeyLength - 1); 93 return string(reinterpret_cast<char*>(buf + 1), kExpectedKeyLength - 1);
94 } 94 }
95 95
96 private: 96 private:
97 crypto::ScopedEVP_PKEY ecdsa_key_; 97 crypto::ScopedEVP_PKEY ecdsa_key_;
98 }; 98 };
99 99
100 class TestChannelIDSource : public ChannelIDSource { 100 class TestChannelIDSource : public ChannelIDSource {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 }; 156 };
157 157
158 // static 158 // static
159 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() { 159 ChannelIDSource* CryptoTestUtils::ChannelIDSourceForTesting() {
160 return new TestChannelIDSource(); 160 return new TestChannelIDSource();
161 } 161 }
162 162
163 } // namespace test 163 } // namespace test
164 164
165 } // namespace net 165 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils_chromium.cc ('k') | net/quic/test_tools/delayed_verify_strike_register_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698