gfx/skia/trunk/src/utils/SkSHA1.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkSHA1_DEFINED
michael@0 9 #define SkSHA1_DEFINED
michael@0 10
michael@0 11 #include "SkTypes.h"
michael@0 12 #include "SkEndian.h"
michael@0 13 #include "SkStream.h"
michael@0 14
michael@0 15 //The following macros can be defined to affect the SHA1 code generated.
michael@0 16 //SK_SHA1_CLEAR_DATA causes all intermediate state to be overwritten with 0's.
michael@0 17 //SK_CPU_BENDIAN allows 32 bit <=> 8 bit conversions without copies (if alligned).
michael@0 18 //SK_CPU_FAST_UNALIGNED_ACCESS allows 32 bit <=> 8 bit conversions without copies if SK_CPU_BENDIAN.
michael@0 19
michael@0 20 class SkSHA1 : public SkWStream {
michael@0 21 public:
michael@0 22 SkSHA1();
michael@0 23
michael@0 24 /** Processes input, adding it to the digest.
michael@0 25 * Note that this treats the buffer as a series of uint8_t values.
michael@0 26 */
michael@0 27 virtual bool write(const void* buffer, size_t size) SK_OVERRIDE {
michael@0 28 update(reinterpret_cast<const uint8_t*>(buffer), size);
michael@0 29 return true;
michael@0 30 }
michael@0 31
michael@0 32 virtual size_t bytesWritten() const SK_OVERRIDE { return SkToSizeT(this->byteCount); }
michael@0 33
michael@0 34 /** Processes input, adding it to the digest. Calling this after finish is undefined. */
michael@0 35 void update(const uint8_t* input, size_t length);
michael@0 36
michael@0 37 struct Digest {
michael@0 38 uint8_t data[20];
michael@0 39 };
michael@0 40
michael@0 41 /** Computes and returns the digest. */
michael@0 42 void finish(Digest& digest);
michael@0 43
michael@0 44 private:
michael@0 45 // number of bytes, modulo 2^64
michael@0 46 uint64_t byteCount;
michael@0 47
michael@0 48 // state (ABCDE)
michael@0 49 uint32_t state[5];
michael@0 50
michael@0 51 // input buffer
michael@0 52 uint8_t buffer[64];
michael@0 53 };
michael@0 54
michael@0 55 #endif

mercurial