Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
SkMD5 Class Reference

#include <SkMD5.h>

Inheritance diagram for SkMD5:
SkWStream

Classes

struct  Digest
 

Public Member Functions

 SkMD5 ()
 
bool write (const void *buffer, size_t size) final
 
size_t bytesWritten () const final
 
Digest finish ()
 
- Public Member Functions inherited from SkWStream
virtual ~SkWStream ()
 
 SkWStream ()
 
virtual bool write (const void *buffer, size_t size)=0
 
virtual void flush ()
 
virtual size_t bytesWritten () const =0
 
bool write8 (U8CPU value)
 
bool write16 (U16CPU value)
 
bool write32 (uint32_t v)
 
bool writeText (const char text[])
 
bool newline ()
 
bool writeDecAsText (int32_t)
 
bool writeBigDecAsText (int64_t, int minDigits=0)
 
bool writeHexAsText (uint32_t, int minDigits=0)
 
bool writeScalarAsText (SkScalar)
 
bool writeBool (bool v)
 
bool writeScalar (SkScalar)
 
bool writePackedUInt (size_t)
 
bool writeStream (SkStream *input, size_t length)
 

Additional Inherited Members

- Static Public Member Functions inherited from SkWStream
static int SizeOfPackedUInt (size_t value)
 

Detailed Description

Definition at line 19 of file SkMD5.h.

Constructor & Destructor Documentation

◆ SkMD5()

SkMD5::SkMD5 ( )

Definition at line 34 of file SkMD5.cpp.

34 : byteCount(0) {
35 // These are magic numbers from the specification.
36 this->state[0] = 0x67452301;
37 this->state[1] = 0xefcdab89;
38 this->state[2] = 0x98badcfe;
39 this->state[3] = 0x10325476;
40}

Member Function Documentation

◆ bytesWritten()

size_t SkMD5::bytesWritten ( ) const
inlinefinalvirtual

Implements SkWStream.

Definition at line 27 of file SkMD5.h.

27{ return SkToSizeT(this->byteCount); }
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31

◆ finish()

SkMD5::Digest SkMD5::finish ( )

Computes and returns the digest.

Definition at line 72 of file SkMD5.cpp.

72 {
73 SkMD5::Digest digest;
74 // Get the number of bits before padding.
75 uint8_t bits[8];
76 encode(bits, this->byteCount << 3);
77
78 // Pad out to 56 mod 64.
79 unsigned int bufferIndex = (unsigned int)(this->byteCount & 0x3F);
80 unsigned int paddingLength = (bufferIndex < 56) ? (56 - bufferIndex) : (120 - bufferIndex);
81 static const uint8_t PADDING[64] = {
82 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 };
87 (void)this->write(PADDING, paddingLength);
88
89 // Append length (length before padding, will cause final update).
90 (void)this->write(bits, 8);
91
92 // Write out digest.
93 encode(digest.data, this->state);
94
95#if defined(SK_MD5_CLEAR_DATA)
96 // Clear state.
97 memset(this, 0, sizeof(*this));
98#endif
99 return digest;
100}
static void encode(uint8_t output[16], const uint32_t input[4])
Definition: SkMD5.cpp:240
bool write(const void *buffer, size_t size) final
Definition: SkMD5.cpp:42
uint8_t data[16]
Definition: SkMD5.h:39

◆ write()

bool SkMD5::write ( const void *  buffer,
size_t  size 
)
finalvirtual

Processes input, adding it to the digest. Calling this after finish is undefined.

Implements SkWStream.

Definition at line 42 of file SkMD5.cpp.

42 {
43 const uint8_t* input = reinterpret_cast<const uint8_t*>(buf);
44 unsigned int bufferIndex = (unsigned int)(this->byteCount & 0x3F);
45 unsigned int bufferAvailable = 64 - bufferIndex;
46
47 unsigned int inputIndex;
48 if (inputLength >= bufferAvailable) {
49 if (bufferIndex) {
50 sk_careful_memcpy(&this->buffer[bufferIndex], input, bufferAvailable);
51 transform(this->state, this->buffer);
52 inputIndex = bufferAvailable;
53 } else {
54 inputIndex = 0;
55 }
56
57 for (; inputIndex + 63 < inputLength; inputIndex += 64) {
58 transform(this->state, &input[inputIndex]);
59 }
60
61 bufferIndex = 0;
62 } else {
63 inputIndex = 0;
64 }
65
66 sk_careful_memcpy(&this->buffer[bufferIndex], &input[inputIndex], inputLength - inputIndex);
67
68 this->byteCount += inputLength;
69 return true;
70}
static void transform(uint32_t state[4], const uint8_t block[64])
Definition: SkMD5.cpp:149
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
Definition: SkMalloc.h:125

The documentation for this class was generated from the following files: