-/* $OpenBSD: md5.c,v 1.3 2014/11/16 17:39:09 tedu Exp $ */
+/* $OpenBSD: md5.c,v 1.4 2014/12/28 10:04:35 tedu Exp $ */
/*
* This code implements the MD5 message-digest algorithm.
if (len >= need) {
if (have != 0) {
- bcopy(input, ctx->buffer + have, need);
+ memcpy(ctx->buffer + have, input, need);
MD5Transform(ctx->state, ctx->buffer);
input += need;
len -= need;
/* Handle any remaining bytes of data. */
if (len != 0)
- bcopy(input, ctx->buffer + have, len);
+ memcpy(ctx->buffer + have, input, len);
}
/*
MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */
MD5Update(ctx, count, 8);
- if (digest != NULL) {
- for (i = 0; i < 4; i++)
- PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
- }
+ for (i = 0; i < 4; i++)
+ PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
explicit_bzero(ctx, sizeof(*ctx)); /* in case it's sensitive */
}
u_int32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4];
#if BYTE_ORDER == LITTLE_ENDIAN
- bcopy(block, in, sizeof(in));
+ memcpy(in, block, sizeof(in));
#else
for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) {
in[a] = (u_int32_t)(
-/* $OpenBSD: sha1.c,v 1.10 2014/11/16 17:39:09 tedu Exp $ */
+/* $OpenBSD: sha1.c,v 1.11 2014/12/28 10:04:35 tedu Exp $ */
/*
* SHA-1 in C
unsigned char workspace[SHA1_BLOCK_LENGTH];
block = (CHAR64LONG16 *)workspace;
- bcopy(buffer, block, SHA1_BLOCK_LENGTH);
+ memcpy(block, buffer, SHA1_BLOCK_LENGTH);
#else
block = (CHAR64LONG16 *)buffer;
#endif
j = (u_int32_t)((context->count >> 3) & 63);
context->count += (len << 3);
if ((j + len) > 63) {
- bcopy(data, &context->buffer[j], (i = 64 - j));
+ memcpy(&context->buffer[j], data, (i = 64 - j));
SHA1Transform(context->state, context->buffer);
for ( ; i + 63 < len; i += 64) {
SHA1Transform(context->state, &data[i]);
j = 0;
}
else i = 0;
- bcopy(&data[i], &context->buffer[j], len - i);
+ memcpy(&context->buffer[j], &data[i], len - i);
}
}
SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
- if (digest)
- for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
- digest[i] = (unsigned char)((context->state[i >> 2] >>
- ((3 - (i & 3)) * 8)) & 255);
- }
- explicit_bzero(&finalcount, 8);
-#if 0 /* We want to use this for "keyfill" */
- /* Wipe variables */
- i = 0;
- bzero(context->buffer, 64);
- bzero(context->state, 20);
- bzero(context->count, 8);
-#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */
- SHA1Transform(context->state, context->buffer);
-#endif
-#endif
+ for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+ digest[i] = (unsigned char)((context->state[i >> 2] >>
+ ((3 - (i & 3)) * 8)) & 255);
+ }
+ explicit_bzero(&finalcount, sizeof(finalcount));
+ explicit_bzero(context, sizeof(*context));
}