/src/openssl30/include/crypto/md32_common.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the Apache License 2.0 (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | /*- |
11 | | * This is a generic 32 bit "collector" for message digest algorithms. |
12 | | * Whenever needed it collects input character stream into chunks of |
13 | | * 32 bit values and invokes a block function that performs actual hash |
14 | | * calculations. |
15 | | * |
16 | | * Porting guide. |
17 | | * |
18 | | * Obligatory macros: |
19 | | * |
20 | | * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN |
21 | | * this macro defines byte order of input stream. |
22 | | * HASH_CBLOCK |
23 | | * size of a unit chunk HASH_BLOCK operates on. |
24 | | * HASH_LONG |
25 | | * has to be at least 32 bit wide. |
26 | | * HASH_CTX |
27 | | * context structure that at least contains following |
28 | | * members: |
29 | | * typedef struct { |
30 | | * ... |
31 | | * HASH_LONG Nl,Nh; |
32 | | * either { |
33 | | * HASH_LONG data[HASH_LBLOCK]; |
34 | | * unsigned char data[HASH_CBLOCK]; |
35 | | * }; |
36 | | * unsigned int num; |
37 | | * ... |
38 | | * } HASH_CTX; |
39 | | * data[] vector is expected to be zeroed upon first call to |
40 | | * HASH_UPDATE. |
41 | | * HASH_UPDATE |
42 | | * name of "Update" function, implemented here. |
43 | | * HASH_TRANSFORM |
44 | | * name of "Transform" function, implemented here. |
45 | | * HASH_FINAL |
46 | | * name of "Final" function, implemented here. |
47 | | * HASH_BLOCK_DATA_ORDER |
48 | | * name of "block" function capable of treating *unaligned* input |
49 | | * message in original (data) byte order, implemented externally. |
50 | | * HASH_MAKE_STRING |
51 | | * macro converting context variables to an ASCII hash string. |
52 | | * |
53 | | * MD5 example: |
54 | | * |
55 | | * #define DATA_ORDER_IS_LITTLE_ENDIAN |
56 | | * |
57 | | * #define HASH_LONG MD5_LONG |
58 | | * #define HASH_CTX MD5_CTX |
59 | | * #define HASH_CBLOCK MD5_CBLOCK |
60 | | * #define HASH_UPDATE MD5_Update |
61 | | * #define HASH_TRANSFORM MD5_Transform |
62 | | * #define HASH_FINAL MD5_Final |
63 | | * #define HASH_BLOCK_DATA_ORDER md5_block_data_order |
64 | | */ |
65 | | |
66 | | #include <openssl/crypto.h> |
67 | | |
68 | | #if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) |
69 | | #error "DATA_ORDER must be defined!" |
70 | | #endif |
71 | | |
72 | | #ifndef HASH_CBLOCK |
73 | | #error "HASH_CBLOCK must be defined!" |
74 | | #endif |
75 | | #ifndef HASH_LONG |
76 | | #error "HASH_LONG must be defined!" |
77 | | #endif |
78 | | #ifndef HASH_CTX |
79 | | #error "HASH_CTX must be defined!" |
80 | | #endif |
81 | | |
82 | | #ifndef HASH_UPDATE |
83 | | #error "HASH_UPDATE must be defined!" |
84 | | #endif |
85 | | #ifndef HASH_TRANSFORM |
86 | | #error "HASH_TRANSFORM must be defined!" |
87 | | #endif |
88 | | #ifndef HASH_FINAL |
89 | | #error "HASH_FINAL must be defined!" |
90 | | #endif |
91 | | |
92 | | #ifndef HASH_BLOCK_DATA_ORDER |
93 | | #error "HASH_BLOCK_DATA_ORDER must be defined!" |
94 | | #endif |
95 | | |
96 | 972M | #define ROTATE(a, n) (((a) << (n)) | (((a) & 0xffffffff) >> (32 - (n)))) |
97 | | |
98 | | #if defined(DATA_ORDER_IS_BIG_ENDIAN) |
99 | | |
100 | 8.35M | #define HOST_c2l(c, l) (l = (((unsigned long)(*((c)++))) << 24), \ |
101 | 8.35M | l |= (((unsigned long)(*((c)++))) << 16), \ |
102 | 8.35M | l |= (((unsigned long)(*((c)++))) << 8), \ |
103 | 8.35M | l |= (((unsigned long)(*((c)++))))) |
104 | 13.3M | #define HOST_l2c(l, c) (*((c)++) = (unsigned char)(((l) >> 24) & 0xff), \ |
105 | 13.3M | *((c)++) = (unsigned char)(((l) >> 16) & 0xff), \ |
106 | 13.3M | *((c)++) = (unsigned char)(((l) >> 8) & 0xff), \ |
107 | 13.3M | *((c)++) = (unsigned char)(((l)) & 0xff), \ |
108 | 13.3M | l) |
109 | | |
110 | | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) |
111 | | |
112 | 34.5M | #define HOST_c2l(c, l) (l = (((unsigned long)(*((c)++)))), \ |
113 | 34.5M | l |= (((unsigned long)(*((c)++))) << 8), \ |
114 | 34.5M | l |= (((unsigned long)(*((c)++))) << 16), \ |
115 | 34.5M | l |= (((unsigned long)(*((c)++))) << 24)) |
116 | 17.7M | #define HOST_l2c(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \ |
117 | 17.7M | *((c)++) = (unsigned char)(((l) >> 8) & 0xff), \ |
118 | 17.7M | *((c)++) = (unsigned char)(((l) >> 16) & 0xff), \ |
119 | 17.7M | *((c)++) = (unsigned char)(((l) >> 24) & 0xff), \ |
120 | 17.7M | l) |
121 | | |
122 | | #endif |
123 | | |
124 | | /* |
125 | | * Time for some action :-) |
126 | | */ |
127 | | |
128 | | int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len) |
129 | 1.06G | { |
130 | 1.06G | const unsigned char *data = data_; |
131 | 1.06G | unsigned char *p; |
132 | 1.06G | HASH_LONG l; |
133 | 1.06G | size_t n; |
134 | | |
135 | 1.06G | if (len == 0) |
136 | 0 | return 1; |
137 | | |
138 | 1.06G | l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL; |
139 | 1.06G | if (l < c->Nl) /* overflow */ |
140 | 0 | c->Nh++; |
141 | 1.06G | c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on |
142 | | * 16-bit */ |
143 | 1.06G | c->Nl = l; |
144 | | |
145 | 1.06G | n = c->num; |
146 | 1.06G | if (n != 0) { |
147 | 531M | p = (unsigned char *)c->data; |
148 | | |
149 | 531M | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { |
150 | 265M | memcpy(p + n, data, HASH_CBLOCK - n); |
151 | 265M | HASH_BLOCK_DATA_ORDER(c, p, 1); |
152 | 265M | n = HASH_CBLOCK - n; |
153 | 265M | data += n; |
154 | 265M | len -= n; |
155 | 265M | c->num = 0; |
156 | | /* |
157 | | * We use memset rather than OPENSSL_cleanse() here deliberately. |
158 | | * Using OPENSSL_cleanse() here could be a performance issue. It |
159 | | * will get properly cleansed on finalisation so this isn't a |
160 | | * security problem. |
161 | | */ |
162 | 265M | memset(p, 0, HASH_CBLOCK); /* keep it zeroed */ |
163 | 265M | } else { |
164 | 265M | memcpy(p + n, data, len); |
165 | 265M | c->num += (unsigned int)len; |
166 | 265M | return 1; |
167 | 265M | } |
168 | 531M | } |
169 | | |
170 | 802M | n = len / HASH_CBLOCK; |
171 | 802M | if (n > 0) { |
172 | 1.54M | HASH_BLOCK_DATA_ORDER(c, data, n); |
173 | 1.54M | n *= HASH_CBLOCK; |
174 | 1.54M | data += n; |
175 | 1.54M | len -= n; |
176 | 1.54M | } |
177 | | |
178 | 802M | if (len != 0) { |
179 | 535M | p = (unsigned char *)c->data; |
180 | 535M | c->num = (unsigned int)len; |
181 | 535M | memcpy(p, data, len); |
182 | 535M | } |
183 | 802M | return 1; |
184 | 1.06G | } Unexecuted instantiation: MD4_Update Line | Count | Source | 129 | 523k | { | 130 | 523k | const unsigned char *data = data_; | 131 | 523k | unsigned char *p; | 132 | 523k | HASH_LONG l; | 133 | 523k | size_t n; | 134 | | | 135 | 523k | if (len == 0) | 136 | 0 | return 1; | 137 | | | 138 | 523k | l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL; | 139 | 523k | if (l < c->Nl) /* overflow */ | 140 | 0 | c->Nh++; | 141 | 523k | c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on | 142 | | * 16-bit */ | 143 | 523k | c->Nl = l; | 144 | | | 145 | 523k | n = c->num; | 146 | 523k | if (n != 0) { | 147 | 140k | p = (unsigned char *)c->data; | 148 | | | 149 | 140k | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { | 150 | 74.1k | memcpy(p + n, data, HASH_CBLOCK - n); | 151 | 74.1k | HASH_BLOCK_DATA_ORDER(c, p, 1); | 152 | 74.1k | n = HASH_CBLOCK - n; | 153 | 74.1k | data += n; | 154 | 74.1k | len -= n; | 155 | 74.1k | c->num = 0; | 156 | | /* | 157 | | * We use memset rather than OPENSSL_cleanse() here deliberately. | 158 | | * Using OPENSSL_cleanse() here could be a performance issue. It | 159 | | * will get properly cleansed on finalisation so this isn't a | 160 | | * security problem. | 161 | | */ | 162 | 74.1k | memset(p, 0, HASH_CBLOCK); /* keep it zeroed */ | 163 | 74.1k | } else { | 164 | 66.3k | memcpy(p + n, data, len); | 165 | 66.3k | c->num += (unsigned int)len; | 166 | 66.3k | return 1; | 167 | 66.3k | } | 168 | 140k | } | 169 | | | 170 | 456k | n = len / HASH_CBLOCK; | 171 | 456k | if (n > 0) { | 172 | 69.2k | HASH_BLOCK_DATA_ORDER(c, data, n); | 173 | 69.2k | n *= HASH_CBLOCK; | 174 | 69.2k | data += n; | 175 | 69.2k | len -= n; | 176 | 69.2k | } | 177 | | | 178 | 456k | if (len != 0) { | 179 | 417k | p = (unsigned char *)c->data; | 180 | 417k | c->num = (unsigned int)len; | 181 | 417k | memcpy(p, data, len); | 182 | 417k | } | 183 | 456k | return 1; | 184 | 523k | } |
Line | Count | Source | 129 | 1.62M | { | 130 | 1.62M | const unsigned char *data = data_; | 131 | 1.62M | unsigned char *p; | 132 | 1.62M | HASH_LONG l; | 133 | 1.62M | size_t n; | 134 | | | 135 | 1.62M | if (len == 0) | 136 | 0 | return 1; | 137 | | | 138 | 1.62M | l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL; | 139 | 1.62M | if (l < c->Nl) /* overflow */ | 140 | 0 | c->Nh++; | 141 | 1.62M | c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on | 142 | | * 16-bit */ | 143 | 1.62M | c->Nl = l; | 144 | | | 145 | 1.62M | n = c->num; | 146 | 1.62M | if (n != 0) { | 147 | 532 | p = (unsigned char *)c->data; | 148 | | | 149 | 532 | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { | 150 | 185 | memcpy(p + n, data, HASH_CBLOCK - n); | 151 | 185 | HASH_BLOCK_DATA_ORDER(c, p, 1); | 152 | 185 | n = HASH_CBLOCK - n; | 153 | 185 | data += n; | 154 | 185 | len -= n; | 155 | 185 | c->num = 0; | 156 | | /* | 157 | | * We use memset rather than OPENSSL_cleanse() here deliberately. | 158 | | * Using OPENSSL_cleanse() here could be a performance issue. It | 159 | | * will get properly cleansed on finalisation so this isn't a | 160 | | * security problem. | 161 | | */ | 162 | 185 | memset(p, 0, HASH_CBLOCK); /* keep it zeroed */ | 163 | 347 | } else { | 164 | 347 | memcpy(p + n, data, len); | 165 | 347 | c->num += (unsigned int)len; | 166 | 347 | return 1; | 167 | 347 | } | 168 | 532 | } | 169 | | | 170 | 1.62M | n = len / HASH_CBLOCK; | 171 | 1.62M | if (n > 0) { | 172 | 1.91k | HASH_BLOCK_DATA_ORDER(c, data, n); | 173 | 1.91k | n *= HASH_CBLOCK; | 174 | 1.91k | data += n; | 175 | 1.91k | len -= n; | 176 | 1.91k | } | 177 | | | 178 | 1.62M | if (len != 0) { | 179 | 1.62M | p = (unsigned char *)c->data; | 180 | 1.62M | c->num = (unsigned int)len; | 181 | 1.62M | memcpy(p, data, len); | 182 | 1.62M | } | 183 | 1.62M | return 1; | 184 | 1.62M | } |
Line | Count | Source | 129 | 1.25M | { | 130 | 1.25M | const unsigned char *data = data_; | 131 | 1.25M | unsigned char *p; | 132 | 1.25M | HASH_LONG l; | 133 | 1.25M | size_t n; | 134 | | | 135 | 1.25M | if (len == 0) | 136 | 0 | return 1; | 137 | | | 138 | 1.25M | l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL; | 139 | 1.25M | if (l < c->Nl) /* overflow */ | 140 | 0 | c->Nh++; | 141 | 1.25M | c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on | 142 | | * 16-bit */ | 143 | 1.25M | c->Nl = l; | 144 | | | 145 | 1.25M | n = c->num; | 146 | 1.25M | if (n != 0) { | 147 | 124k | p = (unsigned char *)c->data; | 148 | | | 149 | 124k | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { | 150 | 64.9k | memcpy(p + n, data, HASH_CBLOCK - n); | 151 | 64.9k | HASH_BLOCK_DATA_ORDER(c, p, 1); | 152 | 64.9k | n = HASH_CBLOCK - n; | 153 | 64.9k | data += n; | 154 | 64.9k | len -= n; | 155 | 64.9k | c->num = 0; | 156 | | /* | 157 | | * We use memset rather than OPENSSL_cleanse() here deliberately. | 158 | | * Using OPENSSL_cleanse() here could be a performance issue. It | 159 | | * will get properly cleansed on finalisation so this isn't a | 160 | | * security problem. | 161 | | */ | 162 | 64.9k | memset(p, 0, HASH_CBLOCK); /* keep it zeroed */ | 163 | 64.9k | } else { | 164 | 59.7k | memcpy(p + n, data, len); | 165 | 59.7k | c->num += (unsigned int)len; | 166 | 59.7k | return 1; | 167 | 59.7k | } | 168 | 124k | } | 169 | | | 170 | 1.19M | n = len / HASH_CBLOCK; | 171 | 1.19M | if (n > 0) { | 172 | 405k | HASH_BLOCK_DATA_ORDER(c, data, n); | 173 | 405k | n *= HASH_CBLOCK; | 174 | 405k | data += n; | 175 | 405k | len -= n; | 176 | 405k | } | 177 | | | 178 | 1.19M | if (len != 0) { | 179 | 1.06M | p = (unsigned char *)c->data; | 180 | 1.06M | c->num = (unsigned int)len; | 181 | 1.06M | memcpy(p, data, len); | 182 | 1.06M | } | 183 | 1.19M | return 1; | 184 | 1.25M | } |
Line | Count | Source | 129 | 1.06G | { | 130 | 1.06G | const unsigned char *data = data_; | 131 | 1.06G | unsigned char *p; | 132 | 1.06G | HASH_LONG l; | 133 | 1.06G | size_t n; | 134 | | | 135 | 1.06G | if (len == 0) | 136 | 0 | return 1; | 137 | | | 138 | 1.06G | l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL; | 139 | 1.06G | if (l < c->Nl) /* overflow */ | 140 | 0 | c->Nh++; | 141 | 1.06G | c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on | 142 | | * 16-bit */ | 143 | 1.06G | c->Nl = l; | 144 | | | 145 | 1.06G | n = c->num; | 146 | 1.06G | if (n != 0) { | 147 | 531M | p = (unsigned char *)c->data; | 148 | | | 149 | 531M | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { | 150 | 265M | memcpy(p + n, data, HASH_CBLOCK - n); | 151 | 265M | HASH_BLOCK_DATA_ORDER(c, p, 1); | 152 | 265M | n = HASH_CBLOCK - n; | 153 | 265M | data += n; | 154 | 265M | len -= n; | 155 | 265M | c->num = 0; | 156 | | /* | 157 | | * We use memset rather than OPENSSL_cleanse() here deliberately. | 158 | | * Using OPENSSL_cleanse() here could be a performance issue. It | 159 | | * will get properly cleansed on finalisation so this isn't a | 160 | | * security problem. | 161 | | */ | 162 | 265M | memset(p, 0, HASH_CBLOCK); /* keep it zeroed */ | 163 | 265M | } else { | 164 | 265M | memcpy(p + n, data, len); | 165 | 265M | c->num += (unsigned int)len; | 166 | 265M | return 1; | 167 | 265M | } | 168 | 531M | } | 169 | | | 170 | 798M | n = len / HASH_CBLOCK; | 171 | 798M | if (n > 0) { | 172 | 1.06M | HASH_BLOCK_DATA_ORDER(c, data, n); | 173 | 1.06M | n *= HASH_CBLOCK; | 174 | 1.06M | data += n; | 175 | 1.06M | len -= n; | 176 | 1.06M | } | 177 | | | 178 | 798M | if (len != 0) { | 179 | 532M | p = (unsigned char *)c->data; | 180 | 532M | c->num = (unsigned int)len; | 181 | 532M | memcpy(p, data, len); | 182 | 532M | } | 183 | 798M | return 1; | 184 | 1.06G | } |
Line | Count | Source | 129 | 4.58k | { | 130 | 4.58k | const unsigned char *data = data_; | 131 | 4.58k | unsigned char *p; | 132 | 4.58k | HASH_LONG l; | 133 | 4.58k | size_t n; | 134 | | | 135 | 4.58k | if (len == 0) | 136 | 0 | return 1; | 137 | | | 138 | 4.58k | l = (c->Nl + (((HASH_LONG)len) << 3)) & 0xffffffffUL; | 139 | 4.58k | if (l < c->Nl) /* overflow */ | 140 | 0 | c->Nh++; | 141 | 4.58k | c->Nh += (HASH_LONG)(len >> 29); /* might cause compiler warning on | 142 | | * 16-bit */ | 143 | 4.58k | c->Nl = l; | 144 | | | 145 | 4.58k | n = c->num; | 146 | 4.58k | if (n != 0) { | 147 | 414 | p = (unsigned char *)c->data; | 148 | | | 149 | 414 | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { | 150 | 164 | memcpy(p + n, data, HASH_CBLOCK - n); | 151 | 164 | HASH_BLOCK_DATA_ORDER(c, p, 1); | 152 | 164 | n = HASH_CBLOCK - n; | 153 | 164 | data += n; | 154 | 164 | len -= n; | 155 | 164 | c->num = 0; | 156 | | /* | 157 | | * We use memset rather than OPENSSL_cleanse() here deliberately. | 158 | | * Using OPENSSL_cleanse() here could be a performance issue. It | 159 | | * will get properly cleansed on finalisation so this isn't a | 160 | | * security problem. | 161 | | */ | 162 | 164 | memset(p, 0, HASH_CBLOCK); /* keep it zeroed */ | 163 | 250 | } else { | 164 | 250 | memcpy(p + n, data, len); | 165 | 250 | c->num += (unsigned int)len; | 166 | 250 | return 1; | 167 | 250 | } | 168 | 414 | } | 169 | | | 170 | 4.33k | n = len / HASH_CBLOCK; | 171 | 4.33k | if (n > 0) { | 172 | 2.08k | HASH_BLOCK_DATA_ORDER(c, data, n); | 173 | 2.08k | n *= HASH_CBLOCK; | 174 | 2.08k | data += n; | 175 | 2.08k | len -= n; | 176 | 2.08k | } | 177 | | | 178 | 4.33k | if (len != 0) { | 179 | 2.37k | p = (unsigned char *)c->data; | 180 | 2.37k | c->num = (unsigned int)len; | 181 | 2.37k | memcpy(p, data, len); | 182 | 2.37k | } | 183 | 4.33k | return 1; | 184 | 4.58k | } |
|
185 | | |
186 | | void HASH_TRANSFORM(HASH_CTX *c, const unsigned char *data) |
187 | 1.24M | { |
188 | 1.24M | HASH_BLOCK_DATA_ORDER(c, data, 1); |
189 | 1.24M | } Unexecuted instantiation: MD4_Transform Unexecuted instantiation: MD5_Transform Unexecuted instantiation: RIPEMD160_Transform Line | Count | Source | 187 | 1.06M | { | 188 | 1.06M | HASH_BLOCK_DATA_ORDER(c, data, 1); | 189 | 1.06M | } |
Line | Count | Source | 187 | 184k | { | 188 | 184k | HASH_BLOCK_DATA_ORDER(c, data, 1); | 189 | 184k | } |
Unexecuted instantiation: ossl_sm3_transform |
190 | | |
191 | | int HASH_FINAL(unsigned char *md, HASH_CTX *c) |
192 | 4.46M | { |
193 | 4.46M | unsigned char *p = (unsigned char *)c->data; |
194 | 4.46M | size_t n = c->num; |
195 | | |
196 | 4.46M | p[n] = 0x80; /* there is always room for one */ |
197 | 4.46M | n++; |
198 | | |
199 | 4.46M | if (n > (HASH_CBLOCK - 8)) { |
200 | 88.1k | memset(p + n, 0, HASH_CBLOCK - n); |
201 | 88.1k | n = 0; |
202 | 88.1k | HASH_BLOCK_DATA_ORDER(c, p, 1); |
203 | 88.1k | } |
204 | 4.46M | memset(p + n, 0, HASH_CBLOCK - 8 - n); |
205 | | |
206 | 4.46M | p += HASH_CBLOCK - 8; |
207 | | #if defined(DATA_ORDER_IS_BIG_ENDIAN) |
208 | 1.84M | (void)HOST_l2c(c->Nh, p); |
209 | 1.84M | (void)HOST_l2c(c->Nl, p); |
210 | | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) |
211 | 2.62M | (void)HOST_l2c(c->Nl, p); |
212 | 2.62M | (void)HOST_l2c(c->Nh, p); |
213 | | #endif |
214 | 4.46M | p -= HASH_CBLOCK; |
215 | 4.46M | HASH_BLOCK_DATA_ORDER(c, p, 1); |
216 | 4.46M | c->num = 0; |
217 | 4.46M | OPENSSL_cleanse(p, HASH_CBLOCK); |
218 | | |
219 | | #ifndef HASH_MAKE_STRING |
220 | | #error "HASH_MAKE_STRING must be defined!" |
221 | | #else |
222 | 4.46M | HASH_MAKE_STRING(c, md); |
223 | 149k | #endif |
224 | | |
225 | 149k | return 1; |
226 | 4.46M | } Unexecuted instantiation: MD4_Final Line | Count | Source | 192 | 627k | { | 193 | 627k | unsigned char *p = (unsigned char *)c->data; | 194 | 627k | size_t n = c->num; | 195 | | | 196 | 627k | p[n] = 0x80; /* there is always room for one */ | 197 | 627k | n++; | 198 | | | 199 | 627k | if (n > (HASH_CBLOCK - 8)) { | 200 | 9.79k | memset(p + n, 0, HASH_CBLOCK - n); | 201 | 9.79k | n = 0; | 202 | 9.79k | HASH_BLOCK_DATA_ORDER(c, p, 1); | 203 | 9.79k | } | 204 | 627k | memset(p + n, 0, HASH_CBLOCK - 8 - n); | 205 | | | 206 | 627k | p += HASH_CBLOCK - 8; | 207 | | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 208 | | (void)HOST_l2c(c->Nh, p); | 209 | | (void)HOST_l2c(c->Nl, p); | 210 | | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 211 | 627k | (void)HOST_l2c(c->Nl, p); | 212 | 627k | (void)HOST_l2c(c->Nh, p); | 213 | 627k | #endif | 214 | 627k | p -= HASH_CBLOCK; | 215 | 627k | HASH_BLOCK_DATA_ORDER(c, p, 1); | 216 | 627k | c->num = 0; | 217 | 627k | OPENSSL_cleanse(p, HASH_CBLOCK); | 218 | | | 219 | | #ifndef HASH_MAKE_STRING | 220 | | #error "HASH_MAKE_STRING must be defined!" | 221 | | #else | 222 | 627k | HASH_MAKE_STRING(c, md); | 223 | 627k | #endif | 224 | | | 225 | 627k | return 1; | 226 | 627k | } |
Line | Count | Source | 192 | 1.99M | { | 193 | 1.99M | unsigned char *p = (unsigned char *)c->data; | 194 | 1.99M | size_t n = c->num; | 195 | | | 196 | 1.99M | p[n] = 0x80; /* there is always room for one */ | 197 | 1.99M | n++; | 198 | | | 199 | 1.99M | if (n > (HASH_CBLOCK - 8)) { | 200 | 261 | memset(p + n, 0, HASH_CBLOCK - n); | 201 | 261 | n = 0; | 202 | 261 | HASH_BLOCK_DATA_ORDER(c, p, 1); | 203 | 261 | } | 204 | 1.99M | memset(p + n, 0, HASH_CBLOCK - 8 - n); | 205 | | | 206 | 1.99M | p += HASH_CBLOCK - 8; | 207 | | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 208 | | (void)HOST_l2c(c->Nh, p); | 209 | | (void)HOST_l2c(c->Nl, p); | 210 | | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 211 | 1.99M | (void)HOST_l2c(c->Nl, p); | 212 | 1.99M | (void)HOST_l2c(c->Nh, p); | 213 | 1.99M | #endif | 214 | 1.99M | p -= HASH_CBLOCK; | 215 | 1.99M | HASH_BLOCK_DATA_ORDER(c, p, 1); | 216 | 1.99M | c->num = 0; | 217 | 1.99M | OPENSSL_cleanse(p, HASH_CBLOCK); | 218 | | | 219 | | #ifndef HASH_MAKE_STRING | 220 | | #error "HASH_MAKE_STRING must be defined!" | 221 | | #else | 222 | 1.99M | HASH_MAKE_STRING(c, md); | 223 | 1.99M | #endif | 224 | | | 225 | 1.99M | return 1; | 226 | 1.99M | } |
Line | Count | Source | 192 | 1.69M | { | 193 | 1.69M | unsigned char *p = (unsigned char *)c->data; | 194 | 1.69M | size_t n = c->num; | 195 | | | 196 | 1.69M | p[n] = 0x80; /* there is always room for one */ | 197 | 1.69M | n++; | 198 | | | 199 | 1.69M | if (n > (HASH_CBLOCK - 8)) { | 200 | 77.4k | memset(p + n, 0, HASH_CBLOCK - n); | 201 | 77.4k | n = 0; | 202 | 77.4k | HASH_BLOCK_DATA_ORDER(c, p, 1); | 203 | 77.4k | } | 204 | 1.69M | memset(p + n, 0, HASH_CBLOCK - 8 - n); | 205 | | | 206 | 1.69M | p += HASH_CBLOCK - 8; | 207 | 1.69M | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 208 | 1.69M | (void)HOST_l2c(c->Nh, p); | 209 | 1.69M | (void)HOST_l2c(c->Nl, p); | 210 | | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 211 | | (void)HOST_l2c(c->Nl, p); | 212 | | (void)HOST_l2c(c->Nh, p); | 213 | | #endif | 214 | 1.69M | p -= HASH_CBLOCK; | 215 | 1.69M | HASH_BLOCK_DATA_ORDER(c, p, 1); | 216 | 1.69M | c->num = 0; | 217 | 1.69M | OPENSSL_cleanse(p, HASH_CBLOCK); | 218 | | | 219 | | #ifndef HASH_MAKE_STRING | 220 | | #error "HASH_MAKE_STRING must be defined!" | 221 | | #else | 222 | 1.69M | HASH_MAKE_STRING(c, md); | 223 | 1.69M | #endif | 224 | | | 225 | 1.69M | return 1; | 226 | 1.69M | } |
Line | Count | Source | 192 | 149k | { | 193 | 149k | unsigned char *p = (unsigned char *)c->data; | 194 | 149k | size_t n = c->num; | 195 | | | 196 | 149k | p[n] = 0x80; /* there is always room for one */ | 197 | 149k | n++; | 198 | | | 199 | 149k | if (n > (HASH_CBLOCK - 8)) { | 200 | 555 | memset(p + n, 0, HASH_CBLOCK - n); | 201 | 555 | n = 0; | 202 | 555 | HASH_BLOCK_DATA_ORDER(c, p, 1); | 203 | 555 | } | 204 | 149k | memset(p + n, 0, HASH_CBLOCK - 8 - n); | 205 | | | 206 | 149k | p += HASH_CBLOCK - 8; | 207 | 149k | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 208 | 149k | (void)HOST_l2c(c->Nh, p); | 209 | 149k | (void)HOST_l2c(c->Nl, p); | 210 | | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 211 | | (void)HOST_l2c(c->Nl, p); | 212 | | (void)HOST_l2c(c->Nh, p); | 213 | | #endif | 214 | 149k | p -= HASH_CBLOCK; | 215 | 149k | HASH_BLOCK_DATA_ORDER(c, p, 1); | 216 | 149k | c->num = 0; | 217 | 149k | OPENSSL_cleanse(p, HASH_CBLOCK); | 218 | | | 219 | | #ifndef HASH_MAKE_STRING | 220 | | #error "HASH_MAKE_STRING must be defined!" | 221 | | #else | 222 | 149k | HASH_MAKE_STRING(c, md); | 223 | 149k | #endif | 224 | | | 225 | 149k | return 1; | 226 | 149k | } |
Line | Count | Source | 192 | 2.24k | { | 193 | 2.24k | unsigned char *p = (unsigned char *)c->data; | 194 | 2.24k | size_t n = c->num; | 195 | | | 196 | 2.24k | p[n] = 0x80; /* there is always room for one */ | 197 | 2.24k | n++; | 198 | | | 199 | 2.24k | if (n > (HASH_CBLOCK - 8)) { | 200 | 55 | memset(p + n, 0, HASH_CBLOCK - n); | 201 | 55 | n = 0; | 202 | 55 | HASH_BLOCK_DATA_ORDER(c, p, 1); | 203 | 55 | } | 204 | 2.24k | memset(p + n, 0, HASH_CBLOCK - 8 - n); | 205 | | | 206 | 2.24k | p += HASH_CBLOCK - 8; | 207 | 2.24k | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | 208 | 2.24k | (void)HOST_l2c(c->Nh, p); | 209 | 2.24k | (void)HOST_l2c(c->Nl, p); | 210 | | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | 211 | | (void)HOST_l2c(c->Nl, p); | 212 | | (void)HOST_l2c(c->Nh, p); | 213 | | #endif | 214 | 2.24k | p -= HASH_CBLOCK; | 215 | 2.24k | HASH_BLOCK_DATA_ORDER(c, p, 1); | 216 | 2.24k | c->num = 0; | 217 | 2.24k | OPENSSL_cleanse(p, HASH_CBLOCK); | 218 | | | 219 | | #ifndef HASH_MAKE_STRING | 220 | | #error "HASH_MAKE_STRING must be defined!" | 221 | | #else | 222 | 2.24k | HASH_MAKE_STRING(c, md); | 223 | 2.24k | #endif | 224 | | | 225 | 2.24k | return 1; | 226 | 2.24k | } |
|
227 | | |
228 | | #ifndef MD32_REG_T |
229 | | #if defined(__alpha) || defined(__sparcv9) || defined(__mips) |
230 | | #define MD32_REG_T long |
231 | | /* |
232 | | * This comment was originally written for MD5, which is why it |
233 | | * discusses A-D. But it basically applies to all 32-bit digests, |
234 | | * which is why it was moved to common header file. |
235 | | * |
236 | | * In case you wonder why A-D are declared as long and not |
237 | | * as MD5_LONG. Doing so results in slight performance |
238 | | * boost on LP64 architectures. The catch is we don't |
239 | | * really care if 32 MSBs of a 64-bit register get polluted |
240 | | * with eventual overflows as we *save* only 32 LSBs in |
241 | | * *either* case. Now declaring 'em long excuses the compiler |
242 | | * from keeping 32 MSBs zeroed resulting in 13% performance |
243 | | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. |
244 | | * Well, to be honest it should say that this *prevents* |
245 | | * performance degradation. |
246 | | */ |
247 | | #else |
248 | | /* |
249 | | * Above is not absolute and there are LP64 compilers that |
250 | | * generate better code if MD32_REG_T is defined int. The above |
251 | | * pre-processor condition reflects the circumstances under which |
252 | | * the conclusion was made and is subject to further extension. |
253 | | */ |
254 | | #define MD32_REG_T int |
255 | | #endif |
256 | | #endif |