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
| ... | ... |
@@ -66,24 +66,6 @@ |
| 66 | 66 |
#define CRYPT_ERROR(format) \ |
| 67 | 67 |
do { msg (D_CRYPT_ERRORS, "%s: " format, error_prefix); goto error_exit; } while (false)
|
| 68 | 68 |
|
| 69 |
-/** |
|
| 70 |
- * As memcmp(), but constant-time. |
|
| 71 |
- * Returns 0 when data is equal, non-zero otherwise. |
|
| 72 |
- */ |
|
| 73 |
-static int |
|
| 74 |
-memcmp_constant_time (const void *a, const void *b, size_t size) {
|
|
| 75 |
- const uint8_t * a1 = a; |
|
| 76 |
- const uint8_t * b1 = b; |
|
| 77 |
- int ret = 0; |
|
| 78 |
- size_t i; |
|
| 79 |
- |
|
| 80 |
- for (i = 0; i < size; i++) {
|
|
| 81 |
- ret |= *a1++ ^ *b1++; |
|
| 82 |
- } |
|
| 83 |
- |
|
| 84 |
- return ret; |
|
| 85 |
-} |
|
| 86 |
- |
|
| 87 | 69 |
static void |
| 88 | 70 |
openvpn_encrypt_aead (struct buffer *buf, struct buffer work, |
| 89 | 71 |
struct crypto_options *opt) {
|
| ... | ... |
@@ -476,6 +476,24 @@ void get_tls_handshake_key (const struct key_type *key_type, |
| 476 | 476 |
* Inline functions |
| 477 | 477 |
*/ |
| 478 | 478 |
|
| 479 |
+/** |
|
| 480 |
+ * As memcmp(), but constant-time. |
|
| 481 |
+ * Returns 0 when data is equal, non-zero otherwise. |
|
| 482 |
+ */ |
|
| 483 |
+static inline int |
|
| 484 |
+memcmp_constant_time (const void *a, const void *b, size_t size) {
|
|
| 485 |
+ const uint8_t * a1 = a; |
|
| 486 |
+ const uint8_t * b1 = b; |
|
| 487 |
+ int ret = 0; |
|
| 488 |
+ size_t i; |
|
| 489 |
+ |
|
| 490 |
+ for (i = 0; i < size; i++) {
|
|
| 491 |
+ ret |= *a1++ ^ *b1++; |
|
| 492 |
+ } |
|
| 493 |
+ |
|
| 494 |
+ return ret; |
|
| 495 |
+} |
|
| 496 |
+ |
|
| 479 | 497 |
static inline bool |
| 480 | 498 |
key_ctx_bi_defined(const struct key_ctx_bi* key) |
| 481 | 499 |
{
|