| 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 18 matching lines...) Expand all Loading... |
| 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 | 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. | 36 // unique content encryption key for a given message. |
| 37 static const size_t kSaltSize; | 37 static const size_t kSaltSize; |
| 38 | 38 |
| 39 GCMMessageCryptographer(); | 39 GCMMessageCryptographer(const base::StringPiece& local_public_key, |
| 40 const base::StringPiece& peer_public_key); |
| 40 ~GCMMessageCryptographer(); | 41 ~GCMMessageCryptographer(); |
| 41 | 42 |
| 42 // Encrypts |plaintext| using the |key| and the |salt|, both of which must be | 43 // Encrypts |plaintext| using the |key| and the |salt|, both of which must be |
| 43 // 16 octets in length. The |plaintext| will be written to a single record, | 44 // 16 octets in length. The |plaintext| will be written to a single record, |
| 44 // and will include a 16 octet authentication tag. The encrypted result will | 45 // and will include a 16 octet authentication tag. The encrypted result will |
| 45 // be written to |ciphertext|, the record size to |record_size|. This | 46 // be written to |ciphertext|, the record size to |record_size|. This |
| 46 // implementation does not support prepending padding to the |plaintext|. | 47 // implementation does not support prepending padding to the |plaintext|. |
| 47 bool Encrypt(const base::StringPiece& plaintext, | 48 bool Encrypt(const base::StringPiece& plaintext, |
| 48 const base::StringPiece& key, | 49 const base::StringPiece& key, |
| 49 const base::StringPiece& salt, | 50 const base::StringPiece& salt, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 76 const base::StringPiece& nonce, | 77 const base::StringPiece& nonce, |
| 77 std::string* output) const; | 78 std::string* output) const; |
| 78 | 79 |
| 79 // Derives the content encryption key from |key| and |salt|. | 80 // Derives the content encryption key from |key| and |salt|. |
| 80 std::string DeriveContentEncryptionKey(const base::StringPiece& key, | 81 std::string DeriveContentEncryptionKey(const base::StringPiece& key, |
| 81 const base::StringPiece& salt) const; | 82 const base::StringPiece& salt) const; |
| 82 | 83 |
| 83 // Derives the nonce from |key| and |salt|. | 84 // Derives the nonce from |key| and |salt|. |
| 84 std::string DeriveNonce(const base::StringPiece& key, | 85 std::string DeriveNonce(const base::StringPiece& key, |
| 85 const base::StringPiece& salt) const; | 86 const base::StringPiece& salt) const; |
| 87 |
| 88 // The context. TODO: Better comment. |
| 89 std::string nonce_info_; |
| 90 std::string content_encryption_key_info_; |
| 91 |
| 92 std::string context_; |
| 86 }; | 93 }; |
| 87 | 94 |
| 88 } // namespace gcm | 95 } // namespace gcm |
| 89 | 96 |
| 90 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ | 97 #endif // COMPONENTS_GCM_DRIVER_CRYPTO_GCM_MESSAGE_CRYPTOGRAPHER_H_ |
| OLD | NEW |