| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/gcm_driver/crypto/p256_key_util.h" | 5 #include "components/gcm_driver/crypto/p256_key_util.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/stl_util.h" | |
| 13 #include "crypto/ec_private_key.h" | 12 #include "crypto/ec_private_key.h" |
| 14 | 13 |
| 15 namespace gcm { | 14 namespace gcm { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 // The first byte in an uncompressed P-256 point per SEC1 2.3.3. | 18 // The first byte in an uncompressed P-256 point per SEC1 2.3.3. |
| 20 const char kUncompressedPointForm = 0x04; | 19 const char kUncompressedPointForm = 0x04; |
| 21 | 20 |
| 22 // A P-256 field element consists of 32 bytes. | 21 // A P-256 field element consists of 32 bytes. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 std::vector<uint8_t> public_key_x509; | 64 std::vector<uint8_t> public_key_x509; |
| 66 | 65 |
| 67 // Export the public key to an X.509 SubjectPublicKeyInfo for enabling NSS to | 66 // Export the public key to an X.509 SubjectPublicKeyInfo for enabling NSS to |
| 68 // import the key material when computing a shared secret. | 67 // import the key material when computing a shared secret. |
| 69 if (!key_pair->ExportPublicKey(&public_key_x509)) { | 68 if (!key_pair->ExportPublicKey(&public_key_x509)) { |
| 70 DLOG(ERROR) << "Unable to export the public key as an X.509 " | 69 DLOG(ERROR) << "Unable to export the public key as an X.509 " |
| 71 << "SubjectPublicKeyInfo block."; | 70 << "SubjectPublicKeyInfo block."; |
| 72 return false; | 71 return false; |
| 73 } | 72 } |
| 74 | 73 |
| 75 out_private_key->assign( | 74 out_private_key->assign(reinterpret_cast<const char*>(private_key.data()), |
| 76 reinterpret_cast<const char*>(vector_as_array(&private_key)), | 75 private_key.size()); |
| 77 private_key.size()); | |
| 78 out_public_key_x509->assign( | 76 out_public_key_x509->assign( |
| 79 reinterpret_cast<const char*>(vector_as_array(&public_key_x509)), | 77 reinterpret_cast<const char*>(public_key_x509.data()), |
| 80 public_key_x509.size()); | 78 public_key_x509.size()); |
| 81 | 79 |
| 82 // Concatenate the leading 0x04 byte and the two uncompressed points. | 80 // Concatenate the leading 0x04 byte and the two uncompressed points. |
| 83 out_public_key->reserve(kUncompressedPointBytes); | 81 out_public_key->reserve(kUncompressedPointBytes); |
| 84 out_public_key->push_back(kUncompressedPointForm); | 82 out_public_key->push_back(kUncompressedPointForm); |
| 85 out_public_key->append(candidate_public_key); | 83 out_public_key->append(candidate_public_key); |
| 86 | 84 |
| 87 return true; | 85 return true; |
| 88 } | 86 } |
| 89 | 87 |
| 90 } // namespace gcm | 88 } // namespace gcm |
| OLD | NEW |