err/err.c: add err_clear_last_constant_time.
authorAndy Polyakov <appro@openssl.org>
Sat, 1 Sep 2018 10:19:30 +0000 (12:19 +0200)
committerMatt Caswell <matt@openssl.org>
Fri, 30 Nov 2018 12:51:58 +0000 (12:51 +0000)
Expected usage pattern is to unconditionally set error and then
wipe it if there was no actual error.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit f658a3b64d8750642f4975090740865f770c2a1b)

crypto/err/err.c
include/internal/constant_time_locl.h

index 34061bc662fc661337bbc965eeb4da8939098e47..66a60e907cd96b766b2779e19e827566ece13c9e 100644 (file)
@@ -20,6 +20,7 @@
 #include <openssl/opensslconf.h>
 #include "internal/thread_once.h"
 #include "internal/ctype.h"
+#include "internal/constant_time_locl.h"
 
 static int err_load_strings(const ERR_STRING_DATA *str);
 
@@ -878,3 +879,23 @@ int ERR_clear_last_mark(void)
     es->err_flags[top] &= ~ERR_FLAG_MARK;
     return 1;
 }
+
+void err_clear_last_constant_time(int clear)
+{
+    ERR_STATE *es;
+    int top;
+
+    es = ERR_get_state();
+    if (es == NULL)
+        return;
+
+    top = es->top;
+
+    es->err_flags[top] &= ~(0 - clear);
+    es->err_buffer[top] &= ~(0UL - clear);
+    es->err_file[top] = (const char *)((uintptr_t)es->err_file[top] &
+                                       ~((uintptr_t)0 - clear));
+    es->err_line[top] |= 0 - clear;
+
+    es->top = (top + ERR_NUM_ERRORS - clear) % ERR_NUM_ERRORS;
+}
index 82ff74652ecca58f74c11c6754b52a176cf530b7..cde30f4067ef19c17627fc89a3803db8996b1d5a 100644 (file)
@@ -324,4 +324,10 @@ static ossl_inline void constant_time_lookup(void *out,
     }
 }
 
+/*
+ * Expected usage pattern is to unconditionally set error and then
+ * wipe it if there was no actual error. |clear| is 1 or 0.
+ */
+void err_clear_last_constant_time(int clear);
+
 #endif                          /* HEADER_CONSTANT_TIME_LOCL_H */