summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/Libgcrypt/cipher/hash-common.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MirOTR/Libgcrypt/cipher/hash-common.c')
-rw-r--r--plugins/MirOTR/Libgcrypt/cipher/hash-common.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/plugins/MirOTR/Libgcrypt/cipher/hash-common.c b/plugins/MirOTR/Libgcrypt/cipher/hash-common.c
index 656e180e2d..ffbc39ed2b 100644
--- a/plugins/MirOTR/Libgcrypt/cipher/hash-common.c
+++ b/plugins/MirOTR/Libgcrypt/cipher/hash-common.c
@@ -21,7 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef HAVE_STDINT_H
+#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
@@ -35,10 +35,10 @@
describing the error.
DATAMODE controls what will be hashed according to this table:
-
+
0 - Hash the supplied DATA of DATALEN.
1 - Hash one million times a 'a'. DATA and DATALEN are ignored.
-
+
*/
const char *
_gcry_hash_selftest_check_one (int algo,
@@ -49,14 +49,14 @@ _gcry_hash_selftest_check_one (int algo,
gcry_error_t err = 0;
gcry_md_hd_t hd;
unsigned char *digest;
-
+
if (_gcry_md_get_algo_dlen (algo) != expectlen)
return "digest size does not match expected size";
-
+
err = _gcry_md_open (&hd, algo, 0);
if (err)
return "gcry_md_open failed";
-
+
switch (datamode)
{
case 0:
@@ -64,7 +64,7 @@ _gcry_hash_selftest_check_one (int algo,
break;
case 1: /* Hash one million times an "a". */
- {
+ {
char aaa[1000];
int i;
@@ -82,7 +82,7 @@ _gcry_hash_selftest_check_one (int algo,
if (!result)
{
digest = _gcry_md_read (hd, algo);
-
+
if ( memcmp (digest, expect, expectlen) )
result = "digest mismatch";
}
@@ -92,3 +92,54 @@ _gcry_hash_selftest_check_one (int algo,
return result;
}
+
+/* Common function to write a chunk of data to the transform function
+ of a hash algorithm. Note that the use of the term "block" does
+ not imply a fixed size block. */
+void
+_gcry_md_block_write (void *context, const void *inbuf_arg, size_t inlen)
+{
+ const unsigned char *inbuf = inbuf_arg;
+ gcry_md_block_ctx_t *hd = context;
+ unsigned int stack_burn = 0;
+
+ if (sizeof(hd->buf) < hd->blocksize)
+ BUG();
+
+ if (hd->buf == NULL || hd->bwrite == NULL)
+ return;
+
+ if (hd->count == hd->blocksize) /* Flush the buffer. */
+ {
+ stack_burn = hd->bwrite (hd, hd->buf);
+ _gcry_burn_stack (stack_burn);
+ stack_burn = 0;
+ hd->count = 0;
+ if (!++hd->nblocks)
+ hd->nblocks_high++;
+ }
+ if (!inbuf)
+ return;
+
+ if (hd->count)
+ {
+ for (; inlen && hd->count < hd->blocksize; inlen--)
+ hd->buf[hd->count++] = *inbuf++;
+ _gcry_md_block_write (hd, NULL, 0);
+ if (!inlen)
+ return;
+ }
+
+ while (inlen >= hd->blocksize)
+ {
+ stack_burn = hd->bwrite (hd, inbuf);
+ hd->count = 0;
+ if (!++hd->nblocks)
+ hd->nblocks_high++;
+ inlen -= hd->blocksize;
+ inbuf += hd->blocksize;
+ }
+ _gcry_burn_stack (stack_burn);
+ for (; inlen && hd->count < hd->blocksize; inlen--)
+ hd->buf[hd->count++] = *inbuf++;
+}