]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - openssl.c
openssl: Introduce openssl_perror().
[paraslash.git] / openssl.c
index e34169499dcc9bfa14560b41d08cf5516465eec1..6dba1b270f5e77fbf285614902ec4e71f95a380e 100644 (file)
--- a/openssl.c
+++ b/openssl.c
@@ -24,15 +24,21 @@ struct asymmetric_key {
        RSA *rsa;
 };
 
+static int openssl_perror(const char *pfx)
+{
+       unsigned long err = ERR_get_error();
+       PARA_ERROR_LOG("%s: \"%s\"\n", pfx, ERR_reason_error_string(err));
+       return -E_OPENSSL;
+}
+
 void get_random_bytes_or_die(unsigned char *buf, int num)
 {
-       unsigned long err;
+       int ret;
 
-       /* RAND_bytes() returns 1 on success, 0 otherwise. */
-       if (RAND_bytes(buf, num) == 1)
+       if (RAND_bytes(buf, num) == 1) /* success */
                return;
-       err = ERR_get_error();
-       PARA_EMERG_LOG("%s\n", ERR_reason_error_string(err));
+       ret = openssl_perror("RAND_bytes");
+       PARA_EMERG_LOG("%s\n", strerror(-ret));
        exit(EXIT_FAILURE);
 }