146
145
byte* old_context;
147
146
byte* new_context;
148
byte* temp_alloc = NULL;
150
if (!is_binary(BIF_ARG_1)) {
150
if ((old_context = erts_get_aligned_binary_bytes(BIF_ARG_1, &temp_alloc)) == NULL) {
152
erts_free_aligned_binary_bytes(temp_alloc);
152
153
BIF_ERROR(BIF_P, BADARG);
154
GET_BINARY_BYTES(BIF_ARG_1, old_context);
156
155
if (binary_size(BIF_ARG_1) != sizeof(MD5_CTX)) {
159
bin = new_binary(BIF_P, old_context, sizeof(MD5_CTX));
160
GET_BINARY_BYTES(bin, new_context);
158
bin = erts_new_heap_binary(BIF_P, old_context, sizeof(MD5_CTX), &new_context);
161
159
if (!update((MD5_CTX *)new_context, BIF_ARG_2)) {
162
erts_free_aligned_binary_bytes(temp_alloc);
173
172
MD5_CTX ctx_copy;
173
byte* temp_alloc = NULL;
175
if (!is_binary(BIF_ARG_1)) {
175
if ((context = erts_get_aligned_binary_bytes(BIF_ARG_1, &temp_alloc)) == NULL) {
177
erts_free_aligned_binary_bytes(temp_alloc);
177
178
BIF_ERROR(BIF_P, BADARG);
179
GET_BINARY_BYTES(BIF_ARG_1, context);
180
180
if (binary_size(BIF_ARG_1) != sizeof(MD5_CTX)) {
183
bin = new_binary(BIF_P, (byte *)NULL, 16);
184
GET_BINARY_BYTES(bin, result);
183
bin = erts_new_heap_binary(BIF_P, (byte *)NULL, 16, &result);
185
184
memcpy(&ctx_copy, context, sizeof(MD5_CTX));
185
erts_free_aligned_binary_bytes(temp_alloc);
186
186
MD5Final(result, &ctx_copy);
191
update(MD5_CTX* context, Eterm obj)
191
update(MD5_CTX* context, Eterm iolist)
193
unsigned char buf[1024];
197
unsigned int csize = 0;
201
goto L_jump_start; /* Avoid push */
203
while (!ESTACK_ISEMPTY(s)) {
208
objp = list_val(obj);
211
if (csize >= sizeof(buf)) {
212
ASSERT(csize == sizeof buf);
213
MD5Update(context, buf, csize);
217
*cptr++ = unsigned_val(obj);
219
} else if (is_binary(obj)) {
221
MD5Update(context, buf, csize);
225
GET_BINARY_BYTES(obj, bytes);
226
MD5Update(context, bytes, binary_size(obj));
227
} else if (is_list(obj)) {
228
ESTACK_PUSH(s, CDR(objp));
229
goto L_iter_list; /* on head */
230
} else if (!is_nil(obj)) {
236
goto L_iter_list; /* on tail */
237
} else if (is_binary(obj)) {
239
MD5Update(context, buf, csize);
243
GET_BINARY_BYTES(obj, bytes);
244
MD5Update(context, bytes, binary_size(obj));
245
} else if (!is_nil(obj)) {
248
} else if (is_binary(obj)) {
250
MD5Update(context, buf, csize);
254
GET_BINARY_BYTES(obj, bytes);
255
MD5Update(context, bytes, binary_size(obj));
256
} else if (!is_nil(obj)) {
264
MD5Update(context, buf, csize);
197
if (is_binary(iolist)) {
201
ERTS_GET_BINARY_BYTES(iolist, bytes, bitoffs, bitsize);
205
size = binary_size(iolist);
207
MD5Update(context, bytes, size);
212
bytes = erts_alloc(ERTS_ALC_T_TMP, size);
213
r = io_list_to_buf(iolist, (char*) bytes, size);
216
} else if (r == -2) { /* Type error */
217
erts_free(ERTS_ALC_T_TMP, (void *) bytes);
220
ASSERT(r == -1); /* Overflow */
221
erts_free(ERTS_ALC_T_TMP, (void *) bytes);
222
if ((size = io_list_len(iolist)) < 0) { /* Type error */
225
bytes = erts_alloc(ERTS_ALC_T_TMP, size);
226
r = io_list_to_buf(iolist, (char*) bytes, size);
229
MD5Update(context, bytes, size);
230
erts_free(ERTS_ALC_T_TMP, (void *) bytes);