0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-11 03:21:53 +00:00

MD5: fixing indentation and code style

This commit is contained in:
Pavel Tvrdík 2015-05-13 11:26:37 +02:00
parent 2a2fef75cd
commit b335daec41

View File

@ -38,7 +38,8 @@ void byteReverse(unsigned char *buf, unsigned longs)
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
* initialization constants. * initialization constants.
*/ */
void md5_init(md5_context *ctx) void
md5_init(md5_context *ctx)
{ {
ctx->buf[0] = 0x67452301; ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89; ctx->buf[1] = 0xefcdab89;
@ -53,7 +54,8 @@ void md5_init(md5_context *ctx)
* Update context to reflect the concatenation of another buffer full * Update context to reflect the concatenation of another buffer full
* of bytes. * of bytes.
*/ */
void md5_update(md5_context *ctx, unsigned char const *buf, unsigned len) void
md5_update(md5_context *ctx, unsigned char const *buf, unsigned len)
{ {
u32 t; u32 t;
@ -68,11 +70,13 @@ void md5_update(md5_context *ctx, unsigned char const *buf, unsigned len)
/* Handle any leading odd-sized chunks */ /* Handle any leading odd-sized chunks */
if (t) { if (t)
{
unsigned char *p = (unsigned char *) ctx->in + t; unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t; t = 64 - t;
if (len < t) { if (len < t)
{
memcpy(p, buf, len); memcpy(p, buf, len);
return; return;
} }
@ -84,7 +88,8 @@ void md5_update(md5_context *ctx, unsigned char const *buf, unsigned len)
} }
/* Process data in 64-byte chunks */ /* Process data in 64-byte chunks */
while (len >= 64) { while (len >= 64)
{
memcpy(ctx->in, buf, 64); memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
md5_transform(ctx->buf, (u32 *) ctx->in); md5_transform(ctx->buf, (u32 *) ctx->in);
@ -101,7 +106,8 @@ void md5_update(md5_context *ctx, unsigned char const *buf, unsigned len)
* Final wrapup - pad to 64-byte boundary with the bit pattern * Final wrapup - pad to 64-byte boundary with the bit pattern
* 1 0* (64-bit count of bits processed, MSB-first) * 1 0* (64-bit count of bits processed, MSB-first)
*/ */
byte *md5_final(md5_context *ctx) byte *
md5_final(md5_context *ctx)
{ {
unsigned count; unsigned count;
unsigned char *p; unsigned char *p;
@ -118,7 +124,8 @@ byte *md5_final(md5_context *ctx)
count = 64 - 1 - count; count = 64 - 1 - count;
/* Pad out to 56 mod 64 */ /* Pad out to 56 mod 64 */
if (count < 8) { if (count < 8)
{
/* Two lots of padding: Pad the first block to 64 bytes */ /* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count); memset(p, 0, count);
byteReverse(ctx->in, 16); byteReverse(ctx->in, 16);
@ -126,7 +133,9 @@ byte *md5_final(md5_context *ctx)
/* Now fill the next block with 56 bytes */ /* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56); memset(ctx->in, 0, 56);
} else { }
else
{
/* Pad block to 56 bytes */ /* Pad block to 56 bytes */
memset(p, 0, count - 8); memset(p, 0, count - 8);
} }
@ -143,7 +152,8 @@ byte *md5_final(md5_context *ctx)
} }
/* I am a hard paranoid */ /* I am a hard paranoid */
void md5_erase_ctx(md5_context *ctx) void
md5_erase_ctx(md5_context *ctx)
{ {
memset((char *) ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ memset((char *) ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
} }
@ -165,7 +175,8 @@ void md5_erase_ctx(md5_context *ctx)
* reflect the addition of 16 longwords of new data. MD5Update blocks * reflect the addition of 16 longwords of new data. MD5Update blocks
* the data and converts bytes into longwords for this routine. * the data and converts bytes into longwords for this routine.
*/ */
void md5_transform(u32 buf[4], u32 const in[16]) void
md5_transform(u32 buf[4], u32 const in[16])
{ {
register u32 a, b, c, d; register u32 a, b, c, d;
@ -293,13 +304,15 @@ md5_hmac_init(md5_hmac_context *ctx, const byte *key, size_t keylen)
md5_update(&ctx->octx, buf, MD5_BLOCK_SIZE); md5_update(&ctx->octx, buf, MD5_BLOCK_SIZE);
} }
void md5_hmac_update(md5_hmac_context *ctx, const byte *buf, size_t buflen) void
md5_hmac_update(md5_hmac_context *ctx, const byte *buf, size_t buflen)
{ {
// Just update the inner digest // Just update the inner digest
md5_update(&ctx->ictx, buf, buflen); md5_update(&ctx->ictx, buf, buflen);
} }
byte *md5_hmac_final(md5_hmac_context *ctx) byte *
md5_hmac_final(md5_hmac_context *ctx)
{ {
// Finish the inner digest // Finish the inner digest
byte *isha = md5_final(&ctx->ictx); byte *isha = md5_final(&ctx->ictx);