#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/gcm_driver/crypto/gcm_message_cryptographer.h"
#include <memory>
#include <string_view>
#include "base/base64url.h"
#include "base/big_endian.h"
#include "base/containers/span.h"
#include "base/logging.h"
#include "components/gcm_driver/crypto/message_payload_parser.h"
#include "components/gcm_driver/crypto/p256_key_util.h"
#include "crypto/ec_private_key.h"
#include "crypto/random.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace gcm {
namespace {
const char kExamplePlaintext[] = …;
constexpr size_t kEcdhSharedSecretSize = …;
constexpr size_t kAuthSecretSize = …;
constexpr size_t kSaltSize = …;
const unsigned char kCommonSenderPublicKey[] = …;
static_assert …;
const unsigned char kCommonRecipientPublicKey[] = …;
static_assert …;
const unsigned char kCommonRecipientPrivateKey[] = …;
const unsigned char kCommonAuthSecret[] = …;
static_assert …;
struct TestVector { … };
const TestVector kEncryptionTestVectorsDraft03[] = …;
const TestVector kEncryptionTestVectorsDraft08[] = …;
const TestVector kDecryptionTestVectorsDraft03[] = …;
const TestVector kDecryptionTestVectorsDraft08[] = …;
bool ComputeSharedP256SecretFromPrivateKeyStr(std::string_view private_key,
std::string_view peer_public_key,
std::string* out_shared_secret) { … }
void ComputeSharedSecret(std::string_view encoded_sender_private_key,
std::string_view encoded_receiver_public_key,
std::string* shared_secret) { … }
}
class GCMMessageCryptographerTestBase : public ::testing::Test { … };
class GCMMessageCryptographerTest
: public GCMMessageCryptographerTestBase,
public testing::WithParamInterface<GCMMessageCryptographer::Version> { … };
TEST_P(GCMMessageCryptographerTest, RoundTrip) { … }
TEST_P(GCMMessageCryptographerTest, RoundTripEmptyMessage) { … }
TEST_P(GCMMessageCryptographerTest, InvalidRecordSize) { … }
TEST_P(GCMMessageCryptographerTest, InvalidRecordPadding) { … }
TEST_P(GCMMessageCryptographerTest, AuthSecretAffectsPRK) { … }
INSTANTIATE_TEST_SUITE_P(…);
class GCMMessageCryptographerTestVectorTest
: public GCMMessageCryptographerTestBase { … };
TEST_F(GCMMessageCryptographerTestVectorTest, EncryptionVectorsDraft03) { … }
TEST_F(GCMMessageCryptographerTestVectorTest, DecryptionVectorsDraft03) { … }
TEST_F(GCMMessageCryptographerTestVectorTest, EncryptionVectorsDraft08) { … }
TEST_F(GCMMessageCryptographerTestVectorTest, DecryptionVectorsDraft08) { … }
class GCMMessageCryptographerReferenceTest : public ::testing::Test { … };
TEST_F(GCMMessageCryptographerReferenceTest, ReferenceDraft03) { … }
TEST_F(GCMMessageCryptographerReferenceTest, ReferenceDraft08) { … }
}