1 // Copyright (c) 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef QUICHE_QUIC_QBONE_PLATFORM_INTERNET_CHECKSUM_H_ 6 #define QUICHE_QUIC_QBONE_PLATFORM_INTERNET_CHECKSUM_H_ 7 8 #include <cstddef> 9 #include <cstdint> 10 11 namespace quic { 12 13 // Incrementally compute an Internet header checksum as described in RFC 1071. 14 class InternetChecksum { 15 public: 16 // Update the checksum with the specified data. Note that while the checksum 17 // is commutative, the data has to be supplied in the units of two-byte words. 18 // If there is an extra byte at the end, the function has to be called on it 19 // last. 20 void Update(const char* data, size_t size); 21 22 void Update(const uint8_t* data, size_t size); 23 24 uint16_t Value() const; 25 26 private: 27 uint32_t accumulator_ = 0; 28 }; 29 30 } // namespace quic 31 32 #endif // QUICHE_QUIC_QBONE_PLATFORM_INTERNET_CHECKSUM_H_ 33