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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/utils/SkMD5.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkMD5_DEFINED
    1.12 +#define SkMD5_DEFINED
    1.13 +
    1.14 +#include "SkTypes.h"
    1.15 +#include "SkEndian.h"
    1.16 +#include "SkStream.h"
    1.17 +
    1.18 +//The following macros can be defined to affect the MD5 code generated.
    1.19 +//SK_MD5_CLEAR_DATA causes all intermediate state to be overwritten with 0's.
    1.20 +//SK_CPU_LENDIAN allows 32 bit <=> 8 bit conversions without copies (if alligned).
    1.21 +//SK_CPU_FAST_UNALIGNED_ACCESS allows 32 bit <=> 8 bit conversions without copies if SK_CPU_LENDIAN.
    1.22 +
    1.23 +class SkMD5 : public SkWStream {
    1.24 +public:
    1.25 +    SkMD5();
    1.26 +
    1.27 +    /** Processes input, adding it to the digest.
    1.28 +     *  Note that this treats the buffer as a series of uint8_t values.
    1.29 +     */
    1.30 +    virtual bool write(const void* buffer, size_t size) SK_OVERRIDE {
    1.31 +        this->update(reinterpret_cast<const uint8_t*>(buffer), size);
    1.32 +        return true;
    1.33 +    }
    1.34 +
    1.35 +    virtual size_t bytesWritten() const SK_OVERRIDE { return SkToSizeT(this->byteCount); }
    1.36 +
    1.37 +    /** Processes input, adding it to the digest. Calling this after finish is undefined. */
    1.38 +    void update(const uint8_t* input, size_t length);
    1.39 +
    1.40 +    struct Digest {
    1.41 +        uint8_t data[16];
    1.42 +    };
    1.43 +
    1.44 +    /** Computes and returns the digest. */
    1.45 +    void finish(Digest& digest);
    1.46 +
    1.47 +private:
    1.48 +    // number of bytes, modulo 2^64
    1.49 +    uint64_t byteCount;
    1.50 +
    1.51 +    // state (ABCD)
    1.52 +    uint32_t state[4];
    1.53 +
    1.54 +    // input buffer
    1.55 +    uint8_t buffer[64];
    1.56 +};
    1.57 +
    1.58 +#endif

mercurial