mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-22 15:22:39 +00:00
libgcrypt: Import libgcrypt 1.11
We currently use an old version of libgcrypt which results in us having fewer ciphers and missing on many other improvements. Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
1 parent
a0d4c94ef6
commit
3312af6e07
468 files changed
+210508
-33178
No files matched your search
@@ -26,6 +26,7 @@
|
||||
#endif
|
||||
|
||||
#include "g10lib.h"
|
||||
#include "bufhelp.h"
|
||||
#include "hash-common.h"
|
||||
|
||||
|
||||
@@ -49,9 +50,11 @@ _gcry_hash_selftest_check_one (int algo,
|
||||
gcry_error_t err = 0;
|
||||
gcry_md_hd_t hd;
|
||||
unsigned char *digest;
|
||||
char aaa[1000];
|
||||
int expect_xof = 0;
|
||||
|
||||
if (_gcry_md_get_algo_dlen (algo) != expectlen)
|
||||
return "digest size does not match expected size";
|
||||
expect_xof = 1;
|
||||
|
||||
err = _gcry_md_open (&hd, algo, 0);
|
||||
if (err)
|
||||
@@ -65,7 +68,6 @@ _gcry_hash_selftest_check_one (int algo,
|
||||
|
||||
case 1: /* Hash one million times an "a". */
|
||||
{
|
||||
char aaa[1000];
|
||||
int i;
|
||||
|
||||
/* Write in odd size chunks so that we test the buffering. */
|
||||
@@ -81,13 +83,109 @@ _gcry_hash_selftest_check_one (int algo,
|
||||
|
||||
if (!result)
|
||||
{
|
||||
digest = _gcry_md_read (hd, algo);
|
||||
if (!expect_xof)
|
||||
{
|
||||
digest = _gcry_md_read (hd, algo);
|
||||
|
||||
if ( memcmp (digest, expect, expectlen) )
|
||||
result = "digest mismatch";
|
||||
if ( memcmp (digest, expect, expectlen) )
|
||||
result = "digest mismatch";
|
||||
}
|
||||
else
|
||||
{
|
||||
gcry_assert(expectlen <= sizeof(aaa));
|
||||
|
||||
err = _gcry_md_extract (hd, algo, aaa, expectlen);
|
||||
if (err)
|
||||
result = "error extracting output from XOF";
|
||||
else if ( memcmp (aaa, expect, expectlen) )
|
||||
result = "digest mismatch";
|
||||
}
|
||||
}
|
||||
|
||||
_gcry_md_close (hd);
|
||||
|
||||
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. Note that we explicitly allow to use
|
||||
this function after the context has been finalized; the result does
|
||||
not have any meaning but writing after finalize is sometimes
|
||||
helpful to mitigate timing attacks. */
|
||||
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;
|
||||
unsigned int nburn;
|
||||
const unsigned int blocksize_shift = hd->blocksize_shift;
|
||||
const unsigned int blocksize = 1 << blocksize_shift;
|
||||
size_t inblocks;
|
||||
size_t copylen;
|
||||
|
||||
if (sizeof(hd->buf) < blocksize)
|
||||
BUG();
|
||||
|
||||
if (!hd->bwrite)
|
||||
return;
|
||||
|
||||
if (hd->count > blocksize)
|
||||
{
|
||||
/* This happens only when gcry_md_write is called after final.
|
||||
* Writing after final is used for mitigating timing attacks. */
|
||||
hd->count = 0;
|
||||
}
|
||||
|
||||
while (hd->count)
|
||||
{
|
||||
if (hd->count == blocksize) /* Flush the buffer. */
|
||||
{
|
||||
nburn = hd->bwrite (hd, hd->buf, 1);
|
||||
stack_burn = nburn > stack_burn ? nburn : stack_burn;
|
||||
hd->count = 0;
|
||||
if (!++hd->nblocks)
|
||||
hd->nblocks_high++;
|
||||
}
|
||||
else
|
||||
{
|
||||
copylen = inlen;
|
||||
if (copylen > blocksize - hd->count)
|
||||
copylen = blocksize - hd->count;
|
||||
|
||||
if (copylen == 0)
|
||||
break;
|
||||
|
||||
buf_cpy (&hd->buf[hd->count], inbuf, copylen);
|
||||
hd->count += copylen;
|
||||
inbuf += copylen;
|
||||
inlen -= copylen;
|
||||
}
|
||||
}
|
||||
|
||||
if (inlen == 0)
|
||||
return;
|
||||
|
||||
if (inlen >= blocksize)
|
||||
{
|
||||
inblocks = inlen >> blocksize_shift;
|
||||
nburn = hd->bwrite (hd, inbuf, inblocks);
|
||||
stack_burn = nburn > stack_burn ? nburn : stack_burn;
|
||||
hd->count = 0;
|
||||
hd->nblocks_high += (hd->nblocks + inblocks < inblocks);
|
||||
hd->nblocks += inblocks;
|
||||
inlen -= inblocks << blocksize_shift;
|
||||
inbuf += inblocks << blocksize_shift;
|
||||
}
|
||||
|
||||
if (inlen)
|
||||
{
|
||||
buf_cpy (hd->buf, inbuf, inlen);
|
||||
hd->count = inlen;
|
||||
}
|
||||
|
||||
if (stack_burn > 0)
|
||||
_gcry_burn_stack (stack_burn);
|
||||
}
|
||||
Reference in new issue
Block a user