]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Move memcmp_constant_time() to crypto.h
authorDavid Sommerseth <davids@openvpn.net>
Thu, 13 Oct 2016 19:59:27 +0000 (21:59 +0200)
committerDavid Sommerseth <davids@openvpn.net>
Fri, 14 Oct 2016 08:37:50 +0000 (10:37 +0200)
This function is quite useful other places, so make it generally
accessible.

[DS: changed function declaration to static inline during commit]

Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Steffan Karger <steffan@karger.me>
Message-Id: <1476388771-16492-2-git-send-email-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg12698.html

src/openvpn/crypto.c
src/openvpn/crypto.h

index 3dd4a9ebc0550740c6484a5e96e6f0cd1d7447d5..026d9aeb2a0defef90f4d5991192b3e7b6011b5b 100644 (file)
 #define CRYPT_ERROR(format) \
   do { msg (D_CRYPT_ERRORS, "%s: " format, error_prefix); goto error_exit; } while (false)
 
-/**
- * As memcmp(), but constant-time.
- * Returns 0 when data is equal, non-zero otherwise.
- */
-static int
-memcmp_constant_time (const void *a, const void *b, size_t size) {
-  const uint8_t * a1 = a;
-  const uint8_t * b1 = b;
-  int ret = 0;
-  size_t i;
-
-  for (i = 0; i < size; i++) {
-      ret |= *a1++ ^ *b1++;
-  }
-
-  return ret;
-}
-
 static void
 openvpn_encrypt_aead (struct buffer *buf, struct buffer work,
         struct crypto_options *opt) {
index 3b6bb98057bf413f98328c78463cf71a9ef5927b..4b90c674eb084dcb9fe828cf25079effceea4b21 100644 (file)
@@ -476,6 +476,24 @@ void get_tls_handshake_key (const struct key_type *key_type,
  * Inline functions
  */
 
+/**
+ * As memcmp(), but constant-time.
+ * Returns 0 when data is equal, non-zero otherwise.
+ */
+static inline int
+memcmp_constant_time (const void *a, const void *b, size_t size) {
+  const uint8_t * a1 = a;
+  const uint8_t * b1 = b;
+  int ret = 0;
+  size_t i;
+
+  for (i = 0; i < size; i++) {
+      ret |= *a1++ ^ *b1++;
+  }
+
+  return ret;
+}
+
 static inline bool
 key_ctx_bi_defined(const struct key_ctx_bi* key)
 {