summaryrefslogtreecommitdiff
path: root/cipher/hash-common.h
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-21 13:54:38 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-21 13:54:38 +0300
commitcce7449efe471b076c5a97929ac8907162011394 (patch)
tree094b7a1184a139576f4443f0e1c373064a295aa2 /cipher/hash-common.h
parent3e5cfa20acfeccb9df2c3fae2730344b40b36104 (diff)
downloadlibgcrypt-cce7449efe471b076c5a97929ac8907162011394.tar.gz
Make SHA-512 use the new _gcry_md_block_write helper
* cipher/hash-common.c (_gcry_md_block_write): Check that hd->buf is large enough. * cipher/hash-common.h (MD_BLOCK_MAX_BLOCKSIZE, MD_NBLOCKS_TYPE): New macros. (gcry_md_block_ctx_t): Use above macros for 'nblocks' and 'buf'. * cipher/sha512.c (SHA512_STATE): New struct. (SHA512_CONTEXT): Add 'bctx' and 'state'. (sha512_init, sha384_init): Initialize 'bctx'. (__transform, _gcry_sha512_transform_armv7_neon): Use SHA512_STATE for 'hd'. (transform): For now, do not return burn stack. (sha512_write): Remove. (sha512_final): Use _gcry_md_block_write and bctx. (_gcry_digest_spec_sha512, _gcry_digest_spec_sha384): Use _gcry_md_block_write. -- Patch changes 'nblocks' counter to 64-bits when SHA-512 is enabled. This does not cause problems with other algorithms; they are already casting 'nblocks' to u32 variable in their finalization functions. Also move 'buf' member to head of 'gcry_md_block_ctx_t' to ensure proper alignment; this is because some algorithms cast buffer pointer to (u64*) in final endian conversion. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/hash-common.h')
-rw-r--r--cipher/hash-common.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/cipher/hash-common.h b/cipher/hash-common.h
index 1d1d4ec5..4dd54411 100644
--- a/cipher/hash-common.h
+++ b/cipher/hash-common.h
@@ -20,6 +20,8 @@
#ifndef GCRY_HASH_COMMON_H
#define GCRY_HASH_COMMON_H
+#include "types.h"
+
const char * _gcry_hash_selftest_check_one
/**/ (int algo,
@@ -29,11 +31,20 @@ const char * _gcry_hash_selftest_check_one
/* Type for the md_write helper function. */
typedef void (*_gcry_md_block_write_t) (void *c, const unsigned char *buf);
+#if defined(HAVE_U64_TYPEDEF) && defined(USE_SHA512)
+/* SHA-512 needs u64 and larger buffer. */
+# define MD_BLOCK_MAX_BLOCKSIZE 128
+# define MD_NBLOCKS_TYPE u64
+#else
+# define MD_BLOCK_MAX_BLOCKSIZE 64
+# define MD_NBLOCKS_TYPE u32
+#endif
+
typedef struct gcry_md_block_ctx
{
- u32 nblocks;
- int count;
- byte buf[64];
+ byte buf[MD_BLOCK_MAX_BLOCKSIZE];
+ MD_NBLOCKS_TYPE nblocks;
+ int count;
size_t blocksize;
_gcry_md_block_write_t bwrite;
size_t stack_burn;