[git] GCRYPT - branch, master, updated. libgcrypt-1.6.0-261-ge97c62a
by Werner Koch
cvs at cvs.gnupg.org
Fri Sep 4 12:47:32 CEST 2015
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".
The branch, master has been updated
via e97c62a4a687b56d00a2d0a63e072a977f8eb81c (commit)
via e2785a2268702312529521df3bd2f4e6b43cea3a (commit)
from c17f84bd02d7ee93845e92e20f6ddba814961588 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit e97c62a4a687b56d00a2d0a63e072a977f8eb81c
Author: Werner Koch <wk at gnupg.org>
Date: Fri Sep 4 12:39:56 2015 +0200
w32: Avoid a few compiler warnings.
* cipher/cipher-selftest.c (_gcry_selftest_helper_cbc)
(_gcry_selftest_helper_cfb, _gcry_selftest_helper_ctr): Mark variable
as unused.
* random/rndw32.c (slow_gatherer): Avoid signed pointer mismatch
warning.
* src/secmem.c (init_pool): Avoid unused variable warning.
* tests/random.c (writen, readn): Include on if needed.
Signed-off-by: Werner Koch <wk at gnupg.org>
diff --git a/cipher/cipher-selftest.c b/cipher/cipher-selftest.c
index 470499f..cecbab7 100644
--- a/cipher/cipher-selftest.c
+++ b/cipher/cipher-selftest.c
@@ -131,6 +131,8 @@ _gcry_selftest_helper_cbc (const char *cipher, gcry_cipher_setkey_t setkey_func,
syslog (LOG_USER|LOG_WARNING, "Libgcrypt warning: "
"%s-CBC-%d test failed (plaintext mismatch)", cipher,
blocksize * 8);
+#else
+ (void)cipher; /* Not used. */
#endif
return "selftest for CBC failed - see syslog for details";
}
@@ -251,6 +253,8 @@ _gcry_selftest_helper_cfb (const char *cipher, gcry_cipher_setkey_t setkey_func,
syslog (LOG_USER|LOG_WARNING, "Libgcrypt warning: "
"%s-CFB-%d test failed (plaintext mismatch)", cipher,
blocksize * 8);
+#else
+ (void)cipher; /* Not used. */
#endif
return "selftest for CFB failed - see syslog for details";
}
@@ -379,6 +383,8 @@ _gcry_selftest_helper_ctr (const char *cipher, gcry_cipher_setkey_t setkey_func,
syslog (LOG_USER|LOG_WARNING, "Libgcrypt warning: "
"%s-CTR-%d test failed (plaintext mismatch)", cipher,
blocksize * 8);
+#else
+ (void)cipher; /* Not used. */
#endif
return "selftest for CTR failed - see syslog for details";
}
diff --git a/random/rndw32.c b/random/rndw32.c
index 4ab1bca..1325b18 100644
--- a/random/rndw32.c
+++ b/random/rndw32.c
@@ -513,7 +513,7 @@ slow_gatherer ( void (*add)(const void*, size_t, enum random_origins),
status = RegQueryValueEx (hKey, "ProductType", 0, NULL,
szValue, &dwSize);
- if (status == ERROR_SUCCESS && stricmp (szValue, "WinNT"))
+ if (status == ERROR_SUCCESS && stricmp ((char*)szValue, "WinNT"))
{
/* Note: There are (at least) three cases for ProductType:
WinNT = NT Workstation, ServerNT = NT Server, LanmanNT =
diff --git a/src/secmem.c b/src/secmem.c
index d75c14c..2109bc2 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -363,8 +363,6 @@ lock_pool (void *p, size_t n)
static void
init_pool (size_t n)
{
- size_t pgsize;
- long int pgsize_val;
memblock_t *mb;
pool_size = n;
@@ -372,48 +370,54 @@ init_pool (size_t n)
if (disable_secmem)
log_bug ("secure memory is disabled");
-#if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
- pgsize_val = sysconf (_SC_PAGESIZE);
-#elif defined(HAVE_GETPAGESIZE)
- pgsize_val = getpagesize ();
-#else
- pgsize_val = -1;
-#endif
- pgsize = (pgsize_val != -1 && pgsize_val > 0)? pgsize_val:DEFAULT_PAGE_SIZE;
-
#if HAVE_MMAP
- pool_size = (pool_size + pgsize - 1) & ~(pgsize - 1);
-#ifdef MAP_ANONYMOUS
- pool = mmap (0, pool_size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-#else /* map /dev/zero instead */
{
- int fd;
+ size_t pgsize;
+ long int pgsize_val;
+
+# if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
+ pgsize_val = sysconf (_SC_PAGESIZE);
+# elif defined(HAVE_GETPAGESIZE)
+ pgsize_val = getpagesize ();
+# else
+ pgsize_val = -1;
+# endif
+ pgsize = (pgsize_val != -1 && pgsize_val > 0)? pgsize_val:DEFAULT_PAGE_SIZE;
+
+ pool_size = (pool_size + pgsize - 1) & ~(pgsize - 1);
+# ifdef MAP_ANONYMOUS
+ pool = mmap (0, pool_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+# else /* map /dev/zero instead */
+ {
+ int fd;
- fd = open ("/dev/zero", O_RDWR);
- if (fd == -1)
- {
- log_error ("can't open /dev/zero: %s\n", strerror (errno));
- pool = (void *) -1;
- }
+ fd = open ("/dev/zero", O_RDWR);
+ if (fd == -1)
+ {
+ log_error ("can't open /dev/zero: %s\n", strerror (errno));
+ pool = (void *) -1;
+ }
+ else
+ {
+ pool = mmap (0, pool_size,
+ (PROT_READ | PROT_WRITE), MAP_PRIVATE, fd, 0);
+ close (fd);
+ }
+ }
+# endif
+ if (pool == (void *) -1)
+ log_info ("can't mmap pool of %u bytes: %s - using malloc\n",
+ (unsigned) pool_size, strerror (errno));
else
{
- pool = mmap (0, pool_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
- close (fd);
+ pool_is_mmapped = 1;
+ pool_okay = 1;
}
}
-#endif
- if (pool == (void *) -1)
- log_info ("can't mmap pool of %u bytes: %s - using malloc\n",
- (unsigned) pool_size, strerror (errno));
- else
- {
- pool_is_mmapped = 1;
- pool_okay = 1;
- }
+#endif /*HAVE_MMAP*/
-#endif
if (!pool_okay)
{
pool = malloc (pool_size);
diff --git a/tests/fipsdrv.c b/tests/fipsdrv.c
index eef2ddd..b3da2a3 100644
--- a/tests/fipsdrv.c
+++ b/tests/fipsdrv.c
@@ -2358,14 +2358,14 @@ main (int argc, char **argv)
{
if (!(++count % 1000))
fprintf (stderr, PGM ": %lu random bytes so far\n",
- (unsigned long int)count * sizeof buffer);
+ (unsigned long int)(count * sizeof buffer));
}
}
while (loop_mode);
if (progress)
fprintf (stderr, PGM ": %lu random bytes\n",
- (unsigned long int)count * sizeof buffer);
+ (unsigned long int)(count * sizeof buffer));
deinit_external_rng_test (context);
}
diff --git a/tests/gchash.c b/tests/gchash.c
index 7a2aad6..7ff99e0 100644
--- a/tests/gchash.c
+++ b/tests/gchash.c
@@ -109,7 +109,7 @@ main (int argc, char **argv)
h = gcry_md_read(hd, 0);
for (i = 0; i < gcry_md_get_algo_dlen (algo); i++)
- printf("%02hhx", h[i]);
+ printf("%02x", h[i]);
printf(" %s\n", *argv);
gcry_md_reset(hd);
diff --git a/tests/random.c b/tests/random.c
index 10bf646..d7a624a 100644
--- a/tests/random.c
+++ b/tests/random.c
@@ -87,7 +87,7 @@ progress_cb (void *cb_data, const char *what, int printchar,
}
-
+#ifndef HAVE_W32_SYSTEM
static int
writen (int fd, const void *buf, size_t nbytes)
{
@@ -110,7 +110,10 @@ writen (int fd, const void *buf, size_t nbytes)
return 0;
}
+#endif /*!HAVE_W32_SYSTEM*/
+
+#ifndef HAVE_W32_SYSTEM
static int
readn (int fd, void *buf, size_t buflen, size_t *ret_nread)
{
@@ -136,7 +139,7 @@ readn (int fd, void *buf, size_t buflen, size_t *ret_nread)
*ret_nread = buflen - nleft;
return 0;
}
-
+#endif /*!HAVE_W32_SYSTEM*/
/* Check that forking won't return the same random. */
commit e2785a2268702312529521df3bd2f4e6b43cea3a
Author: Werner Koch <wk at gnupg.org>
Date: Fri Sep 4 12:32:16 2015 +0200
w32: Fix alignment problem with AESNI on Windows >= 8
* cipher/cipher-selftest.c (_gcry_cipher_selftest_alloc_ctx): New.
* cipher/rijndael.c (selftest_basic_128, selftest_basic_192)
(selftest_basic_256): Allocate context on the heap.
--
The stack alignment on Windows changed and because ld seems to limit
stack variables to a 8 byte alignment (we request 16), we get bus
errors from the selftests if AESNI is in use.
GnuPG-bug-id: 2085
Signed-off-by: Werner Koch <wk at gnupg.org>
diff --git a/cipher/cipher-selftest.c b/cipher/cipher-selftest.c
index 852368a..470499f 100644
--- a/cipher/cipher-selftest.c
+++ b/cipher/cipher-selftest.c
@@ -44,6 +44,29 @@
#endif
+/* Return an allocated buffers of size CONTEXT_SIZE with an alignment
+ of 16. The caller must free that buffer using the address returned
+ at R_MEM. Returns NULL and sets ERRNO on failure. */
+void *
+_gcry_cipher_selftest_alloc_ctx (const int context_size, unsigned char **r_mem)
+{
+ int offs;
+ unsigned int ctx_aligned_size, memsize;
+
+ ctx_aligned_size = context_size + 15;
+ ctx_aligned_size -= ctx_aligned_size & 0xf;
+
+ memsize = ctx_aligned_size + 16;
+
+ *r_mem = xtrycalloc (1, memsize);
+ if (!*r_mem)
+ return NULL;
+
+ offs = (16 - ((uintptr_t)*r_mem & 15)) & 15;
+ return (void*)(*r_mem + offs);
+}
+
+
/* Run the self-tests for <block cipher>-CBC-<block size>, tests bulk CBC
decryption. Returns NULL on success. */
const char *
diff --git a/cipher/cipher-selftest.h b/cipher/cipher-selftest.h
index a70667a..a435080 100644
--- a/cipher/cipher-selftest.h
+++ b/cipher/cipher-selftest.h
@@ -40,6 +40,11 @@ typedef void (*gcry_cipher_bulk_ctr_enc_t)(void *context, unsigned char *iv,
const void *inbuf_arg,
size_t nblocks);
+/* Helper function to allocate an aligned context for selftests. */
+void *_gcry_cipher_selftest_alloc_ctx (const int context_size,
+ unsigned char **r_mem);
+
+
/* Helper function for bulk CBC decryption selftest */
const char *
_gcry_selftest_helper_cbc (const char *cipher, gcry_cipher_setkey_t setkey,
diff --git a/cipher/rijndael.c b/cipher/rijndael.c
index eff59c2..0130924 100644
--- a/cipher/rijndael.c
+++ b/cipher/rijndael.c
@@ -1358,7 +1358,8 @@ _gcry_aes_ocb_auth (gcry_cipher_hd_t c, const void *abuf_arg, size_t nblocks)
static const char*
selftest_basic_128 (void)
{
- RIJNDAEL_context ctx;
+ RIJNDAEL_context *ctx;
+ unsigned char *ctxmem;
unsigned char scratch[16];
/* The test vectors are from the AES supplied ones; more or less
@@ -1401,11 +1402,21 @@ selftest_basic_128 (void)
};
#endif
- rijndael_setkey (&ctx, key_128, sizeof (key_128));
- rijndael_encrypt (&ctx, scratch, plaintext_128);
+ /* Because gcc/ld can only align the CTX struct on 8 bytes on the
+ stack, we need to allocate that context on the heap. */
+ ctx = _gcry_cipher_selftest_alloc_ctx (sizeof *ctx, &ctxmem);
+ if (!ctx)
+ return "failed to allocate memory";
+
+ rijndael_setkey (ctx, key_128, sizeof (key_128));
+ rijndael_encrypt (ctx, scratch, plaintext_128);
if (memcmp (scratch, ciphertext_128, sizeof (ciphertext_128)))
- return "AES-128 test encryption failed.";
- rijndael_decrypt (&ctx, scratch, scratch);
+ {
+ xfree (ctxmem);
+ return "AES-128 test encryption failed.";
+ }
+ rijndael_decrypt (ctx, scratch, scratch);
+ xfree (ctxmem);
if (memcmp (scratch, plaintext_128, sizeof (plaintext_128)))
return "AES-128 test decryption failed.";
@@ -1416,7 +1427,8 @@ selftest_basic_128 (void)
static const char*
selftest_basic_192 (void)
{
- RIJNDAEL_context ctx;
+ RIJNDAEL_context *ctx;
+ unsigned char *ctxmem;
unsigned char scratch[16];
static unsigned char plaintext_192[16] =
@@ -1436,11 +1448,18 @@ selftest_basic_192 (void)
0x12,0x13,0x1A,0xC7,0xC5,0x47,0x88,0xAA
};
- rijndael_setkey (&ctx, key_192, sizeof(key_192));
- rijndael_encrypt (&ctx, scratch, plaintext_192);
+ ctx = _gcry_cipher_selftest_alloc_ctx (sizeof *ctx, &ctxmem);
+ if (!ctx)
+ return "failed to allocate memory";
+ rijndael_setkey (ctx, key_192, sizeof(key_192));
+ rijndael_encrypt (ctx, scratch, plaintext_192);
if (memcmp (scratch, ciphertext_192, sizeof (ciphertext_192)))
- return "AES-192 test encryption failed.";
- rijndael_decrypt (&ctx, scratch, scratch);
+ {
+ xfree (ctxmem);
+ return "AES-192 test encryption failed.";
+ }
+ rijndael_decrypt (ctx, scratch, scratch);
+ xfree (ctxmem);
if (memcmp (scratch, plaintext_192, sizeof (plaintext_192)))
return "AES-192 test decryption failed.";
@@ -1452,7 +1471,8 @@ selftest_basic_192 (void)
static const char*
selftest_basic_256 (void)
{
- RIJNDAEL_context ctx;
+ RIJNDAEL_context *ctx;
+ unsigned char *ctxmem;
unsigned char scratch[16];
static unsigned char plaintext_256[16] =
@@ -1473,11 +1493,18 @@ selftest_basic_256 (void)
0x9A,0xCF,0x72,0x80,0x86,0x04,0x0A,0xE3
};
- rijndael_setkey (&ctx, key_256, sizeof(key_256));
- rijndael_encrypt (&ctx, scratch, plaintext_256);
+ ctx = _gcry_cipher_selftest_alloc_ctx (sizeof *ctx, &ctxmem);
+ if (!ctx)
+ return "failed to allocate memory";
+ rijndael_setkey (ctx, key_256, sizeof(key_256));
+ rijndael_encrypt (ctx, scratch, plaintext_256);
if (memcmp (scratch, ciphertext_256, sizeof (ciphertext_256)))
- return "AES-256 test encryption failed.";
- rijndael_decrypt (&ctx, scratch, scratch);
+ {
+ xfree (ctxmem);
+ return "AES-256 test encryption failed.";
+ }
+ rijndael_decrypt (ctx, scratch, scratch);
+ xfree (ctxmem);
if (memcmp (scratch, plaintext_256, sizeof (plaintext_256)))
return "AES-256 test decryption failed.";
-----------------------------------------------------------------------
Summary of changes:
cipher/cipher-selftest.c | 29 +++++++++++++++++++
cipher/cipher-selftest.h | 5 ++++
cipher/rijndael.c | 57 +++++++++++++++++++++++++++----------
random/rndw32.c | 2 +-
src/secmem.c | 74 +++++++++++++++++++++++++-----------------------
tests/fipsdrv.c | 4 +--
tests/gchash.c | 2 +-
tests/random.c | 7 +++--
8 files changed, 124 insertions(+), 56 deletions(-)
hooks/post-receive
--
The GNU crypto library
http://git.gnupg.org
_______________________________________________
Gnupg-commits mailing list
Gnupg-commits at gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-commits
More information about the Gcrypt-devel
mailing list