michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkMD5_DEFINED michael@0: #define SkMD5_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: #include "SkEndian.h" michael@0: #include "SkStream.h" michael@0: michael@0: //The following macros can be defined to affect the MD5 code generated. michael@0: //SK_MD5_CLEAR_DATA causes all intermediate state to be overwritten with 0's. michael@0: //SK_CPU_LENDIAN allows 32 bit <=> 8 bit conversions without copies (if alligned). michael@0: //SK_CPU_FAST_UNALIGNED_ACCESS allows 32 bit <=> 8 bit conversions without copies if SK_CPU_LENDIAN. michael@0: michael@0: class SkMD5 : public SkWStream { michael@0: public: michael@0: SkMD5(); michael@0: michael@0: /** Processes input, adding it to the digest. michael@0: * Note that this treats the buffer as a series of uint8_t values. michael@0: */ michael@0: virtual bool write(const void* buffer, size_t size) SK_OVERRIDE { michael@0: this->update(reinterpret_cast(buffer), size); michael@0: return true; michael@0: } michael@0: michael@0: virtual size_t bytesWritten() const SK_OVERRIDE { return SkToSizeT(this->byteCount); } michael@0: michael@0: /** Processes input, adding it to the digest. Calling this after finish is undefined. */ michael@0: void update(const uint8_t* input, size_t length); michael@0: michael@0: struct Digest { michael@0: uint8_t data[16]; michael@0: }; michael@0: michael@0: /** Computes and returns the digest. */ michael@0: void finish(Digest& digest); michael@0: michael@0: private: michael@0: // number of bytes, modulo 2^64 michael@0: uint64_t byteCount; michael@0: michael@0: // state (ABCD) michael@0: uint32_t state[4]; michael@0: michael@0: // input buffer michael@0: uint8_t buffer[64]; michael@0: }; michael@0: michael@0: #endif