Compare commits
No commits in common. "c8" and "imports/c9-beta/nettle-3.7.3-2.el9" have entirely different histories.
c8
...
imports/c9
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
|||||||
SOURCES/nettle-3.4.1-hobbled.tar.xz
|
SOURCES/nettle-3.7.3-hobbled.tar.xz
|
||||||
|
@ -1 +1 @@
|
|||||||
be5faff0092a6d78186484374c0ea20465eb218c SOURCES/nettle-3.4.1-hobbled.tar.xz
|
128dc3ced096462fef4233404b542ed6dfe40b87 SOURCES/nettle-3.7.3-hobbled.tar.xz
|
||||||
|
@ -1,181 +0,0 @@
|
|||||||
diff --git a/examples/ecc-benchmark.c b/examples/ecc-benchmark.c
|
|
||||||
index 8e5e095..720d483 100644
|
|
||||||
--- a/examples/ecc-benchmark.c
|
|
||||||
+++ b/examples/ecc-benchmark.c
|
|
||||||
@@ -330,8 +330,6 @@ bench_curve (const struct ecc_curve *ecc)
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct ecc_curve * const curves[] = {
|
|
||||||
- &nettle_secp_192r1,
|
|
||||||
- &nettle_secp_224r1,
|
|
||||||
&_nettle_curve25519,
|
|
||||||
&nettle_secp_256r1,
|
|
||||||
&nettle_secp_384r1,
|
|
||||||
diff --git a/examples/hogweed-benchmark.c b/examples/hogweed-benchmark.c
|
|
||||||
index 3fabe20..0223fe7 100644
|
|
||||||
--- a/examples/hogweed-benchmark.c
|
|
||||||
+++ b/examples/hogweed-benchmark.c
|
|
||||||
@@ -393,24 +393,6 @@ bench_ecdsa_init (unsigned size)
|
|
||||||
|
|
||||||
switch (size)
|
|
||||||
{
|
|
||||||
- case 192:
|
|
||||||
- ecc = &nettle_secp_192r1;
|
|
||||||
- xs = "8e8e07360350fb6b7ad8370cfd32fa8c6bba785e6e200599";
|
|
||||||
- ys = "7f82ddb58a43d59ff8dc66053002b918b99bd01bd68d6736";
|
|
||||||
- zs = "f2e620e086d658b4b507996988480917640e4dc107808bdd";
|
|
||||||
- ctx->digest = hash_string (&nettle_sha1, "abc");
|
|
||||||
- ctx->digest_size = 20;
|
|
||||||
- break;
|
|
||||||
- case 224:
|
|
||||||
- ecc = &nettle_secp_224r1;
|
|
||||||
- xs = "993bf363f4f2bc0f255f22563980449164e9c894d9efd088d7b77334";
|
|
||||||
- ys = "b75fff9849997d02d135140e4d0030944589586e22df1fc4b629082a";
|
|
||||||
- zs = "cdfd01838247f5de3cc70b688418046f10a2bfaca6de9ec836d48c27";
|
|
||||||
- ctx->digest = hash_string (&nettle_sha224, "abc");
|
|
||||||
- ctx->digest_size = 28;
|
|
||||||
- break;
|
|
||||||
-
|
|
||||||
- /* From RFC 4754 */
|
|
||||||
case 256:
|
|
||||||
ecc = &nettle_secp_256r1;
|
|
||||||
xs = "2442A5CC 0ECD015F A3CA31DC 8E2BBC70 BF42D60C BCA20085 E0822CB0 4235E970";
|
|
||||||
@@ -581,16 +563,6 @@ bench_openssl_ecdsa_init (unsigned size)
|
|
||||||
|
|
||||||
switch (size)
|
|
||||||
{
|
|
||||||
- case 192:
|
|
||||||
- ctx->key = EC_KEY_new_by_curve_name (NID_X9_62_prime192v1);
|
|
||||||
- ctx->digest_length = 24; /* truncated */
|
|
||||||
- ctx->digest = hash_string (&nettle_sha224, "abc");
|
|
||||||
- break;
|
|
||||||
- case 224:
|
|
||||||
- ctx->key = EC_KEY_new_by_curve_name (NID_secp224r1);
|
|
||||||
- ctx->digest_length = SHA224_DIGEST_SIZE;
|
|
||||||
- ctx->digest = hash_string (&nettle_sha224, "abc");
|
|
||||||
- break;
|
|
||||||
case 256:
|
|
||||||
ctx->key = EC_KEY_new_by_curve_name (NID_X9_62_prime256v1);
|
|
||||||
ctx->digest_length = SHA256_DIGEST_SIZE;
|
|
||||||
@@ -701,14 +673,10 @@ struct alg alg_list[] = {
|
|
||||||
#if 0
|
|
||||||
{ "dsa",2048, bench_dsa_init, bench_dsa_sign, bench_dsa_verify, bench_dsa_clear },
|
|
||||||
#endif
|
|
||||||
- { "ecdsa", 192, bench_ecdsa_init, bench_ecdsa_sign, bench_ecdsa_verify, bench_ecdsa_clear },
|
|
||||||
- { "ecdsa", 224, bench_ecdsa_init, bench_ecdsa_sign, bench_ecdsa_verify, bench_ecdsa_clear },
|
|
||||||
{ "ecdsa", 256, bench_ecdsa_init, bench_ecdsa_sign, bench_ecdsa_verify, bench_ecdsa_clear },
|
|
||||||
{ "ecdsa", 384, bench_ecdsa_init, bench_ecdsa_sign, bench_ecdsa_verify, bench_ecdsa_clear },
|
|
||||||
{ "ecdsa", 521, bench_ecdsa_init, bench_ecdsa_sign, bench_ecdsa_verify, bench_ecdsa_clear },
|
|
||||||
#if WITH_OPENSSL
|
|
||||||
- { "ecdsa (openssl)", 192, bench_openssl_ecdsa_init, bench_openssl_ecdsa_sign, bench_openssl_ecdsa_verify, bench_openssl_ecdsa_clear },
|
|
||||||
- { "ecdsa (openssl)", 224, bench_openssl_ecdsa_init, bench_openssl_ecdsa_sign, bench_openssl_ecdsa_verify, bench_openssl_ecdsa_clear },
|
|
||||||
{ "ecdsa (openssl)", 256, bench_openssl_ecdsa_init, bench_openssl_ecdsa_sign, bench_openssl_ecdsa_verify, bench_openssl_ecdsa_clear },
|
|
||||||
{ "ecdsa (openssl)", 384, bench_openssl_ecdsa_init, bench_openssl_ecdsa_sign, bench_openssl_ecdsa_verify, bench_openssl_ecdsa_clear },
|
|
||||||
{ "ecdsa (openssl)", 521, bench_openssl_ecdsa_init, bench_openssl_ecdsa_sign, bench_openssl_ecdsa_verify, bench_openssl_ecdsa_clear },
|
|
||||||
diff --git a/testsuite/ecdh-test.c b/testsuite/ecdh-test.c
|
|
||||||
index 5a2b39d..08870b1 100644
|
|
||||||
--- a/testsuite/ecdh-test.c
|
|
||||||
+++ b/testsuite/ecdh-test.c
|
|
||||||
@@ -138,26 +138,6 @@ test_dh (const char *name, const struct ecc_curve *ecc,
|
|
||||||
void
|
|
||||||
test_main(void)
|
|
||||||
{
|
|
||||||
- test_dh ("secp-192r1", &nettle_secp_192r1,
|
|
||||||
- "3406157206141798348095184987208239421004566462391397236532",
|
|
||||||
- "1050363442265225480786760666329560655512990381040021438562",
|
|
||||||
- "5298249600854377235107392014200406283816103564916230704184",
|
|
||||||
- "738368960171459956677260317271477822683777845013274506165",
|
|
||||||
- "2585840779771604687467445319428618542927556223024046979917",
|
|
||||||
- "293088185788565313717816218507714888251468410990708684573",
|
|
||||||
- "149293809021051532782730990145509724807636529827149481690",
|
|
||||||
- "2891131861147398318714693938158856874319184314120776776192");
|
|
||||||
-
|
|
||||||
- test_dh ("secp-224r1", &nettle_secp_224r1,
|
|
||||||
- "1321072106881784386340709783538698930880431939595776773514895067682",
|
|
||||||
- "6768311794185371282972144247871764855860666277647541840973645586477",
|
|
||||||
- "2880077809069104378181313860274147139049600284805670362929579614547",
|
|
||||||
- "13934723037778859565852601874354272638301919827851286722006496784914",
|
|
||||||
- "373124771833407982305885866158843810218322878380632071540538232035",
|
|
||||||
- "24223309755162432227459925493224336241652868856405241018762887667883",
|
|
||||||
- "8330362698029245839097779050425944245826040430538860338085968752913",
|
|
||||||
- "24167244512472228715617822000878192535267113543393576038737592837010");
|
|
||||||
-
|
|
||||||
test_dh ("secp-256r1", &nettle_secp_256r1,
|
|
||||||
"94731533361265297353914491124013058635674217345912524033267198103710636378786",
|
|
||||||
"22441589863306126152768848344973918725077248391248404659242620344938484650846",
|
|
||||||
diff --git a/testsuite/ecdsa-sign-test.c b/testsuite/ecdsa-sign-test.c
|
|
||||||
index 559de8e..1ca36c2 100644
|
|
||||||
--- a/testsuite/ecdsa-sign-test.c
|
|
||||||
+++ b/testsuite/ecdsa-sign-test.c
|
|
||||||
@@ -60,37 +60,6 @@ test_main (void)
|
|
||||||
{
|
|
||||||
/* Test cases for the smaller groups, verified with a
|
|
||||||
proof-of-concept implementation done for Yubico AB. */
|
|
||||||
- test_ecdsa (&nettle_secp_192r1,
|
|
||||||
- "DC51D3866A15BACDE33D96F992FCA99D"
|
|
||||||
- "A7E6EF0934E70975", /* z */
|
|
||||||
-
|
|
||||||
- "9E56F509196784D963D1C0A401510EE7"
|
|
||||||
- "ADA3DCC5DEE04B15", /* k */
|
|
||||||
-
|
|
||||||
- SHEX("BA7816BF8F01CFEA414140DE5DAE2223"
|
|
||||||
- "B00361A396177A9C"), /* h */
|
|
||||||
-
|
|
||||||
- "8c478db6a5c131540cebc739f9c0a9a8"
|
|
||||||
- "c720c2abdd14a891", /* r */
|
|
||||||
-
|
|
||||||
- "a91fb738f9f175d72f9c98527e881c36"
|
|
||||||
- "8de68cb55ffe589"); /* s */
|
|
||||||
-
|
|
||||||
- test_ecdsa (&nettle_secp_224r1,
|
|
||||||
- "446df0a771ed58403ca9cb316e617f6b"
|
|
||||||
- "158420465d00a69601e22858", /* z */
|
|
||||||
-
|
|
||||||
- "4c13f1905ad7eb201178bc08e0c9267b"
|
|
||||||
- "4751c15d5e1831ca214c33f4", /* z */
|
|
||||||
-
|
|
||||||
- SHEX("1b28a611fe62ab3649350525d06703ba"
|
|
||||||
- "4b979a1e543566fd5caa85c6"), /* h */
|
|
||||||
-
|
|
||||||
- "2cc280778f3d067df6d3adbe3a6aad63"
|
|
||||||
- "bc75f08f5c5f915411902a99", /* r */
|
|
||||||
-
|
|
||||||
- "d0f069fd0f108eb07b7bbc54c8d6c88d"
|
|
||||||
- "f2715c38a95c31a2b486995f"); /* s */
|
|
||||||
|
|
||||||
/* From RFC 4754 */
|
|
||||||
test_ecdsa (&nettle_secp_256r1,
|
|
||||||
diff --git a/testsuite/testutils.c b/testsuite/testutils.c
|
|
||||||
index 6f89761..901f62b 100644
|
|
||||||
--- a/testsuite/testutils.c
|
|
||||||
+++ b/testsuite/testutils.c
|
|
||||||
@@ -1212,8 +1212,6 @@ test_dsa_key(const struct dsa_params *params,
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct ecc_curve * const ecc_curves[] = {
|
|
||||||
- &nettle_secp_192r1,
|
|
||||||
- &nettle_secp_224r1,
|
|
||||||
&nettle_secp_256r1,
|
|
||||||
&nettle_secp_384r1,
|
|
||||||
&nettle_secp_521r1,
|
|
||||||
@@ -1270,20 +1268,6 @@ test_ecc_mul_a (unsigned curve, unsigned n, const mp_limb_t *p)
|
|
||||||
{
|
|
||||||
/* For each curve, the points 2 g, 3 g and 4 g */
|
|
||||||
static const struct ecc_ref_point ref[6][3] = {
|
|
||||||
- { { "dafebf5828783f2ad35534631588a3f629a70fb16982a888",
|
|
||||||
- "dd6bda0d993da0fa46b27bbc141b868f59331afa5c7e93ab" },
|
|
||||||
- { "76e32a2557599e6edcd283201fb2b9aadfd0d359cbb263da",
|
|
||||||
- "782c37e372ba4520aa62e0fed121d49ef3b543660cfd05fd" },
|
|
||||||
- { "35433907297cc378b0015703374729d7a4fe46647084e4ba",
|
|
||||||
- "a2649984f2135c301ea3acb0776cd4f125389b311db3be32" }
|
|
||||||
- },
|
|
||||||
- { { "706a46dc76dcb76798e60e6d89474788d16dc18032d268fd1a704fa6",
|
|
||||||
- "1c2b76a7bc25e7702a704fa986892849fca629487acf3709d2e4e8bb" },
|
|
||||||
- { "df1b1d66a551d0d31eff822558b9d2cc75c2180279fe0d08fd896d04",
|
|
||||||
- "a3f7f03cadd0be444c0aa56830130ddf77d317344e1af3591981a925" },
|
|
||||||
- { "ae99feebb5d26945b54892092a8aee02912930fa41cd114e40447301",
|
|
||||||
- "482580a0ec5bc47e88bc8c378632cd196cb3fa058a7114eb03054c9" },
|
|
||||||
- },
|
|
||||||
{ { "7cf27b188d034f7e8a52380304b51ac3c08969e277f21b35a60b48fc47669978",
|
|
||||||
"7775510db8ed040293d9ac69f7430dbba7dade63ce982299e04b79d227873d1" },
|
|
||||||
{ "5ecbe4d1a6330a44c8f7ef951d4bf165e6c6b721efada985fb41661bc6e7fd6c",
|
|
@ -1,12 +1,13 @@
|
|||||||
diff -up nettle-3.4/Makefile.in.annocheck nettle-3.4/Makefile.in
|
Index: nettle-3.7/Makefile.in
|
||||||
--- nettle-3.4/Makefile.in.annocheck 2018-10-16 15:06:53.340138708 +0200
|
===================================================================
|
||||||
+++ nettle-3.4/Makefile.in 2018-10-16 15:12:25.150276379 +0200
|
--- nettle-3.7.orig/Makefile.in
|
||||||
@@ -377,7 +377,7 @@ ecc-25519.$(OBJEXT): ecc-25519.h
|
+++ nettle-3.7/Makefile.in
|
||||||
|
@@ -291,7 +291,7 @@ libhogweed.a: $(hogweed_OBJS)
|
||||||
|
|
||||||
.asm.$(OBJEXT): $(srcdir)/asm.m4 machine.m4 config.m4
|
%.$(OBJEXT): %.asm $(srcdir)/m4-utils.m4 $(srcdir)/asm.m4 config.m4 machine.m4
|
||||||
$(M4) $(srcdir)/asm.m4 machine.m4 config.m4 $< >$*.s
|
$(M4) $(srcdir)/m4-utils.m4 $(srcdir)/asm.m4 config.m4 machine.m4 $< >$*.s
|
||||||
- $(COMPILE) -c $*.s
|
- $(COMPILE) -c $*.s
|
||||||
+ $(COMPILE) -c -Wa,--generate-missing-build-notes=yes $*.s
|
+ $(COMPILE) -c -Wa,--generate-missing-build-notes=yes $*.s
|
||||||
@echo "$@ : $< $(srcdir)/asm.m4 machine.m4 config.m4" >$@.d
|
|
||||||
|
|
||||||
# Texinfo rules
|
%.$(OBJEXT): %.c
|
||||||
|
$(COMPILE) -c $< \
|
||||||
|
@ -1,109 +0,0 @@
|
|||||||
From 932ea29845da1ae350d9c056cb2cb0379a66d642 Mon Sep 17 00:00:00 2001
|
|
||||||
From: Daiki Ueno <dueno@redhat.com>
|
|
||||||
Date: Tue, 30 Mar 2021 09:22:47 +0200
|
|
||||||
Subject: [PATCH] Port upstream hardening of EC scaler multiplication
|
|
||||||
|
|
||||||
Some internal functions used in point multiplications are known to
|
|
||||||
misbehave if the scaler is out-of-range. This performs canonical
|
|
||||||
reduction on scalers, before point multiplication.
|
|
||||||
|
|
||||||
Signed-off-by: Daiki Ueno <dueno@redhat.com>
|
|
||||||
---
|
|
||||||
ecc-ecdsa-sign.c | 7 +++++--
|
|
||||||
ecc-ecdsa-verify.c | 14 ++++++++++++--
|
|
||||||
eddsa-hash.c | 9 +++++++--
|
|
||||||
3 files changed, 24 insertions(+), 6 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/ecc-ecdsa-sign.c b/ecc-ecdsa-sign.c
|
|
||||||
index 3b9e9cc1..45062528 100644
|
|
||||||
--- a/ecc-ecdsa-sign.c
|
|
||||||
+++ b/ecc-ecdsa-sign.c
|
|
||||||
@@ -62,6 +62,8 @@ ecc_ecdsa_sign (const struct ecc_curve *ecc,
|
|
||||||
mp_limb_t *rp, mp_limb_t *sp,
|
|
||||||
mp_limb_t *scratch)
|
|
||||||
{
|
|
||||||
+ mp_limb_t cy;
|
|
||||||
+
|
|
||||||
#define P scratch
|
|
||||||
#define kinv scratch /* Needs 5*ecc->p.size for computation */
|
|
||||||
#define hp (scratch + ecc->p.size) /* NOTE: ecc->p.size + 1 limbs! */
|
|
||||||
@@ -91,8 +93,9 @@ ecc_ecdsa_sign (const struct ecc_curve *ecc,
|
|
||||||
ecc_modq_mul (ecc, tp, zp, rp);
|
|
||||||
ecc_modq_add (ecc, hp, hp, tp);
|
|
||||||
ecc_modq_mul (ecc, tp, hp, kinv);
|
|
||||||
-
|
|
||||||
- mpn_copyi (sp, tp, ecc->p.size);
|
|
||||||
+ /* Ensure canonical reduction. */
|
|
||||||
+ cy = mpn_sub_n (sp, tp, ecc->q.m, ecc->q.size);
|
|
||||||
+ cnd_copy (cy, sp, tp, ecc->q.size);
|
|
||||||
#undef P
|
|
||||||
#undef hp
|
|
||||||
#undef kinv
|
|
||||||
diff --git a/ecc-ecdsa-verify.c b/ecc-ecdsa-verify.c
|
|
||||||
index d7f5b684..6b8acb07 100644
|
|
||||||
--- a/ecc-ecdsa-verify.c
|
|
||||||
+++ b/ecc-ecdsa-verify.c
|
|
||||||
@@ -75,6 +75,8 @@ ecc_ecdsa_verify (const struct ecc_curve *ecc,
|
|
||||||
const mp_limb_t *rp, const mp_limb_t *sp,
|
|
||||||
mp_limb_t *scratch)
|
|
||||||
{
|
|
||||||
+ mp_limb_t cy;
|
|
||||||
+
|
|
||||||
/* Procedure, according to RFC 6090, "KT-I". q denotes the group
|
|
||||||
order.
|
|
||||||
|
|
||||||
@@ -98,6 +100,7 @@ ecc_ecdsa_verify (const struct ecc_curve *ecc,
|
|
||||||
#define P1 (scratch + 4*ecc->p.size)
|
|
||||||
#define sinv (scratch)
|
|
||||||
#define hp (scratch + ecc->p.size)
|
|
||||||
+#define tp (scratch + 4*ecc->p.size)
|
|
||||||
|
|
||||||
if (! (ecdsa_in_range (ecc, rp)
|
|
||||||
&& ecdsa_in_range (ecc, sp)))
|
|
||||||
@@ -112,10 +115,16 @@ ecc_ecdsa_verify (const struct ecc_curve *ecc,
|
|
||||||
|
|
||||||
/* u1 = h / s, P1 = u1 * G */
|
|
||||||
ecc_hash (&ecc->q, hp, length, digest);
|
|
||||||
- ecc_modq_mul (ecc, u1, hp, sinv);
|
|
||||||
+ ecc_modq_mul (ecc, tp, hp, sinv);
|
|
||||||
+ /* Ensure canonical reduction. */
|
|
||||||
+ cy = mpn_sub_n (u1, tp, ecc->q.m, ecc->q.size);
|
|
||||||
+ cnd_copy (cy, u1, tp, ecc->q.size);
|
|
||||||
|
|
||||||
/* u2 = r / s, P2 = u2 * Y */
|
|
||||||
- ecc_modq_mul (ecc, u2, rp, sinv);
|
|
||||||
+ ecc_modq_mul (ecc, hp, rp, sinv);
|
|
||||||
+ /* Ensure canonical reduction. */
|
|
||||||
+ cy = mpn_sub_n (u2, hp, ecc->q.m, ecc->q.size);
|
|
||||||
+ cnd_copy (cy, u2, hp, ecc->q.size);
|
|
||||||
|
|
||||||
/* Total storage: 5*ecc->p.size + ecc->mul_itch */
|
|
||||||
ecc->mul (ecc, P2, u2, pp, u2 + ecc->p.size);
|
|
||||||
@@ -154,4 +163,5 @@ ecc_ecdsa_verify (const struct ecc_curve *ecc,
|
|
||||||
#undef u2
|
|
||||||
#undef hp
|
|
||||||
#undef u1
|
|
||||||
+#undef tp
|
|
||||||
}
|
|
||||||
diff --git a/eddsa-hash.c b/eddsa-hash.c
|
|
||||||
index 4fb79f1b..53c6fc49 100644
|
|
||||||
--- a/eddsa-hash.c
|
|
||||||
+++ b/eddsa-hash.c
|
|
||||||
@@ -45,7 +45,12 @@ void
|
|
||||||
_eddsa_hash (const struct ecc_modulo *m,
|
|
||||||
mp_limb_t *rp, const uint8_t *digest)
|
|
||||||
{
|
|
||||||
+ mp_limb_t cy;
|
|
||||||
+
|
|
||||||
size_t nbytes = 1 + m->bit_size / 8;
|
|
||||||
- mpn_set_base256_le (rp, 2*m->size, digest, 2*nbytes);
|
|
||||||
- m->mod (m, rp);
|
|
||||||
+ mpn_set_base256_le (rp + m->size, 2*m->size, digest, 2*nbytes);
|
|
||||||
+ m->mod (m, rp + m->size);
|
|
||||||
+ /* Ensure canonical reduction. */
|
|
||||||
+ cy = mpn_sub_n (rp, rp + m->size, m->m, m->size);
|
|
||||||
+ cnd_copy (cy, rp, rp + m->size, m->size);
|
|
||||||
}
|
|
||||||
--
|
|
||||||
2.30.2
|
|
||||||
|
|
@ -1,210 +0,0 @@
|
|||||||
diff --git a/asm.m4 b/asm.m4
|
|
||||||
index 8da47201..59d64098 100644
|
|
||||||
--- a/asm.m4
|
|
||||||
+++ b/asm.m4
|
|
||||||
@@ -32,7 +32,7 @@ define(<GMP_NUMB_BITS>,<>)dnl
|
|
||||||
define(<PROLOGUE>,
|
|
||||||
<.globl C_NAME($1)
|
|
||||||
DECLARE_FUNC(C_NAME($1))
|
|
||||||
-C_NAME($1):>)
|
|
||||||
+C_NAME($1): ASM_X86_ENDBR>)
|
|
||||||
|
|
||||||
define(<EPILOGUE>,
|
|
||||||
<ifelse(ELF_STYLE,yes,
|
|
||||||
--- a/config.m4.in 2018-12-04 21:56:06.000000000 +0100
|
|
||||||
+++ b/config.m4.in 2020-05-15 11:25:42.350465132 +0200
|
|
||||||
@@ -7,6 +7,9 @@
|
|
||||||
define(<ALIGN_LOG>, <@ASM_ALIGN_LOG@>)dnl
|
|
||||||
define(<W64_ABI>, <@W64_ABI@>)dnl
|
|
||||||
define(<RODATA>, <@ASM_RODATA@>)dnl
|
|
||||||
+define(<ASM_X86_ENDBR>,<@ASM_X86_ENDBR@>)dnl
|
|
||||||
+define(<ASM_X86_MARK_CET_ALIGN>,<@ASM_X86_MARK_CET_ALIGN@>)dnl
|
|
||||||
divert(1)
|
|
||||||
+@ASM_X86_MARK_CET@
|
|
||||||
@ASM_MARK_NOEXEC_STACK@
|
|
||||||
divert
|
|
||||||
--- a/configure.ac 2018-12-04 21:56:06.000000000 +0100
|
|
||||||
+++ b/configure.ac 2020-05-15 11:46:39.152373137 +0200
|
|
||||||
@@ -787,6 +787,68 @@
|
|
||||||
ASM_ALIGN_LOG="$nettle_cv_asm_align_log"
|
|
||||||
fi
|
|
||||||
|
|
||||||
+dnl Define
|
|
||||||
+dnl 1. ASM_X86_ENDBR for endbr32/endbr64.
|
|
||||||
+dnl 2. ASM_X86_MARK_CET to add a .note.gnu.property section to mark
|
|
||||||
+dnl Intel CET support if needed.
|
|
||||||
+dnl 3. ASM_X86_MARK_CET_ALIGN to align ASM_X86_MARK_CET.
|
|
||||||
+AC_CACHE_CHECK([if Intel CET is enabled],
|
|
||||||
+ [nettle_cv_asm_x86_intel_cet],
|
|
||||||
+ [AC_TRY_COMPILE([
|
|
||||||
+#ifndef __CET__
|
|
||||||
+#error Intel CET is not enabled
|
|
||||||
+#endif
|
|
||||||
+ ], [],
|
|
||||||
+ [nettle_cv_asm_x86_intel_cet=yes],
|
|
||||||
+ [nettle_cv_asm_x86_intel_cet=no])])
|
|
||||||
+if test "$nettle_cv_asm_x86_intel_cet" = yes; then
|
|
||||||
+ case $ABI in
|
|
||||||
+ 32|standard)
|
|
||||||
+ ASM_X86_ENDBR=endbr32
|
|
||||||
+ ASM_X86_MARK_CET_ALIGN=2
|
|
||||||
+ ;;
|
|
||||||
+ 64)
|
|
||||||
+ ASM_X86_ENDBR=endbr64
|
|
||||||
+ ASM_X86_MARK_CET_ALIGN=3
|
|
||||||
+ ;;
|
|
||||||
+ x32)
|
|
||||||
+ ASM_X86_ENDBR=endbr64
|
|
||||||
+ ASM_X86_MARK_CET_ALIGN=2
|
|
||||||
+ ;;
|
|
||||||
+ esac
|
|
||||||
+ AC_CACHE_CHECK([if .note.gnu.property section is needed],
|
|
||||||
+ [nettle_cv_asm_x86_gnu_property],
|
|
||||||
+ [AC_TRY_COMPILE([
|
|
||||||
+#if !defined __ELF__ || !defined __CET__
|
|
||||||
+#error GNU property is not needed
|
|
||||||
+#endif
|
|
||||||
+ ], [],
|
|
||||||
+ [nettle_cv_asm_x86_gnu_property=yes],
|
|
||||||
+ [nettle_cv_asm_x86_gnu_property=no])])
|
|
||||||
+else
|
|
||||||
+ nettle_cv_asm_x86_gnu_property=no
|
|
||||||
+fi
|
|
||||||
+if test "$nettle_cv_asm_x86_gnu_property" = yes; then
|
|
||||||
+ ASM_X86_MARK_CET='
|
|
||||||
+ .pushsection ".note.gnu.property", "a"
|
|
||||||
+ .p2align ASM_X86_MARK_CET_ALIGN
|
|
||||||
+ .long 1f - 0f
|
|
||||||
+ .long 4f - 1f
|
|
||||||
+ .long 5
|
|
||||||
+0:
|
|
||||||
+ .asciz "GNU"
|
|
||||||
+1:
|
|
||||||
+ .p2align ASM_X86_MARK_CET_ALIGN
|
|
||||||
+ .long 0xc0000002
|
|
||||||
+ .long 3f - 2f
|
|
||||||
+2:
|
|
||||||
+ .long 3
|
|
||||||
+3:
|
|
||||||
+ .p2align ASM_X86_MARK_CET_ALIGN
|
|
||||||
+4:
|
|
||||||
+ .popsection'
|
|
||||||
+fi
|
|
||||||
+
|
|
||||||
AC_SUBST(ASM_SYMBOL_PREFIX)
|
|
||||||
AC_SUBST(ASM_ELF_STYLE)
|
|
||||||
AC_SUBST(ASM_COFF_STYLE)
|
|
||||||
@@ -796,6 +858,9 @@
|
|
||||||
AC_SUBST(ASM_ALIGN_LOG)
|
|
||||||
AC_SUBST(W64_ABI)
|
|
||||||
AC_SUBST(EMULATOR)
|
|
||||||
+AC_SUBST(ASM_X86_ENDBR)
|
|
||||||
+AC_SUBST(ASM_X86_MARK_CET)
|
|
||||||
+AC_SUBST(ASM_X86_MARK_CET_ALIGN)
|
|
||||||
|
|
||||||
AC_SUBST(LIBNETTLE_MAJOR)
|
|
||||||
AC_SUBST(LIBNETTLE_MINOR)
|
|
||||||
diff --git a/testsuite/.test-rules.make b/testsuite/.test-rules.make
|
|
||||||
index 922a2c7f..9de8f412 100644
|
|
||||||
--- a/testsuite/.test-rules.make
|
|
||||||
+++ b/testsuite/.test-rules.make
|
|
||||||
@@ -178,6 +178,9 @@ xts-test$(EXEEXT): xts-test.$(OBJEXT)
|
|
||||||
pbkdf2-test$(EXEEXT): pbkdf2-test.$(OBJEXT)
|
|
||||||
$(LINK) pbkdf2-test.$(OBJEXT) $(TEST_OBJS) -o pbkdf2-test$(EXEEXT)
|
|
||||||
|
|
||||||
+x86-ibt-test$(EXEEXT): x86-ibt-test.$(OBJEXT)
|
|
||||||
+ $(LINK) x86-ibt-test.$(OBJEXT) $(TEST_OBJS) -o x86-ibt-test$(EXEEXT)
|
|
||||||
+
|
|
||||||
sexp-test$(EXEEXT): sexp-test.$(OBJEXT)
|
|
||||||
$(LINK) sexp-test.$(OBJEXT) $(TEST_OBJS) -o sexp-test$(EXEEXT)
|
|
||||||
|
|
||||||
--- a/testsuite/Makefile.in 2018-12-04 21:56:06.000000000 +0100
|
|
||||||
+++ b/testsuite/Makefile.in 2020-05-15 11:21:15.673321598 +0200
|
|
||||||
@@ -31,7 +31,8 @@
|
|
||||||
hmac-test.c umac-test.c \
|
|
||||||
meta-hash-test.c meta-cipher-test.c\
|
|
||||||
meta-aead-test.c meta-armor-test.c \
|
|
||||||
- buffer-test.c yarrow-test.c pbkdf2-test.c
|
|
||||||
+ buffer-test.c yarrow-test.c pbkdf2-test.c \
|
|
||||||
+ x86-ibt-test.c
|
|
||||||
|
|
||||||
TS_HOGWEED_SOURCES = sexp-test.c sexp-format-test.c \
|
|
||||||
rsa2sexp-test.c sexp2rsa-test.c \
|
|
||||||
diff --git a/testsuite/x86-ibt-test.c b/testsuite/x86-ibt-test.c
|
|
||||||
new file mode 100644
|
|
||||||
index 00000000..1f3d1d67
|
|
||||||
--- /dev/null
|
|
||||||
+++ b/testsuite/x86-ibt-test.c
|
|
||||||
@@ -0,0 +1,69 @@
|
|
||||||
+#include "testutils.h"
|
|
||||||
+#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) \
|
|
||||||
+ && defined(__CET__) && defined(__linux__)
|
|
||||||
+#include <signal.h>
|
|
||||||
+
|
|
||||||
+static void
|
|
||||||
+segfault_handler(int signo)
|
|
||||||
+{
|
|
||||||
+ exit(0);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static void
|
|
||||||
+ibt_violation(void)
|
|
||||||
+{
|
|
||||||
+#ifdef __i386__
|
|
||||||
+ unsigned int reg;
|
|
||||||
+ asm volatile("lea 1f, %0\n\t"
|
|
||||||
+ "jmp *%0\n"
|
|
||||||
+ "1:" : "=r" (reg));
|
|
||||||
+#else
|
|
||||||
+ unsigned long long reg;
|
|
||||||
+ asm volatile("lea 1f(%%rip), %0\n\t"
|
|
||||||
+ "jmp *%0\n"
|
|
||||||
+ "1:" : "=r" (reg));
|
|
||||||
+#endif
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+#ifdef __i386__
|
|
||||||
+static unsigned int
|
|
||||||
+_get_ssp(void)
|
|
||||||
+{
|
|
||||||
+ unsigned int ssp;
|
|
||||||
+ asm volatile("xor %0, %0\n\trdsspd %0" : "=r" (ssp));
|
|
||||||
+ return ssp;
|
|
||||||
+}
|
|
||||||
+#else
|
|
||||||
+static unsigned long long
|
|
||||||
+_get_ssp(void)
|
|
||||||
+{
|
|
||||||
+ unsigned long long ssp;
|
|
||||||
+ asm volatile("xor %0, %0\n\trdsspq %0" : "=r" (ssp));
|
|
||||||
+ return ssp;
|
|
||||||
+}
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
+void
|
|
||||||
+test_main(void)
|
|
||||||
+{
|
|
||||||
+ /* NB: This test should trigger SIGSEGV on CET platforms. _get_ssp
|
|
||||||
+ returns the address of shadow stack pointer. If the address of
|
|
||||||
+ shadow stack pointer is 0, SHSTK is disabled and we assume that
|
|
||||||
+ IBT is also disabled. */
|
|
||||||
+ if (_get_ssp() == 0)
|
|
||||||
+ {
|
|
||||||
+ ibt_violation();
|
|
||||||
+ SKIP();
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ signal(SIGSEGV, segfault_handler);
|
|
||||||
+ ibt_violation();
|
|
||||||
+ FAIL();
|
|
||||||
+}
|
|
||||||
+#else
|
|
||||||
+void
|
|
||||||
+test_main(void)
|
|
||||||
+{
|
|
||||||
+ SKIP();
|
|
||||||
+}
|
|
||||||
+#endif
|
|
||||||
--
|
|
||||||
2.25.4
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,609 +0,0 @@
|
|||||||
From 5646ca77ee92de0ae33e7d2e0a3383c61a4091ed Mon Sep 17 00:00:00 2001
|
|
||||||
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
|
|
||||||
Date: Thu, 6 May 2021 21:30:23 +0200
|
|
||||||
Subject: [PATCH 1/4] Add check that message length to _pkcs1_sec_decrypt is
|
|
||||||
valid.
|
|
||||||
|
|
||||||
* pkcs1-sec-decrypt.c (_pkcs1_sec_decrypt): Check that message
|
|
||||||
length is valid, for given key size.
|
|
||||||
* testsuite/rsa-sec-decrypt-test.c (test_main): Add test cases for
|
|
||||||
calls to rsa_sec_decrypt specifying a too large message length.
|
|
||||||
|
|
||||||
(cherry picked from commit 7616541e6eff73353bf682c62e3a68e4fe696707)
|
|
||||||
---
|
|
||||||
ChangeLog | 8 ++++++++
|
|
||||||
pkcs1-sec-decrypt.c | 4 +++-
|
|
||||||
testsuite/rsa-sec-decrypt-test.c | 17 ++++++++++++++++-
|
|
||||||
3 files changed, 27 insertions(+), 2 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/ChangeLog b/ChangeLog
|
|
||||||
index 4c7338a1..7cd0455e 100644
|
|
||||||
--- a/ChangeLog
|
|
||||||
+++ b/ChangeLog
|
|
||||||
@@ -1,3 +1,11 @@
|
|
||||||
+2021-05-06 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
+
|
|
||||||
+ Bug fixes merged from from 3.7.3 release (starting from 2021-05-06).
|
|
||||||
+ * pkcs1-sec-decrypt.c (_pkcs1_sec_decrypt): Check that message
|
|
||||||
+ length is valid, for given key size.
|
|
||||||
+ * testsuite/rsa-sec-decrypt-test.c (test_main): Add test cases for
|
|
||||||
+ calls to rsa_sec_decrypt specifying a too large message length.
|
|
||||||
+
|
|
||||||
2018-12-04 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
|
|
||||||
* Released nettle-3.4.1.
|
|
||||||
diff --git a/pkcs1-sec-decrypt.c b/pkcs1-sec-decrypt.c
|
|
||||||
index 722044b0..02fd07e1 100644
|
|
||||||
--- a/pkcs1-sec-decrypt.c
|
|
||||||
+++ b/pkcs1-sec-decrypt.c
|
|
||||||
@@ -64,7 +64,9 @@ _pkcs1_sec_decrypt (size_t length, uint8_t *message,
|
|
||||||
volatile int ok;
|
|
||||||
size_t i, t;
|
|
||||||
|
|
||||||
- assert (padded_message_length >= length);
|
|
||||||
+ /* Message independent branch */
|
|
||||||
+ if (length + 11 > padded_message_length)
|
|
||||||
+ return 0;
|
|
||||||
|
|
||||||
t = padded_message_length - length - 1;
|
|
||||||
|
|
||||||
diff --git a/testsuite/rsa-sec-decrypt-test.c b/testsuite/rsa-sec-decrypt-test.c
|
|
||||||
index 64f0b13c..4a9f301b 100644
|
|
||||||
--- a/testsuite/rsa-sec-decrypt-test.c
|
|
||||||
+++ b/testsuite/rsa-sec-decrypt-test.c
|
|
||||||
@@ -55,6 +55,7 @@ rsa_decrypt_for_test(const struct rsa_public_key *pub,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define PAYLOAD_SIZE 50
|
|
||||||
+#define DECRYPTED_SIZE 256
|
|
||||||
void
|
|
||||||
test_main(void)
|
|
||||||
{
|
|
||||||
@@ -63,7 +64,7 @@ test_main(void)
|
|
||||||
struct knuth_lfib_ctx random_ctx;
|
|
||||||
|
|
||||||
uint8_t plaintext[PAYLOAD_SIZE];
|
|
||||||
- uint8_t decrypted[PAYLOAD_SIZE];
|
|
||||||
+ uint8_t decrypted[DECRYPTED_SIZE];
|
|
||||||
uint8_t verifybad[PAYLOAD_SIZE];
|
|
||||||
unsigned n_size = 1024;
|
|
||||||
mpz_t gibberish;
|
|
||||||
@@ -98,6 +99,20 @@ test_main(void)
|
|
||||||
PAYLOAD_SIZE, decrypted, gibberish) == 1);
|
|
||||||
ASSERT (MEMEQ (PAYLOAD_SIZE, plaintext, decrypted));
|
|
||||||
|
|
||||||
+ ASSERT (pub.size > 10);
|
|
||||||
+ ASSERT (pub.size <= DECRYPTED_SIZE);
|
|
||||||
+
|
|
||||||
+ /* Check that too large message length is rejected, largest
|
|
||||||
+ valid size is pub.size - 11. */
|
|
||||||
+ ASSERT (!rsa_decrypt_for_test (&pub, &key, &random_ctx,
|
|
||||||
+ (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ pub.size - 10, decrypted, gibberish));
|
|
||||||
+
|
|
||||||
+ /* This case used to result in arithmetic underflow and a crash. */
|
|
||||||
+ ASSERT (!rsa_decrypt_for_test (&pub, &key, &random_ctx,
|
|
||||||
+ (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ pub.size, decrypted, gibberish));
|
|
||||||
+
|
|
||||||
/* bad one */
|
|
||||||
memcpy(decrypted, verifybad, PAYLOAD_SIZE);
|
|
||||||
nettle_mpz_random_size(garbage, &random_ctx,
|
|
||||||
--
|
|
||||||
2.31.1
|
|
||||||
|
|
||||||
|
|
||||||
From 743cdf38353f6dd5d3d91eadc769106cfc116301 Mon Sep 17 00:00:00 2001
|
|
||||||
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
|
|
||||||
Date: Tue, 8 Jun 2021 21:30:48 +0200
|
|
||||||
Subject: [PATCH 2/4] Fix comment typos.
|
|
||||||
|
|
||||||
(cherry picked from commit 0a714543136de97c7fd34f1c6ac1592dc5036879)
|
|
||||||
---
|
|
||||||
pkcs1-sec-decrypt.c | 4 ++--
|
|
||||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/pkcs1-sec-decrypt.c b/pkcs1-sec-decrypt.c
|
|
||||||
index 02fd07e1..a7f85c2e 100644
|
|
||||||
--- a/pkcs1-sec-decrypt.c
|
|
||||||
+++ b/pkcs1-sec-decrypt.c
|
|
||||||
@@ -102,8 +102,8 @@ _pkcs1_sec_decrypt_variable(size_t *length, uint8_t *message,
|
|
||||||
|
|
||||||
/* length is discovered in a side-channel silent way.
|
|
||||||
* not_found goes to 0 when the terminator is found.
|
|
||||||
- * offset strts at 3 as it includes the terminator and
|
|
||||||
- * the fomat bytes already */
|
|
||||||
+ * offset starts at 3 as it includes the terminator and
|
|
||||||
+ * the format bytes already */
|
|
||||||
offset = 3;
|
|
||||||
for (i = 2; i < padded_message_length; i++)
|
|
||||||
{
|
|
||||||
--
|
|
||||||
2.31.1
|
|
||||||
|
|
||||||
|
|
||||||
From dfce46c4540d2abf040073070cff15f9d1708050 Mon Sep 17 00:00:00 2001
|
|
||||||
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
|
|
||||||
Date: Tue, 8 Jun 2021 21:31:39 +0200
|
|
||||||
Subject: [PATCH 3/4] Change _rsa_sec_compute_root_tr to take a fix input size.
|
|
||||||
|
|
||||||
Improves consistency with _rsa_sec_compute_root, and fixes zero-input bug.
|
|
||||||
|
|
||||||
(cherry picked from commit 485b5e2820a057e873b1ba812fdb39cae4adf98c)
|
|
||||||
---
|
|
||||||
ChangeLog | 17 +++++++++-
|
|
||||||
rsa-decrypt-tr.c | 7 ++---
|
|
||||||
rsa-internal.h | 4 +--
|
|
||||||
rsa-sec-decrypt.c | 9 ++++--
|
|
||||||
rsa-sign-tr.c | 61 +++++++++++++++++-------------------
|
|
||||||
testsuite/rsa-encrypt-test.c | 14 ++++++++-
|
|
||||||
6 files changed, 69 insertions(+), 43 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/ChangeLog b/ChangeLog
|
|
||||||
index 7cd0455e..ae660fc0 100644
|
|
||||||
--- a/ChangeLog
|
|
||||||
+++ b/ChangeLog
|
|
||||||
@@ -1,6 +1,21 @@
|
|
||||||
-2021-05-06 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
+2021-05-14 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
|
|
||||||
Bug fixes merged from from 3.7.3 release (starting from 2021-05-06).
|
|
||||||
+ * rsa-sign-tr.c (rsa_sec_blind): Delete mn argument.
|
|
||||||
+ (_rsa_sec_compute_root_tr): Delete mn argument, instead require
|
|
||||||
+ that input size matches key size. Rearrange use of temporary
|
|
||||||
+ storage, to support in-place operation, x == m. Update all
|
|
||||||
+ callers.
|
|
||||||
+
|
|
||||||
+ * rsa-decrypt-tr.c (rsa_decrypt_tr): Make zero-padded copy of
|
|
||||||
+ input, for calling _rsa_sec_compute_root_tr.
|
|
||||||
+ * rsa-sec-decrypt.c (rsa_sec_decrypt): Likewise.
|
|
||||||
+
|
|
||||||
+ * testsuite/rsa-encrypt-test.c (test_main): Test calling all of
|
|
||||||
+ rsa_decrypt, rsa_decrypt_tr, and rsa_sec_decrypt with zero input.
|
|
||||||
+
|
|
||||||
+2021-05-06 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
+
|
|
||||||
* pkcs1-sec-decrypt.c (_pkcs1_sec_decrypt): Check that message
|
|
||||||
length is valid, for given key size.
|
|
||||||
* testsuite/rsa-sec-decrypt-test.c (test_main): Add test cases for
|
|
||||||
diff --git a/rsa-decrypt-tr.c b/rsa-decrypt-tr.c
|
|
||||||
index 5dfb91b1..c118e852 100644
|
|
||||||
--- a/rsa-decrypt-tr.c
|
|
||||||
+++ b/rsa-decrypt-tr.c
|
|
||||||
@@ -52,14 +52,13 @@ rsa_decrypt_tr(const struct rsa_public_key *pub,
|
|
||||||
mp_size_t key_limb_size;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
- key_limb_size = NETTLE_OCTET_SIZE_TO_LIMB_SIZE(key->size);
|
|
||||||
+ key_limb_size = mpz_size(pub->n);
|
|
||||||
|
|
||||||
TMP_GMP_ALLOC (m, key_limb_size);
|
|
||||||
TMP_GMP_ALLOC (em, key->size);
|
|
||||||
+ mpz_limbs_copy(m, gibberish, key_limb_size);
|
|
||||||
|
|
||||||
- res = _rsa_sec_compute_root_tr (pub, key, random_ctx, random, m,
|
|
||||||
- mpz_limbs_read(gibberish),
|
|
||||||
- mpz_size(gibberish));
|
|
||||||
+ res = _rsa_sec_compute_root_tr (pub, key, random_ctx, random, m, m);
|
|
||||||
|
|
||||||
mpn_get_base256 (em, key->size, m, key_limb_size);
|
|
||||||
|
|
||||||
diff --git a/rsa-internal.h b/rsa-internal.h
|
|
||||||
index bd667bc2..64a7edf6 100644
|
|
||||||
--- a/rsa-internal.h
|
|
||||||
+++ b/rsa-internal.h
|
|
||||||
@@ -53,12 +53,12 @@ _rsa_sec_compute_root(const struct rsa_private_key *key,
|
|
||||||
mp_limb_t *scratch);
|
|
||||||
|
|
||||||
/* Safe side-channel silent variant, using RSA blinding, and checking the
|
|
||||||
- * result after CRT. */
|
|
||||||
+ * result after CRT. In-place calls, with x == m, is allowed. */
|
|
||||||
int
|
|
||||||
_rsa_sec_compute_root_tr(const struct rsa_public_key *pub,
|
|
||||||
const struct rsa_private_key *key,
|
|
||||||
void *random_ctx, nettle_random_func *random,
|
|
||||||
- mp_limb_t *x, const mp_limb_t *m, size_t mn);
|
|
||||||
+ mp_limb_t *x, const mp_limb_t *m);
|
|
||||||
|
|
||||||
/* additional resistance to memory access side-channel attacks.
|
|
||||||
* Note: message buffer is returned unchanged on error */
|
|
||||||
diff --git a/rsa-sec-decrypt.c b/rsa-sec-decrypt.c
|
|
||||||
index e6a4b267..633a6852 100644
|
|
||||||
--- a/rsa-sec-decrypt.c
|
|
||||||
+++ b/rsa-sec-decrypt.c
|
|
||||||
@@ -57,9 +57,12 @@ rsa_sec_decrypt(const struct rsa_public_key *pub,
|
|
||||||
TMP_GMP_ALLOC (m, mpz_size(pub->n));
|
|
||||||
TMP_GMP_ALLOC (em, key->size);
|
|
||||||
|
|
||||||
- res = _rsa_sec_compute_root_tr (pub, key, random_ctx, random, m,
|
|
||||||
- mpz_limbs_read(gibberish),
|
|
||||||
- mpz_size(gibberish));
|
|
||||||
+ /* We need a copy because m can be shorter than key_size,
|
|
||||||
+ * but _rsa_sec_compute_root_tr expect all inputs to be
|
|
||||||
+ * normalized to a key_size long buffer length */
|
|
||||||
+ mpz_limbs_copy(m, gibberish, mpz_size(pub->n));
|
|
||||||
+
|
|
||||||
+ res = _rsa_sec_compute_root_tr (pub, key, random_ctx, random, m, m);
|
|
||||||
|
|
||||||
mpn_get_base256 (em, key->size, m, mpz_size(pub->n));
|
|
||||||
|
|
||||||
diff --git a/rsa-sign-tr.c b/rsa-sign-tr.c
|
|
||||||
index 59c9bd07..141a52c7 100644
|
|
||||||
--- a/rsa-sign-tr.c
|
|
||||||
+++ b/rsa-sign-tr.c
|
|
||||||
@@ -131,35 +131,34 @@ int
|
|
||||||
_rsa_sec_compute_root_tr(const struct rsa_public_key *pub,
|
|
||||||
const struct rsa_private_key *key,
|
|
||||||
void *random_ctx, nettle_random_func *random,
|
|
||||||
- mp_limb_t *x, const mp_limb_t *m, size_t mn)
|
|
||||||
+ mp_limb_t *x, const mp_limb_t *m)
|
|
||||||
{
|
|
||||||
+ mp_size_t nn;
|
|
||||||
mpz_t mz;
|
|
||||||
mpz_t xz;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
- mpz_init(mz);
|
|
||||||
mpz_init(xz);
|
|
||||||
|
|
||||||
- mpn_copyi(mpz_limbs_write(mz, mn), m, mn);
|
|
||||||
- mpz_limbs_finish(mz, mn);
|
|
||||||
+ nn = mpz_size (pub->n);
|
|
||||||
|
|
||||||
- res = rsa_compute_root_tr(pub, key, random_ctx, random, xz, mz);
|
|
||||||
+ res = rsa_compute_root_tr(pub, key, random_ctx, random, xz,
|
|
||||||
+ mpz_roinit_n(mz, m, nn));
|
|
||||||
|
|
||||||
if (res)
|
|
||||||
- mpz_limbs_copy(x, xz, mpz_size(pub->n));
|
|
||||||
+ mpz_limbs_copy(x, xz, nn);
|
|
||||||
|
|
||||||
- mpz_clear(mz);
|
|
||||||
mpz_clear(xz);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/* Blinds m, by computing c = m r^e (mod n), for a random r. Also
|
|
||||||
- returns the inverse (ri), for use by rsa_unblind. */
|
|
||||||
+ returns the inverse (ri), for use by rsa_unblind. Must have c != m,
|
|
||||||
+ no in-place operation.*/
|
|
||||||
static void
|
|
||||||
rsa_sec_blind (const struct rsa_public_key *pub,
|
|
||||||
void *random_ctx, nettle_random_func *random,
|
|
||||||
- mp_limb_t *c, mp_limb_t *ri, const mp_limb_t *m,
|
|
||||||
- mp_size_t mn)
|
|
||||||
+ mp_limb_t *c, mp_limb_t *ri, const mp_limb_t *m)
|
|
||||||
{
|
|
||||||
const mp_limb_t *ep = mpz_limbs_read (pub->e);
|
|
||||||
const mp_limb_t *np = mpz_limbs_read (pub->n);
|
|
||||||
@@ -177,15 +176,15 @@ rsa_sec_blind (const struct rsa_public_key *pub,
|
|
||||||
|
|
||||||
/* c = m*(r^e) mod n */
|
|
||||||
itch = mpn_sec_powm_itch(nn, ebn, nn);
|
|
||||||
- i2 = mpn_sec_mul_itch(nn, mn);
|
|
||||||
+ i2 = mpn_sec_mul_itch(nn, nn);
|
|
||||||
itch = MAX(itch, i2);
|
|
||||||
- i2 = mpn_sec_div_r_itch(nn + mn, nn);
|
|
||||||
+ i2 = mpn_sec_div_r_itch(2*nn, nn);
|
|
||||||
itch = MAX(itch, i2);
|
|
||||||
i2 = mpn_sec_invert_itch(nn);
|
|
||||||
itch = MAX(itch, i2);
|
|
||||||
|
|
||||||
- TMP_GMP_ALLOC (tp, nn + mn + itch);
|
|
||||||
- scratch = tp + nn + mn;
|
|
||||||
+ TMP_GMP_ALLOC (tp, 2*nn + itch);
|
|
||||||
+ scratch = tp + 2*nn;
|
|
||||||
|
|
||||||
/* ri = r^(-1) */
|
|
||||||
do
|
|
||||||
@@ -198,9 +197,8 @@ rsa_sec_blind (const struct rsa_public_key *pub,
|
|
||||||
while (!mpn_sec_invert (ri, tp, np, nn, 2 * nn * GMP_NUMB_BITS, scratch));
|
|
||||||
|
|
||||||
mpn_sec_powm (c, rp, nn, ep, ebn, np, nn, scratch);
|
|
||||||
- /* normally mn == nn, but m can be smaller in some cases */
|
|
||||||
- mpn_sec_mul (tp, c, nn, m, mn, scratch);
|
|
||||||
- mpn_sec_div_r (tp, nn + mn, np, nn, scratch);
|
|
||||||
+ mpn_sec_mul (tp, c, nn, m, nn, scratch);
|
|
||||||
+ mpn_sec_div_r (tp, 2*nn, np, nn, scratch);
|
|
||||||
mpn_copyi(c, tp, nn);
|
|
||||||
|
|
||||||
TMP_GMP_FREE (r);
|
|
||||||
@@ -208,7 +206,7 @@ rsa_sec_blind (const struct rsa_public_key *pub,
|
|
||||||
TMP_GMP_FREE (tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
-/* m = c ri mod n */
|
|
||||||
+/* m = c ri mod n. Allows x == c. */
|
|
||||||
static void
|
|
||||||
rsa_sec_unblind (const struct rsa_public_key *pub,
|
|
||||||
mp_limb_t *x, mp_limb_t *ri, const mp_limb_t *c)
|
|
||||||
@@ -298,7 +296,7 @@ int
|
|
||||||
_rsa_sec_compute_root_tr(const struct rsa_public_key *pub,
|
|
||||||
const struct rsa_private_key *key,
|
|
||||||
void *random_ctx, nettle_random_func *random,
|
|
||||||
- mp_limb_t *x, const mp_limb_t *m, size_t mn)
|
|
||||||
+ mp_limb_t *x, const mp_limb_t *m)
|
|
||||||
{
|
|
||||||
TMP_GMP_DECL (c, mp_limb_t);
|
|
||||||
TMP_GMP_DECL (ri, mp_limb_t);
|
|
||||||
@@ -306,7 +304,7 @@ _rsa_sec_compute_root_tr(const struct rsa_public_key *pub,
|
|
||||||
size_t key_limb_size;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
- key_limb_size = NETTLE_OCTET_SIZE_TO_LIMB_SIZE(key->size);
|
|
||||||
+ key_limb_size = mpz_size(pub->n);
|
|
||||||
|
|
||||||
/* mpz_powm_sec handles only odd moduli. If p, q or n is even, the
|
|
||||||
key is invalid and rejected by rsa_private_key_prepare. However,
|
|
||||||
@@ -320,19 +318,18 @@ _rsa_sec_compute_root_tr(const struct rsa_public_key *pub,
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(mpz_size(pub->n) == key_limb_size);
|
|
||||||
- assert(mn <= key_limb_size);
|
|
||||||
|
|
||||||
TMP_GMP_ALLOC (c, key_limb_size);
|
|
||||||
TMP_GMP_ALLOC (ri, key_limb_size);
|
|
||||||
TMP_GMP_ALLOC (scratch, _rsa_sec_compute_root_itch(key));
|
|
||||||
|
|
||||||
- rsa_sec_blind (pub, random_ctx, random, x, ri, m, mn);
|
|
||||||
+ rsa_sec_blind (pub, random_ctx, random, c, ri, m);
|
|
||||||
|
|
||||||
- _rsa_sec_compute_root(key, c, x, scratch);
|
|
||||||
+ _rsa_sec_compute_root(key, x, c, scratch);
|
|
||||||
|
|
||||||
- ret = rsa_sec_check_root(pub, c, x);
|
|
||||||
+ ret = rsa_sec_check_root(pub, x, c);
|
|
||||||
|
|
||||||
- rsa_sec_unblind(pub, x, ri, c);
|
|
||||||
+ rsa_sec_unblind(pub, x, ri, x);
|
|
||||||
|
|
||||||
cnd_mpn_zero(1 - ret, x, key_limb_size);
|
|
||||||
|
|
||||||
@@ -356,17 +353,17 @@ rsa_compute_root_tr(const struct rsa_public_key *pub,
|
|
||||||
mpz_t x, const mpz_t m)
|
|
||||||
{
|
|
||||||
TMP_GMP_DECL (l, mp_limb_t);
|
|
||||||
+ mp_size_t nn = mpz_size(pub->n);
|
|
||||||
int res;
|
|
||||||
|
|
||||||
- mp_size_t l_size = NETTLE_OCTET_SIZE_TO_LIMB_SIZE(key->size);
|
|
||||||
- TMP_GMP_ALLOC (l, l_size);
|
|
||||||
+ TMP_GMP_ALLOC (l, nn);
|
|
||||||
+ mpz_limbs_copy(l, m, nn);
|
|
||||||
|
|
||||||
- res = _rsa_sec_compute_root_tr (pub, key, random_ctx, random, l,
|
|
||||||
- mpz_limbs_read(m), mpz_size(m));
|
|
||||||
+ res = _rsa_sec_compute_root_tr (pub, key, random_ctx, random, l, l);
|
|
||||||
if (res) {
|
|
||||||
- mp_limb_t *xp = mpz_limbs_write (x, l_size);
|
|
||||||
- mpn_copyi (xp, l, l_size);
|
|
||||||
- mpz_limbs_finish (x, l_size);
|
|
||||||
+ mp_limb_t *xp = mpz_limbs_write (x, nn);
|
|
||||||
+ mpn_copyi (xp, l, nn);
|
|
||||||
+ mpz_limbs_finish (x, nn);
|
|
||||||
}
|
|
||||||
|
|
||||||
TMP_GMP_FREE (l);
|
|
||||||
diff --git a/testsuite/rsa-encrypt-test.c b/testsuite/rsa-encrypt-test.c
|
|
||||||
index 87525f78..d3bc374b 100644
|
|
||||||
--- a/testsuite/rsa-encrypt-test.c
|
|
||||||
+++ b/testsuite/rsa-encrypt-test.c
|
|
||||||
@@ -19,6 +19,7 @@ test_main(void)
|
|
||||||
uint8_t after;
|
|
||||||
|
|
||||||
mpz_t gibberish;
|
|
||||||
+ mpz_t zero;
|
|
||||||
|
|
||||||
rsa_private_key_init(&key);
|
|
||||||
rsa_public_key_init(&pub);
|
|
||||||
@@ -101,6 +102,17 @@ test_main(void)
|
|
||||||
ASSERT(decrypted[decrypted_length] == after);
|
|
||||||
ASSERT(decrypted[0] == 'A');
|
|
||||||
|
|
||||||
+ /* Test zero input. */
|
|
||||||
+ mpz_init_set_ui (zero, 0);
|
|
||||||
+ decrypted_length = msg_length;
|
|
||||||
+ ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, zero));
|
|
||||||
+ ASSERT(!rsa_decrypt_tr(&pub, &key,
|
|
||||||
+ &lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ &decrypted_length, decrypted, zero));
|
|
||||||
+ ASSERT(!rsa_sec_decrypt(&pub, &key,
|
|
||||||
+ &lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ decrypted_length, decrypted, zero));
|
|
||||||
+ ASSERT(decrypted_length == msg_length);
|
|
||||||
|
|
||||||
/* Test invalid key. */
|
|
||||||
mpz_add_ui (key.q, key.q, 2);
|
|
||||||
@@ -112,6 +124,6 @@ test_main(void)
|
|
||||||
rsa_private_key_clear(&key);
|
|
||||||
rsa_public_key_clear(&pub);
|
|
||||||
mpz_clear(gibberish);
|
|
||||||
+ mpz_clear(zero);
|
|
||||||
free(decrypted);
|
|
||||||
}
|
|
||||||
-
|
|
||||||
--
|
|
||||||
2.31.1
|
|
||||||
|
|
||||||
|
|
||||||
From f601611b3c315aba373c0ab2ddf24772e88c1b3e Mon Sep 17 00:00:00 2001
|
|
||||||
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
|
|
||||||
Date: Tue, 8 Jun 2021 21:32:38 +0200
|
|
||||||
Subject: [PATCH 4/4] Add input check to rsa_decrypt family of functions.
|
|
||||||
|
|
||||||
(cherry picked from commit 0ad0b5df315665250dfdaa4a1e087f4799edaefe)
|
|
||||||
---
|
|
||||||
ChangeLog | 10 +++++++++-
|
|
||||||
rsa-decrypt-tr.c | 4 ++++
|
|
||||||
rsa-decrypt.c | 10 ++++++++++
|
|
||||||
rsa-sec-decrypt.c | 4 ++++
|
|
||||||
rsa.h | 5 +++--
|
|
||||||
testsuite/rsa-encrypt-test.c | 38 ++++++++++++++++++++++++++++++------
|
|
||||||
6 files changed, 62 insertions(+), 9 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/ChangeLog b/ChangeLog
|
|
||||||
index ae660fc0..27f022db 100644
|
|
||||||
--- a/ChangeLog
|
|
||||||
+++ b/ChangeLog
|
|
||||||
@@ -1,6 +1,14 @@
|
|
||||||
-2021-05-14 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
+2021-05-17 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
|
|
||||||
Bug fixes merged from from 3.7.3 release (starting from 2021-05-06).
|
|
||||||
+ * rsa-decrypt-tr.c (rsa_decrypt_tr): Check up-front that input is
|
|
||||||
+ in range.
|
|
||||||
+ * rsa-sec-decrypt.c (rsa_sec_decrypt): Likewise.
|
|
||||||
+ * rsa-decrypt.c (rsa_decrypt): Likewise.
|
|
||||||
+ * testsuite/rsa-encrypt-test.c (test_main): Add tests with input > n.
|
|
||||||
+
|
|
||||||
+2021-05-14 Niels Möller <nisse@lysator.liu.se>
|
|
||||||
+
|
|
||||||
* rsa-sign-tr.c (rsa_sec_blind): Delete mn argument.
|
|
||||||
(_rsa_sec_compute_root_tr): Delete mn argument, instead require
|
|
||||||
that input size matches key size. Rearrange use of temporary
|
|
||||||
diff --git a/rsa-decrypt-tr.c b/rsa-decrypt-tr.c
|
|
||||||
index c118e852..1ba3d286 100644
|
|
||||||
--- a/rsa-decrypt-tr.c
|
|
||||||
+++ b/rsa-decrypt-tr.c
|
|
||||||
@@ -52,6 +52,10 @@ rsa_decrypt_tr(const struct rsa_public_key *pub,
|
|
||||||
mp_size_t key_limb_size;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
+ /* First check that input is in range. */
|
|
||||||
+ if (mpz_sgn (gibberish) < 0 || mpz_cmp (gibberish, pub->n) >= 0)
|
|
||||||
+ return 0;
|
|
||||||
+
|
|
||||||
key_limb_size = mpz_size(pub->n);
|
|
||||||
|
|
||||||
TMP_GMP_ALLOC (m, key_limb_size);
|
|
||||||
diff --git a/rsa-decrypt.c b/rsa-decrypt.c
|
|
||||||
index 7681439d..540d8baa 100644
|
|
||||||
--- a/rsa-decrypt.c
|
|
||||||
+++ b/rsa-decrypt.c
|
|
||||||
@@ -48,6 +48,16 @@ rsa_decrypt(const struct rsa_private_key *key,
|
|
||||||
int res;
|
|
||||||
|
|
||||||
mpz_init(m);
|
|
||||||
+
|
|
||||||
+ /* First check that input is in range. Since we don't have the
|
|
||||||
+ public key available here, we need to reconstruct n. */
|
|
||||||
+ mpz_mul (m, key->p, key->q);
|
|
||||||
+ if (mpz_sgn (gibberish) < 0 || mpz_cmp (gibberish, m) >= 0)
|
|
||||||
+ {
|
|
||||||
+ mpz_clear (m);
|
|
||||||
+ return 0;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
rsa_compute_root(key, m, gibberish);
|
|
||||||
|
|
||||||
res = pkcs1_decrypt (key->size, m, length, message);
|
|
||||||
diff --git a/rsa-sec-decrypt.c b/rsa-sec-decrypt.c
|
|
||||||
index 633a6852..53113c69 100644
|
|
||||||
--- a/rsa-sec-decrypt.c
|
|
||||||
+++ b/rsa-sec-decrypt.c
|
|
||||||
@@ -54,6 +54,10 @@ rsa_sec_decrypt(const struct rsa_public_key *pub,
|
|
||||||
TMP_GMP_DECL (em, uint8_t);
|
|
||||||
int res;
|
|
||||||
|
|
||||||
+ /* First check that input is in range. */
|
|
||||||
+ if (mpz_sgn (gibberish) < 0 || mpz_cmp (gibberish, pub->n) >= 0)
|
|
||||||
+ return 0;
|
|
||||||
+
|
|
||||||
TMP_GMP_ALLOC (m, mpz_size(pub->n));
|
|
||||||
TMP_GMP_ALLOC (em, key->size);
|
|
||||||
|
|
||||||
diff --git a/rsa.h b/rsa.h
|
|
||||||
index 0aac6a26..54c35688 100644
|
|
||||||
--- a/rsa.h
|
|
||||||
+++ b/rsa.h
|
|
||||||
@@ -433,13 +433,14 @@ rsa_sec_decrypt(const struct rsa_public_key *pub,
|
|
||||||
size_t length, uint8_t *message,
|
|
||||||
const mpz_t gibberish);
|
|
||||||
|
|
||||||
-/* Compute x, the e:th root of m. Calling it with x == m is allowed. */
|
|
||||||
+/* Compute x, the e:th root of m. Calling it with x == m is allowed.
|
|
||||||
+ It is required that 0 <= m < n. */
|
|
||||||
void
|
|
||||||
rsa_compute_root(const struct rsa_private_key *key,
|
|
||||||
mpz_t x, const mpz_t m);
|
|
||||||
|
|
||||||
/* Safer variant, using RSA blinding, and checking the result after
|
|
||||||
- CRT. */
|
|
||||||
+ CRT. It is required that 0 <= m < n. */
|
|
||||||
int
|
|
||||||
rsa_compute_root_tr(const struct rsa_public_key *pub,
|
|
||||||
const struct rsa_private_key *key,
|
|
||||||
diff --git a/testsuite/rsa-encrypt-test.c b/testsuite/rsa-encrypt-test.c
|
|
||||||
index d3bc374b..d1a440f6 100644
|
|
||||||
--- a/testsuite/rsa-encrypt-test.c
|
|
||||||
+++ b/testsuite/rsa-encrypt-test.c
|
|
||||||
@@ -19,11 +19,12 @@ test_main(void)
|
|
||||||
uint8_t after;
|
|
||||||
|
|
||||||
mpz_t gibberish;
|
|
||||||
- mpz_t zero;
|
|
||||||
+ mpz_t bad_input;
|
|
||||||
|
|
||||||
rsa_private_key_init(&key);
|
|
||||||
rsa_public_key_init(&pub);
|
|
||||||
mpz_init(gibberish);
|
|
||||||
+ mpz_init(bad_input);
|
|
||||||
|
|
||||||
knuth_lfib_init(&lfib, 17);
|
|
||||||
|
|
||||||
@@ -103,15 +104,40 @@ test_main(void)
|
|
||||||
ASSERT(decrypted[0] == 'A');
|
|
||||||
|
|
||||||
/* Test zero input. */
|
|
||||||
- mpz_init_set_ui (zero, 0);
|
|
||||||
+ mpz_set_ui (bad_input, 0);
|
|
||||||
decrypted_length = msg_length;
|
|
||||||
- ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, zero));
|
|
||||||
+ ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, bad_input));
|
|
||||||
ASSERT(!rsa_decrypt_tr(&pub, &key,
|
|
||||||
&lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
- &decrypted_length, decrypted, zero));
|
|
||||||
+ &decrypted_length, decrypted, bad_input));
|
|
||||||
ASSERT(!rsa_sec_decrypt(&pub, &key,
|
|
||||||
&lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
- decrypted_length, decrypted, zero));
|
|
||||||
+ decrypted_length, decrypted, bad_input));
|
|
||||||
+ ASSERT(decrypted_length == msg_length);
|
|
||||||
+
|
|
||||||
+ /* Test input that is slightly larger than n */
|
|
||||||
+ mpz_add(bad_input, gibberish, pub.n);
|
|
||||||
+ decrypted_length = msg_length;
|
|
||||||
+ ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, bad_input));
|
|
||||||
+ ASSERT(!rsa_decrypt_tr(&pub, &key,
|
|
||||||
+ &lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ &decrypted_length, decrypted, bad_input));
|
|
||||||
+ ASSERT(!rsa_sec_decrypt(&pub, &key,
|
|
||||||
+ &lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ decrypted_length, decrypted, bad_input));
|
|
||||||
+ ASSERT(decrypted_length == msg_length);
|
|
||||||
+
|
|
||||||
+ /* Test input that is considerably larger than n */
|
|
||||||
+ mpz_mul_2exp (bad_input, pub.n, 100);
|
|
||||||
+ mpz_add (bad_input, bad_input, gibberish);
|
|
||||||
+ decrypted_length = msg_length;
|
|
||||||
+ ASSERT(!rsa_decrypt(&key, &decrypted_length, decrypted, bad_input));
|
|
||||||
+ ASSERT(!rsa_decrypt_tr(&pub, &key,
|
|
||||||
+ &lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ &decrypted_length, decrypted, bad_input));
|
|
||||||
+ ASSERT(!rsa_sec_decrypt(&pub, &key,
|
|
||||||
+ &lfib, (nettle_random_func *) knuth_lfib_random,
|
|
||||||
+ decrypted_length, decrypted, bad_input));
|
|
||||||
ASSERT(decrypted_length == msg_length);
|
|
||||||
|
|
||||||
/* Test invalid key. */
|
|
||||||
@@ -124,6 +150,6 @@ test_main(void)
|
|
||||||
rsa_private_key_clear(&key);
|
|
||||||
rsa_public_key_clear(&pub);
|
|
||||||
mpz_clear(gibberish);
|
|
||||||
- mpz_clear(zero);
|
|
||||||
+ mpz_clear(bad_input);
|
|
||||||
free(decrypted);
|
|
||||||
}
|
|
||||||
--
|
|
||||||
2.31.1
|
|
||||||
|
|
40
SOURCES/nettle-3.7.2-suppress-maybe-uninit.patch
Normal file
40
SOURCES/nettle-3.7.2-suppress-maybe-uninit.patch
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
From 952c2d890902782ee90b6ed273f1d8b4e95dbff1 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Daiki Ueno <dueno@redhat.com>
|
||||||
|
Date: Sun, 21 Mar 2021 11:13:36 +0100
|
||||||
|
Subject: [PATCH] nettle-benchmark: suppress -Wmaybe-uninitialized warnings
|
||||||
|
|
||||||
|
---
|
||||||
|
examples/nettle-benchmark.c | 3 +++
|
||||||
|
1 file changed, 3 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c
|
||||||
|
index ca6346e0..518b947d 100644
|
||||||
|
--- a/examples/nettle-benchmark.c
|
||||||
|
+++ b/examples/nettle-benchmark.c
|
||||||
|
@@ -392,6 +392,7 @@ time_umac(void)
|
||||||
|
|
||||||
|
uint8_t key[16];
|
||||||
|
|
||||||
|
+ init_key(sizeof(key), key);
|
||||||
|
umac32_set_key (&ctx32, key);
|
||||||
|
info.ctx = &ctx32;
|
||||||
|
info.update = (nettle_hash_update_func *) umac32_update;
|
||||||
|
@@ -434,6 +435,7 @@ time_cmac(void)
|
||||||
|
|
||||||
|
uint8_t key[16];
|
||||||
|
|
||||||
|
+ init_key(sizeof(key), key);
|
||||||
|
cmac_aes128_set_key (&ctx, key);
|
||||||
|
info.ctx = &ctx;
|
||||||
|
info.update = (nettle_hash_update_func *) cmac_aes128_update;
|
||||||
|
@@ -451,6 +453,7 @@ time_poly1305_aes(void)
|
||||||
|
struct poly1305_aes_ctx ctx;
|
||||||
|
uint8_t key[32];
|
||||||
|
|
||||||
|
+ init_key(sizeof(key), key);
|
||||||
|
poly1305_aes_set_key (&ctx, key);
|
||||||
|
info.ctx = &ctx;
|
||||||
|
info.update = (nettle_hash_update_func *) poly1305_aes_update;
|
||||||
|
--
|
||||||
|
2.30.2
|
||||||
|
|
@ -1,24 +1,35 @@
|
|||||||
|
# Recent so-version, so we do not bump accidentally.
|
||||||
|
%global nettle_so_ver 8
|
||||||
|
%global hogweed_so_ver 6
|
||||||
|
|
||||||
|
# Set to 1 when building a bootstrap for a bumped so-name.
|
||||||
|
%global bootstrap 0
|
||||||
|
|
||||||
|
%if 0%{?bootstrap}
|
||||||
|
%global version_old 3.5.1
|
||||||
|
%global nettle_so_ver_old 7
|
||||||
|
%global hogweed_so_ver_old 5
|
||||||
|
%endif
|
||||||
|
|
||||||
%bcond_without fips
|
%bcond_without fips
|
||||||
|
|
||||||
Name: nettle
|
Name: nettle
|
||||||
Version: 3.4.1
|
Version: 3.7.3
|
||||||
Release: 7%{?dist}
|
Release: 2%{?dist}
|
||||||
Summary: A low-level cryptographic library
|
Summary: A low-level cryptographic library
|
||||||
|
|
||||||
Group: Development/Libraries
|
|
||||||
License: LGPLv3+ or GPLv2+
|
License: LGPLv3+ or GPLv2+
|
||||||
URL: http://www.lysator.liu.se/~nisse/nettle/
|
URL: http://www.lysator.liu.se/~nisse/nettle/
|
||||||
Source0: %{name}-%{version}-hobbled.tar.xz
|
Source0: %{name}-%{version}-hobbled.tar.xz
|
||||||
#Source0: http://www.lysator.liu.se/~nisse/archive/%{name}-%{version}.tar.gz
|
#Source0: http://www.lysator.liu.se/~nisse/archive/%{name}-%{version}.tar.gz
|
||||||
Patch0: nettle-3.3-remove-ecc-testsuite.patch
|
%if 0%{?bootstrap}
|
||||||
Patch1: nettle-3.4-annocheck.patch
|
Source1: %{name}-%{version_old}-hobbled.tar.xz
|
||||||
Patch2: nettle-3.4.1-enable-intel-cet.patch
|
Source2: nettle-3.5-remove-ecc-testsuite.patch
|
||||||
# https://lists.lysator.liu.se/pipermail/nettle-bugs/2021/009458.html
|
%endif
|
||||||
Patch3: nettle-3.4.1-ecdsa-verify.patch
|
Patch0: nettle-3.4-annocheck.patch
|
||||||
Patch4: nettle-3.4.1-powerpc64-aes-asm.patch
|
Patch1: nettle-3.7.2-suppress-maybe-uninit.patch
|
||||||
Patch5: nettle-3.4.1-powerpc64-ghash-asm.patch
|
|
||||||
Patch6: nettle-3.4.1-rsa-decrypt.patch
|
|
||||||
|
|
||||||
|
BuildRequires: make
|
||||||
BuildRequires: gcc
|
BuildRequires: gcc
|
||||||
BuildRequires: gmp-devel, m4
|
BuildRequires: gmp-devel, m4
|
||||||
BuildRequires: libtool, automake, autoconf, gettext-devel
|
BuildRequires: libtool, automake, autoconf, gettext-devel
|
||||||
@ -26,13 +37,8 @@ BuildRequires: libtool, automake, autoconf, gettext-devel
|
|||||||
BuildRequires: fipscheck
|
BuildRequires: fipscheck
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
Requires(post): info
|
|
||||||
Requires(preun): info
|
|
||||||
|
|
||||||
|
|
||||||
%package devel
|
%package devel
|
||||||
Summary: Development headers for a low-level cryptographic library
|
Summary: Development headers for a low-level cryptographic library
|
||||||
Group: Development/Libraries
|
|
||||||
Requires: %{name} = %{version}-%{release}
|
Requires: %{name} = %{version}-%{release}
|
||||||
Requires: gmp-devel%{?_isa}
|
Requires: gmp-devel%{?_isa}
|
||||||
|
|
||||||
@ -51,38 +57,72 @@ applications with nettle.
|
|||||||
|
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q
|
%autosetup -Tb 0 -p1
|
||||||
|
|
||||||
|
%if 0%{?bootstrap}
|
||||||
|
mkdir -p bootstrap_ver
|
||||||
|
pushd bootstrap_ver
|
||||||
|
tar --strip-components=1 -xf %{SOURCE1}
|
||||||
|
patch -p1 < %{SOURCE2}
|
||||||
|
|
||||||
# Disable -ggdb3 which makes debugedit unhappy
|
# Disable -ggdb3 which makes debugedit unhappy
|
||||||
sed s/ggdb3/g/ -i configure
|
sed s/ggdb3/g/ -i configure
|
||||||
sed 's/ecc-192.c//g' -i Makefile.in
|
sed 's/ecc-192.c//g' -i Makefile.in
|
||||||
sed 's/ecc-224.c//g' -i Makefile.in
|
sed 's/ecc-224.c//g' -i Makefile.in
|
||||||
%patch0 -p1
|
popd
|
||||||
%patch1 -p1
|
%endif
|
||||||
%patch2 -p1
|
|
||||||
%patch3 -p1
|
# Disable -ggdb3 which makes debugedit unhappy
|
||||||
%patch4 -p1
|
sed s/ggdb3/g/ -i configure
|
||||||
%patch5 -p1
|
sed 's/ecc-secp192r1.c//g' -i Makefile.in
|
||||||
%patch6 -p1
|
sed 's/ecc-secp224r1.c//g' -i Makefile.in
|
||||||
|
|
||||||
%build
|
%build
|
||||||
autoreconf -ifv
|
autoreconf -ifv
|
||||||
%configure --enable-shared --enable-fat
|
%configure --enable-shared --enable-fat
|
||||||
make %{?_smp_mflags}
|
%make_build
|
||||||
|
|
||||||
|
%if 0%{?bootstrap}
|
||||||
|
pushd bootstrap_ver
|
||||||
|
autoconf
|
||||||
|
%configure --with-tests
|
||||||
|
%make_build
|
||||||
|
popd
|
||||||
|
%endif
|
||||||
|
|
||||||
%if %{with fips}
|
%if %{with fips}
|
||||||
|
%define fipshmac() \
|
||||||
|
fipshmac -d $RPM_BUILD_ROOT%{_libdir} $RPM_BUILD_ROOT%{_libdir}/%1.* \
|
||||||
|
file=`basename $RPM_BUILD_ROOT%{_libdir}/%1.*.hmac` && \
|
||||||
|
mv $RPM_BUILD_ROOT%{_libdir}/$file $RPM_BUILD_ROOT%{_libdir}/.$file && \
|
||||||
|
ln -s .$file $RPM_BUILD_ROOT%{_libdir}/.%1.hmac
|
||||||
|
|
||||||
|
%if 0%{?bootstrap}
|
||||||
|
%define bootstrap_fips 1
|
||||||
|
%endif
|
||||||
|
|
||||||
%define __spec_install_post \
|
%define __spec_install_post \
|
||||||
%{?__debug_package:%{__debug_install_post}} \
|
%{?__debug_package:%{__debug_install_post}} \
|
||||||
%{__arch_install_post} \
|
%{__arch_install_post} \
|
||||||
%{__os_install_post} \
|
%{__os_install_post} \
|
||||||
fipshmac -d $RPM_BUILD_ROOT%{_libdir} $RPM_BUILD_ROOT%{_libdir}/libnettle.so.6.* \
|
%fipshmac libnettle.so.%{nettle_so_ver} \
|
||||||
fipshmac -d $RPM_BUILD_ROOT%{_libdir} $RPM_BUILD_ROOT%{_libdir}/libhogweed.so.4.* \
|
%fipshmac libhogweed.so.%{hogweed_so_ver} \
|
||||||
file=`basename $RPM_BUILD_ROOT%{_libdir}/libnettle.so.6.*.hmac` && mv $RPM_BUILD_ROOT%{_libdir}/$file $RPM_BUILD_ROOT%{_libdir}/.$file && ln -s .$file $RPM_BUILD_ROOT%{_libdir}/.libnettle.so.6.hmac \
|
%{?bootstrap_fips:%fipshmac libnettle.so.%{nettle_so_ver_old}} \
|
||||||
file=`basename $RPM_BUILD_ROOT%{_libdir}/libhogweed.so.4.*.hmac` && mv $RPM_BUILD_ROOT%{_libdir}/$file $RPM_BUILD_ROOT%{_libdir}/.$file && ln -s .$file $RPM_BUILD_ROOT%{_libdir}/.libhogweed.so.4.hmac \
|
%{?bootstrap_fips:%fipshmac libhogweed.so.%{hogweed_so_ver_old}} \
|
||||||
%{nil}
|
%{nil}
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
|
||||||
%install
|
%install
|
||||||
make install DESTDIR=$RPM_BUILD_ROOT INSTALL="install -p"
|
%if 0%{?bootstrap}
|
||||||
|
make -C bootstrap_ver install-shared-nettle DESTDIR=$RPM_BUILD_ROOT INSTALL="install -p"
|
||||||
|
make -C bootstrap_ver install-shared-hogweed DESTDIR=$RPM_BUILD_ROOT INSTALL="install -p"
|
||||||
|
|
||||||
|
chmod 0755 $RPM_BUILD_ROOT%{_libdir}/libnettle.so.%{nettle_so_ver_old}.*
|
||||||
|
chmod 0755 $RPM_BUILD_ROOT%{_libdir}/libhogweed.so.%{hogweed_so_ver_old}.*
|
||||||
|
%endif
|
||||||
|
|
||||||
|
%make_install
|
||||||
make install-shared DESTDIR=$RPM_BUILD_ROOT INSTALL="install -p"
|
make install-shared DESTDIR=$RPM_BUILD_ROOT INSTALL="install -p"
|
||||||
mkdir -p $RPM_BUILD_ROOT%{_infodir}
|
mkdir -p $RPM_BUILD_ROOT%{_infodir}
|
||||||
install -p -m 644 nettle.info $RPM_BUILD_ROOT%{_infodir}/
|
install -p -m 644 nettle.info $RPM_BUILD_ROOT%{_infodir}/
|
||||||
@ -94,20 +134,26 @@ rm -f $RPM_BUILD_ROOT%{_bindir}/sexp-conv
|
|||||||
rm -f $RPM_BUILD_ROOT%{_bindir}/nettle-hash
|
rm -f $RPM_BUILD_ROOT%{_bindir}/nettle-hash
|
||||||
rm -f $RPM_BUILD_ROOT%{_bindir}/nettle-pbkdf2
|
rm -f $RPM_BUILD_ROOT%{_bindir}/nettle-pbkdf2
|
||||||
|
|
||||||
chmod 0755 $RPM_BUILD_ROOT%{_libdir}/libnettle.so.6.*
|
chmod 0755 $RPM_BUILD_ROOT%{_libdir}/libnettle.so.%{nettle_so_ver}.*
|
||||||
chmod 0755 $RPM_BUILD_ROOT%{_libdir}/libhogweed.so.4.*
|
chmod 0755 $RPM_BUILD_ROOT%{_libdir}/libhogweed.so.%{hogweed_so_ver}.*
|
||||||
|
|
||||||
%check
|
%check
|
||||||
make check
|
make check
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%doc AUTHORS NEWS README TODO
|
%doc AUTHORS NEWS README
|
||||||
%license COPYINGv2 COPYING.LESSERv3
|
%license COPYINGv2 COPYING.LESSERv3
|
||||||
%{_infodir}/nettle.info.gz
|
%{_infodir}/nettle.info.*
|
||||||
%{_libdir}/libnettle.so.6
|
%{_libdir}/libnettle.so.%{nettle_so_ver}
|
||||||
%{_libdir}/libnettle.so.6.*
|
%{_libdir}/libnettle.so.%{nettle_so_ver}.*
|
||||||
%{_libdir}/libhogweed.so.4
|
%{_libdir}/libhogweed.so.%{hogweed_so_ver}
|
||||||
%{_libdir}/libhogweed.so.4.*
|
%{_libdir}/libhogweed.so.%{hogweed_so_ver}.*
|
||||||
|
%if 0%{?bootstrap}
|
||||||
|
%{_libdir}/libnettle.so.%{nettle_so_ver_old}
|
||||||
|
%{_libdir}/libnettle.so.%{nettle_so_ver_old}.*
|
||||||
|
%{_libdir}/libhogweed.so.%{hogweed_so_ver_old}
|
||||||
|
%{_libdir}/libhogweed.so.%{hogweed_so_ver_old}.*
|
||||||
|
%endif
|
||||||
%if %{with fips}
|
%if %{with fips}
|
||||||
%{_libdir}/.libhogweed.so.*.hmac
|
%{_libdir}/.libhogweed.so.*.hmac
|
||||||
%{_libdir}/.libnettle.so.*.hmac
|
%{_libdir}/.libnettle.so.*.hmac
|
||||||
@ -121,45 +167,84 @@ make check
|
|||||||
%{_libdir}/pkgconfig/hogweed.pc
|
%{_libdir}/pkgconfig/hogweed.pc
|
||||||
%{_libdir}/pkgconfig/nettle.pc
|
%{_libdir}/pkgconfig/nettle.pc
|
||||||
|
|
||||||
%post
|
%ldconfig_scriptlets
|
||||||
/sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :
|
|
||||||
/sbin/ldconfig
|
|
||||||
|
|
||||||
%preun
|
|
||||||
if [ $1 = 0 ]; then
|
|
||||||
/sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || :
|
|
||||||
fi
|
|
||||||
|
|
||||||
%postun -p /sbin/ldconfig
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Wed Jul 14 2021 Daiki Ueno <dueno@redhat.com> - 3.4.1-7
|
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 3.7.3-2
|
||||||
- Backport CVE-2021-3580 from upstream 3.7.3 release (#1967990)
|
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
|
||||||
|
Related: rhbz#1991688
|
||||||
|
|
||||||
* Wed Jul 14 2021 Daiki Ueno <dueno@redhat.com> - 3.4.1-6
|
* Wed Jul 28 2021 Daiki Ueno <dueno@redhat.com> - 3.7.3-1
|
||||||
- Enable CTR mode optimization when the block size is 16
|
- Update to nettle 3.7.3 (#1986712)
|
||||||
|
|
||||||
* Wed Jun 30 2021 Daiki Ueno <dueno@redhat.com> - 3.4.1-5
|
* Fri Apr 16 2021 Mohan Boddu <mboddu@redhat.com> - 3.7.2-2
|
||||||
- Backport powerpc64 optimization patches from upstream (#1855228)
|
- Rebuilt for RHEL 9 BETA on Apr 15th 2021. Related: rhbz#1947937
|
||||||
Patch from Christopher M. Riedl.
|
|
||||||
|
|
||||||
* Wed Apr 7 2021 Daiki Ueno <dueno@redhat.com> - 3.4.1-4
|
* Sun Mar 21 2021 Daiki Ueno <dueno@redhat.com> - 3.7.2-1
|
||||||
- Fix patch application
|
- Update to nettle 3.7.2
|
||||||
|
- Merge nettle-3.6-remove-ecc-testsuite.patch to hobble-nettle script
|
||||||
|
|
||||||
* Tue Mar 30 2021 Daiki Ueno <dueno@redhat.com> - 3.4.1-3
|
* Tue Mar 9 2021 Daiki Ueno <dueno@redhat.com> - 3.7.1-1
|
||||||
- Port fixes for potential miscalculation in ecdsa_verify (#1942925)
|
- Update to nettle 3.7.1
|
||||||
|
|
||||||
* Fri May 15 2020 Anderson Sasaki <ansasaki@redhat.com> - 3.4.1-2
|
* Wed Feb 10 2021 Daiki Ueno <dueno@redhat.com> - 3.7-3
|
||||||
- Enable Intel CET support (#1737542)
|
- Port a fix for chacha counter issue on ppc64le
|
||||||
|
|
||||||
* Tue Dec 11 2018 Daiki Ueno <dueno@redhat.com> - 3.4.1-1
|
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.7-2
|
||||||
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
|
||||||
|
|
||||||
|
* Mon Jan 11 2021 Daiki Ueno <dueno@redhat.com> - 3.7-1
|
||||||
|
- Update to nettle 3.7
|
||||||
|
|
||||||
|
* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 3.6-3
|
||||||
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
|
||||||
|
|
||||||
|
* Tue Jul 14 2020 Tom Stellard <tstellar@redhat.com> - 3.6-2
|
||||||
|
- Use make macros
|
||||||
|
- https://fedoraproject.org/wiki/Changes/UseMakeBuildInstallMacro
|
||||||
|
|
||||||
|
* Mon May 4 2020 Daiki Ueno <dueno@redhat.com> - 3.6-1
|
||||||
|
- Update to nettle 3.6
|
||||||
|
|
||||||
|
* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 3.5.1-5
|
||||||
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
|
||||||
|
|
||||||
|
* Thu Oct 31 2019 Nikos Mavrogiannopoulos <nmav@redhat.com> - 3.5.1-4
|
||||||
- New upstream release
|
- New upstream release
|
||||||
|
|
||||||
* Tue Oct 16 2018 Tomáš Mráz <tmraz@redhat.com> - 3.4-4
|
* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 3.5.1-3
|
||||||
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
|
||||||
|
|
||||||
|
* Tue Jul 16 2019 Daiki Ueno <dueno@redhat.com> - 3.5.1-2
|
||||||
|
- Rebuild with bootstrap enabled
|
||||||
|
|
||||||
|
* Mon Jul 15 2019 Nikos Mavrogiannopoulos <nmav@redhat.com> - 3.5.1-1
|
||||||
|
- New upstream release
|
||||||
|
|
||||||
|
* Wed Apr 24 2019 Björn Esser <besser82@fedoraproject.org> - 3.4.1rc1-3
|
||||||
|
- Remove hardcoded gzip suffix from GNU info pages
|
||||||
|
|
||||||
|
* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 3.4.1rc1-2
|
||||||
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
|
||||||
|
|
||||||
|
* Fri Nov 30 2018 Nikos Mavrogiannopoulos <nmav@redhat.com> - 3.4.1rc1-1
|
||||||
|
- New upstream release; provides API for constant memory access RSA operations
|
||||||
|
|
||||||
|
* Tue Oct 16 2018 Tomáš Mráz <tmraz@redhat.com> - 3.4-7
|
||||||
|
- Generate the .hmac checksums unless --without fips is used
|
||||||
|
|
||||||
|
* Tue Oct 16 2018 Tomáš Mráz <tmraz@redhat.com> - 3.4-6
|
||||||
- Cover the gaps in annotation coverage for assembler sources
|
- Cover the gaps in annotation coverage for assembler sources
|
||||||
- Add .hmac checksums for FIPS mode integrity checking
|
|
||||||
|
* Fri Aug 31 2018 Leigh Scott <leigh123linux@googlemail.com> - 3.4-5
|
||||||
|
- update libary versions used for fips
|
||||||
|
|
||||||
|
* Sat Jul 28 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 3.4-4
|
||||||
|
- Replace obsolete scriptlets
|
||||||
|
|
||||||
|
* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 3.4-3
|
||||||
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
|
||||||
|
|
||||||
* Thu Feb 08 2018 Fedora Release Engineering <releng@fedoraproject.org> - 3.4-2
|
* Thu Feb 08 2018 Fedora Release Engineering <releng@fedoraproject.org> - 3.4-2
|
||||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
|
||||||
|
Loading…
Reference in New Issue
Block a user