update to 1.8.5
This commit is contained in:
parent
efd386bb84
commit
3f33b83ad8
@ -1,67 +0,0 @@
|
|||||||
From d5407b78cca9f9d318a4f4d2f6ba2b8388584cd9 Mon Sep 17 00:00:00 2001
|
|
||||||
From: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
Date: Wed, 17 Jul 2019 12:44:50 +0900
|
|
||||||
Subject: [PATCH] ecc: Add mitigation against timing attack.
|
|
||||||
MIME-Version: 1.0
|
|
||||||
Content-Type: text/plain; charset=utf8
|
|
||||||
Content-Transfer-Encoding: 8bit
|
|
||||||
|
|
||||||
* cipher/ecc-ecdsa.c (_gcry_ecc_ecdsa_sign): Add the order N to K.
|
|
||||||
* mpi/ec.c (_gcry_mpi_ec_mul_point): Compute with NBITS of P or larger.
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Cherry-picked master commit of:
|
|
||||||
b9577f7c89b4327edc09f2231bc8b31521102c79
|
|
||||||
|
|
||||||
CVE-id: CVE-2019-13627
|
|
||||||
GnuPG-bug-id: 4626
|
|
||||||
Co-authored-by: Ján JanÄár <johny@neuromancer.sk>
|
|
||||||
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
---
|
|
||||||
cipher/ecc-ecdsa.c | 10 ++++++++++
|
|
||||||
mpi/ec.c | 6 +++++-
|
|
||||||
2 files changed, 15 insertions(+), 1 deletion(-)
|
|
||||||
|
|
||||||
diff --git a/cipher/ecc-ecdsa.c b/cipher/ecc-ecdsa.c
|
|
||||||
index 140e8c09..84a1cf84 100644
|
|
||||||
--- a/cipher/ecc-ecdsa.c
|
|
||||||
+++ b/cipher/ecc-ecdsa.c
|
|
||||||
@@ -114,6 +114,16 @@ _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
|
|
||||||
else
|
|
||||||
k = _gcry_dsa_gen_k (skey->E.n, GCRY_STRONG_RANDOM);
|
|
||||||
|
|
||||||
+ /* Originally, ECDSA computation requires k where 0 < k < n.
|
|
||||||
+ * Here, we add n (the order of curve), to keep k in a
|
|
||||||
+ * range: n < k < 2*n, or, addming more n, keep k in a range:
|
|
||||||
+ * 2*n < k < 3*n, so that timing difference of the EC
|
|
||||||
+ * multiply operation can be small. The result is same.
|
|
||||||
+ */
|
|
||||||
+ mpi_add (k, k, skey->E.n);
|
|
||||||
+ if (!mpi_test_bit (k, qbits))
|
|
||||||
+ mpi_add (k, k, skey->E.n);
|
|
||||||
+
|
|
||||||
_gcry_mpi_ec_mul_point (&I, k, &skey->E.G, ctx);
|
|
||||||
if (_gcry_mpi_ec_get_affine (x, NULL, &I, ctx))
|
|
||||||
{
|
|
||||||
diff --git a/mpi/ec.c b/mpi/ec.c
|
|
||||||
index 89077cd9..adb02600 100644
|
|
||||||
--- a/mpi/ec.c
|
|
||||||
+++ b/mpi/ec.c
|
|
||||||
@@ -1309,7 +1309,11 @@ _gcry_mpi_ec_mul_point (mpi_point_t result,
|
|
||||||
unsigned int nbits;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
- nbits = mpi_get_nbits (scalar);
|
|
||||||
+ if (mpi_cmp (scalar, ctx->p) >= 0)
|
|
||||||
+ nbits = mpi_get_nbits (scalar);
|
|
||||||
+ else
|
|
||||||
+ nbits = mpi_get_nbits (ctx->p);
|
|
||||||
+
|
|
||||||
if (ctx->model == MPI_EC_WEIERSTRASS)
|
|
||||||
{
|
|
||||||
mpi_set_ui (result->x, 1);
|
|
||||||
--
|
|
||||||
2.11.0
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,123 +0,0 @@
|
|||||||
From db4e9976cc31b314aafad6626b2894e86ee44d60 Mon Sep 17 00:00:00 2001
|
|
||||||
From: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
Date: Thu, 8 Aug 2019 17:42:02 +0900
|
|
||||||
Subject: [PATCH] dsa,ecdsa: Fix use of nonce, use larger one.
|
|
||||||
|
|
||||||
* cipher/dsa-common.c (_gcry_dsa_modify_k): New.
|
|
||||||
* cipher/pubkey-internal.h (_gcry_dsa_modify_k): New.
|
|
||||||
* cipher/dsa.c (sign): Use _gcry_dsa_modify_k.
|
|
||||||
* cipher/ecc-ecdsa.c (_gcry_ecc_ecdsa_sign): Likewise.
|
|
||||||
* cipher/ecc-gost.c (_gcry_ecc_gost_sign): Likewise.
|
|
||||||
|
|
||||||
--
|
|
||||||
|
|
||||||
Cherry-picked master commit of:
|
|
||||||
7c2943309d14407b51c8166c4dcecb56a3628567
|
|
||||||
|
|
||||||
CVE-id: CVE-2019-13627
|
|
||||||
GnuPG-bug-id: 4626
|
|
||||||
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
|
|
||||||
---
|
|
||||||
cipher/dsa-common.c | 24 ++++++++++++++++++++++++
|
|
||||||
cipher/dsa.c | 2 ++
|
|
||||||
cipher/ecc-ecdsa.c | 10 +---------
|
|
||||||
cipher/ecc-gost.c | 2 ++
|
|
||||||
cipher/pubkey-internal.h | 1 +
|
|
||||||
5 files changed, 30 insertions(+), 9 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/cipher/dsa-common.c b/cipher/dsa-common.c
|
|
||||||
index 8c0a6843..fe49248d 100644
|
|
||||||
--- a/cipher/dsa-common.c
|
|
||||||
+++ b/cipher/dsa-common.c
|
|
||||||
@@ -30,6 +30,30 @@
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
+ * Modify K, so that computation time difference can be small,
|
|
||||||
+ * by making K large enough.
|
|
||||||
+ *
|
|
||||||
+ * Originally, (EC)DSA computation requires k where 0 < k < q. Here,
|
|
||||||
+ * we add q (the order), to keep k in a range: q < k < 2*q (or,
|
|
||||||
+ * addming more q, to keep k in a range: 2*q < k < 3*q), so that
|
|
||||||
+ * timing difference of the EC multiply (or exponentiation) operation
|
|
||||||
+ * can be small. The result of (EC)DSA computation is same.
|
|
||||||
+ */
|
|
||||||
+void
|
|
||||||
+_gcry_dsa_modify_k (gcry_mpi_t k, gcry_mpi_t q, int qbits)
|
|
||||||
+{
|
|
||||||
+ gcry_mpi_t k1 = mpi_new (qbits+2);
|
|
||||||
+
|
|
||||||
+ mpi_resize (k, (qbits+2+BITS_PER_MPI_LIMB-1) / BITS_PER_MPI_LIMB);
|
|
||||||
+ k->nlimbs = k->alloced;
|
|
||||||
+ mpi_add (k, k, q);
|
|
||||||
+ mpi_add (k1, k, q);
|
|
||||||
+ mpi_set_cond (k, k1, !mpi_test_bit (k, qbits));
|
|
||||||
+
|
|
||||||
+ mpi_free (k1);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
* Generate a random secret exponent K less than Q.
|
|
||||||
* Note that ECDSA uses this code also to generate D.
|
|
||||||
*/
|
|
||||||
diff --git a/cipher/dsa.c b/cipher/dsa.c
|
|
||||||
index 22d8d782..24a53528 100644
|
|
||||||
--- a/cipher/dsa.c
|
|
||||||
+++ b/cipher/dsa.c
|
|
||||||
@@ -635,6 +635,8 @@ sign (gcry_mpi_t r, gcry_mpi_t s, gcry_mpi_t input, DSA_secret_key *skey,
|
|
||||||
k = _gcry_dsa_gen_k (skey->q, GCRY_STRONG_RANDOM);
|
|
||||||
}
|
|
||||||
|
|
||||||
+ _gcry_dsa_modify_k (k, skey->q, qbits);
|
|
||||||
+
|
|
||||||
/* r = (a^k mod p) mod q */
|
|
||||||
mpi_powm( r, skey->g, k, skey->p );
|
|
||||||
mpi_fdiv_r( r, r, skey->q );
|
|
||||||
diff --git a/cipher/ecc-ecdsa.c b/cipher/ecc-ecdsa.c
|
|
||||||
index 84a1cf84..97966c3a 100644
|
|
||||||
--- a/cipher/ecc-ecdsa.c
|
|
||||||
+++ b/cipher/ecc-ecdsa.c
|
|
||||||
@@ -114,15 +114,7 @@ _gcry_ecc_ecdsa_sign (gcry_mpi_t input, ECC_secret_key *skey,
|
|
||||||
else
|
|
||||||
k = _gcry_dsa_gen_k (skey->E.n, GCRY_STRONG_RANDOM);
|
|
||||||
|
|
||||||
- /* Originally, ECDSA computation requires k where 0 < k < n.
|
|
||||||
- * Here, we add n (the order of curve), to keep k in a
|
|
||||||
- * range: n < k < 2*n, or, addming more n, keep k in a range:
|
|
||||||
- * 2*n < k < 3*n, so that timing difference of the EC
|
|
||||||
- * multiply operation can be small. The result is same.
|
|
||||||
- */
|
|
||||||
- mpi_add (k, k, skey->E.n);
|
|
||||||
- if (!mpi_test_bit (k, qbits))
|
|
||||||
- mpi_add (k, k, skey->E.n);
|
|
||||||
+ _gcry_dsa_modify_k (k, skey->E.n, qbits);
|
|
||||||
|
|
||||||
_gcry_mpi_ec_mul_point (&I, k, &skey->E.G, ctx);
|
|
||||||
if (_gcry_mpi_ec_get_affine (x, NULL, &I, ctx))
|
|
||||||
diff --git a/cipher/ecc-gost.c b/cipher/ecc-gost.c
|
|
||||||
index a34fa084..0362a6c7 100644
|
|
||||||
--- a/cipher/ecc-gost.c
|
|
||||||
+++ b/cipher/ecc-gost.c
|
|
||||||
@@ -94,6 +94,8 @@ _gcry_ecc_gost_sign (gcry_mpi_t input, ECC_secret_key *skey,
|
|
||||||
mpi_free (k);
|
|
||||||
k = _gcry_dsa_gen_k (skey->E.n, GCRY_STRONG_RANDOM);
|
|
||||||
|
|
||||||
+ _gcry_dsa_modify_k (k, skey->E.n, qbits);
|
|
||||||
+
|
|
||||||
_gcry_mpi_ec_mul_point (&I, k, &skey->E.G, ctx);
|
|
||||||
if (_gcry_mpi_ec_get_affine (x, NULL, &I, ctx))
|
|
||||||
{
|
|
||||||
diff --git a/cipher/pubkey-internal.h b/cipher/pubkey-internal.h
|
|
||||||
index b8167c77..d31e26f3 100644
|
|
||||||
--- a/cipher/pubkey-internal.h
|
|
||||||
+++ b/cipher/pubkey-internal.h
|
|
||||||
@@ -84,6 +84,7 @@ _gcry_rsa_pss_verify (gcry_mpi_t value, gcry_mpi_t encoded,
|
|
||||||
|
|
||||||
|
|
||||||
/*-- dsa-common.c --*/
|
|
||||||
+void _gcry_dsa_modify_k (gcry_mpi_t k, gcry_mpi_t q, int qbits);
|
|
||||||
gcry_mpi_t _gcry_dsa_gen_k (gcry_mpi_t q, int security_level);
|
|
||||||
gpg_err_code_t _gcry_dsa_gen_rfc6979_k (gcry_mpi_t *r_k,
|
|
||||||
gcry_mpi_t dsa_q, gcry_mpi_t dsa_x,
|
|
||||||
--
|
|
||||||
2.11.0
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
From f74687fd43f5772a372f54031d5a9527597f4ce4 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Werner Koch <wk@gnupg.org>
|
|
||||||
Date: Wed, 24 Oct 2018 11:55:34 +0200
|
|
||||||
Subject: [PATCH 098/152] Fix memory leak in secmem in out of core conditions.
|
|
||||||
|
|
||||||
* src/secmem.c (_gcry_secmem_malloc_internal): Release pool descriptor
|
|
||||||
if the pool could not be allocated.
|
|
||||||
--
|
|
||||||
|
|
||||||
GnuPG-bug-id: 4211
|
|
||||||
Signed-off-by: Werner Koch <wk@gnupg.org>
|
|
||||||
---
|
|
||||||
src/secmem.c | 5 ++++-
|
|
||||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
|
||||||
|
|
||||||
diff --git a/src/secmem.c b/src/secmem.c
|
|
||||||
index 79c135f..3e091d8 100644
|
|
||||||
--- a/src/secmem.c
|
|
||||||
+++ b/src/secmem.c
|
|
||||||
@@ -658,7 +658,10 @@ _gcry_secmem_malloc_internal (size_t size, int xhint)
|
|
||||||
pool->size = auto_expand? auto_expand : STANDARD_POOL_SIZE;
|
|
||||||
pool->mem = malloc (pool->size);
|
|
||||||
if (!pool->mem)
|
|
||||||
- return NULL; /* Not enough memory available for a new pool. */
|
|
||||||
+ {
|
|
||||||
+ free (pool);
|
|
||||||
+ return NULL; /* Not enough memory available for a new pool. */
|
|
||||||
+ }
|
|
||||||
/* Initialize first memory block. */
|
|
||||||
mb = (memblock_t *) pool->mem;
|
|
||||||
mb->size = pool->size - BLOCK_HEAD_SIZE;
|
|
||||||
--
|
|
||||||
1.8.3.1
|
|
||||||
|
|
||||||
144
curves.c
144
curves.c
@ -1,144 +0,0 @@
|
|||||||
/* curves.c - ECC curves regression tests
|
|
||||||
* Copyright (C) 2011 Free Software Foundation, Inc.
|
|
||||||
*
|
|
||||||
* This file is part of Libgcrypt.
|
|
||||||
*
|
|
||||||
* Libgcrypt is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Libgcrypt is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include <config.h>
|
|
||||||
#endif
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include "../src/gcrypt-int.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define PGM "curves"
|
|
||||||
#include "t-common.h"
|
|
||||||
|
|
||||||
/* Number of curves defined in ../cipger/ecc.c */
|
|
||||||
#define N_CURVES 14
|
|
||||||
|
|
||||||
/* A real world sample public key. */
|
|
||||||
static char const sample_key_1[] =
|
|
||||||
"(public-key\n"
|
|
||||||
" (ecdsa\n"
|
|
||||||
" (p #00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF#)\n"
|
|
||||||
" (a #00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC#)\n"
|
|
||||||
" (b #5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B#)\n"
|
|
||||||
" (g #046B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
|
|
||||||
"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5#)\n"
|
|
||||||
" (n #00FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551#)\n"
|
|
||||||
" (h #000000000000000000000000000000000000000000000000000000000000000001#)\n"
|
|
||||||
" (q #0442B927242237639A36CE9221B340DB1A9AB76DF2FE3E171277F6A4023DED146EE"
|
|
||||||
"86525E38CCECFF3FB8D152CC6334F70D23A525175C1BCBDDE6E023B2228770E#)\n"
|
|
||||||
" ))";
|
|
||||||
static char const sample_key_1_curve[] = "NIST P-256";
|
|
||||||
static unsigned int sample_key_1_nbits = 256;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
list_curves (void)
|
|
||||||
{
|
|
||||||
int idx;
|
|
||||||
const char *name;
|
|
||||||
unsigned int nbits;
|
|
||||||
|
|
||||||
for (idx=0; (name = gcry_pk_get_curve (NULL, idx, &nbits)); idx++)
|
|
||||||
{
|
|
||||||
if (verbose)
|
|
||||||
printf ("%s - %u bits\n", name, nbits);
|
|
||||||
}
|
|
||||||
if (idx != N_CURVES)
|
|
||||||
fail ("expected %d curves but got %d\n", N_CURVES, idx);
|
|
||||||
if (gcry_pk_get_curve (NULL, -1, NULL))
|
|
||||||
fail ("curve iteration failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
check_matching (void)
|
|
||||||
{
|
|
||||||
gpg_error_t err;
|
|
||||||
gcry_sexp_t key;
|
|
||||||
const char *name;
|
|
||||||
unsigned int nbits;
|
|
||||||
|
|
||||||
err = gcry_sexp_new (&key, sample_key_1, 0, 1);
|
|
||||||
if (err)
|
|
||||||
die ("parsing s-expression string failed: %s\n", gpg_strerror (err));
|
|
||||||
name = gcry_pk_get_curve (key, 0, &nbits);
|
|
||||||
if (!name)
|
|
||||||
fail ("curve name not found for sample_key_1\n");
|
|
||||||
else if (strcmp (name, sample_key_1_curve))
|
|
||||||
fail ("expected curve name %s but got %s for sample_key_1\n",
|
|
||||||
sample_key_1_curve, name);
|
|
||||||
else if (nbits != sample_key_1_nbits)
|
|
||||||
fail ("expected curve size %u but got %u for sample_key_1\n",
|
|
||||||
sample_key_1_nbits, nbits);
|
|
||||||
|
|
||||||
gcry_sexp_release (key);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
check_get_params (void)
|
|
||||||
{
|
|
||||||
gcry_sexp_t param;
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
param = gcry_pk_get_param (GCRY_PK_ECDSA, sample_key_1_curve);
|
|
||||||
if (!param)
|
|
||||||
fail ("error gerring parameters for `%s'\n", sample_key_1_curve);
|
|
||||||
|
|
||||||
name = gcry_pk_get_curve (param, 0, NULL);
|
|
||||||
if (!name)
|
|
||||||
fail ("get_param: curve name not found for sample_key_1\n");
|
|
||||||
else if (strcmp (name, sample_key_1_curve))
|
|
||||||
fail ("get_param: expected curve name %s but got %s for sample_key_1\n",
|
|
||||||
sample_key_1_curve, name);
|
|
||||||
|
|
||||||
gcry_sexp_release (param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
if (argc > 1 && !strcmp (argv[1], "--verbose"))
|
|
||||||
verbose = 1;
|
|
||||||
else if (argc > 1 && !strcmp (argv[1], "--debug"))
|
|
||||||
verbose = debug = 1;
|
|
||||||
|
|
||||||
if (!gcry_check_version (GCRYPT_VERSION))
|
|
||||||
die ("version mismatch\n");
|
|
||||||
|
|
||||||
xgcry_control (GCRYCTL_DISABLE_SECMEM, 0);
|
|
||||||
xgcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
|
||||||
if (debug)
|
|
||||||
xgcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
|
|
||||||
list_curves ();
|
|
||||||
check_matching ();
|
|
||||||
check_get_params ();
|
|
||||||
|
|
||||||
return error_count ? 1 : 0;
|
|
||||||
}
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
From e57e75ea517f32109b508113f18298fc69fd1192 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Werner Koch <wk@gnupg.org>
|
|
||||||
Date: Wed, 24 Oct 2018 11:50:46 +0200
|
|
||||||
Subject: [PATCH 097/152] ecc: Fix memory leak in the error case of
|
|
||||||
ecc_encrypt_raw
|
|
||||||
|
|
||||||
* cipher/ecc.c (ecc_encrypt_raw): Add proper error cleanup in the main
|
|
||||||
block.
|
|
||||||
--
|
|
||||||
|
|
||||||
GnuPG-bug-id: 4210
|
|
||||||
Signed-off-by: Werner Koch <wk@gnupg.org>
|
|
||||||
---
|
|
||||||
cipher/ecc.c | 10 ++++++----
|
|
||||||
1 file changed, 6 insertions(+), 4 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/cipher/ecc.c b/cipher/ecc.c
|
|
||||||
index 4e3e5b1..3f221a2 100644
|
|
||||||
--- a/cipher/ecc.c
|
|
||||||
+++ b/cipher/ecc.c
|
|
||||||
@@ -1392,6 +1392,7 @@ ecc_encrypt_raw (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t keyparms)
|
|
||||||
unsigned char *rawmpi;
|
|
||||||
unsigned int rawmpilen;
|
|
||||||
|
|
||||||
+ rc = 0;
|
|
||||||
x = mpi_new (0);
|
|
||||||
if (ec->model == MPI_EC_MONTGOMERY)
|
|
||||||
y = NULL;
|
|
||||||
@@ -1418,7 +1419,7 @@ ecc_encrypt_raw (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t keyparms)
|
|
||||||
if (!(flags & PUBKEY_FLAG_DJB_TWEAK))
|
|
||||||
{ /* It's not for X25519, then, the input data was simply wrong. */
|
|
||||||
rc = GPG_ERR_INV_DATA;
|
|
||||||
- goto leave;
|
|
||||||
+ goto leave_main;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (y)
|
|
||||||
@@ -1443,7 +1444,7 @@ ecc_encrypt_raw (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t keyparms)
|
|
||||||
if (_gcry_mpi_ec_get_affine (x, y, &R, ec))
|
|
||||||
{
|
|
||||||
rc = GPG_ERR_INV_DATA;
|
|
||||||
- goto leave;
|
|
||||||
+ goto leave_main;
|
|
||||||
}
|
|
||||||
if (y)
|
|
||||||
mpi_e = _gcry_ecc_ec2os (x, y, pk.E.p);
|
|
||||||
@@ -1461,11 +1462,12 @@ ecc_encrypt_raw (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t keyparms)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-
|
|
||||||
+ leave_main:
|
|
||||||
mpi_free (x);
|
|
||||||
mpi_free (y);
|
|
||||||
-
|
|
||||||
point_free (&R);
|
|
||||||
+ if (rc)
|
|
||||||
+ goto leave;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rc)
|
|
||||||
--
|
|
||||||
1.8.3.1
|
|
||||||
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
From 149ceb3cae03d0385341d32430aa5ae57de90007 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Werner Koch <wk@gnupg.org>
|
|
||||||
Date: Wed, 24 Oct 2018 09:50:17 +0200
|
|
||||||
Subject: [PATCH 096/152] ecc: Fix possible memory leakage in parameter check
|
|
||||||
of eddsa.
|
|
||||||
|
|
||||||
* cipher/ecc-eddsa.c (_gcry_ecc_eddsa_verify): Fix mem leak.
|
|
||||||
--
|
|
||||||
|
|
||||||
GnuPG-bug-id: 4209
|
|
||||||
Signed-off-by: Werner Koch <wk@gnupg.org>
|
|
||||||
---
|
|
||||||
cipher/ecc-eddsa.c | 5 ++++-
|
|
||||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
|
||||||
|
|
||||||
diff --git a/cipher/ecc-eddsa.c b/cipher/ecc-eddsa.c
|
|
||||||
index 813e030..89b708a 100644
|
|
||||||
--- a/cipher/ecc-eddsa.c
|
|
||||||
+++ b/cipher/ecc-eddsa.c
|
|
||||||
@@ -760,7 +760,10 @@ _gcry_ecc_eddsa_verify (gcry_mpi_t input, ECC_public_key *pkey,
|
|
||||||
pkey->E.p, pkey->E.a, pkey->E.b);
|
|
||||||
b = ctx->nbits/8;
|
|
||||||
if (b != 256/8)
|
|
||||||
- return GPG_ERR_INTERNAL; /* We only support 256 bit. */
|
|
||||||
+ {
|
|
||||||
+ rc = GPG_ERR_INTERNAL; /* We only support 256 bit. */
|
|
||||||
+ goto leave;
|
|
||||||
+ }
|
|
||||||
|
|
||||||
/* Decode and check the public key. */
|
|
||||||
rc = _gcry_ecc_eddsa_decodepoint (pk, ctx, &Q, &encpk, &encpklen);
|
|
||||||
--
|
|
||||||
1.8.3.1
|
|
||||||
|
|
||||||
1207
ecc-curves.c
1207
ecc-curves.c
File diff suppressed because it is too large
Load Diff
@ -1,11 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Quit out if anything fails.
|
|
||||||
set -e -x
|
|
||||||
|
|
||||||
# Clean out patent-or-otherwise-encumbered code.
|
|
||||||
# EC: ????????? ??/??/2015
|
|
||||||
|
|
||||||
rm -f cipher/ecc-curves.c
|
|
||||||
rm -f tests/curves.c
|
|
||||||
rm -f tests/t-mpi-point.c
|
|
||||||
@ -1,115 +0,0 @@
|
|||||||
diff -up libgcrypt-1.8.0/cipher/dsa.c.tests libgcrypt-1.8.0/cipher/dsa.c
|
|
||||||
--- libgcrypt-1.8.0/cipher/dsa.c.tests 2016-04-07 17:30:08.000000000 +0200
|
|
||||||
+++ libgcrypt-1.8.0/cipher/dsa.c 2017-08-15 15:10:39.551600227 +0200
|
|
||||||
@@ -457,11 +457,22 @@ generate_fips186 (DSA_secret_key *sk, un
|
|
||||||
&prime_q, &prime_p,
|
|
||||||
r_counter,
|
|
||||||
r_seed, r_seedlen);
|
|
||||||
- else
|
|
||||||
- ec = _gcry_generate_fips186_3_prime (nbits, qbits, NULL, 0,
|
|
||||||
+ else if (!domain->p || !domain->q)
|
|
||||||
+ ec = _gcry_generate_fips186_3_prime (nbits, qbits,
|
|
||||||
+ initial_seed.seed,
|
|
||||||
+ initial_seed.seedlen,
|
|
||||||
&prime_q, &prime_p,
|
|
||||||
r_counter,
|
|
||||||
r_seed, r_seedlen, NULL);
|
|
||||||
+ else
|
|
||||||
+ {
|
|
||||||
+ /* Domain parameters p and q are given; use them. */
|
|
||||||
+ prime_p = mpi_copy (domain->p);
|
|
||||||
+ prime_q = mpi_copy (domain->q);
|
|
||||||
+ gcry_assert (mpi_get_nbits (prime_p) == nbits);
|
|
||||||
+ gcry_assert (mpi_get_nbits (prime_q) == qbits);
|
|
||||||
+ ec = 0;
|
|
||||||
+ }
|
|
||||||
sexp_release (initial_seed.sexp);
|
|
||||||
if (ec)
|
|
||||||
goto leave;
|
|
||||||
@@ -855,13 +866,12 @@ dsa_generate (const gcry_sexp_t genparms
|
|
||||||
sexp_release (l1);
|
|
||||||
sexp_release (domainsexp);
|
|
||||||
|
|
||||||
- /* Check that all domain parameters are available. */
|
|
||||||
- if (!domain.p || !domain.q || !domain.g)
|
|
||||||
+ /* Check that p and q domain parameters are available. */
|
|
||||||
+ if (!domain.p || !domain.q || (!domain.g && !(flags & PUBKEY_FLAG_USE_FIPS186)))
|
|
||||||
{
|
|
||||||
_gcry_mpi_release (domain.p);
|
|
||||||
_gcry_mpi_release (domain.q);
|
|
||||||
_gcry_mpi_release (domain.g);
|
|
||||||
- sexp_release (deriveparms);
|
|
||||||
return GPG_ERR_MISSING_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
diff -up libgcrypt-1.8.0/cipher/rsa.c.tests libgcrypt-1.8.0/cipher/rsa.c
|
|
||||||
--- libgcrypt-1.8.0/cipher/rsa.c.tests 2017-07-06 10:21:36.000000000 +0200
|
|
||||||
+++ libgcrypt-1.8.0/cipher/rsa.c 2017-08-15 15:10:39.551600227 +0200
|
|
||||||
@@ -696,7 +696,7 @@ generate_x931 (RSA_secret_key *sk, unsig
|
|
||||||
|
|
||||||
*swapped = 0;
|
|
||||||
|
|
||||||
- if (e_value == 1) /* Alias for a secure value. */
|
|
||||||
+ if (e_value == 1 || e_value == 0) /* Alias for a secure value. */
|
|
||||||
e_value = 65537;
|
|
||||||
|
|
||||||
/* Point 1 of section 4.1: k = 1024 + 256s with S >= 0 */
|
|
||||||
diff -up libgcrypt-1.8.0/tests/keygen.c.tests libgcrypt-1.8.0/tests/keygen.c
|
|
||||||
--- libgcrypt-1.8.0/tests/keygen.c.tests 2017-08-15 15:10:39.551600227 +0200
|
|
||||||
+++ libgcrypt-1.8.0/tests/keygen.c 2017-08-15 15:16:05.433176171 +0200
|
|
||||||
@@ -200,11 +200,11 @@ check_rsa_keys (void)
|
|
||||||
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
- info ("creating 512 bit RSA key with e=257\n");
|
|
||||||
+ info ("creating 1024 bit RSA key with e=257\n");
|
|
||||||
rc = gcry_sexp_new (&keyparm,
|
|
||||||
"(genkey\n"
|
|
||||||
" (rsa\n"
|
|
||||||
- " (nbits 3:512)\n"
|
|
||||||
+ " (nbits 4:1024)\n"
|
|
||||||
" (rsa-use-e 3:257)\n"
|
|
||||||
" ))", 0, 1);
|
|
||||||
if (rc)
|
|
||||||
@@ -225,11 +225,11 @@ check_rsa_keys (void)
|
|
||||||
gcry_sexp_release (key);
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
- info ("creating 512 bit RSA key with default e\n");
|
|
||||||
+ info ("creating 1024 bit RSA key with default e\n");
|
|
||||||
rc = gcry_sexp_new (&keyparm,
|
|
||||||
"(genkey\n"
|
|
||||||
" (rsa\n"
|
|
||||||
- " (nbits 3:512)\n"
|
|
||||||
+ " (nbits 4:1024)\n"
|
|
||||||
" (rsa-use-e 1:0)\n"
|
|
||||||
" ))", 0, 1);
|
|
||||||
if (rc)
|
|
||||||
@@ -309,12 +309,12 @@ check_dsa_keys (void)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
- info ("creating 1536 bit DSA key\n");
|
|
||||||
+ info ("creating 2048 bit DSA key\n");
|
|
||||||
rc = gcry_sexp_new (&keyparm,
|
|
||||||
"(genkey\n"
|
|
||||||
" (dsa\n"
|
|
||||||
- " (nbits 4:1536)\n"
|
|
||||||
- " (qbits 3:224)\n"
|
|
||||||
+ " (nbits 4:2048)\n"
|
|
||||||
+ " (qbits 3:256)\n"
|
|
||||||
" ))", 0, 1);
|
|
||||||
if (rc)
|
|
||||||
die ("error creating S-expression: %s\n", gpg_strerror (rc));
|
|
||||||
diff -up libgcrypt-1.8.0/tests/pubkey.c.tests libgcrypt-1.8.0/tests/pubkey.c
|
|
||||||
--- libgcrypt-1.8.0/tests/pubkey.c.tests 2017-01-18 15:24:25.000000000 +0100
|
|
||||||
+++ libgcrypt-1.8.0/tests/pubkey.c 2017-08-15 15:10:39.552600207 +0200
|
|
||||||
@@ -595,7 +595,7 @@ get_dsa_key_fips186_with_seed_new (gcry_
|
|
||||||
" (use-fips186)"
|
|
||||||
" (transient-key)"
|
|
||||||
" (derive-parms"
|
|
||||||
- " (seed #0cb1990c1fd3626055d7a0096f8fa99807399871#))))",
|
|
||||||
+ " (seed #8b4c4d671fff82e8ed932260206d0571e3a1c2cee8cd94cb73fe58f9b67488fa#))))",
|
|
||||||
0, 1);
|
|
||||||
if (rc)
|
|
||||||
die ("error creating S-expression: %s\n", gcry_strerror (rc));
|
|
||||||
322
libgcrypt-1.8.3-cmac-selftest.patch
Normal file
322
libgcrypt-1.8.3-cmac-selftest.patch
Normal file
@ -0,0 +1,322 @@
|
|||||||
|
diff -up libgcrypt-1.8.3/cipher/cipher-cmac.c.cmac-selftest libgcrypt-1.8.3/cipher/cipher-cmac.c
|
||||||
|
--- libgcrypt-1.8.3/cipher/cipher-cmac.c.cmac-selftest 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.3/cipher/cipher-cmac.c 2019-05-31 17:33:35.594407152 +0200
|
||||||
|
@@ -251,3 +251,246 @@ _gcry_cipher_cmac_set_subkeys (gcry_ciph
|
||||||
|
|
||||||
|
return GPG_ERR_NO_ERROR;
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+/* CMAC selftests.
|
||||||
|
+ * Copyright (C) 2008 Free Software Foundation, Inc.
|
||||||
|
+ * Copyright (C) 2019 Red Hat, Inc.
|
||||||
|
+ */
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+/* Check one MAC with MAC ALGO using the regular MAC
|
||||||
|
+ * API. (DATA,DATALEN) is the data to be MACed, (KEY,KEYLEN) the key
|
||||||
|
+ * and (EXPECT,EXPECTLEN) the expected result. If TRUNC is set, the
|
||||||
|
+ * EXPECTLEN may be less than the digest length. Returns NULL on
|
||||||
|
+ * success or a string describing the failure. */
|
||||||
|
+static const char *
|
||||||
|
+check_one (int algo,
|
||||||
|
+ const void *data, size_t datalen,
|
||||||
|
+ const void *key, size_t keylen,
|
||||||
|
+ const void *expect, size_t expectlen)
|
||||||
|
+{
|
||||||
|
+ gcry_mac_hd_t hd;
|
||||||
|
+ unsigned char mac[512]; /* hardcoded to avoid allocation */
|
||||||
|
+ size_t macoutlen = expectlen;
|
||||||
|
+
|
||||||
|
+/* printf ("MAC algo %d\n", algo); */
|
||||||
|
+ if (_gcry_mac_get_algo_maclen (algo) != expectlen ||
|
||||||
|
+ expectlen > sizeof (mac))
|
||||||
|
+ return "invalid tests data";
|
||||||
|
+ if (_gcry_mac_open (&hd, algo, 0, NULL))
|
||||||
|
+ return "gcry_mac_open failed";
|
||||||
|
+ if (_gcry_mac_setkey (hd, key, keylen))
|
||||||
|
+ {
|
||||||
|
+ _gcry_mac_close (hd);
|
||||||
|
+ return "gcry_md_setkey failed";
|
||||||
|
+ }
|
||||||
|
+ if (_gcry_mac_write (hd, data, datalen))
|
||||||
|
+ {
|
||||||
|
+ _gcry_mac_close (hd);
|
||||||
|
+ return "gcry_mac_write failed";
|
||||||
|
+ }
|
||||||
|
+ if (_gcry_mac_read (hd, mac, &macoutlen))
|
||||||
|
+ {
|
||||||
|
+ _gcry_mac_close (hd);
|
||||||
|
+ return "gcry_mac_read failed";
|
||||||
|
+ }
|
||||||
|
+ _gcry_mac_close (hd);
|
||||||
|
+ if (macoutlen != expectlen || memcmp (mac, expect, expectlen))
|
||||||
|
+ {
|
||||||
|
+/* int i; */
|
||||||
|
+
|
||||||
|
+/* fputs (" {", stdout); */
|
||||||
|
+/* for (i=0; i < expectlen-1; i++) */
|
||||||
|
+/* { */
|
||||||
|
+/* if (i && !(i % 8)) */
|
||||||
|
+/* fputs ("\n ", stdout); */
|
||||||
|
+/* printf (" 0x%02x,", mac[i]); */
|
||||||
|
+/* } */
|
||||||
|
+/* printf (" 0x%02x } },\n", mac[i]); */
|
||||||
|
+
|
||||||
|
+ return "does not match";
|
||||||
|
+ }
|
||||||
|
+ return NULL;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+static gpg_err_code_t
|
||||||
|
+selftests_cmac_tdes (int extended, selftest_report_func_t report)
|
||||||
|
+{
|
||||||
|
+ const char *what;
|
||||||
|
+ const char *errtxt;
|
||||||
|
+
|
||||||
|
+ what = "Basic TDES";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_3DES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
|
||||||
|
+ "\xae\x2d\x8a\x57", 20,
|
||||||
|
+ "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
|
||||||
|
+ "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", 24,
|
||||||
|
+ "\x74\x3d\xdb\xe0\xce\x2d\xc2\xed", 8);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+
|
||||||
|
+ if (extended)
|
||||||
|
+ {
|
||||||
|
+ what = "Extended TDES #1";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_3DES,
|
||||||
|
+ "", 0,
|
||||||
|
+ "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
|
||||||
|
+ "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", 24,
|
||||||
|
+ "\xb7\xa6\x88\xe1\x22\xff\xaf\x95", 8);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+
|
||||||
|
+ what = "Extended TDES #2";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_3DES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96", 8,
|
||||||
|
+ "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
|
||||||
|
+ "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", 24,
|
||||||
|
+ "\x8e\x8f\x29\x31\x36\x28\x37\x97", 8);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+
|
||||||
|
+ what = "Extended TDES #3";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_3DES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
|
||||||
|
+ "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51", 32,
|
||||||
|
+ "\x8a\xa8\x3b\xf8\xcb\xda\x10\x62\x0b\xc1\xbf\x19\xfb\xb6\xcd\x58"
|
||||||
|
+ "\xbc\x31\x3d\x4a\x37\x1c\xa8\xb5", 24,
|
||||||
|
+ "\x33\xe6\xb1\x09\x24\x00\xea\xe5", 8);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return 0; /* Succeeded. */
|
||||||
|
+
|
||||||
|
+ failed:
|
||||||
|
+ if (report)
|
||||||
|
+ report ("cmac", GCRY_MAC_CMAC_3DES, what, errtxt);
|
||||||
|
+ return GPG_ERR_SELFTEST_FAILED;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+static gpg_err_code_t
|
||||||
|
+selftests_cmac_aes (int extended, selftest_report_func_t report)
|
||||||
|
+{
|
||||||
|
+ const char *what;
|
||||||
|
+ const char *errtxt;
|
||||||
|
+
|
||||||
|
+ what = "Basic AES128";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_AES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
|
||||||
|
+ "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
|
||||||
|
+ "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11", 40,
|
||||||
|
+ "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c", 16,
|
||||||
|
+ "\xdf\xa6\x67\x47\xde\x9a\xe6\x30\x30\xca\x32\x61\x14\x97\xc8\x27", 16);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+
|
||||||
|
+ what = "Basic AES192";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_AES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
|
||||||
|
+ "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
|
||||||
|
+ "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11", 40,
|
||||||
|
+ "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
|
||||||
|
+ "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b", 24,
|
||||||
|
+ "\x8a\x1d\xe5\xbe\x2e\xb3\x1a\xad\x08\x9a\x82\xe6\xee\x90\x8b\x0e", 16);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+
|
||||||
|
+ what = "Basic AES256";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_AES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
|
||||||
|
+ "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
|
||||||
|
+ "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11", 40,
|
||||||
|
+ "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
|
||||||
|
+ "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4", 32,
|
||||||
|
+ "\xaa\xf3\xd8\xf1\xde\x56\x40\xc2\x32\xf5\xb1\x69\xb9\xc9\x11\xe6", 16);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+ if (extended)
|
||||||
|
+ {
|
||||||
|
+ what = "Extended AES #1";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_AES,
|
||||||
|
+ "", 0,
|
||||||
|
+ "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c", 16,
|
||||||
|
+ "\xbb\x1d\x69\x29\xe9\x59\x37\x28\x7f\xa3\x7d\x12\x9b\x75\x67\x46", 16);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+
|
||||||
|
+ what = "Extended AES #2";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_AES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a", 16,
|
||||||
|
+ "\x8e\x73\xb0\xf7\xda\x0e\x64\x52\xc8\x10\xf3\x2b\x80\x90\x79\xe5"
|
||||||
|
+ "\x62\xf8\xea\xd2\x52\x2c\x6b\x7b", 24,
|
||||||
|
+ "\x9e\x99\xa7\xbf\x31\xe7\x10\x90\x06\x62\xf6\x5e\x61\x7c\x51\x84", 16);
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+
|
||||||
|
+ what = "Extended AES #3";
|
||||||
|
+ errtxt = check_one (GCRY_MAC_CMAC_AES,
|
||||||
|
+ "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a"
|
||||||
|
+ "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51"
|
||||||
|
+ "\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a\x0a\x52\xef"
|
||||||
|
+ "\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b\xe6\x6c\x37\x10", 64,
|
||||||
|
+ "\x60\x3d\xeb\x10\x15\xca\x71\xbe\x2b\x73\xae\xf0\x85\x7d\x77\x81"
|
||||||
|
+ "\x1f\x35\x2c\x07\x3b\x61\x08\xd7\x2d\x98\x10\xa3\x09\x14\xdf\xf4", 32,
|
||||||
|
+ "\xe1\x99\x21\x90\x54\x9f\x6e\xd5\x69\x6a\x2c\x05\x6c\x31\x54\x10", 16 );
|
||||||
|
+ if (errtxt)
|
||||||
|
+ goto failed;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return 0; /* Succeeded. */
|
||||||
|
+
|
||||||
|
+ failed:
|
||||||
|
+ if (report)
|
||||||
|
+ report ("cmac", GCRY_MAC_CMAC_AES, what, errtxt);
|
||||||
|
+ return GPG_ERR_SELFTEST_FAILED;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+/* Run a full self-test for ALGO and return 0 on success. */
|
||||||
|
+static gpg_err_code_t
|
||||||
|
+run_cmac_selftests (int algo, int extended, selftest_report_func_t report)
|
||||||
|
+{
|
||||||
|
+ gpg_err_code_t ec;
|
||||||
|
+
|
||||||
|
+ switch (algo)
|
||||||
|
+ {
|
||||||
|
+ case GCRY_MAC_CMAC_3DES:
|
||||||
|
+ ec = selftests_cmac_tdes (extended, report);
|
||||||
|
+ break;
|
||||||
|
+ case GCRY_MAC_CMAC_AES:
|
||||||
|
+ ec = selftests_cmac_aes (extended, report);
|
||||||
|
+ break;
|
||||||
|
+
|
||||||
|
+ default:
|
||||||
|
+ ec = GPG_ERR_MAC_ALGO;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ return ec;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+/* Run the selftests for CMAC with CMAC algorithm ALGO with optional
|
||||||
|
+ reporting function REPORT. */
|
||||||
|
+gpg_error_t
|
||||||
|
+_gcry_cmac_selftest (int algo, int extended, selftest_report_func_t report)
|
||||||
|
+{
|
||||||
|
+ gcry_err_code_t ec = 0;
|
||||||
|
+
|
||||||
|
+ if (!_gcry_mac_algo_info( algo, GCRYCTL_TEST_ALGO, NULL, NULL ))
|
||||||
|
+ {
|
||||||
|
+ ec = run_cmac_selftests (algo, extended, report);
|
||||||
|
+ }
|
||||||
|
+ else
|
||||||
|
+ {
|
||||||
|
+ ec = GPG_ERR_MAC_ALGO;
|
||||||
|
+ if (report)
|
||||||
|
+ report ("mac", algo, "module", "algorithm not available");
|
||||||
|
+ }
|
||||||
|
+ return gpg_error (ec);
|
||||||
|
+}
|
||||||
|
diff -up libgcrypt-1.8.3/src/cipher-proto.h.cmac-selftest libgcrypt-1.8.3/src/cipher-proto.h
|
||||||
|
--- libgcrypt-1.8.3/src/cipher-proto.h.cmac-selftest 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.3/src/cipher-proto.h 2019-05-31 17:29:34.574588234 +0200
|
||||||
|
@@ -256,6 +256,8 @@ gcry_error_t _gcry_pk_selftest (int algo
|
||||||
|
selftest_report_func_t report);
|
||||||
|
gcry_error_t _gcry_hmac_selftest (int algo, int extended,
|
||||||
|
selftest_report_func_t report);
|
||||||
|
+gcry_error_t _gcry_cmac_selftest (int algo, int extended,
|
||||||
|
+ selftest_report_func_t report);
|
||||||
|
|
||||||
|
gcry_error_t _gcry_random_selftest (selftest_report_func_t report);
|
||||||
|
|
||||||
|
diff -up libgcrypt-1.8.3/src/fips.c.cmac-selftest libgcrypt-1.8.3/src/fips.c
|
||||||
|
--- libgcrypt-1.8.3/src/fips.c.cmac-selftest 2018-11-01 15:40:36.051865535 +0100
|
||||||
|
+++ libgcrypt-1.8.3/src/fips.c 2019-05-31 17:31:20.157756640 +0200
|
||||||
|
@@ -521,29 +521,32 @@ run_digest_selftests (int extended)
|
||||||
|
|
||||||
|
/* Run self-tests for all HMAC algorithms. Return 0 on success. */
|
||||||
|
static int
|
||||||
|
-run_hmac_selftests (int extended)
|
||||||
|
+run_mac_selftests (int extended)
|
||||||
|
{
|
||||||
|
- static int algos[] =
|
||||||
|
+ static int algos[][2] =
|
||||||
|
{
|
||||||
|
- GCRY_MD_SHA1,
|
||||||
|
- GCRY_MD_SHA224,
|
||||||
|
- GCRY_MD_SHA256,
|
||||||
|
- GCRY_MD_SHA384,
|
||||||
|
- GCRY_MD_SHA512,
|
||||||
|
- GCRY_MD_SHA3_224,
|
||||||
|
- GCRY_MD_SHA3_256,
|
||||||
|
- GCRY_MD_SHA3_384,
|
||||||
|
- GCRY_MD_SHA3_512,
|
||||||
|
- 0
|
||||||
|
+ { GCRY_MD_SHA1, 0 },
|
||||||
|
+ { GCRY_MD_SHA224, 0 },
|
||||||
|
+ { GCRY_MD_SHA256, 0 },
|
||||||
|
+ { GCRY_MD_SHA384, 0 },
|
||||||
|
+ { GCRY_MD_SHA512, 0 },
|
||||||
|
+ { GCRY_MD_SHA3_224, 0 },
|
||||||
|
+ { GCRY_MD_SHA3_256, 0 },
|
||||||
|
+ { GCRY_MD_SHA3_384, 0 },
|
||||||
|
+ { GCRY_MD_SHA3_512, 0 },
|
||||||
|
+ { GCRY_MAC_CMAC_3DES, 1 },
|
||||||
|
+ { GCRY_MAC_CMAC_AES, 1 },
|
||||||
|
+ { 0, 0 }
|
||||||
|
};
|
||||||
|
int idx;
|
||||||
|
gpg_error_t err;
|
||||||
|
int anyerr = 0;
|
||||||
|
|
||||||
|
- for (idx=0; algos[idx]; idx++)
|
||||||
|
+ for (idx=0; algos[idx][0]; idx++)
|
||||||
|
{
|
||||||
|
- err = _gcry_hmac_selftest (algos[idx], extended, reporter);
|
||||||
|
- reporter ("hmac", algos[idx], NULL,
|
||||||
|
+ err = algos[idx][1] ? _gcry_cmac_selftest (algos[idx][0], extended, reporter) :
|
||||||
|
+ _gcry_hmac_selftest (algos[idx][0], extended, reporter);
|
||||||
|
+ reporter (algos[idx][1] ? "cmac" : "hmac", algos[idx][0], NULL,
|
||||||
|
err? gpg_strerror (err):NULL);
|
||||||
|
if (err)
|
||||||
|
anyerr = 1;
|
||||||
|
@@ -747,7 +750,7 @@ _gcry_fips_run_selftests (int extended)
|
||||||
|
if (run_digest_selftests (extended))
|
||||||
|
goto leave;
|
||||||
|
|
||||||
|
- if (run_hmac_selftests (extended))
|
||||||
|
+ if (run_mac_selftests (extended))
|
||||||
|
goto leave;
|
||||||
|
|
||||||
|
/* Run random tests before the pubkey tests because the latter
|
||||||
113
libgcrypt-1.8.3-fips-enttest.patch
Normal file
113
libgcrypt-1.8.3-fips-enttest.patch
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
diff -up libgcrypt-1.8.3/random/random-drbg.c.fips-enttest libgcrypt-1.8.3/random/random-drbg.c
|
||||||
|
--- libgcrypt-1.8.3/random/random-drbg.c.fips-enttest 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.3/random/random-drbg.c 2019-06-24 10:04:23.219547141 +0200
|
||||||
|
@@ -317,6 +317,7 @@ struct drbg_state_s
|
||||||
|
unsigned char *ctr_null; /* CTR mode zero buffer */
|
||||||
|
int seeded:1; /* DRBG fully seeded? */
|
||||||
|
int pr:1; /* Prediction resistance enabled? */
|
||||||
|
+ int ent_primed:1; /* Previous entropy data primed? */
|
||||||
|
/* Taken from libgcrypt ANSI X9.31 DRNG: We need to keep track of the
|
||||||
|
* process which did the initialization so that we can detect a fork.
|
||||||
|
* The volatile modifier is required so that the compiler does not
|
||||||
|
@@ -324,6 +325,7 @@ struct drbg_state_s
|
||||||
|
pid_t seed_init_pid;
|
||||||
|
const struct drbg_state_ops_s *d_ops;
|
||||||
|
const struct drbg_core_s *core;
|
||||||
|
+ unsigned char ent_hash[64]; /* Hash of previous entropy data */
|
||||||
|
struct drbg_test_data_s *test_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
@@ -610,11 +612,13 @@ drbg_get_entropy (drbg_state_t drbg, uns
|
||||||
|
size_t len)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
+ unsigned char newhash[64];
|
||||||
|
|
||||||
|
/* Perform testing as defined in 11.3.2 */
|
||||||
|
if (drbg->test_data && drbg->test_data->fail_seed_source)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
+redo:
|
||||||
|
read_cb_buffer = buffer;
|
||||||
|
read_cb_size = len;
|
||||||
|
read_cb_len = 0;
|
||||||
|
@@ -634,6 +638,27 @@ drbg_get_entropy (drbg_state_t drbg, uns
|
||||||
|
#else
|
||||||
|
rc = -1;
|
||||||
|
#endif
|
||||||
|
+
|
||||||
|
+ /* to avoid storing the actual entropy obtained for indefinite
|
||||||
|
+ time, we just store the SHA-512 hash of the entropy gathered
|
||||||
|
+ */
|
||||||
|
+ _gcry_md_hash_buffer (GCRY_MD_SHA512, newhash, buffer, len);
|
||||||
|
+
|
||||||
|
+ if (!drbg->ent_primed)
|
||||||
|
+ {
|
||||||
|
+ memcpy (drbg->ent_hash, newhash, sizeof (drbg->ent_hash));
|
||||||
|
+ drbg->ent_primed = 1;
|
||||||
|
+ goto redo;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (memcmp (newhash, drbg->ent_hash, sizeof (drbg->ent_hash)) == 0)
|
||||||
|
+ {
|
||||||
|
+ fips_signal_error ("Entropy source failed the continuous test");
|
||||||
|
+ return -1; /* continuous entropy test failed */
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ memcpy (drbg->ent_hash, newhash, sizeof (drbg->ent_hash));
|
||||||
|
+
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1341,26 +1366,38 @@ drbg_seed (drbg_state_t drbg, drbg_strin
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
+ int nonce = 0;
|
||||||
|
/* Gather entropy equal to the security strength of the DRBG.
|
||||||
|
* With a derivation function, a nonce is required in addition
|
||||||
|
* to the entropy. A nonce must be at least 1/2 of the security
|
||||||
|
* strength of the DRBG in size. Thus, entropy * nonce is 3/2
|
||||||
|
* of the strength. The consideration of a nonce is only
|
||||||
|
- * applicable during initial seeding. */
|
||||||
|
+ * applicable during initial seeding.
|
||||||
|
+ * To avoid pulling different length of data from entropy
|
||||||
|
+ * source, we use 2 * strength for initial seeding. */
|
||||||
|
entropylen = drbg_sec_strength (drbg->core->flags);
|
||||||
|
if (!entropylen)
|
||||||
|
return GPG_ERR_GENERAL;
|
||||||
|
if (0 == reseed)
|
||||||
|
- /* make sure we round up strength/2 in
|
||||||
|
- * case it is not divisible by 2 */
|
||||||
|
- entropylen = ((entropylen + 1) / 2) * 3;
|
||||||
|
+ {
|
||||||
|
+ nonce = 1;
|
||||||
|
+ }
|
||||||
|
dbg (("DRBG: (re)seeding with %lu bytes of entropy\n", entropylen));
|
||||||
|
- entropy = xcalloc_secure (1, entropylen);
|
||||||
|
+ entropy = xcalloc_secure (nonce + 1, entropylen);
|
||||||
|
if (!entropy)
|
||||||
|
return GPG_ERR_ENOMEM;
|
||||||
|
ret = drbg_get_entropy (drbg, entropy, entropylen);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
+ if (nonce)
|
||||||
|
+ {
|
||||||
|
+ ret = drbg_get_entropy (drbg, entropy + entropylen, entropylen);
|
||||||
|
+ if (ret)
|
||||||
|
+ goto out;
|
||||||
|
+ /* make sure we round up strength/2 in
|
||||||
|
+ * case it is not divisible by 2 */
|
||||||
|
+ entropylen = 2 * entropylen;
|
||||||
|
+ }
|
||||||
|
drbg_string_fill (&data1, entropy, entropylen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -1597,6 +1634,7 @@ drbg_instantiate (drbg_state_t drbg,
|
||||||
|
drbg->core = &drbg_cores[coreref];
|
||||||
|
drbg->pr = pr;
|
||||||
|
drbg->seeded = 0;
|
||||||
|
+ drbg->ent_primed = 0;
|
||||||
|
if (drbg->core->flags & DRBG_HMAC)
|
||||||
|
drbg->d_ops = &drbg_hmac_ops;
|
||||||
|
else if (drbg->core->flags & DRBG_HASH_MASK)
|
||||||
@ -1,101 +0,0 @@
|
|||||||
diff -up libgcrypt-1.8.3/random/random.c.getrandom libgcrypt-1.8.3/random/random.c
|
|
||||||
--- libgcrypt-1.8.3/random/random.c.getrandom 2017-11-23 19:16:58.000000000 +0100
|
|
||||||
+++ libgcrypt-1.8.3/random/random.c 2018-07-10 15:38:34.303855808 +0200
|
|
||||||
@@ -110,8 +110,8 @@ _gcry_random_read_conf (void)
|
|
||||||
unsigned int result = 0;
|
|
||||||
|
|
||||||
fp = fopen (fname, "r");
|
|
||||||
- if (!fp)
|
|
||||||
- return result;
|
|
||||||
+ if (!fp) /* We make only_urandom the default. */
|
|
||||||
+ return RANDOM_CONF_ONLY_URANDOM;
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
diff -up libgcrypt-1.8.3/random/random-csprng.c.getrandom libgcrypt-1.8.3/random/random-csprng.c
|
|
||||||
--- libgcrypt-1.8.3/random/random-csprng.c.getrandom 2017-11-23 19:16:58.000000000 +0100
|
|
||||||
+++ libgcrypt-1.8.3/random/random-csprng.c 2018-06-14 16:31:04.731179208 +0200
|
|
||||||
@@ -55,6 +55,10 @@
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
#include <process.h>
|
|
||||||
#endif
|
|
||||||
+#if defined(__linux__) && defined(HAVE_SYSCALL)
|
|
||||||
+# include <sys/syscall.h>
|
|
||||||
+# include <linux/random.h>
|
|
||||||
+#endif
|
|
||||||
#include "g10lib.h"
|
|
||||||
#include "random.h"
|
|
||||||
#include "rand-internal.h"
|
|
||||||
@@ -1116,6 +1120,22 @@ getfnc_gather_random (void))(void (*)(co
|
|
||||||
enum random_origins, size_t, int);
|
|
||||||
|
|
||||||
#if USE_RNDLINUX
|
|
||||||
+#if defined(__linux__) && defined(HAVE_SYSCALL) && defined(__NR_getrandom)
|
|
||||||
+ long ret;
|
|
||||||
+ char buffer[1];
|
|
||||||
+
|
|
||||||
+ _gcry_pre_syscall ();
|
|
||||||
+ ret = syscall (__NR_getrandom,
|
|
||||||
+ (void*)buffer, (size_t)1, (unsigned int)GRND_NONBLOCK);
|
|
||||||
+ _gcry_post_syscall ();
|
|
||||||
+ if (ret != -1 || errno != ENOSYS)
|
|
||||||
+ {
|
|
||||||
+ fnc = _gcry_rndlinux_gather_random;
|
|
||||||
+ return fnc;
|
|
||||||
+ }
|
|
||||||
+ else
|
|
||||||
+ /* The syscall is not supported - fallback to /dev/urandom. */
|
|
||||||
+#endif
|
|
||||||
if ( !access (NAME_OF_DEV_RANDOM, R_OK)
|
|
||||||
&& !access (NAME_OF_DEV_URANDOM, R_OK))
|
|
||||||
{
|
|
||||||
diff -up libgcrypt-1.8.3/random/rndlinux.c.getrandom libgcrypt-1.8.3/random/rndlinux.c
|
|
||||||
--- libgcrypt-1.8.3/random/rndlinux.c.getrandom 2018-06-14 16:31:04.722178971 +0200
|
|
||||||
+++ libgcrypt-1.8.3/random/rndlinux.c 2018-07-10 15:55:03.301075155 +0200
|
|
||||||
@@ -35,6 +35,7 @@
|
|
||||||
#include <poll.h>
|
|
||||||
#if defined(__linux__) && defined(HAVE_SYSCALL)
|
|
||||||
# include <sys/syscall.h>
|
|
||||||
+# include <linux/random.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "types.h"
|
|
||||||
@@ -204,6 +205,18 @@ _gcry_rndlinux_gather_random (void (*add
|
|
||||||
{
|
|
||||||
if (fd_urandom == -1)
|
|
||||||
{
|
|
||||||
+#if defined(__linux__) && defined(HAVE_SYSCALL) && defined(__NR_getrandom)
|
|
||||||
+ long ret;
|
|
||||||
+
|
|
||||||
+ _gcry_pre_syscall ();
|
|
||||||
+ ret = syscall (__NR_getrandom,
|
|
||||||
+ (void*)buffer, (size_t)1, (unsigned int)GRND_NONBLOCK);
|
|
||||||
+ _gcry_post_syscall ();
|
|
||||||
+ if (ret > -1 || errno == EAGAIN || errno == EINTR)
|
|
||||||
+ fd_urandom = -2;
|
|
||||||
+ else
|
|
||||||
+ /* The syscall is not supported - fallback to /dev/urandom. */
|
|
||||||
+#endif
|
|
||||||
fd_urandom = open_device (NAME_OF_DEV_URANDOM, (ever_opened & 2));
|
|
||||||
ever_opened |= 2;
|
|
||||||
}
|
|
||||||
@@ -230,7 +243,7 @@ _gcry_rndlinux_gather_random (void (*add
|
|
||||||
* syscall and not a new device and thus we are not able to use
|
|
||||||
* select(2) to have a timeout. */
|
|
||||||
#if defined(__linux__) && defined(HAVE_SYSCALL) && defined(__NR_getrandom)
|
|
||||||
- if (fd == fd_urandom)
|
|
||||||
+ if (fd == -2)
|
|
||||||
{
|
|
||||||
long ret;
|
|
||||||
size_t nbytes;
|
|
||||||
@@ -246,9 +259,7 @@ _gcry_rndlinux_gather_random (void (*add
|
|
||||||
_gcry_post_syscall ();
|
|
||||||
}
|
|
||||||
while (ret == -1 && errno == EINTR);
|
|
||||||
- if (ret == -1 && errno == ENOSYS)
|
|
||||||
- ; /* The syscall is not supported - fallback to /dev/urandom. */
|
|
||||||
- else
|
|
||||||
+ if (1)
|
|
||||||
{ /* The syscall is supported. Some sanity checks. */
|
|
||||||
if (ret == -1)
|
|
||||||
log_fatal ("unexpected error from getrandom: %s\n",
|
|
||||||
12
libgcrypt-1.8.3-md-fips-enforce.patch
Normal file
12
libgcrypt-1.8.3-md-fips-enforce.patch
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
diff -up libgcrypt-1.8.3/cipher/md.c.fips-enforce libgcrypt-1.8.3/cipher/md.c
|
||||||
|
--- libgcrypt-1.8.3/cipher/md.c.fips-enforce 2018-11-01 15:40:36.051865535 +0100
|
||||||
|
+++ libgcrypt-1.8.3/cipher/md.c 2019-06-03 11:50:21.435401753 +0200
|
||||||
|
@@ -409,7 +409,7 @@ md_enable (gcry_md_hd_t hd, int algorith
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- if (!err && algorithm == GCRY_MD_MD5 && fips_mode ())
|
||||||
|
+ if (!err && !spec->flags.fips && fips_mode ())
|
||||||
|
{
|
||||||
|
if (_gcry_enforced_fips_mode () )
|
||||||
|
{
|
||||||
Binary file not shown.
65
libgcrypt-1.8.4-fips-keygen.patch
Normal file
65
libgcrypt-1.8.4-fips-keygen.patch
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
diff -up libgcrypt-1.8.4/cipher/dsa.c.fips-keygen libgcrypt-1.8.4/cipher/dsa.c
|
||||||
|
--- libgcrypt-1.8.4/cipher/dsa.c.fips-keygen 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/cipher/dsa.c 2019-02-12 14:29:25.629513989 +0100
|
||||||
|
@@ -457,11 +457,22 @@ generate_fips186 (DSA_secret_key *sk, un
|
||||||
|
&prime_q, &prime_p,
|
||||||
|
r_counter,
|
||||||
|
r_seed, r_seedlen);
|
||||||
|
- else
|
||||||
|
- ec = _gcry_generate_fips186_3_prime (nbits, qbits, NULL, 0,
|
||||||
|
+ else if (!domain->p || !domain->q)
|
||||||
|
+ ec = _gcry_generate_fips186_3_prime (nbits, qbits,
|
||||||
|
+ initial_seed.seed,
|
||||||
|
+ initial_seed.seedlen,
|
||||||
|
&prime_q, &prime_p,
|
||||||
|
r_counter,
|
||||||
|
r_seed, r_seedlen, NULL);
|
||||||
|
+ else
|
||||||
|
+ {
|
||||||
|
+ /* Domain parameters p and q are given; use them. */
|
||||||
|
+ prime_p = mpi_copy (domain->p);
|
||||||
|
+ prime_q = mpi_copy (domain->q);
|
||||||
|
+ gcry_assert (mpi_get_nbits (prime_p) == nbits);
|
||||||
|
+ gcry_assert (mpi_get_nbits (prime_q) == qbits);
|
||||||
|
+ ec = 0;
|
||||||
|
+ }
|
||||||
|
sexp_release (initial_seed.sexp);
|
||||||
|
if (ec)
|
||||||
|
goto leave;
|
||||||
|
@@ -855,13 +866,12 @@ dsa_generate (const gcry_sexp_t genparms
|
||||||
|
sexp_release (l1);
|
||||||
|
sexp_release (domainsexp);
|
||||||
|
|
||||||
|
- /* Check that all domain parameters are available. */
|
||||||
|
- if (!domain.p || !domain.q || !domain.g)
|
||||||
|
+ /* Check that p and q domain parameters are available. */
|
||||||
|
+ if (!domain.p || !domain.q || (!domain.g && !(flags & PUBKEY_FLAG_USE_FIPS186)))
|
||||||
|
{
|
||||||
|
_gcry_mpi_release (domain.p);
|
||||||
|
_gcry_mpi_release (domain.q);
|
||||||
|
_gcry_mpi_release (domain.g);
|
||||||
|
- sexp_release (deriveparms);
|
||||||
|
return GPG_ERR_MISSING_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
diff -up libgcrypt-1.8.4/cipher/rsa.c.fips-keygen libgcrypt-1.8.4/cipher/rsa.c
|
||||||
|
--- libgcrypt-1.8.4/cipher/rsa.c.fips-keygen 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/cipher/rsa.c 2019-02-12 14:29:25.630513971 +0100
|
||||||
|
@@ -389,7 +389,7 @@ generate_fips (RSA_secret_key *sk, unsig
|
||||||
|
|
||||||
|
if (nbits < 1024 || (nbits & 0x1FF))
|
||||||
|
return GPG_ERR_INV_VALUE;
|
||||||
|
- if (_gcry_enforced_fips_mode() && nbits != 2048 && nbits != 3072)
|
||||||
|
+ if (fips_mode() && nbits < 2048)
|
||||||
|
return GPG_ERR_INV_VALUE;
|
||||||
|
|
||||||
|
/* The random quality depends on the transient_key flag. */
|
||||||
|
@@ -696,7 +696,7 @@ generate_x931 (RSA_secret_key *sk, unsig
|
||||||
|
|
||||||
|
*swapped = 0;
|
||||||
|
|
||||||
|
- if (e_value == 1) /* Alias for a secure value. */
|
||||||
|
+ if (e_value == 1 || e_value == 0) /* Alias for a secure value. */
|
||||||
|
e_value = 65537;
|
||||||
|
|
||||||
|
/* Point 1 of section 4.1: k = 1024 + 256s with S >= 0 */
|
||||||
134
libgcrypt-1.8.4-getrandom.patch
Normal file
134
libgcrypt-1.8.4-getrandom.patch
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
diff -up libgcrypt-1.8.4/random/random.c.getrandom libgcrypt-1.8.4/random/random.c
|
||||||
|
--- libgcrypt-1.8.4/random/random.c.getrandom 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/random/random.c 2018-11-20 15:52:41.738708554 +0100
|
||||||
|
@@ -110,8 +110,8 @@ _gcry_random_read_conf (void)
|
||||||
|
unsigned int result = 0;
|
||||||
|
|
||||||
|
fp = fopen (fname, "r");
|
||||||
|
- if (!fp)
|
||||||
|
- return result;
|
||||||
|
+ if (!fp) /* We make only_urandom the default. */
|
||||||
|
+ return RANDOM_CONF_ONLY_URANDOM;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
diff -up libgcrypt-1.8.4/random/random-csprng.c.getrandom libgcrypt-1.8.4/random/random-csprng.c
|
||||||
|
--- libgcrypt-1.8.4/random/random-csprng.c.getrandom 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/random/random-csprng.c 2018-11-20 15:52:41.738708554 +0100
|
||||||
|
@@ -55,6 +55,10 @@
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#include <process.h>
|
||||||
|
#endif
|
||||||
|
+#if defined(__linux__) && defined(HAVE_SYSCALL)
|
||||||
|
+# include <sys/syscall.h>
|
||||||
|
+# include <linux/random.h>
|
||||||
|
+#endif
|
||||||
|
#include "g10lib.h"
|
||||||
|
#include "random.h"
|
||||||
|
#include "rand-internal.h"
|
||||||
|
@@ -1116,6 +1120,22 @@ getfnc_gather_random (void))(void (*)(co
|
||||||
|
enum random_origins, size_t, int);
|
||||||
|
|
||||||
|
#if USE_RNDLINUX
|
||||||
|
+#if defined(__linux__) && defined(HAVE_SYSCALL) && defined(__NR_getrandom)
|
||||||
|
+ long ret;
|
||||||
|
+ char buffer[1];
|
||||||
|
+
|
||||||
|
+ _gcry_pre_syscall ();
|
||||||
|
+ ret = syscall (__NR_getrandom,
|
||||||
|
+ (void*)buffer, (size_t)1, (unsigned int)GRND_NONBLOCK);
|
||||||
|
+ _gcry_post_syscall ();
|
||||||
|
+ if (ret != -1 || errno != ENOSYS)
|
||||||
|
+ {
|
||||||
|
+ fnc = _gcry_rndlinux_gather_random;
|
||||||
|
+ return fnc;
|
||||||
|
+ }
|
||||||
|
+ else
|
||||||
|
+ /* The syscall is not supported - fallback to /dev/urandom. */
|
||||||
|
+#endif
|
||||||
|
if ( !access (NAME_OF_DEV_RANDOM, R_OK)
|
||||||
|
&& !access (NAME_OF_DEV_URANDOM, R_OK))
|
||||||
|
{
|
||||||
|
diff -up libgcrypt-1.8.4/random/rndlinux.c.getrandom libgcrypt-1.8.4/random/rndlinux.c
|
||||||
|
--- libgcrypt-1.8.4/random/rndlinux.c.getrandom 2018-11-20 15:52:41.731708393 +0100
|
||||||
|
+++ libgcrypt-1.8.4/random/rndlinux.c 2018-11-20 16:06:45.431207374 +0100
|
||||||
|
@@ -35,6 +35,7 @@
|
||||||
|
#include <poll.h>
|
||||||
|
#if defined(__linux__) && defined(HAVE_SYSCALL)
|
||||||
|
# include <sys/syscall.h>
|
||||||
|
+# include <linux/random.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
@@ -147,12 +148,12 @@ _gcry_rndlinux_gather_random (void (*add
|
||||||
|
if (!add)
|
||||||
|
{
|
||||||
|
/* Special mode to close the descriptors. */
|
||||||
|
- if (fd_random != -1)
|
||||||
|
+ if (fd_random >= 0)
|
||||||
|
{
|
||||||
|
close (fd_random);
|
||||||
|
fd_random = -1;
|
||||||
|
}
|
||||||
|
- if (fd_urandom != -1)
|
||||||
|
+ if (fd_urandom >= 0)
|
||||||
|
{
|
||||||
|
close (fd_urandom);
|
||||||
|
fd_urandom = -1;
|
||||||
|
@@ -166,12 +167,12 @@ _gcry_rndlinux_gather_random (void (*add
|
||||||
|
apid = getpid ();
|
||||||
|
if (my_pid != apid)
|
||||||
|
{
|
||||||
|
- if (fd_random != -1)
|
||||||
|
+ if (fd_random >= 0)
|
||||||
|
{
|
||||||
|
close (fd_random);
|
||||||
|
fd_random = -1;
|
||||||
|
}
|
||||||
|
- if (fd_urandom != -1)
|
||||||
|
+ if (fd_urandom >= 0)
|
||||||
|
{
|
||||||
|
close (fd_urandom);
|
||||||
|
fd_urandom = -1;
|
||||||
|
@@ -216,6 +217,22 @@ _gcry_rndlinux_gather_random (void (*add
|
||||||
|
that we always require the device to be existent but want a more
|
||||||
|
graceful behaviour if the rarely needed close operation has been
|
||||||
|
used and the device needs to be re-opened later. */
|
||||||
|
+#if defined(__linux__) && defined(HAVE_SYSCALL) && defined(__NR_getrandom)
|
||||||
|
+ if (fd_urandom != -2)
|
||||||
|
+ {
|
||||||
|
+ long ret;
|
||||||
|
+
|
||||||
|
+ _gcry_pre_syscall ();
|
||||||
|
+ ret = syscall (__NR_getrandom,
|
||||||
|
+ (void*)buffer, (size_t)1, (unsigned int)GRND_NONBLOCK);
|
||||||
|
+ _gcry_post_syscall ();
|
||||||
|
+ if (ret > -1 || errno == EAGAIN || errno == EINTR)
|
||||||
|
+ {
|
||||||
|
+ fd_urandom = -2;
|
||||||
|
+ fd_random = -2;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+#endif
|
||||||
|
if (level >= GCRY_VERY_STRONG_RANDOM && !only_urandom)
|
||||||
|
{
|
||||||
|
if (fd_random == -1)
|
||||||
|
@@ -255,6 +272,7 @@ _gcry_rndlinux_gather_random (void (*add
|
||||||
|
* syscall and not a new device and thus we are not able to use
|
||||||
|
* select(2) to have a timeout. */
|
||||||
|
#if defined(__linux__) && defined(HAVE_SYSCALL) && defined(__NR_getrandom)
|
||||||
|
+ if (fd == -2)
|
||||||
|
{
|
||||||
|
long ret;
|
||||||
|
size_t nbytes;
|
||||||
|
@@ -270,9 +288,7 @@ _gcry_rndlinux_gather_random (void (*add
|
||||||
|
_gcry_post_syscall ();
|
||||||
|
}
|
||||||
|
while (ret == -1 && errno == EINTR);
|
||||||
|
- if (ret == -1 && errno == ENOSYS)
|
||||||
|
- ; /* The syscall is not supported - fallback to pulling from fd. */
|
||||||
|
- else
|
||||||
|
+ if (1)
|
||||||
|
{ /* The syscall is supported. Some sanity checks. */
|
||||||
|
if (ret == -1)
|
||||||
|
log_fatal ("unexpected error from getrandom: %s\n",
|
||||||
184
libgcrypt-1.8.4-tests-fipsmode.patch
Normal file
184
libgcrypt-1.8.4-tests-fipsmode.patch
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
diff -up libgcrypt-1.8.4/tests/basic.c.tests-fipsmode libgcrypt-1.8.4/tests/basic.c
|
||||||
|
--- libgcrypt-1.8.4/tests/basic.c.tests-fipsmode 2018-04-17 17:29:40.000000000 +0200
|
||||||
|
+++ libgcrypt-1.8.4/tests/basic.c 2019-02-12 13:30:48.935791024 +0100
|
||||||
|
@@ -6964,7 +6964,7 @@ check_ciphers (void)
|
||||||
|
check_one_cipher (algos[i], GCRY_CIPHER_MODE_CTR, 0);
|
||||||
|
if (gcry_cipher_get_algo_blklen (algos[i]) == GCRY_CCM_BLOCK_LEN)
|
||||||
|
check_one_cipher (algos[i], GCRY_CIPHER_MODE_CCM, 0);
|
||||||
|
- if (gcry_cipher_get_algo_blklen (algos[i]) == GCRY_GCM_BLOCK_LEN)
|
||||||
|
+ if (!in_fips_mode && gcry_cipher_get_algo_blklen (algos[i]) == GCRY_GCM_BLOCK_LEN)
|
||||||
|
check_one_cipher (algos[i], GCRY_CIPHER_MODE_GCM, 0);
|
||||||
|
if (gcry_cipher_get_algo_blklen (algos[i]) == GCRY_OCB_BLOCK_LEN)
|
||||||
|
check_one_cipher (algos[i], GCRY_CIPHER_MODE_OCB, 0);
|
||||||
|
@@ -7010,11 +7010,17 @@ check_cipher_modes(void)
|
||||||
|
check_cfb_cipher ();
|
||||||
|
check_ofb_cipher ();
|
||||||
|
check_ccm_cipher ();
|
||||||
|
- check_gcm_cipher ();
|
||||||
|
- check_poly1305_cipher ();
|
||||||
|
- check_ocb_cipher ();
|
||||||
|
+ if (!in_fips_mode)
|
||||||
|
+ {
|
||||||
|
+ check_gcm_cipher ();
|
||||||
|
+ check_poly1305_cipher ();
|
||||||
|
+ check_ocb_cipher ();
|
||||||
|
+ }
|
||||||
|
check_xts_cipher ();
|
||||||
|
- check_gost28147_cipher ();
|
||||||
|
+ if (!in_fips_mode)
|
||||||
|
+ {
|
||||||
|
+ check_gost28147_cipher ();
|
||||||
|
+ }
|
||||||
|
check_stream_cipher ();
|
||||||
|
check_stream_cipher_large_block ();
|
||||||
|
|
||||||
|
@@ -10001,7 +10007,7 @@ check_mac (void)
|
||||||
|
show_mac_not_available (algos[i].algo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
- if (gcry_mac_test_algo (algos[i].algo) && in_fips_mode)
|
||||||
|
+ if ((algos[i].algo == GCRY_MAC_GMAC_AES || gcry_mac_test_algo (algos[i].algo)) && in_fips_mode)
|
||||||
|
{
|
||||||
|
if (verbose)
|
||||||
|
fprintf (stderr, " algorithm %d not available in fips mode\n",
|
||||||
|
@@ -11095,8 +11101,6 @@ main (int argc, char **argv)
|
||||||
|
/* If we are in fips mode do some more tests. */
|
||||||
|
gcry_md_hd_t md;
|
||||||
|
|
||||||
|
- /* First trigger a self-test. */
|
||||||
|
- xgcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
|
||||||
|
if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0))
|
||||||
|
fail ("not in operational state after self-test\n");
|
||||||
|
|
||||||
|
@@ -11121,15 +11125,6 @@ main (int argc, char **argv)
|
||||||
|
gcry_md_close (md);
|
||||||
|
if (gcry_control (GCRYCTL_OPERATIONAL_P, 0))
|
||||||
|
fail ("expected error state but still in operational state\n");
|
||||||
|
- else
|
||||||
|
- {
|
||||||
|
- /* Now run a self-test and to get back into
|
||||||
|
- operational state. */
|
||||||
|
- xgcry_control (GCRYCTL_FORCE_FIPS_MODE, 0);
|
||||||
|
- if (!gcry_control (GCRYCTL_OPERATIONAL_P, 0))
|
||||||
|
- fail ("did not reach operational after error "
|
||||||
|
- "and self-test\n");
|
||||||
|
- }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diff -up libgcrypt-1.8.4/tests/benchmark.c.tests-fipsmode libgcrypt-1.8.4/tests/benchmark.c
|
||||||
|
--- libgcrypt-1.8.4/tests/benchmark.c.tests-fipsmode 2019-02-12 11:31:44.859603883 +0100
|
||||||
|
+++ libgcrypt-1.8.4/tests/benchmark.c 2019-02-12 14:10:40.271999352 +0100
|
||||||
|
@@ -872,8 +872,10 @@ cipher_bench ( const char *algoname )
|
||||||
|
|| (blklen == 1 && modes[modeidx].mode != GCRY_CIPHER_MODE_STREAM))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
- if (modes[modeidx].req_blocksize > 0
|
||||||
|
- && blklen != modes[modeidx].req_blocksize)
|
||||||
|
+ if ((modes[modeidx].req_blocksize > 0
|
||||||
|
+ && blklen != modes[modeidx].req_blocksize)
|
||||||
|
+ || (in_fips_mode
|
||||||
|
+ && modes[modeidx].mode == GCRY_CIPHER_MODE_GCM))
|
||||||
|
{
|
||||||
|
printf (" %7s %7s", "-", "-" );
|
||||||
|
continue;
|
||||||
|
diff -up libgcrypt-1.8.4/tests/bench-slope.c.tests-fipsmode libgcrypt-1.8.4/tests/bench-slope.c
|
||||||
|
--- libgcrypt-1.8.4/tests/bench-slope.c.tests-fipsmode 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/tests/bench-slope.c 2019-02-12 14:14:33.618763325 +0100
|
||||||
|
@@ -1338,7 +1338,7 @@ cipher_bench_one (int algo, struct bench
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* GCM has restrictions for block-size */
|
||||||
|
- if (mode.mode == GCRY_CIPHER_MODE_GCM && blklen != GCRY_GCM_BLOCK_LEN)
|
||||||
|
+ if (mode.mode == GCRY_CIPHER_MODE_GCM && (gcry_fips_mode_active () || blklen != GCRY_GCM_BLOCK_LEN))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* XTS has restrictions for block-size */
|
||||||
|
diff -up libgcrypt-1.8.4/tests/pubkey.c.tests-fipsmode libgcrypt-1.8.4/tests/pubkey.c
|
||||||
|
--- libgcrypt-1.8.4/tests/pubkey.c.tests-fipsmode 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/tests/pubkey.c 2019-02-12 13:52:25.658746415 +0100
|
||||||
|
@@ -504,15 +504,30 @@ get_dsa_key_with_domain_new (gcry_sexp_t
|
||||||
|
rc = gcry_sexp_new
|
||||||
|
(&key_spec,
|
||||||
|
"(genkey (dsa (transient-key)(domain"
|
||||||
|
- "(p #d3aed1876054db831d0c1348fbb1ada72507e5fbf9a62cbd47a63aeb7859d6921"
|
||||||
|
- "4adeb9146a6ec3f43520f0fd8e3125dd8bbc5d87405d1ac5f82073cd762a3f8d7"
|
||||||
|
- "74322657c9da88a7d2f0e1a9ceb84a39cb40876179e6a76e400498de4bb9379b0"
|
||||||
|
- "5f5feb7b91eb8fea97ee17a955a0a8a37587a272c4719d6feb6b54ba4ab69#)"
|
||||||
|
- "(q #9c916d121de9a03f71fb21bc2e1c0d116f065a4f#)"
|
||||||
|
- "(g #8157c5f68ca40b3ded11c353327ab9b8af3e186dd2e8dade98761a0996dda99ab"
|
||||||
|
- "0250d3409063ad99efae48b10c6ab2bba3ea9a67b12b911a372a2bba260176fad"
|
||||||
|
- "b4b93247d9712aad13aa70216c55da9858f7a298deb670a403eb1e7c91b847f1e"
|
||||||
|
- "ccfbd14bd806fd42cf45dbb69cd6d6b43add2a78f7d16928eaa04458dea44#)"
|
||||||
|
+ " (p #a85378d8fd3f8d72ec7418080da21317e43ec4b62ba8c862"
|
||||||
|
+ " 3b7e4d04441dd1a0658662596493ca8e9e8fbb7e34aaddb6"
|
||||||
|
+ " 2e5d67b6d09a6e61b769e7c352aa2b10e20ca0636963b552"
|
||||||
|
+ " 3e86470decbbeda027e797e7b67635d4d49c30700e74af8a"
|
||||||
|
+ " 0ff156a801af57a26e7078f1d82f74908ecb6d07e70b3503"
|
||||||
|
+ " eed94fa32cf17a7fc3d6cf40dc7b00830e6a2566dc073e34"
|
||||||
|
+ " 3312517c6aa5152b4bfecd2e551fee346318a153423c996b"
|
||||||
|
+ " 0d5dcb9102aedd38798616f1f1e0d6c403525b1f9b3d4dc7"
|
||||||
|
+ " 66de2dfc4a56d7b8ba5963d60f3e16318870ad436952e557"
|
||||||
|
+ " 65374eab85e8ec17d6b9a4547b9b5f2752f3105be809b23a"
|
||||||
|
+ " 2c8d7469db02e24d592394a7dba069e9#)"
|
||||||
|
+ " (q #d277044e50f5a4e3f510a50a0b84fdffbca047ed27602056"
|
||||||
|
+ " 7441a0a5#)"
|
||||||
|
+ " (g #13d754e21fd241655da891c522a65a72a89bdc64ec9b54a8"
|
||||||
|
+ " 21ed4a898b490e0c4fcb72192a4a20f541f3f2925399f0ba"
|
||||||
|
+ " ecf929aafbf79dfe4332393b32cd2e2fcf272f32a627434a"
|
||||||
|
+ " 0df242b75b414df372121e53a553f222f836b000f016485b"
|
||||||
|
+ " 6bd0898451801dcd8de64cd5365696ffc532d528c506620a"
|
||||||
|
+ " 942a0305046d8f1876341f1e570bc3974ba6b9a438e97023"
|
||||||
|
+ " 02a2e6e67bfd06d32bc679962271d7b40cd72f386e64e0d7"
|
||||||
|
+ " ef86ca8ca5d14228dc2a4f16e3189886b5990674f4200f3a"
|
||||||
|
+ " 4cf65a3f0ddba1fa672dff2f5e143d10e4e97ae84f6da095"
|
||||||
|
+ " 35d5b9df259181a79b63b069e949972b02ba36b3586aab7e"
|
||||||
|
+ " 45f322f82e4e85ca3ab85591b3c2a966#)"
|
||||||
|
")))", 0, 1);
|
||||||
|
if (rc)
|
||||||
|
die ("error creating S-expression: %s\n", gcry_strerror (rc));
|
||||||
|
@@ -595,7 +610,7 @@ get_dsa_key_fips186_with_seed_new (gcry_
|
||||||
|
" (use-fips186)"
|
||||||
|
" (transient-key)"
|
||||||
|
" (derive-parms"
|
||||||
|
- " (seed #0cb1990c1fd3626055d7a0096f8fa99807399871#))))",
|
||||||
|
+ " (seed #8b4c4d671fff82e8ed932260206d0571e3a1c2cee8cd94cb73fe58f9b67488fa#))))",
|
||||||
|
0, 1);
|
||||||
|
if (rc)
|
||||||
|
die ("error creating S-expression: %s\n", gcry_strerror (rc));
|
||||||
|
diff -up libgcrypt-1.8.4/tests/t-cv25519.c.tests-fipsmode libgcrypt-1.8.4/tests/t-cv25519.c
|
||||||
|
--- libgcrypt-1.8.4/tests/t-cv25519.c.tests-fipsmode 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/tests/t-cv25519.c 2019-02-12 14:02:35.935705390 +0100
|
||||||
|
@@ -560,6 +560,9 @@ main (int argc, char **argv)
|
||||||
|
xgcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
|
||||||
|
xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
|
||||||
|
xgcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||||
|
+ /* Curve25519 isn't supported in fips mode */
|
||||||
|
+ if (gcry_fips_mode_active())
|
||||||
|
+ return 77;
|
||||||
|
|
||||||
|
start_timer ();
|
||||||
|
check_cv25519 ();
|
||||||
|
diff -up libgcrypt-1.8.4/tests/t-secmem.c.tests-fipsmode libgcrypt-1.8.4/tests/t-secmem.c
|
||||||
|
--- libgcrypt-1.8.4/tests/t-secmem.c.tests-fipsmode 2017-11-23 19:19:54.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.4/tests/t-secmem.c 2019-02-12 11:51:02.462190538 +0100
|
||||||
|
@@ -174,7 +174,8 @@ main (int argc, char **argv)
|
||||||
|
xgcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
|
||||||
|
xgcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
|
||||||
|
xgcry_control (GCRYCTL_INIT_SECMEM, pool_size, 0);
|
||||||
|
- gcry_set_outofcore_handler (outofcore_handler, NULL);
|
||||||
|
+ if (!gcry_fips_mode_active ())
|
||||||
|
+ gcry_set_outofcore_handler (outofcore_handler, NULL);
|
||||||
|
xgcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
|
||||||
|
|
||||||
|
/* Libgcrypt prints a warning when the first overflow is allocated;
|
||||||
|
@@ -184,7 +185,8 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
|
test_secmem ();
|
||||||
|
- test_secmem_overflow ();
|
||||||
|
+ if (!gcry_fips_mode_active ())
|
||||||
|
+ test_secmem_overflow ();
|
||||||
|
/* FIXME: We need to improve the tests, for example by registering
|
||||||
|
* our own log handler and comparing the output of
|
||||||
|
* PRIV_CTL_DUMP_SECMEM_STATS to expected pattern. */
|
||||||
@ -1,6 +1,6 @@
|
|||||||
diff -up libgcrypt-1.8.0/random/rndlinux.c.use-poll libgcrypt-1.8.0/random/rndlinux.c
|
diff -up libgcrypt-1.8.4/random/rndlinux.c.use-poll libgcrypt-1.8.4/random/rndlinux.c
|
||||||
--- libgcrypt-1.8.0/random/rndlinux.c.use-poll 2017-06-24 13:34:29.000000000 +0200
|
--- libgcrypt-1.8.4/random/rndlinux.c.use-poll 2018-10-26 13:50:20.000000000 +0200
|
||||||
+++ libgcrypt-1.8.0/random/rndlinux.c 2017-08-15 15:37:37.604629377 +0200
|
+++ libgcrypt-1.8.4/random/rndlinux.c 2018-11-20 15:51:56.760669058 +0100
|
||||||
@@ -32,6 +32,7 @@
|
@@ -32,6 +32,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -9,7 +9,7 @@ diff -up libgcrypt-1.8.0/random/rndlinux.c.use-poll libgcrypt-1.8.0/random/rndli
|
|||||||
#if defined(__linux__) && defined(HAVE_SYSCALL)
|
#if defined(__linux__) && defined(HAVE_SYSCALL)
|
||||||
# include <sys/syscall.h>
|
# include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -216,9 +217,8 @@ _gcry_rndlinux_gather_random (void (*add
|
@@ -241,9 +242,8 @@ _gcry_rndlinux_gather_random (void (*add
|
||||||
return with something we will actually use 100ms. */
|
return with something we will actually use 100ms. */
|
||||||
while (length)
|
while (length)
|
||||||
{
|
{
|
||||||
@ -18,9 +18,9 @@ diff -up libgcrypt-1.8.0/random/rndlinux.c.use-poll libgcrypt-1.8.0/random/rndli
|
|||||||
int rc;
|
int rc;
|
||||||
+ struct pollfd pfd;
|
+ struct pollfd pfd;
|
||||||
|
|
||||||
/* If we have a modern Linux kernel and we want to read from the
|
/* If we have a modern Linux kernel, we first try to use the new
|
||||||
* the non-blocking /dev/urandom, we first try to use the new
|
* getrandom syscall. That call guarantees that the kernel's
|
||||||
@@ -276,36 +276,25 @@ _gcry_rndlinux_gather_random (void (*add
|
@@ -300,36 +300,25 @@ _gcry_rndlinux_gather_random (void (*add
|
||||||
any_need_entropy = 1;
|
any_need_entropy = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
14
libgcrypt-1.8.5-build.patch
Normal file
14
libgcrypt-1.8.5-build.patch
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
diff -up libgcrypt-1.8.5/cipher/poly1305-armv7-neon.S.build libgcrypt-1.8.5/cipher/poly1305-armv7-neon.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/poly1305-armv7-neon.S.build 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/poly1305-armv7-neon.S 2020-01-30 17:26:12.026404286 +0100
|
||||||
|
@@ -87,9 +87,8 @@ _gcry_poly1305_armv7_neon_init_ext:
|
||||||
|
.Lpoly1305_init_ext_neon_local:
|
||||||
|
stmfd sp!, {r4-r11, lr}
|
||||||
|
sub sp, sp, #32
|
||||||
|
- mov r14, r2
|
||||||
|
+ mov r14, #-1
|
||||||
|
and r2, r2, r2
|
||||||
|
- moveq r14, #-1
|
||||||
|
UNALIGNED_LDMIA4(r1, r2, r3, r4, r5)
|
||||||
|
GET_DATA_POINTER(r7,.Lpoly1305_init_constants_neon,r8)
|
||||||
|
mov r6, r2
|
||||||
348
libgcrypt-1.8.5-intel-cet.patch
Normal file
348
libgcrypt-1.8.5-intel-cet.patch
Normal file
@ -0,0 +1,348 @@
|
|||||||
|
diff -up libgcrypt-1.8.5/cipher/camellia-aesni-avx2-amd64.S.intel-cet libgcrypt-1.8.5/cipher/camellia-aesni-avx2-amd64.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/camellia-aesni-avx2-amd64.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/camellia-aesni-avx2-amd64.S 2020-01-23 15:36:44.148972045 +0100
|
||||||
|
@@ -18,8 +18,9 @@
|
||||||
|
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
-#ifdef __x86_64
|
||||||
|
#include <config.h>
|
||||||
|
+
|
||||||
|
+#ifdef __x86_64
|
||||||
|
#if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \
|
||||||
|
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && \
|
||||||
|
defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX2_SUPPORT)
|
||||||
|
diff -up libgcrypt-1.8.5/cipher/camellia-aesni-avx-amd64.S.intel-cet libgcrypt-1.8.5/cipher/camellia-aesni-avx-amd64.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/camellia-aesni-avx-amd64.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/camellia-aesni-avx-amd64.S 2020-01-23 15:36:44.145972088 +0100
|
||||||
|
@@ -18,8 +18,9 @@
|
||||||
|
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
-#ifdef __x86_64
|
||||||
|
#include <config.h>
|
||||||
|
+
|
||||||
|
+#ifdef __x86_64
|
||||||
|
#if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \
|
||||||
|
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && \
|
||||||
|
defined(ENABLE_AESNI_SUPPORT) && defined(ENABLE_AVX_SUPPORT)
|
||||||
|
diff -up libgcrypt-1.8.5/cipher/chacha20-avx2-amd64.S.intel-cet libgcrypt-1.8.5/cipher/chacha20-avx2-amd64.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/chacha20-avx2-amd64.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/chacha20-avx2-amd64.S 2020-01-23 15:36:16.780250066 +0100
|
||||||
|
@@ -48,6 +48,9 @@
|
||||||
|
.globl _gcry_chacha20_amd64_avx2_blocks
|
||||||
|
ELF(.type _gcry_chacha20_amd64_avx2_blocks,@function;)
|
||||||
|
_gcry_chacha20_amd64_avx2_blocks:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lchacha_blocks_avx2_local:
|
||||||
|
vzeroupper
|
||||||
|
pushq %rbx
|
||||||
|
diff -up libgcrypt-1.8.5/cipher/chacha20-sse2-amd64.S.intel-cet libgcrypt-1.8.5/cipher/chacha20-sse2-amd64.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/chacha20-sse2-amd64.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/chacha20-sse2-amd64.S 2020-01-23 15:36:16.783250095 +0100
|
||||||
|
@@ -41,6 +41,9 @@
|
||||||
|
.globl _gcry_chacha20_amd64_sse2_blocks
|
||||||
|
ELF(.type _gcry_chacha20_amd64_sse2_blocks,@function;)
|
||||||
|
_gcry_chacha20_amd64_sse2_blocks:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lchacha_blocks_sse2_local:
|
||||||
|
pushq %rbx
|
||||||
|
pushq %rbp
|
||||||
|
diff -up libgcrypt-1.8.5/cipher/poly1305-avx2-amd64.S.intel-cet libgcrypt-1.8.5/cipher/poly1305-avx2-amd64.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/poly1305-avx2-amd64.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/poly1305-avx2-amd64.S 2020-01-23 15:36:16.784250105 +0100
|
||||||
|
@@ -43,6 +43,9 @@
|
||||||
|
.globl _gcry_poly1305_amd64_avx2_init_ext
|
||||||
|
ELF(.type _gcry_poly1305_amd64_avx2_init_ext,@function;)
|
||||||
|
_gcry_poly1305_amd64_avx2_init_ext:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lpoly1305_init_ext_avx2_local:
|
||||||
|
xor %edx, %edx
|
||||||
|
vzeroupper
|
||||||
|
@@ -406,6 +409,9 @@ ELF(.size _gcry_poly1305_amd64_avx2_init
|
||||||
|
.globl _gcry_poly1305_amd64_avx2_blocks
|
||||||
|
ELF(.type _gcry_poly1305_amd64_avx2_blocks,@function;)
|
||||||
|
_gcry_poly1305_amd64_avx2_blocks:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lpoly1305_blocks_avx2_local:
|
||||||
|
vzeroupper
|
||||||
|
pushq %rbp
|
||||||
|
@@ -732,6 +738,9 @@ ELF(.size _gcry_poly1305_amd64_avx2_bloc
|
||||||
|
.globl _gcry_poly1305_amd64_avx2_finish_ext
|
||||||
|
ELF(.type _gcry_poly1305_amd64_avx2_finish_ext,@function;)
|
||||||
|
_gcry_poly1305_amd64_avx2_finish_ext:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lpoly1305_finish_ext_avx2_local:
|
||||||
|
vzeroupper
|
||||||
|
pushq %rbp
|
||||||
|
diff -up libgcrypt-1.8.5/cipher/poly1305-sse2-amd64.S.intel-cet libgcrypt-1.8.5/cipher/poly1305-sse2-amd64.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/poly1305-sse2-amd64.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/poly1305-sse2-amd64.S 2020-01-23 15:36:16.787250134 +0100
|
||||||
|
@@ -42,6 +42,9 @@
|
||||||
|
.globl _gcry_poly1305_amd64_sse2_init_ext
|
||||||
|
ELF(.type _gcry_poly1305_amd64_sse2_init_ext,@function;)
|
||||||
|
_gcry_poly1305_amd64_sse2_init_ext:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lpoly1305_init_ext_x86_local:
|
||||||
|
xor %edx, %edx
|
||||||
|
pushq %r12
|
||||||
|
@@ -288,6 +291,9 @@ ELF(.size _gcry_poly1305_amd64_sse2_init
|
||||||
|
.globl _gcry_poly1305_amd64_sse2_finish_ext
|
||||||
|
ELF(.type _gcry_poly1305_amd64_sse2_finish_ext,@function;)
|
||||||
|
_gcry_poly1305_amd64_sse2_finish_ext:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lpoly1305_finish_ext_x86_local:
|
||||||
|
pushq %rbp
|
||||||
|
movq %rsp, %rbp
|
||||||
|
@@ -439,6 +445,9 @@ ELF(.size _gcry_poly1305_amd64_sse2_fini
|
||||||
|
.globl _gcry_poly1305_amd64_sse2_blocks
|
||||||
|
ELF(.type _gcry_poly1305_amd64_sse2_blocks,@function;)
|
||||||
|
_gcry_poly1305_amd64_sse2_blocks:
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
.Lpoly1305_blocks_x86_local:
|
||||||
|
pushq %rbp
|
||||||
|
movq %rsp, %rbp
|
||||||
|
diff -up libgcrypt-1.8.5/cipher/serpent-avx2-amd64.S.intel-cet libgcrypt-1.8.5/cipher/serpent-avx2-amd64.S
|
||||||
|
--- libgcrypt-1.8.5/cipher/serpent-avx2-amd64.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/cipher/serpent-avx2-amd64.S 2020-01-23 15:36:44.151972003 +0100
|
||||||
|
@@ -18,8 +18,9 @@
|
||||||
|
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
-#ifdef __x86_64
|
||||||
|
#include <config.h>
|
||||||
|
+
|
||||||
|
+#ifdef __x86_64
|
||||||
|
#if (defined(HAVE_COMPATIBLE_GCC_AMD64_PLATFORM_AS) || \
|
||||||
|
defined(HAVE_COMPATIBLE_GCC_WIN64_PLATFORM_AS)) && defined(USE_SERPENT) && \
|
||||||
|
defined(ENABLE_AVX2_SUPPORT)
|
||||||
|
diff -up libgcrypt-1.8.5/configure.ac.intel-cet libgcrypt-1.8.5/configure.ac
|
||||||
|
--- libgcrypt-1.8.5/configure.ac.intel-cet 2019-08-29 15:00:08.000000000 +0200
|
||||||
|
+++ libgcrypt-1.8.5/configure.ac 2020-01-23 15:35:28.147774463 +0100
|
||||||
|
@@ -95,6 +95,12 @@ AH_TOP([
|
||||||
|
AH_BOTTOM([
|
||||||
|
#define _GCRYPT_IN_LIBGCRYPT 1
|
||||||
|
|
||||||
|
+/* Add .note.gnu.property section for Intel CET in assembler sources
|
||||||
|
+ when CET is enabled. */
|
||||||
|
+#if defined(__ASSEMBLER__) && defined(__CET__)
|
||||||
|
+# include <cet.h>
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
/* If the configure check for endianness has been disabled, get it from
|
||||||
|
OS macros. This is intended for making fat binary builds on OS X. */
|
||||||
|
#ifdef DISABLED_ENDIAN_CHECK
|
||||||
|
diff -up libgcrypt-1.8.5/mpi/config.links.intel-cet libgcrypt-1.8.5/mpi/config.links
|
||||||
|
--- libgcrypt-1.8.5/mpi/config.links.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/mpi/config.links 2020-01-23 15:35:46.398952954 +0100
|
||||||
|
@@ -382,6 +382,16 @@ if test x"$mpi_cpu_arch" = x ; then
|
||||||
|
mpi_cpu_arch="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
+# Add .note.gnu.property section for Intel CET in assembler sources
|
||||||
|
+# when CET is enabled. */
|
||||||
|
+if test x"$mpi_cpu_arch" = xx86 ; then
|
||||||
|
+ cat <<EOF >> ./mpi/asm-syntax.h
|
||||||
|
+
|
||||||
|
+#if defined(__ASSEMBLER__) && defined(__CET__)
|
||||||
|
+# include <cet.h>
|
||||||
|
+#endif
|
||||||
|
+EOF
|
||||||
|
+fi
|
||||||
|
|
||||||
|
# Make sysdep.h
|
||||||
|
echo '/* created by config.links - do not edit */' >./mpi/sysdep.h
|
||||||
|
diff -up libgcrypt-1.8.5/mpi/i386/mpih-add1.S.intel-cet libgcrypt-1.8.5/mpi/i386/mpih-add1.S
|
||||||
|
--- libgcrypt-1.8.5/mpi/i386/mpih-add1.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/mpi/i386/mpih-add1.S 2020-01-23 15:37:40.470175379 +0100
|
||||||
|
@@ -52,6 +52,10 @@ C_SYMBOL_NAME(_gcry_mpih_add_n:)
|
||||||
|
movl 20(%esp),%edx /* s2_ptr */
|
||||||
|
movl 24(%esp),%ecx /* size */
|
||||||
|
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ pushl %ebx
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
movl %ecx,%eax
|
||||||
|
shrl $3,%ecx /* compute count for unrolled loop */
|
||||||
|
negl %eax
|
||||||
|
@@ -63,6 +67,9 @@ C_SYMBOL_NAME(_gcry_mpih_add_n:)
|
||||||
|
subl %eax,%esi /* ... by a constant when we ... */
|
||||||
|
subl %eax,%edx /* ... enter the loop */
|
||||||
|
shrl $2,%eax /* restore previous value */
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ leal -4(,%eax,4),%ebx /* Count for 4-byte endbr32 */
|
||||||
|
+#endif
|
||||||
|
#ifdef PIC
|
||||||
|
/* Calculate start address in loop for PIC. Due to limitations in some
|
||||||
|
assemblers, Loop-L0-3 cannot be put into the leal */
|
||||||
|
@@ -75,29 +82,53 @@ L0: leal (%eax,%eax,8),%eax
|
||||||
|
/* Calculate start address in loop for non-PIC. */
|
||||||
|
leal (Loop - 3)(%eax,%eax,8),%eax
|
||||||
|
#endif
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ addl %ebx,%eax /* Adjust for endbr32 */
|
||||||
|
+#endif
|
||||||
|
jmp *%eax /* jump into loop */
|
||||||
|
ALIGN (3)
|
||||||
|
Loop: movl (%esi),%eax
|
||||||
|
adcl (%edx),%eax
|
||||||
|
movl %eax,(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 4(%esi),%eax
|
||||||
|
adcl 4(%edx),%eax
|
||||||
|
movl %eax,4(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 8(%esi),%eax
|
||||||
|
adcl 8(%edx),%eax
|
||||||
|
movl %eax,8(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 12(%esi),%eax
|
||||||
|
adcl 12(%edx),%eax
|
||||||
|
movl %eax,12(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 16(%esi),%eax
|
||||||
|
adcl 16(%edx),%eax
|
||||||
|
movl %eax,16(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 20(%esi),%eax
|
||||||
|
adcl 20(%edx),%eax
|
||||||
|
movl %eax,20(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 24(%esi),%eax
|
||||||
|
adcl 24(%edx),%eax
|
||||||
|
movl %eax,24(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 28(%esi),%eax
|
||||||
|
adcl 28(%edx),%eax
|
||||||
|
movl %eax,28(%edi)
|
||||||
|
@@ -110,6 +141,10 @@ Loop: movl (%esi),%eax
|
||||||
|
sbbl %eax,%eax
|
||||||
|
negl %eax
|
||||||
|
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ popl %ebx
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
popl %esi
|
||||||
|
popl %edi
|
||||||
|
ret
|
||||||
|
diff -up libgcrypt-1.8.5/mpi/i386/mpih-sub1.S.intel-cet libgcrypt-1.8.5/mpi/i386/mpih-sub1.S
|
||||||
|
--- libgcrypt-1.8.5/mpi/i386/mpih-sub1.S.intel-cet 2017-11-23 19:16:58.000000000 +0100
|
||||||
|
+++ libgcrypt-1.8.5/mpi/i386/mpih-sub1.S 2020-01-23 15:37:40.472175351 +0100
|
||||||
|
@@ -53,6 +53,10 @@ C_SYMBOL_NAME(_gcry_mpih_sub_n:)
|
||||||
|
movl 20(%esp),%edx /* s2_ptr */
|
||||||
|
movl 24(%esp),%ecx /* size */
|
||||||
|
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ pushl %ebx
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
movl %ecx,%eax
|
||||||
|
shrl $3,%ecx /* compute count for unrolled loop */
|
||||||
|
negl %eax
|
||||||
|
@@ -64,6 +68,9 @@ C_SYMBOL_NAME(_gcry_mpih_sub_n:)
|
||||||
|
subl %eax,%esi /* ... by a constant when we ... */
|
||||||
|
subl %eax,%edx /* ... enter the loop */
|
||||||
|
shrl $2,%eax /* restore previous value */
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ leal -4(,%eax,4),%ebx /* Count for 4-byte endbr32 */
|
||||||
|
+#endif
|
||||||
|
#ifdef PIC
|
||||||
|
/* Calculate start address in loop for PIC. Due to limitations in some
|
||||||
|
assemblers, Loop-L0-3 cannot be put into the leal */
|
||||||
|
@@ -76,29 +83,53 @@ L0: leal (%eax,%eax,8),%eax
|
||||||
|
/* Calculate start address in loop for non-PIC. */
|
||||||
|
leal (Loop - 3)(%eax,%eax,8),%eax
|
||||||
|
#endif
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ addl %ebx,%eax /* Adjust for endbr32 */
|
||||||
|
+#endif
|
||||||
|
jmp *%eax /* jump into loop */
|
||||||
|
ALIGN (3)
|
||||||
|
Loop: movl (%esi),%eax
|
||||||
|
sbbl (%edx),%eax
|
||||||
|
movl %eax,(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 4(%esi),%eax
|
||||||
|
sbbl 4(%edx),%eax
|
||||||
|
movl %eax,4(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 8(%esi),%eax
|
||||||
|
sbbl 8(%edx),%eax
|
||||||
|
movl %eax,8(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 12(%esi),%eax
|
||||||
|
sbbl 12(%edx),%eax
|
||||||
|
movl %eax,12(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 16(%esi),%eax
|
||||||
|
sbbl 16(%edx),%eax
|
||||||
|
movl %eax,16(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 20(%esi),%eax
|
||||||
|
sbbl 20(%edx),%eax
|
||||||
|
movl %eax,20(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 24(%esi),%eax
|
||||||
|
sbbl 24(%edx),%eax
|
||||||
|
movl %eax,24(%edi)
|
||||||
|
+#ifdef _CET_ENDBR
|
||||||
|
+ _CET_ENDBR
|
||||||
|
+#endif
|
||||||
|
movl 28(%esi),%eax
|
||||||
|
sbbl 28(%edx),%eax
|
||||||
|
movl %eax,28(%edi)
|
||||||
|
@@ -111,6 +142,10 @@ Loop: movl (%esi),%eax
|
||||||
|
sbbl %eax,%eax
|
||||||
|
negl %eax
|
||||||
|
|
||||||
|
+#if defined __CET__ && (__CET__ & 1) != 0
|
||||||
|
+ popl %ebx
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
popl %esi
|
||||||
|
popl %edi
|
||||||
|
ret
|
||||||
BIN
libgcrypt-1.8.5.tar.gz
Normal file
BIN
libgcrypt-1.8.5.tar.gz
Normal file
Binary file not shown.
@ -1,38 +1,32 @@
|
|||||||
%define gcrylibdir %{_libdir}
|
%define gcrylibdir %{_libdir}
|
||||||
Name: libgcrypt
|
Name: libgcrypt
|
||||||
Version: 1.8.3
|
Version: 1.8.5
|
||||||
Release: 5
|
Release: 1
|
||||||
Summary: A general-purpose cryptography library
|
Summary: A general-purpose cryptography library
|
||||||
License: LGPLv2+
|
License: LGPLv2+
|
||||||
URL: https://www.gnupg.org/
|
URL: https://www.gnupg.org/
|
||||||
Source0: https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-%{version}.tar.gz
|
Source0: https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-%{version}.tar.gz
|
||||||
Source2: wk@g10code.com
|
|
||||||
Source3: hobble-libgcrypt
|
|
||||||
Source4: ecc-curves.c
|
|
||||||
Source5: curves.c
|
|
||||||
Source6: t-mpi-point.c
|
|
||||||
Source7: random.conf
|
Source7: random.conf
|
||||||
|
|
||||||
Patch2: libgcrypt-1.6.2-use-fipscheck.patch
|
Patch2: libgcrypt-1.6.2-use-fipscheck.patch
|
||||||
Patch5: libgcrypt-1.8.0-tests.patch
|
Patch5: libgcrypt-1.8.4-fips-keygen.patch
|
||||||
|
Patch6: libgcrypt-1.8.4-tests-fipsmode.patch
|
||||||
Patch7: libgcrypt-1.7.3-fips-cavs.patch
|
Patch7: libgcrypt-1.7.3-fips-cavs.patch
|
||||||
Patch11: libgcrypt-1.8.0-use-poll.patch
|
Patch11: libgcrypt-1.8.4-use-poll.patch
|
||||||
Patch13: libgcrypt-1.6.1-mpicoder-gccopt.patch
|
Patch13: libgcrypt-1.6.1-mpicoder-gccopt.patch
|
||||||
Patch14: libgcrypt-1.7.3-ecc-test-fix.patch
|
Patch14: libgcrypt-1.7.3-ecc-test-fix.patch
|
||||||
Patch18: libgcrypt-1.8.3-fips-ctor.patch
|
Patch18: libgcrypt-1.8.3-fips-ctor.patch
|
||||||
Patch22: libgcrypt-1.7.3-fips-reqs.patch
|
Patch22: libgcrypt-1.7.3-fips-reqs.patch
|
||||||
Patch24: libgcrypt-1.8.3-getrandom.patch
|
Patch24: libgcrypt-1.8.4-getrandom.patch
|
||||||
|
Patch25: libgcrypt-1.8.3-cmac-selftest.patch
|
||||||
Patch6000: sexp-Fix-uninitialized-use-of-a-var-in-the-error-cas.patch
|
Patch26: libgcrypt-1.8.3-fips-enttest.patch
|
||||||
Patch6001: ecc-Fix-possible-memory-leakage-in-parameter-check-o.patch
|
Patch27: libgcrypt-1.8.3-md-fips-enforce.patch
|
||||||
Patch6002: ecc-Fix-memory-leak-in-the-error-case-of-ecc_encrypt.patch
|
Patch28: libgcrypt-1.8.5-intel-cet.patch
|
||||||
Patch6003: Fix-memory-leak-in-secmem-in-out-of-core-conditions.patch
|
Patch29: libgcrypt-1.8.5-build.patch
|
||||||
|
|
||||||
Patch6004: CVE-2019-12904-1.patch
|
Patch6004: CVE-2019-12904-1.patch
|
||||||
Patch6005: CVE-2019-12904-2.patch
|
Patch6005: CVE-2019-12904-2.patch
|
||||||
Patch6006: CVE-2019-12904-3.patch
|
Patch6006: CVE-2019-12904-3.patch
|
||||||
Patch6007: CVE-2019-13627-1.patch
|
|
||||||
Patch6008: CVE-2019-13627-2.patch
|
|
||||||
|
|
||||||
BuildRequires: gcc fipscheck texinfo git
|
BuildRequires: gcc fipscheck texinfo git
|
||||||
BuildRequires: gawk libgpg-error-devel >= 1.11 pkgconfig
|
BuildRequires: gawk libgpg-error-devel >= 1.11 pkgconfig
|
||||||
@ -43,9 +37,7 @@ Libgcrypt is a general purpose cryptographic library originally based on code fr
|
|||||||
%package devel
|
%package devel
|
||||||
Summary: Development files for the %{name} package
|
Summary: Development files for the %{name} package
|
||||||
License: LGPLv2+ and GPLv2+
|
License: LGPLv2+ and GPLv2+
|
||||||
Requires(pre): /sbin/install-info
|
Requires: libgpg-error-devel %{name} = %{version}-%{release} pkgconfig
|
||||||
Requires(post): /sbin/install-info
|
|
||||||
Requires: libgpg-error-devel %{name} = %{version}-%{release}
|
|
||||||
|
|
||||||
%description devel
|
%description devel
|
||||||
Libgcrypt is a general purpose crypto library based on the code used
|
Libgcrypt is a general purpose crypto library based on the code used
|
||||||
@ -56,10 +48,6 @@ applications using libgcrypt.
|
|||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup -n %{name}-%{version} -p1 -S git
|
%autosetup -n %{name}-%{version} -p1 -S git
|
||||||
chmod +x %{SOURCE3}
|
|
||||||
%{SOURCE3}
|
|
||||||
cp %{SOURCE4} cipher/
|
|
||||||
cp %{SOURCE5} %{SOURCE6} tests/
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%configure --enable-noexecstack --enable-hmac-binary-check \
|
%configure --enable-noexecstack --enable-hmac-binary-check \
|
||||||
@ -70,6 +58,8 @@ sed -i -e '/^sys_lib_dlsearch_path_spec/s,/lib /usr/lib,/usr/lib /lib64 /usr/lib
|
|||||||
|
|
||||||
%check
|
%check
|
||||||
fipshmac src/.libs/libgcrypt.so.??
|
fipshmac src/.libs/libgcrypt.so.??
|
||||||
|
make check
|
||||||
|
|
||||||
%define __spec_install_post \
|
%define __spec_install_post \
|
||||||
%{?__debug_package:%{__debug_install_post}} \
|
%{?__debug_package:%{__debug_install_post}} \
|
||||||
%{__arch_install_post} \
|
%{__arch_install_post} \
|
||||||
@ -114,17 +104,6 @@ install -m644 %{SOURCE7} $RPM_BUILD_ROOT/etc/gcrypt/random.conf
|
|||||||
|
|
||||||
%ldconfig_scriptlets
|
%ldconfig_scriptlets
|
||||||
|
|
||||||
%post devel
|
|
||||||
[ -f %{_infodir}/gcrypt.info.gz ] && \
|
|
||||||
/sbin/install-info %{_infodir}/gcrypt.info.gz %{_infodir}/dir
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
%preun devel
|
|
||||||
if [ $1 = 0 -a -f %{_infodir}/gcrypt.info.gz ]; then
|
|
||||||
/sbin/install-info --delete %{_infodir}/gcrypt.info.gz %{_infodir}/dir
|
|
||||||
fi
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%defattr(-,root,root)
|
%defattr(-,root,root)
|
||||||
%doc AUTHORS NEWS THANKS
|
%doc AUTHORS NEWS THANKS
|
||||||
@ -140,6 +119,7 @@ exit 0
|
|||||||
%{_bindir}/*
|
%{_bindir}/*
|
||||||
%{_includedir}/*
|
%{_includedir}/*
|
||||||
%{_libdir}/*.so
|
%{_libdir}/*.so
|
||||||
|
%{_libdir}/pkgconfig/libgcrypt.pc
|
||||||
%{_datadir}/aclocal/*
|
%{_datadir}/aclocal/*
|
||||||
|
|
||||||
%files help
|
%files help
|
||||||
@ -148,6 +128,9 @@ exit 0
|
|||||||
%{_infodir}/gcrypt.info*
|
%{_infodir}/gcrypt.info*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sat Dec 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.8.5-1
|
||||||
|
- update to 1.8.5 from upstream
|
||||||
|
|
||||||
* Sat Dec 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.8.3-5
|
* Sat Dec 21 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.8.3-5
|
||||||
- Type:cves
|
- Type:cves
|
||||||
- ID:NA
|
- ID:NA
|
||||||
|
|||||||
@ -1,45 +0,0 @@
|
|||||||
From 9f2c7ec4d8b07e82663ad084c90c016d3c3b80c2 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Werner Koch <wk@gnupg.org>
|
|
||||||
Date: Tue, 23 Oct 2018 22:51:40 +0200
|
|
||||||
Subject: [PATCH 088/152] sexp: Fix uninitialized use of a var in the error
|
|
||||||
case.
|
|
||||||
|
|
||||||
* src/sexp.c (_gcry_sexp_vextract_param): Initialize L1.
|
|
||||||
--
|
|
||||||
GnuPG-bug-id: 4212
|
|
||||||
|
|
||||||
Signed-off-by: Werner Koch <wk@gnupg.org>
|
|
||||||
---
|
|
||||||
src/gcrypt.h.in | 2 +-
|
|
||||||
src/sexp.c | 2 +-
|
|
||||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
|
|
||||||
index d2dfe80..36bbf20 100644
|
|
||||||
--- a/src/gcrypt.h.in
|
|
||||||
+++ b/src/gcrypt.h.in
|
|
||||||
@@ -1318,7 +1318,7 @@ gpg_error_t gcry_md_extract (gcry_md_hd_t hd, int algo, void *buffer,
|
|
||||||
size_t length);
|
|
||||||
|
|
||||||
/* Convenience function to calculate the hash from the data in BUFFER
|
|
||||||
- of size LENGTH using the algorithm ALGO avoiding the creating of a
|
|
||||||
+ of size LENGTH using the algorithm ALGO avoiding the creation of a
|
|
||||||
hash object. The hash is returned in the caller provided buffer
|
|
||||||
DIGEST which must be large enough to hold the digest of the given
|
|
||||||
algorithm. */
|
|
||||||
diff --git a/src/sexp.c b/src/sexp.c
|
|
||||||
index 9d89268..f2a164c 100644
|
|
||||||
--- a/src/sexp.c
|
|
||||||
+++ b/src/sexp.c
|
|
||||||
@@ -2232,7 +2232,7 @@ _gcry_sexp_vextract_param (gcry_sexp_t sexp, const char *path,
|
|
||||||
gcry_mpi_t *array[20];
|
|
||||||
char arrayisdesc[20];
|
|
||||||
int idx;
|
|
||||||
- gcry_sexp_t l1;
|
|
||||||
+ gcry_sexp_t l1 = NULL;
|
|
||||||
int mode = '+'; /* Default to GCRYMPI_FMT_USG. */
|
|
||||||
gcry_sexp_t freethis = NULL;
|
|
||||||
|
|
||||||
--
|
|
||||||
1.8.3.1
|
|
||||||
|
|
||||||
1225
t-mpi-point.c
1225
t-mpi-point.c
File diff suppressed because it is too large
Load Diff
2007
wk@g10code.com
2007
wk@g10code.com
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user