#include "quiche/quic/core/quic_utils.h"
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include <string>
#include "absl/base/macros.h"
#include "absl/base/optimization.h"
#include "absl/numeric/int128.h"
#include "absl/strings/string_view.h"
#include "openssl/sha.h"
#include "quiche/quic/core/quic_connection_id.h"
#include "quiche/quic/core/quic_constants.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/core/quic_versions.h"
#include "quiche/quic/platform/api/quic_bug_tracker.h"
#include "quiche/quic/platform/api/quic_flag_utils.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/common/platform/api/quiche_logging.h"
#include "quiche/common/platform/api/quiche_mem_slice.h"
#include "quiche/common/quiche_endian.h"
namespace quic {
namespace {
#if defined(__x86_64__) && \
((defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))) || \
defined(__clang__))
#define QUIC_UTIL_HAS_UINT128 …
#endif
#ifdef QUIC_UTIL_HAS_UINT128
absl::uint128 IncrementalHashFast(absl::uint128 uhash, absl::string_view data) { … }
#endif
#ifndef QUIC_UTIL_HAS_UINT128
absl::uint128 IncrementalHashSlow(absl::uint128 hash, absl::string_view data) {
static const absl::uint128 kPrime = absl::MakeUint128(16777216, 315);
const uint8_t* octets = reinterpret_cast<const uint8_t*>(data.data());
for (size_t i = 0; i < data.length(); ++i) {
hash = hash ^ absl::MakeUint128(0, octets[i]);
hash = hash * kPrime;
}
return hash;
}
#endif
absl::uint128 IncrementalHash(absl::uint128 hash, absl::string_view data) { … }
}
uint64_t QuicUtils::FNV1a_64_Hash(absl::string_view data) { … }
absl::uint128 QuicUtils::FNV1a_128_Hash(absl::string_view data) { … }
absl::uint128 QuicUtils::FNV1a_128_Hash_Two(absl::string_view data1,
absl::string_view data2) { … }
absl::uint128 QuicUtils::FNV1a_128_Hash_Three(absl::string_view data1,
absl::string_view data2,
absl::string_view data3) { … }
void QuicUtils::SerializeUint128Short(absl::uint128 v, uint8_t* out) { … }
#define RETURN_STRING_LITERAL …
std::string QuicUtils::AddressChangeTypeToString(AddressChangeType type) { … }
const char* QuicUtils::SentPacketStateToString(SentPacketState state) { … }
const char* QuicUtils::QuicLongHeaderTypetoString(QuicLongHeaderType type) { … }
const char* QuicUtils::AckResultToString(AckResult result) { … }
AddressChangeType QuicUtils::DetermineAddressChangeType(
const QuicSocketAddress& old_address,
const QuicSocketAddress& new_address) { … }
bool QuicUtils::IsAckable(SentPacketState state) { … }
bool QuicUtils::IsRetransmittableFrame(QuicFrameType type) { … }
bool QuicUtils::IsHandshakeFrame(const QuicFrame& frame,
QuicTransportVersion transport_version) { … }
bool QuicUtils::ContainsFrameType(const QuicFrames& frames,
QuicFrameType type) { … }
SentPacketState QuicUtils::RetransmissionTypeToPacketState(
TransmissionType retransmission_type) { … }
bool QuicUtils::IsIetfPacketHeader(uint8_t first_byte) { … }
bool QuicUtils::IsIetfPacketShortHeader(uint8_t first_byte) { … }
QuicStreamId QuicUtils::GetInvalidStreamId(QuicTransportVersion version) { … }
QuicStreamId QuicUtils::GetCryptoStreamId(QuicTransportVersion version) { … }
bool QuicUtils::IsCryptoStreamId(QuicTransportVersion version,
QuicStreamId stream_id) { … }
QuicStreamId QuicUtils::GetHeadersStreamId(QuicTransportVersion version) { … }
bool QuicUtils::IsClientInitiatedStreamId(QuicTransportVersion version,
QuicStreamId id) { … }
bool QuicUtils::IsServerInitiatedStreamId(QuicTransportVersion version,
QuicStreamId id) { … }
bool QuicUtils::IsOutgoingStreamId(ParsedQuicVersion version, QuicStreamId id,
Perspective perspective) { … }
bool QuicUtils::IsBidirectionalStreamId(QuicStreamId id,
ParsedQuicVersion version) { … }
StreamType QuicUtils::GetStreamType(QuicStreamId id, Perspective perspective,
bool peer_initiated,
ParsedQuicVersion version) { … }
QuicStreamId QuicUtils::StreamIdDelta(QuicTransportVersion version) { … }
QuicStreamId QuicUtils::GetFirstBidirectionalStreamId(
QuicTransportVersion version, Perspective perspective) { … }
QuicStreamId QuicUtils::GetFirstUnidirectionalStreamId(
QuicTransportVersion version, Perspective perspective) { … }
QuicStreamId QuicUtils::GetMaxClientInitiatedBidirectionalStreamId(
QuicTransportVersion version) { … }
QuicConnectionId QuicUtils::CreateRandomConnectionId() { … }
QuicConnectionId QuicUtils::CreateRandomConnectionId(QuicRandom* random) { … }
QuicConnectionId QuicUtils::CreateRandomConnectionId(
uint8_t connection_id_length) { … }
QuicConnectionId QuicUtils::CreateRandomConnectionId(
uint8_t connection_id_length, QuicRandom* random) { … }
QuicConnectionId QuicUtils::CreateZeroConnectionId(
QuicTransportVersion version) { … }
bool QuicUtils::IsConnectionIdLengthValidForVersion(
size_t connection_id_length, QuicTransportVersion transport_version) { … }
bool QuicUtils::IsConnectionIdValidForVersion(
QuicConnectionId connection_id, QuicTransportVersion transport_version) { … }
StatelessResetToken QuicUtils::GenerateStatelessResetToken(
QuicConnectionId connection_id) { … }
QuicStreamCount QuicUtils::GetMaxStreamCount() { … }
PacketNumberSpace QuicUtils::GetPacketNumberSpace(
EncryptionLevel encryption_level) { … }
EncryptionLevel QuicUtils::GetEncryptionLevelToSendAckofSpace(
PacketNumberSpace packet_number_space) { … }
bool QuicUtils::IsProbingFrame(QuicFrameType type) { … }
bool QuicUtils::IsAckElicitingFrame(QuicFrameType type) { … }
bool QuicUtils::AreStatelessResetTokensEqual(
const StatelessResetToken& token1, const StatelessResetToken& token2) { … }
bool IsValidWebTransportSessionId(WebTransportSessionId id,
ParsedQuicVersion version) { … }
QuicByteCount MemSliceSpanTotalSize(absl::Span<quiche::QuicheMemSlice> span) { … }
std::string RawSha256(absl::string_view input) { … }
#undef RETURN_STRING_LITERAL
}