Skip to content

Commit

Permalink
Ensure BN_ULONG is correctly defined for 32-bit architectures
Browse files Browse the repository at this point in the history
Use __SIZEOF_LONG__ to define either SIXTY_FOUR_BIT_LONG or
THIRTY_TWO_BIT consistenly in crypto's bn_conf.h and openssl's
configuration.h.

Otherwise, for example on i386, the openssl bignum routines will attempt
to use 32-bit shifts on 32-bit unsigned longs, which is undefined
behavior.
  • Loading branch information
DimitryAndric committed Jun 9, 2023
1 parent 5c15257 commit 61d17d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
20 changes: 11 additions & 9 deletions crypto/openssl/include/crypto/bn_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
/* Should we define BN_DIV2W here? */

/* Only one for the following should be defined */
#ifdef __LP64__
#define SIXTY_FOUR_BIT_LONG
#undef SIXTY_FOUR_BIT
#undef THIRTY_TWO_BIT
#else
#undef SIXTY_FOUR_BIT_LONG
#undef SIXTY_FOUR_BIT
#define THIRTY_TWO_BIT
#endif
# if __SIZEOF_LONG__ == 8
# define SIXTY_FOUR_BIT_LONG
# undef SIXTY_FOUR_BIT
# undef THIRTY_TWO_BIT
# elif __SIZEOF_LONG__ == 4
# undef SIXTY_FOUR_BIT_LONG
# undef SIXTY_FOUR_BIT
# define THIRTY_TWO_BIT
# else
# error Unsupported size of long
# endif

#endif
18 changes: 14 additions & 4 deletions crypto/openssl/include/openssl/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,21 @@ extern "C" {
* The following are cipher-specific, but are part of the public API.
*/
# if !defined(OPENSSL_SYS_UEFI)
# undef BN_LLONG
# if __SIZEOF_LONG__ == 8
# undef BN_LLONG
/* Only one for the following should be defined */
# define SIXTY_FOUR_BIT_LONG
# undef SIXTY_FOUR_BIT
# undef THIRTY_TWO_BIT
# define SIXTY_FOUR_BIT_LONG
# undef SIXTY_FOUR_BIT
# undef THIRTY_TWO_BIT
# elif __SIZEOF_LONG__ == 4
# define BN_LLONG
/* Only one for the following should be defined */
# undef SIXTY_FOUR_BIT_LONG
# undef SIXTY_FOUR_BIT
# define THIRTY_TWO_BIT
# else
# error Unsupported size of long
# endif
# endif

# define RC4_INT unsigned int
Expand Down

0 comments on commit 61d17d8

Please sign in to comment.