dovecot-2.2: hmac: Fixed crashes on CPUs that don't allow unalig...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Sep 8 19:20:50 EEST 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/92a54bb2ee00
changeset: 16718:92a54bb2ee00
user: Timo Sirainen <tss at iki.fi>
date: Sun Sep 08 19:20:39 2013 +0300
description:
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
diffstat:
src/lib/hmac-cram-md5.c | 6 ++++--
src/lib/hmac.c | 7 +++++--
src/lib/hmac.h | 13 +++++++++++--
3 files changed, 20 insertions(+), 6 deletions(-)
diffs (89 lines):
diff -r 66b5839375f0 -r 92a54bb2ee00 src/lib/hmac-cram-md5.c
--- a/src/lib/hmac-cram-md5.c Fri Sep 06 18:30:54 2013 +0300
+++ b/src/lib/hmac-cram-md5.c Sun Sep 08 19:20:39 2013 +0300
@@ -9,9 +9,10 @@
#include "md5.h"
#include "hmac-cram-md5.h"
-void hmac_md5_get_cram_context(struct hmac_context *hmac_ctx,
+void hmac_md5_get_cram_context(struct hmac_context *_hmac_ctx,
unsigned char context_digest[CRAM_MD5_CONTEXTLEN])
{
+ struct hmac_context_priv *hmac_ctx = &_hmac_ctx->u.priv;
unsigned char *cdp;
struct md5_context *ctx = (void*)hmac_ctx->ctx;
@@ -34,9 +35,10 @@
CDPUT(cdp, ctx->d);
}
-void hmac_md5_set_cram_context(struct hmac_context *hmac_ctx,
+void hmac_md5_set_cram_context(struct hmac_context *_hmac_ctx,
const unsigned char context_digest[CRAM_MD5_CONTEXTLEN])
{
+ struct hmac_context_priv *hmac_ctx = &_hmac_ctx->u.priv;
const unsigned char *cdp;
struct md5_context *ctx = (void*)hmac_ctx->ctx;
diff -r 66b5839375f0 -r 92a54bb2ee00 src/lib/hmac.c
--- a/src/lib/hmac.c Fri Sep 06 18:30:54 2013 +0300
+++ b/src/lib/hmac.c Sun Sep 08 19:20:39 2013 +0300
@@ -11,9 +11,10 @@
#include "hmac.h"
#include "safe-memset.h"
-void hmac_init(struct hmac_context *ctx, const unsigned char *key,
+void hmac_init(struct hmac_context *_ctx, const unsigned char *key,
size_t key_len, const struct hash_method *meth)
{
+ struct hmac_context_priv *ctx = &_ctx->u.priv;
int i;
unsigned char k_ipad[64];
unsigned char k_opad[64];
@@ -49,8 +50,10 @@
safe_memset(k_opad, 0, 64);
}
-void hmac_final(struct hmac_context *ctx, unsigned char *digest)
+void hmac_final(struct hmac_context *_ctx, unsigned char *digest)
{
+ struct hmac_context_priv *ctx = &_ctx->u.priv;
+
ctx->hash->result(ctx->ctx, digest);
ctx->hash->loop(ctx->ctxo, digest, ctx->hash->digest_size);
diff -r 66b5839375f0 -r 92a54bb2ee00 src/lib/hmac.h
--- a/src/lib/hmac.h Fri Sep 06 18:30:54 2013 +0300
+++ b/src/lib/hmac.h Sun Sep 08 19:20:39 2013 +0300
@@ -6,20 +6,29 @@
#define HMAC_MAX_CONTEXT_SIZE 256
-struct hmac_context {
+struct hmac_context_priv {
char ctx[HMAC_MAX_CONTEXT_SIZE];
char ctxo[HMAC_MAX_CONTEXT_SIZE];
const struct hash_method *hash;
};
+struct hmac_context {
+ union {
+ struct hmac_context_priv priv;
+ uint64_t padding_requirement;
+ } u;
+};
+
void hmac_init(struct hmac_context *ctx, const unsigned char *key,
size_t key_len, const struct hash_method *meth);
void hmac_final(struct hmac_context *ctx, unsigned char *digest);
static inline void
-hmac_update(struct hmac_context *ctx, const void *data, size_t size)
+hmac_update(struct hmac_context *_ctx, const void *data, size_t size)
{
+ struct hmac_context_priv *ctx = &_ctx->u.priv;
+
ctx->hash->loop(ctx->ctx, data, size);
}
More information about the dovecot-cvs
mailing list