File 0001-err-err.c-add-err_clear_last_constant_time.patch of Package openssl-1_1.10336
From d2cd28b99efa65dbd39cb8db0f2ad992be1aab00 Mon Sep 17 00:00:00 2001
From: Andy Polyakov <appro@openssl.org>
Date: Sat, 1 Sep 2018 12:19:30 +0200
Subject: [PATCH 1/5] err/err.c: add err_clear_last_constant_time.
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 | 21 +++++++++++++++++++++
include/internal/constant_time_locl.h | 6 ++++++
2 files changed, 27 insertions(+)
Index: openssl-1.1.1/crypto/err/err.c
===================================================================
--- openssl-1.1.1.orig/crypto/err/err.c 2019-02-08 14:10:07.477744462 +0100
+++ openssl-1.1.1/crypto/err/err.c 2019-02-08 14:10:31.797882486 +0100
@@ -19,6 +19,7 @@
#include <openssl/bio.h>
#include <openssl/opensslconf.h>
#include "internal/thread_once.h"
+#include "internal/constant_time_locl.h"
static int err_load_strings(const ERR_STRING_DATA *str);
@@ -857,3 +858,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: openssl-1.1.1/include/internal/constant_time_locl.h
===================================================================
--- openssl-1.1.1.orig/include/internal/constant_time_locl.h 2019-02-08 14:10:07.477744462 +0100
+++ openssl-1.1.1/include/internal/constant_time_locl.h 2019-02-08 14:10:11.505767323 +0100
@@ -324,4 +324,10 @@ static ossl_inline void constant_time_lo
}
}
+/*
+ * 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 */