blob: 4273a422f5275e7313663a71252bf967b865fbcd [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/cryptauth/raw_eid_generator_impl.h"
#include "base/sys_byteorder.h"
#include "crypto/sha2.h"
namespace cryptauth {
const int32_t RawEidGenerator::kNumBytesInEidValue = 2;
RawEidGeneratorImpl::RawEidGeneratorImpl() {}
RawEidGeneratorImpl::~RawEidGeneratorImpl() {}
std::string RawEidGeneratorImpl::GenerateEid(
const std::string& eid_seed,
int64_t start_of_period_timestamp_ms,
std::string const* extra_entropy) {
// The data to hash is the eid seed, followed by the extra entropy (if it
// exists), followed by the timestamp.
std::string to_hash = eid_seed;
if (extra_entropy) {
to_hash += *extra_entropy;
uint64_t timestamp_data =
to_hash.append(reinterpret_cast<char*>(&timestamp_data), sizeof(uint64_t));
std::string result = crypto::SHA256HashString(to_hash);
return result;
} // namespace cryptauth