ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] util: Add a constant time version of l_memeq
@ 2021-02-10 23:36 Andrew Zaborowski
  2021-02-10 23:36 ` [PATCH 2/3] pem/cert/tls: Use l_secure_memeq for verifying padding Andrew Zaborowski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Zaborowski @ 2021-02-10 23:36 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 1253 bytes --]

---
 ell/ell.sym |  1 +
 ell/util.c  | 12 ++++++++++++
 ell/util.h  |  1 +
 3 files changed, 14 insertions(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index aa0c046..9938216 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -21,6 +21,7 @@ global:
 	l_util_debug;
 	l_util_get_debugfs_path;
 	l_memeq;
+	l_secure_memeq;
 	/* test */
 	l_test_init;
 	l_test_run;
diff --git a/ell/util.c b/ell/util.c
index 6896bc8..5b443a9 100644
--- a/ell/util.c
+++ b/ell/util.c
@@ -652,3 +652,15 @@ LIB_EXPORT bool l_memeq(const void *field, size_t size, uint8_t byte)
 
 	return true;
 }
+
+LIB_EXPORT bool l_secure_memeq(const void *field, size_t size, uint8_t byte)
+{
+	const volatile uint8_t *mem = field;
+	size_t i;
+	bool diff = false;
+
+	for (i = 0; i < size; i++)
+		diff |= mem[i] != byte;
+
+	return !diff;
+}
diff --git a/ell/util.h b/ell/util.h
index 11708c2..b112878 100644
--- a/ell/util.h
+++ b/ell/util.h
@@ -412,6 +412,7 @@ static inline int l_secure_memcmp(const void *a, const void *b,
 }
 
 bool l_memeq(const void *field, size_t size, uint8_t byte);
+bool l_secure_memeq(const void *field, size_t size, uint8_t byte);
 
 static inline bool l_memeqzero(const void *field, size_t size)
 {
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-10 23:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 23:36 [PATCH 1/3] util: Add a constant time version of l_memeq Andrew Zaborowski
2021-02-10 23:36 ` [PATCH 2/3] pem/cert/tls: Use l_secure_memeq for verifying padding Andrew Zaborowski
2021-02-10 23:36 ` [PATCH 3/3] pem/cert: Ensure RFC8018/RFC1423 padding isn't 0 Andrew Zaborowski
2021-02-10 23:47 ` [PATCH 1/3] util: Add a constant time version of l_memeq Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).