rand: remove unimplemented librandom stub code
[openssl.git] / crypto / info.c
index 05edbc3fc8b5077923994e5f85f04209aba70b9e..c823283279ba9837e9243f5fd48168314220f32c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -21,6 +21,9 @@
 #elif defined(__s390__) || defined(__s390x__)
 # include "s390x_arch.h"
 # define CPU_INFO_STR_LEN 2048
+#elif defined(__riscv)
+# include "crypto/riscv_arch.h"
+# define CPU_INFO_STR_LEN 2048
 #else
 # define CPU_INFO_STR_LEN 128
 #endif
@@ -45,10 +48,10 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings)
 
     BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
                  CPUINFO_PREFIX "OPENSSL_ia32cap=0x%llx:0x%llx",
-                 (long long)OPENSSL_ia32cap_P[0] |
-                 (long long)OPENSSL_ia32cap_P[1] << 32,
-                 (long long)OPENSSL_ia32cap_P[2] |
-                 (long long)OPENSSL_ia32cap_P[3] << 32);
+                 (unsigned long long)OPENSSL_ia32cap_P[0] |
+                 (unsigned long long)OPENSSL_ia32cap_P[1] << 32,
+                 (unsigned long long)OPENSSL_ia32cap_P[2] |
+                 (unsigned long long)OPENSSL_ia32cap_P[3] << 32);
     if ((env = getenv("OPENSSL_ia32cap")) != NULL)
         BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
                      sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
@@ -98,6 +101,33 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings)
         BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
                      sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
                      " env:%s", env);
+# elif defined(__riscv)
+    const char *env;
+    char sep = '=';
+
+    BIO_snprintf(ossl_cpu_info_str, sizeof(ossl_cpu_info_str),
+                 CPUINFO_PREFIX "OPENSSL_riscvcap");
+    for (size_t i = 0; i < kRISCVNumCaps; ++i) {
+        if (OPENSSL_riscvcap_P[RISCV_capabilities[i].index]
+                & (1 << RISCV_capabilities[i].bit_offset)) {
+            /* Match, display the name */
+            BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
+                         sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
+                         "%c%s", sep, RISCV_capabilities[i].name);
+            /* Only the first sep is '=' */
+            sep = '_';
+        }
+    }
+    /* If no capability is found, add back the = */
+    if (sep == '=') {
+        BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
+                     sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
+                     "%c", sep);
+    }
+    if ((env = getenv("OPENSSL_riscvcap")) != NULL)
+        BIO_snprintf(ossl_cpu_info_str + strlen(ossl_cpu_info_str),
+                     sizeof(ossl_cpu_info_str) - strlen(ossl_cpu_info_str),
+                     " env:%s", env);
 # endif
 #endif
 
@@ -131,8 +161,8 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings)
 #ifdef OPENSSL_RAND_SEED_NONE
         add_seeds_string("none");
 #endif
-#ifdef OPENSSL_RAND_SEED_RTDSC
-        add_seeds_string("stdsc");
+#ifdef OPENSSL_RAND_SEED_RDTSC
+        add_seeds_string("rdtsc");
 #endif
 #ifdef OPENSSL_RAND_SEED_RDCPU
 # ifdef __aarch64__
@@ -141,9 +171,6 @@ DEFINE_RUN_ONCE_STATIC(init_info_strings)
         add_seeds_string("rdrand ( rdseed rdrand )");
 # endif
 #endif
-#ifdef OPENSSL_RAND_SEED_LIBRANDOM
-        add_seeds_string("C-library-random");
-#endif
 #ifdef OPENSSL_RAND_SEED_GETRANDOM
         add_seeds_string("getrandom-syscall");
 #endif