| 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 #ifndef COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ |
| 6 #define COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ | 6 #define COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // draft-thomson-http-encryption-01: | 25 // draft-thomson-http-encryption-01: |
| 26 // | 26 // |
| 27 // https://tools.ietf.org/html/draft-thomson-http-encryption-01 | 27 // https://tools.ietf.org/html/draft-thomson-http-encryption-01 |
| 28 // | 28 // |
| 29 // Note that while this class is not responsible for creating or storing the | 29 // Note that while this class is not responsible for creating or storing the |
| 30 // actual keys, it uses a key derivation function for the actual message | 30 // actual keys, it uses a key derivation function for the actual message |
| 31 // encryption/decryption, thus allowing for the safe re-use of keys in multiple | 31 // encryption/decryption, thus allowing for the safe re-use of keys in multiple |
| 32 // messages provided that a cryptographically-strong random salt is used. | 32 // messages provided that a cryptographically-strong random salt is used. |
| 33 class GCMMessageCryptographer { | 33 class GCMMessageCryptographer { |
| 34 public: | 34 public: |
| 35 // Salt size, in bytes, that will be used together with the key to create a |
| 36 // unique content encryption key for a given message. |
| 37 static const size_t kSaltSize; |
| 38 |
| 35 GCMMessageCryptographer(); | 39 GCMMessageCryptographer(); |
| 36 ~GCMMessageCryptographer(); | 40 ~GCMMessageCryptographer(); |
| 37 | 41 |
| 38 // Encrypts |plaintext| using the |key| and the |salt|, both of which must be | 42 // Encrypts |plaintext| using the |key| and the |salt|, both of which must be |
| 39 // 16 octets in length. The |plaintext| will be written to a single record, | 43 // 16 octets in length. The |plaintext| will be written to a single record, |
| 40 // and will include a 16 octet authentication tag. The encrypted result will | 44 // and will include a 16 octet authentication tag. The encrypted result will |
| 41 // be written to |ciphertext|, the record size to |record_size|. This | 45 // be written to |ciphertext|, the record size to |record_size|. This |
| 42 // implementation does not support prepending padding to the |plaintext|. | 46 // implementation does not support prepending padding to the |plaintext|. |
| 43 bool Encrypt(const base::StringPiece& plaintext, | 47 bool Encrypt(const base::StringPiece& plaintext, |
| 44 const base::StringPiece& key, | 48 const base::StringPiece& key, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 const base::StringPiece& salt) const; | 81 const base::StringPiece& salt) const; |
| 78 | 82 |
| 79 // Derives the nonce from |key| and |salt|. | 83 // Derives the nonce from |key| and |salt|. |
| 80 std::string DeriveNonce(const base::StringPiece& key, | 84 std::string DeriveNonce(const base::StringPiece& key, |
| 81 const base::StringPiece& salt) const; | 85 const base::StringPiece& salt) const; |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 } // namespace gcm | 88 } // namespace gcm |
| 85 | 89 |
| 86 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ | 90 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ |
| OLD | NEW |