mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 10:11:53 +00:00
SHA: only renamed hd -> ctx
This commit is contained in:
parent
f84f925036
commit
5beaaa3d6b
30
lib/sha1.c
30
lib/sha1.c
@ -274,15 +274,15 @@ sha1_final(sha1_context *hd)
|
||||
void
|
||||
sha1_hash_buffer(byte *outbuf, const byte *buffer, uint length)
|
||||
{
|
||||
sha1_context hd;
|
||||
sha1_context ctx;
|
||||
|
||||
sha1_init(&hd);
|
||||
sha1_update(&hd, buffer, length);
|
||||
memcpy(outbuf, sha1_final(&hd), SHA1_SIZE);
|
||||
sha1_init(&ctx);
|
||||
sha1_update(&ctx, buffer, length);
|
||||
memcpy(outbuf, sha1_final(&ctx), SHA1_SIZE);
|
||||
}
|
||||
|
||||
void
|
||||
sha1_hmac_init(sha1_hmac_context *hd, const byte *key, uint keylen)
|
||||
sha1_hmac_init(sha1_hmac_context *ctx, const byte *key, uint keylen)
|
||||
{
|
||||
byte keybuf[SHA1_BLOCK_SIZE], buf[SHA1_BLOCK_SIZE];
|
||||
|
||||
@ -299,34 +299,34 @@ sha1_hmac_init(sha1_hmac_context *hd, const byte *key, uint keylen)
|
||||
}
|
||||
|
||||
// Initialize the inner digest
|
||||
sha1_init(&hd->ictx);
|
||||
sha1_init(&ctx->ictx);
|
||||
int i;
|
||||
for (i = 0; i < SHA1_BLOCK_SIZE; i++)
|
||||
buf[i] = keybuf[i] ^ 0x36;
|
||||
sha1_update(&hd->ictx, buf, SHA1_BLOCK_SIZE);
|
||||
sha1_update(&ctx->ictx, buf, SHA1_BLOCK_SIZE);
|
||||
|
||||
// Initialize the outer digest
|
||||
sha1_init(&hd->octx);
|
||||
sha1_init(&ctx->octx);
|
||||
for (i = 0; i < SHA1_BLOCK_SIZE; i++)
|
||||
buf[i] = keybuf[i] ^ 0x5c;
|
||||
sha1_update(&hd->octx, buf, SHA1_BLOCK_SIZE);
|
||||
sha1_update(&ctx->octx, buf, SHA1_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
void
|
||||
sha1_hmac_update(sha1_hmac_context *hd, const byte *data, uint datalen)
|
||||
sha1_hmac_update(sha1_hmac_context *ctx, const byte *data, uint datalen)
|
||||
{
|
||||
// Just update the inner digest
|
||||
sha1_update(&hd->ictx, data, datalen);
|
||||
sha1_update(&ctx->ictx, data, datalen);
|
||||
}
|
||||
|
||||
byte *sha1_hmac_final(sha1_hmac_context *hd)
|
||||
byte *sha1_hmac_final(sha1_hmac_context *ctx)
|
||||
{
|
||||
// Finish the inner digest
|
||||
byte *isha = sha1_final(&hd->ictx);
|
||||
byte *isha = sha1_final(&ctx->ictx);
|
||||
|
||||
// Finish the outer digest
|
||||
sha1_update(&hd->octx, isha, SHA1_SIZE);
|
||||
return sha1_final(&hd->octx);
|
||||
sha1_update(&ctx->octx, isha, SHA1_SIZE);
|
||||
return sha1_final(&ctx->octx);
|
||||
}
|
||||
|
||||
void
|
||||
|
16
lib/sha256.c
16
lib/sha256.c
@ -393,14 +393,14 @@ void sha256_hmac_update(sha256_hmac_context *ctx, const byte *buf, size_t buflen
|
||||
sha256_update(&ctx->ictx, buf, buflen);
|
||||
}
|
||||
|
||||
byte *sha256_hmac_final(sha256_hmac_context *hd)
|
||||
byte *sha256_hmac_final(sha256_hmac_context *ctx)
|
||||
{
|
||||
// Finish the inner digest
|
||||
byte *isha = sha256_final(&hd->ictx);
|
||||
byte *isha = sha256_final(&ctx->ictx);
|
||||
|
||||
// Finish the outer digest
|
||||
sha256_update(&hd->octx, isha, SHA256_SIZE);
|
||||
return sha256_final(&hd->octx);
|
||||
sha256_update(&ctx->octx, isha, SHA256_SIZE);
|
||||
return sha256_final(&ctx->octx);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -454,12 +454,12 @@ void sha224_hmac_update(sha224_hmac_context *ctx, const byte *buf, size_t buflen
|
||||
sha256_update(&ctx->ictx, buf, buflen);
|
||||
}
|
||||
|
||||
byte *sha224_hmac_final(sha224_hmac_context *hd)
|
||||
byte *sha224_hmac_final(sha224_hmac_context *ctx)
|
||||
{
|
||||
// Finish the inner digest
|
||||
byte *isha = sha224_final(&hd->ictx);
|
||||
byte *isha = sha224_final(&ctx->ictx);
|
||||
|
||||
// Finish the outer digest
|
||||
sha224_update(&hd->octx, isha, SHA224_SIZE);
|
||||
return sha224_final(&hd->octx);
|
||||
sha224_update(&ctx->octx, isha, SHA224_SIZE);
|
||||
return sha224_final(&ctx->octx);
|
||||
}
|
||||
|
16
lib/sha512.c
16
lib/sha512.c
@ -543,14 +543,14 @@ void sha512_hmac_update(sha512_hmac_context *ctx, const byte *buf, size_t buflen
|
||||
sha512_update(&ctx->ictx, buf, buflen);
|
||||
}
|
||||
|
||||
byte *sha512_hmac_final(sha512_hmac_context *hd)
|
||||
byte *sha512_hmac_final(sha512_hmac_context *ctx)
|
||||
{
|
||||
// Finish the inner digest
|
||||
byte *isha = sha512_final(&hd->ictx);
|
||||
byte *isha = sha512_final(&ctx->ictx);
|
||||
|
||||
// Finish the outer digest
|
||||
sha512_update(&hd->octx, isha, SHA512_SIZE);
|
||||
return sha512_final(&hd->octx);
|
||||
sha512_update(&ctx->octx, isha, SHA512_SIZE);
|
||||
return sha512_final(&ctx->octx);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -604,12 +604,12 @@ void sha384_hmac_update(sha384_hmac_context *ctx, const byte *buf, size_t buflen
|
||||
sha384_update(&ctx->ictx, buf, buflen);
|
||||
}
|
||||
|
||||
byte *sha384_hmac_final(sha384_hmac_context *hd)
|
||||
byte *sha384_hmac_final(sha384_hmac_context *ctx)
|
||||
{
|
||||
// Finish the inner digest
|
||||
byte *isha = sha384_final(&hd->ictx);
|
||||
byte *isha = sha384_final(&ctx->ictx);
|
||||
|
||||
// Finish the outer digest
|
||||
sha384_update(&hd->octx, isha, SHA384_SIZE);
|
||||
return sha384_final(&hd->octx);
|
||||
sha384_update(&ctx->octx, isha, SHA384_SIZE);
|
||||
return sha384_final(&ctx->octx);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user