| 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/gcm_crypto_test_helpers.h" | 5 #include "components/gcm_driver/crypto/gcm_crypto_test_helpers.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 &shared_secret)) { | 37 &shared_secret)) { |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 | 40 |
| 41 std::string salt; | 41 std::string salt; |
| 42 | 42 |
| 43 // Generate a cryptographically secure random salt for the message. | 43 // Generate a cryptographically secure random salt for the message. |
| 44 const size_t salt_size = GCMMessageCryptographer::kSaltSize; | 44 const size_t salt_size = GCMMessageCryptographer::kSaltSize; |
| 45 crypto::RandBytes(base::WriteInto(&salt, salt_size + 1), salt_size); | 45 crypto::RandBytes(base::WriteInto(&salt, salt_size + 1), salt_size); |
| 46 | 46 |
| 47 GCMMessageCryptographer cryptographer(GCMMessageCryptographer::Label::P256, | 47 GCMMessageCryptographer cryptographer(peer_public_key, public_key, |
| 48 peer_public_key, public_key, | |
| 49 auth_secret.as_string()); | 48 auth_secret.as_string()); |
| 50 | 49 |
| 51 size_t record_size; | 50 size_t record_size; |
| 52 std::string ciphertext; | 51 std::string ciphertext; |
| 53 | 52 |
| 54 if (!cryptographer.Encrypt(payload, shared_secret, salt, &record_size, | 53 if (!cryptographer.Encrypt(payload, shared_secret, salt, &record_size, |
| 55 &ciphertext)) { | 54 &ciphertext)) { |
| 56 return false; | 55 return false; |
| 57 } | 56 } |
| 58 | 57 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 std::stringstream crypto_key_header; | 73 std::stringstream crypto_key_header; |
| 75 crypto_key_header << "dh=" << encoded_public_key; | 74 crypto_key_header << "dh=" << encoded_public_key; |
| 76 | 75 |
| 77 message->data["crypto-key"] = crypto_key_header.str(); | 76 message->data["crypto-key"] = crypto_key_header.str(); |
| 78 | 77 |
| 79 message->raw_data.swap(ciphertext); | 78 message->raw_data.swap(ciphertext); |
| 80 return true; | 79 return true; |
| 81 } | 80 } |
| 82 | 81 |
| 83 } // namespace gcm | 82 } // namespace gcm |
| OLD | NEW |