diff options
author | Richard Levitte <levitte@openssl.org> | 2020-07-09 08:40:50 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-07-11 10:00:33 +0200 |
commit | 310a0edbd003dd7c580ae3cf78f1782b2c3d9ded (patch) | |
tree | 46fc233a14e17822b083744811beb8a138fc5699 /crypto | |
parent | e23d850ff3281220f33ed78d9ca4fcadfa279565 (diff) |
BN: Check endianness in run-time, in BN_native2bn() and BN_bn2nativepad()
The code relied on B_ENDIAN being defined on all big-endian platform,
which turned out to not always be the case.
Fixes #12387
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/12390)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/bn/bn_lib.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index a0924d0e31..57783e47d8 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -10,6 +10,7 @@ #include <assert.h> #include <limits.h> #include "internal/cryptlib.h" +#include "internal/endian.h" #include "bn_local.h" #include <openssl/opensslconf.h> #include "internal/constant_time.h" @@ -583,20 +584,20 @@ int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen) BIGNUM *BN_native2bn(const unsigned char *s, int len, BIGNUM *ret) { -#ifdef B_ENDIAN + DECLARE_IS_ENDIAN; + + if (IS_LITTLE_ENDIAN) + return BN_lebin2bn(s, len, ret); return BN_bin2bn(s, len, ret); -#else - return BN_lebin2bn(s, len, ret); -#endif } int BN_bn2nativepad(const BIGNUM *a, unsigned char *to, int tolen) { -#ifdef B_ENDIAN + DECLARE_IS_ENDIAN; + + if (IS_LITTLE_ENDIAN) + return BN_bn2lebinpad(a, to, tolen); return BN_bn2binpad(a, to, tolen); -#else - return BN_bn2lebinpad(a, to, tolen); -#endif } int BN_ucmp(const BIGNUM *a, const BIGNUM *b) |