diff options
author | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2011-12-01 18:43:39 +0100 |
---|---|---|
committer | Benjamin Dauvergne <bdauvergne@entrouvert.com> | 2011-12-05 12:03:12 +0100 |
commit | 10edf69bfc0a88df2d7f83c0bb45f0967f9fa3b9 (patch) | |
tree | 7dd7b0c7f02cee18a14453e43d4da2919a0fc6f0 | |
parent | 9de6450f4c0f2db9d87c30741a7229b22fb4744e (diff) | |
download | lasso-10edf69bfc0a88df2d7f83c0bb45f0967f9fa3b9.tar.gz lasso-10edf69bfc0a88df2d7f83c0bb45f0967f9fa3b9.tar.xz lasso-10edf69bfc0a88df2d7f83c0bb45f0967f9fa3b9.zip |
[utils] add lasso_crypto_memequal function
This method compare byte strings in constant time.
-rw-r--r-- | lasso/utils.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lasso/utils.h b/lasso/utils.h index 0a58271c..465f4b6a 100644 --- a/lasso/utils.h +++ b/lasso/utils.h @@ -685,4 +685,24 @@ lasso_xmlstrisnotequal(const xmlChar *a, const xmlChar *b) { return lasso_strisnotequal((char*)a, (char*)b); } +/** + * lasso_crypto_memequal: + * @a: first buffer + * @b: second buffer + * @l: common length + * + * Compare two buffers, preventing timing attacks. + */ +static inline gboolean +lasso_crypto_memequal(void *a, void *b, unsigned int l) +{ + unsigned char *x = a, *y = b; + gboolean result = TRUE; + + for (;l;l--, x++, y++) { + result = result && (*x == *y); + } + return result; +} + #endif /* __LASSO_UTILS_H__ */ |