summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordjm <>2018-09-05 00:55:33 +0000
committerdjm <>2018-09-05 00:55:33 +0000
commit500c35c4f020d87efbd1b5f638d51d78cce1b5ea (patch)
treee041735a97a92c3a22eab8257b329a2e73d4f9b0 /src/lib
parenta707e9b3b7839a52fa4e75b9c174d23c7dd8b683 (diff)
downloadopenbsd-500c35c4f020d87efbd1b5f638d51d78cce1b5ea.tar.gz
openbsd-500c35c4f020d87efbd1b5f638d51d78cce1b5ea.tar.bz2
openbsd-500c35c4f020d87efbd1b5f638d51d78cce1b5ea.zip
use timing-safe compares for checking results in signature verification
(there are no known attacks, this is just inexpensive prudence) feedback and ok tb@ jsing@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/rsa/rsa_pmeth.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_pss.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c7
4 files changed, 10 insertions, 9 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_pmeth.c b/src/lib/libcrypto/rsa/rsa_pmeth.c
index b4a4e730c0..ea6401b3da 100644
--- a/src/lib/libcrypto/rsa/rsa_pmeth.c
+++ b/src/lib/libcrypto/rsa/rsa_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_pmeth.c,v 1.20 2017/08/28 17:41:59 jsing Exp $ */ 1/* $OpenBSD: rsa_pmeth.c,v 1.21 2018/09/05 00:55:33 djm Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006. 3 * project 2006.
4 */ 4 */
@@ -296,7 +296,7 @@ pkey_rsa_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
296 return 0; 296 return 0;
297 } 297 }
298 298
299 if (rslen != tbslen || memcmp(tbs, rctx->tbuf, rslen)) 299 if (rslen != tbslen || timingsafe_bcmp(tbs, rctx->tbuf, rslen))
300 return 0; 300 return 0;
301 301
302 return 1; 302 return 1;
diff --git a/src/lib/libcrypto/rsa/rsa_pss.c b/src/lib/libcrypto/rsa/rsa_pss.c
index 870f634b8d..562f7b252c 100644
--- a/src/lib/libcrypto/rsa/rsa_pss.c
+++ b/src/lib/libcrypto/rsa/rsa_pss.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_pss.c,v 1.12 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: rsa_pss.c,v 1.13 2018/09/05 00:55:33 djm Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2005. 3 * project 2005.
4 */ 4 */
@@ -163,7 +163,7 @@ RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
163 } 163 }
164 if (!EVP_DigestFinal_ex(&ctx, H_, NULL)) 164 if (!EVP_DigestFinal_ex(&ctx, H_, NULL))
165 goto err; 165 goto err;
166 if (memcmp(H_, H, hLen)) { 166 if (timingsafe_bcmp(H_, H, hLen)) {
167 RSAerror(RSA_R_BAD_SIGNATURE); 167 RSAerror(RSA_R_BAD_SIGNATURE);
168 ret = 0; 168 ret = 0;
169 } else 169 } else
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
index e1fbdcb5df..93492ac503 100644
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_saos.c,v 1.23 2017/05/02 03:59:45 deraadt Exp $ */ 1/* $OpenBSD: rsa_saos.c,v 1.24 2018/09/05 00:55:33 djm Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -130,7 +130,7 @@ RSA_verify_ASN1_OCTET_STRING(int dtype, const unsigned char *m,
130 goto err; 130 goto err;
131 131
132 if ((unsigned int)sig->length != m_len || 132 if ((unsigned int)sig->length != m_len ||
133 memcmp(m, sig->data, m_len) != 0) { 133 timingsafe_bcmp(m, sig->data, m_len) != 0) {
134 RSAerror(RSA_R_BAD_SIGNATURE); 134 RSAerror(RSA_R_BAD_SIGNATURE);
135 } else 135 } else
136 ret = 1; 136 ret = 1;
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index 2383259dda..50e07f4f1e 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_sign.c,v 1.30 2018/07/23 17:37:17 tb Exp $ */ 1/* $OpenBSD: rsa_sign.c,v 1.31 2018/09/05 00:55:33 djm Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -214,7 +214,8 @@ int_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
214 RSAerror(RSA_R_INVALID_MESSAGE_LENGTH); 214 RSAerror(RSA_R_INVALID_MESSAGE_LENGTH);
215 goto err; 215 goto err;
216 } 216 }
217 if (memcmp(decrypt_buf, m, SSL_SIG_LENGTH) != 0) { 217 if (timingsafe_bcmp(decrypt_buf,
218 m, SSL_SIG_LENGTH) != 0) {
218 RSAerror(RSA_R_BAD_SIGNATURE); 219 RSAerror(RSA_R_BAD_SIGNATURE);
219 goto err; 220 goto err;
220 } 221 }
@@ -244,7 +245,7 @@ int_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
244 goto err; 245 goto err;
245 246
246 if (encoded_len != decrypt_len || 247 if (encoded_len != decrypt_len ||
247 memcmp(encoded, decrypt_buf, encoded_len) != 0) { 248 timingsafe_bcmp(encoded, decrypt_buf, encoded_len) != 0) {
248 RSAerror(RSA_R_BAD_SIGNATURE); 249 RSAerror(RSA_R_BAD_SIGNATURE);
249 goto err; 250 goto err;
250 } 251 }