convert HMAC functions to static where possible
This commit is contained in:
parent
3ff39dfab4
commit
6741cfc22b
44
lib/hmac.c
44
lib/hmac.c
@ -31,21 +31,16 @@
|
|||||||
|
|
||||||
#include "hmac.h"
|
#include "hmac.h"
|
||||||
|
|
||||||
void hmac_sha256(const char *msg, const unsigned int msg_len,
|
typedef struct {
|
||||||
unsigned char *hmac, const char *hmac_key)
|
SHA256_CTX ctx_inside;
|
||||||
{
|
SHA256_CTX ctx_outside;
|
||||||
hmac_sha256_ctx ctx;
|
|
||||||
|
|
||||||
memset(&ctx, 0, sizeof(&ctx));
|
unsigned char block_inner_pad[SHA256_BLOCK_LEN];
|
||||||
|
unsigned char block_outer_pad[SHA256_BLOCK_LEN];
|
||||||
|
} hmac_sha256_ctx;
|
||||||
|
|
||||||
hmac_sha256_init(&ctx, hmac_key);
|
static void
|
||||||
hmac_sha256_update(&ctx, msg, msg_len);
|
hmac_sha256_init(hmac_sha256_ctx *ctx, const char *key)
|
||||||
hmac_sha256_final(&ctx, hmac);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hmac_sha256_init(hmac_sha256_ctx *ctx, const char *key)
|
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
@ -63,14 +58,16 @@ void hmac_sha256_init(hmac_sha256_ctx *ctx, const char *key)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hmac_sha256_update(hmac_sha256_ctx *ctx, const char *msg,
|
static void
|
||||||
|
hmac_sha256_update(hmac_sha256_ctx *ctx, const char *msg,
|
||||||
unsigned int msg_len)
|
unsigned int msg_len)
|
||||||
{
|
{
|
||||||
SHA256_Update(&ctx->ctx_inside, (unsigned char *)msg, msg_len);
|
SHA256_Update(&ctx->ctx_inside, (unsigned char *)msg, msg_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *hmac)
|
static void
|
||||||
|
hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *hmac)
|
||||||
{
|
{
|
||||||
unsigned char digest_inside[SHA256_DIGEST_LEN];
|
unsigned char digest_inside[SHA256_DIGEST_LEN];
|
||||||
|
|
||||||
@ -80,3 +77,20 @@ void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *hmac)
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
hmac_sha256(const char *msg, const unsigned int msg_len,
|
||||||
|
unsigned char *hmac, const char *hmac_key)
|
||||||
|
{
|
||||||
|
hmac_sha256_ctx ctx;
|
||||||
|
|
||||||
|
memset(&ctx, 0, sizeof(&ctx));
|
||||||
|
|
||||||
|
hmac_sha256_init(&ctx, hmac_key);
|
||||||
|
hmac_sha256_update(&ctx, msg, msg_len);
|
||||||
|
hmac_sha256_final(&ctx, hmac);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
lib/hmac.h
13
lib/hmac.h
@ -33,22 +33,9 @@
|
|||||||
|
|
||||||
#include "digest.h"
|
#include "digest.h"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
SHA256_CTX ctx_inside;
|
|
||||||
SHA256_CTX ctx_outside;
|
|
||||||
|
|
||||||
unsigned char block_inner_pad[SHA256_BLOCK_LEN];
|
|
||||||
unsigned char block_outer_pad[SHA256_BLOCK_LEN];
|
|
||||||
} hmac_sha256_ctx;
|
|
||||||
|
|
||||||
void hmac_sha256(const char *msg, const unsigned int msg_len,
|
void hmac_sha256(const char *msg, const unsigned int msg_len,
|
||||||
unsigned char *hmac, const char *hmac_key);
|
unsigned char *hmac, const char *hmac_key);
|
||||||
|
|
||||||
void hmac_sha256_init(hmac_sha256_ctx *ctx, const char *key);
|
|
||||||
void hmac_sha256_update(hmac_sha256_ctx *ctx, const char *msg,
|
|
||||||
unsigned int msg_len);
|
|
||||||
void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *hmac);
|
|
||||||
|
|
||||||
#endif /* HMAC_H */
|
#endif /* HMAC_H */
|
||||||
|
|
||||||
/***EOF***/
|
/***EOF***/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user