Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* Simple class for computing SHA1. */ |
michael@0 | 8 | |
michael@0 | 9 | #ifndef mozilla_SHA1_h |
michael@0 | 10 | #define mozilla_SHA1_h |
michael@0 | 11 | |
michael@0 | 12 | #include "mozilla/Types.h" |
michael@0 | 13 | |
michael@0 | 14 | #include <stddef.h> |
michael@0 | 15 | #include <stdint.h> |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | /** |
michael@0 | 20 | * This class computes the SHA1 hash of a byte sequence, or of the concatenation |
michael@0 | 21 | * of multiple sequences. For example, computing the SHA1 of two sequences of |
michael@0 | 22 | * bytes could be done as follows: |
michael@0 | 23 | * |
michael@0 | 24 | * void SHA1(const uint8_t* buf1, uint32_t size1, |
michael@0 | 25 | * const uint8_t* buf2, uint32_t size2, |
michael@0 | 26 | * SHA1Sum::Hash& hash) |
michael@0 | 27 | * { |
michael@0 | 28 | * SHA1Sum s; |
michael@0 | 29 | * s.update(buf1, size1); |
michael@0 | 30 | * s.update(buf2, size2); |
michael@0 | 31 | * s.finish(hash); |
michael@0 | 32 | * } |
michael@0 | 33 | * |
michael@0 | 34 | * The finish method may only be called once and cannot be followed by calls |
michael@0 | 35 | * to update. |
michael@0 | 36 | */ |
michael@0 | 37 | class SHA1Sum |
michael@0 | 38 | { |
michael@0 | 39 | union { |
michael@0 | 40 | uint32_t w[16]; /* input buffer */ |
michael@0 | 41 | uint8_t b[64]; |
michael@0 | 42 | } u; |
michael@0 | 43 | uint64_t size; /* count of hashed bytes. */ |
michael@0 | 44 | unsigned H[22]; /* 5 state variables, 16 tmp values, 1 extra */ |
michael@0 | 45 | bool mDone; |
michael@0 | 46 | |
michael@0 | 47 | public: |
michael@0 | 48 | MFBT_API SHA1Sum(); |
michael@0 | 49 | |
michael@0 | 50 | static const size_t HashSize = 20; |
michael@0 | 51 | typedef uint8_t Hash[HashSize]; |
michael@0 | 52 | |
michael@0 | 53 | /* Add len bytes of dataIn to the data sequence being hashed. */ |
michael@0 | 54 | MFBT_API void update(const void* dataIn, uint32_t len); |
michael@0 | 55 | |
michael@0 | 56 | /* Compute the final hash of all data into hashOut. */ |
michael@0 | 57 | MFBT_API void finish(SHA1Sum::Hash& hashOut); |
michael@0 | 58 | }; |
michael@0 | 59 | |
michael@0 | 60 | } /* namespace mozilla */ |
michael@0 | 61 | |
michael@0 | 62 | #endif /* mozilla_SHA1_h */ |