From: Matt Caswell Date: Wed, 2 Aug 2017 13:46:31 +0000 (+0100) Subject: Move ossl_assert X-Git-Tag: OpenSSL_1_1_1-pre1~902 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=67dc995eaf538ea309c6292a1a5073465201f55b;p=oweals%2Fopenssl.git Move ossl_assert Move the definition of ossl_assert() out of e_os.h which is intended for OS specific things. Instead it is moved into internal/cryptlib.h. This also changes the definition to remove the (int) cast. Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/4073) --- diff --git a/crypto/include/internal/cryptlib.h b/crypto/include/internal/cryptlib.h deleted file mode 100644 index d2ab720d34..0000000000 --- a/crypto/include/internal/cryptlib.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the OpenSSL license (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#ifndef HEADER_CRYPTLIB_H -# define HEADER_CRYPTLIB_H - -# include -# include - -# include "e_os.h" - -# ifdef OPENSSL_USE_APPLINK -# undef BIO_FLAGS_UPLINK -# define BIO_FLAGS_UPLINK 0x8000 -# include "ms/uplink.h" -# endif - -# include -# include -# include -# include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ex_callback_st EX_CALLBACK; - -DEFINE_STACK_OF(EX_CALLBACK) - -typedef struct app_mem_info_st APP_INFO; - -typedef struct mem_st MEM; -DEFINE_LHASH_OF(MEM); - -# ifndef OPENSSL_SYS_VMS -# define X509_CERT_AREA OPENSSLDIR -# define X509_CERT_DIR OPENSSLDIR "/certs" -# define X509_CERT_FILE OPENSSLDIR "/cert.pem" -# define X509_PRIVATE_DIR OPENSSLDIR "/private" -# define CTLOG_FILE OPENSSLDIR "/ct_log_list.cnf" -# else -# define X509_CERT_AREA "OSSL$DATAROOT:[000000]" -# define X509_CERT_DIR "OSSL$DATAROOT:[CERTS]" -# define X509_CERT_FILE "OSSL$DATAROOT:[000000]cert.pem" -# define X509_PRIVATE_DIR "OSSL$DATAROOT:[PRIVATE]" -# define CTLOG_FILE "OSSL$DATAROOT:[000000]ct_log_list.cnf" -# endif - -# define X509_CERT_DIR_EVP "SSL_CERT_DIR" -# define X509_CERT_FILE_EVP "SSL_CERT_FILE" -# define CTLOG_FILE_EVP "CTLOG_FILE" - -/* size of string representations */ -# define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) -# define HEX_SIZE(type) (sizeof(type)*2) - -void OPENSSL_cpuid_setup(void); -extern unsigned int OPENSSL_ia32cap_P[]; -void OPENSSL_showfatal(const char *fmta, ...); -extern int OPENSSL_NONPIC_relocated; -void crypto_cleanup_all_ex_data_int(void); -int openssl_init_fork_handlers(void); - -int openssl_strerror_r(int errnum, char *buf, size_t buflen); -# if !defined(OPENSSL_NO_STDIO) -FILE *openssl_fopen(const char *filename, const char *mode); -# else -void *openssl_fopen(const char *filename, const char *mode); -# endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/e_os.h b/e_os.h index 7138c7a181..d4cef609bb 100644 --- a/e_os.h +++ b/e_os.h @@ -545,23 +545,6 @@ struct servent *getservbyname(const char *name, const char *proto); # define CRYPTO_memcmp memcmp #endif -#ifdef NDEBUG -# define ossl_assert(x) (int)(x) -#else -__owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr, - const char *file, int line) -{ - if (!expr) - OPENSSL_die(exprstr, file, line); - - return expr; -} - -# define ossl_assert(x) ossl_assert_int((int)(x), "Assertion failed: "#x, \ - __FILE__, __LINE__) - -#endif - #ifdef __cplusplus } #endif diff --git a/include/internal/cryptlib.h b/include/internal/cryptlib.h new file mode 100644 index 0000000000..c73c754242 --- /dev/null +++ b/include/internal/cryptlib.h @@ -0,0 +1,99 @@ +/* + * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef HEADER_CRYPTLIB_H +# define HEADER_CRYPTLIB_H + +# include +# include + +# include "e_os.h" + +# ifdef OPENSSL_USE_APPLINK +# undef BIO_FLAGS_UPLINK +# define BIO_FLAGS_UPLINK 0x8000 +# include "ms/uplink.h" +# endif + +# include +# include +# include +# include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef NDEBUG +# define ossl_assert(x) ((x) != 0) +#else +__owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr, + const char *file, int line) +{ + if (!expr) + OPENSSL_die(exprstr, file, line); + + return expr; +} + +# define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \ + __FILE__, __LINE__) + +#endif + +typedef struct ex_callback_st EX_CALLBACK; + +DEFINE_STACK_OF(EX_CALLBACK) + +typedef struct app_mem_info_st APP_INFO; + +typedef struct mem_st MEM; +DEFINE_LHASH_OF(MEM); + +# ifndef OPENSSL_SYS_VMS +# define X509_CERT_AREA OPENSSLDIR +# define X509_CERT_DIR OPENSSLDIR "/certs" +# define X509_CERT_FILE OPENSSLDIR "/cert.pem" +# define X509_PRIVATE_DIR OPENSSLDIR "/private" +# define CTLOG_FILE OPENSSLDIR "/ct_log_list.cnf" +# else +# define X509_CERT_AREA "OSSL$DATAROOT:[000000]" +# define X509_CERT_DIR "OSSL$DATAROOT:[CERTS]" +# define X509_CERT_FILE "OSSL$DATAROOT:[000000]cert.pem" +# define X509_PRIVATE_DIR "OSSL$DATAROOT:[PRIVATE]" +# define CTLOG_FILE "OSSL$DATAROOT:[000000]ct_log_list.cnf" +# endif + +# define X509_CERT_DIR_EVP "SSL_CERT_DIR" +# define X509_CERT_FILE_EVP "SSL_CERT_FILE" +# define CTLOG_FILE_EVP "CTLOG_FILE" + +/* size of string representations */ +# define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) +# define HEX_SIZE(type) (sizeof(type)*2) + +void OPENSSL_cpuid_setup(void); +extern unsigned int OPENSSL_ia32cap_P[]; +void OPENSSL_showfatal(const char *fmta, ...); +extern int OPENSSL_NONPIC_relocated; +void crypto_cleanup_all_ex_data_int(void); +int openssl_init_fork_handlers(void); + +int openssl_strerror_r(int errnum, char *buf, size_t buflen); +# if !defined(OPENSSL_NO_STDIO) +FILE *openssl_fopen(const char *filename, const char *mode); +# else +void *openssl_fopen(const char *filename, const char *mode); +# endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ssl/packet.c b/ssl/packet.c index 7c4be4fee5..7a4414ae6a 100644 --- a/ssl/packet.c +++ b/ssl/packet.c @@ -7,7 +7,7 @@ * https://www.openssl.org/source/license.html */ -#include "e_os.h" +#include "internal/cryptlib.h" #include "packet_locl.h" #define DEFAULT_BUF_SIZE 256 diff --git a/ssl/record/rec_layer_d1.c b/ssl/record/rec_layer_d1.c index 83f40943f3..75e3aebdf2 100644 --- a/ssl/record/rec_layer_d1.c +++ b/ssl/record/rec_layer_d1.c @@ -15,6 +15,7 @@ #include #include "record_locl.h" #include "../packet_locl.h" +#include "internal/cryptlib.h" int DTLS_RECORD_LAYER_new(RECORD_LAYER *rl) { diff --git a/ssl/record/ssl3_record.c b/ssl/record/ssl3_record.c index bd27290aa8..afb03fde5b 100644 --- a/ssl/record/ssl3_record.c +++ b/ssl/record/ssl3_record.c @@ -11,6 +11,7 @@ #include "internal/constant_time_locl.h" #include #include "record_locl.h" +#include "internal/cryptlib.h" static const unsigned char ssl3_pad_1[48] = { 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, diff --git a/ssl/record/ssl3_record_tls13.c b/ssl/record/ssl3_record_tls13.c index 61e209254e..ec8f9f9e8f 100644 --- a/ssl/record/ssl3_record_tls13.c +++ b/ssl/record/ssl3_record_tls13.c @@ -9,6 +9,7 @@ #include "../ssl_locl.h" #include "record_locl.h" +#include "internal/cryptlib.h" /*- * tls13_enc encrypts/decrypts |n_recs| in |recs|. diff --git a/ssl/s3_cbc.c b/ssl/s3_cbc.c index bab9b26816..7d9c377697 100644 --- a/ssl/s3_cbc.c +++ b/ssl/s3_cbc.c @@ -9,6 +9,7 @@ #include "internal/constant_time_locl.h" #include "ssl_locl.h" +#include "internal/cryptlib.h" #include #include diff --git a/ssl/s3_enc.c b/ssl/s3_enc.c index e33c07fdcc..bef9f99e7d 100644 --- a/ssl/s3_enc.c +++ b/ssl/s3_enc.c @@ -12,6 +12,7 @@ #include "ssl_locl.h" #include #include +#include "internal/cryptlib.h" static int ssl3_generate_key_block(SSL *s, unsigned char *km, int num) { diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c index 47f715d29e..914d0d8f4a 100644 --- a/ssl/ssl_ciph.c +++ b/ssl/ssl_ciph.c @@ -17,6 +17,7 @@ #include #include "ssl_locl.h" #include "internal/thread_once.h" +#include "internal/cryptlib.h" #define SSL_ENC_DES_IDX 0 #define SSL_ENC_3DES_IDX 1 diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 491023f835..048669c451 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -20,6 +20,7 @@ #include #include #include +#include "internal/cryptlib.h" const char SSL_version_str[] = OPENSSL_VERSION_TEXT; diff --git a/ssl/statem/extensions_clnt.c b/ssl/statem/extensions_clnt.c index 1bbb2102d7..35e7173190 100644 --- a/ssl/statem/extensions_clnt.c +++ b/ssl/statem/extensions_clnt.c @@ -9,6 +9,7 @@ #include #include "../ssl_locl.h" +#include "internal/cryptlib.h" #include "statem_locl.h" EXT_RETURN tls_construct_ctos_renegotiate(SSL *s, WPACKET *pkt, diff --git a/ssl/statem/extensions_cust.c b/ssl/statem/extensions_cust.c index cd63d04b00..24b9909047 100644 --- a/ssl/statem/extensions_cust.c +++ b/ssl/statem/extensions_cust.c @@ -11,6 +11,7 @@ #include #include "../ssl_locl.h" +#include "internal/cryptlib.h" #include "statem_locl.h" typedef struct { diff --git a/ssl/statem/statem_dtls.c b/ssl/statem/statem_dtls.c index 83bd8d3322..7fb6cdb8e2 100644 --- a/ssl/statem/statem_dtls.c +++ b/ssl/statem/statem_dtls.c @@ -12,6 +12,7 @@ #include #include "../ssl_locl.h" #include "statem_locl.h" +#include "internal/cryptlib.h" #include #include #include diff --git a/ssl/statem/statem_lib.c b/ssl/statem/statem_lib.c index 08d5f416f3..c92c8b5ff8 100644 --- a/ssl/statem/statem_lib.c +++ b/ssl/statem/statem_lib.c @@ -13,6 +13,7 @@ #include #include "../ssl_locl.h" #include "statem_locl.h" +#include "internal/cryptlib.h" #include #include #include