diff options
author | Ben Laurie <ben@links.org> | 2013-01-28 17:30:38 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2013-02-06 13:56:12 +0000 |
commit | f5cd3561ba9363e6bcc58fcb6b1e94930f81967d (patch) | |
tree | a4d926b0e59470d717c082e85006c6961e1e1efb /crypto/crypto.h | |
parent | 115f7fa5625580b8ec7850c093ba4e334756da92 (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.
(cherry picked from commit 2ee798880a246d648ecddadc5b91367bee4a5d98)
Diffstat (limited to 'crypto/crypto.h')
-rw-r--r-- | crypto/crypto.h | 7 |
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. |