// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_REPORTING_ENCRYPTION_ENCRYPTION_H_ #define COMPONENTS_REPORTING_ENCRYPTION_ENCRYPTION_H_ #include <optional> #include <string> #include <string_view> #include <utility> #include "base/functional/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h" #include "base/task/sequenced_task_runner.h" #include "components/reporting/proto/synced/record.pb.h" #include "components/reporting/util/status.h" #include "components/reporting/util/statusor.h" namespace reporting { // Full implementation of Encryptor, intended for use in reporting client. // ChaCha20_Poly1305 AEAD encryption of a record in place with symmetric key. // Curve25519 encryption of the symmetric key with asymmetric public key. // // We generate new Curve25519 public/private keys pair for each record. // Then we produce Curve25519 shared secret from our private key and peer's // public key, and use it for ChaCha20_Poly1305 AEAD encryption of the record. // We send out our public value (calling it encrypted symmetric key) together // with encrypted record. // // Upon receiving the encrypted message the peer will produce the same shared // secret by combining their private key and our public key, and use it as // a symmetric key for ChaCha20_Poly1305 decryption and validation of the // record. // // Instantiated by a factory: // StatusOr<scoped_refptr<Encryptor>> Create(); // The implementation class should never be used directly by the client code. class Encryptor : public base::RefCountedThreadSafe<Encryptor> { … }; } // namespace reporting #endif // COMPONENTS_REPORTING_ENCRYPTION_ENCRYPTION_H_