2

Been writing code that uses OpenSSL, and I've noticed that, confusingly, most of the crypto library functions return 1 for success and 0 for failure:

So my question is, why does OpenSSL not use the typical C/POSIX standard return values ?

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
wesinat0r
  • 121
  • 8
  • Possible duplicate of [Why does OpenSSL return 0 even though there's an error?](https://stackoverflow.com/questions/19888630/why-does-openssl-return-0-even-though-theres-an-error) – wesinat0r Mar 08 '19 at 17:37

1 Answers1

3

Traditionally, in C, an integer value of 0 stands for false and 1 stands for true and OpenSSL follows that convention. See this section of the Wikipedia page about the Boolean data type for some context:

Initial implementations of the language C (1972) provided no Boolean type, and to this day Boolean values are commonly represented by integers (ints) in C programs. The comparison operators (>, ==, etc.) are defined to return a signed integer (int) result, either 0 (for false) or 1 (for true).

This has changed somewhat with the introduction of the _Bool type in C99 but the initial implementation OpenSSL predates that -- hence the use of the integer values of 0 and 1. Also, in some cases OpenSSL functions use different integer values to indicate different types of results.

The SO answer on return values that you have pointed to is specifically about the special case of the exit value of a process, to be returned to its parent. Indeed, for that particular situation a value of zero indicates success. But that is not a typical approach applied to function return values in general.

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69