author | Edouard Tisserant <edouard@beremiz.fr> |
Fri, 08 Nov 2024 11:34:46 +0100 | |
changeset 4035 | c317fc64035e |
parent 3940 | 934bd46a7500 |
permissions | -rw-r--r-- |
3940
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
/* MD5 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
2 |
converted to C++ class by Frank Thilo (thilo@unix-ag.org) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
3 |
for bzflag (http://www.bzflag.org) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
4 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
5 |
based on: |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
6 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
7 |
md5.h and md5.c |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
8 |
reference implemantion of RFC 1321 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
9 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
10 |
Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
11 |
rights reserved. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
12 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
13 |
License to copy and use this software is granted provided that it |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
is identified as the "RSA Data Security, Inc. MD5 Message-Digest |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
15 |
Algorithm" in all material mentioning or referencing this software |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
16 |
or this function. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
17 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
18 |
License is also granted to make and use derivative works provided |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
19 |
that such works are identified as "derived from the RSA Data |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
20 |
Security, Inc. MD5 Message-Digest Algorithm" in all material |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
21 |
mentioning or referencing the derived work. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
22 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
23 |
RSA Data Security, Inc. makes no representations concerning either |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
24 |
the merchantability of this software or the suitability of this |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
25 |
software for any particular purpose. It is provided "as is" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
26 |
without express or implied warranty of any kind. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
27 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
28 |
These notices must be retained in any copies of any part of this |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
29 |
documentation and/or software. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
30 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
31 |
*/ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
32 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
33 |
#include <stdlib.h> |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
34 |
#include <string.h> |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
35 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
36 |
/* interface header */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
37 |
#include "md5.hpp" |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
38 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
39 |
// Constants for MD5Transform routine. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
40 |
#define S11 7 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
41 |
#define S12 12 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
42 |
#define S13 17 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
43 |
#define S14 22 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
44 |
#define S21 5 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
45 |
#define S22 9 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
46 |
#define S23 14 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
47 |
#define S24 20 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
48 |
#define S31 4 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
49 |
#define S32 11 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
50 |
#define S33 16 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
51 |
#define S34 23 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
52 |
#define S41 6 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
53 |
#define S42 10 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
54 |
#define S43 15 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
55 |
#define S44 21 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
56 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
57 |
/////////////////////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
58 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
59 |
// F, G, H and I are basic MD5 functions. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
60 |
inline uint32_t MD5::F(uint32_t x, uint32_t y, uint32_t z) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
61 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
62 |
return x & y | ~x & z; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
63 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
64 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
65 |
inline uint32_t MD5::G(uint32_t x, uint32_t y, uint32_t z) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
66 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
67 |
return x & z | y & ~z; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
68 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
69 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
70 |
inline uint32_t MD5::H(uint32_t x, uint32_t y, uint32_t z) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
71 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
72 |
return x ^ y ^ z; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
73 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
74 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
75 |
inline uint32_t MD5::I(uint32_t x, uint32_t y, uint32_t z) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
76 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
77 |
return y ^ (x | ~z); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
78 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
79 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
80 |
// rotate_left rotates x left n bits. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
81 |
inline uint32_t MD5::rotate_left(uint32_t x, int n) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
82 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
83 |
return (x << n) | (x >> (32 - n)); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
84 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
85 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
86 |
// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
87 |
// Rotation is separate from addition to prevent recomputation. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
88 |
inline void MD5::FF(uint32_t &a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
89 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
90 |
a = rotate_left(a + F(b, c, d) + x + ac, s) + b; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
91 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
92 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
93 |
inline void MD5::GG(uint32_t &a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
94 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
95 |
a = rotate_left(a + G(b, c, d) + x + ac, s) + b; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
96 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
97 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
98 |
inline void MD5::HH(uint32_t &a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
99 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
100 |
a = rotate_left(a + H(b, c, d) + x + ac, s) + b; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
101 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
102 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
103 |
inline void MD5::II(uint32_t &a, uint32_t b, uint32_t c, uint32_t d, uint32_t x, uint32_t s, uint32_t ac) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
104 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
105 |
a = rotate_left(a + I(b, c, d) + x + ac, s) + b; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
106 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
107 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
108 |
////////////////////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
109 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
110 |
// default ctor, just initailize |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
111 |
MD5::MD5() |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
112 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
113 |
init(); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
114 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
115 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
116 |
////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
117 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
118 |
void MD5::init() |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
119 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
120 |
count[0] = 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
121 |
count[1] = 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
122 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
123 |
// load magic initialization constants. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
124 |
state[0] = 0x67452301; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
125 |
state[1] = 0xefcdab89; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
126 |
state[2] = 0x98badcfe; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
127 |
state[3] = 0x10325476; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
128 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
129 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
130 |
////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
131 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
132 |
// decodes input (unsigned char) into output (uint32_t). Assumes len is a multiple of 4. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
133 |
void MD5::decode(uint32_t output[], const uint8_t input[], size_type len) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
134 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
135 |
for (unsigned int i = 0, j = 0; j < len; i++, j += 4) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
136 |
output[i] = ((uint32_t)input[j]) | (((uint32_t)input[j + 1]) << 8) | |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
137 |
(((uint32_t)input[j + 2]) << 16) | (((uint32_t)input[j + 3]) << 24); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
138 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
139 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
140 |
////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
141 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
142 |
// encodes input (uint32_t) into output (unsigned char). Assumes len is |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
143 |
// a multiple of 4. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
144 |
void MD5::encode(uint8_t output[], const uint32_t input[], size_type len) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
145 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
146 |
for (size_type i = 0, j = 0; j < len; i++, j += 4) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
147 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
148 |
output[j] = input[i] & 0xff; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
149 |
output[j + 1] = (input[i] >> 8) & 0xff; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
150 |
output[j + 2] = (input[i] >> 16) & 0xff; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
151 |
output[j + 3] = (input[i] >> 24) & 0xff; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
152 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
153 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
154 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
155 |
////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
156 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
157 |
// apply MD5 algo on a block |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
158 |
void MD5::transform(const uint8_t block[blocksize]) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
159 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
160 |
uint32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16]; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
161 |
decode(x, block, blocksize); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
162 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
163 |
/* Round 1 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
164 |
FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
165 |
FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
166 |
FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
167 |
FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
168 |
FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
169 |
FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
170 |
FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
171 |
FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
172 |
FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
173 |
FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
174 |
FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
175 |
FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
176 |
FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
177 |
FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
178 |
FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
179 |
FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
180 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
181 |
/* Round 2 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
182 |
GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
183 |
GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
184 |
GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
185 |
GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
186 |
GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
187 |
GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
188 |
GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
189 |
GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
190 |
GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
191 |
GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
192 |
GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
193 |
GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
194 |
GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
195 |
GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
196 |
GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
197 |
GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
198 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
199 |
/* Round 3 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
200 |
HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
201 |
HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
202 |
HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
203 |
HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
204 |
HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
205 |
HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
206 |
HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
207 |
HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
208 |
HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
209 |
HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
210 |
HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
211 |
HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
212 |
HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
213 |
HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
214 |
HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
215 |
HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
216 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
217 |
/* Round 4 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
218 |
II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
219 |
II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
220 |
II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
221 |
II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
222 |
II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
223 |
II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
224 |
II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
225 |
II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
226 |
II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
227 |
II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
228 |
II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
229 |
II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
230 |
II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
231 |
II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
232 |
II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
233 |
II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
234 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
235 |
state[0] += a; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
236 |
state[1] += b; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
237 |
state[2] += c; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
238 |
state[3] += d; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
239 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
240 |
// Zeroize sensitive information. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
241 |
memset(x, 0, sizeof x); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
242 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
243 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
244 |
////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
245 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
246 |
// MD5 block update operation. Continues an MD5 message-digest |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
247 |
// operation, processing another message block |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
248 |
void MD5::update(const unsigned char input[], size_type length) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
249 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
250 |
// compute number of bytes mod 64 |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
251 |
size_type index = count[0] / 8 % blocksize; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
252 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
253 |
// Update number of bits |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
254 |
if ((count[0] += (length << 3)) < (length << 3)) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
255 |
count[1]++; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
256 |
count[1] += (length >> 29); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
257 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
258 |
// number of bytes we need to fill in buffer |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
259 |
size_type firstpart = 64 - index; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
260 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
261 |
size_type i; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
262 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
263 |
// transform as many times as possible. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
264 |
if (length >= firstpart) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
265 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
266 |
// fill buffer first, transform |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
267 |
memcpy(&buffer[index], input, firstpart); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
268 |
transform(buffer); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
269 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
270 |
// transform chunks of blocksize (64 bytes) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
271 |
for (i = firstpart; i + blocksize <= length; i += blocksize) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
272 |
transform(&input[i]); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
273 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
274 |
index = 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
275 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
276 |
else |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
277 |
i = 0; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
278 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
279 |
// buffer remaining input |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
280 |
memcpy(&buffer[index], &input[i], length - i); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
281 |
} |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
282 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
283 |
////////////////////////////// |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
284 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
285 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
286 |
MD5::digest_t MD5::digest() |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
287 |
{ |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
288 |
static const unsigned char padding[64] = { |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
289 |
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
290 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
291 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
292 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
293 |
// Copies of hash state |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
294 |
uint8_t _buffer[blocksize]; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
295 |
uint32_t _count[2]; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
296 |
uint32_t _state[4]; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
297 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
298 |
// Backup hash state at previous block boundary |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
299 |
memcpy(_buffer, buffer, blocksize); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
300 |
memcpy(_count, count, 8); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
301 |
memcpy(_state, state, 16); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
302 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
303 |
// Save number of bits |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
304 |
unsigned char bits[8]; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
305 |
encode(bits, count, 8); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
306 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
307 |
// pad out to 56 mod 64. |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
308 |
size_type index = count[0] / 8 % 64; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
309 |
size_type padLen = (index < 56) ? (56 - index) : (120 - index); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
310 |
update(padding, padLen); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
311 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
312 |
// Append length (before padding) |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
313 |
update(bits, 8); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
314 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
315 |
// Store state in digest |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
316 |
digest_t result; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
317 |
encode(result.data, state, 16); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
318 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
319 |
// revert hash state to previous hash boundary |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
320 |
memcpy(buffer, _buffer, blocksize); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
321 |
memcpy(count, _count, 8); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
322 |
memcpy(state, _state, 16); |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
323 |
|
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
324 |
return result; |
934bd46a7500
C++ runtime: WIP: untested PLCObject implementation. Still missing tracing.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
325 |
} |