| 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_message_cryptographer.h" | 5 #include "components/gcm_driver/crypto/gcm_message_cryptographer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/big_endian.h" | 9 #include "base/big_endian.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "crypto/hkdf.h" | 11 #include "crypto/hkdf.h" |
| 12 | 12 |
| 13 namespace gcm { | 13 namespace gcm { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Size, in bytes, of the nonce for a record. This must be at least the size | 16 // Size, in bytes, of the nonce for a record. This must be at least the size |
| 17 // of a uint64_t, which is used to indicate the record sequence number. | 17 // of a uint64_t, which is used to indicate the record sequence number. |
| 18 const uint64_t kNonceSize = 12; | 18 const uint64_t kNonceSize = 12; |
| 19 | 19 |
| 20 // The default record size as defined by draft-thomson-http-encryption-01. | 20 // The default record size as defined by draft-thomson-http-encryption-01. |
| 21 const size_t kDefaultRecordSize = 4096; | 21 const size_t kDefaultRecordSize = 4096; |
| 22 | 22 |
| 23 // Key size, in bytes, of a valid AEAD_AES_128_GCM key. | 23 // Key size, in bytes, of a valid AEAD_AES_128_GCM key. |
| 24 const size_t kContentEncryptionKeySize = 16; | 24 const size_t kContentEncryptionKeySize = 16; |
| 25 | 25 |
| 26 // Salt size, in bytes, that will be used together with the key to create a | |
| 27 // unique content encryption key for a given message. | |
| 28 const size_t kSaltSize = 16; | |
| 29 | |
| 30 } // namespace | 26 } // namespace |
| 31 | 27 |
| 32 const size_t GCMMessageCryptographer::kAuthenticationTagBytes = 16; | 28 const size_t GCMMessageCryptographer::kAuthenticationTagBytes = 16; |
| 29 const size_t GCMMessageCryptographer::kSaltSize = 16; |
| 33 | 30 |
| 34 GCMMessageCryptographer::GCMMessageCryptographer() {} | 31 GCMMessageCryptographer::GCMMessageCryptographer() {} |
| 35 | 32 |
| 36 GCMMessageCryptographer::~GCMMessageCryptographer() {} | 33 GCMMessageCryptographer::~GCMMessageCryptographer() {} |
| 37 | 34 |
| 38 bool GCMMessageCryptographer::Encrypt(const base::StringPiece& plaintext, | 35 bool GCMMessageCryptographer::Encrypt(const base::StringPiece& plaintext, |
| 39 const base::StringPiece& key, | 36 const base::StringPiece& key, |
| 40 const base::StringPiece& salt, | 37 const base::StringPiece& salt, |
| 41 size_t* record_size, | 38 size_t* record_size, |
| 42 std::string* ciphertext) const { | 39 std::string* ciphertext) const { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 0 /* subkey_secret_bytes_to_generate */); | 143 0 /* subkey_secret_bytes_to_generate */); |
| 147 | 144 |
| 148 // draft-thomson-http-encryption-01 defines that the result should be XOR'ed | 145 // draft-thomson-http-encryption-01 defines that the result should be XOR'ed |
| 149 // with the record's sequence number, but because Web Push encryption is | 146 // with the record's sequence number, but because Web Push encryption is |
| 150 // limited to a single record we do not have to do that. | 147 // limited to a single record we do not have to do that. |
| 151 | 148 |
| 152 return hkdf.client_write_key().as_string(); | 149 return hkdf.client_write_key().as_string(); |
| 153 } | 150 } |
| 154 | 151 |
| 155 } // namespace gcm | 152 } // namespace gcm |
| OLD | NEW |