0
0
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:
Pavel Tvrdík 2015-05-12 12:24:28 +02:00
parent f84f925036
commit 5beaaa3d6b
3 changed files with 31 additions and 31 deletions

View File

@ -274,15 +274,15 @@ sha1_final(sha1_context *hd)
void void
sha1_hash_buffer(byte *outbuf, const byte *buffer, uint length) sha1_hash_buffer(byte *outbuf, const byte *buffer, uint length)
{ {
sha1_context hd; sha1_context ctx;
sha1_init(&hd); sha1_init(&ctx);
sha1_update(&hd, buffer, length); sha1_update(&ctx, buffer, length);
memcpy(outbuf, sha1_final(&hd), SHA1_SIZE); memcpy(outbuf, sha1_final(&ctx), SHA1_SIZE);
} }
void 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]; 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 // Initialize the inner digest
sha1_init(&hd->ictx); sha1_init(&ctx->ictx);
int i; int i;
for (i = 0; i < SHA1_BLOCK_SIZE; i++) for (i = 0; i < SHA1_BLOCK_SIZE; i++)
buf[i] = keybuf[i] ^ 0x36; 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 // Initialize the outer digest
sha1_init(&hd->octx); sha1_init(&ctx->octx);
for (i = 0; i < SHA1_BLOCK_SIZE; i++) for (i = 0; i < SHA1_BLOCK_SIZE; i++)
buf[i] = keybuf[i] ^ 0x5c; buf[i] = keybuf[i] ^ 0x5c;
sha1_update(&hd->octx, buf, SHA1_BLOCK_SIZE); sha1_update(&ctx->octx, buf, SHA1_BLOCK_SIZE);
} }
void 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 // 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 // Finish the inner digest
byte *isha = sha1_final(&hd->ictx); byte *isha = sha1_final(&ctx->ictx);
// Finish the outer digest // Finish the outer digest
sha1_update(&hd->octx, isha, SHA1_SIZE); sha1_update(&ctx->octx, isha, SHA1_SIZE);
return sha1_final(&hd->octx); return sha1_final(&ctx->octx);
} }
void void

View File

@ -393,14 +393,14 @@ void sha256_hmac_update(sha256_hmac_context *ctx, const byte *buf, size_t buflen
sha256_update(&ctx->ictx, buf, 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 // Finish the inner digest
byte *isha = sha256_final(&hd->ictx); byte *isha = sha256_final(&ctx->ictx);
// Finish the outer digest // Finish the outer digest
sha256_update(&hd->octx, isha, SHA256_SIZE); sha256_update(&ctx->octx, isha, SHA256_SIZE);
return sha256_final(&hd->octx); 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); 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 // Finish the inner digest
byte *isha = sha224_final(&hd->ictx); byte *isha = sha224_final(&ctx->ictx);
// Finish the outer digest // Finish the outer digest
sha224_update(&hd->octx, isha, SHA224_SIZE); sha224_update(&ctx->octx, isha, SHA224_SIZE);
return sha224_final(&hd->octx); return sha224_final(&ctx->octx);
} }

View File

@ -543,14 +543,14 @@ void sha512_hmac_update(sha512_hmac_context *ctx, const byte *buf, size_t buflen
sha512_update(&ctx->ictx, buf, 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 // Finish the inner digest
byte *isha = sha512_final(&hd->ictx); byte *isha = sha512_final(&ctx->ictx);
// Finish the outer digest // Finish the outer digest
sha512_update(&hd->octx, isha, SHA512_SIZE); sha512_update(&ctx->octx, isha, SHA512_SIZE);
return sha512_final(&hd->octx); 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); 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 // Finish the inner digest
byte *isha = sha384_final(&hd->ictx); byte *isha = sha384_final(&ctx->ictx);
// Finish the outer digest // Finish the outer digest
sha384_update(&hd->octx, isha, SHA384_SIZE); sha384_update(&ctx->octx, isha, SHA384_SIZE);
return sha384_final(&hd->octx); return sha384_final(&ctx->octx);
} }