4

I'm trying to use openssl dsa implementation, but I'm very confused with the following details:

  • Option '-text' of the command openssl dsa ....: the hexadecimal numbers in the output, am I correct to assume that those are the bytes, and thus they are in little-Endian order?

  • Functions BN_bn2hex and BN_hex2bn, what Endianess they use?

Thanks in advance for the help.

indiv
  • 17,306
  • 6
  • 61
  • 82
dsign
  • 12,340
  • 6
  • 59
  • 82

1 Answers1

11

OpenSSL treats all series of bytes (unsigned char arrays) as big endian.

The functions BN_bn2hex and BN_hex2bn are for converting to and from a printable format. Printable formats are always in natural reading order, which is big endian.

For non-printable format conversions like bn2bin, the documentation explicitly states that the conversion is big endian. But like I said before, the convention in OpenSSL is big endian for all series of bytes.

indiv
  • 17,306
  • 6
  • 61
  • 82
  • 1
    @indiv Does this mean I have to do byte swapping for any data that should be passed to OpenSSL API if the code is running on a little endian machine? – user3342339 Jan 17 '17 at 19:48
  • 2
    @user3342339: No. Only sequence of bytes (typically `unsigned char[]` or `unsigned char *`) that represent numbers are interpreted as big endian. API functions that accept primitive types like `int` or `long` are host format, as you'd expect. – indiv Jan 17 '17 at 19:59