#include "crypto/sparse_array.h"
#include "rsa_local.h"
#include "internal/constant_time.h"
+#if defined(OPENSSL_SYS_TANDEM)
+# include "internal/tsan_assist.h"
+# include "internal/threads_common.h"
+#endif
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
return r;
}
+#if defined(OPENSSL_SYS_TANDEM)
+static TSAN_QUALIFIER uint64_t tsan_thread_id = 1;
+#endif
+
+static uintptr_t get_unique_thread_id(void)
+{
+#if defined(OPENSSL_SYS_TANDEM)
+ uintptr_t thread_id = (uintptr_t)CRYPTO_THREAD_get_local_ex(CRYPTO_THREAD_LOCAL_TANDEM_ID_KEY,
+ NULL);
+
+ if (thread_id == 0) {
+ thread_id = tsan_counter(&tsan_thread_id);
+ CRYPTO_THREAD_set_local_ex(CRYPTO_THREAD_LOCAL_TANDEM_ID_KEY, NULL, (void *)thread_id);
+ }
+ return thread_id;
+#else
+ return (uintptr_t)CRYPTO_THREAD_get_current_id();
+#endif
+}
+
static void free_bn_blinding(ossl_uintmax_t idx, BN_BLINDING *b, void *arg)
{
BN_BLINDING_free(b);
static BN_BLINDING *ossl_rsa_get_thread_bn_blinding(RSA *rsa)
{
SPARSE_ARRAY_OF(BN_BLINDING) *blindings = rsa->blindings_sa;
- uintptr_t tid = (uintptr_t)CRYPTO_THREAD_get_current_id();
+ uintptr_t tid = get_unique_thread_id();
return ossl_sa_BN_BLINDING_get(blindings, tid);
}
static int ossl_rsa_set_thread_bn_blinding(RSA *rsa, BN_BLINDING *b)
{
SPARSE_ARRAY_OF(BN_BLINDING) *blindings = rsa->blindings_sa;
- uintptr_t tid = (uintptr_t)CRYPTO_THREAD_get_current_id();
+ uintptr_t tid = get_unique_thread_id();
return ossl_sa_BN_BLINDING_set(blindings, tid, b);
}
# endif
#endif
+#if !defined(RUSAGE_SELF) && defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
+# include <sys/times.h>
+#endif
int main(int ac, char **av)
{
#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L
struct stat sb;
FILE *fp;
char *contents;
+# if !defined(RUSAGE_SELF)
+ struct tms rus;
+ struct timeval u_start, u_end, u_elapsed;
+ struct timeval s_start, s_end, s_elapsed;
+# else
struct rusage start, end, elapsed;
+# endif
struct timeval e_start, e_end, e_elapsed;
/* Parse JCL. */
perror("elapsed start");
exit(EXIT_FAILURE);
}
+# if !defined(RUSAGE_SELF)
+ times(&rus);
+ u_start.tv_sec = rus.tms_utime / CLOCKS_PER_SEC;
+ u_start.tv_usec = (rus.tms_utime * 1000000) / CLOCKS_PER_SEC;
+ s_start.tv_sec = rus.tms_stime / CLOCKS_PER_SEC;
+ s_start.tv_usec = (rus.tms_stime * 1000000) / CLOCKS_PER_SEC;
+# else
if (getrusage(RUSAGE_SELF, &start) < 0) {
OPENSSL_free(contents);
perror("start");
exit(EXIT_FAILURE);
}
+# endif
for (i = count; i > 0; i--) {
switch (what) {
case 'c':
break;
}
}
+# if !defined(RUSAGE_SELF)
+ times(&rus);
+ u_end.tv_sec = rus.tms_utime / CLOCKS_PER_SEC;
+ u_end.tv_usec = (rus.tms_utime * 1000000) / CLOCKS_PER_SEC;
+ s_end.tv_sec = rus.tms_stime / CLOCKS_PER_SEC;
+ s_end.tv_usec = (rus.tms_stime * 1000000) / CLOCKS_PER_SEC;
+# else
if (getrusage(RUSAGE_SELF, &end) < 0) {
OPENSSL_free(contents);
perror("getrusage");
exit(EXIT_FAILURE);
}
+# endif
if (gettimeofday(&e_end, NULL) < 0) {
OPENSSL_free(contents);
perror("gettimeofday");
exit(EXIT_FAILURE);
}
+# if !defined(RUSAGE_SELF)
+ timersub(&u_end, &u_start, &u_elapsed);
+ timersub(&s_end, &s_start, &s_elapsed);
+# else
timersub(&end.ru_utime, &start.ru_stime, &elapsed.ru_stime);
timersub(&end.ru_utime, &start.ru_utime, &elapsed.ru_utime);
+# endif
timersub(&e_end, &e_start, &e_elapsed);
+# if !defined(RUSAGE_SELF)
+ print_timeval("user ", &u_elapsed);
+ print_timeval("sys ", &s_elapsed);
+# else
print_timeval("user ", &elapsed.ru_utime);
print_timeval("sys ", &elapsed.ru_stime);
+# endif
if (debug)
print_timeval("elapsed??", &e_elapsed);