summaryrefslogtreecommitdiffstats
path: root/crypto/crypto.h
diff options
context:
space:
mode:
authorBen Laurie <ben@links.org>2013-01-28 17:30:38 +0000
committerBen Laurie <ben@links.org>2013-01-28 17:30:38 +0000
commit2ee798880a246d648ecddadc5b91367bee4a5d98 (patch)
tree519fae50d830922bb0f0cf55bd8da81f373e6395 /crypto/crypto.h
parentffcf4c61641068918e36b738b9464a16d0488e43 (diff)
Add and use a constant-time memcmp.
This change adds CRYPTO_memcmp, which compares two vectors of bytes in an amount of time that's independent of their contents. It also changes several MAC compares in the code to use this over the standard memcmp, which may leak information about the size of a matching prefix.
Diffstat (limited to 'crypto/crypto.h')
-rw-r--r--crypto/crypto.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/crypto/crypto.h b/crypto/crypto.h
index 61605769bb..f92fc5182d 100644
--- a/crypto/crypto.h
+++ b/crypto/crypto.h
@@ -574,6 +574,13 @@ void OPENSSL_init(void);
#define fips_cipher_abort(alg) while(0)
#endif
+/* CRYPTO_memcmp returns zero iff the |len| bytes at |a| and |b| are equal. It
+ * takes an amount of time dependent on |len|, but independent of the contents
+ * of |a| and |b|. Unlike memcmp, it cannot be used to put elements into a
+ * defined order as the return value when a != b is undefined, other than to be
+ * non-zero. */
+int CRYPTO_memcmp(const void *a, const void *b, size_t len);
+
/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.