diff --git a/.gitmodules b/.gitmodules index 998884126a20ce2ddeeed6a3b1e06d8405cd4574..9d203614f9f72d01db210b80d71c0fc6cd71e479 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,7 @@ [submodule "3rd/nanomsg"] path = 3rd/nanomsg - url = https://gitee.com/embedded-lib/nanomsg.git + url = https://gitee.com/ThinkingT/nanomsg.git +[submodule "3rd/curl"] + path = 3rd/curl + url = https://gitee.com/ThinkingT/curl.git diff --git a/3rd/curl b/3rd/curl new file mode 160000 index 0000000000000000000000000000000000000000..cb013830383f1ccc9757aba36bc32df5ec281c02 --- /dev/null +++ b/3rd/curl @@ -0,0 +1 @@ +Subproject commit cb013830383f1ccc9757aba36bc32df5ec281c02 diff --git a/3rd/include/boost.zip b/3rd/include/boost.zip new file mode 100644 index 0000000000000000000000000000000000000000..28560b5f285591358378d6bcc850852f49b35e94 Binary files /dev/null and b/3rd/include/boost.zip differ diff --git a/3rd/jerryscript b/3rd/jerryscript index 9ff25dbc1220097b9dc04746bdf07a3b66c2e2d4..8ba0d1b6ee5a065a42f3b306771ad8e3c0d819bc 160000 --- a/3rd/jerryscript +++ b/3rd/jerryscript @@ -1 +1 @@ -Subproject commit 9ff25dbc1220097b9dc04746bdf07a3b66c2e2d4 +Subproject commit 8ba0d1b6ee5a065a42f3b306771ad8e3c0d819bc diff --git a/3rd/nanomsg b/3rd/nanomsg index 63252794a0a1bec04e46ece82f7a3edf0b527d82..1749fd7b039165a91b8d556b4df18e3e632ad830 160000 --- a/3rd/nanomsg +++ b/3rd/nanomsg @@ -1 +1 @@ -Subproject commit 63252794a0a1bec04e46ece82f7a3edf0b527d82 +Subproject commit 1749fd7b039165a91b8d556b4df18e3e632ad830 diff --git a/3rd/readme.txt b/3rd/readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..4bb148c68bacd309d7ad14d203cbdf93f2601a90 --- /dev/null +++ b/3rd/readme.txt @@ -0,0 +1 @@ +cmake -DEVENT__DISABLE_TESTS=ON -DEVENT__DISABLE_SAMPLES=ON -DEVENT__DISABLE_REGRESS=ON -DEVENT__DISABLE_OPENSSL=ON diff --git a/access/sqlite3.h b/access/sqlite3.h index c1ad6968e36a7f824a56c2274912a6e7ba15371c..08f9709a69c04e1739153d7072076459f6bdd8f5 100644 --- a/access/sqlite3.h +++ b/access/sqlite3.h @@ -2161,8 +2161,7 @@ void sqlite3_randomness(int N, void* P); ** ** {H12522} The default authorizer is NULL. */ -int sqlite3_set_authorizer( - sqlite3*, int (*xAuth)(void*, int, const char*, const char*, const char*, const char*), void* pUserData); +int sqlite3_set_authorizer(sqlite3*, int (*xAuth)(void*, int, const char*, const char*, const char*, const char*), void* pUserData); /* ** CAPI3REF: Authorizer Return Codes {H12590} @@ -4579,17 +4578,10 @@ void sqlite3_result_zeroblob(sqlite3_context*, int n); ** requires the least amount of conversion from the default ** text encoding of the database. */ -int sqlite3_create_collation( - sqlite3*, const char* zName, int eTextRep, void*, int (*xCompare)(void*, int, const void*, int, const void*)); +int sqlite3_create_collation(sqlite3*, const char* zName, int eTextRep, void*, int (*xCompare)(void*, int, const void*, int, const void*)); int sqlite3_create_collation_v2( - sqlite3*, - const char* zName, - int eTextRep, - void*, - int (*xCompare)(void*, int, const void*, int, const void*), - void (*xDestroy)(void*)); -int sqlite3_create_collation16( - sqlite3*, const void* zName, int eTextRep, void*, int (*xCompare)(void*, int, const void*, int, const void*)); + sqlite3*, const char* zName, int eTextRep, void*, int (*xCompare)(void*, int, const void*, int, const void*), void (*xDestroy)(void*)); +int sqlite3_create_collation16(sqlite3*, const void* zName, int eTextRep, void*, int (*xCompare)(void*, int, const void*, int, const void*)); /* ** CAPI3REF: Collation Needed Callbacks {H16700} @@ -5272,12 +5264,7 @@ struct sqlite3_module { int (*xSync)(sqlite3_vtab* pVTab); int (*xCommit)(sqlite3_vtab* pVTab); int (*xRollback)(sqlite3_vtab* pVTab); - int (*xFindFunction)( - sqlite3_vtab* pVtab, - int nArg, - const char* zName, - void (**pxFunc)(sqlite3_context*, int, sqlite3_value**), - void** ppArg); + int (*xFindFunction)(sqlite3_vtab* pVtab, int nArg, const char* zName, void (**pxFunc)(sqlite3_context*, int, sqlite3_value**), void** ppArg); int (*xRename)(sqlite3_vtab* pVtab, const char* zNew); }; @@ -5341,17 +5328,17 @@ struct sqlite3_index_info { unsigned char op; /* Constraint operator */ unsigned char usable; /* True if this constraint is usable */ int iTermOffset; /* Used internally - xBestIndex should ignore */ - } * aConstraint; /* Table of WHERE clause constraints */ + }* aConstraint; /* Table of WHERE clause constraints */ int nOrderBy; /* Number of terms in the ORDER BY clause */ struct sqlite3_index_orderby { int iColumn; /* Column number */ unsigned char desc; /* True for DESC. False for ASC. */ - } * aOrderBy; /* The ORDER BY clause */ + }* aOrderBy; /* The ORDER BY clause */ /* Outputs */ struct sqlite3_index_constraint_usage { int argvIndex; /* if >0, constraint is part of argv to xFilter */ unsigned char omit; /* Do not code a test for this constraint */ - } * aConstraintUsage; + }* aConstraintUsage; int idxNum; /* Number used to identify the index */ char* idxStr; /* String, possibly obtained from sqlite3_malloc */ int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */ @@ -5578,14 +5565,7 @@ typedef struct sqlite3_blob sqlite3_blob; ** an [ON CONFLICT] side effect, then the [sqlite3_blob] shall ** be marked as invalid. */ -int sqlite3_blob_open( - sqlite3*, - const char* zDb, - const char* zTable, - const char* zColumn, - sqlite3_int64 iRow, - int flags, - sqlite3_blob** ppBlob); +int sqlite3_blob_open(sqlite3*, const char* zDb, const char* zTable, const char* zColumn, sqlite3_int64 iRow, int flags, sqlite3_blob** ppBlob); /* ** CAPI3REF: Close A BLOB Handle {H17830} diff --git a/asynio/asio/boostdef.hpp b/asynio/asio/boostdef.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ab998788acfd0089f3c39e55903cd05fba4dd1b5 --- /dev/null +++ b/asynio/asio/boostdef.hpp @@ -0,0 +1,49 @@ +#ifndef _BOOST_DEF_H_ +#define _BOOST_DEF_H_ + +#define BOOST_ERROR_CODE_HEADER_ONLY +#define BOOST_USE_WINAPI_VERSION 0x0501 +#define BOOST_ALL_NO_LIB +#define BOOST_REGEX_NO_LIB +#define BOOST_DATE_TIME_SOURCE +#define BOOST_SYSTEM_NO_LIB +#define BOOST_ASIO_ENABLE_CANCELIO +#define BOOST_SYSTEM_NO_DEPRECATED + +#include +#include +#include +#include + +using boost::asio::ip::tcp; + +typedef boost::asio::io_service io_service; +typedef io_service* io_service_ptr; + +typedef boost::asio::io_service::strand io_strand; +typedef io_strand* io_strand_ptr; + +typedef boost::asio::io_service::work io_work; +typedef boost::asio::io_service::work* io_work_ptr; + +typedef boost::asio::ip::tcp::socket io_socket; +typedef io_socket* io_socket_ptr; + +typedef boost::asio::ip::udp::socket io_usocket; +typedef io_usocket* io_usocket_ptr; + +typedef boost::asio::ip::tcp::acceptor io_acceptor; +typedef io_acceptor* io_acceptor_ptr; + +typedef boost::asio::deadline_timer io_time; +typedef io_time* io_time_ptr; + +typedef boost::asio::steady_timer io_steady_time; +typedef io_steady_time* io_steady_time_ptr; + +typedef boost::asio::ip::tcp::resolver io_resolver; +typedef io_resolver* io_resolver_ptr; + +typedef const boost::system::error_code& io_c_error_code; + +#endif // !_BOOST_DEF_H_ diff --git a/asynio/asio/iocontext.cpp b/asynio/asio/iocontext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d846c3a3085bcdcc13b272d84f64829a6fbe712 --- /dev/null +++ b/asynio/asio/iocontext.cpp @@ -0,0 +1,115 @@ +#include "iocontext.h" +#include + +static io_contextpool_t* iopool = NULL; + +static int startfunccb(void* data, void* context) +{ + return S_SUCCESS; +} + +static int workfunccb(void* data, void* context) +{ + io_contextpool_t* pool = (io_contextpool_t*)(data); + io_thread_t* thread = (io_thread_t*)(context); + io_context_t* task = (pool->context + thread->id); + + task->service->run(); + + return S_SUCCESS; +} + +static int stopfunccb(void* data, void* context) +{ + return S_SUCCESS; +} + +static int errorfunccb(void* data, void* context) +{ + return S_SUCCESS; +} + +int contexts_init(io_contextpool_t* pool, unsigned int count) +{ + rc_assert(pool != NULL, S_ERROR); + + pool->context = (io_context_t*)malloc(sizeof(io_context_t) * count); + + unsigned int index; + for (index = 0; index < count; index++) { + io_context_t* context = pool->context + index; + context->service = ALLOC_NEW io_service; + context->work = ALLOC_NEW io_work(*context->service); + } + + pool->index = 0; + pool->tp.count = count; + pool->tp.func.start = startfunccb; + pool->tp.func.work = workfunccb; + pool->tp.func.stop = stopfunccb; + pool->tp.func.error = errorfunccb; + + iopool = pool; + + return init_threadpool(&pool->tp); +} + +int contexts_start(io_contextpool_t* pool, void* context) +{ + rc_assert(pool != NULL, S_ERROR); + rc_assert(context != NULL, S_ERROR); + pool->tp.ctx = context; + return start_threadpool(&pool->tp); +} +int contexts_stop(io_contextpool_t* pool) +{ + rc_assert(pool != NULL, S_ERROR); + + unsigned int index = 0; + + for (index = 0; index < pool->tp.count; index++) { + io_context_t* context = pool->context + index; + context->service->stop(); + } + return stop_threadpool(&pool->tp); +} +int contexts_uninit(io_contextpool_t* pool) +{ + rc_assert(pool != NULL, S_ERROR); + + uinit_threadpool(&pool->tp); + + unsigned int index = 0; + for (index = 0; index < pool->tp.count; index++) { + io_context_t* context = pool->context + index; + + if (context->work) + delete context->work; + + if (context->service) + delete context->service; + + context = NULL; + } + + if (pool->context) + free(pool->context); + + return S_SUCCESS; +} + +io_service_ptr set_instance(io_contextpool_t* pool) +{ + rc_assert(pool != NULL, NULL); + iopool = pool; + return (iopool->context)->service; +} + +io_service* get_instance(io_contextpool_t* pool) +{ + rc_assert(iopool != NULL, NULL); + rc_assert(iopool->context != NULL, NULL); + iopool->index++; + unsigned short index = (iopool->index % iopool->tp.count); + return (iopool->context + index)->service; +} diff --git a/asynio/asio/iocontext.h b/asynio/asio/iocontext.h new file mode 100644 index 0000000000000000000000000000000000000000..3df36faebe89d11f2d68f0590012a302a5edba49 --- /dev/null +++ b/asynio/asio/iocontext.h @@ -0,0 +1,29 @@ +#ifndef _IO_CONTEXT_H_ +#define _IO_CONTEXT_H_ + +#include "ioeventdef.h" + +typedef struct io_context_s io_context_t; + +struct io_context_s { + io_service_ptr service; + io_work_ptr work; +}; + +typedef struct io_contextpool_s io_contextpool_t; + +struct io_contextpool_s { + _threadpool_t tp; + io_context_t* context; + unsigned short index; +}; + +int contexts_init(io_contextpool_t* pool, unsigned int count); +int contexts_start(io_contextpool_t* pool, void* context); +int contexts_stop(io_contextpool_t* pool); +int contexts_uninit(io_contextpool_t* pool); + +io_service* set_instance(io_contextpool_t* pool); +io_service* get_instance(io_contextpool_t* pool); + +#endif diff --git a/asynio/asio/iodgram.cpp b/asynio/asio/iodgram.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5418d132a1e79f6fe97ed666dac0de7fabb83916 --- /dev/null +++ b/asynio/asio/iodgram.cpp @@ -0,0 +1,61 @@ +#include "iodgram.h" + +CIoDgram::CIoDgram() +{ +} + +CIoDgram::~CIoDgram() +{ +} + +int CIoDgram::async_read(NET_ADDR addr, NET_PORT port, BYTE* buf, unsigned long size) +{ + rc_assert(this->ptr != NULL, S_ERROR); + rc_assert(this->safe != NULL, S_ERROR); + + boost::asio::ip::udp::endpoint point(boost::asio::ip::address::from_string(addr), port); + + // no need try catch + this->ptr->async_receive_from( + boost::asio::buffer(this->context.rptr, this->context.rlen), point, + safe->wrap(boost::bind(&CIoDgram::dgram_handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); + + return S_SUCCESS; +} + +int CIoDgram::async_write(NET_ADDR addr, NET_PORT port, BYTE* buf, unsigned long size) +{ + rc_assert(this->ptr != NULL, S_ERROR); + rc_assert(this->safe != NULL, S_ERROR); + + boost::asio::ip::udp::endpoint point(boost::asio::ip::address::from_string(addr), port); + + // no need try catch + this->ptr->async_send_to( + boost::asio::buffer(this->context.wptr, this->context.wlen), point, + safe->wrap(boost::bind(&CIoDgram::dgram_handle_write, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); + + return S_SUCCESS; +} + +int CIoDgram::dgram_handle_write(io_c_error_code ec, size_t wbytes) +{ + if (ec) { + this->DgramEventcb(DGRAM_WRITE_ERROR); + return S_ERROR; + } else { + this->DgramWritecb(wbytes); + } + return S_SUCCESS; +} + +int CIoDgram::dgram_handle_read(io_c_error_code ec, size_t rbytes) +{ + if (ec) { + this->DgramEventcb(DGRAM_READ_ERROR); + return S_ERROR; + } else { + this->DgramReadcb(rbytes); + } + return S_SUCCESS; +} diff --git a/asynio/asio/iodgram.h b/asynio/asio/iodgram.h new file mode 100644 index 0000000000000000000000000000000000000000..75b9ec8b7342b9aa82e4b7b89077826be78b630d --- /dev/null +++ b/asynio/asio/iodgram.h @@ -0,0 +1,23 @@ +#ifndef _IO_DGRAM_H_ +#define _IO_DGRAM_H_ + +#include "ioudp.h" + +class CIoDgram : public CIoUdp +{ +public: + CIoDgram(); + virtual ~CIoDgram(); + +public: + int async_read(NET_ADDR addr, NET_PORT port, BYTE* buf, unsigned long size); + int async_write(NET_ADDR addr, NET_PORT port, BYTE* buf, unsigned long size); + int dgram_handle_read(io_c_error_code ec, size_t rbytes); + int dgram_handle_write(io_c_error_code ec, size_t wbytes); + + virtual void DgramWritecb(unsigned long ulen) = 0; + virtual void DgramReadcb(unsigned long ulen) = 0; + virtual void DgramEventcb(short what) = 0; +}; + +#endif diff --git a/asynio/asio/ioeventdef.h b/asynio/asio/ioeventdef.h new file mode 100644 index 0000000000000000000000000000000000000000..508ef008ba3f6c51871b0de35d4897cce4d5d29e --- /dev/null +++ b/asynio/asio/ioeventdef.h @@ -0,0 +1,49 @@ +#ifndef _IOEVENTDEF_H_ +#define _IOEVENTDEF_H_ + +#include +#include + +#define PORT_MAX 65535 + +#define STREAM_READ_ERROR 0x01 +#define STREAM_READ_TIMEOUT 0x02 +#define STREAM_WRITE_ERROR 0x04 +#define STREAM_WRITE_TIMEOUT 0x80 + +#define STREAM_READ 0x20 +#define STREAM_WRITE 0x40 + +#define STREAM_READING 0x20 +#define STREAM_WRITEING 0x40 + +#define TCP_CONNECTED 0 +#define TCP_CONNECT_FAILD 1 +#define TCP_CONNECT_TIMEOUT 2 + +#define DGRAM_READ_ERROR 0x01 +#define DGRAM_READ_TIMEOUT 0x02 +#define DGRAM_WRITE_ERROR 0x04 +#define DGRAM_WRITE_TIMEOUT 0x08 + +#define TCP_ACCEPT_CONNECTED 0 +#define TCP_ACCEPT_FAILD 1 + +typedef void (*async_fun_cb)(void* data); + +typedef struct io_data_s io_data_t; + +struct io_data_s { + void* data; + unsigned long sid; + unsigned long rid; + async_fun_cb func; + async_fun_cb freefunc; + async_fun_cb errorfunc; + unsigned char* wptr; + unsigned long wlen; + unsigned char* rptr; + unsigned long rlen; +}; + +#endif diff --git a/asynio/asio/iostream.cpp b/asynio/asio/iostream.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a7187d57cc3005b7c0db2d138855270af3e3a9c3 --- /dev/null +++ b/asynio/asio/iostream.cpp @@ -0,0 +1,61 @@ +#include "iostream.h" + +CIoStream::CIoStream() +{ +} + +CIoStream::~CIoStream() +{ +} + +int CIoStream::async_read(BYTE* buf, unsigned long size) +{ + rc_assert(this->ptr != NULL, S_ERROR); + rc_assert(this->safe != NULL, S_ERROR); + + // no need try catch + this->ptr->async_receive( + boost::asio::buffer(this->context.rptr, this->context.rlen), + safe->wrap( + boost::bind(&CIoStream::stream_handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); + + return S_SUCCESS; +} + +int CIoStream::async_write(BYTE* buf, unsigned long size) +{ + rc_assert(this->ptr != NULL, S_ERROR); + rc_assert(this->safe != NULL, S_ERROR); + + // no need try catch + this->ptr->async_send( + boost::asio::buffer(this->context.wptr, this->context.wlen), + safe->wrap( + boost::bind(&CIoStream::stream_handle_write, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); + + return S_SUCCESS; +} + +int CIoStream::stream_handle_write(io_c_error_code ec, size_t wbytes) +{ + if (ec) { + this->StreamEventcb(STREAM_WRITE_ERROR); + return S_ERROR; + } else { + this->StreamWritecb(wbytes); + } + + return S_SUCCESS; +} + +int CIoStream::stream_handle_read(io_c_error_code ec, size_t rbytes) +{ + if (ec) { + this->StreamEventcb(STREAM_READ_ERROR); + return S_ERROR; + } else { + this->StreamReadcb(rbytes); + } + + return S_SUCCESS; +} diff --git a/asynio/asio/iostream.h b/asynio/asio/iostream.h new file mode 100644 index 0000000000000000000000000000000000000000..bbeae512b831b3cbe658030781f608c1b23caf50 --- /dev/null +++ b/asynio/asio/iostream.h @@ -0,0 +1,24 @@ +#ifndef _IO_STREAM_H_ +#define _IO_STREAM_H_ + +#include "iotcp.h" + +class CIoStream : public CIoTcp +{ +public: + CIoStream(); + virtual ~CIoStream(); + +public: + int async_read(BYTE* buf, unsigned long size); + int async_write(BYTE* buf, unsigned long size); + + int stream_handle_read(io_c_error_code ec, size_t rbytes); + int stream_handle_write(io_c_error_code ec, size_t wbytes); + + virtual void StreamWritecb(unsigned long ulen) = 0; + virtual void StreamReadcb(unsigned long ulen) = 0; + virtual void StreamEventcb(short what) = 0; +}; + +#endif diff --git a/asynio/asio/iotcp.cpp b/asynio/asio/iotcp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c49b1c42df07b376eb7b31eb680915799842717e --- /dev/null +++ b/asynio/asio/iotcp.cpp @@ -0,0 +1,113 @@ +#include "iotcp.h" +#include "iocontext.h" +#include + +CIoTcp::CIoTcp() +{ + this->ptr = NULL; + this->safe = NULL; +} +CIoTcp::~CIoTcp() +{ +} +int CIoTcp::tcp_init() +{ + io_service* service = get_instance(NULL); + this->ptr = ALLOC_NEW io_socket(*service); + this->tm = ALLOC_NEW io_time(*service); + this->safe = ALLOC_NEW io_strand(*service); + + return S_SUCCESS; +} +int CIoTcp::tcp_uninit() +{ + rc_assert(this->ptr != NULL, S_ERROR); + delete this->ptr; + rc_assert(this->tm != NULL, S_ERROR); + delete this->tm; + return S_SUCCESS; +} + +int CIoTcp::tcp_assign(_sock_t* s) +{ + rc_assert(this->ptr != NULL, S_ERROR); + boost::system::error_code ec; + this->ptr->assign(boost::asio::ip::tcp::v4(), *s, ec); + rc_assert(!ec, S_ERROR) rc_assert(this->ptr->is_open(), S_ERROR) return S_SUCCESS; +} + +int CIoTcp::tcp_close() +{ + rc_assert(this->ptr != NULL, S_ERROR); + rc_assert(this->ptr->is_open(), S_ERROR); + boost::system::error_code ec; + + try { + this->ptr->shutdown(boost::asio::socket_base::shutdown_both, ec); + this->ptr->close(ec); + } catch (const boost::system::error_code& err) { + return err.value(); + } + return S_SUCCESS; +} + +int CIoTcp::tcp_async_connect(void* data, const char* addr, unsigned short port, int timeout) +{ + rc_assert(this->ptr != NULL, S_ERROR); + rc_assert(this->tm != NULL, S_ERROR); + + try { + this->ptr->async_connect( + tcp::endpoint(boost::asio::ip::address::from_string(addr), port), + boost::bind(&CIoTcp::tcp_connect_handler, this, boost::asio::placeholders::error)); + + this->tm->expires_from_now(boost::posix_time::seconds(timeout)); + + this->tm->async_wait(boost::bind(&CIoTcp::tcp_connect_timeout_handler, this, boost::asio::placeholders::error)); + + } catch (const boost::system::error_code& err) { + return err.value(); + } + return S_SUCCESS; +} +int CIoTcp::tcp_is_open() +{ + rc_assert(this->ptr->is_open(), S_ERROR); + return S_SUCCESS; +} +int CIoTcp::tcp_setoption() +{ + rc_assert(this->ptr != NULL, S_ERROR) + try { + this->ptr->set_option(boost::asio::ip::tcp::no_delay(true)); + this->ptr->set_option(boost::asio::socket_base::linger(true, 0)); + } catch (boost::system::error_code& err) { + return err.value(); + } + return S_SUCCESS; +} + +int CIoTcp::tcp_connect_handler(io_c_error_code ec) +{ + if (ec) { + if (ec.value() != boost::system::errc::operation_canceled) { } + this->ptr->close(); + this->ConnectCB(this->context.data, TCP_CONNECT_FAILD); + + } else { + this->tcp_setoption(); + this->ConnectCB(this->context.data, TCP_CONNECTED); + } + + this->tm->cancel(); + return S_SUCCESS; +} +int CIoTcp::tcp_connect_timeout_handler(io_c_error_code ec) +{ + if (ec) { + if (ec.value() != boost::system::errc::operation_canceled) { } + } else { + this->ConnectCB(this->context.data, TCP_CONNECT_TIMEOUT); + } + return S_SUCCESS; +} diff --git a/asynio/asio/iotcp.h b/asynio/asio/iotcp.h new file mode 100644 index 0000000000000000000000000000000000000000..ae9e488ded96d26541bf36895adbb900e5de7943 --- /dev/null +++ b/asynio/asio/iotcp.h @@ -0,0 +1,33 @@ +#ifndef _IO_TCP_H_ +#define _IO_TCP_H_ + +#include "ioeventdef.h" + +class CIoTcp +{ +public: + CIoTcp(); + virtual ~CIoTcp(); + +public: + int tcp_init(); + int tcp_uninit(); + int tcp_assign(_sock_t* s); + int tcp_close(); + int tcp_async_connect(void* data, const char* addr, unsigned short port, int timeout); + int tcp_is_open(); + int tcp_setoption(); + int tcp_connect_handler(io_c_error_code ec); + int tcp_connect_timeout_handler(io_c_error_code ec); + +public: + io_socket_ptr ptr; + io_strand_ptr safe; + io_time_ptr tm; + io_data_t context; + +public: + virtual void ConnectCB(void* data, int error_code) = 0; +}; + +#endif diff --git a/asynio/asio/iotcpaccept.cpp b/asynio/asio/iotcpaccept.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b8d9efc1ebaa621b8538edb0e7075d4dc0a6dfb9 --- /dev/null +++ b/asynio/asio/iotcpaccept.cpp @@ -0,0 +1,90 @@ +#include "iotcpaccept.h" +#include "iocontext.h" + +CIoTcpAccpet::CIoTcpAccpet() +{ +} +CIoTcpAccpet::~CIoTcpAccpet() +{ +} + +int CIoTcpAccpet::accpet_init() +{ + io_service* pService = get_instance(NULL); + this->acceptptr = ALLOC_NEW io_acceptor(*pService); + this->safe = ALLOC_NEW io_strand(*pService); + return S_SUCCESS; +} +int CIoTcpAccpet::accpet_uninit() +{ + rc_assert(this->acceptptr != NULL, S_ERROR); + delete this->acceptptr; + return S_SUCCESS; +} + +int CIoTcpAccpet::accpet_assign(_sock_t* s) +{ + rc_assert(this->acceptptr != NULL, S_ERROR); + boost::system::error_code ec; + this->acceptptr->assign(boost::asio::ip::tcp::v4(), *s, ec); + rc_assert(!ec, S_ERROR); + rc_assert(this->acceptptr->is_open(), S_ERROR); + return S_SUCCESS; +} + +int CIoTcpAccpet::accpet_close() +{ + rc_assert(this->acceptptr != NULL, S_ERROR); + rc_assert(this->acceptptr->is_open(), S_ERROR); + boost::system::error_code ec; + + try { + this->acceptptr->cancel(ec); + this->acceptptr->close(ec); + } catch (const boost::system::error_code& err) { + return err.value(); + } + + return S_SUCCESS; +} + +int CIoTcpAccpet::accpet_listen() +{ + rc_assert(this->acceptptr != NULL, S_ERROR); + boost::system::error_code ec; + this->acceptptr->listen(boost::asio::socket_base::max_connections, ec); + rc_assert(!ec, S_ERROR); + return S_SUCCESS; +} +int CIoTcpAccpet::accpet_bind(const char* addr, unsigned short port) +{ + rc_assert(this->acceptptr != NULL, S_ERROR); + boost::system::error_code ec; + this->acceptptr->bind(tcp::endpoint(boost::asio::ip::address::from_string(addr), port), ec); + rc_assert(!ec, S_ERROR); + return S_SUCCESS; +} +int CIoTcpAccpet::accpet_wait(const CIoTcp* tcp, void* data) +{ + rc_assert(this->acceptptr != NULL, S_ERROR); + + this->acceptptr->async_accept(*tcp->ptr, safe->wrap(boost::bind(&CIoTcpAccpet::accept_handle, this, boost::asio::placeholders::error, data))); + + return S_SUCCESS; +} +int CIoTcpAccpet::accept_is_open() +{ + rc_assert(this->acceptptr->is_open(), S_ERROR); + return S_SUCCESS; +} + +int CIoTcpAccpet::accept_handle(io_c_error_code ec, void* data) +{ + if (ec) { + this->AcceptCB(data, TCP_ACCEPT_FAILD); + } else { + // accept->socket->release();//////////////shut out + debug_view("accept socket Start") this->AcceptCB(data, TCP_ACCEPT_CONNECTED); + } + return S_SUCCESS; +} diff --git a/asynio/asio/iotcpaccept.h b/asynio/asio/iotcpaccept.h new file mode 100644 index 0000000000000000000000000000000000000000..74131ecde25781955ff02afe709fc2636670886c --- /dev/null +++ b/asynio/asio/iotcpaccept.h @@ -0,0 +1,30 @@ +#ifndef _IO_TCPACCEPT_H_ +#define _IO_TCPACCEPT_H_ + +#include "iotcp.h" + +class CIoTcpAccpet +{ +public: + CIoTcpAccpet(); + virtual ~CIoTcpAccpet(); + +public: + int accpet_init(); + int accpet_uninit(); + int accpet_assign(_sock_t* s); + int accpet_close(); + int accpet_listen(); + int accpet_bind(const char* addr, unsigned short port); + int accpet_wait(const CIoTcp* tcp, void* data); + int accept_is_open(); + int accept_handle(io_c_error_code ec, void* data); + + io_acceptor_ptr acceptptr; + io_strand_ptr safe; + +public: + virtual void AcceptCB(void* data, int error_code) = 0; +}; + +#endif diff --git a/asynio/asio/iotimer.cpp b/asynio/asio/iotimer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad6861ee573919b0dd47ce27269239168e87885a --- /dev/null +++ b/asynio/asio/iotimer.cpp @@ -0,0 +1,65 @@ +#include "iotimer.h" +#include "iocontext.h" +#include + +CIoTimer::CIoTimer() +{ + second = 0; +} +CIoTimer::~CIoTimer() +{ +} + +int CIoTimer::time_init() +{ + io_service* pService = get_instance(NULL); + this->tm = ALLOC_NEW io_time(*pService); + return S_SUCCESS; +} +int CIoTimer::time_uninit() +{ + rc_assert(this->tm != NULL, S_ERROR); + delete this->tm; + return S_SUCCESS; +} + +int CIoTimer::time_sec(int sec) +{ + rc_assert(this->tm != NULL, S_ERROR); + + try { + this->tm->expires_from_now(boost::posix_time::seconds(sec)); + second = sec; + } catch (const boost::system::error_code& err) { + return err.value(); + } + return S_SUCCESS; +} + +int CIoTimer::time_start() +{ + rc_assert(this->tm != NULL, S_ERROR); + + try { + this->tm->async_wait(boost::bind(&CIoTimer::timer_handler, this, boost::asio::placeholders::error)); + } catch (const boost::system::error_code& err) { + return err.value(); + } + return S_SUCCESS; +} +int CIoTimer::time_stop() +{ + rc_assert(this->tm != NULL, S_ERROR); + this->tm->cancel(); + return S_SUCCESS; +} + +int CIoTimer::timer_handler(io_c_error_code ec) +{ + if (ec) { + if (ec.value() != boost::system::errc::operation_canceled) { } + } else { + this->OnTime(); + } + return S_SUCCESS; +} diff --git a/asynio/asio/iotimer.h b/asynio/asio/iotimer.h new file mode 100644 index 0000000000000000000000000000000000000000..e078c3a64d9d632122a236e83b4c7b945f70f7f0 --- /dev/null +++ b/asynio/asio/iotimer.h @@ -0,0 +1,27 @@ +#ifndef _IO_TIMER_H_ +#define _IO_TIMER_H_ + +#include "ioeventdef.h" + +class CIoTimer +{ +public: + CIoTimer(void); + virtual ~CIoTimer(void); + int time_init(); + int time_uninit(); + int time_sec(int sec); + int time_start(); + int time_stop(); + int timer_handler(io_c_error_code ec); + +public: + virtual void OnTime() = 0; + +private: + int second; + io_time_ptr tm; + io_strand_ptr safe; +}; + +#endif diff --git a/asynio/asio/ioudp.cpp b/asynio/asio/ioudp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04e7b3275f0b954b8b1f6287b693814722fa38c4 --- /dev/null +++ b/asynio/asio/ioudp.cpp @@ -0,0 +1,67 @@ +#include "ioudp.h" +#include "iocontext.h" +#include + +CIoUdp::CIoUdp() +{ + this->ptr = NULL; + this->safe = NULL; +} +CIoUdp::~CIoUdp() +{ +} +int CIoUdp::udp_init() +{ + io_service* service = get_instance(NULL); + this->ptr = ALLOC_NEW io_usocket(*service); + this->safe = ALLOC_NEW io_strand(*service); + return S_SUCCESS; +} +int CIoUdp::udp_uninit() +{ + rc_assert(this->ptr != NULL, S_ERROR); + delete this->ptr; + return S_SUCCESS; +} + +int CIoUdp::udp_assign(_sock_t* s) +{ + rc_assert(this->ptr != NULL, S_ERROR); + boost::system::error_code ec; + this->ptr->assign(boost::asio::ip::udp::v4(), *s, ec); + rc_assert(!ec, S_ERROR); + rc_assert(this->ptr->is_open(), S_ERROR); + return S_SUCCESS; +} + +int CIoUdp::udp_close() +{ + rc_assert(this->ptr != NULL, S_ERROR); + rc_assert(this->ptr->is_open(), S_ERROR); + boost::system::error_code ec; + + try { + this->ptr->shutdown(boost::asio::socket_base::shutdown_both, ec); + this->ptr->close(ec); + } catch (const boost::system::error_code& err) { + return err.value(); + } + + return S_SUCCESS; +} + +int CIoUdp::udp_is_open() +{ + rc_assert(this->ptr->is_open(), S_ERROR); + return S_SUCCESS; +} +int CIoUdp::udp_setoption() +{ + rc_assert(this->ptr != NULL, S_ERROR); + try { + this->ptr->set_option(boost::asio::socket_base::linger(true, 0)); + } catch (boost::system::error_code& err) { + return err.value(); + } + return S_SUCCESS; +} diff --git a/asynio/asio/ioudp.h b/asynio/asio/ioudp.h new file mode 100644 index 0000000000000000000000000000000000000000..c605da15db0edd7fcb3dcff369798644f79b60ba --- /dev/null +++ b/asynio/asio/ioudp.h @@ -0,0 +1,26 @@ +#ifndef _IO_UDP_H_ +#define _IO_UDP_H_ + +#include "ioeventdef.h" + +class CIoUdp +{ +public: + CIoUdp(); + virtual ~CIoUdp(); + +public: + int udp_init(); + int udp_uninit(); + int udp_assign(_sock_t* s); + int udp_close(); + int udp_is_open(); + int udp_setoption(); + +public: + io_usocket_ptr ptr; + io_strand_ptr safe; + io_data_t context; +}; + +#endif diff --git a/asynio/asynframeimpl.cpp b/asynio/asynframeimpl.cpp index 0236483d50776989b95656fa590df05f3f7a0ef8..ea28202e6c583781c12e2a3a9d52951dda16a4c6 100644 --- a/asynio/asynframeimpl.cpp +++ b/asynio/asynframeimpl.cpp @@ -1,5 +1,4 @@ #include "asynframeimpl.h" -#include "fileimpl.h" #include "tcpsocketimpl.h" #include "tcpsocketsslimpl.h" #include "udpsocketimpl.h" @@ -11,6 +10,7 @@ CAsynFrameImpl::CAsynFrameImpl(void) { + m_serviceindex = 0; } CAsynFrameImpl::~CAsynFrameImpl(void) @@ -18,6 +18,23 @@ CAsynFrameImpl::~CAsynFrameImpl(void) logi("CAsynFrameImpl::~CAsynFrameImpl"); } +static int OnEvloopNotify(ioevloop_t* evloop, int index) +{ + rc_assert(evloop != NULL, S_ERROR); + CAsynFrameImpl* frame = (CAsynFrameImpl*)ioevloop_getctx(evloop); + rc_assert(frame != NULL, S_ERROR); + frame->PostComplete(index); + return S_SUCCESS; +} +static void OnEvLoopTime(int sock, short event, void* arg) +{ + c_assert(arg != NULL); + struct ioevloop_s* ev = (struct ioevloop_s*)(arg); + c_assert(ev != NULL); + c_assert(ev->notify != NULL); + ev->notify(ev, IOEV_NOTIFY_TYPE_WORK); +} + HRESULT CAsynFrameImpl::Init(IBase* pRot, IBase* pBase) { rc_assert(pRot != NULL, E_FAIL); @@ -26,6 +43,18 @@ HRESULT CAsynFrameImpl::Init(IBase* pRot, IBase* pBase) hr = pRot->QueryInterface(IID_IRot, (void**)&m_pRot); rc_assert(hr == S_OK, E_FAIL); + InitIoEv(); + + this->m_tpcount = 4; + this->m_evloop = (ioevloop_t*)heap_malloc(this->m_tpcount * sizeof(ioevloop_t)); + + unsigned int index = 0; + + for (index = 0; index < this->m_tpcount; index++) { + ioevloop_t* ev = this->m_evloop + index; + CreateIOEvLoop(ev, OnEvloopNotify, this); + } + return S_OK; } HRESULT CAsynFrameImpl::Uninit() @@ -36,14 +65,31 @@ HRESULT CAsynFrameImpl::Start(_pid_t pid, unsigned int type) { initsockenv(2, 0); - CThread::Start_Thread(); - this->m_asynframe_sem.Wait(); + CThreadPool::StartThreadPool(m_tpcount); + + unsigned int index = 0; + for (index = 0; index < this->m_tpcount; index++) { + this->m_sem.Wait(); + } + return S_OK; } HRESULT CAsynFrameImpl::Stop(unsigned int exit) { - CThread::Stop_Thread(); + unsigned int index = 0; + + for (index = 0; index < this->m_tpcount; index++) { + ioevloop_t* ev = this->m_evloop + index; + ExitIoEvLoop(ev); + } + + for (index = 0; index < this->m_tpcount; index++) { + this->m_exitsem.Wait(); + } + + CThreadPool::StopThreadPool(); uninitsockenv(2, 0); + return S_OK; } HRESULT CAsynFrameImpl::CreateIo(IO_Protocol iop, IBase** pBase) @@ -62,8 +108,6 @@ HRESULT CAsynFrameImpl::CreateIo(IO_Protocol iop, IBase** pBase) return CreateITcpSocketSSL(pBase); else if (io_timer == iop) return CreateITimer(pBase); - else if (io_file == iop) - return CreateIFile(pBase); else if (io_pipe == iop) return CreateIPipe(pBase); else if (io_spipe == iop) @@ -76,97 +120,196 @@ HRESULT CAsynFrameImpl::PostIo(IBase* pOperation) int rc = S_SUCCESS; return rc == S_SUCCESS ? S_OK : E_FAIL; } -HRESULT CAsynFrameImpl::Thread_Init() + +HRESULT CAsynFrameImpl::ThreadPool_Run(void* user, void* ctx) +{ + rc_assert(ctx != NULL, E_FAIL) io_thread_t* thread = (io_thread_t*)(ctx); + rc_assert(thread != NULL, E_FAIL) ioevloop_t* ev = m_evloop + thread->id; + rc_assert(ev != NULL, E_FAIL) RunIoEvloop(ev); + return S_OK; +} +HRESULT CAsynFrameImpl::PostComplete(int type) { + if (IOEV_NOTIFY_TYPE_WORK == type) { + this->m_sem.Post(); + } + + if (IOEV_NOTIFY_TYPE_EXIT == type) { + this->m_exitsem.Post(); + } + return S_OK; } -HRESULT CAsynFrameImpl::Thread_Run() +HRESULT CAsynFrameImpl::ThreadPool_Start() { - SetService(true); return S_OK; } -HRESULT CAsynFrameImpl::Thread_UnInit() +HRESULT CAsynFrameImpl::ThreadPool_Stop() { return S_OK; } -HRESULT CAsynFrameImpl::SetService(bool bstart) +HRESULT CAsynFrameImpl::ThreadPool_Error() { - if (bstart) { - this->m_asynframe_sem.Post(); - } return S_OK; } HRESULT CAsynFrameImpl::CreateIOperation(IBase** ppOperation) { - CIoOperationImpl* pObject = NULL; - pObject = ALLOC_NEW CIoOperationImpl; - rc_assert(pObject != NULL, E_FAIL); - return pObject->QueryInterface(IID_IOperation, (void**)ppOperation); + CIoOperationImpl* pObj = NULL; + pObj = ALLOC_NEW CIoOperationImpl; + rc_assert(pObj != NULL, E_FAIL); + return pObj->QueryInterface(IID_IOperation, (void**)ppOperation); } HRESULT CAsynFrameImpl::CreateITcpSocket(IBase** pAsynTcpSocket) { - CTcpSocketImpl* pObject = NULL; - pObject = ALLOC_NEW CTcpSocketImpl; - rc_assert(pObject != NULL, E_FAIL); - HRESULT hr = S_OK; - _lComPtr pBase; - hr = this->QueryInterface(IID_IBase, (void**)&pBase); - rc_assert(hr == S_OK, E_FAIL); + CTcpSocketImpl* pObj = NULL; + pObj = ALLOC_NEW CTcpSocketImpl; + rc_assert(pObj != NULL, E_FAIL); - hr = pObject->init_class(pBase); + hr = pObj->CreateIoOperation(this); rc_assert(hr == S_OK, E_FAIL); - return pObject->QueryInterface(IID_ITcpSocket, (void**)pAsynTcpSocket); + pObj->BindEvloop(get_service()); + + return pObj->QueryInterface(IID_ITcpSocket, (void**)pAsynTcpSocket); } HRESULT CAsynFrameImpl::CreateIUdpSocket(IBase** pAsynUdpSocket) { - CUdpSocketImpl* pObject = NULL; - pObject = ALLOC_NEW CUdpSocketImpl; - rc_assert(pObject != NULL, E_FAIL); - return pObject->QueryInterface(IID_IUdpSocket, (void**)pAsynUdpSocket); + HRESULT hr = S_OK; + + CUdpSocketImpl* pObj = NULL; + pObj = ALLOC_NEW CUdpSocketImpl; + rc_assert(pObj != NULL, E_FAIL); + + hr = pObj->CreateIoOperation(this); + rc_assert(hr == S_OK, E_FAIL); + + pObj->BindEvloop(get_service()); + + return pObj->QueryInterface(IID_IUdpSocket, (void**)pAsynUdpSocket); } HRESULT CAsynFrameImpl::CreateITcpListenSocket(IBase** pAsynTcpListenSocket) { - HRESULT hr = S_OK; - CTcpListenSocketImpl* pObject = NULL; - pObject = ALLOC_NEW CTcpListenSocketImpl; - rc_assert(pObject != NULL, E_FAIL); - return pObject->QueryInterface(IID_ITcpListen, (void**)pAsynTcpListenSocket); + CTcpListenSocketImpl* pObj = NULL; + pObj = ALLOC_NEW CTcpListenSocketImpl; + rc_assert(pObj != NULL, E_FAIL); + + pObj->BindEvloop(get_service()); + + return pObj->QueryInterface(IID_ITcpListen, (void**)pAsynTcpListenSocket); } HRESULT CAsynFrameImpl::CreateITcpSocketSSL(IBase** pAsynTcpSocket) { - CTcpSocketSSLImpl* pObject = NULL; - pObject = ALLOC_NEW CTcpSocketSSLImpl; - return pObject->QueryInterface(IID_ITcpSocketSSL, (void**)pAsynTcpSocket); + HRESULT hr = S_OK; + + CTcpSocketSSLImpl* pObj = NULL; + pObj = ALLOC_NEW CTcpSocketSSLImpl; + rc_assert(pObj != NULL, E_FAIL); + + hr = pObj->CreateIoOperation(this); + rc_assert(hr == S_OK, E_FAIL); + + pObj->BindEvloop(get_service()); + + return pObj->QueryInterface(IID_ITcpSocketSSL, (void**)pAsynTcpSocket); } HRESULT CAsynFrameImpl::CreateITimer(IBase** pTimer) { - CTimerImpl* pObject = NULL; - pObject = ALLOC_NEW CTimerImpl(); - rc_assert(pObject != NULL, E_FAIL); - return pObject->QueryInterface(IID_ITimer, (void**)pTimer); + + CTimerImpl* pObj = NULL; + pObj = ALLOC_NEW CTimerImpl(); + rc_assert(pObj != NULL, E_FAIL); + return pObj->QueryInterface(IID_ITimer, (void**)pTimer); +} +HRESULT CAsynFrameImpl::CreateIPipe(IBase** pPipe) +{ + CPipeImpl* pObj = NULL; + pObj = ALLOC_NEW CPipeImpl; + rc_assert(pObj != NULL, E_FAIL); + + HRESULT hr = S_OK; + + _lComPtr pBase; + hr = this->QueryInterface(IID_IBase, (void**)&pBase); + rc_assert(hr == S_OK, E_FAIL); + + return pObj->QueryInterface(IID_IPipe, (void**)pPipe); } -HRESULT CAsynFrameImpl::CreateIFile(IBase** pFile) +HRESULT CAsynFrameImpl::CreateISPipe(IBase** pPipe) { - CFileImpl* pObject = NULL; - pObject = ALLOC_NEW CFileImpl; - rc_assert(pObject != NULL, E_FAIL); - return pObject->QueryInterface(IID_IFile, (void**)pFile); + CSPipeImpl* pObj = NULL; + pObj = ALLOC_NEW CSPipeImpl; + rc_assert(pObj != NULL, E_FAIL); + return pObj->QueryInterface(IID_ISPipe, (void**)pPipe); } -HRESULT CAsynFrameImpl::CreateIPipe(IBase** pPipe) +HRESULT CAsynFrameImpl::InitIoEv() { - CPipeImpl* pObject = NULL; - pObject = ALLOC_NEW CPipeImpl; - rc_assert(pObject != NULL, E_FAIL); - return pObject->QueryInterface(IID_IPipe, (void**)pPipe); +#if (TARGET_OS == OS_WINDOWS) + evthread_use_windows_threads(); +#elif (TARGET_OS == OS_POSIX) + evthread_use_pthreads(); +#elif (TARGET_OS == OS_MACH) + evthread_use_pthreads(); +#endif + return S_OK; } -HRESULT CAsynFrameImpl::CreateISPipe(IBase** pPipe) +HRESULT CAsynFrameImpl::CreateIOEvLoop(ioevloop_t* ev, evloop_notify cb, void* user) { - CSPipeImpl* pObject = NULL; - pObject = ALLOC_NEW CSPipeImpl; - rc_assert(pObject != NULL, E_FAIL); - return pObject->QueryInterface(IID_ISPipe, (void**)pPipe); + rc_assert(ev != NULL, E_FAIL); + + ioevloop_setctx(ev, user); + + ev->loop = event_base_new(); + ev->notify = cb; + +#if (TARGET_OS == OS_WINDOWS) + struct event_iocp_port* port = NULL; + event_base_start_iocp_(eventloop->loop, 1); + port = event_base_get_iocp_(eventloop->loop); +#endif + + return S_OK; +} +HRESULT CAsynFrameImpl::ExitIoEvLoop(ioevloop_t* ev) +{ + rc_assert(ev != NULL, E_FAIL); + rc_assert(ev->loop != NULL, E_FAIL); + event_base_loopexit(ev->loop, NULL); + return S_OK; +} + +HRESULT CAsynFrameImpl::RunIoEvloop(ioevloop_t* ev) +{ + rc_assert(ev != NULL, E_FAIL); + struct timeval tv; + struct event* evtime = NULL; + + evtime = evtimer_new(ev->loop, OnEvLoopTime, ev); + rc_assert(evtime != NULL, E_FAIL); + + tv.tv_sec = 0; + tv.tv_usec = 1; + + event_add(evtime, &tv); + event_base_loop(ev->loop, EVLOOP_NO_EXIT_ON_EMPTY); + event_del(evtime); + event_free(evtime); + event_base_free(ev->loop); + + ev->notify(ev, IOEV_NOTIFY_TYPE_EXIT); + + return S_OK; +} +ioevloop_t* CAsynFrameImpl::get_service() +{ + { + SYNC_OBJ(&m_lockSection) + m_serviceindex++; + if (m_serviceindex == m_tpcount) { + m_serviceindex = 0; + } + } + return this->m_evloop + m_serviceindex; } diff --git a/asynio/asynframeimpl.h b/asynio/asynframeimpl.h index b2c7e4cd46812ad0bd0d9e6a1491d33cd7896808..3a5705221fce3c0a9622094681fea19c2f845422 100644 --- a/asynio/asynframeimpl.h +++ b/asynio/asynframeimpl.h @@ -2,12 +2,13 @@ #define _ASYNFRAMEIMPL_H_ #include "stdafx.h" +#include "ioevdef.h" class CAsynFrameImpl : public IAsynFrame, public IPlugin, public IPluginRun, public CUnknownImp, - public CThread + public CThreadPool { public: CAsynFrameImpl(void); @@ -32,12 +33,14 @@ public: std_method(CreateIo)(IO_Protocol iop, IBase** pBase); std_method(PostIo)(IBase* pOperation); +public: + std_method(PostComplete)(int type); + protected: - // ithread - std_method(Thread_Init)(); - std_method(Thread_Run)(); - std_method(Thread_UnInit)(); - std_method(SetService)(bool bstart); + std_method(ThreadPool_Run)(void* user, void* ctx); + std_method(ThreadPool_Start)(); + std_method(ThreadPool_Stop)(); + std_method(ThreadPool_Error)(); private: std_method(CreateIOperation)(IBase** ppOperation); @@ -46,7 +49,6 @@ private: std_method(CreateITcpListenSocket)(IBase** pAsynTcpListenSocket); std_method(CreateITcpSocketSSL)(IBase** pAsynTcpSocket); std_method(CreateITimer)(IBase** pTimer); - std_method(CreateIFile)(IBase** pFile); std_method(CreateIPipe)(IBase** pPipe); std_method(CreateISPipe)(IBase** pPipe); @@ -54,6 +56,21 @@ private: _lComPtr m_pRot; private: - CSemHandle m_asynframe_sem; + std_method(InitIoEv)(); + std_method(CreateIOEvLoop)(ioevloop_t* ev, evloop_notify cb, void* user); + std_method(ExitIoEvLoop)(ioevloop_t* ev); + std_method(RunIoEvloop)(ioevloop_t* ev); + +private: + ioevloop_t* get_service(); + +private: + CSemHandle m_sem; + CSemHandle m_exitsem; + unsigned int m_tpcount; + ioevloop_t* m_evloop; + CAutoLock m_lockSection; + unsigned int m_serviceindex; }; + #endif diff --git a/asynio/event/buffer.c b/asynio/event/buffer.c new file mode 100644 index 0000000000000000000000000000000000000000..fac054616994ecf428fb7d4ac4bdbef0b2e71206 --- /dev/null +++ b/asynio/event/buffer.c @@ -0,0 +1,3243 @@ +/* + * Copyright (c) 2002-2007 Niels Provos + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef _WIN32 +#include +#include +#include +#endif + +#ifdef EVENT__HAVE_VASPRINTF +/* If we have vasprintf, we need to define _GNU_SOURCE before we include + * stdio.h. This comes from evconfig-private.h. + */ +#endif + +#include + +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif + +#ifdef EVENT__HAVE_SYS_UIO_H +#include +#endif + +#ifdef EVENT__HAVE_SYS_IOCTL_H +#include +#endif + +#ifdef EVENT__HAVE_SYS_MMAN_H +#include +#endif + +#ifdef EVENT__HAVE_SYS_SENDFILE_H +#include +#endif +#ifdef EVENT__HAVE_SYS_STAT_H +#include +#endif + +#include +#include +#include +#include +#ifdef EVENT__HAVE_STDARG_H +#include +#endif +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif +#include + +#include "eventbase.h" +#include "buffer.h" +#include "buffer_compat.h" +#include "bufferevent.h" +#include "bufferevent_compat.h" +#include "bufferevent_struct.h" + +#include "evconfig-internal.h" + +/* some systems do not have MAP_FAILED */ +#ifndef MAP_FAILED +#define MAP_FAILED ((void*)-1) +#endif + +/* send file support */ +#if defined(EVENT__HAVE_SYS_SENDFILE_H) && defined(EVENT__HAVE_SENDFILE) && defined(__linux__) +#define USE_SENDFILE 1 +#define SENDFILE_IS_LINUX 1 +#elif defined(EVENT__HAVE_SENDFILE) && defined(__FreeBSD__) +#define USE_SENDFILE 1 +#define SENDFILE_IS_FREEBSD 1 +#elif defined(EVENT__HAVE_SENDFILE) && defined(__APPLE__) +#define USE_SENDFILE 1 +#define SENDFILE_IS_MACOSX 1 +#elif defined(EVENT__HAVE_SENDFILE) && defined(__sun__) && defined(__svr4__) +#define USE_SENDFILE 1 +#define SENDFILE_IS_SOLARIS 1 +#endif + +/* Mask of user-selectable callback flags. */ +#define EVBUFFER_CB_USER_FLAGS 0xffff +/* Mask of all internal-use-only flags. */ +#define EVBUFFER_CB_INTERNAL_FLAGS 0xffff0000 + +/* Flag set if the callback is using the cb_obsolete function pointer */ +#define EVBUFFER_CB_OBSOLETE 0x00040000 + +/* evbuffer_chain support */ +#define CHAIN_SPACE_PTR(ch) ((ch)->buffer + (ch)->misalign + (ch)->off) +#define CHAIN_SPACE_LEN(ch) ((ch)->flags & EVBUFFER_IMMUTABLE ? 0 : (ch)->buffer_len - ((ch)->misalign + (ch)->off)) + +#define CHAIN_PINNED(ch) (((ch)->flags & EVBUFFER_MEM_PINNED_ANY) != 0) +#define CHAIN_PINNED_R(ch) (((ch)->flags & EVBUFFER_MEM_PINNED_R) != 0) + +/* evbuffer_ptr support */ +#define PTR_NOT_FOUND(ptr) \ + do { \ + (ptr)->pos = -1; \ + (ptr)->internal_.chain = NULL; \ + (ptr)->internal_.pos_in_chain = 0; \ + } while (0) + +static void evbuffer_chain_align(struct evbuffer_chain* chain); +static int evbuffer_chain_should_realign(struct evbuffer_chain* chain, size_t datalen); +static void evbuffer_deferred_callback(struct event_callback* cb, void* arg); +static int evbuffer_ptr_memcmp(const struct evbuffer* buf, const struct evbuffer_ptr* pos, const char* mem, size_t len); +static struct evbuffer_chain* evbuffer_expand_singlechain(struct evbuffer* buf, size_t datlen); +static int evbuffer_ptr_subtract(struct evbuffer* buf, struct evbuffer_ptr* pos, size_t howfar); +static int evbuffer_file_segment_materialize(struct evbuffer_file_segment* seg); +static inline void evbuffer_chain_incref(struct evbuffer_chain* chain); + +static struct evbuffer_chain* evbuffer_chain_new(size_t size) +{ + struct evbuffer_chain* chain; + size_t to_alloc; + + if (size > EVBUFFER_CHAIN_MAX - EVBUFFER_CHAIN_SIZE) + return (NULL); + + size += EVBUFFER_CHAIN_SIZE; + + /* get the next largest memory that can hold the buffer */ + if (size < EVBUFFER_CHAIN_MAX / 2) { + to_alloc = MIN_BUFFER_SIZE; + while (to_alloc < size) { + to_alloc <<= 1; + } + } else { + to_alloc = size; + } + + /* we get everything in one chunk */ + if ((chain = mm_malloc(to_alloc)) == NULL) + return (NULL); + + memset(chain, 0, EVBUFFER_CHAIN_SIZE); + + chain->buffer_len = to_alloc - EVBUFFER_CHAIN_SIZE; + + /* this way we can manipulate the buffer to different addresses, + * which is required for mmap for example. + */ + chain->buffer = EVBUFFER_CHAIN_EXTRA(unsigned char, chain); + + chain->refcnt = 1; + + return (chain); +} + +static inline void evbuffer_chain_free(struct evbuffer_chain* chain) +{ + EVUTIL_ASSERT(chain->refcnt > 0); + if (--chain->refcnt > 0) { + /* chain is still referenced by other chains */ + return; + } + + if (CHAIN_PINNED(chain)) { + /* will get freed once no longer dangling */ + chain->refcnt++; + chain->flags |= EVBUFFER_DANGLING; + return; + } + + /* safe to release chain, it's either a referencing + * chain or all references to it have been freed */ + if (chain->flags & EVBUFFER_REFERENCE) { + struct evbuffer_chain_reference* info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_reference, chain); + if (info->cleanupfn) + (*info->cleanupfn)(chain->buffer, chain->buffer_len, info->extra); + } + if (chain->flags & EVBUFFER_FILESEGMENT) { + struct evbuffer_chain_file_segment* info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, chain); + if (info->segment) { +#ifdef _WIN32 + if (info->segment->is_mapping) + UnmapViewOfFile(chain->buffer); +#endif + evbuffer_file_segment_free(info->segment); + } + } + if (chain->flags & EVBUFFER_MULTICAST) { + struct evbuffer_multicast_parent* info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_multicast_parent, chain); + /* referencing chain is being freed, decrease + * refcounts of source chain and associated + * evbuffer (which get freed once both reach + * zero) */ + EVUTIL_ASSERT(info->source != NULL); + EVUTIL_ASSERT(info->parent != NULL); + EVBUFFER_LOCK(info->source); + evbuffer_chain_free(info->parent); + evbuffer_decref_and_unlock_(info->source); + } + + mm_free(chain); +} + +static void evbuffer_free_all_chains(struct evbuffer_chain* chain) +{ + struct evbuffer_chain* next; + for (; chain; chain = next) { + next = chain->next; + evbuffer_chain_free(chain); + } +} + +#ifndef NDEBUG +static int evbuffer_chains_all_empty(struct evbuffer_chain* chain) +{ + for (; chain; chain = chain->next) { + if (chain->off) + return 0; + } + return 1; +} +#else +/* The definition is needed for EVUTIL_ASSERT, which uses sizeof to avoid +"unused variable" warnings. */ +static inline int evbuffer_chains_all_empty(struct evbuffer_chain* chain) +{ + return 1; +} +#endif + +/* Free all trailing chains in 'buf' that are neither pinned nor empty, prior + * to replacing them all with a new chain. Return a pointer to the place + * where the new chain will go. + * + * Internal; requires lock. The caller must fix up buf->last and buf->first + * as needed; they might have been freed. + */ +static struct evbuffer_chain** evbuffer_free_trailing_empty_chains(struct evbuffer* buf) +{ + struct evbuffer_chain** ch = buf->last_with_datap; + /* Find the first victim chain. It might be *last_with_datap */ + while ((*ch) && ((*ch)->off != 0 || CHAIN_PINNED(*ch))) + ch = &(*ch)->next; + if (*ch) { + EVUTIL_ASSERT(evbuffer_chains_all_empty(*ch)); + evbuffer_free_all_chains(*ch); + *ch = NULL; + } + return ch; +} + +/* Add a single chain 'chain' to the end of 'buf', freeing trailing empty + * chains as necessary. Requires lock. Does not schedule callbacks. + */ +static void evbuffer_chain_insert(struct evbuffer* buf, struct evbuffer_chain* chain) +{ + ASSERT_EVBUFFER_LOCKED(buf); + if (*buf->last_with_datap == NULL) { + /* There are no chains data on the buffer at all. */ + EVUTIL_ASSERT(buf->last_with_datap == &buf->first); + EVUTIL_ASSERT(buf->first == NULL); + buf->first = buf->last = chain; + } else { + struct evbuffer_chain** chp; + chp = evbuffer_free_trailing_empty_chains(buf); + *chp = chain; + if (chain->off) + buf->last_with_datap = chp; + buf->last = chain; + } + buf->total_len += chain->off; +} + +static inline struct evbuffer_chain* evbuffer_chain_insert_new(struct evbuffer* buf, size_t datlen) +{ + struct evbuffer_chain* chain; + if ((chain = evbuffer_chain_new(datlen)) == NULL) + return NULL; + evbuffer_chain_insert(buf, chain); + return chain; +} + +void evbuffer_chain_pin_(struct evbuffer_chain* chain, unsigned flag) +{ + EVUTIL_ASSERT((chain->flags & flag) == 0); + chain->flags |= flag; +} + +void evbuffer_chain_unpin_(struct evbuffer_chain* chain, unsigned flag) +{ + EVUTIL_ASSERT((chain->flags & flag) != 0); + chain->flags &= ~flag; + if (chain->flags & EVBUFFER_DANGLING) + evbuffer_chain_free(chain); +} + +static inline void evbuffer_chain_incref(struct evbuffer_chain* chain) +{ + ++chain->refcnt; +} + +struct evbuffer* evbuffer_new(void) +{ + struct evbuffer* buffer; + + buffer = mm_calloc(1, sizeof(struct evbuffer)); + if (buffer == NULL) + return (NULL); + + LIST_INIT(&buffer->callbacks); + buffer->refcnt = 1; + buffer->last_with_datap = &buffer->first; + + return (buffer); +} + +int evbuffer_set_flags(struct evbuffer* buf, ev_uint64_t flags) +{ + EVBUFFER_LOCK(buf); + buf->flags |= (ev_uint32_t)flags; + EVBUFFER_UNLOCK(buf); + return 0; +} + +int evbuffer_clear_flags(struct evbuffer* buf, ev_uint64_t flags) +{ + EVBUFFER_LOCK(buf); + buf->flags &= ~(ev_uint32_t)flags; + EVBUFFER_UNLOCK(buf); + return 0; +} + +void evbuffer_incref_(struct evbuffer* buf) +{ + EVBUFFER_LOCK(buf); + ++buf->refcnt; + EVBUFFER_UNLOCK(buf); +} + +void evbuffer_incref_and_lock_(struct evbuffer* buf) +{ + EVBUFFER_LOCK(buf); + ++buf->refcnt; +} + +int evbuffer_defer_callbacks(struct evbuffer* buffer, struct event_base* base) +{ + EVBUFFER_LOCK(buffer); + buffer->cb_queue = base; + buffer->deferred_cbs = 1; + event_deferred_cb_init_(&buffer->deferred, event_base_get_npriorities(base) / 2, evbuffer_deferred_callback, buffer); + EVBUFFER_UNLOCK(buffer); + return 0; +} + +int evbuffer_enable_locking(struct evbuffer* buf, void* lock) +{ +#ifdef EVENT__DISABLE_THREAD_SUPPORT + return -1; +#else + if (buf->lock) + return -1; + + if (!lock) { + EVTHREAD_ALLOC_LOCK(lock, EVTHREAD_LOCKTYPE_RECURSIVE); + if (!lock) + return -1; + buf->lock = lock; + buf->own_lock = 1; + } else { + buf->lock = lock; + buf->own_lock = 0; + } + + return 0; +#endif +} + +void evbuffer_set_parent_(struct evbuffer* buf, struct bufferevent* bev) +{ + EVBUFFER_LOCK(buf); + buf->parent = bev; + EVBUFFER_UNLOCK(buf); +} + +static void evbuffer_run_callbacks(struct evbuffer* buffer, int running_deferred) +{ + struct evbuffer_cb_entry *cbent, *next; + struct evbuffer_cb_info info; + size_t new_size; + ev_uint32_t mask, masked_val; + int clear = 1; + + if (running_deferred) { + mask = EVBUFFER_CB_NODEFER | EVBUFFER_CB_ENABLED; + masked_val = EVBUFFER_CB_ENABLED; + } else if (buffer->deferred_cbs) { + mask = EVBUFFER_CB_NODEFER | EVBUFFER_CB_ENABLED; + masked_val = EVBUFFER_CB_NODEFER | EVBUFFER_CB_ENABLED; + /* Don't zero-out n_add/n_del, since the deferred callbacks + will want to see them. */ + clear = 0; + } else { + mask = EVBUFFER_CB_ENABLED; + masked_val = EVBUFFER_CB_ENABLED; + } + + ASSERT_EVBUFFER_LOCKED(buffer); + + if (LIST_EMPTY(&buffer->callbacks)) { + buffer->n_add_for_cb = buffer->n_del_for_cb = 0; + return; + } + if (buffer->n_add_for_cb == 0 && buffer->n_del_for_cb == 0) + return; + + new_size = buffer->total_len; + info.orig_size = new_size + buffer->n_del_for_cb - buffer->n_add_for_cb; + info.n_added = buffer->n_add_for_cb; + info.n_deleted = buffer->n_del_for_cb; + if (clear) { + buffer->n_add_for_cb = 0; + buffer->n_del_for_cb = 0; + } + for (cbent = LIST_FIRST(&buffer->callbacks); cbent != LIST_END(&buffer->callbacks); cbent = next) { + /* Get the 'next' pointer now in case this callback decides + * to remove itself or something. */ + next = LIST_NEXT(cbent, next); + + if ((cbent->flags & mask) != masked_val) + continue; + + if ((cbent->flags & EVBUFFER_CB_OBSOLETE)) + cbent->cb.cb_obsolete(buffer, info.orig_size, new_size, cbent->cbarg); + else + cbent->cb.cb_func(buffer, &info, cbent->cbarg); + } +} + +void evbuffer_invoke_callbacks_(struct evbuffer* buffer) +{ + if (LIST_EMPTY(&buffer->callbacks)) { + buffer->n_add_for_cb = buffer->n_del_for_cb = 0; + return; + } + + if (buffer->deferred_cbs) { + if (event_deferred_cb_schedule_(buffer->cb_queue, &buffer->deferred)) { + evbuffer_incref_and_lock_(buffer); + if (buffer->parent) + bufferevent_incref_(buffer->parent); + } + EVBUFFER_UNLOCK(buffer); + } + + evbuffer_run_callbacks(buffer, 0); +} + +static void evbuffer_deferred_callback(struct event_callback* cb, void* arg) +{ + struct bufferevent* parent = NULL; + struct evbuffer* buffer = arg; + + /* XXXX It would be better to run these callbacks without holding the + * lock */ + EVBUFFER_LOCK(buffer); + parent = buffer->parent; + evbuffer_run_callbacks(buffer, 1); + evbuffer_decref_and_unlock_(buffer); + if (parent) + bufferevent_decref_(parent); +} + +static void evbuffer_remove_all_callbacks(struct evbuffer* buffer) +{ + struct evbuffer_cb_entry* cbent; + + while ((cbent = LIST_FIRST(&buffer->callbacks))) { + LIST_REMOVE(cbent, next); + mm_free(cbent); + } +} + +void evbuffer_decref_and_unlock_(struct evbuffer* buffer) +{ + struct evbuffer_chain *chain, *next; + ASSERT_EVBUFFER_LOCKED(buffer); + + EVUTIL_ASSERT(buffer->refcnt > 0); + + if (--buffer->refcnt > 0) { + EVBUFFER_UNLOCK(buffer); + return; + } + + for (chain = buffer->first; chain != NULL; chain = next) { + next = chain->next; + evbuffer_chain_free(chain); + } + evbuffer_remove_all_callbacks(buffer); + if (buffer->deferred_cbs) + event_deferred_cb_cancel_(buffer->cb_queue, &buffer->deferred); + + EVBUFFER_UNLOCK(buffer); + if (buffer->own_lock) + EVTHREAD_FREE_LOCK(buffer->lock, EVTHREAD_LOCKTYPE_RECURSIVE); + mm_free(buffer); +} + +void evbuffer_free(struct evbuffer* buffer) +{ + EVBUFFER_LOCK(buffer); + evbuffer_decref_and_unlock_(buffer); +} + +void evbuffer_lock(struct evbuffer* buf) +{ + EVBUFFER_LOCK(buf); +} + +void evbuffer_unlock(struct evbuffer* buf) +{ + EVBUFFER_UNLOCK(buf); +} + +size_t evbuffer_get_length(const struct evbuffer* buffer) +{ + size_t result; + + EVBUFFER_LOCK(buffer); + + result = (buffer->total_len); + + EVBUFFER_UNLOCK(buffer); + + return result; +} + +size_t evbuffer_get_contiguous_space(const struct evbuffer* buf) +{ + struct evbuffer_chain* chain; + size_t result; + + EVBUFFER_LOCK(buf); + chain = buf->first; + result = (chain != NULL ? chain->off : 0); + EVBUFFER_UNLOCK(buf); + + return result; +} + +size_t evbuffer_add_iovec(struct evbuffer* buf, struct evbuffer_iovec* vec, int n_vec) +{ + int n; + size_t res; + size_t to_alloc; + + EVBUFFER_LOCK(buf); + + res = to_alloc = 0; + + for (n = 0; n < n_vec; n++) { + to_alloc += vec[n].iov_len; + } + + if (evbuffer_expand_fast_(buf, to_alloc, 2) < 0) { + goto done; + } + + for (n = 0; n < n_vec; n++) { + /* XXX each 'add' call here does a bunch of setup that's + * obviated by evbuffer_expand_fast_, and some cleanup that we + * would like to do only once. Instead we should just extract + * the part of the code that's needed. */ + + if (evbuffer_add(buf, vec[n].iov_base, vec[n].iov_len) < 0) { + goto done; + } + + res += vec[n].iov_len; + } + +done: + EVBUFFER_UNLOCK(buf); + return res; +} + +int evbuffer_reserve_space(struct evbuffer* buf, ev_ssize_t size, struct evbuffer_iovec* vec, int n_vecs) +{ + struct evbuffer_chain *chain, **chainp; + int n = -1; + + EVBUFFER_LOCK(buf); + if (buf->freeze_end) + goto done; + if (n_vecs < 1) + goto done; + if (n_vecs == 1) { + if ((chain = evbuffer_expand_singlechain(buf, size)) == NULL) + goto done; + + vec[0].iov_base = (void*)CHAIN_SPACE_PTR(chain); + vec[0].iov_len = (size_t)CHAIN_SPACE_LEN(chain); + EVUTIL_ASSERT(size < 0 || (size_t)vec[0].iov_len >= (size_t)size); + n = 1; + } else { + if (evbuffer_expand_fast_(buf, size, n_vecs) < 0) + goto done; + n = evbuffer_read_setup_vecs_(buf, size, vec, n_vecs, &chainp, 0); + } + +done: + EVBUFFER_UNLOCK(buf); + return n; +} + +static int advance_last_with_data(struct evbuffer* buf) +{ + int n = 0; + ASSERT_EVBUFFER_LOCKED(buf); + + if (!*buf->last_with_datap) + return 0; + + while ((*buf->last_with_datap)->next && (*buf->last_with_datap)->next->off) { + buf->last_with_datap = &(*buf->last_with_datap)->next; + ++n; + } + return n; +} + +int evbuffer_commit_space(struct evbuffer* buf, struct evbuffer_iovec* vec, int n_vecs) +{ + struct evbuffer_chain *chain, **firstchainp, **chainp; + int result = -1; + size_t added = 0; + int i; + + EVBUFFER_LOCK(buf); + + if (buf->freeze_end) + goto done; + if (n_vecs == 0) { + result = 0; + goto done; + } else if (n_vecs == 1 && (buf->last && vec[0].iov_base == (void*)CHAIN_SPACE_PTR(buf->last))) { + /* The user only got or used one chain; it might not + * be the first one with space in it. */ + if ((size_t)vec[0].iov_len > (size_t)CHAIN_SPACE_LEN(buf->last)) + goto done; + buf->last->off += vec[0].iov_len; + added = vec[0].iov_len; + if (added) + advance_last_with_data(buf); + goto okay; + } + + /* Advance 'firstchain' to the first chain with space in it. */ + firstchainp = buf->last_with_datap; + if (!*firstchainp) + goto done; + if (CHAIN_SPACE_LEN(*firstchainp) == 0) { + firstchainp = &(*firstchainp)->next; + } + + chain = *firstchainp; + /* pass 1: make sure that the pointers and lengths of vecs[] are in + * bounds before we try to commit anything. */ + for (i = 0; i < n_vecs; ++i) { + if (!chain) + goto done; + if (vec[i].iov_base != (void*)CHAIN_SPACE_PTR(chain) || (size_t)vec[i].iov_len > CHAIN_SPACE_LEN(chain)) + goto done; + chain = chain->next; + } + /* pass 2: actually adjust all the chains. */ + chainp = firstchainp; + for (i = 0; i < n_vecs; ++i) { + (*chainp)->off += vec[i].iov_len; + added += vec[i].iov_len; + if (vec[i].iov_len) { + buf->last_with_datap = chainp; + } + chainp = &(*chainp)->next; + } + +okay: + buf->total_len += added; + buf->n_add_for_cb += added; + result = 0; + evbuffer_invoke_callbacks_(buf); + +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +static inline int HAS_PINNED_R(struct evbuffer* buf) +{ + return (buf->last && CHAIN_PINNED_R(buf->last)); +} + +static inline void ZERO_CHAIN(struct evbuffer* dst) +{ + ASSERT_EVBUFFER_LOCKED(dst); + dst->first = NULL; + dst->last = NULL; + dst->last_with_datap = &(dst)->first; + dst->total_len = 0; +} + +/* Prepares the contents of src to be moved to another buffer by removing + * read-pinned chains. The first pinned chain is saved in first, and the + * last in last. If src has no read-pinned chains, first and last are set + * to NULL. */ +static int PRESERVE_PINNED(struct evbuffer* src, struct evbuffer_chain** first, struct evbuffer_chain** last) +{ + struct evbuffer_chain *chain, **pinned; + + ASSERT_EVBUFFER_LOCKED(src); + + if (!HAS_PINNED_R(src)) { + *first = *last = NULL; + return 0; + } + + pinned = src->last_with_datap; + if (!CHAIN_PINNED_R(*pinned)) + pinned = &(*pinned)->next; + EVUTIL_ASSERT(CHAIN_PINNED_R(*pinned)); + chain = *first = *pinned; + *last = src->last; + + /* If there's data in the first pinned chain, we need to allocate + * a new chain and copy the data over. */ + if (chain->off) { + struct evbuffer_chain* tmp; + + EVUTIL_ASSERT(pinned == src->last_with_datap); + tmp = evbuffer_chain_new(chain->off); + if (!tmp) + return -1; + memcpy(tmp->buffer, chain->buffer + chain->misalign, chain->off); + tmp->off = chain->off; + *src->last_with_datap = tmp; + src->last = tmp; + chain->misalign += chain->off; + chain->off = 0; + } else { + src->last = *src->last_with_datap; + *pinned = NULL; + } + + return 0; +} + +static inline void RESTORE_PINNED(struct evbuffer* src, struct evbuffer_chain* pinned, struct evbuffer_chain* last) +{ + ASSERT_EVBUFFER_LOCKED(src); + + if (!pinned) { + ZERO_CHAIN(src); + return; + } + + src->first = pinned; + src->last = last; + src->last_with_datap = &src->first; + src->total_len = 0; +} + +static inline void COPY_CHAIN(struct evbuffer* dst, struct evbuffer* src) +{ + ASSERT_EVBUFFER_LOCKED(dst); + ASSERT_EVBUFFER_LOCKED(src); + dst->first = src->first; + if (src->last_with_datap == &src->first) + dst->last_with_datap = &dst->first; + else + dst->last_with_datap = src->last_with_datap; + dst->last = src->last; + dst->total_len = src->total_len; +} + +static void APPEND_CHAIN(struct evbuffer* dst, struct evbuffer* src) +{ + struct evbuffer_chain** chp; + + ASSERT_EVBUFFER_LOCKED(dst); + ASSERT_EVBUFFER_LOCKED(src); + + chp = evbuffer_free_trailing_empty_chains(dst); + *chp = src->first; + + if (src->last_with_datap == &src->first) + dst->last_with_datap = chp; + else + dst->last_with_datap = src->last_with_datap; + dst->last = src->last; + dst->total_len += src->total_len; +} + +static inline void APPEND_CHAIN_MULTICAST(struct evbuffer* dst, struct evbuffer* src) +{ + struct evbuffer_chain* tmp; + struct evbuffer_chain* chain = src->first; + struct evbuffer_multicast_parent* extra; + + ASSERT_EVBUFFER_LOCKED(dst); + ASSERT_EVBUFFER_LOCKED(src); + + for (; chain; chain = chain->next) { + if (!chain->off || chain->flags & EVBUFFER_DANGLING) { + /* skip empty chains */ + continue; + } + + tmp = evbuffer_chain_new(sizeof(struct evbuffer_multicast_parent)); + if (!tmp) { + event_warn("%s: out of memory", __func__); + return; + } + extra = EVBUFFER_CHAIN_EXTRA(struct evbuffer_multicast_parent, tmp); + /* reference evbuffer containing source chain so it + * doesn't get released while the chain is still + * being referenced to */ + evbuffer_incref_(src); + extra->source = src; + /* reference source chain which now becomes immutable */ + evbuffer_chain_incref(chain); + extra->parent = chain; + chain->flags |= EVBUFFER_IMMUTABLE; + tmp->buffer_len = chain->buffer_len; + tmp->misalign = chain->misalign; + tmp->off = chain->off; + tmp->flags |= EVBUFFER_MULTICAST | EVBUFFER_IMMUTABLE; + tmp->buffer = chain->buffer; + evbuffer_chain_insert(dst, tmp); + } +} + +static void PREPEND_CHAIN(struct evbuffer* dst, struct evbuffer* src) +{ + ASSERT_EVBUFFER_LOCKED(dst); + ASSERT_EVBUFFER_LOCKED(src); + src->last->next = dst->first; + dst->first = src->first; + dst->total_len += src->total_len; + if (*dst->last_with_datap == NULL) { + if (src->last_with_datap == &(src)->first) + dst->last_with_datap = &dst->first; + else + dst->last_with_datap = src->last_with_datap; + } else if (dst->last_with_datap == &dst->first) { + dst->last_with_datap = &src->last->next; + } +} + +int evbuffer_add_buffer(struct evbuffer* outbuf, struct evbuffer* inbuf) +{ + struct evbuffer_chain *pinned, *last; + size_t in_total_len, out_total_len; + int result = 0; + + EVBUFFER_LOCK2(inbuf, outbuf); + in_total_len = inbuf->total_len; + out_total_len = outbuf->total_len; + + if (in_total_len == 0 || outbuf == inbuf) + goto done; + + if (outbuf->freeze_end || inbuf->freeze_start) { + result = -1; + goto done; + } + + if (PRESERVE_PINNED(inbuf, &pinned, &last) < 0) { + result = -1; + goto done; + } + + if (out_total_len == 0) { + /* There might be an empty chain at the start of outbuf; free + * it. */ + evbuffer_free_all_chains(outbuf->first); + COPY_CHAIN(outbuf, inbuf); + } else { + APPEND_CHAIN(outbuf, inbuf); + } + + RESTORE_PINNED(inbuf, pinned, last); + + inbuf->n_del_for_cb += in_total_len; + outbuf->n_add_for_cb += in_total_len; + + evbuffer_invoke_callbacks_(inbuf); + evbuffer_invoke_callbacks_(outbuf); + +done: + EVBUFFER_UNLOCK2(inbuf, outbuf); + return result; +} + +int evbuffer_add_buffer_reference(struct evbuffer* outbuf, struct evbuffer* inbuf) +{ + size_t in_total_len, out_total_len; + struct evbuffer_chain* chain; + int result = 0; + + EVBUFFER_LOCK2(inbuf, outbuf); + in_total_len = inbuf->total_len; + out_total_len = outbuf->total_len; + chain = inbuf->first; + + if (in_total_len == 0) + goto done; + + if (outbuf->freeze_end || outbuf == inbuf) { + result = -1; + goto done; + } + + for (; chain; chain = chain->next) { + if ((chain->flags & (EVBUFFER_FILESEGMENT | EVBUFFER_SENDFILE | EVBUFFER_MULTICAST)) != 0) { + /* chain type can not be referenced */ + result = -1; + goto done; + } + } + + if (out_total_len == 0) { + /* There might be an empty chain at the start of outbuf; free + * it. */ + evbuffer_free_all_chains(outbuf->first); + } + APPEND_CHAIN_MULTICAST(outbuf, inbuf); + + outbuf->n_add_for_cb += in_total_len; + evbuffer_invoke_callbacks_(outbuf); + +done: + EVBUFFER_UNLOCK2(inbuf, outbuf); + return result; +} + +int evbuffer_prepend_buffer(struct evbuffer* outbuf, struct evbuffer* inbuf) +{ + struct evbuffer_chain *pinned, *last; + size_t in_total_len, out_total_len; + int result = 0; + + EVBUFFER_LOCK2(inbuf, outbuf); + + in_total_len = inbuf->total_len; + out_total_len = outbuf->total_len; + + if (!in_total_len || inbuf == outbuf) + goto done; + + if (outbuf->freeze_start || inbuf->freeze_start) { + result = -1; + goto done; + } + + if (PRESERVE_PINNED(inbuf, &pinned, &last) < 0) { + result = -1; + goto done; + } + + if (out_total_len == 0) { + /* There might be an empty chain at the start of outbuf; free + * it. */ + evbuffer_free_all_chains(outbuf->first); + COPY_CHAIN(outbuf, inbuf); + } else { + PREPEND_CHAIN(outbuf, inbuf); + } + + RESTORE_PINNED(inbuf, pinned, last); + + inbuf->n_del_for_cb += in_total_len; + outbuf->n_add_for_cb += in_total_len; + + evbuffer_invoke_callbacks_(inbuf); + evbuffer_invoke_callbacks_(outbuf); +done: + EVBUFFER_UNLOCK2(inbuf, outbuf); + return result; +} + +int evbuffer_drain(struct evbuffer* buf, size_t len) +{ + struct evbuffer_chain *chain, *next; + size_t remaining, old_len; + int result = 0; + + EVBUFFER_LOCK(buf); + old_len = buf->total_len; + + if (old_len == 0) + goto done; + + if (buf->freeze_start) { + result = -1; + goto done; + } + + if (len >= old_len && !HAS_PINNED_R(buf)) { + len = old_len; + for (chain = buf->first; chain != NULL; chain = next) { + next = chain->next; + evbuffer_chain_free(chain); + } + + ZERO_CHAIN(buf); + } else { + if (len >= old_len) + len = old_len; + + buf->total_len -= len; + remaining = len; + for (chain = buf->first; remaining >= chain->off; chain = next) { + next = chain->next; + remaining -= chain->off; + + if (chain == *buf->last_with_datap) { + buf->last_with_datap = &buf->first; + } + if (&chain->next == buf->last_with_datap) + buf->last_with_datap = &buf->first; + + if (CHAIN_PINNED_R(chain)) { + EVUTIL_ASSERT(remaining == 0); + chain->misalign += chain->off; + chain->off = 0; + break; + } else + evbuffer_chain_free(chain); + } + + buf->first = chain; + EVUTIL_ASSERT(chain && remaining <= chain->off); + chain->misalign += remaining; + chain->off -= remaining; + } + + buf->n_del_for_cb += len; + /* Tell someone about changes in this buffer */ + evbuffer_invoke_callbacks_(buf); + +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +/* Reads data from an event buffer and drains the bytes read */ +int evbuffer_remove(struct evbuffer* buf, void* data_out, size_t datlen) +{ + ev_ssize_t n; + EVBUFFER_LOCK(buf); + n = evbuffer_copyout_from(buf, NULL, data_out, datlen); + if (n > 0) { + if (evbuffer_drain(buf, n) < 0) + n = -1; + } + EVBUFFER_UNLOCK(buf); + return (int)n; +} + +ev_ssize_t evbuffer_copyout(struct evbuffer* buf, void* data_out, size_t datlen) +{ + return evbuffer_copyout_from(buf, NULL, data_out, datlen); +} + +ev_ssize_t evbuffer_copyout_from(struct evbuffer* buf, const struct evbuffer_ptr* pos, void* data_out, size_t datlen) +{ + /*XXX fails badly on sendfile case. */ + struct evbuffer_chain* chain; + char* data = data_out; + size_t nread; + ev_ssize_t result = 0; + size_t pos_in_chain; + + EVBUFFER_LOCK(buf); + + if (pos) { + if (datlen > (size_t)(EV_SSIZE_MAX - pos->pos)) { + result = -1; + goto done; + } + chain = pos->internal_.chain; + pos_in_chain = pos->internal_.pos_in_chain; + if (datlen + pos->pos > buf->total_len) + datlen = buf->total_len - pos->pos; + } else { + chain = buf->first; + pos_in_chain = 0; + if (datlen > buf->total_len) + datlen = buf->total_len; + } + + if (datlen == 0) + goto done; + + if (buf->freeze_start) { + result = -1; + goto done; + } + + nread = datlen; + + while (datlen && datlen >= chain->off - pos_in_chain) { + size_t copylen = chain->off - pos_in_chain; + memcpy(data, chain->buffer + chain->misalign + pos_in_chain, copylen); + data += copylen; + datlen -= copylen; + + chain = chain->next; + pos_in_chain = 0; + EVUTIL_ASSERT(chain || datlen == 0); + } + + if (datlen) { + EVUTIL_ASSERT(chain); + EVUTIL_ASSERT(datlen + pos_in_chain <= chain->off); + + memcpy(data, chain->buffer + chain->misalign + pos_in_chain, datlen); + } + + result = nread; +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +/* reads data from the src buffer to the dst buffer, avoids memcpy as + * possible. */ +/* XXXX should return ev_ssize_t */ +int evbuffer_remove_buffer(struct evbuffer* src, struct evbuffer* dst, size_t datlen) +{ + /*XXX We should have an option to force this to be zero-copy.*/ + + /*XXX can fail badly on sendfile case. */ + struct evbuffer_chain *chain, *previous; + size_t nread = 0; + int result; + + EVBUFFER_LOCK2(src, dst); + + chain = previous = src->first; + + if (datlen == 0 || dst == src) { + result = 0; + goto done; + } + + if (dst->freeze_end || src->freeze_start) { + result = -1; + goto done; + } + + /* short-cut if there is no more data buffered */ + if (datlen >= src->total_len) { + datlen = src->total_len; + evbuffer_add_buffer(dst, src); + result = (int)datlen; /*XXXX should return ev_ssize_t*/ + goto done; + } + + /* removes chains if possible */ + while (chain->off <= datlen) { + /* We can't remove the last with data from src unless we + * remove all chains, in which case we would have done the if + * block above */ + EVUTIL_ASSERT(chain != *src->last_with_datap); + nread += chain->off; + datlen -= chain->off; + previous = chain; + if (src->last_with_datap == &chain->next) + src->last_with_datap = &src->first; + chain = chain->next; + } + + if (nread) { + /* we can remove the chain */ + struct evbuffer_chain** chp; + chp = evbuffer_free_trailing_empty_chains(dst); + + if (dst->first == NULL) { + dst->first = src->first; + } else { + *chp = src->first; + } + dst->last = previous; + previous->next = NULL; + src->first = chain; + advance_last_with_data(dst); + + dst->total_len += nread; + dst->n_add_for_cb += nread; + } + + /* we know that there is more data in the src buffer than + * we want to read, so we manually drain the chain */ + evbuffer_add(dst, chain->buffer + chain->misalign, datlen); + chain->misalign += datlen; + chain->off -= datlen; + nread += datlen; + + /* You might think we would want to increment dst->n_add_for_cb + * here too. But evbuffer_add above already took care of that. + */ + src->total_len -= nread; + src->n_del_for_cb += nread; + + if (nread) { + evbuffer_invoke_callbacks_(dst); + evbuffer_invoke_callbacks_(src); + } + result = (int)nread; /*XXXX should change return type */ + +done: + EVBUFFER_UNLOCK2(src, dst); + return result; +} + +unsigned char* evbuffer_pullup(struct evbuffer* buf, ev_ssize_t size) +{ + struct evbuffer_chain *chain, *next, *tmp, *last_with_data; + unsigned char *buffer, *result = NULL; + ev_ssize_t remaining; + int removed_last_with_data = 0; + int removed_last_with_datap = 0; + + EVBUFFER_LOCK(buf); + + chain = buf->first; + + if (size < 0) + size = buf->total_len; + /* if size > buf->total_len, we cannot guarantee to the user that she + * is going to have a long enough buffer afterwards; so we return + * NULL */ + if (size == 0 || (size_t)size > buf->total_len) + goto done; + + /* No need to pull up anything; the first size bytes are + * already here. */ + if (chain->off >= (size_t)size) { + result = chain->buffer + chain->misalign; + goto done; + } + + /* Make sure that none of the chains we need to copy from is pinned. */ + remaining = size - chain->off; + EVUTIL_ASSERT(remaining >= 0); + for (tmp = chain->next; tmp; tmp = tmp->next) { + if (CHAIN_PINNED(tmp)) + goto done; + if (tmp->off >= (size_t)remaining) + break; + remaining -= tmp->off; + } + + if (CHAIN_PINNED(chain)) { + size_t old_off = chain->off; + if (CHAIN_SPACE_LEN(chain) < size - chain->off) { + /* not enough room at end of chunk. */ + goto done; + } + buffer = CHAIN_SPACE_PTR(chain); + tmp = chain; + tmp->off = size; + size -= old_off; + chain = chain->next; + } else if (chain->buffer_len - chain->misalign >= (size_t)size) { + /* already have enough space in the first chain */ + size_t old_off = chain->off; + buffer = chain->buffer + chain->misalign + chain->off; + tmp = chain; + tmp->off = size; + size -= old_off; + chain = chain->next; + } else { + if ((tmp = evbuffer_chain_new(size)) == NULL) { + event_warn("%s: out of memory", __func__); + goto done; + } + buffer = tmp->buffer; + tmp->off = size; + buf->first = tmp; + } + + /* TODO(niels): deal with buffers that point to NULL like sendfile */ + + /* Copy and free every chunk that will be entirely pulled into tmp */ + last_with_data = *buf->last_with_datap; + for (; chain != NULL && (size_t)size >= chain->off; chain = next) { + next = chain->next; + + memcpy(buffer, chain->buffer + chain->misalign, chain->off); + size -= chain->off; + buffer += chain->off; + if (chain == last_with_data) + removed_last_with_data = 1; + if (&chain->next == buf->last_with_datap) + removed_last_with_datap = 1; + + evbuffer_chain_free(chain); + } + + if (chain != NULL) { + memcpy(buffer, chain->buffer + chain->misalign, size); + chain->misalign += size; + chain->off -= size; + } else { + buf->last = tmp; + } + + tmp->next = chain; + + if (removed_last_with_data) { + buf->last_with_datap = &buf->first; + } else if (removed_last_with_datap) { + if (buf->first->next && buf->first->next->off) + buf->last_with_datap = &buf->first->next; + else + buf->last_with_datap = &buf->first; + } + + result = (tmp->buffer + tmp->misalign); + +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +/* + * Reads a line terminated by either '\r\n', '\n\r' or '\r' or '\n'. + * The returned buffer needs to be freed by the called. + */ +char* evbuffer_readline(struct evbuffer* buffer) +{ + return evbuffer_readln(buffer, NULL, EVBUFFER_EOL_ANY); +} + +static inline ev_ssize_t evbuffer_strchr(struct evbuffer_ptr* it, const char chr) +{ + struct evbuffer_chain* chain = it->internal_.chain; + size_t i = it->internal_.pos_in_chain; + while (chain != NULL) { + char* buffer = (char*)chain->buffer + chain->misalign; + char* cp = memchr(buffer + i, chr, chain->off - i); + if (cp) { + it->internal_.chain = chain; + it->internal_.pos_in_chain = cp - buffer; + it->pos += (cp - buffer - i); + return it->pos; + } + it->pos += chain->off - i; + i = 0; + chain = chain->next; + } + + return (-1); +} + +static inline char* find_eol_char(char* s, size_t len) +{ +#define CHUNK_SZ 128 + /* Lots of benchmarking found this approach to be faster in practice + * than doing two memchrs over the whole buffer, doin a memchr on each + * char of the buffer, or trying to emulate memchr by hand. */ + char *s_end, *cr, *lf; + s_end = s + len; + while (s < s_end) { + size_t chunk = (s + CHUNK_SZ < s_end) ? CHUNK_SZ : (s_end - s); + cr = memchr(s, '\r', chunk); + lf = memchr(s, '\n', chunk); + if (cr) { + if (lf && lf < cr) + return lf; + return cr; + } else if (lf) { + return lf; + } + s += CHUNK_SZ; + } + + return NULL; +#undef CHUNK_SZ +} + +static ev_ssize_t evbuffer_find_eol_char(struct evbuffer_ptr* it) +{ + struct evbuffer_chain* chain = it->internal_.chain; + size_t i = it->internal_.pos_in_chain; + while (chain != NULL) { + char* buffer = (char*)chain->buffer + chain->misalign; + char* cp = find_eol_char(buffer + i, chain->off - i); + if (cp) { + it->internal_.chain = chain; + it->internal_.pos_in_chain = cp - buffer; + it->pos += (cp - buffer) - i; + return it->pos; + } + it->pos += chain->off - i; + i = 0; + chain = chain->next; + } + + return (-1); +} + +static inline int evbuffer_strspn(struct evbuffer_ptr* ptr, const char* chrset) +{ + int count = 0; + struct evbuffer_chain* chain = ptr->internal_.chain; + size_t i = ptr->internal_.pos_in_chain; + + if (!chain) + return 0; + + while (1) { + char* buffer = (char*)chain->buffer + chain->misalign; + for (; i < chain->off; ++i) { + const char* p = chrset; + while (*p) { + if (buffer[i] == *p++) + goto next; + } + ptr->internal_.chain = chain; + ptr->internal_.pos_in_chain = i; + ptr->pos += count; + return count; + next: + ++count; + } + i = 0; + + if (!chain->next) { + ptr->internal_.chain = chain; + ptr->internal_.pos_in_chain = i; + ptr->pos += count; + return count; + } + + chain = chain->next; + } +} + +static inline int evbuffer_getchr(struct evbuffer_ptr* it) +{ + struct evbuffer_chain* chain = it->internal_.chain; + size_t off = it->internal_.pos_in_chain; + + if (chain == NULL) + return -1; + + return (unsigned char)chain->buffer[chain->misalign + off]; +} + +struct evbuffer_ptr evbuffer_search_eol(struct evbuffer* buffer, struct evbuffer_ptr* start, size_t* eol_len_out, enum evbuffer_eol_style eol_style) +{ + struct evbuffer_ptr it, it2; + size_t extra_drain = 0; + int ok = 0; + + /* Avoid locking in trivial edge cases */ + if (start && start->internal_.chain == NULL) { + PTR_NOT_FOUND(&it); + if (eol_len_out) + *eol_len_out = extra_drain; + return it; + } + + EVBUFFER_LOCK(buffer); + + if (start) { + memcpy(&it, start, sizeof(it)); + } else { + it.pos = 0; + it.internal_.chain = buffer->first; + it.internal_.pos_in_chain = 0; + } + + /* the eol_style determines our first stop character and how many + * characters we are going to drain afterwards. */ + switch (eol_style) { + case EVBUFFER_EOL_ANY: + if (evbuffer_find_eol_char(&it) < 0) + goto done; + memcpy(&it2, &it, sizeof(it)); + extra_drain = evbuffer_strspn(&it2, "\r\n"); + break; + case EVBUFFER_EOL_CRLF_STRICT: { + it = evbuffer_search(buffer, "\r\n", 2, &it); + if (it.pos < 0) + goto done; + extra_drain = 2; + break; + } + case EVBUFFER_EOL_CRLF: { + ev_ssize_t start_pos = it.pos; + /* Look for a LF ... */ + if (evbuffer_strchr(&it, '\n') < 0) + goto done; + extra_drain = 1; + /* ... optionally preceeded by a CR. */ + if (it.pos == start_pos) + break; /* If the first character is \n, don't back up */ + /* This potentially does an extra linear walk over the first + * few chains. Probably, that's not too expensive unless you + * have a really pathological setup. */ + memcpy(&it2, &it, sizeof(it)); + if (evbuffer_ptr_subtract(buffer, &it2, 1) < 0) + break; + if (evbuffer_getchr(&it2) == '\r') { + memcpy(&it, &it2, sizeof(it)); + extra_drain = 2; + } + break; + } + case EVBUFFER_EOL_LF: + if (evbuffer_strchr(&it, '\n') < 0) + goto done; + extra_drain = 1; + break; + case EVBUFFER_EOL_NUL: + if (evbuffer_strchr(&it, '\0') < 0) + goto done; + extra_drain = 1; + break; + default: + goto done; + } + + ok = 1; +done: + EVBUFFER_UNLOCK(buffer); + + if (!ok) + PTR_NOT_FOUND(&it); + if (eol_len_out) + *eol_len_out = extra_drain; + + return it; +} + +char* evbuffer_readln(struct evbuffer* buffer, size_t* n_read_out, enum evbuffer_eol_style eol_style) +{ + struct evbuffer_ptr it; + char* line; + size_t n_to_copy = 0, extra_drain = 0; + char* result = NULL; + + EVBUFFER_LOCK(buffer); + + if (buffer->freeze_start) { + goto done; + } + + it = evbuffer_search_eol(buffer, NULL, &extra_drain, eol_style); + if (it.pos < 0) + goto done; + n_to_copy = it.pos; + + if ((line = mm_malloc(n_to_copy + 1)) == NULL) { + event_warn("%s: out of memory", __func__); + goto done; + } + + evbuffer_remove(buffer, line, n_to_copy); + line[n_to_copy] = '\0'; + + evbuffer_drain(buffer, extra_drain); + result = line; +done: + EVBUFFER_UNLOCK(buffer); + + if (n_read_out) + *n_read_out = result ? n_to_copy : 0; + + return result; +} + +#define EVBUFFER_CHAIN_MAX_AUTO_SIZE 4096 + +/* Adds data to an event buffer */ + +int evbuffer_add(struct evbuffer* buf, const void* data_in, size_t datlen) +{ + struct evbuffer_chain *chain, *tmp; + const unsigned char* data = data_in; + size_t remain, to_alloc; + int result = -1; + + EVBUFFER_LOCK(buf); + + if (buf->freeze_end) { + goto done; + } + /* Prevent buf->total_len overflow */ + if (datlen > EV_SIZE_MAX - buf->total_len) { + goto done; + } + + if (*buf->last_with_datap == NULL) { + chain = buf->last; + } else { + chain = *buf->last_with_datap; + } + + /* If there are no chains allocated for this buffer, allocate one + * big enough to hold all the data. */ + if (chain == NULL) { + chain = evbuffer_chain_new(datlen); + if (!chain) + goto done; + evbuffer_chain_insert(buf, chain); + } + + if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { + /* Always true for mutable buffers */ + EVUTIL_ASSERT(chain->misalign >= 0 && (ev_uint64_t)chain->misalign <= EVBUFFER_CHAIN_MAX); + remain = chain->buffer_len - (size_t)chain->misalign - chain->off; + if (remain >= datlen) { + /* there's enough space to hold all the data in the + * current last chain */ + memcpy(chain->buffer + chain->misalign + chain->off, data, datlen); + chain->off += datlen; + buf->total_len += datlen; + buf->n_add_for_cb += datlen; + goto out; + } else if (!CHAIN_PINNED(chain) && evbuffer_chain_should_realign(chain, datlen)) { + /* we can fit the data into the misalignment */ + evbuffer_chain_align(chain); + + memcpy(chain->buffer + chain->off, data, datlen); + chain->off += datlen; + buf->total_len += datlen; + buf->n_add_for_cb += datlen; + goto out; + } + } else { + /* we cannot write any data to the last chain */ + remain = 0; + } + + /* we need to add another chain */ + to_alloc = chain->buffer_len; + if (to_alloc <= EVBUFFER_CHAIN_MAX_AUTO_SIZE / 2) + to_alloc <<= 1; + if (datlen > to_alloc) + to_alloc = datlen; + tmp = evbuffer_chain_new(to_alloc); + if (tmp == NULL) + goto done; + + if (remain) { + memcpy(chain->buffer + chain->misalign + chain->off, data, remain); + chain->off += remain; + buf->total_len += remain; + buf->n_add_for_cb += remain; + } + + data += remain; + datlen -= remain; + + memcpy(tmp->buffer, data, datlen); + tmp->off = datlen; + evbuffer_chain_insert(buf, tmp); + buf->n_add_for_cb += datlen; + +out: + evbuffer_invoke_callbacks_(buf); + result = 0; +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +int evbuffer_prepend(struct evbuffer* buf, const void* data, size_t datlen) +{ + struct evbuffer_chain *chain, *tmp; + int result = -1; + + EVBUFFER_LOCK(buf); + + if (buf->freeze_start) { + goto done; + } + if (datlen > EV_SIZE_MAX - buf->total_len) { + goto done; + } + + chain = buf->first; + + if (chain == NULL) { + chain = evbuffer_chain_new(datlen); + if (!chain) + goto done; + evbuffer_chain_insert(buf, chain); + } + + /* we cannot touch immutable buffers */ + if ((chain->flags & EVBUFFER_IMMUTABLE) == 0) { + /* Always true for mutable buffers */ + EVUTIL_ASSERT(chain->misalign >= 0 && (ev_uint64_t)chain->misalign <= EVBUFFER_CHAIN_MAX); + + /* If this chain is empty, we can treat it as + * 'empty at the beginning' rather than 'empty at the end' */ + if (chain->off == 0) + chain->misalign = chain->buffer_len; + + if ((size_t)chain->misalign >= datlen) { + /* we have enough space to fit everything */ + memcpy(chain->buffer + chain->misalign - datlen, data, datlen); + chain->off += datlen; + chain->misalign -= datlen; + buf->total_len += datlen; + buf->n_add_for_cb += datlen; + goto out; + } else if (chain->misalign) { + /* we can only fit some of the data. */ + memcpy(chain->buffer, (char*)data + datlen - chain->misalign, (size_t)chain->misalign); + chain->off += (size_t)chain->misalign; + buf->total_len += (size_t)chain->misalign; + buf->n_add_for_cb += (size_t)chain->misalign; + datlen -= (size_t)chain->misalign; + chain->misalign = 0; + } + } + + /* we need to add another chain */ + if ((tmp = evbuffer_chain_new(datlen)) == NULL) + goto done; + buf->first = tmp; + if (buf->last_with_datap == &buf->first) + buf->last_with_datap = &tmp->next; + + tmp->next = chain; + + tmp->off = datlen; + EVUTIL_ASSERT(datlen <= tmp->buffer_len); + tmp->misalign = tmp->buffer_len - datlen; + + memcpy(tmp->buffer + tmp->misalign, data, datlen); + buf->total_len += datlen; + buf->n_add_for_cb += datlen; + +out: + evbuffer_invoke_callbacks_(buf); + result = 0; +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +/** Helper: realigns the memory in chain->buffer so that misalign is 0. */ +static void evbuffer_chain_align(struct evbuffer_chain* chain) +{ + EVUTIL_ASSERT(!(chain->flags & EVBUFFER_IMMUTABLE)); + EVUTIL_ASSERT(!(chain->flags & EVBUFFER_MEM_PINNED_ANY)); + memmove(chain->buffer, chain->buffer + chain->misalign, chain->off); + chain->misalign = 0; +} + +#define MAX_TO_COPY_IN_EXPAND 4096 +#define MAX_TO_REALIGN_IN_EXPAND 2048 + +/** Helper: return true iff we should realign chain to fit datalen bytes of + data in it. */ +static int evbuffer_chain_should_realign(struct evbuffer_chain* chain, size_t datlen) +{ + return chain->buffer_len - chain->off >= datlen && (chain->off < chain->buffer_len / 2) && (chain->off <= MAX_TO_REALIGN_IN_EXPAND); +} + +/* Expands the available space in the event buffer to at least datlen, all in + * a single chunk. Return that chunk. */ +static struct evbuffer_chain* evbuffer_expand_singlechain(struct evbuffer* buf, size_t datlen) +{ + struct evbuffer_chain *chain, **chainp; + struct evbuffer_chain* result = NULL; + ASSERT_EVBUFFER_LOCKED(buf); + + chainp = buf->last_with_datap; + + /* XXX If *chainp is no longer writeable, but has enough space in its + * misalign, this might be a bad idea: we could still use *chainp, not + * (*chainp)->next. */ + if (*chainp && CHAIN_SPACE_LEN(*chainp) == 0) + chainp = &(*chainp)->next; + + /* 'chain' now points to the first chain with writable space (if any) + * We will either use it, realign it, replace it, or resize it. */ + chain = *chainp; + + if (chain == NULL || (chain->flags & (EVBUFFER_IMMUTABLE | EVBUFFER_MEM_PINNED_ANY))) { + /* We can't use the last_with_data chain at all. Just add a + * new one that's big enough. */ + goto insert_new; + } + + /* If we can fit all the data, then we don't have to do anything */ + if (CHAIN_SPACE_LEN(chain) >= datlen) { + result = chain; + goto ok; + } + + /* If the chain is completely empty, just replace it by adding a new + * empty chain. */ + if (chain->off == 0) { + goto insert_new; + } + + /* If the misalignment plus the remaining space fulfills our data + * needs, we could just force an alignment to happen. Afterwards, we + * have enough space. But only do this if we're saving a lot of space + * and not moving too much data. Otherwise the space savings are + * probably offset by the time lost in copying. + */ + if (evbuffer_chain_should_realign(chain, datlen)) { + evbuffer_chain_align(chain); + result = chain; + goto ok; + } + + /* At this point, we can either resize the last chunk with space in + * it, use the next chunk after it, or If we add a new chunk, we waste + * CHAIN_SPACE_LEN(chain) bytes in the former last chunk. If we + * resize, we have to copy chain->off bytes. + */ + + /* Would expanding this chunk be affordable and worthwhile? */ + if (CHAIN_SPACE_LEN(chain) < chain->buffer_len / 8 || chain->off > MAX_TO_COPY_IN_EXPAND || datlen >= (EVBUFFER_CHAIN_MAX - chain->off)) { + /* It's not worth resizing this chain. Can the next one be + * used? */ + if (chain->next && CHAIN_SPACE_LEN(chain->next) >= datlen) { + /* Yes, we can just use the next chain (which should + * be empty. */ + result = chain->next; + goto ok; + } else { + /* No; append a new chain (which will free all + * terminal empty chains.) */ + goto insert_new; + } + } else { + /* Okay, we're going to try to resize this chain: Not doing so + * would waste at least 1/8 of its current allocation, and we + * can do so without having to copy more than + * MAX_TO_COPY_IN_EXPAND bytes. */ + /* figure out how much space we need */ + size_t length = chain->off + datlen; + struct evbuffer_chain* tmp = evbuffer_chain_new(length); + if (tmp == NULL) + goto err; + + /* copy the data over that we had so far */ + tmp->off = chain->off; + memcpy(tmp->buffer, chain->buffer + chain->misalign, chain->off); + /* fix up the list */ + EVUTIL_ASSERT(*chainp == chain); + result = *chainp = tmp; + + if (buf->last == chain) + buf->last = tmp; + + tmp->next = chain->next; + evbuffer_chain_free(chain); + goto ok; + } + +insert_new: + result = evbuffer_chain_insert_new(buf, datlen); + if (!result) + goto err; +ok: + EVUTIL_ASSERT(result); + EVUTIL_ASSERT(CHAIN_SPACE_LEN(result) >= datlen); +err: + return result; +} + +/* Make sure that datlen bytes are available for writing in the last n + * chains. Never copies or moves data. */ +int evbuffer_expand_fast_(struct evbuffer* buf, size_t datlen, int n) +{ + struct evbuffer_chain *chain = buf->last, *tmp, *next; + size_t avail; + int used; + + ASSERT_EVBUFFER_LOCKED(buf); + EVUTIL_ASSERT(n >= 2); + + if (chain == NULL || (chain->flags & EVBUFFER_IMMUTABLE)) { + /* There is no last chunk, or we can't touch the last chunk. + * Just add a new chunk. */ + chain = evbuffer_chain_new(datlen); + if (chain == NULL) + return (-1); + + evbuffer_chain_insert(buf, chain); + return (0); + } + + used = 0; /* number of chains we're using space in. */ + avail = 0; /* how much space they have. */ + /* How many bytes can we stick at the end of buffer as it is? Iterate + * over the chains at the end of the buffer, tring to see how much + * space we have in the first n. */ + for (chain = *buf->last_with_datap; chain; chain = chain->next) { + if (chain->off) { + size_t space = (size_t)CHAIN_SPACE_LEN(chain); + EVUTIL_ASSERT(chain == *buf->last_with_datap); + if (space) { + avail += space; + ++used; + } + } else { + /* No data in chain; realign it. */ + chain->misalign = 0; + avail += chain->buffer_len; + ++used; + } + if (avail >= datlen) { + /* There is already enough space. Just return */ + return (0); + } + if (used == n) + break; + } + + /* There wasn't enough space in the first n chains with space in + * them. Either add a new chain with enough space, or replace all + * empty chains with one that has enough space, depending on n. */ + if (used < n) { + /* The loop ran off the end of the chains before it hit n + * chains; we can add another. */ + EVUTIL_ASSERT(chain == NULL); + + tmp = evbuffer_chain_new(datlen - avail); + if (tmp == NULL) + return (-1); + + buf->last->next = tmp; + buf->last = tmp; + /* (we would only set last_with_data if we added the first + * chain. But if the buffer had no chains, we would have + * just allocated a new chain earlier) */ + return (0); + } else { + /* Nuke _all_ the empty chains. */ + int rmv_all = 0; /* True iff we removed last_with_data. */ + chain = *buf->last_with_datap; + if (!chain->off) { + EVUTIL_ASSERT(chain == buf->first); + rmv_all = 1; + avail = 0; + } else { + /* can't overflow, since only mutable chains have + * huge misaligns. */ + avail = (size_t)CHAIN_SPACE_LEN(chain); + chain = chain->next; + } + + for (; chain; chain = next) { + next = chain->next; + EVUTIL_ASSERT(chain->off == 0); + evbuffer_chain_free(chain); + } + EVUTIL_ASSERT(datlen >= avail); + tmp = evbuffer_chain_new(datlen - avail); + if (tmp == NULL) { + if (rmv_all) { + ZERO_CHAIN(buf); + } else { + buf->last = *buf->last_with_datap; + (*buf->last_with_datap)->next = NULL; + } + return (-1); + } + + if (rmv_all) { + buf->first = buf->last = tmp; + buf->last_with_datap = &buf->first; + } else { + (*buf->last_with_datap)->next = tmp; + buf->last = tmp; + } + return (0); + } +} + +int evbuffer_expand(struct evbuffer* buf, size_t datlen) +{ + struct evbuffer_chain* chain; + + EVBUFFER_LOCK(buf); + chain = evbuffer_expand_singlechain(buf, datlen); + EVBUFFER_UNLOCK(buf); + return chain ? 0 : -1; +} + +/* + * Reads data from a file descriptor into a buffer. + */ + +#if defined(EVENT__HAVE_SYS_UIO_H) || defined(_WIN32) +#define USE_IOVEC_IMPL +#endif + +#ifdef USE_IOVEC_IMPL + +#ifdef EVENT__HAVE_SYS_UIO_H +/* number of iovec we use for writev, fragmentation is going to determine + * how much we end up writing */ + +#define DEFAULT_WRITE_IOVEC 128 + +#if defined(UIO_MAXIOV) && UIO_MAXIOV < DEFAULT_WRITE_IOVEC +#define NUM_WRITE_IOVEC UIO_MAXIOV +#elif defined(IOV_MAX) && IOV_MAX < DEFAULT_WRITE_IOVEC +#define NUM_WRITE_IOVEC IOV_MAX +#else +#define NUM_WRITE_IOVEC DEFAULT_WRITE_IOVEC +#endif + +#define IOV_TYPE struct iovec +#define IOV_PTR_FIELD iov_base +#define IOV_LEN_FIELD iov_len +#define IOV_LEN_TYPE size_t +#else +#define NUM_WRITE_IOVEC 16 +#define IOV_TYPE WSABUF +#define IOV_PTR_FIELD buf +#define IOV_LEN_FIELD len +#define IOV_LEN_TYPE unsigned long +#endif +#endif +#define NUM_READ_IOVEC 4 + +#define EVBUFFER_MAX_READ 4096 + +/** Helper function to figure out which space to use for reading data into + an evbuffer. Internal use only. + + @param buf The buffer to read into + @param howmuch How much we want to read. + @param vecs An array of two or more iovecs or WSABUFs. + @param n_vecs_avail The length of vecs + @param chainp A pointer to a variable to hold the first chain we're + reading into. + @param exact Boolean: if true, we do not provide more than 'howmuch' + space in the vectors, even if more space is available. + @return The number of buffers we're using. + */ +int evbuffer_read_setup_vecs_( + struct evbuffer* buf, ev_ssize_t howmuch, struct evbuffer_iovec* vecs, int n_vecs_avail, struct evbuffer_chain*** chainp, int exact) +{ + struct evbuffer_chain* chain; + struct evbuffer_chain** firstchainp; + size_t so_far; + int i; + ASSERT_EVBUFFER_LOCKED(buf); + + if (howmuch < 0) + return -1; + + so_far = 0; + /* Let firstchain be the first chain with any space on it */ + firstchainp = buf->last_with_datap; + if (CHAIN_SPACE_LEN(*firstchainp) == 0) { + firstchainp = &(*firstchainp)->next; + } + + chain = *firstchainp; + for (i = 0; i < n_vecs_avail && so_far < (size_t)howmuch; ++i) { + size_t avail = (size_t)CHAIN_SPACE_LEN(chain); + if (avail > (howmuch - so_far) && exact) + avail = howmuch - so_far; + vecs[i].iov_base = (void*)CHAIN_SPACE_PTR(chain); + vecs[i].iov_len = avail; + so_far += avail; + chain = chain->next; + } + + *chainp = firstchainp; + return i; +} + +static int get_n_bytes_readable_on_socket(evutil_socket_t fd) +{ +#if defined(FIONREAD) && defined(_WIN32) + unsigned long lng = EVBUFFER_MAX_READ; + if (ioctlsocket(fd, FIONREAD, &lng) < 0) + return -1; + /* Can overflow, but mostly harmlessly. XXXX */ + return (int)lng; +#elif defined(FIONREAD) + int n = EVBUFFER_MAX_READ; + if (ioctl(fd, FIONREAD, &n) < 0) + return -1; + return n; +#else + return EVBUFFER_MAX_READ; +#endif +} + +/* TODO(niels): should this function return ev_ssize_t and take ev_ssize_t + * as howmuch? */ +int evbuffer_read(struct evbuffer* buf, evutil_socket_t fd, int howmuch) +{ + struct evbuffer_chain** chainp; + int n; + int result; + +#ifdef USE_IOVEC_IMPL + int nvecs, i, remaining; +#else + struct evbuffer_chain* chain; + unsigned char* p; +#endif + + EVBUFFER_LOCK(buf); + + if (buf->freeze_end) { + result = -1; + goto done; + } + + n = get_n_bytes_readable_on_socket(fd); + if (n <= 0 || n > EVBUFFER_MAX_READ) + n = EVBUFFER_MAX_READ; + if (howmuch < 0 || howmuch > n) + howmuch = n; + +#ifdef USE_IOVEC_IMPL + /* Since we can use iovecs, we're willing to use the last + * NUM_READ_IOVEC chains. */ + if (evbuffer_expand_fast_(buf, howmuch, NUM_READ_IOVEC) == -1) { + result = -1; + goto done; + } else { + IOV_TYPE vecs[NUM_READ_IOVEC]; +#ifdef EVBUFFER_IOVEC_IS_NATIVE_ + nvecs = evbuffer_read_setup_vecs_(buf, howmuch, vecs, NUM_READ_IOVEC, &chainp, 1); +#else + /* We aren't using the native struct iovec. Therefore, + we are on win32. */ + struct evbuffer_iovec ev_vecs[NUM_READ_IOVEC]; + nvecs = evbuffer_read_setup_vecs_(buf, howmuch, ev_vecs, 2, &chainp, 1); + + for (i = 0; i < nvecs; ++i) + WSABUF_FROM_EVBUFFER_IOV(&vecs[i], &ev_vecs[i]); +#endif + +#ifdef _WIN32 + { + DWORD bytesRead; + DWORD flags = 0; + if (WSARecv(fd, vecs, nvecs, &bytesRead, &flags, NULL, NULL)) { + /* The read failed. It might be a close, + * or it might be an error. */ + if (WSAGetLastError() == WSAECONNABORTED) + n = 0; + else + n = -1; + } else + n = bytesRead; + } +#else + n = readv(fd, vecs, nvecs); +#endif + } + +#else /*!USE_IOVEC_IMPL*/ + /* If we don't have FIONREAD, we might waste some space here */ + /* XXX we _will_ waste some space here if there is any space left + * over on buf->last. */ + if ((chain = evbuffer_expand_singlechain(buf, howmuch)) == NULL) { + result = -1; + goto done; + } + + /* We can append new data at this point */ + p = chain->buffer + chain->misalign + chain->off; + +#ifndef _WIN32 + n = read(fd, p, howmuch); +#else + n = recv(fd, p, howmuch, 0); +#endif +#endif /* USE_IOVEC_IMPL */ + + if (n == -1) { + result = -1; + goto done; + } + if (n == 0) { + result = 0; + goto done; + } + +#ifdef USE_IOVEC_IMPL + remaining = n; + for (i = 0; i < nvecs; ++i) { + /* can't overflow, since only mutable chains have + * huge misaligns. */ + size_t space = (size_t)CHAIN_SPACE_LEN(*chainp); + /* XXXX This is a kludge that can waste space in perverse + * situations. */ + if (space > EVBUFFER_CHAIN_MAX) + space = EVBUFFER_CHAIN_MAX; + if ((ev_ssize_t)space < remaining) { + (*chainp)->off += space; + remaining -= (int)space; + } else { + (*chainp)->off += remaining; + buf->last_with_datap = chainp; + break; + } + chainp = &(*chainp)->next; + } +#else + chain->off += n; + advance_last_with_data(buf); +#endif + buf->total_len += n; + buf->n_add_for_cb += n; + + /* Tell someone about changes in this buffer */ + evbuffer_invoke_callbacks_(buf); + result = n; +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +#ifdef USE_IOVEC_IMPL +static inline int evbuffer_write_iovec(struct evbuffer* buffer, evutil_socket_t fd, ev_ssize_t howmuch) +{ + IOV_TYPE iov[NUM_WRITE_IOVEC]; + struct evbuffer_chain* chain = buffer->first; + int n, i = 0; + + if (howmuch < 0) + return -1; + + ASSERT_EVBUFFER_LOCKED(buffer); + /* XXX make this top out at some maximal data length? if the + * buffer has (say) 1MB in it, split over 128 chains, there's + * no way it all gets written in one go. */ + while (chain != NULL && i < NUM_WRITE_IOVEC && howmuch) { +#ifdef USE_SENDFILE + /* we cannot write the file info via writev */ + if (chain->flags & EVBUFFER_SENDFILE) + break; +#endif + iov[i].IOV_PTR_FIELD = (void*)(chain->buffer + chain->misalign); + if ((size_t)howmuch >= chain->off) { + /* XXXcould be problematic when windows supports mmap*/ + iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)chain->off; + howmuch -= chain->off; + } else { + /* XXXcould be problematic when windows supports mmap*/ + iov[i++].IOV_LEN_FIELD = (IOV_LEN_TYPE)howmuch; + break; + } + chain = chain->next; + } + if (!i) + return 0; + +#ifdef _WIN32 + { + DWORD bytesSent; + if (WSASend(fd, iov, i, &bytesSent, 0, NULL, NULL)) + n = -1; + else + n = bytesSent; + } +#else + n = writev(fd, iov, i); +#endif + return (n); +} +#endif + +#ifdef USE_SENDFILE +static inline int evbuffer_write_sendfile(struct evbuffer* buffer, evutil_socket_t dest_fd, ev_ssize_t howmuch) +{ + struct evbuffer_chain* chain = buffer->first; + struct evbuffer_chain_file_segment* info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, chain); + const int source_fd = info->segment->fd; +#if defined(SENDFILE_IS_MACOSX) || defined(SENDFILE_IS_FREEBSD) + int res; + ev_off_t len = chain->off; +#elif defined(SENDFILE_IS_LINUX) || defined(SENDFILE_IS_SOLARIS) + ev_ssize_t res; + ev_off_t offset = chain->misalign; +#endif + + ASSERT_EVBUFFER_LOCKED(buffer); + +#if defined(SENDFILE_IS_MACOSX) + res = sendfile(source_fd, dest_fd, chain->misalign, &len, NULL, 0); + if (res == -1 && !EVUTIL_ERR_RW_RETRIABLE(errno)) + return (-1); + + return (len); +#elif defined(SENDFILE_IS_FREEBSD) + res = sendfile(source_fd, dest_fd, chain->misalign, chain->off, NULL, &len, 0); + if (res == -1 && !EVUTIL_ERR_RW_RETRIABLE(errno)) + return (-1); + + return (len); +#elif defined(SENDFILE_IS_LINUX) + /* TODO(niels): implement splice */ + res = sendfile(dest_fd, source_fd, &offset, chain->off); + if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) { + /* if this is EAGAIN or EINTR return 0; otherwise, -1 */ + return (0); + } + return (res); +#elif defined(SENDFILE_IS_SOLARIS) + { + const off_t offset_orig = offset; + res = sendfile(dest_fd, source_fd, &offset, chain->off); + if (res == -1 && EVUTIL_ERR_RW_RETRIABLE(errno)) { + if (offset - offset_orig) + return offset - offset_orig; + /* if this is EAGAIN or EINTR and no bytes were + * written, return 0 */ + return (0); + } + return (res); + } +#endif +} +#endif + +int evbuffer_write_atmost(struct evbuffer* buffer, evutil_socket_t fd, ev_ssize_t howmuch) +{ + int n = -1; + + EVBUFFER_LOCK(buffer); + + if (buffer->freeze_start) { + goto done; + } + + if (howmuch < 0 || (size_t)howmuch > buffer->total_len) + howmuch = buffer->total_len; + + if (howmuch > 0) { +#ifdef USE_SENDFILE + struct evbuffer_chain* chain = buffer->first; + if (chain != NULL && (chain->flags & EVBUFFER_SENDFILE)) + n = evbuffer_write_sendfile(buffer, fd, howmuch); + else { +#endif +#ifdef USE_IOVEC_IMPL + n = evbuffer_write_iovec(buffer, fd, howmuch); +#elif defined(_WIN32) + /* XXX(nickm) Don't disable this code until we know if + * the WSARecv code above works. */ + void* p = evbuffer_pullup(buffer, howmuch); + EVUTIL_ASSERT(p || !howmuch); + n = send(fd, p, howmuch, 0); +#else + void* p = evbuffer_pullup(buffer, howmuch); + EVUTIL_ASSERT(p || !howmuch); + n = write(fd, p, howmuch); +#endif +#ifdef USE_SENDFILE + } +#endif + } + + if (n > 0) + evbuffer_drain(buffer, n); + +done: + EVBUFFER_UNLOCK(buffer); + return (n); +} + +int evbuffer_write(struct evbuffer* buffer, evutil_socket_t fd) +{ + return evbuffer_write_atmost(buffer, fd, -1); +} + +unsigned char* evbuffer_find(struct evbuffer* buffer, const unsigned char* what, size_t len) +{ + unsigned char* search; + struct evbuffer_ptr ptr; + + EVBUFFER_LOCK(buffer); + + ptr = evbuffer_search(buffer, (const char*)what, len, NULL); + if (ptr.pos < 0) { + search = NULL; + } else { + search = evbuffer_pullup(buffer, ptr.pos + len); + if (search) + search += ptr.pos; + } + EVBUFFER_UNLOCK(buffer); + return search; +} + +/* Subract howfar from the position of pos within + * buf. Returns 0 on success, -1 on failure. + * + * This isn't exposed yet, because of potential inefficiency issues. + * Maybe it should be. */ +static int evbuffer_ptr_subtract(struct evbuffer* buf, struct evbuffer_ptr* pos, size_t howfar) +{ + if (pos->pos < 0) + return -1; + if (howfar > (size_t)pos->pos) + return -1; + if (pos->internal_.chain && howfar <= pos->internal_.pos_in_chain) { + pos->internal_.pos_in_chain -= howfar; + pos->pos -= howfar; + return 0; + } else { + const size_t newpos = pos->pos - howfar; + /* Here's the inefficient part: it walks over the + * chains until we hit newpos. */ + return evbuffer_ptr_set(buf, pos, newpos, EVBUFFER_PTR_SET); + } +} + +int evbuffer_ptr_set(struct evbuffer* buf, struct evbuffer_ptr* pos, size_t position, enum evbuffer_ptr_how how) +{ + size_t left = position; + struct evbuffer_chain* chain = NULL; + int result = 0; + + EVBUFFER_LOCK(buf); + + switch (how) { + case EVBUFFER_PTR_SET: + chain = buf->first; + pos->pos = position; + position = 0; + break; + case EVBUFFER_PTR_ADD: + /* this avoids iterating over all previous chains if + we just want to advance the position */ + if (pos->pos < 0 || EV_SIZE_MAX - position < (size_t)pos->pos) { + EVBUFFER_UNLOCK(buf); + return -1; + } + chain = pos->internal_.chain; + pos->pos += position; + position = pos->internal_.pos_in_chain; + break; + } + + EVUTIL_ASSERT(EV_SIZE_MAX - left >= position); + while (chain && position + left >= chain->off) { + left -= chain->off - position; + chain = chain->next; + position = 0; + } + if (chain) { + pos->internal_.chain = chain; + pos->internal_.pos_in_chain = position + left; + } else if (left == 0) { + /* The first byte in the (nonexistent) chain after the last chain */ + pos->internal_.chain = NULL; + pos->internal_.pos_in_chain = 0; + } else { + PTR_NOT_FOUND(pos); + result = -1; + } + + EVBUFFER_UNLOCK(buf); + + return result; +} + +/** + Compare the bytes in buf at position pos to the len bytes in mem. Return + less than 0, 0, or greater than 0 as memcmp. + */ +static int evbuffer_ptr_memcmp(const struct evbuffer* buf, const struct evbuffer_ptr* pos, const char* mem, size_t len) +{ + struct evbuffer_chain* chain; + size_t position; + int r; + + ASSERT_EVBUFFER_LOCKED(buf); + + if (pos->pos < 0 || EV_SIZE_MAX - len < (size_t)pos->pos || pos->pos + len > buf->total_len) + return -1; + + chain = pos->internal_.chain; + position = pos->internal_.pos_in_chain; + while (len && chain) { + size_t n_comparable; + if (len + position > chain->off) + n_comparable = chain->off - position; + else + n_comparable = len; + r = memcmp(chain->buffer + chain->misalign + position, mem, n_comparable); + if (r) + return r; + mem += n_comparable; + len -= n_comparable; + position = 0; + chain = chain->next; + } + + return 0; +} + +struct evbuffer_ptr evbuffer_search(struct evbuffer* buffer, const char* what, size_t len, const struct evbuffer_ptr* start) +{ + return evbuffer_search_range(buffer, what, len, start, NULL); +} + +struct evbuffer_ptr + evbuffer_search_range(struct evbuffer* buffer, const char* what, size_t len, const struct evbuffer_ptr* start, const struct evbuffer_ptr* end) +{ + struct evbuffer_ptr pos; + struct evbuffer_chain *chain, *last_chain = NULL; + const unsigned char* p; + char first; + + EVBUFFER_LOCK(buffer); + + if (start) { + memcpy(&pos, start, sizeof(pos)); + chain = pos.internal_.chain; + } else { + pos.pos = 0; + chain = pos.internal_.chain = buffer->first; + pos.internal_.pos_in_chain = 0; + } + + if (end) + last_chain = end->internal_.chain; + + if (!len || len > EV_SSIZE_MAX) + goto done; + + first = what[0]; + + while (chain) { + const unsigned char* start_at = chain->buffer + chain->misalign + pos.internal_.pos_in_chain; + p = memchr(start_at, first, chain->off - pos.internal_.pos_in_chain); + if (p) { + pos.pos += p - start_at; + pos.internal_.pos_in_chain += p - start_at; + if (!evbuffer_ptr_memcmp(buffer, &pos, what, len)) { + if (end && pos.pos + (ev_ssize_t)len > end->pos) + goto not_found; + else + goto done; + } + ++pos.pos; + ++pos.internal_.pos_in_chain; + if (pos.internal_.pos_in_chain == chain->off) { + chain = pos.internal_.chain = chain->next; + pos.internal_.pos_in_chain = 0; + } + } else { + if (chain == last_chain) + goto not_found; + pos.pos += chain->off - pos.internal_.pos_in_chain; + chain = pos.internal_.chain = chain->next; + pos.internal_.pos_in_chain = 0; + } + } + +not_found: + PTR_NOT_FOUND(&pos); +done: + EVBUFFER_UNLOCK(buffer); + return pos; +} + +int evbuffer_peek(struct evbuffer* buffer, ev_ssize_t len, struct evbuffer_ptr* start_at, struct evbuffer_iovec* vec, int n_vec) +{ + struct evbuffer_chain* chain; + int idx = 0; + ev_ssize_t len_so_far = 0; + + /* Avoid locking in trivial edge cases */ + if (start_at && start_at->internal_.chain == NULL) + return 0; + + EVBUFFER_LOCK(buffer); + + if (start_at) { + chain = start_at->internal_.chain; + len_so_far = chain->off - start_at->internal_.pos_in_chain; + idx = 1; + if (n_vec > 0) { + vec[0].iov_base = (void*)(chain->buffer + chain->misalign + start_at->internal_.pos_in_chain); + vec[0].iov_len = len_so_far; + } + chain = chain->next; + } else { + chain = buffer->first; + } + + if (n_vec == 0 && len < 0) { + /* If no vectors are provided and they asked for "everything", + * pretend they asked for the actual available amount. */ + len = buffer->total_len; + if (start_at) { + len -= start_at->pos; + } + } + + while (chain) { + if (len >= 0 && len_so_far >= len) + break; + if (idx < n_vec) { + vec[idx].iov_base = (void*)(chain->buffer + chain->misalign); + vec[idx].iov_len = chain->off; + } else if (len < 0) { + break; + } + ++idx; + len_so_far += chain->off; + chain = chain->next; + } + + EVBUFFER_UNLOCK(buffer); + + return idx; +} + +int evbuffer_add_vprintf(struct evbuffer* buf, const char* fmt, va_list ap) +{ + char* buffer; + size_t space; + int sz, result = -1; + va_list aq; + struct evbuffer_chain* chain; + + EVBUFFER_LOCK(buf); + + if (buf->freeze_end) { + goto done; + } + + /* make sure that at least some space is available */ + if ((chain = evbuffer_expand_singlechain(buf, 64)) == NULL) + goto done; + + for (;;) { +#if 0 + size_t used = chain->misalign + chain->off; + buffer = (char *)chain->buffer + chain->misalign + chain->off; + EVUTIL_ASSERT(chain->buffer_len >= used); + space = chain->buffer_len - used; +#endif + buffer = (char*)CHAIN_SPACE_PTR(chain); + space = (size_t)CHAIN_SPACE_LEN(chain); + +#ifndef va_copy +#define va_copy(dst, src) memcpy(&(dst), &(src), sizeof(va_list)) +#endif + va_copy(aq, ap); + + sz = evutil_vsnprintf(buffer, space, fmt, aq); + + va_end(aq); + + if (sz < 0) + goto done; + if (INT_MAX >= EVBUFFER_CHAIN_MAX && (size_t)sz >= EVBUFFER_CHAIN_MAX) + goto done; + if ((size_t)sz < space) { + chain->off += sz; + buf->total_len += sz; + buf->n_add_for_cb += sz; + + advance_last_with_data(buf); + evbuffer_invoke_callbacks_(buf); + result = sz; + goto done; + } + if ((chain = evbuffer_expand_singlechain(buf, sz + 1)) == NULL) + goto done; + } + /* NOTREACHED */ + +done: + EVBUFFER_UNLOCK(buf); + return result; +} + +int evbuffer_add_printf(struct evbuffer* buf, const char* fmt, ...) +{ + int res = -1; + va_list ap; + + va_start(ap, fmt); + res = evbuffer_add_vprintf(buf, fmt, ap); + va_end(ap); + + return (res); +} + +int evbuffer_add_reference(struct evbuffer* outbuf, const void* data, size_t datlen, evbuffer_ref_cleanup_cb cleanupfn, void* extra) +{ + struct evbuffer_chain* chain; + struct evbuffer_chain_reference* info; + int result = -1; + + chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_reference)); + if (!chain) + return (-1); + chain->flags |= EVBUFFER_REFERENCE | EVBUFFER_IMMUTABLE; + chain->buffer = (unsigned char*)data; + chain->buffer_len = datlen; + chain->off = datlen; + + info = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_reference, chain); + info->cleanupfn = cleanupfn; + info->extra = extra; + + EVBUFFER_LOCK(outbuf); + if (outbuf->freeze_end) { + /* don't call chain_free; we do not want to actually invoke + * the cleanup function */ + mm_free(chain); + goto done; + } + evbuffer_chain_insert(outbuf, chain); + outbuf->n_add_for_cb += datlen; + + evbuffer_invoke_callbacks_(outbuf); + + result = 0; +done: + EVBUFFER_UNLOCK(outbuf); + + return result; +} + +/* TODO(niels): we may want to add to automagically convert to mmap, in + * case evbuffer_remove() or evbuffer_pullup() are being used. + */ +struct evbuffer_file_segment* evbuffer_file_segment_new(int fd, ev_off_t offset, ev_off_t length, unsigned flags) +{ + struct evbuffer_file_segment* seg = mm_calloc(sizeof(struct evbuffer_file_segment), 1); + if (!seg) + return NULL; + seg->refcnt = 1; + seg->fd = fd; + seg->flags = flags; + seg->file_offset = offset; + seg->cleanup_cb = NULL; + seg->cleanup_cb_arg = NULL; +#ifdef _WIN32 +#ifndef lseek +#define lseek _lseeki64 +#endif +#ifndef fstat +#define fstat _fstat +#endif +#ifndef stat +#define stat _stat +#endif +#endif + if (length == -1) { + struct stat st; + if (fstat(fd, &st) < 0) + goto err; + length = st.st_size; + } + seg->length = length; + + if (offset < 0 || length < 0 || ((ev_uint64_t)length > EVBUFFER_CHAIN_MAX) || (ev_uint64_t)offset > (ev_uint64_t)(EVBUFFER_CHAIN_MAX - length)) + goto err; + +#if defined(USE_SENDFILE) + if (!(flags & EVBUF_FS_DISABLE_SENDFILE)) { + seg->can_sendfile = 1; + goto done; + } +#endif + + if (evbuffer_file_segment_materialize(seg) < 0) + goto err; + +#if defined(USE_SENDFILE) +done: +#endif + if (!(flags & EVBUF_FS_DISABLE_LOCKING)) { + EVTHREAD_ALLOC_LOCK(seg->lock, 0); + } + return seg; +err: + mm_free(seg); + return NULL; +} + +#ifdef EVENT__HAVE_MMAP +static long get_page_size(void) +{ +#ifdef SC_PAGE_SIZE + return sysconf(SC_PAGE_SIZE); +#elif defined(_SC_PAGE_SIZE) + return sysconf(_SC_PAGE_SIZE); +#else + return 1; +#endif +} +#endif + +/* DOCDOC */ +/* Requires lock */ +static int evbuffer_file_segment_materialize(struct evbuffer_file_segment* seg) +{ + const unsigned flags = seg->flags; + const int fd = seg->fd; + const ev_off_t length = seg->length; + const ev_off_t offset = seg->file_offset; + + if (seg->contents) + return 0; /* already materialized */ + +#if defined(EVENT__HAVE_MMAP) + if (!(flags & EVBUF_FS_DISABLE_MMAP)) { + off_t offset_rounded = 0, offset_leftover = 0; + void* mapped; + if (offset) { + /* mmap implementations don't generally like us + * to have an offset that isn't a round */ + long page_size = get_page_size(); + if (page_size == -1) + goto err; + offset_leftover = offset % page_size; + offset_rounded = offset - offset_leftover; + } + mapped = mmap( + NULL, length + offset_leftover, PROT_READ, +#ifdef MAP_NOCACHE + MAP_NOCACHE | /* ??? */ +#endif +#ifdef MAP_FILE + MAP_FILE | +#endif + MAP_PRIVATE, + fd, offset_rounded); + if (mapped == MAP_FAILED) { + event_warn("%s: mmap(%d, %d, %zu) failed", __func__, fd, 0, (size_t)(offset + length)); + } else { + seg->mapping = mapped; + seg->contents = (char*)mapped + offset_leftover; + seg->mmap_offset = 0; + seg->is_mapping = 1; + goto done; + } + } +#endif +#ifdef _WIN32 + if (!(flags & EVBUF_FS_DISABLE_MMAP)) { + intptr_t h = _get_osfhandle(fd); + HANDLE m; + ev_uint64_t total_size = length + offset; + if ((HANDLE)h == INVALID_HANDLE_VALUE) + goto err; + m = CreateFileMapping((HANDLE)h, NULL, PAGE_READONLY, (total_size >> 32), total_size & 0xfffffffful, NULL); + if (m != INVALID_HANDLE_VALUE) { /* Does h leak? */ + seg->mapping_handle = m; + seg->mmap_offset = offset; + seg->is_mapping = 1; + goto done; + } + } +#endif + { + ev_off_t start_pos = lseek(fd, 0, SEEK_CUR), pos; + ev_off_t read_so_far = 0; + char* mem; + int e; + ev_ssize_t n = 0; + if (!(mem = mm_malloc(length))) + goto err; + if (start_pos < 0) { + mm_free(mem); + goto err; + } + if (lseek(fd, offset, SEEK_SET) < 0) { + mm_free(mem); + goto err; + } + while (read_so_far < length) { + n = read(fd, mem + read_so_far, length - read_so_far); + if (n <= 0) + break; + read_so_far += n; + } + + e = errno; + pos = lseek(fd, start_pos, SEEK_SET); + if (n < 0 || (n == 0 && length > read_so_far)) { + mm_free(mem); + errno = e; + goto err; + } else if (pos < 0) { + mm_free(mem); + goto err; + } + + seg->contents = mem; + } + +done: + return 0; +err: + return -1; +} + +void evbuffer_file_segment_add_cleanup_cb(struct evbuffer_file_segment* seg, evbuffer_file_segment_cleanup_cb cb, void* arg) +{ + EVUTIL_ASSERT(seg->refcnt > 0); + seg->cleanup_cb = cb; + seg->cleanup_cb_arg = arg; +} + +void evbuffer_file_segment_free(struct evbuffer_file_segment* seg) +{ + int refcnt; + EVLOCK_LOCK(seg->lock, 0); + refcnt = --seg->refcnt; + EVLOCK_UNLOCK(seg->lock, 0); + if (refcnt > 0) + return; + EVUTIL_ASSERT(refcnt == 0); + + if (seg->is_mapping) { +#ifdef _WIN32 + CloseHandle(seg->mapping_handle); +#elif defined(EVENT__HAVE_MMAP) + off_t offset_leftover; + offset_leftover = seg->file_offset % get_page_size(); + if (munmap(seg->mapping, seg->length + offset_leftover) == -1) + event_warn("%s: munmap failed", __func__); +#endif + } else if (seg->contents) { + mm_free(seg->contents); + } + + if ((seg->flags & EVBUF_FS_CLOSE_ON_FREE) && seg->fd >= 0) { + close(seg->fd); + } + + if (seg->cleanup_cb) { + (*seg->cleanup_cb)((struct evbuffer_file_segment const*)seg, seg->flags, seg->cleanup_cb_arg); + seg->cleanup_cb = NULL; + seg->cleanup_cb_arg = NULL; + } + + EVTHREAD_FREE_LOCK(seg->lock, 0); + mm_free(seg); +} + +int evbuffer_add_file_segment(struct evbuffer* buf, struct evbuffer_file_segment* seg, ev_off_t offset, ev_off_t length) +{ + struct evbuffer_chain* chain; + struct evbuffer_chain_file_segment* extra; + int can_use_sendfile = 0; + + EVBUFFER_LOCK(buf); + EVLOCK_LOCK(seg->lock, 0); + if (buf->flags & EVBUFFER_FLAG_DRAINS_TO_FD) { + can_use_sendfile = 1; + } else { + if (!seg->contents) { + if (evbuffer_file_segment_materialize(seg) < 0) { + EVLOCK_UNLOCK(seg->lock, 0); + EVBUFFER_UNLOCK(buf); + return -1; + } + } + } + ++seg->refcnt; + EVLOCK_UNLOCK(seg->lock, 0); + + if (buf->freeze_end) + goto err; + + if (length < 0) { + if (offset > seg->length) + goto err; + length = seg->length - offset; + } + + /* Can we actually add this? */ + if (offset + length > seg->length) + goto err; + + chain = evbuffer_chain_new(sizeof(struct evbuffer_chain_file_segment)); + if (!chain) + goto err; + extra = EVBUFFER_CHAIN_EXTRA(struct evbuffer_chain_file_segment, chain); + + chain->flags |= EVBUFFER_IMMUTABLE | EVBUFFER_FILESEGMENT; + if (can_use_sendfile && seg->can_sendfile) { + chain->flags |= EVBUFFER_SENDFILE; + chain->misalign = seg->file_offset + offset; + chain->off = length; + chain->buffer_len = chain->misalign + length; + } else if (seg->is_mapping) { +#ifdef _WIN32 + ev_uint64_t total_offset = seg->mmap_offset + offset; + ev_uint64_t offset_rounded = 0, offset_remaining = 0; + LPVOID data; + if (total_offset) { + SYSTEM_INFO si; + memset(&si, 0, sizeof(si)); /* cargo cult */ + GetSystemInfo(&si); + offset_remaining = total_offset % si.dwAllocationGranularity; + offset_rounded = total_offset - offset_remaining; + } + data = MapViewOfFile(seg->mapping_handle, FILE_MAP_READ, offset_rounded >> 32, offset_rounded & 0xfffffffful, length + offset_remaining); + if (data == NULL) { + mm_free(chain); + goto err; + } + chain->buffer = (unsigned char*)data; + chain->buffer_len = length + offset_remaining; + chain->misalign = offset_remaining; + chain->off = length; +#else + chain->buffer = (unsigned char*)(seg->contents + offset); + chain->buffer_len = length; + chain->off = length; +#endif + } else { + chain->buffer = (unsigned char*)(seg->contents + offset); + chain->buffer_len = length; + chain->off = length; + } + + extra->segment = seg; + buf->n_add_for_cb += length; + evbuffer_chain_insert(buf, chain); + + evbuffer_invoke_callbacks_(buf); + + EVBUFFER_UNLOCK(buf); + + return 0; +err: + EVBUFFER_UNLOCK(buf); + evbuffer_file_segment_free(seg); /* Lowers the refcount */ + return -1; +} + +int evbuffer_add_file(struct evbuffer* buf, int fd, ev_off_t offset, ev_off_t length) +{ + struct evbuffer_file_segment* seg; + unsigned flags = EVBUF_FS_CLOSE_ON_FREE; + int r; + + seg = evbuffer_file_segment_new(fd, offset, length, flags); + if (!seg) + return -1; + r = evbuffer_add_file_segment(buf, seg, 0, length); + if (r == 0) + evbuffer_file_segment_free(seg); + return r; +} + +void evbuffer_setcb(struct evbuffer* buffer, evbuffer_cb cb, void* cbarg) +{ + EVBUFFER_LOCK(buffer); + + if (!LIST_EMPTY(&buffer->callbacks)) + evbuffer_remove_all_callbacks(buffer); + + if (cb) { + struct evbuffer_cb_entry* ent = evbuffer_add_cb(buffer, NULL, cbarg); + ent->cb.cb_obsolete = cb; + ent->flags |= EVBUFFER_CB_OBSOLETE; + } + EVBUFFER_UNLOCK(buffer); +} + +struct evbuffer_cb_entry* evbuffer_add_cb(struct evbuffer* buffer, evbuffer_cb_func cb, void* cbarg) +{ + struct evbuffer_cb_entry* e; + if (!(e = mm_calloc(1, sizeof(struct evbuffer_cb_entry)))) + return NULL; + EVBUFFER_LOCK(buffer); + e->cb.cb_func = cb; + e->cbarg = cbarg; + e->flags = EVBUFFER_CB_ENABLED; + LIST_INSERT_HEAD(&buffer->callbacks, e, next); + EVBUFFER_UNLOCK(buffer); + return e; +} + +int evbuffer_remove_cb_entry(struct evbuffer* buffer, struct evbuffer_cb_entry* ent) +{ + EVBUFFER_LOCK(buffer); + LIST_REMOVE(ent, next); + EVBUFFER_UNLOCK(buffer); + mm_free(ent); + return 0; +} + +int evbuffer_remove_cb(struct evbuffer* buffer, evbuffer_cb_func cb, void* cbarg) +{ + struct evbuffer_cb_entry* cbent; + int result = -1; + EVBUFFER_LOCK(buffer); + LIST_FOREACH(cbent, &buffer->callbacks, next) + { + if (cb == cbent->cb.cb_func && cbarg == cbent->cbarg) { + result = evbuffer_remove_cb_entry(buffer, cbent); + goto done; + } + } +done: + EVBUFFER_UNLOCK(buffer); + return result; +} + +int evbuffer_cb_set_flags(struct evbuffer* buffer, struct evbuffer_cb_entry* cb, ev_uint32_t flags) +{ + /* the user isn't allowed to mess with these. */ + flags &= ~EVBUFFER_CB_INTERNAL_FLAGS; + EVBUFFER_LOCK(buffer); + cb->flags |= flags; + EVBUFFER_UNLOCK(buffer); + return 0; +} + +int evbuffer_cb_clear_flags(struct evbuffer* buffer, struct evbuffer_cb_entry* cb, ev_uint32_t flags) +{ + /* the user isn't allowed to mess with these. */ + flags &= ~EVBUFFER_CB_INTERNAL_FLAGS; + EVBUFFER_LOCK(buffer); + cb->flags &= ~flags; + EVBUFFER_UNLOCK(buffer); + return 0; +} + +int evbuffer_freeze(struct evbuffer* buffer, int start) +{ + EVBUFFER_LOCK(buffer); + if (start) + buffer->freeze_start = 1; + else + buffer->freeze_end = 1; + EVBUFFER_UNLOCK(buffer); + return 0; +} + +int evbuffer_unfreeze(struct evbuffer* buffer, int start) +{ + EVBUFFER_LOCK(buffer); + if (start) + buffer->freeze_start = 0; + else + buffer->freeze_end = 0; + EVBUFFER_UNLOCK(buffer); + return 0; +} + +#if 0 +void +evbuffer_cb_suspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb) +{ + if (!(cb->flags & EVBUFFER_CB_SUSPENDED)) { + cb->size_before_suspend = evbuffer_get_length(buffer); + cb->flags |= EVBUFFER_CB_SUSPENDED; + } +} + +void +evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb) +{ + if ((cb->flags & EVBUFFER_CB_SUSPENDED)) { + unsigned call = (cb->flags & EVBUFFER_CB_CALL_ON_UNSUSPEND); + size_t sz = cb->size_before_suspend; + cb->flags &= ~(EVBUFFER_CB_SUSPENDED| + EVBUFFER_CB_CALL_ON_UNSUSPEND); + cb->size_before_suspend = 0; + if (call && (cb->flags & EVBUFFER_CB_ENABLED)) { + cb->cb(buffer, sz, evbuffer_get_length(buffer), cb->cbarg); + } + } +} +#endif + +int evbuffer_get_callbacks_(struct evbuffer* buffer, struct event_callback** cbs, int max_cbs) +{ + int r = 0; + EVBUFFER_LOCK(buffer); + if (buffer->deferred_cbs) { + if (max_cbs < 1) { + r = -1; + goto done; + } + cbs[0] = &buffer->deferred; + r = 1; + } +done: + EVBUFFER_UNLOCK(buffer); + return r; +} diff --git a/asynio/event/buffer.h b/asynio/event/buffer.h new file mode 100644 index 0000000000000000000000000000000000000000..c7cb6869ff4d814a024bab9d1e0e1df39442300f --- /dev/null +++ b/asynio/event/buffer.h @@ -0,0 +1,228 @@ + +#ifndef EVENT2_BUFFER_H_INCLUDED_ +#define EVENT2_BUFFER_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_SYS_UIO_H +#include +#endif + +#include + +#include "util.h" + +struct evbuffer +#ifdef EVENT_IN_DOXYGEN_ +{ +} +#endif +; + +struct evbuffer_ptr { + ev_ssize_t pos; + struct { + void* chain; + size_t pos_in_chain; + } internal_; +}; + +#ifdef EVENT__HAVE_SYS_UIO_H +#define evbuffer_iovec iovec +/* Internal use -- defined only if we are using the native struct iovec */ +#define EVBUFFER_IOVEC_IS_NATIVE_ +#else +struct evbuffer_iovec { + /** The start of the extent of memory. */ + void* iov_base; + /** The length of the extent of memory. */ + size_t iov_len; +}; +#endif + +struct evbuffer* evbuffer_new(void); + +void evbuffer_free(struct evbuffer* buf); + +int evbuffer_enable_locking(struct evbuffer* buf, void* lock); + +void evbuffer_lock(struct evbuffer* buf); + +void evbuffer_unlock(struct evbuffer* buf); + +#define EVBUFFER_FLAG_DRAINS_TO_FD 1 + +int evbuffer_set_flags(struct evbuffer* buf, ev_uint64_t flags); +int evbuffer_clear_flags(struct evbuffer* buf, ev_uint64_t flags); +size_t evbuffer_get_length(const struct evbuffer* buf); +size_t evbuffer_get_contiguous_space(const struct evbuffer* buf); +int evbuffer_expand(struct evbuffer* buf, size_t datlen); + +int evbuffer_reserve_space(struct evbuffer* buf, ev_ssize_t size, struct evbuffer_iovec* vec, int n_vec); + +int evbuffer_commit_space(struct evbuffer* buf, struct evbuffer_iovec* vec, int n_vecs); + +int evbuffer_add(struct evbuffer* buf, const void* data, size_t datlen); + +int evbuffer_remove(struct evbuffer* buf, void* data, size_t datlen); + +ev_ssize_t evbuffer_copyout(struct evbuffer* buf, void* data_out, size_t datlen); + +ev_ssize_t evbuffer_copyout_from(struct evbuffer* buf, const struct evbuffer_ptr* pos, void* data_out, size_t datlen); + +int evbuffer_remove_buffer(struct evbuffer* src, struct evbuffer* dst, size_t datlen); + +enum evbuffer_eol_style { + /** Any sequence of CR and LF characters is acceptable as an + * EOL. + * + * Note that this style can produce ambiguous results: the + * sequence "CRLF" will be treated as a single EOL if it is + * all in the buffer at once, but if you first read a CR from + * the network and later read an LF from the network, it will + * be treated as two EOLs. + */ + EVBUFFER_EOL_ANY, + /** An EOL is an LF, optionally preceded by a CR. This style is + * most useful for implementing text-based internet protocols. */ + EVBUFFER_EOL_CRLF, + /** An EOL is a CR followed by an LF. */ + EVBUFFER_EOL_CRLF_STRICT, + /** An EOL is a LF. */ + EVBUFFER_EOL_LF, + /** An EOL is a NUL character (that is, a single byte with value 0) */ + EVBUFFER_EOL_NUL +}; + +char* evbuffer_readln(struct evbuffer* buffer, size_t* n_read_out, enum evbuffer_eol_style eol_style); + +int evbuffer_add_buffer(struct evbuffer* outbuf, struct evbuffer* inbuf); + +int evbuffer_add_buffer_reference(struct evbuffer* outbuf, struct evbuffer* inbuf); + +typedef void (*evbuffer_ref_cleanup_cb)(const void* data, size_t datalen, void* extra); + +int evbuffer_add_reference(struct evbuffer* outbuf, const void* data, size_t datlen, evbuffer_ref_cleanup_cb cleanupfn, void* cleanupfn_arg); + +int evbuffer_add_file(struct evbuffer* outbuf, int fd, ev_off_t offset, ev_off_t length); + +struct evbuffer_file_segment; + +#define EVBUF_FS_CLOSE_ON_FREE 0x01 +#define EVBUF_FS_DISABLE_MMAP 0x02 +#define EVBUF_FS_DISABLE_SENDFILE 0x04 +#define EVBUF_FS_DISABLE_LOCKING 0x08 + +typedef void (*evbuffer_file_segment_cleanup_cb)(struct evbuffer_file_segment const* seg, int flags, void* arg); + +struct evbuffer_file_segment* evbuffer_file_segment_new(int fd, ev_off_t offset, ev_off_t length, unsigned flags); + +void evbuffer_file_segment_free(struct evbuffer_file_segment* seg); + +void evbuffer_file_segment_add_cleanup_cb(struct evbuffer_file_segment* seg, evbuffer_file_segment_cleanup_cb cb, void* arg); + +int evbuffer_add_file_segment(struct evbuffer* buf, struct evbuffer_file_segment* seg, ev_off_t offset, ev_off_t length); + +int evbuffer_add_printf(struct evbuffer* buf, const char* fmt, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 2, 3))) +#endif + ; + +int evbuffer_add_vprintf(struct evbuffer* buf, const char* fmt, va_list ap) +#ifdef __GNUC__ + __attribute__((format(printf, 2, 0))) +#endif + ; + +int evbuffer_drain(struct evbuffer* buf, size_t len); + +int evbuffer_write(struct evbuffer* buffer, evutil_socket_t fd); + +int evbuffer_write_atmost(struct evbuffer* buffer, evutil_socket_t fd, ev_ssize_t howmuch); + +int evbuffer_read(struct evbuffer* buffer, evutil_socket_t fd, int howmuch); + +struct evbuffer_ptr evbuffer_search(struct evbuffer* buffer, const char* what, size_t len, const struct evbuffer_ptr* start); + +struct evbuffer_ptr + evbuffer_search_range(struct evbuffer* buffer, const char* what, size_t len, const struct evbuffer_ptr* start, const struct evbuffer_ptr* end); + +enum evbuffer_ptr_how { + /** Sets the pointer to the position; can be called on with an + uninitialized evbuffer_ptr. */ + EVBUFFER_PTR_SET, + /** Advances the pointer by adding to the current position. */ + EVBUFFER_PTR_ADD +}; + +int evbuffer_ptr_set(struct evbuffer* buffer, struct evbuffer_ptr* ptr, size_t position, enum evbuffer_ptr_how how); + +struct evbuffer_ptr evbuffer_search_eol(struct evbuffer* buffer, struct evbuffer_ptr* start, size_t* eol_len_out, enum evbuffer_eol_style eol_style); + +int evbuffer_peek(struct evbuffer* buffer, ev_ssize_t len, struct evbuffer_ptr* start_at, struct evbuffer_iovec* vec_out, int n_vec); + +struct evbuffer_cb_info { + /** The number of bytes in this evbuffer when callbacks were last + * invoked. */ + size_t orig_size; + /** The number of bytes added since callbacks were last invoked. */ + size_t n_added; + /** The number of bytes removed since callbacks were last invoked. */ + size_t n_deleted; +}; + +typedef void (*evbuffer_cb_func)(struct evbuffer* buffer, const struct evbuffer_cb_info* info, void* arg); + +struct evbuffer_cb_entry; + +struct evbuffer_cb_entry* evbuffer_add_cb(struct evbuffer* buffer, evbuffer_cb_func cb, void* cbarg); + +int evbuffer_remove_cb_entry(struct evbuffer* buffer, struct evbuffer_cb_entry* ent); + +int evbuffer_remove_cb(struct evbuffer* buffer, evbuffer_cb_func cb, void* cbarg); + +#define EVBUFFER_CB_ENABLED 1 + +int evbuffer_cb_set_flags(struct evbuffer* buffer, struct evbuffer_cb_entry* cb, ev_uint32_t flags); + +int evbuffer_cb_clear_flags(struct evbuffer* buffer, struct evbuffer_cb_entry* cb, ev_uint32_t flags); + +#if 0 + + +void evbuffer_cb_suspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb); + +void evbuffer_cb_unsuspend(struct evbuffer *buffer, struct evbuffer_cb_entry *cb); + +#endif + +unsigned char* evbuffer_pullup(struct evbuffer* buf, ev_ssize_t size); + +int evbuffer_prepend(struct evbuffer* buf, const void* data, size_t size); + +int evbuffer_prepend_buffer(struct evbuffer* dst, struct evbuffer* src); + +int evbuffer_freeze(struct evbuffer* buf, int at_front); + +int evbuffer_unfreeze(struct evbuffer* buf, int at_front); + +struct event_base; + +int evbuffer_defer_callbacks(struct evbuffer* buffer, struct event_base* base); + +size_t evbuffer_add_iovec(struct evbuffer* buffer, struct evbuffer_iovec* vec, int n_vec); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/buffer_compat.h b/asynio/event/buffer_compat.h new file mode 100644 index 0000000000000000000000000000000000000000..b9856d70efe84420df0ab41a4ae4084e35221ade --- /dev/null +++ b/asynio/event/buffer_compat.h @@ -0,0 +1,17 @@ +#ifndef EVENT2_BUFFER_COMPAT_H_INCLUDED_ +#define EVENT2_BUFFER_COMPAT_H_INCLUDED_ + +#include "evconfig.h" + +char* evbuffer_readline(struct evbuffer* buffer); + +typedef void (*evbuffer_cb)(struct evbuffer* buffer, size_t old_len, size_t new_len, void* arg); + +void evbuffer_setcb(struct evbuffer* buffer, evbuffer_cb cb, void* cbarg); + +unsigned char* evbuffer_find(struct evbuffer* buffer, const unsigned char* what, size_t len); + +#define EVBUFFER_LENGTH(x) evbuffer_get_length(x) +#define EVBUFFER_DATA(x) evbuffer_pullup((x), -1) + +#endif diff --git a/asynio/event/buffer_iocp.c b/asynio/event/buffer_iocp.c new file mode 100644 index 0000000000000000000000000000000000000000..8998b854c6a65a08fc00a4b2ce6423a3d9d55e16 --- /dev/null +++ b/asynio/event/buffer_iocp.c @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + @file buffer_iocp.c + + This module implements overlapped read and write functions for evbuffer + objects on Windows. +*/ +#include "event-config.h" +#include "evconfig-private.h" + +#include "event2/buffer.h" +#include "event2/buffer_compat.h" +#include "event2/util.h" +#include "event2/thread.h" +#include "util-internal.h" +#include "evthread-internal.h" +#include "evbuffer-internal.h" +#include "iocp-internal.h" +#include "mm-internal.h" + +#include +#include +#include + +#define MAX_WSABUFS 16 + +/** An evbuffer that can handle overlapped IO. */ +struct evbuffer_overlapped { + struct evbuffer buffer; + /** The socket that we're doing overlapped IO on. */ + evutil_socket_t fd; + + /** pending I/O type */ + unsigned read_in_progress : 1; + unsigned write_in_progress : 1; + + /** The first pinned chain in the buffer. */ + struct evbuffer_chain* first_pinned; + + /** How many chains are pinned; how many of the fields in buffers + * are we using. */ + int n_buffers; + WSABUF buffers[MAX_WSABUFS]; +}; + +/** Given an evbuffer, return the correponding evbuffer structure, or NULL if + * the evbuffer isn't overlapped. */ +static inline struct evbuffer_overlapped* upcast_evbuffer(struct evbuffer* buf) +{ + if (!buf || !buf->is_overlapped) + return NULL; + return EVUTIL_UPCAST(buf, struct evbuffer_overlapped, buffer); +} + +/** Unpin all the chains noted as pinned in 'eo'. */ +static void pin_release(struct evbuffer_overlapped* eo, unsigned flag) +{ + int i; + struct evbuffer_chain *next, *chain = eo->first_pinned; + + for (i = 0; i < eo->n_buffers; ++i) { + EVUTIL_ASSERT(chain); + next = chain->next; + evbuffer_chain_unpin_(chain, flag); + chain = next; + } +} + +void evbuffer_commit_read_(struct evbuffer* evbuf, ev_ssize_t nBytes) +{ + struct evbuffer_overlapped* buf = upcast_evbuffer(evbuf); + struct evbuffer_chain** chainp; + size_t remaining, len; + unsigned i; + + EVBUFFER_LOCK(evbuf); + EVUTIL_ASSERT(buf->read_in_progress && !buf->write_in_progress); + EVUTIL_ASSERT(nBytes >= 0); /* XXXX Can this be false? */ + + evbuffer_unfreeze(evbuf, 0); + + chainp = evbuf->last_with_datap; + if (!((*chainp)->flags & EVBUFFER_MEM_PINNED_R)) + chainp = &(*chainp)->next; + remaining = nBytes; + for (i = 0; remaining > 0 && i < (unsigned)buf->n_buffers; ++i) { + EVUTIL_ASSERT(*chainp); + len = buf->buffers[i].len; + if (remaining < len) + len = remaining; + (*chainp)->off += len; + evbuf->last_with_datap = chainp; + remaining -= len; + chainp = &(*chainp)->next; + } + + pin_release(buf, EVBUFFER_MEM_PINNED_R); + + buf->read_in_progress = 0; + + evbuf->total_len += nBytes; + evbuf->n_add_for_cb += nBytes; + + evbuffer_invoke_callbacks_(evbuf); + + evbuffer_decref_and_unlock_(evbuf); +} + +void evbuffer_commit_write_(struct evbuffer* evbuf, ev_ssize_t nBytes) +{ + struct evbuffer_overlapped* buf = upcast_evbuffer(evbuf); + + EVBUFFER_LOCK(evbuf); + EVUTIL_ASSERT(buf->write_in_progress && !buf->read_in_progress); + evbuffer_unfreeze(evbuf, 1); + evbuffer_drain(evbuf, nBytes); + pin_release(buf, EVBUFFER_MEM_PINNED_W); + buf->write_in_progress = 0; + evbuffer_decref_and_unlock_(evbuf); +} + +struct evbuffer* evbuffer_overlapped_new_(evutil_socket_t fd) +{ + struct evbuffer_overlapped* evo; + + evo = mm_calloc(1, sizeof(struct evbuffer_overlapped)); + if (!evo) + return NULL; + + LIST_INIT(&evo->buffer.callbacks); + evo->buffer.refcnt = 1; + evo->buffer.last_with_datap = &evo->buffer.first; + + evo->buffer.is_overlapped = 1; + evo->fd = fd; + + return &evo->buffer; +} + +int evbuffer_launch_write_(struct evbuffer* buf, ev_ssize_t at_most, struct event_overlapped* ol) +{ + struct evbuffer_overlapped* buf_o = upcast_evbuffer(buf); + int r = -1; + int i; + struct evbuffer_chain* chain; + DWORD bytesSent; + + if (!buf) { + /* No buffer, or it isn't overlapped */ + return -1; + } + + EVBUFFER_LOCK(buf); + EVUTIL_ASSERT(!buf_o->read_in_progress); + if (buf->freeze_start || buf_o->write_in_progress) + goto done; + if (!buf->total_len) { + /* Nothing to write */ + r = 0; + goto done; + } else if (at_most < 0 || (size_t)at_most > buf->total_len) { + at_most = buf->total_len; + } + evbuffer_freeze(buf, 1); + + buf_o->first_pinned = NULL; + buf_o->n_buffers = 0; + memset(buf_o->buffers, 0, sizeof(buf_o->buffers)); + + chain = buf_o->first_pinned = buf->first; + + for (i = 0; i < MAX_WSABUFS && chain; ++i, chain = chain->next) { + WSABUF* b = &buf_o->buffers[i]; + b->buf = (char*)(chain->buffer + chain->misalign); + evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_W); + + if ((size_t)at_most > chain->off) { + /* XXXX Cast is safe for now, since win32 has no + mmaped chains. But later, we need to have this + add more WSAbufs if chain->off is greater than + ULONG_MAX */ + b->len = (unsigned long)chain->off; + at_most -= chain->off; + } else { + b->len = (unsigned long)at_most; + ++i; + break; + } + } + + buf_o->n_buffers = i; + evbuffer_incref_(buf); + if (WSASend(buf_o->fd, buf_o->buffers, i, &bytesSent, 0, &ol->overlapped, NULL)) { + int error = WSAGetLastError(); + if (error != WSA_IO_PENDING) { + /* An actual error. */ + pin_release(buf_o, EVBUFFER_MEM_PINNED_W); + evbuffer_unfreeze(buf, 1); + evbuffer_free(buf); /* decref */ + goto done; + } + } + + buf_o->write_in_progress = 1; + r = 0; +done: + EVBUFFER_UNLOCK(buf); + return r; +} + +int evbuffer_launch_read_(struct evbuffer* buf, size_t at_most, struct event_overlapped* ol) +{ + struct evbuffer_overlapped* buf_o = upcast_evbuffer(buf); + int r = -1, i; + int nvecs; + int npin = 0; + struct evbuffer_chain *chain = NULL, **chainp; + DWORD bytesRead; + DWORD flags = 0; + struct evbuffer_iovec vecs[MAX_WSABUFS]; + + if (!buf_o) + return -1; + EVBUFFER_LOCK(buf); + EVUTIL_ASSERT(!buf_o->write_in_progress); + if (buf->freeze_end || buf_o->read_in_progress) + goto done; + + buf_o->first_pinned = NULL; + buf_o->n_buffers = 0; + memset(buf_o->buffers, 0, sizeof(buf_o->buffers)); + + if (evbuffer_expand_fast_(buf, at_most, MAX_WSABUFS) == -1) + goto done; + evbuffer_freeze(buf, 0); + + nvecs = evbuffer_read_setup_vecs_(buf, at_most, vecs, MAX_WSABUFS, &chainp, 1); + for (i = 0; i < nvecs; ++i) { + WSABUF_FROM_EVBUFFER_IOV(&buf_o->buffers[i], &vecs[i]); + } + + buf_o->n_buffers = nvecs; + buf_o->first_pinned = chain = *chainp; + + npin = 0; + for (; chain; chain = chain->next) { + evbuffer_chain_pin_(chain, EVBUFFER_MEM_PINNED_R); + ++npin; + } + EVUTIL_ASSERT(npin == nvecs); + + evbuffer_incref_(buf); + if (WSARecv(buf_o->fd, buf_o->buffers, nvecs, &bytesRead, &flags, &ol->overlapped, NULL)) { + int error = WSAGetLastError(); + if (error != WSA_IO_PENDING) { + /* An actual error. */ + pin_release(buf_o, EVBUFFER_MEM_PINNED_R); + evbuffer_unfreeze(buf, 0); + evbuffer_free(buf); /* decref */ + goto done; + } + } + + buf_o->read_in_progress = 1; + r = 0; +done: + EVBUFFER_UNLOCK(buf); + return r; +} + +evutil_socket_t evbuffer_overlapped_get_fd_(struct evbuffer* buf) +{ + struct evbuffer_overlapped* buf_o = upcast_evbuffer(buf); + return buf_o ? buf_o->fd : -1; +} + +void evbuffer_overlapped_set_fd_(struct evbuffer* buf, evutil_socket_t fd) +{ + struct evbuffer_overlapped* buf_o = upcast_evbuffer(buf); + EVBUFFER_LOCK(buf); + /* XXX is this right?, should it cancel current I/O operations? */ + if (buf_o) + buf_o->fd = fd; + EVBUFFER_UNLOCK(buf); +} diff --git a/asynio/event/bufferevent-internal.h b/asynio/event/bufferevent-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..918a1f503b9bffab80ce64058809a1c584e908d9 --- /dev/null +++ b/asynio/event/bufferevent-internal.h @@ -0,0 +1,388 @@ +#ifndef BUFFEREVENT_INTERNAL_H_INCLUDED_ +#define BUFFEREVENT_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#include "event_struct.h" +#include "evconfig-private.h" +#include "util.h" +#include "defer-internal.h" +#include "evthread-internal.h" +#include "thread-internal.h" +#include "ratelim-internal.h" +#include "bufferevent_struct.h" + +#include "ipv6-internal.h" + +#ifdef _WIN32 +#include +#endif +#ifdef EVENT__HAVE_NETINET_IN_H +#include +#endif +#ifdef EVENT__HAVE_NETINET_IN6_H +#include +#endif + +#define BEV_SUSPEND_WM 0x01 +/* On a base bufferevent: when we have emptied a bandwidth buckets */ +#define BEV_SUSPEND_BW 0x02 +/* On a base bufferevent: when we have emptied the group's bandwidth bucket. */ +#define BEV_SUSPEND_BW_GROUP 0x04 +/* On a socket bufferevent: can't do any operations while we're waiting for + * name lookup to finish. */ +#define BEV_SUSPEND_LOOKUP 0x08 +/* On a base bufferevent, for reading: used when a filter has choked this + * (underlying) bufferevent because it has stopped reading from it. */ +#define BEV_SUSPEND_FILT_READ 0x10 + +typedef ev_uint16_t bufferevent_suspend_flags; + +struct bufferevent_rate_limit_group { + /** List of all members in the group */ + LIST_HEAD(rlim_group_member_list, bufferevent_private) members; + /** Current limits for the group. */ + struct ev_token_bucket rate_limit; + struct ev_token_bucket_cfg rate_limit_cfg; + + /** True iff we don't want to read from any member of the group.until + * the token bucket refills. */ + unsigned read_suspended : 1; + /** True iff we don't want to write from any member of the group.until + * the token bucket refills. */ + unsigned write_suspended : 1; + /** True iff we were unable to suspend one of the bufferevents in the + * group for reading the last time we tried, and we should try + * again. */ + unsigned pending_unsuspend_read : 1; + /** True iff we were unable to suspend one of the bufferevents in the + * group for writing the last time we tried, and we should try + * again. */ + unsigned pending_unsuspend_write : 1; + + /*@{*/ + /** Total number of bytes read or written in this group since last + * reset. */ + ev_uint64_t total_read; + ev_uint64_t total_written; + /*@}*/ + + /** The number of bufferevents in the group. */ + int n_members; + + /** The smallest number of bytes that any member of the group should + * be limited to read or write at a time. */ + ev_ssize_t min_share; + ev_ssize_t configured_min_share; + + /** Timeout event that goes off once a tick, when the bucket is ready + * to refill. */ + struct event master_refill_event; + + /** Seed for weak random number generator. Protected by 'lock' */ + struct evutil_weakrand_state weakrand_seed; + + /** Lock to protect the members of this group. This lock should nest + * within every bufferevent lock: if you are holding this lock, do + * not assume you can lock another bufferevent. */ + void* lock; +}; + +/** Fields for rate-limiting a single bufferevent. */ +struct bufferevent_rate_limit { + /* Linked-list elements for storing this bufferevent_private in a + * group. + * + * Note that this field is supposed to be protected by the group + * lock */ + LIST_ENTRY(bufferevent_private) next_in_group; + /** The rate-limiting group for this bufferevent, or NULL if it is + * only rate-limited on its own. */ + struct bufferevent_rate_limit_group* group; + + /* This bufferevent's current limits. */ + struct ev_token_bucket limit; + /* Pointer to the rate-limit configuration for this bufferevent. + * Can be shared. XXX reference-count this? */ + struct ev_token_bucket_cfg* cfg; + + /* Timeout event used when one this bufferevent's buckets are + * empty. */ + struct event refill_bucket_event; +}; + +/** Parts of the bufferevent structure that are shared among all bufferevent + * types, but not exposed in bufferevent_struct.h. */ +struct bufferevent_private { + /** The underlying bufferevent structure. */ + struct bufferevent bev; + + /** Evbuffer callback to enforce watermarks on input. */ + struct evbuffer_cb_entry* read_watermarks_cb; + + /** If set, we should free the lock when we free the bufferevent. */ + unsigned own_lock : 1; + + /** Flag: set if we have deferred callbacks and a read callback is + * pending. */ + unsigned readcb_pending : 1; + /** Flag: set if we have deferred callbacks and a write callback is + * pending. */ + unsigned writecb_pending : 1; + /** Flag: set if we are currently busy connecting. */ + unsigned connecting : 1; + /** Flag: set if a connect failed prematurely; this is a hack for + * getting around the bufferevent abstraction. */ + unsigned connection_refused : 1; + /** Set to the events pending if we have deferred callbacks and + * an events callback is pending. */ + short eventcb_pending; + + /** If set, read is suspended until one or more conditions are over. + * The actual value here is a bitfield of those conditions; see the + * BEV_SUSPEND_* flags above. */ + bufferevent_suspend_flags read_suspended; + + /** If set, writing is suspended until one or more conditions are over. + * The actual value here is a bitfield of those conditions; see the + * BEV_SUSPEND_* flags above. */ + bufferevent_suspend_flags write_suspended; + + /** Set to the current socket errno if we have deferred callbacks and + * an events callback is pending. */ + int errno_pending; + + /** The DNS error code for bufferevent_socket_connect_hostname */ + int dns_error; + + /** Used to implement deferred callbacks */ + struct event_callback deferred; + + /** The options this bufferevent was constructed with */ + enum bufferevent_options options; + + /** Current reference count for this bufferevent. */ + int refcnt; + + /** Lock for this bufferevent. Shared by the inbuf and the outbuf. + * If NULL, locking is disabled. */ + void* lock; + + /** No matter how big our bucket gets, don't try to read more than this + * much in a single read operation. */ + ev_ssize_t max_single_read; + + /** No matter how big our bucket gets, don't try to write more than this + * much in a single write operation. */ + ev_ssize_t max_single_write; + + /** Rate-limiting information for this bufferevent */ + struct bufferevent_rate_limit* rate_limiting; + + /* Saved conn_addr, to extract IP address from it. + * + * Because some servers may reset/close connection without waiting clients, + * in that case we can't extract IP address even in close_cb. + * So we need to save it, just after we connected to remote server, or + * after resolving (to avoid extra dns requests during retrying, since UDP + * is slow) */ + union { + struct sockaddr_in6 in6; + struct sockaddr_in in; + } conn_address; + + struct evdns_getaddrinfo_request* dns_request; +}; + +/** Possible operations for a control callback. */ +enum bufferevent_ctrl_op { BEV_CTRL_SET_FD, BEV_CTRL_GET_FD, BEV_CTRL_GET_UNDERLYING, BEV_CTRL_CANCEL_ALL }; + +/** Possible data types for a control callback */ +union bufferevent_ctrl_data { + void* ptr; + evutil_socket_t fd; +}; + +/** + Implementation table for a bufferevent: holds function pointers and other + information to make the various bufferevent types work. +*/ +struct bufferevent_ops { + /** The name of the bufferevent's type. */ + const char* type; + /** At what offset into the implementation type will we find a + bufferevent structure? + + Example: if the type is implemented as + struct bufferevent_x { + int extra_data; + struct bufferevent bev; + } + then mem_offset should be offsetof(struct bufferevent_x, bev) + */ + off_t mem_offset; + + /** Enables one or more of EV_READ|EV_WRITE on a bufferevent. Does + not need to adjust the 'enabled' field. Returns 0 on success, -1 + on failure. + */ + int (*enable)(struct bufferevent*, short); + + /** Disables one or more of EV_READ|EV_WRITE on a bufferevent. Does + not need to adjust the 'enabled' field. Returns 0 on success, -1 + on failure. + */ + int (*disable)(struct bufferevent*, short); + + /** Detatches the bufferevent from related data structures. Called as + * soon as its reference count reaches 0. */ + void (*unlink)(struct bufferevent*); + + /** Free any storage and deallocate any extra data or structures used + in this implementation. Called when the bufferevent is + finalized. + */ + void (*destruct)(struct bufferevent*); + + /** Called when the timeouts on the bufferevent have changed.*/ + int (*adj_timeouts)(struct bufferevent*); + + /** Called to flush data. */ + int (*flush)(struct bufferevent*, short, enum bufferevent_flush_mode); + + /** Called to access miscellaneous fields. */ + int (*ctrl)(struct bufferevent*, enum bufferevent_ctrl_op, union bufferevent_ctrl_data*); +}; + +extern const struct bufferevent_ops bufferevent_ops_socket; +extern const struct bufferevent_ops bufferevent_ops_filter; +extern const struct bufferevent_ops bufferevent_ops_pair; + +#define BEV_IS_SOCKET(bevp) ((bevp)->be_ops == &bufferevent_ops_socket) +#define BEV_IS_FILTER(bevp) ((bevp)->be_ops == &bufferevent_ops_filter) +#define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair) + +#ifdef _WIN32 +extern const struct bufferevent_ops bufferevent_ops_async; +#define BEV_IS_ASYNC(bevp) ((bevp)->be_ops == &bufferevent_ops_async) +#else +#define BEV_IS_ASYNC(bevp) 0 +#endif + +/** Initialize the shared parts of a bufferevent. */ +int bufferevent_init_common_(struct bufferevent_private*, struct event_base*, const struct bufferevent_ops*, enum bufferevent_options options); + +/** For internal use: temporarily stop all reads on bufev, until the conditions + * in 'what' are over. */ +void bufferevent_suspend_read_(struct bufferevent* bufev, bufferevent_suspend_flags what); +/** For internal use: clear the conditions 'what' on bufev, and re-enable + * reading if there are no conditions left. */ +void bufferevent_unsuspend_read_(struct bufferevent* bufev, bufferevent_suspend_flags what); + +/** For internal use: temporarily stop all writes on bufev, until the conditions + * in 'what' are over. */ +void bufferevent_suspend_write_(struct bufferevent* bufev, bufferevent_suspend_flags what); +/** For internal use: clear the conditions 'what' on bufev, and re-enable + * writing if there are no conditions left. */ +void bufferevent_unsuspend_write_(struct bufferevent* bufev, bufferevent_suspend_flags what); + +#define bufferevent_wm_suspend_read(b) bufferevent_suspend_read_((b), BEV_SUSPEND_WM) +#define bufferevent_wm_unsuspend_read(b) bufferevent_unsuspend_read_((b), BEV_SUSPEND_WM) + +int bufferevent_disable_hard_(struct bufferevent* bufev, short event); + +int bufferevent_enable_locking_(struct bufferevent* bufev, void* lock); + +#define bufferevent_incref_(bufev) bufferevent_incref(bufev) + +void bufferevent_incref_and_lock_(struct bufferevent* bufev); + +#define bufferevent_decref_(bufev) bufferevent_decref(bufev) + +int bufferevent_decref_and_unlock_(struct bufferevent* bufev); + +void bufferevent_run_readcb_(struct bufferevent* bufev, int options); + +void bufferevent_run_writecb_(struct bufferevent* bufev, int options); + +void bufferevent_run_eventcb_(struct bufferevent* bufev, short what, int options); + +static inline void bufferevent_trigger_nolock_(struct bufferevent* bufev, short iotype, int options); + +static inline void bufferevent_trigger_nolock_(struct bufferevent* bufev, short iotype, int options) +{ + if ((iotype & EV_READ) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || evbuffer_get_length(bufev->input) >= bufev->wm_read.low)) + bufferevent_run_readcb_(bufev, options); + if ((iotype & EV_WRITE) && ((options & BEV_TRIG_IGNORE_WATERMARKS) || evbuffer_get_length(bufev->output) <= bufev->wm_write.low)) + bufferevent_run_writecb_(bufev, options); +} + +int bufferevent_add_event_(struct event* ev, const struct timeval* tv); + +void bufferevent_init_generic_timeout_cbs_(struct bufferevent* bev); + +int bufferevent_generic_adj_timeouts_(struct bufferevent* bev); +int bufferevent_generic_adj_existing_timeouts_(struct bufferevent* bev); + +enum bufferevent_options bufferevent_get_options_(struct bufferevent* bev); + +const struct sockaddr* bufferevent_socket_get_conn_address_(struct bufferevent* bev); + +#define BEV_RESET_GENERIC_READ_TIMEOUT(bev) \ + do { \ + if (evutil_timerisset(&(bev)->timeout_read)) \ + event_add(&(bev)->ev_read, &(bev)->timeout_read); \ + } while (0) +/** Internal use: We have just successfully written data from an inbuf, so + * reset the read timeout (if any). */ +#define BEV_RESET_GENERIC_WRITE_TIMEOUT(bev) \ + do { \ + if (evutil_timerisset(&(bev)->timeout_write)) \ + event_add(&(bev)->ev_write, &(bev)->timeout_write); \ + } while (0) +#define BEV_DEL_GENERIC_READ_TIMEOUT(bev) event_del(&(bev)->ev_read) +#define BEV_DEL_GENERIC_WRITE_TIMEOUT(bev) event_del(&(bev)->ev_write) + +/** Internal: Given a bufferevent, return its corresponding + * bufferevent_private. */ +#define BEV_UPCAST(b) EVUTIL_UPCAST((b), struct bufferevent_private, bev) + +#ifdef EVENT__DISABLE_THREAD_SUPPORT +#define BEV_LOCK(b) EVUTIL_NIL_STMT_ +#define BEV_UNLOCK(b) EVUTIL_NIL_STMT_ +#else +/** Internal: Grab the lock (if any) on a bufferevent */ +#define BEV_LOCK(b) \ + do { \ + struct bufferevent_private* locking = BEV_UPCAST(b); \ + EVLOCK_LOCK(locking->lock, 0); \ + } while (0) + +/** Internal: Release the lock (if any) on a bufferevent */ +#define BEV_UNLOCK(b) \ + do { \ + struct bufferevent_private* locking = BEV_UPCAST(b); \ + EVLOCK_UNLOCK(locking->lock, 0); \ + } while (0) +#endif + +/* ==== For rate-limiting. */ + +int bufferevent_decrement_write_buckets_(struct bufferevent_private* bev, ev_ssize_t bytes); +int bufferevent_decrement_read_buckets_(struct bufferevent_private* bev, ev_ssize_t bytes); +ev_ssize_t bufferevent_get_read_max_(struct bufferevent_private* bev); +ev_ssize_t bufferevent_get_write_max_(struct bufferevent_private* bev); + +int bufferevent_ratelim_init_(struct bufferevent_private* bev); + +#define BEV_IS_SSL(bevp) (!memcmp((bevp)->be_ops->type, "ssl", 3)) + +#ifdef __cplusplus +} +#endif + +#endif /* BUFFEREVENT_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/bufferevent.c b/asynio/event/bufferevent.c new file mode 100644 index 0000000000000000000000000000000000000000..cb86ae67b424edd62a1ecf3631d561ad0ac5edab --- /dev/null +++ b/asynio/event/bufferevent.c @@ -0,0 +1,896 @@ +/* + * Copyright (c) 2002-2007 Niels Provos + * Copyright (c) 2007-2012 Niels Provos, Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#include + +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +#include +#include +#include +#include +#ifdef EVENT__HAVE_STDARG_H +#include +#endif + +#ifdef _WIN32 +#include +#endif + +#include "util.h" +#include "buffer.h" +#include "buffer_compat.h" +#include "bufferevent.h" +#include "bufferevent_struct.h" +#include "bufferevent_compat.h" +#include "eventbase.h" + +#include "evconfig-internal.h" + +static void bufferevent_cancel_all_(struct bufferevent* bev); +static void bufferevent_finalize_cb_(struct event_callback* evcb, void* arg_); + +void bufferevent_suspend_read_(struct bufferevent* bufev, bufferevent_suspend_flags what) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + BEV_LOCK(bufev); + if (!bufev_private->read_suspended) + bufev->be_ops->disable(bufev, EV_READ); + bufev_private->read_suspended |= what; + BEV_UNLOCK(bufev); +} + +void bufferevent_unsuspend_read_(struct bufferevent* bufev, bufferevent_suspend_flags what) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + BEV_LOCK(bufev); + bufev_private->read_suspended &= ~what; + if (!bufev_private->read_suspended && (bufev->enabled & EV_READ)) + bufev->be_ops->enable(bufev, EV_READ); + BEV_UNLOCK(bufev); +} + +void bufferevent_suspend_write_(struct bufferevent* bufev, bufferevent_suspend_flags what) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + BEV_LOCK(bufev); + if (!bufev_private->write_suspended) + bufev->be_ops->disable(bufev, EV_WRITE); + bufev_private->write_suspended |= what; + BEV_UNLOCK(bufev); +} + +void bufferevent_unsuspend_write_(struct bufferevent* bufev, bufferevent_suspend_flags what) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + BEV_LOCK(bufev); + bufev_private->write_suspended &= ~what; + if (!bufev_private->write_suspended && (bufev->enabled & EV_WRITE)) + bufev->be_ops->enable(bufev, EV_WRITE); + BEV_UNLOCK(bufev); +} + +/* Callback to implement watermarks on the input buffer. Only enabled + * if the watermark is set. */ +static void bufferevent_inbuf_wm_cb(struct evbuffer* buf, const struct evbuffer_cb_info* cbinfo, void* arg) +{ + struct bufferevent* bufev = arg; + size_t size; + + size = evbuffer_get_length(buf); + + if (size >= bufev->wm_read.high) + bufferevent_wm_suspend_read(bufev); + else + bufferevent_wm_unsuspend_read(bufev); +} + +static void bufferevent_run_deferred_callbacks_locked(struct event_callback* cb, void* arg) +{ + struct bufferevent_private* bufev_private = arg; + struct bufferevent* bufev = &bufev_private->bev; + + BEV_LOCK(bufev); + if ((bufev_private->eventcb_pending & BEV_EVENT_CONNECTED) && bufev->errorcb) { + /* The "connected" happened before any reads or writes, so + send it first. */ + bufev_private->eventcb_pending &= ~BEV_EVENT_CONNECTED; + bufev->errorcb(bufev, BEV_EVENT_CONNECTED, bufev->cbarg); + } + if (bufev_private->readcb_pending && bufev->readcb) { + bufev_private->readcb_pending = 0; + bufev->readcb(bufev, bufev->cbarg); + } + if (bufev_private->writecb_pending && bufev->writecb) { + bufev_private->writecb_pending = 0; + bufev->writecb(bufev, bufev->cbarg); + } + if (bufev_private->eventcb_pending && bufev->errorcb) { + short what = bufev_private->eventcb_pending; + int err = bufev_private->errno_pending; + bufev_private->eventcb_pending = 0; + bufev_private->errno_pending = 0; + EVUTIL_SET_SOCKET_ERROR(err); + bufev->errorcb(bufev, what, bufev->cbarg); + } + bufferevent_decref_and_unlock_(bufev); +} + +static void bufferevent_run_deferred_callbacks_unlocked(struct event_callback* cb, void* arg) +{ + struct bufferevent_private* bufev_private = arg; + struct bufferevent* bufev = &bufev_private->bev; + + BEV_LOCK(bufev); +#define UNLOCKED(stmt) \ + do { \ + BEV_UNLOCK(bufev); \ + stmt; \ + BEV_LOCK(bufev); \ + } while (0) + + if ((bufev_private->eventcb_pending & BEV_EVENT_CONNECTED) && bufev->errorcb) { + /* The "connected" happened before any reads or writes, so + send it first. */ + bufferevent_event_cb errorcb = bufev->errorcb; + void* cbarg = bufev->cbarg; + bufev_private->eventcb_pending &= ~BEV_EVENT_CONNECTED; + UNLOCKED(errorcb(bufev, BEV_EVENT_CONNECTED, cbarg)); + } + if (bufev_private->readcb_pending && bufev->readcb) { + bufferevent_data_cb readcb = bufev->readcb; + void* cbarg = bufev->cbarg; + bufev_private->readcb_pending = 0; + UNLOCKED(readcb(bufev, cbarg)); + } + if (bufev_private->writecb_pending && bufev->writecb) { + bufferevent_data_cb writecb = bufev->writecb; + void* cbarg = bufev->cbarg; + bufev_private->writecb_pending = 0; + UNLOCKED(writecb(bufev, cbarg)); + } + if (bufev_private->eventcb_pending && bufev->errorcb) { + bufferevent_event_cb errorcb = bufev->errorcb; + void* cbarg = bufev->cbarg; + short what = bufev_private->eventcb_pending; + int err = bufev_private->errno_pending; + bufev_private->eventcb_pending = 0; + bufev_private->errno_pending = 0; + EVUTIL_SET_SOCKET_ERROR(err); + UNLOCKED(errorcb(bufev, what, cbarg)); + } + bufferevent_decref_and_unlock_(bufev); +#undef UNLOCKED +} + +#define SCHEDULE_DEFERRED(bevp) \ + do { \ + if (event_deferred_cb_schedule_((bevp)->bev.ev_base, &(bevp)->deferred)) \ + bufferevent_incref_(&(bevp)->bev); \ + } while (0) + +void bufferevent_run_readcb_(struct bufferevent* bufev, int options) +{ + /* Requires that we hold the lock and a reference */ + struct bufferevent_private* p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + if (bufev->readcb == NULL) + return; + if ((p->options | options) & BEV_OPT_DEFER_CALLBACKS) { + p->readcb_pending = 1; + SCHEDULE_DEFERRED(p); + } else { + bufev->readcb(bufev, bufev->cbarg); + } +} + +void bufferevent_run_writecb_(struct bufferevent* bufev, int options) +{ + /* Requires that we hold the lock and a reference */ + struct bufferevent_private* p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + if (bufev->writecb == NULL) + return; + if ((p->options | options) & BEV_OPT_DEFER_CALLBACKS) { + p->writecb_pending = 1; + SCHEDULE_DEFERRED(p); + } else { + bufev->writecb(bufev, bufev->cbarg); + } +} + +#define BEV_TRIG_ALL_OPTS (BEV_TRIG_IGNORE_WATERMARKS | BEV_TRIG_DEFER_CALLBACKS) + +void bufferevent_trigger(struct bufferevent* bufev, short iotype, int options) +{ + bufferevent_incref_and_lock_(bufev); + bufferevent_trigger_nolock_(bufev, iotype, options & BEV_TRIG_ALL_OPTS); + bufferevent_decref_and_unlock_(bufev); +} + +void bufferevent_run_eventcb_(struct bufferevent* bufev, short what, int options) +{ + /* Requires that we hold the lock and a reference */ + struct bufferevent_private* p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + if (bufev->errorcb == NULL) + return; + if ((p->options | options) & BEV_OPT_DEFER_CALLBACKS) { + p->eventcb_pending |= what; + p->errno_pending = EVUTIL_SOCKET_ERROR(); + SCHEDULE_DEFERRED(p); + } else { + bufev->errorcb(bufev, what, bufev->cbarg); + } +} + +void bufferevent_trigger_event(struct bufferevent* bufev, short what, int options) +{ + bufferevent_incref_and_lock_(bufev); + bufferevent_run_eventcb_(bufev, what, options & BEV_TRIG_ALL_OPTS); + bufferevent_decref_and_unlock_(bufev); +} + +int bufferevent_init_common_( + struct bufferevent_private* bufev_private, struct event_base* base, const struct bufferevent_ops* ops, enum bufferevent_options options) +{ + struct bufferevent* bufev = &bufev_private->bev; + + if (!bufev->input) { + if ((bufev->input = evbuffer_new()) == NULL) + return -1; + } + + if (!bufev->output) { + if ((bufev->output = evbuffer_new()) == NULL) { + evbuffer_free(bufev->input); + return -1; + } + } + + bufev_private->refcnt = 1; + bufev->ev_base = base; + + /* Disable timeouts. */ + evutil_timerclear(&bufev->timeout_read); + evutil_timerclear(&bufev->timeout_write); + + bufev->be_ops = ops; + + bufferevent_ratelim_init_(bufev_private); + + /* + * Set to EV_WRITE so that using bufferevent_write is going to + * trigger a callback. Reading needs to be explicitly enabled + * because otherwise no data will be available. + */ + bufev->enabled = EV_WRITE; + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (options & BEV_OPT_THREADSAFE) { + if (bufferevent_enable_locking_(bufev, NULL) < 0) { + /* cleanup */ + evbuffer_free(bufev->input); + evbuffer_free(bufev->output); + bufev->input = NULL; + bufev->output = NULL; + return -1; + } + } +#endif + if ((options & (BEV_OPT_DEFER_CALLBACKS | BEV_OPT_UNLOCK_CALLBACKS)) == BEV_OPT_UNLOCK_CALLBACKS) { + event_warnx("UNLOCK_CALLBACKS requires DEFER_CALLBACKS"); + return -1; + } + if (options & BEV_OPT_UNLOCK_CALLBACKS) + event_deferred_cb_init_( + &bufev_private->deferred, event_base_get_npriorities(base) / 2, bufferevent_run_deferred_callbacks_unlocked, bufev_private); + else + event_deferred_cb_init_( + &bufev_private->deferred, event_base_get_npriorities(base) / 2, bufferevent_run_deferred_callbacks_locked, bufev_private); + + bufev_private->options = options; + + evbuffer_set_parent_(bufev->input, bufev); + evbuffer_set_parent_(bufev->output, bufev); + + return 0; +} + +void bufferevent_setcb(struct bufferevent* bufev, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, void* cbarg) +{ + BEV_LOCK(bufev); + + bufev->readcb = readcb; + bufev->writecb = writecb; + bufev->errorcb = eventcb; + + bufev->cbarg = cbarg; + BEV_UNLOCK(bufev); +} + +void bufferevent_getcb( + struct bufferevent* bufev, bufferevent_data_cb* readcb_ptr, bufferevent_data_cb* writecb_ptr, bufferevent_event_cb* eventcb_ptr, void** cbarg_ptr) +{ + BEV_LOCK(bufev); + if (readcb_ptr) + *readcb_ptr = bufev->readcb; + if (writecb_ptr) + *writecb_ptr = bufev->writecb; + if (eventcb_ptr) + *eventcb_ptr = bufev->errorcb; + if (cbarg_ptr) + *cbarg_ptr = bufev->cbarg; + + BEV_UNLOCK(bufev); +} + +struct evbuffer* bufferevent_get_input(struct bufferevent* bufev) +{ + return bufev->input; +} + +struct evbuffer* bufferevent_get_output(struct bufferevent* bufev) +{ + return bufev->output; +} + +struct event_base* bufferevent_get_base(struct bufferevent* bufev) +{ + return bufev->ev_base; +} + +int bufferevent_get_priority(const struct bufferevent* bufev) +{ + if (event_initialized(&bufev->ev_read)) { + return event_get_priority(&bufev->ev_read); + } else { + return event_base_get_npriorities(bufev->ev_base) / 2; + } +} + +int bufferevent_write(struct bufferevent* bufev, const void* data, size_t size) +{ + if (evbuffer_add(bufev->output, data, size) == -1) + return (-1); + + return 0; +} + +int bufferevent_write_buffer(struct bufferevent* bufev, struct evbuffer* buf) +{ + if (evbuffer_add_buffer(bufev->output, buf) == -1) + return (-1); + + return 0; +} + +size_t bufferevent_read(struct bufferevent* bufev, void* data, size_t size) +{ + return (evbuffer_remove(bufev->input, data, size)); +} + +int bufferevent_read_buffer(struct bufferevent* bufev, struct evbuffer* buf) +{ + return (evbuffer_add_buffer(buf, bufev->input)); +} + +int bufferevent_enable(struct bufferevent* bufev, short event) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + short impl_events = event; + int r = 0; + + bufferevent_incref_and_lock_(bufev); + if (bufev_private->read_suspended) + impl_events &= ~EV_READ; + if (bufev_private->write_suspended) + impl_events &= ~EV_WRITE; + + bufev->enabled |= event; + + if (impl_events && bufev->be_ops->enable(bufev, impl_events) < 0) + r = -1; + + bufferevent_decref_and_unlock_(bufev); + return r; +} + +int bufferevent_set_timeouts(struct bufferevent* bufev, const struct timeval* tv_read, const struct timeval* tv_write) +{ + int r = 0; + BEV_LOCK(bufev); + if (tv_read) { + bufev->timeout_read = *tv_read; + } else { + evutil_timerclear(&bufev->timeout_read); + } + if (tv_write) { + bufev->timeout_write = *tv_write; + } else { + evutil_timerclear(&bufev->timeout_write); + } + + if (bufev->be_ops->adj_timeouts) + r = bufev->be_ops->adj_timeouts(bufev); + BEV_UNLOCK(bufev); + + return r; +} + +/* Obsolete; use bufferevent_set_timeouts */ +void bufferevent_settimeout(struct bufferevent* bufev, int timeout_read, int timeout_write) +{ + struct timeval tv_read, tv_write; + struct timeval *ptv_read = NULL, *ptv_write = NULL; + + memset(&tv_read, 0, sizeof(tv_read)); + memset(&tv_write, 0, sizeof(tv_write)); + + if (timeout_read) { + tv_read.tv_sec = timeout_read; + ptv_read = &tv_read; + } + if (timeout_write) { + tv_write.tv_sec = timeout_write; + ptv_write = &tv_write; + } + + bufferevent_set_timeouts(bufev, ptv_read, ptv_write); +} + +int bufferevent_disable_hard_(struct bufferevent* bufev, short event) +{ + int r = 0; + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + + BEV_LOCK(bufev); + bufev->enabled &= ~event; + + bufev_private->connecting = 0; + if (bufev->be_ops->disable(bufev, event) < 0) + r = -1; + + BEV_UNLOCK(bufev); + return r; +} + +int bufferevent_disable(struct bufferevent* bufev, short event) +{ + int r = 0; + + BEV_LOCK(bufev); + bufev->enabled &= ~event; + + if (bufev->be_ops->disable(bufev, event) < 0) + r = -1; + + BEV_UNLOCK(bufev); + return r; +} + +/* + * Sets the water marks + */ + +void bufferevent_setwatermark(struct bufferevent* bufev, short events, size_t lowmark, size_t highmark) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + + BEV_LOCK(bufev); + if (events & EV_WRITE) { + bufev->wm_write.low = lowmark; + bufev->wm_write.high = highmark; + } + + if (events & EV_READ) { + bufev->wm_read.low = lowmark; + bufev->wm_read.high = highmark; + + if (highmark) { + /* There is now a new high-water mark for read. + enable the callback if needed, and see if we should + suspend/bufferevent_wm_unsuspend. */ + + if (bufev_private->read_watermarks_cb == NULL) { + bufev_private->read_watermarks_cb = evbuffer_add_cb(bufev->input, bufferevent_inbuf_wm_cb, bufev); + } + evbuffer_cb_set_flags(bufev->input, bufev_private->read_watermarks_cb, EVBUFFER_CB_ENABLED | EVBUFFER_CB_NODEFER); + + if (evbuffer_get_length(bufev->input) >= highmark) + bufferevent_wm_suspend_read(bufev); + else if (evbuffer_get_length(bufev->input) < highmark) + bufferevent_wm_unsuspend_read(bufev); + } else { + /* There is now no high-water mark for read. */ + if (bufev_private->read_watermarks_cb) + evbuffer_cb_clear_flags(bufev->input, bufev_private->read_watermarks_cb, EVBUFFER_CB_ENABLED); + bufferevent_wm_unsuspend_read(bufev); + } + } + BEV_UNLOCK(bufev); +} + +int bufferevent_getwatermark(struct bufferevent* bufev, short events, size_t* lowmark, size_t* highmark) +{ + if (events == EV_WRITE) { + BEV_LOCK(bufev); + if (lowmark) + *lowmark = bufev->wm_write.low; + if (highmark) + *highmark = bufev->wm_write.high; + BEV_UNLOCK(bufev); + return 0; + } + + if (events == EV_READ) { + BEV_LOCK(bufev); + if (lowmark) + *lowmark = bufev->wm_read.low; + if (highmark) + *highmark = bufev->wm_read.high; + BEV_UNLOCK(bufev); + return 0; + } + return -1; +} + +int bufferevent_flush(struct bufferevent* bufev, short iotype, enum bufferevent_flush_mode mode) +{ + int r = -1; + BEV_LOCK(bufev); + if (bufev->be_ops->flush) + r = bufev->be_ops->flush(bufev, iotype, mode); + BEV_UNLOCK(bufev); + return r; +} + +void bufferevent_incref_and_lock_(struct bufferevent* bufev) +{ + struct bufferevent_private* bufev_private = BEV_UPCAST(bufev); + BEV_LOCK(bufev); + ++bufev_private->refcnt; +} + +#if 0 +static void +bufferevent_transfer_lock_ownership_(struct bufferevent *donor, + struct bufferevent *recipient) +{ + struct bufferevent_private *d = BEV_UPCAST(donor); + struct bufferevent_private *r = BEV_UPCAST(recipient); + if (d->lock != r->lock) + return; + if (r->own_lock) + return; + if (d->own_lock) { + d->own_lock = 0; + r->own_lock = 1; + } +} +#endif + +int bufferevent_decref_and_unlock_(struct bufferevent* bufev) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + int n_cbs = 0; +#define MAX_CBS 16 + struct event_callback* cbs[MAX_CBS]; + + EVUTIL_ASSERT(bufev_private->refcnt > 0); + + if (--bufev_private->refcnt) { + BEV_UNLOCK(bufev); + return 0; + } + + if (bufev->be_ops->unlink) + bufev->be_ops->unlink(bufev); + + /* Okay, we're out of references. Let's finalize this once all the + * callbacks are done running. */ + cbs[0] = &bufev->ev_read.ev_evcallback; + cbs[1] = &bufev->ev_write.ev_evcallback; + cbs[2] = &bufev_private->deferred; + n_cbs = 3; + if (bufev_private->rate_limiting) { + struct event* e = &bufev_private->rate_limiting->refill_bucket_event; + if (event_initialized(e)) + cbs[n_cbs++] = &e->ev_evcallback; + } + n_cbs += evbuffer_get_callbacks_(bufev->input, cbs + n_cbs, MAX_CBS - n_cbs); + n_cbs += evbuffer_get_callbacks_(bufev->output, cbs + n_cbs, MAX_CBS - n_cbs); + + event_callback_finalize_many_(bufev->ev_base, n_cbs, cbs, bufferevent_finalize_cb_); + +#undef MAX_CBS + BEV_UNLOCK(bufev); + + return 1; +} + +static void bufferevent_finalize_cb_(struct event_callback* evcb, void* arg_) +{ + struct bufferevent* bufev = arg_; + struct bufferevent* underlying; + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + + BEV_LOCK(bufev); + underlying = bufferevent_get_underlying(bufev); + + /* Clean up the shared info */ + if (bufev->be_ops->destruct) + bufev->be_ops->destruct(bufev); + + /* XXX what happens if refcnt for these buffers is > 1? + * The buffers can share a lock with this bufferevent object, + * but the lock might be destroyed below. */ + /* evbuffer will free the callbacks */ + evbuffer_free(bufev->input); + evbuffer_free(bufev->output); + + if (bufev_private->rate_limiting) { + if (bufev_private->rate_limiting->group) + bufferevent_remove_from_rate_limit_group_internal_(bufev, 0); + mm_free(bufev_private->rate_limiting); + bufev_private->rate_limiting = NULL; + } + + BEV_UNLOCK(bufev); + + if (bufev_private->own_lock) + EVTHREAD_FREE_LOCK(bufev_private->lock, EVTHREAD_LOCKTYPE_RECURSIVE); + + /* Free the actual allocated memory. */ + mm_free(((char*)bufev) - bufev->be_ops->mem_offset); + + /* Release the reference to underlying now that we no longer need the + * reference to it. We wait this long mainly in case our lock is + * shared with underlying. + * + * The 'destruct' function will also drop a reference to underlying + * if BEV_OPT_CLOSE_ON_FREE is set. + * + * XXX Should we/can we just refcount evbuffer/bufferevent locks? + * It would probably save us some headaches. + */ + if (underlying) + bufferevent_decref_(underlying); +} + +int bufferevent_decref(struct bufferevent* bufev) +{ + BEV_LOCK(bufev); + return bufferevent_decref_and_unlock_(bufev); +} + +void bufferevent_free(struct bufferevent* bufev) +{ + BEV_LOCK(bufev); + bufferevent_setcb(bufev, NULL, NULL, NULL, NULL); + bufferevent_cancel_all_(bufev); + bufferevent_decref_and_unlock_(bufev); +} + +void bufferevent_incref(struct bufferevent* bufev) +{ + struct bufferevent_private* bufev_private = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + + /* XXX: now that this function is public, we might want to + * - return the count from this function + * - create a new function to atomically grab the current refcount + */ + BEV_LOCK(bufev); + ++bufev_private->refcnt; + BEV_UNLOCK(bufev); +} + +int bufferevent_enable_locking_(struct bufferevent* bufev, void* lock) +{ +#ifdef EVENT__DISABLE_THREAD_SUPPORT + return -1; +#else + struct bufferevent* underlying; + + if (BEV_UPCAST(bufev)->lock) + return -1; + underlying = bufferevent_get_underlying(bufev); + + if (!lock && underlying && BEV_UPCAST(underlying)->lock) { + lock = BEV_UPCAST(underlying)->lock; + BEV_UPCAST(bufev)->lock = lock; + BEV_UPCAST(bufev)->own_lock = 0; + } else if (!lock) { + EVTHREAD_ALLOC_LOCK(lock, EVTHREAD_LOCKTYPE_RECURSIVE); + if (!lock) + return -1; + BEV_UPCAST(bufev)->lock = lock; + BEV_UPCAST(bufev)->own_lock = 1; + } else { + BEV_UPCAST(bufev)->lock = lock; + BEV_UPCAST(bufev)->own_lock = 0; + } + evbuffer_enable_locking(bufev->input, lock); + evbuffer_enable_locking(bufev->output, lock); + + if (underlying && !BEV_UPCAST(underlying)->lock) + bufferevent_enable_locking_(underlying, lock); + + return 0; +#endif +} + +int bufferevent_setfd(struct bufferevent* bev, evutil_socket_t fd) +{ + union bufferevent_ctrl_data d; + int res = -1; + d.fd = fd; + BEV_LOCK(bev); + if (bev->be_ops->ctrl) + res = bev->be_ops->ctrl(bev, BEV_CTRL_SET_FD, &d); + BEV_UNLOCK(bev); + return res; +} + +evutil_socket_t bufferevent_getfd(struct bufferevent* bev) +{ + union bufferevent_ctrl_data d; + int res = -1; + d.fd = -1; + BEV_LOCK(bev); + if (bev->be_ops->ctrl) + res = bev->be_ops->ctrl(bev, BEV_CTRL_GET_FD, &d); + BEV_UNLOCK(bev); + return (res < 0) ? -1 : d.fd; +} + +enum bufferevent_options bufferevent_get_options_(struct bufferevent* bev) +{ + struct bufferevent_private* bev_p = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + enum bufferevent_options options; + + BEV_LOCK(bev); + options = bev_p->options; + BEV_UNLOCK(bev); + return options; +} + +static void bufferevent_cancel_all_(struct bufferevent* bev) +{ + union bufferevent_ctrl_data d; + memset(&d, 0, sizeof(d)); + BEV_LOCK(bev); + if (bev->be_ops->ctrl) + bev->be_ops->ctrl(bev, BEV_CTRL_CANCEL_ALL, &d); + BEV_UNLOCK(bev); +} + +short bufferevent_get_enabled(struct bufferevent* bufev) +{ + short r; + BEV_LOCK(bufev); + r = bufev->enabled; + BEV_UNLOCK(bufev); + return r; +} + +struct bufferevent* bufferevent_get_underlying(struct bufferevent* bev) +{ + union bufferevent_ctrl_data d; + int res = -1; + d.ptr = NULL; + BEV_LOCK(bev); + if (bev->be_ops->ctrl) + res = bev->be_ops->ctrl(bev, BEV_CTRL_GET_UNDERLYING, &d); + BEV_UNLOCK(bev); + return (res < 0) ? NULL : d.ptr; +} + +static void bufferevent_generic_read_timeout_cb(evutil_socket_t fd, short event, void* ctx) +{ + struct bufferevent* bev = ctx; + bufferevent_incref_and_lock_(bev); + bufferevent_disable(bev, EV_READ); + bufferevent_run_eventcb_(bev, BEV_EVENT_TIMEOUT | BEV_EVENT_READING, 0); + bufferevent_decref_and_unlock_(bev); +} +static void bufferevent_generic_write_timeout_cb(evutil_socket_t fd, short event, void* ctx) +{ + struct bufferevent* bev = ctx; + bufferevent_incref_and_lock_(bev); + bufferevent_disable(bev, EV_WRITE); + bufferevent_run_eventcb_(bev, BEV_EVENT_TIMEOUT | BEV_EVENT_WRITING, 0); + bufferevent_decref_and_unlock_(bev); +} + +void bufferevent_init_generic_timeout_cbs_(struct bufferevent* bev) +{ + event_assign(&bev->ev_read, bev->ev_base, -1, EV_FINALIZE, bufferevent_generic_read_timeout_cb, bev); + event_assign(&bev->ev_write, bev->ev_base, -1, EV_FINALIZE, bufferevent_generic_write_timeout_cb, bev); +} + +int bufferevent_generic_adj_timeouts_(struct bufferevent* bev) +{ + const short enabled = bev->enabled; + struct bufferevent_private* bev_p = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + int r1 = 0, r2 = 0; + if ((enabled & EV_READ) && !bev_p->read_suspended && evutil_timerisset(&bev->timeout_read)) + r1 = event_add(&bev->ev_read, &bev->timeout_read); + else + r1 = event_del(&bev->ev_read); + + if ((enabled & EV_WRITE) && !bev_p->write_suspended && evutil_timerisset(&bev->timeout_write) && evbuffer_get_length(bev->output)) + r2 = event_add(&bev->ev_write, &bev->timeout_write); + else + r2 = event_del(&bev->ev_write); + if (r1 < 0 || r2 < 0) + return -1; + return 0; +} + +int bufferevent_generic_adj_existing_timeouts_(struct bufferevent* bev) +{ + int r = 0; + if (event_pending(&bev->ev_read, EV_READ, NULL)) { + if (evutil_timerisset(&bev->timeout_read)) { + if (bufferevent_add_event_(&bev->ev_read, &bev->timeout_read) < 0) + r = -1; + } else { + event_remove_timer(&bev->ev_read); + } + } + if (event_pending(&bev->ev_write, EV_WRITE, NULL)) { + if (evutil_timerisset(&bev->timeout_write)) { + if (bufferevent_add_event_(&bev->ev_write, &bev->timeout_write) < 0) + r = -1; + } else { + event_remove_timer(&bev->ev_write); + } + } + return r; +} + +int bufferevent_add_event_(struct event* ev, const struct timeval* tv) +{ + if (!evutil_timerisset(tv)) + return event_add(ev, NULL); + else + return event_add(ev, tv); +} + +/* For use by user programs only; internally, we should be calling + either bufferevent_incref_and_lock_(), or BEV_LOCK. */ +void bufferevent_lock(struct bufferevent* bev) +{ + bufferevent_incref_and_lock_(bev); +} + +void bufferevent_unlock(struct bufferevent* bev) +{ + bufferevent_decref_and_unlock_(bev); +} diff --git a/asynio/event/bufferevent.h b/asynio/event/bufferevent.h new file mode 100644 index 0000000000000000000000000000000000000000..5c6846dcf27961b6b4c231215a3a8bb8f51e4001 --- /dev/null +++ b/asynio/event/bufferevent.h @@ -0,0 +1,246 @@ +#ifndef EVENT2_BUFFEREVENT_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +/* For int types. */ +#include "util.h" + +#define BEV_EVENT_READING 0x01 /**< error encountered while reading */ +#define BEV_EVENT_WRITING 0x02 /**< error encountered while writing */ +#define BEV_EVENT_EOF 0x10 /**< eof file reached */ +#define BEV_EVENT_ERROR 0x20 /**< unrecoverable error encountered */ +#define BEV_EVENT_TIMEOUT 0x40 /**< user-specified timeout reached */ +#define BEV_EVENT_CONNECTED 0x80 /**< connect operation finished. */ + +struct bufferevent +#ifdef EVENT_IN_DOXYGEN_ +{ +} +#endif +; +struct event_base; +struct evbuffer; +struct sockaddr; + +typedef void (*bufferevent_data_cb)(struct bufferevent* bev, void* ctx); + +typedef void (*bufferevent_event_cb)(struct bufferevent* bev, short what, void* ctx); + +/** Options that can be specified when creating a bufferevent */ +enum bufferevent_options { + /** If set, we close the underlying file + * descriptor/bufferevent/whatever when this bufferevent is freed. */ + BEV_OPT_CLOSE_ON_FREE = (1 << 0), + + /** If set, and threading is enabled, operations on this bufferevent + * are protected by a lock */ + BEV_OPT_THREADSAFE = (1 << 1), + + /** If set, callbacks are run deferred in the event loop. */ + BEV_OPT_DEFER_CALLBACKS = (1 << 2), + + /** If set, callbacks are executed without locks being held on the + * bufferevent. This option currently requires that + * BEV_OPT_DEFER_CALLBACKS also be set; a future version of Libevent + * might remove the requirement.*/ + BEV_OPT_UNLOCK_CALLBACKS = (1 << 3) +}; + +struct bufferevent* bufferevent_socket_new(struct event_base* base, evutil_socket_t fd, int options); + +int bufferevent_socket_connect(struct bufferevent*, const struct sockaddr*, int); + +struct evdns_base; + +int bufferevent_socket_connect_hostname(struct bufferevent*, struct evdns_base*, int, const char*, int); + +int bufferevent_socket_get_dns_error(struct bufferevent* bev); + +int bufferevent_base_set(struct event_base* base, struct bufferevent* bufev); + +struct event_base* bufferevent_get_base(struct bufferevent* bev); + +int bufferevent_priority_set(struct bufferevent* bufev, int pri); + +int bufferevent_get_priority(const struct bufferevent* bufev); + +void bufferevent_free(struct bufferevent* bufev); + +void bufferevent_setcb(struct bufferevent* bufev, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, void* cbarg); + +void bufferevent_getcb( + struct bufferevent* bufev, + bufferevent_data_cb* readcb_ptr, + bufferevent_data_cb* writecb_ptr, + bufferevent_event_cb* eventcb_ptr, + void** cbarg_ptr); + +int bufferevent_setfd(struct bufferevent* bufev, evutil_socket_t fd); + +evutil_socket_t bufferevent_getfd(struct bufferevent* bufev); + +struct bufferevent* bufferevent_get_underlying(struct bufferevent* bufev); + +int bufferevent_write(struct bufferevent* bufev, const void* data, size_t size); + +int bufferevent_write_buffer(struct bufferevent* bufev, struct evbuffer* buf); + +size_t bufferevent_read(struct bufferevent* bufev, void* data, size_t size); + +int bufferevent_read_buffer(struct bufferevent* bufev, struct evbuffer* buf); + +struct evbuffer* bufferevent_get_input(struct bufferevent* bufev); + +struct evbuffer* bufferevent_get_output(struct bufferevent* bufev); + +int bufferevent_enable(struct bufferevent* bufev, short event); + +int bufferevent_disable(struct bufferevent* bufev, short event); + +short bufferevent_get_enabled(struct bufferevent* bufev); + +int bufferevent_set_timeouts(struct bufferevent* bufev, const struct timeval* timeout_read, const struct timeval* timeout_write); + +void bufferevent_setwatermark(struct bufferevent* bufev, short events, size_t lowmark, size_t highmark); + +int bufferevent_getwatermark(struct bufferevent* bufev, short events, size_t* lowmark, size_t* highmark); + +void bufferevent_lock(struct bufferevent* bufev); + +void bufferevent_unlock(struct bufferevent* bufev); + +void bufferevent_incref(struct bufferevent* bufev); + +int bufferevent_decref(struct bufferevent* bufev); + +enum bufferevent_flush_mode { + /** usually set when processing data */ + BEV_NORMAL = 0, + + /** want to checkpoint all data sent. */ + BEV_FLUSH = 1, + + /** encountered EOF on read or done sending data */ + BEV_FINISHED = 2 +}; + +int bufferevent_flush(struct bufferevent* bufev, short iotype, enum bufferevent_flush_mode mode); + +enum bufferevent_trigger_options { + /** trigger the callback regardless of the watermarks */ + BEV_TRIG_IGNORE_WATERMARKS = (1 << 16), + + /** defer even if the callbacks are not */ + BEV_TRIG_DEFER_CALLBACKS = BEV_OPT_DEFER_CALLBACKS + + /* (Note: for internal reasons, these need to be disjoint from + * bufferevent_options, except when they mean the same thing. */ +}; + +void bufferevent_trigger(struct bufferevent* bufev, short iotype, int options); + +void bufferevent_trigger_event(struct bufferevent* bufev, short what, int options); + +enum bufferevent_filter_result { + /** everything is okay */ + BEV_OK = 0, + + /** the filter needs to read more data before output */ + BEV_NEED_MORE = 1, + + /** the filter encountered a critical error, no further data + can be processed. */ + BEV_ERROR = 2 +}; + +typedef enum bufferevent_filter_result (*bufferevent_filter_cb)( + struct evbuffer* src, struct evbuffer* dst, ev_ssize_t dst_limit, enum bufferevent_flush_mode mode, void* ctx); + +struct bufferevent* bufferevent_filter_new( + struct bufferevent* underlying, + bufferevent_filter_cb input_filter, + bufferevent_filter_cb output_filter, + int options, + void (*free_context)(void*), + void* ctx); + +int bufferevent_pair_new(struct event_base* base, int options, struct bufferevent* pair[2]); + +struct bufferevent* bufferevent_pair_get_partner(struct bufferevent* bev); + +struct ev_token_bucket_cfg; + +struct bufferevent_rate_limit_group; + +#define EV_RATE_LIMIT_MAX EV_SSIZE_MAX + +struct ev_token_bucket_cfg* + ev_token_bucket_cfg_new(size_t read_rate, size_t read_burst, size_t write_rate, size_t write_burst, const struct timeval* tick_len); + +void ev_token_bucket_cfg_free(struct ev_token_bucket_cfg* cfg); + +int bufferevent_set_rate_limit(struct bufferevent* bev, struct ev_token_bucket_cfg* cfg); + +struct bufferevent_rate_limit_group* bufferevent_rate_limit_group_new(struct event_base* base, const struct ev_token_bucket_cfg* cfg); + +int bufferevent_rate_limit_group_set_cfg(struct bufferevent_rate_limit_group*, const struct ev_token_bucket_cfg*); + +int bufferevent_rate_limit_group_set_min_share(struct bufferevent_rate_limit_group*, size_t); + +void bufferevent_rate_limit_group_free(struct bufferevent_rate_limit_group*); + +int bufferevent_add_to_rate_limit_group(struct bufferevent* bev, struct bufferevent_rate_limit_group* g); + +int bufferevent_remove_from_rate_limit_group(struct bufferevent* bev); + +int bufferevent_set_max_single_read(struct bufferevent* bev, size_t size); + +int bufferevent_set_max_single_write(struct bufferevent* bev, size_t size); + +ev_ssize_t bufferevent_get_max_single_read(struct bufferevent* bev); + +ev_ssize_t bufferevent_get_max_single_write(struct bufferevent* bev); + +ev_ssize_t bufferevent_get_read_limit(struct bufferevent* bev); + +ev_ssize_t bufferevent_get_write_limit(struct bufferevent* bev); + +ev_ssize_t bufferevent_get_max_to_read(struct bufferevent* bev); + +ev_ssize_t bufferevent_get_max_to_write(struct bufferevent* bev); + +const struct ev_token_bucket_cfg* bufferevent_get_token_bucket_cfg(const struct bufferevent* bev); + +ev_ssize_t bufferevent_rate_limit_group_get_read_limit(struct bufferevent_rate_limit_group*); + +ev_ssize_t bufferevent_rate_limit_group_get_write_limit(struct bufferevent_rate_limit_group*); + +int bufferevent_decrement_read_limit(struct bufferevent* bev, ev_ssize_t decr); + +int bufferevent_decrement_write_limit(struct bufferevent* bev, ev_ssize_t decr); + +int bufferevent_rate_limit_group_decrement_read(struct bufferevent_rate_limit_group*, ev_ssize_t); + +int bufferevent_rate_limit_group_decrement_write(struct bufferevent_rate_limit_group*, ev_ssize_t); + +void bufferevent_rate_limit_group_get_totals(struct bufferevent_rate_limit_group* grp, ev_uint64_t* total_read_out, ev_uint64_t* total_written_out); + +void bufferevent_rate_limit_group_reset_totals(struct bufferevent_rate_limit_group* grp); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT2_BUFFEREVENT_H_INCLUDED_ */ diff --git a/asynio/event/bufferevent_async.c b/asynio/event/bufferevent_async.c new file mode 100644 index 0000000000000000000000000000000000000000..baae046dff8a7de579f01129d0d0bda1f65d65ee --- /dev/null +++ b/asynio/event/bufferevent_async.c @@ -0,0 +1,633 @@ +/* + * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "event-config.h" +#include "evconfig-private.h" + +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +#include +#include +#include +#include +#ifdef EVENT__HAVE_STDARG_H +#include +#endif +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif + +#ifdef _WIN32 +#include +#include +#endif + +#include + +#include "util.h" +#include "bufferevent.h" +#include "buffer.h" +#include "bufferevent_struct.h" +#include "eventbase.h" + +#include "event-internal.h" +#include "log-internal.h" +#include "mm-internal.h" +#include "bufferevent-internal.h" +#include "util-internal.h" +#include "iocp-internal.h" + +#ifndef SO_UPDATE_CONNECT_CONTEXT +/* Mingw is sometimes missing this */ +#define SO_UPDATE_CONNECT_CONTEXT 0x7010 +#endif + +/* prototypes */ +static int be_async_enable(struct bufferevent*, short); +static int be_async_disable(struct bufferevent*, short); +static void be_async_destruct(struct bufferevent*); +static int be_async_flush(struct bufferevent*, short, enum bufferevent_flush_mode); +static int be_async_ctrl(struct bufferevent*, enum bufferevent_ctrl_op, union bufferevent_ctrl_data*); + +struct bufferevent_async { + struct bufferevent_private bev; + struct event_overlapped connect_overlapped; + struct event_overlapped read_overlapped; + struct event_overlapped write_overlapped; + size_t read_in_progress; + size_t write_in_progress; + unsigned ok : 1; + unsigned read_added : 1; + unsigned write_added : 1; +}; + +const struct bufferevent_ops bufferevent_ops_async = { + "socket_async", + evutil_offsetof(struct bufferevent_async, bev.bev), + be_async_enable, + be_async_disable, + NULL, /* Unlink */ + be_async_destruct, + bufferevent_generic_adj_timeouts_, + be_async_flush, + be_async_ctrl, +}; + +static inline struct bufferevent_async* upcast(struct bufferevent* bev) +{ + struct bufferevent_async* bev_a; + if (bev->be_ops != &bufferevent_ops_async) + return NULL; + bev_a = EVUTIL_UPCAST(bev, struct bufferevent_async, bev.bev); + return bev_a; +} + +static inline struct bufferevent_async* upcast_connect(struct event_overlapped* eo) +{ + struct bufferevent_async* bev_a; + bev_a = EVUTIL_UPCAST(eo, struct bufferevent_async, connect_overlapped); + EVUTIL_ASSERT(BEV_IS_ASYNC(&bev_a->bev.bev)); + return bev_a; +} + +static inline struct bufferevent_async* upcast_read(struct event_overlapped* eo) +{ + struct bufferevent_async* bev_a; + bev_a = EVUTIL_UPCAST(eo, struct bufferevent_async, read_overlapped); + EVUTIL_ASSERT(BEV_IS_ASYNC(&bev_a->bev.bev)); + return bev_a; +} + +static inline struct bufferevent_async* upcast_write(struct event_overlapped* eo) +{ + struct bufferevent_async* bev_a; + bev_a = EVUTIL_UPCAST(eo, struct bufferevent_async, write_overlapped); + EVUTIL_ASSERT(BEV_IS_ASYNC(&bev_a->bev.bev)); + return bev_a; +} + +static void bev_async_del_write(struct bufferevent_async* beva) +{ + struct bufferevent* bev = &beva->bev.bev; + + if (beva->write_added) { + beva->write_added = 0; + event_base_del_virtual_(bev->ev_base); + } +} + +static void bev_async_del_read(struct bufferevent_async* beva) +{ + struct bufferevent* bev = &beva->bev.bev; + + if (beva->read_added) { + beva->read_added = 0; + event_base_del_virtual_(bev->ev_base); + } +} + +static void bev_async_add_write(struct bufferevent_async* beva) +{ + struct bufferevent* bev = &beva->bev.bev; + + if (!beva->write_added) { + beva->write_added = 1; + event_base_add_virtual_(bev->ev_base); + } +} + +static void bev_async_add_read(struct bufferevent_async* beva) +{ + struct bufferevent* bev = &beva->bev.bev; + + if (!beva->read_added) { + beva->read_added = 1; + event_base_add_virtual_(bev->ev_base); + } +} + +static void bev_async_consider_writing(struct bufferevent_async* beva) +{ + size_t at_most; + int limit; + struct bufferevent* bev = &beva->bev.bev; + + /* Don't write if there's a write in progress, or we do not + * want to write, or when there's nothing left to write. */ + if (beva->write_in_progress || beva->bev.connecting) + return; + if (!beva->ok || !(bev->enabled & EV_WRITE) || !evbuffer_get_length(bev->output)) { + bev_async_del_write(beva); + return; + } + + at_most = evbuffer_get_length(bev->output); + + /* This is safe so long as bufferevent_get_write_max never returns + * more than INT_MAX. That's true for now. XXXX */ + limit = (int)bufferevent_get_write_max_(&beva->bev); + if (at_most >= (size_t)limit && limit >= 0) + at_most = limit; + + if (beva->bev.write_suspended) { + bev_async_del_write(beva); + return; + } + + /* XXXX doesn't respect low-water mark very well. */ + bufferevent_incref_(bev); + if (evbuffer_launch_write_(bev->output, at_most, &beva->write_overlapped)) { + bufferevent_decref_(bev); + beva->ok = 0; + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); + } else { + beva->write_in_progress = at_most; + bufferevent_decrement_write_buckets_(&beva->bev, at_most); + bev_async_add_write(beva); + } +} + +static void bev_async_consider_reading(struct bufferevent_async* beva) +{ + size_t cur_size; + size_t read_high; + size_t at_most; + int limit; + struct bufferevent* bev = &beva->bev.bev; + + /* Don't read if there is a read in progress, or we do not + * want to read. */ + if (beva->read_in_progress || beva->bev.connecting) + return; + if (!beva->ok || !(bev->enabled & EV_READ)) { + bev_async_del_read(beva); + return; + } + + /* Don't read if we're full */ + cur_size = evbuffer_get_length(bev->input); + read_high = bev->wm_read.high; + if (read_high) { + if (cur_size >= read_high) { + bev_async_del_read(beva); + return; + } + at_most = read_high - cur_size; + } else { + at_most = 16384; /* FIXME totally magic. */ + } + + /* XXXX This over-commits. */ + /* XXXX see also not above on cast on bufferevent_get_write_max_() */ + limit = (int)bufferevent_get_read_max_(&beva->bev); + if (at_most >= (size_t)limit && limit >= 0) + at_most = limit; + + if (beva->bev.read_suspended) { + bev_async_del_read(beva); + return; + } + + bufferevent_incref_(bev); + if (evbuffer_launch_read_(bev->input, at_most, &beva->read_overlapped)) { + beva->ok = 0; + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); + bufferevent_decref_(bev); + } else { + beva->read_in_progress = at_most; + bufferevent_decrement_read_buckets_(&beva->bev, at_most); + bev_async_add_read(beva); + } + + return; +} + +static void be_async_outbuf_callback(struct evbuffer* buf, const struct evbuffer_cb_info* cbinfo, void* arg) +{ + struct bufferevent* bev = arg; + struct bufferevent_async* bev_async = upcast(bev); + + /* If we added data to the outbuf and were not writing before, + * we may want to write now. */ + + bufferevent_incref_and_lock_(bev); + + if (cbinfo->n_added) + bev_async_consider_writing(bev_async); + + bufferevent_decref_and_unlock_(bev); +} + +static void be_async_inbuf_callback(struct evbuffer* buf, const struct evbuffer_cb_info* cbinfo, void* arg) +{ + struct bufferevent* bev = arg; + struct bufferevent_async* bev_async = upcast(bev); + + /* If we drained data from the inbuf and were not reading before, + * we may want to read now */ + + bufferevent_incref_and_lock_(bev); + + if (cbinfo->n_deleted) + bev_async_consider_reading(bev_async); + + bufferevent_decref_and_unlock_(bev); +} + +static int be_async_enable(struct bufferevent* buf, short what) +{ + struct bufferevent_async* bev_async = upcast(buf); + + if (!bev_async->ok) + return -1; + + if (bev_async->bev.connecting) { + /* Don't launch anything during connection attempts. */ + return 0; + } + + if (what & EV_READ) + BEV_RESET_GENERIC_READ_TIMEOUT(buf); + if (what & EV_WRITE) + BEV_RESET_GENERIC_WRITE_TIMEOUT(buf); + + /* If we newly enable reading or writing, and we aren't reading or + writing already, consider launching a new read or write. */ + + if (what & EV_READ) + bev_async_consider_reading(bev_async); + if (what & EV_WRITE) + bev_async_consider_writing(bev_async); + return 0; +} + +static int be_async_disable(struct bufferevent* bev, short what) +{ + struct bufferevent_async* bev_async = upcast(bev); + /* XXXX If we disable reading or writing, we may want to consider + * canceling any in-progress read or write operation, though it might + * not work. */ + + if (what & EV_READ) { + BEV_DEL_GENERIC_READ_TIMEOUT(bev); + bev_async_del_read(bev_async); + } + if (what & EV_WRITE) { + BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); + bev_async_del_write(bev_async); + } + + return 0; +} + +static void be_async_destruct(struct bufferevent* bev) +{ + struct bufferevent_async* bev_async = upcast(bev); + struct bufferevent_private* bev_p = BEV_UPCAST(bev); + evutil_socket_t fd; + + EVUTIL_ASSERT(!upcast(bev)->write_in_progress && !upcast(bev)->read_in_progress); + + bev_async_del_read(bev_async); + bev_async_del_write(bev_async); + + fd = evbuffer_overlapped_get_fd_(bev->input); + if (fd != (evutil_socket_t)INVALID_SOCKET && (bev_p->options & BEV_OPT_CLOSE_ON_FREE)) { + evutil_closesocket(fd); + evbuffer_overlapped_set_fd_(bev->input, INVALID_SOCKET); + } +} + +/* GetQueuedCompletionStatus doesn't reliably yield WSA error codes, so + * we use WSAGetOverlappedResult to translate. */ +static void bev_async_set_wsa_error(struct bufferevent* bev, struct event_overlapped* eo) +{ + DWORD bytes, flags; + evutil_socket_t fd; + + fd = evbuffer_overlapped_get_fd_(bev->input); + WSAGetOverlappedResult(fd, &eo->overlapped, &bytes, FALSE, &flags); +} + +static int be_async_flush(struct bufferevent* bev, short what, enum bufferevent_flush_mode mode) +{ + return 0; +} + +static void connect_complete(struct event_overlapped* eo, ev_uintptr_t key, ev_ssize_t nbytes, int ok) +{ + struct bufferevent_async* bev_a = upcast_connect(eo); + struct bufferevent* bev = &bev_a->bev.bev; + evutil_socket_t sock; + + BEV_LOCK(bev); + + EVUTIL_ASSERT(bev_a->bev.connecting); + bev_a->bev.connecting = 0; + sock = evbuffer_overlapped_get_fd_(bev_a->bev.bev.input); + /* XXXX Handle error? */ + setsockopt(sock, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); + + if (ok) + bufferevent_async_set_connected_(bev); + else + bev_async_set_wsa_error(bev, eo); + + bufferevent_run_eventcb_(bev, ok ? BEV_EVENT_CONNECTED : BEV_EVENT_ERROR, 0); + + event_base_del_virtual_(bev->ev_base); + + bufferevent_decref_and_unlock_(bev); +} + +static void read_complete(struct event_overlapped* eo, ev_uintptr_t key, ev_ssize_t nbytes, int ok) +{ + struct bufferevent_async* bev_a = upcast_read(eo); + struct bufferevent* bev = &bev_a->bev.bev; + short what = BEV_EVENT_READING; + ev_ssize_t amount_unread; + BEV_LOCK(bev); + EVUTIL_ASSERT(bev_a->read_in_progress); + + amount_unread = bev_a->read_in_progress - nbytes; + evbuffer_commit_read_(bev->input, nbytes); + bev_a->read_in_progress = 0; + if (amount_unread) + bufferevent_decrement_read_buckets_(&bev_a->bev, -amount_unread); + + if (!ok) + bev_async_set_wsa_error(bev, eo); + + if (bev_a->ok) { + if (ok && nbytes) { + BEV_RESET_GENERIC_READ_TIMEOUT(bev); + bufferevent_trigger_nolock_(bev, EV_READ, 0); + bev_async_consider_reading(bev_a); + } else if (!ok) { + what |= BEV_EVENT_ERROR; + bev_a->ok = 0; + bufferevent_run_eventcb_(bev, what, 0); + } else if (!nbytes) { + what |= BEV_EVENT_EOF; + bev_a->ok = 0; + bufferevent_run_eventcb_(bev, what, 0); + } + } + + bufferevent_decref_and_unlock_(bev); +} + +static void write_complete(struct event_overlapped* eo, ev_uintptr_t key, ev_ssize_t nbytes, int ok) +{ + struct bufferevent_async* bev_a = upcast_write(eo); + struct bufferevent* bev = &bev_a->bev.bev; + short what = BEV_EVENT_WRITING; + ev_ssize_t amount_unwritten; + + BEV_LOCK(bev); + EVUTIL_ASSERT(bev_a->write_in_progress); + + amount_unwritten = bev_a->write_in_progress - nbytes; + evbuffer_commit_write_(bev->output, nbytes); + bev_a->write_in_progress = 0; + + if (amount_unwritten) + bufferevent_decrement_write_buckets_(&bev_a->bev, -amount_unwritten); + + if (!ok) + bev_async_set_wsa_error(bev, eo); + + if (bev_a->ok) { + if (ok && nbytes) { + BEV_RESET_GENERIC_WRITE_TIMEOUT(bev); + bufferevent_trigger_nolock_(bev, EV_WRITE, 0); + bev_async_consider_writing(bev_a); + } else if (!ok) { + what |= BEV_EVENT_ERROR; + bev_a->ok = 0; + bufferevent_run_eventcb_(bev, what, 0); + } else if (!nbytes) { + what |= BEV_EVENT_EOF; + bev_a->ok = 0; + bufferevent_run_eventcb_(bev, what, 0); + } + } + + bufferevent_decref_and_unlock_(bev); +} + +struct bufferevent* bufferevent_async_new_(struct event_base* base, evutil_socket_t fd, int options) +{ + struct bufferevent_async* bev_a; + struct bufferevent* bev; + struct event_iocp_port* iocp; + + options |= BEV_OPT_THREADSAFE; + + if (!(iocp = event_base_get_iocp_(base))) + return NULL; + + if (fd >= 0 && event_iocp_port_associate_(iocp, fd, 1) < 0) { + int err = GetLastError(); + /* We may have alrady associated this fd with a port. + * Let's hope it's this port, and that the error code + * for doing this neer changes. */ + if (err != ERROR_INVALID_PARAMETER) + return NULL; + } + + if (!(bev_a = mm_calloc(1, sizeof(struct bufferevent_async)))) + return NULL; + + bev = &bev_a->bev.bev; + if (!(bev->input = evbuffer_overlapped_new_(fd))) { + mm_free(bev_a); + return NULL; + } + if (!(bev->output = evbuffer_overlapped_new_(fd))) { + evbuffer_free(bev->input); + mm_free(bev_a); + return NULL; + } + + if (bufferevent_init_common_(&bev_a->bev, base, &bufferevent_ops_async, options) < 0) + goto err; + + evbuffer_add_cb(bev->input, be_async_inbuf_callback, bev); + evbuffer_add_cb(bev->output, be_async_outbuf_callback, bev); + + event_overlapped_init_(&bev_a->connect_overlapped, connect_complete); + event_overlapped_init_(&bev_a->read_overlapped, read_complete); + event_overlapped_init_(&bev_a->write_overlapped, write_complete); + + bufferevent_init_generic_timeout_cbs_(bev); + + bev_a->ok = fd >= 0; + + return bev; +err: + bufferevent_free(&bev_a->bev.bev); + return NULL; +} + +void bufferevent_async_set_connected_(struct bufferevent* bev) +{ + struct bufferevent_async* bev_async = upcast(bev); + bev_async->ok = 1; + bufferevent_init_generic_timeout_cbs_(bev); + /* Now's a good time to consider reading/writing */ + be_async_enable(bev, bev->enabled); +} + +int bufferevent_async_can_connect_(struct bufferevent* bev) +{ + const struct win32_extension_fns* ext = event_get_win32_extension_fns_(); + + if (BEV_IS_ASYNC(bev) && event_base_get_iocp_(bev->ev_base) && ext && ext->ConnectEx) + return 1; + + return 0; +} + +int bufferevent_async_connect_(struct bufferevent* bev, evutil_socket_t fd, const struct sockaddr* sa, int socklen) +{ + BOOL rc; + struct bufferevent_async* bev_async = upcast(bev); + struct sockaddr_storage ss; + const struct win32_extension_fns* ext = event_get_win32_extension_fns_(); + + EVUTIL_ASSERT(ext && ext->ConnectEx && fd >= 0 && sa != NULL); + + /* ConnectEx() requires that the socket be bound to an address + * with bind() before using, otherwise it will fail. We attempt + * to issue a bind() here, taking into account that the error + * code is set to WSAEINVAL when the socket is already bound. */ + memset(&ss, 0, sizeof(ss)); + if (sa->sa_family == AF_INET) { + struct sockaddr_in* sin = (struct sockaddr_in*)&ss; + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = INADDR_ANY; + } else if (sa->sa_family == AF_INET6) { + struct sockaddr_in6* sin6 = (struct sockaddr_in6*)&ss; + sin6->sin6_family = AF_INET6; + sin6->sin6_addr = in6addr_any; + } else { + /* Well, the user will have to bind() */ + return -1; + } + if (bind(fd, (struct sockaddr*)&ss, sizeof(ss)) < 0 && WSAGetLastError() != WSAEINVAL) + return -1; + + event_base_add_virtual_(bev->ev_base); + bufferevent_incref_(bev); + rc = ext->ConnectEx(fd, sa, socklen, NULL, 0, NULL, &bev_async->connect_overlapped.overlapped); + if (rc || WSAGetLastError() == ERROR_IO_PENDING) + return 0; + + event_base_del_virtual_(bev->ev_base); + bufferevent_decref_(bev); + + return -1; +} + +static int be_async_ctrl(struct bufferevent* bev, enum bufferevent_ctrl_op op, union bufferevent_ctrl_data* data) +{ + switch (op) { + case BEV_CTRL_GET_FD: + data->fd = evbuffer_overlapped_get_fd_(bev->input); + return 0; + case BEV_CTRL_SET_FD: { + struct event_iocp_port* iocp; + + if (data->fd == evbuffer_overlapped_get_fd_(bev->input)) + return 0; + if (!(iocp = event_base_get_iocp_(bev->ev_base))) + return -1; + if (event_iocp_port_associate_(iocp, data->fd, 1) < 0) + return -1; + evbuffer_overlapped_set_fd_(bev->input, data->fd); + evbuffer_overlapped_set_fd_(bev->output, data->fd); + return 0; + } + case BEV_CTRL_CANCEL_ALL: { + struct bufferevent_async* bev_a = upcast(bev); + evutil_socket_t fd = evbuffer_overlapped_get_fd_(bev->input); + if (fd != (evutil_socket_t)INVALID_SOCKET && (bev_a->bev.options & BEV_OPT_CLOSE_ON_FREE)) { + closesocket(fd); + evbuffer_overlapped_set_fd_(bev->input, INVALID_SOCKET); + } + bev_a->ok = 0; + return 0; + } + case BEV_CTRL_GET_UNDERLYING: + default: + return -1; + } +} diff --git a/asynio/event/bufferevent_compat.h b/asynio/event/bufferevent_compat.h new file mode 100644 index 0000000000000000000000000000000000000000..c5e2ae45d69da1c73aa647dc858e41e012772e95 --- /dev/null +++ b/asynio/event/bufferevent_compat.h @@ -0,0 +1,21 @@ +#ifndef EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_COMPAT_H_INCLUDED_ + +#define evbuffercb bufferevent_data_cb +#define everrorcb bufferevent_event_cb + +struct bufferevent* bufferevent_new(evutil_socket_t fd, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void* cbarg); + +void bufferevent_settimeout(struct bufferevent* bufev, int timeout_read, int timeout_write); + +#define EVBUFFER_READ BEV_EVENT_READING +#define EVBUFFER_WRITE BEV_EVENT_WRITING +#define EVBUFFER_EOF BEV_EVENT_EOF +#define EVBUFFER_ERROR BEV_EVENT_ERROR +#define EVBUFFER_TIMEOUT BEV_EVENT_TIMEOUT + +#define EVBUFFER_INPUT(x) bufferevent_get_input(x) + +#define EVBUFFER_OUTPUT(x) bufferevent_get_output(x) + +#endif diff --git a/asynio/event/bufferevent_filter.c b/asynio/event/bufferevent_filter.c new file mode 100644 index 0000000000000000000000000000000000000000..10bc362ad346726d80b11cec40ba1e77379b48c5 --- /dev/null +++ b/asynio/event/bufferevent_filter.c @@ -0,0 +1,547 @@ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * Copyright (c) 2002-2006 Niels Provos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#include + +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +#include +#include +#include +#include +#ifdef EVENT__HAVE_STDARG_H +#include +#endif + +#ifdef _WIN32 +#include +#endif + +#include "util.h" +#include "bufferevent.h" +#include "buffer.h" +#include "bufferevent_struct.h" +#include "eventbase.h" + +#include "evconfig-internal.h" + +/* prototypes */ +static int be_filter_enable(struct bufferevent*, short); +static int be_filter_disable(struct bufferevent*, short); +static void be_filter_unlink(struct bufferevent*); +static void be_filter_destruct(struct bufferevent*); + +static void be_filter_readcb(struct bufferevent*, void*); +static void be_filter_writecb(struct bufferevent*, void*); +static void be_filter_eventcb(struct bufferevent*, short, void*); +static int be_filter_flush(struct bufferevent* bufev, short iotype, enum bufferevent_flush_mode mode); +static int be_filter_ctrl(struct bufferevent*, enum bufferevent_ctrl_op, union bufferevent_ctrl_data*); + +static void bufferevent_filtered_inbuf_cb(struct evbuffer* buf, const struct evbuffer_cb_info* cbinfo, void* arg); + +static void bufferevent_filtered_outbuf_cb(struct evbuffer* buf, const struct evbuffer_cb_info* info, void* arg); + +struct bufferevent_filtered { + struct bufferevent_private bev; + + /** The bufferevent that we read/write filtered data from/to. */ + struct bufferevent* underlying; + /** A callback on our inbuf to notice somebory removes data */ + struct evbuffer_cb_entry* inbuf_cb; + /** A callback on our outbuf to notice when somebody adds data */ + struct evbuffer_cb_entry* outbuf_cb; + /** True iff we have received an EOF callback from the underlying + * bufferevent. */ + unsigned got_eof; + + /** Function to free context when we're done. */ + void (*free_context)(void*); + /** Input filter */ + bufferevent_filter_cb process_in; + /** Output filter */ + bufferevent_filter_cb process_out; + /** User-supplied argument to the filters. */ + void* context; +}; + +const struct bufferevent_ops bufferevent_ops_filter = { + "filter", + evutil_offsetof(struct bufferevent_filtered, bev.bev), + be_filter_enable, + be_filter_disable, + be_filter_unlink, + be_filter_destruct, + bufferevent_generic_adj_timeouts_, + be_filter_flush, + be_filter_ctrl, +}; + +/* Given a bufferevent that's really the bev filter of a bufferevent_filtered, + * return that bufferevent_filtered. Returns NULL otherwise.*/ +static inline struct bufferevent_filtered* upcast(struct bufferevent* bev) +{ + struct bufferevent_filtered* bev_f; + if (bev->be_ops != &bufferevent_ops_filter) + return NULL; + bev_f = (void*)(((char*)bev) - evutil_offsetof(struct bufferevent_filtered, bev.bev)); + EVUTIL_ASSERT(bev_f->bev.bev.be_ops == &bufferevent_ops_filter); + return bev_f; +} + +#define downcast(bev_f) (&(bev_f)->bev.bev) + +/** Return 1 iff bevf's underlying bufferevent's output buffer is at or + * over its high watermark such that we should not write to it in a given + * flush mode. */ +static int be_underlying_writebuf_full(struct bufferevent_filtered* bevf, enum bufferevent_flush_mode state) +{ + struct bufferevent* u = bevf->underlying; + return state == BEV_NORMAL && u->wm_write.high && evbuffer_get_length(u->output) >= u->wm_write.high; +} + +/** Return 1 if our input buffer is at or over its high watermark such that we + * should not write to it in a given flush mode. */ +static int be_readbuf_full(struct bufferevent_filtered* bevf, enum bufferevent_flush_mode state) +{ + struct bufferevent* bufev = downcast(bevf); + return state == BEV_NORMAL && bufev->wm_read.high && evbuffer_get_length(bufev->input) >= bufev->wm_read.high; +} + +/* Filter to use when we're created with a NULL filter. */ +static enum bufferevent_filter_result + be_null_filter(struct evbuffer* src, struct evbuffer* dst, ev_ssize_t lim, enum bufferevent_flush_mode state, void* ctx) +{ + (void)state; + if (evbuffer_remove_buffer(src, dst, lim) == 0) + return BEV_OK; + else + return BEV_ERROR; +} + +struct bufferevent* bufferevent_filter_new( + struct bufferevent* underlying, + bufferevent_filter_cb input_filter, + bufferevent_filter_cb output_filter, + int options, + void (*free_context)(void*), + void* ctx) +{ + struct bufferevent_filtered* bufev_f; + int tmp_options = options & ~BEV_OPT_THREADSAFE; + + if (!underlying) + return NULL; + + if (!input_filter) + input_filter = be_null_filter; + if (!output_filter) + output_filter = be_null_filter; + + bufev_f = mm_calloc(1, sizeof(struct bufferevent_filtered)); + if (!bufev_f) + return NULL; + + if (bufferevent_init_common_(&bufev_f->bev, underlying->ev_base, &bufferevent_ops_filter, tmp_options) < 0) { + mm_free(bufev_f); + return NULL; + } + if (options & BEV_OPT_THREADSAFE) { + bufferevent_enable_locking_(downcast(bufev_f), NULL); + } + + bufev_f->underlying = underlying; + + bufev_f->process_in = input_filter; + bufev_f->process_out = output_filter; + bufev_f->free_context = free_context; + bufev_f->context = ctx; + + bufferevent_setcb(bufev_f->underlying, be_filter_readcb, be_filter_writecb, be_filter_eventcb, bufev_f); + + bufev_f->inbuf_cb = evbuffer_add_cb(downcast(bufev_f)->input, bufferevent_filtered_inbuf_cb, bufev_f); + evbuffer_cb_clear_flags(downcast(bufev_f)->input, bufev_f->inbuf_cb, EVBUFFER_CB_ENABLED); + + bufev_f->outbuf_cb = evbuffer_add_cb(downcast(bufev_f)->output, bufferevent_filtered_outbuf_cb, bufev_f); + + bufferevent_init_generic_timeout_cbs_(downcast(bufev_f)); + bufferevent_incref_(underlying); + + bufferevent_enable(underlying, EV_READ | EV_WRITE); + bufferevent_suspend_read_(underlying, BEV_SUSPEND_FILT_READ); + + return downcast(bufev_f); +} + +static void be_filter_unlink(struct bufferevent* bev) +{ + struct bufferevent_filtered* bevf = upcast(bev); + EVUTIL_ASSERT(bevf); + + if (bevf->bev.options & BEV_OPT_CLOSE_ON_FREE) { + /* Yes, there is also a decref in bufferevent_decref_. + * That decref corresponds to the incref when we set + * underlying for the first time. This decref is an + * extra one to remove the last reference. + */ + if (BEV_UPCAST(bevf->underlying)->refcnt < 2) { + event_warnx("BEV_OPT_CLOSE_ON_FREE set on an " + "bufferevent with too few references"); + } else { + bufferevent_free(bevf->underlying); + } + } else { + if (bevf->underlying) { + if (bevf->underlying->errorcb == be_filter_eventcb) + bufferevent_setcb(bevf->underlying, NULL, NULL, NULL, NULL); + bufferevent_unsuspend_read_(bevf->underlying, BEV_SUSPEND_FILT_READ); + } + } +} + +static void be_filter_destruct(struct bufferevent* bev) +{ + struct bufferevent_filtered* bevf = upcast(bev); + EVUTIL_ASSERT(bevf); + if (bevf->free_context) + bevf->free_context(bevf->context); + + if (bevf->inbuf_cb) + evbuffer_remove_cb_entry(bev->input, bevf->inbuf_cb); + + if (bevf->outbuf_cb) + evbuffer_remove_cb_entry(bev->output, bevf->outbuf_cb); +} + +static int be_filter_enable(struct bufferevent* bev, short event) +{ + struct bufferevent_filtered* bevf = upcast(bev); + if (event & EV_WRITE) + BEV_RESET_GENERIC_WRITE_TIMEOUT(bev); + + if (event & EV_READ) { + BEV_RESET_GENERIC_READ_TIMEOUT(bev); + bufferevent_unsuspend_read_(bevf->underlying, BEV_SUSPEND_FILT_READ); + } + return 0; +} + +static int be_filter_disable(struct bufferevent* bev, short event) +{ + struct bufferevent_filtered* bevf = upcast(bev); + if (event & EV_WRITE) + BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); + if (event & EV_READ) { + BEV_DEL_GENERIC_READ_TIMEOUT(bev); + bufferevent_suspend_read_(bevf->underlying, BEV_SUSPEND_FILT_READ); + } + return 0; +} + +static enum bufferevent_filter_result + be_filter_process_input(struct bufferevent_filtered* bevf, enum bufferevent_flush_mode state, int* processed_out) +{ + enum bufferevent_filter_result res; + struct bufferevent* bev = downcast(bevf); + + if (state == BEV_NORMAL) { + /* If we're in 'normal' mode, don't urge data on the filter + * unless we're reading data and under our high-water mark.*/ + if (!(bev->enabled & EV_READ) || be_readbuf_full(bevf, state)) + return BEV_OK; + } + + do { + ev_ssize_t limit = -1; + if (state == BEV_NORMAL && bev->wm_read.high) + limit = bev->wm_read.high - evbuffer_get_length(bev->input); + + res = bevf->process_in(bevf->underlying->input, bev->input, limit, state, bevf->context); + + if (res == BEV_OK) + *processed_out = 1; + } while (res == BEV_OK && (bev->enabled & EV_READ) && evbuffer_get_length(bevf->underlying->input) && !be_readbuf_full(bevf, state)); + + if (*processed_out) + BEV_RESET_GENERIC_READ_TIMEOUT(bev); + + return res; +} + +static enum bufferevent_filter_result + be_filter_process_output(struct bufferevent_filtered* bevf, enum bufferevent_flush_mode state, int* processed_out) +{ + /* Requires references and lock: might call writecb */ + enum bufferevent_filter_result res = BEV_OK; + struct bufferevent* bufev = downcast(bevf); + int again = 0; + + if (state == BEV_NORMAL) { + /* If we're in 'normal' mode, don't urge data on the + * filter unless we're writing data, and the underlying + * bufferevent is accepting data, and we have data to + * give the filter. If we're in 'flush' or 'finish', + * call the filter no matter what. */ + if (!(bufev->enabled & EV_WRITE) || be_underlying_writebuf_full(bevf, state) || !evbuffer_get_length(bufev->output)) + return BEV_OK; + } + + /* disable the callback that calls this function + when the user adds to the output buffer. */ + evbuffer_cb_clear_flags(bufev->output, bevf->outbuf_cb, EVBUFFER_CB_ENABLED); + + do { + int processed = 0; + again = 0; + + do { + ev_ssize_t limit = -1; + if (state == BEV_NORMAL && bevf->underlying->wm_write.high) + limit = bevf->underlying->wm_write.high - evbuffer_get_length(bevf->underlying->output); + + res = bevf->process_out(downcast(bevf)->output, bevf->underlying->output, limit, state, bevf->context); + + if (res == BEV_OK) + processed = *processed_out = 1; + } while (/* Stop if the filter wasn't successful...*/ + res == BEV_OK && + /* Or if we aren't writing any more. */ + (bufev->enabled & EV_WRITE) && + /* Of if we have nothing more to write and we are + * not flushing. */ + evbuffer_get_length(bufev->output) && + /* Or if we have filled the underlying output buffer. */ + !be_underlying_writebuf_full(bevf, state)); + + if (processed) { + /* call the write callback.*/ + bufferevent_trigger_nolock_(bufev, EV_WRITE, 0); + + if (res == BEV_OK && (bufev->enabled & EV_WRITE) && evbuffer_get_length(bufev->output) && !be_underlying_writebuf_full(bevf, state)) { + again = 1; + } + } + } while (again); + + /* reenable the outbuf_cb */ + evbuffer_cb_set_flags(bufev->output, bevf->outbuf_cb, EVBUFFER_CB_ENABLED); + + if (*processed_out) + BEV_RESET_GENERIC_WRITE_TIMEOUT(bufev); + + return res; +} + +/* Called when the size of our outbuf changes. */ +static void bufferevent_filtered_outbuf_cb(struct evbuffer* buf, const struct evbuffer_cb_info* cbinfo, void* arg) +{ + struct bufferevent_filtered* bevf = arg; + struct bufferevent* bev = downcast(bevf); + + if (cbinfo->n_added) { + int processed_any = 0; + /* Somebody added more data to the output buffer. Try to + * process it, if we should. */ + bufferevent_incref_and_lock_(bev); + be_filter_process_output(bevf, BEV_NORMAL, &processed_any); + bufferevent_decref_and_unlock_(bev); + } +} + +static void be_filter_read_nolock_(struct bufferevent* underlying, void* me_) +{ + struct bufferevent_filtered* bevf = me_; + enum bufferevent_filter_result res; + enum bufferevent_flush_mode state; + struct bufferevent* bufev = downcast(bevf); + struct bufferevent_private* bufev_private = BEV_UPCAST(bufev); + int processed_any = 0; + + // It's possible our refcount is 0 at this point if another thread free'd our filterevent + EVUTIL_ASSERT(bufev_private->refcnt >= 0); + + // If our refcount is > 0 + if (bufev_private->refcnt > 0) { + if (bevf->got_eof) + state = BEV_FINISHED; + else + state = BEV_NORMAL; + + /* XXXX use return value */ + res = be_filter_process_input(bevf, state, &processed_any); + (void)res; + + /* XXX This should be in process_input, not here. There are + * other places that can call process-input, and they should + * force readcb calls as needed. */ + if (processed_any) { + bufferevent_trigger_nolock_(bufev, EV_READ, 0); + if (evbuffer_get_length(underlying->input) > 0 && be_readbuf_full(bevf, state)) { + /* data left in underlying buffer and filter input buffer + * hit its read high watermark. + * Schedule callback to avoid data gets stuck in underlying + * input buffer. + */ + evbuffer_cb_set_flags(bufev->input, bevf->inbuf_cb, EVBUFFER_CB_ENABLED); + } + } + } +} + +/* Called when the size of our inbuf changes. */ +static void bufferevent_filtered_inbuf_cb(struct evbuffer* buf, const struct evbuffer_cb_info* cbinfo, void* arg) +{ + struct bufferevent_filtered* bevf = arg; + enum bufferevent_flush_mode state; + struct bufferevent* bev = downcast(bevf); + + BEV_LOCK(bev); + + if (bevf->got_eof) + state = BEV_FINISHED; + else + state = BEV_NORMAL; + + if (!be_readbuf_full(bevf, state)) { + /* opportunity to read data which was left in underlying + * input buffer because filter input buffer hit read + * high watermark. + */ + evbuffer_cb_clear_flags(bev->input, bevf->inbuf_cb, EVBUFFER_CB_ENABLED); + if (evbuffer_get_length(bevf->underlying->input) > 0) + be_filter_read_nolock_(bevf->underlying, bevf); + } + + BEV_UNLOCK(bev); +} + +/* Called when the underlying socket has read. */ +static void be_filter_readcb(struct bufferevent* underlying, void* me_) +{ + struct bufferevent_filtered* bevf = me_; + struct bufferevent* bev = downcast(bevf); + + BEV_LOCK(bev); + + be_filter_read_nolock_(underlying, me_); + + BEV_UNLOCK(bev); +} + +/* Called when the underlying socket has drained enough that we can write to + it. */ +static void be_filter_writecb(struct bufferevent* underlying, void* me_) +{ + struct bufferevent_filtered* bevf = me_; + struct bufferevent* bev = downcast(bevf); + struct bufferevent_private* bufev_private = BEV_UPCAST(bev); + int processed_any = 0; + + BEV_LOCK(bev); + + // It's possible our refcount is 0 at this point if another thread free'd our filterevent + EVUTIL_ASSERT(bufev_private->refcnt >= 0); + + // If our refcount is > 0 + if (bufev_private->refcnt > 0) { + be_filter_process_output(bevf, BEV_NORMAL, &processed_any); + } + + BEV_UNLOCK(bev); +} + +/* Called when the underlying socket has given us an error */ +static void be_filter_eventcb(struct bufferevent* underlying, short what, void* me_) +{ + struct bufferevent_filtered* bevf = me_; + struct bufferevent* bev = downcast(bevf); + struct bufferevent_private* bufev_private = BEV_UPCAST(bev); + + BEV_LOCK(bev); + + // It's possible our refcount is 0 at this point if another thread free'd our filterevent + EVUTIL_ASSERT(bufev_private->refcnt >= 0); + + // If our refcount is > 0 + if (bufev_private->refcnt > 0) { + /* All we can really to is tell our own eventcb. */ + bufferevent_run_eventcb_(bev, what, 0); + } + + BEV_UNLOCK(bev); +} + +static int be_filter_flush(struct bufferevent* bufev, short iotype, enum bufferevent_flush_mode mode) +{ + struct bufferevent_filtered* bevf = upcast(bufev); + int processed_any = 0; + EVUTIL_ASSERT(bevf); + + bufferevent_incref_and_lock_(bufev); + + if (iotype & EV_READ) { + be_filter_process_input(bevf, mode, &processed_any); + } + if (iotype & EV_WRITE) { + be_filter_process_output(bevf, mode, &processed_any); + } + /* XXX check the return value? */ + /* XXX does this want to recursively call lower-level flushes? */ + bufferevent_flush(bevf->underlying, iotype, mode); + + bufferevent_decref_and_unlock_(bufev); + + return processed_any; +} + +static int be_filter_ctrl(struct bufferevent* bev, enum bufferevent_ctrl_op op, union bufferevent_ctrl_data* data) +{ + struct bufferevent_filtered* bevf; + switch (op) { + case BEV_CTRL_GET_UNDERLYING: + bevf = upcast(bev); + data->ptr = bevf->underlying; + return 0; + case BEV_CTRL_SET_FD: + bevf = upcast(bev); + + if (bevf->underlying && bevf->underlying->be_ops && bevf->underlying->be_ops->ctrl) { + return (bevf->underlying->be_ops->ctrl)(bevf->underlying, op, data); + } + + case BEV_CTRL_GET_FD: + case BEV_CTRL_CANCEL_ALL: + default: + return -1; + } + + return -1; +} diff --git a/asynio/event/bufferevent_mbedtls.c b/asynio/event/bufferevent_mbedtls.c new file mode 100644 index 0000000000000000000000000000000000000000..20cbfb4d10ee01e6afdeec384598369de0695490 --- /dev/null +++ b/asynio/event/bufferevent_mbedtls.c @@ -0,0 +1,384 @@ + +#define MBEDTLS_ALLOW_PRIVATE_ACCESS +#include "mbedtls-compat.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "util-internal.h" +#include "buffer.h" +#include "bufferevent.h" +#include "bufferevent_struct.h" +#include "bufferevent_ssl.h" + +#include "ssl-compat.h" +#include "mm-internal.h" + +struct mbedtls_context { + mbedtls_ssl_context *ssl; + mbedtls_net_context net; +}; +static void * +mbedtls_context_init(void *ssl) +{ + struct mbedtls_context *ctx = mm_malloc(sizeof(*ctx)); + if (ctx) { + ctx->ssl = ssl; + ctx->net.fd = -1; + } + return ctx; +} +static void +mbedtls_context_free(void *ssl, int flags) +{ + struct mbedtls_context *ctx = ssl; + if (flags & BEV_OPT_CLOSE_ON_FREE) + mbedtls_ssl_free(ctx->ssl); + mm_free(ctx); +} +static int +mbedtls_context_renegotiate(void *ssl) +{ +#ifdef MBEDTLS_SSL_RENEGOTIATION + struct mbedtls_context *ctx = ssl; + return mbedtls_ssl_renegotiate(ctx->ssl); +#else + return MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE; +#endif +} +static int +mbedtls_context_write(void *ssl, const unsigned char *buf, size_t len) +{ + struct mbedtls_context *ctx = ssl; + return mbedtls_ssl_write(ctx->ssl, buf, len); +} +static int +mbedtls_context_read(void *ssl, unsigned char *buf, size_t len) +{ + struct mbedtls_context *ctx = ssl; + return mbedtls_ssl_read(ctx->ssl, buf, len); +} +static size_t +mbedtls_context_pending(void *ssl) +{ + struct mbedtls_context *ctx = ssl; + return mbedtls_ssl_get_bytes_avail(ctx->ssl); +} +static int +mbedtls_context_handshake(void *ssl) +{ + struct mbedtls_context *ctx = ssl; + return mbedtls_ssl_handshake(ctx->ssl); +} +static int +mbedtls_get_error(void *ssl, int ret) +{ + return ret; +} +static void +mbedtls_clear_error(void) +{ +} +static int +mbedtls_clear(void *ssl) +{ + return 1; +} +static void +mbedtls_set_ssl_noops(void *ssl) +{ +} +static int +mbedtls_is_ok(int err) +{ + return err == 0; +} +static int +mbedtls_is_want_read(int err) +{ + return err == MBEDTLS_ERR_SSL_WANT_READ; +} +static int +mbedtls_is_want_write(int err) +{ + return err == MBEDTLS_ERR_SSL_WANT_WRITE; +} + +static evutil_socket_t +be_mbedtls_get_fd(void *ssl) +{ + struct bufferevent_ssl *bev = ssl; + struct mbedtls_context *ctx = bev->ssl; + return ctx->net.fd; +} + +static int be_mbedtls_bio_set_fd( + struct bufferevent_ssl *bev_ssl, evutil_socket_t fd); + +#if 0 +static void +print_err(int val) +{ + char buf[1024]; + mbedtls_strerror(val, buf, sizeof(buf)); + printf("Error was %d:%s\n", val, buf); +} +#else +static void +print_err(int val) +{ +} +#endif + +/* Called to extract data from the BIO. */ +static int +bio_bufferevent_read(void *ctx, unsigned char *out, size_t outlen) +{ + struct bufferevent *bufev = (struct bufferevent *)ctx; + int r = 0; + struct evbuffer *input; + + if (!out) + return 0; + if (!bufev) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + input = bufferevent_get_input(bufev); + if (evbuffer_get_length(input) == 0) { + /* If there's no data to read, say so. */ + return MBEDTLS_ERR_SSL_WANT_READ; + } else { + r = evbuffer_remove(input, out, outlen); + } + + return r; +} + +/* Called to write data into the BIO */ +static int +bio_bufferevent_write(void *ctx, const unsigned char *in, size_t inlen) +{ + struct bufferevent *bufev = (struct bufferevent *)ctx; + struct evbuffer *output; + size_t outlen; + + if (!bufev) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + output = bufferevent_get_output(bufev); + outlen = evbuffer_get_length(output); + + /* Copy only as much data onto the output buffer as can fit under the + * high-water mark. */ + if (bufev->wm_write.high && bufev->wm_write.high <= (outlen + inlen)) { + if (bufev->wm_write.high <= outlen) { + /* If no data can fit, we'll need to retry later. */ + return MBEDTLS_ERR_SSL_WANT_WRITE; + } + inlen = bufev->wm_write.high - outlen; + } + + EVUTIL_ASSERT(inlen > 0); + evbuffer_add(output, in, inlen); + return inlen; +} + +static void +conn_closed(struct bufferevent_ssl *bev_ssl, int when, int errcode, int ret) +{ + int event = BEV_EVENT_ERROR; + char buf[100]; + + if (when & BEV_EVENT_READING && ret == 0) { + if (bev_ssl->flags & BUFFEREVENT_SSL_DIRTY_SHUTDOWN) + event = BEV_EVENT_EOF; + } else { + mbedtls_strerror(errcode, buf, sizeof(buf)); + switch (errcode) { + case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY: + event = BEV_EVENT_EOF; + break; + case MBEDTLS_ERR_SSL_CLIENT_RECONNECT: + event_warnx("BUG: Unsupported feature %d: %s", errcode, buf); + break; + default: + /* should be impossible; treat as normal error. */ + event_warnx( + "BUG: Unexpected mbedtls error code %d: %s", errcode, buf); + break; + } + + bufferevent_ssl_put_error(bev_ssl, errcode); + } + + bufferevent_ssl_stop_reading(bev_ssl); + bufferevent_ssl_stop_writing(bev_ssl); + + bufferevent_run_eventcb_(&bev_ssl->bev.bev, when | event, 0); +} + +static int +be_mbedtls_bio_set_fd(struct bufferevent_ssl *bev_ssl, evutil_socket_t fd) +{ + struct mbedtls_context *ctx = bev_ssl->ssl; + if (!bev_ssl->underlying) { + ctx->net.fd = fd; + mbedtls_ssl_set_bio( + ctx->ssl, &ctx->net, mbedtls_net_send, mbedtls_net_recv, NULL); + } else { + mbedtls_ssl_set_bio(ctx->ssl, bev_ssl->underlying, + bio_bufferevent_write, bio_bufferevent_read, NULL); + } + return 0; +} + +int +bufferevent_mbedtls_get_allow_dirty_shutdown(struct bufferevent *bev) +{ + return bufferevent_ssl_get_allow_dirty_shutdown(bev); +} + +void +bufferevent_mbedtls_set_allow_dirty_shutdown( + struct bufferevent *bev, int allow_dirty_shutdown) +{ + bufferevent_ssl_set_allow_dirty_shutdown(bev, allow_dirty_shutdown); +} + +mbedtls_ssl_context * +bufferevent_mbedtls_get_ssl(struct bufferevent *bufev) +{ + struct mbedtls_context *ctx = NULL; + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bufev); + if (!bev_ssl) + return NULL; + ctx = bev_ssl->ssl; + return ctx->ssl; +} + +int +bufferevent_mbedtls_renegotiate(struct bufferevent *bufev) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bufev); + if (!bev_ssl) + return -1; + return bufferevent_ssl_renegotiate_impl(bufev); +} + +unsigned long +bufferevent_get_mbedtls_error(struct bufferevent *bufev) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bufev); + if (!bev_ssl) + return 0; + return bufferevent_get_ssl_error(bufev); +} + +static struct le_ssl_ops le_mbedtls_ops = { + mbedtls_context_init, + mbedtls_context_free, + (void (*)(void *))mbedtls_ssl_free, + mbedtls_context_renegotiate, + mbedtls_context_write, + mbedtls_context_read, + mbedtls_context_pending, + mbedtls_context_handshake, + mbedtls_get_error, + mbedtls_clear_error, + mbedtls_clear, + mbedtls_set_ssl_noops, + mbedtls_set_ssl_noops, + mbedtls_is_ok, + mbedtls_is_want_read, + mbedtls_is_want_write, + be_mbedtls_get_fd, + be_mbedtls_bio_set_fd, + (void (*)(struct bufferevent_ssl *))mbedtls_set_ssl_noops, + (void (*)(struct bufferevent_ssl *))mbedtls_set_ssl_noops, + conn_closed, + print_err, +}; + +struct bufferevent * +bufferevent_mbedtls_filter_new(struct event_base *base, + struct bufferevent *underlying, mbedtls_ssl_context *ssl, + enum bufferevent_ssl_state state, int options) +{ + struct bufferevent *bev; + + if (!underlying) + goto err; + + bev = bufferevent_ssl_new_impl( + base, underlying, -1, ssl, state, options, &le_mbedtls_ops); + + if (bev) { + be_mbedtls_bio_set_fd(bufferevent_ssl_upcast(bev), -1); + } + + return bev; + +err: + if (options & BEV_OPT_CLOSE_ON_FREE) + mbedtls_ssl_free(ssl); + return NULL; +} + +struct bufferevent * +bufferevent_mbedtls_socket_new(struct event_base *base, evutil_socket_t fd, + mbedtls_ssl_context *ssl, enum bufferevent_ssl_state state, int options) +{ + long have_fd = -1; + struct bufferevent *bev; + + if (ssl->p_bio) { + /* The SSL is already configured with bio. */ + if (ssl->f_send == mbedtls_net_send && + ssl->f_recv == mbedtls_net_recv) { + have_fd = ((mbedtls_net_context *)ssl->p_bio)->fd; + } else if (ssl->f_send == bio_bufferevent_write && + ssl->f_recv == bio_bufferevent_read) { + have_fd = bufferevent_getfd(ssl->p_bio); + } else { + /* We don't known the fd. */ + have_fd = LONG_MAX; + } + } + + if (have_fd >= 0) { + if (fd < 0) { + /* We should learn the fd from the SSL. */ + fd = (evutil_socket_t)have_fd; + } else if (have_fd == (long)fd) { + /* We already know the fd from the SSL; do nothing */ + } else { + /* We specified an fd different from that of the SSL. + This is probably an error on our part. Fail. */ + goto err; + } + } else { + if (fd >= 0) { + /* ... and we have an fd we want to use. */ + } else { + /* Leave the fd unset. */ + } + } + + bev = bufferevent_ssl_new_impl( + base, NULL, fd, ssl, state, options, &le_mbedtls_ops); + + if (bev) { + be_mbedtls_bio_set_fd(bufferevent_ssl_upcast(bev), fd); + } + + return bev; +err: + return NULL; +} diff --git a/asynio/event/bufferevent_pair.c b/asynio/event/bufferevent_pair.c new file mode 100644 index 0000000000000000000000000000000000000000..6f00cb34e64463a8fc930acde1986e647c6cabe8 --- /dev/null +++ b/asynio/event/bufferevent_pair.c @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2009-2012 Niels Provos, Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#include + +#ifdef _WIN32 +#include +#endif + +#include "util.h" +#include "buffer.h" +#include "bufferevent.h" +#include "bufferevent_struct.h" +#include "eventbase.h" + +#include "evconfig-internal.h" + +struct bufferevent_pair { + struct bufferevent_private bev; + struct bufferevent_pair* partner; + /* For ->destruct() lock checking */ + struct bufferevent_pair* unlinked_partner; +}; + +/* Given a bufferevent that's really a bev part of a bufferevent_pair, + * return that bufferevent_filtered. Returns NULL otherwise.*/ +static inline struct bufferevent_pair* upcast(struct bufferevent* bev) +{ + struct bufferevent_pair* bev_p; + if (bev->be_ops != &bufferevent_ops_pair) + return NULL; + bev_p = EVUTIL_UPCAST(bev, struct bufferevent_pair, bev.bev); + EVUTIL_ASSERT(bev_p->bev.bev.be_ops == &bufferevent_ops_pair); + return bev_p; +} + +#define downcast(bev_pair) (&(bev_pair)->bev.bev) + +static inline void incref_and_lock(struct bufferevent* b) +{ + struct bufferevent_pair* bevp; + bufferevent_incref_and_lock_(b); + bevp = upcast(b); + if (bevp->partner) + bufferevent_incref_and_lock_(downcast(bevp->partner)); +} + +static inline void decref_and_unlock(struct bufferevent* b) +{ + struct bufferevent_pair* bevp = upcast(b); + if (bevp->partner) + bufferevent_decref_and_unlock_(downcast(bevp->partner)); + bufferevent_decref_and_unlock_(b); +} + +/* XXX Handle close */ + +static void be_pair_outbuf_cb(struct evbuffer*, const struct evbuffer_cb_info*, void*); + +static struct bufferevent_pair* bufferevent_pair_elt_new(struct event_base* base, int options) +{ + struct bufferevent_pair* bufev; + if (!(bufev = mm_calloc(1, sizeof(struct bufferevent_pair)))) + return NULL; + if (bufferevent_init_common_(&bufev->bev, base, &bufferevent_ops_pair, options)) { + mm_free(bufev); + return NULL; + } + if (!evbuffer_add_cb(bufev->bev.bev.output, be_pair_outbuf_cb, bufev)) { + bufferevent_free(downcast(bufev)); + return NULL; + } + + bufferevent_init_generic_timeout_cbs_(&bufev->bev.bev); + + return bufev; +} + +int bufferevent_pair_new(struct event_base* base, int options, struct bufferevent* pair[2]) +{ + struct bufferevent_pair *bufev1 = NULL, *bufev2 = NULL; + int tmp_options; + + options |= BEV_OPT_DEFER_CALLBACKS; + tmp_options = options & ~BEV_OPT_THREADSAFE; + + bufev1 = bufferevent_pair_elt_new(base, options); + if (!bufev1) + return -1; + bufev2 = bufferevent_pair_elt_new(base, tmp_options); + if (!bufev2) { + bufferevent_free(downcast(bufev1)); + return -1; + } + + if (options & BEV_OPT_THREADSAFE) { + /*XXXX check return */ + bufferevent_enable_locking_(downcast(bufev2), bufev1->bev.lock); + } + + bufev1->partner = bufev2; + bufev2->partner = bufev1; + + evbuffer_freeze(downcast(bufev1)->input, 0); + evbuffer_freeze(downcast(bufev1)->output, 1); + evbuffer_freeze(downcast(bufev2)->input, 0); + evbuffer_freeze(downcast(bufev2)->output, 1); + + pair[0] = downcast(bufev1); + pair[1] = downcast(bufev2); + + return 0; +} + +static void be_pair_transfer(struct bufferevent* src, struct bufferevent* dst, int ignore_wm) +{ + size_t dst_size; + size_t n; + + evbuffer_unfreeze(src->output, 1); + evbuffer_unfreeze(dst->input, 0); + + if (dst->wm_read.high) { + dst_size = evbuffer_get_length(dst->input); + if (dst_size < dst->wm_read.high) { + n = dst->wm_read.high - dst_size; + evbuffer_remove_buffer(src->output, dst->input, n); + } else { + if (!ignore_wm) + goto done; + n = evbuffer_get_length(src->output); + evbuffer_add_buffer(dst->input, src->output); + } + } else { + n = evbuffer_get_length(src->output); + evbuffer_add_buffer(dst->input, src->output); + } + + if (n) { + BEV_RESET_GENERIC_READ_TIMEOUT(dst); + + if (evbuffer_get_length(dst->output)) + BEV_RESET_GENERIC_WRITE_TIMEOUT(dst); + else + BEV_DEL_GENERIC_WRITE_TIMEOUT(dst); + } + + bufferevent_trigger_nolock_(dst, EV_READ, 0); + bufferevent_trigger_nolock_(src, EV_WRITE, 0); +done: + evbuffer_freeze(src->output, 1); + evbuffer_freeze(dst->input, 0); +} + +static inline int be_pair_wants_to_talk(struct bufferevent_pair* src, struct bufferevent_pair* dst) +{ + return (downcast(src)->enabled & EV_WRITE) && (downcast(dst)->enabled & EV_READ) && !dst->bev.read_suspended + && evbuffer_get_length(downcast(src)->output); +} + +static void be_pair_outbuf_cb(struct evbuffer* outbuf, const struct evbuffer_cb_info* info, void* arg) +{ + struct bufferevent_pair* bev_pair = arg; + struct bufferevent_pair* partner = bev_pair->partner; + + incref_and_lock(downcast(bev_pair)); + + if (info->n_added > info->n_deleted && partner) { + /* We got more data. If the other side's reading, then + hand it over. */ + if (be_pair_wants_to_talk(bev_pair, partner)) { + be_pair_transfer(downcast(bev_pair), downcast(partner), 0); + } + } + + decref_and_unlock(downcast(bev_pair)); +} + +static int be_pair_enable(struct bufferevent* bufev, short events) +{ + struct bufferevent_pair* bev_p = upcast(bufev); + struct bufferevent_pair* partner = bev_p->partner; + + incref_and_lock(bufev); + + if (events & EV_READ) { + BEV_RESET_GENERIC_READ_TIMEOUT(bufev); + } + if ((events & EV_WRITE) && evbuffer_get_length(bufev->output)) + BEV_RESET_GENERIC_WRITE_TIMEOUT(bufev); + + /* We're starting to read! Does the other side have anything to write?*/ + if ((events & EV_READ) && partner && be_pair_wants_to_talk(partner, bev_p)) { + be_pair_transfer(downcast(partner), bufev, 0); + } + /* We're starting to write! Does the other side want to read? */ + if ((events & EV_WRITE) && partner && be_pair_wants_to_talk(bev_p, partner)) { + be_pair_transfer(bufev, downcast(partner), 0); + } + decref_and_unlock(bufev); + return 0; +} + +static int be_pair_disable(struct bufferevent* bev, short events) +{ + if (events & EV_READ) { + BEV_DEL_GENERIC_READ_TIMEOUT(bev); + } + if (events & EV_WRITE) { + BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); + } + return 0; +} + +static void be_pair_unlink(struct bufferevent* bev) +{ + struct bufferevent_pair* bev_p = upcast(bev); + + if (bev_p->partner) { + bev_p->unlinked_partner = bev_p->partner; + bev_p->partner->partner = NULL; + bev_p->partner = NULL; + } +} + +/* Free *shared* lock in the latest be (since we share it between two of them). */ +static void be_pair_destruct(struct bufferevent* bev) +{ + struct bufferevent_pair* bev_p = upcast(bev); + + /* Transfer ownership of the lock into partner, otherwise we will use + * already free'd lock during freeing second bev, see next example: + * + * bev1->own_lock = 1 + * bev2->own_lock = 0 + * bev2->lock = bev1->lock + * + * bufferevent_free(bev1) # refcnt == 0 -> unlink + * bufferevent_free(bev2) # refcnt == 0 -> unlink + * + * event_base_free() -> finilizers -> EVTHREAD_FREE_LOCK(bev1->lock) + * -> BEV_LOCK(bev2->lock) <-- already freed + * + * Where bev1 == pair[0], bev2 == pair[1]. + */ + if (bev_p->unlinked_partner && bev_p->bev.own_lock) { + bev_p->unlinked_partner->bev.own_lock = 1; + bev_p->bev.own_lock = 0; + } + bev_p->unlinked_partner = NULL; +} + +static int be_pair_flush(struct bufferevent* bev, short iotype, enum bufferevent_flush_mode mode) +{ + struct bufferevent_pair* bev_p = upcast(bev); + struct bufferevent* partner; + + if (!bev_p->partner) + return -1; + + if (mode == BEV_NORMAL) + return 0; + + incref_and_lock(bev); + + partner = downcast(bev_p->partner); + + if ((iotype & EV_READ) != 0) + be_pair_transfer(partner, bev, 1); + + if ((iotype & EV_WRITE) != 0) + be_pair_transfer(bev, partner, 1); + + if (mode == BEV_FINISHED) { + short what = BEV_EVENT_EOF; + if (iotype & EV_READ) + what |= BEV_EVENT_WRITING; + if (iotype & EV_WRITE) + what |= BEV_EVENT_READING; + bufferevent_run_eventcb_(partner, what, 0); + } + decref_and_unlock(bev); + return 0; +} + +struct bufferevent* bufferevent_pair_get_partner(struct bufferevent* bev) +{ + struct bufferevent_pair* bev_p; + struct bufferevent* partner = NULL; + bev_p = upcast(bev); + if (!bev_p) + return NULL; + + incref_and_lock(bev); + if (bev_p->partner) + partner = downcast(bev_p->partner); + decref_and_unlock(bev); + return partner; +} + +const struct bufferevent_ops bufferevent_ops_pair = { + "pair_elt", + evutil_offsetof(struct bufferevent_pair, bev.bev), + be_pair_enable, + be_pair_disable, + be_pair_unlink, + be_pair_destruct, + bufferevent_generic_adj_timeouts_, + be_pair_flush, + NULL, /* ctrl */ +}; diff --git a/asynio/event/bufferevent_ratelim.c b/asynio/event/bufferevent_ratelim.c new file mode 100644 index 0000000000000000000000000000000000000000..9e3b454ca83d46b012f7df7761d4e28821446dd7 --- /dev/null +++ b/asynio/event/bufferevent_ratelim.c @@ -0,0 +1,989 @@ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * Copyright (c) 2002-2006 Niels Provos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#include +#include +#include +#include + +#include "eventbase.h" +#include "event_struct.h" +#include "util.h" +#include "bufferevent.h" +#include "bufferevent_struct.h" +#include "buffer.h" + +#include "evconfig-internal.h" + +int ev_token_bucket_init_(struct ev_token_bucket* bucket, const struct ev_token_bucket_cfg* cfg, ev_uint32_t current_tick, int reinitialize) +{ + if (reinitialize) { + /* on reinitialization, we only clip downwards, since we've + already used who-knows-how-much bandwidth this tick. We + leave "last_updated" as it is; the next update will add the + appropriate amount of bandwidth to the bucket. + */ + if (bucket->read_limit > (ev_int64_t)cfg->read_maximum) + bucket->read_limit = cfg->read_maximum; + if (bucket->write_limit > (ev_int64_t)cfg->write_maximum) + bucket->write_limit = cfg->write_maximum; + } else { + bucket->read_limit = cfg->read_rate; + bucket->write_limit = cfg->write_rate; + bucket->last_updated = current_tick; + } + return 0; +} + +int ev_token_bucket_update_(struct ev_token_bucket* bucket, const struct ev_token_bucket_cfg* cfg, ev_uint32_t current_tick) +{ + /* It's okay if the tick number overflows, since we'll just + * wrap around when we do the unsigned substraction. */ + unsigned n_ticks = current_tick - bucket->last_updated; + + /* Make sure some ticks actually happened, and that time didn't + * roll back. */ + if (n_ticks == 0 || n_ticks > INT_MAX) + return 0; + + /* Naively, we would say + bucket->limit += n_ticks * cfg->rate; + + if (bucket->limit > cfg->maximum) + bucket->limit = cfg->maximum; + + But we're worried about overflow, so we do it like this: + */ + + if ((cfg->read_maximum - bucket->read_limit) / n_ticks < cfg->read_rate) + bucket->read_limit = cfg->read_maximum; + else + bucket->read_limit += n_ticks * cfg->read_rate; + + if ((cfg->write_maximum - bucket->write_limit) / n_ticks < cfg->write_rate) + bucket->write_limit = cfg->write_maximum; + else + bucket->write_limit += n_ticks * cfg->write_rate; + + bucket->last_updated = current_tick; + + return 1; +} + +static inline void bufferevent_update_buckets(struct bufferevent_private* bev) +{ + /* Must hold lock on bev. */ + struct timeval now; + unsigned tick; + event_base_gettimeofday_cached(bev->bev.ev_base, &now); + tick = ev_token_bucket_get_tick_(&now, bev->rate_limiting->cfg); + if (tick != bev->rate_limiting->limit.last_updated) + ev_token_bucket_update_(&bev->rate_limiting->limit, bev->rate_limiting->cfg, tick); +} + +ev_uint32_t ev_token_bucket_get_tick_(const struct timeval* tv, const struct ev_token_bucket_cfg* cfg) +{ + /* This computation uses two multiplies and a divide. We could do + * fewer if we knew that the tick length was an integer number of + * seconds, or if we knew it divided evenly into a second. We should + * investigate that more. + */ + + /* We cast to an ev_uint64_t first, since we don't want to overflow + * before we do the final divide. */ + ev_uint64_t msec = (ev_uint64_t)tv->tv_sec * 1000 + tv->tv_usec / 1000; + return (unsigned)(msec / cfg->msec_per_tick); +} + +struct ev_token_bucket_cfg* + ev_token_bucket_cfg_new(size_t read_rate, size_t read_burst, size_t write_rate, size_t write_burst, const struct timeval* tick_len) +{ + struct ev_token_bucket_cfg* r; + struct timeval g; + if (!tick_len) { + g.tv_sec = 1; + g.tv_usec = 0; + tick_len = &g; + } + if (read_rate > read_burst || write_rate > write_burst || read_rate < 1 || write_rate < 1) + return NULL; + if (read_rate > EV_RATE_LIMIT_MAX || write_rate > EV_RATE_LIMIT_MAX || read_burst > EV_RATE_LIMIT_MAX || write_burst > EV_RATE_LIMIT_MAX) + return NULL; + r = mm_calloc(1, sizeof(struct ev_token_bucket_cfg)); + if (!r) + return NULL; + r->read_rate = read_rate; + r->write_rate = write_rate; + r->read_maximum = read_burst; + r->write_maximum = write_burst; + memcpy(&r->tick_timeout, tick_len, sizeof(struct timeval)); + r->msec_per_tick = (tick_len->tv_sec * 1000) + (tick_len->tv_usec & COMMON_TIMEOUT_MICROSECONDS_MASK) / 1000; + return r; +} + +void ev_token_bucket_cfg_free(struct ev_token_bucket_cfg* cfg) +{ + mm_free(cfg); +} + +/* Default values for max_single_read & max_single_write variables. */ +#define MAX_SINGLE_READ_DEFAULT 16384 +#define MAX_SINGLE_WRITE_DEFAULT 16384 + +#define LOCK_GROUP(g) EVLOCK_LOCK((g)->lock, 0) +#define UNLOCK_GROUP(g) EVLOCK_UNLOCK((g)->lock, 0) + +static int bev_group_suspend_reading_(struct bufferevent_rate_limit_group* g); +static int bev_group_suspend_writing_(struct bufferevent_rate_limit_group* g); +static void bev_group_unsuspend_reading_(struct bufferevent_rate_limit_group* g); +static void bev_group_unsuspend_writing_(struct bufferevent_rate_limit_group* g); + +/** Helper: figure out the maximum amount we should write if is_write, or + the maximum amount we should read if is_read. Return that maximum, or + 0 if our bucket is wholly exhausted. + */ +static inline ev_ssize_t bufferevent_get_rlim_max_(struct bufferevent_private* bev, int is_write) +{ + /* needs lock on bev. */ + ev_ssize_t max_so_far = is_write ? bev->max_single_write : bev->max_single_read; + +#define LIM(x) (is_write ? (x).write_limit : (x).read_limit) + +#define GROUP_SUSPENDED(g) (is_write ? (g)->write_suspended : (g)->read_suspended) + + /* Sets max_so_far to MIN(x, max_so_far) */ +#define CLAMPTO(x) \ + do { \ + if (max_so_far > (x)) \ + max_so_far = (x); \ + } while (0); + + if (!bev->rate_limiting) + return max_so_far; + + /* If rate-limiting is enabled at all, update the appropriate + bucket, and take the smaller of our rate limit and the group + rate limit. + */ + + if (bev->rate_limiting->cfg) { + bufferevent_update_buckets(bev); + max_so_far = LIM(bev->rate_limiting->limit); + } + if (bev->rate_limiting->group) { + struct bufferevent_rate_limit_group* g = bev->rate_limiting->group; + ev_ssize_t share; + LOCK_GROUP(g); + if (GROUP_SUSPENDED(g)) { + /* We can get here if we failed to lock this + * particular bufferevent while suspending the whole + * group. */ + if (is_write) + bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW_GROUP); + else + bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW_GROUP); + share = 0; + } else { + /* XXXX probably we should divide among the active + * members, not the total members. */ + share = LIM(g->rate_limit) / g->n_members; + if (share < g->min_share) + share = g->min_share; + } + UNLOCK_GROUP(g); + CLAMPTO(share); + } + + if (max_so_far < 0) + max_so_far = 0; + return max_so_far; +} + +ev_ssize_t bufferevent_get_read_max_(struct bufferevent_private* bev) +{ + return bufferevent_get_rlim_max_(bev, 0); +} + +ev_ssize_t bufferevent_get_write_max_(struct bufferevent_private* bev) +{ + return bufferevent_get_rlim_max_(bev, 1); +} + +int bufferevent_decrement_read_buckets_(struct bufferevent_private* bev, ev_ssize_t bytes) +{ + /* XXXXX Make sure all users of this function check its return value */ + int r = 0; + /* need to hold lock on bev */ + if (!bev->rate_limiting) + return 0; + + if (bev->rate_limiting->cfg) { + bev->rate_limiting->limit.read_limit -= bytes; + if (bev->rate_limiting->limit.read_limit <= 0) { + bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW); + if (event_add(&bev->rate_limiting->refill_bucket_event, &bev->rate_limiting->cfg->tick_timeout) < 0) + r = -1; + } else if (bev->read_suspended & BEV_SUSPEND_BW) { + if (!(bev->write_suspended & BEV_SUSPEND_BW)) + event_del(&bev->rate_limiting->refill_bucket_event); + bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); + } + } + + if (bev->rate_limiting->group) { + LOCK_GROUP(bev->rate_limiting->group); + bev->rate_limiting->group->rate_limit.read_limit -= bytes; + bev->rate_limiting->group->total_read += bytes; + if (bev->rate_limiting->group->rate_limit.read_limit <= 0) { + bev_group_suspend_reading_(bev->rate_limiting->group); + } else if (bev->rate_limiting->group->read_suspended) { + bev_group_unsuspend_reading_(bev->rate_limiting->group); + } + UNLOCK_GROUP(bev->rate_limiting->group); + } + + return r; +} + +int bufferevent_decrement_write_buckets_(struct bufferevent_private* bev, ev_ssize_t bytes) +{ + /* XXXXX Make sure all users of this function check its return value */ + int r = 0; + /* need to hold lock */ + if (!bev->rate_limiting) + return 0; + + if (bev->rate_limiting->cfg) { + bev->rate_limiting->limit.write_limit -= bytes; + if (bev->rate_limiting->limit.write_limit <= 0) { + bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW); + if (event_add(&bev->rate_limiting->refill_bucket_event, &bev->rate_limiting->cfg->tick_timeout) < 0) + r = -1; + } else if (bev->write_suspended & BEV_SUSPEND_BW) { + if (!(bev->read_suspended & BEV_SUSPEND_BW)) + event_del(&bev->rate_limiting->refill_bucket_event); + bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); + } + } + + if (bev->rate_limiting->group) { + LOCK_GROUP(bev->rate_limiting->group); + bev->rate_limiting->group->rate_limit.write_limit -= bytes; + bev->rate_limiting->group->total_written += bytes; + if (bev->rate_limiting->group->rate_limit.write_limit <= 0) { + bev_group_suspend_writing_(bev->rate_limiting->group); + } else if (bev->rate_limiting->group->write_suspended) { + bev_group_unsuspend_writing_(bev->rate_limiting->group); + } + UNLOCK_GROUP(bev->rate_limiting->group); + } + + return r; +} + +/** Stop reading on every bufferevent in g */ +static int bev_group_suspend_reading_(struct bufferevent_rate_limit_group* g) +{ + /* Needs group lock */ + struct bufferevent_private* bev; + g->read_suspended = 1; + g->pending_unsuspend_read = 0; + + /* Note that in this loop we call EVLOCK_TRY_LOCK_ instead of BEV_LOCK, + to prevent a deadlock. (Ordinarily, the group lock nests inside + the bufferevent locks. If we are unable to lock any individual + bufferevent, it will find out later when it looks at its limit + and sees that its group is suspended.) + */ + LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) + { + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW_GROUP); + EVLOCK_UNLOCK(bev->lock, 0); + } + } + return 0; +} + +/** Stop writing on every bufferevent in g */ +static int bev_group_suspend_writing_(struct bufferevent_rate_limit_group* g) +{ + /* Needs group lock */ + struct bufferevent_private* bev; + g->write_suspended = 1; + g->pending_unsuspend_write = 0; + LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) + { + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW_GROUP); + EVLOCK_UNLOCK(bev->lock, 0); + } + } + return 0; +} + +/** Timer callback invoked on a single bufferevent with one or more exhausted + buckets when they are ready to refill. */ +static void bev_refill_callback_(evutil_socket_t fd, short what, void* arg) +{ + unsigned tick; + struct timeval now; + struct bufferevent_private* bev = arg; + int again = 0; + BEV_LOCK(&bev->bev); + if (!bev->rate_limiting || !bev->rate_limiting->cfg) { + BEV_UNLOCK(&bev->bev); + return; + } + + /* First, update the bucket */ + event_base_gettimeofday_cached(bev->bev.ev_base, &now); + tick = ev_token_bucket_get_tick_(&now, bev->rate_limiting->cfg); + ev_token_bucket_update_(&bev->rate_limiting->limit, bev->rate_limiting->cfg, tick); + + /* Now unsuspend any read/write operations as appropriate. */ + if ((bev->read_suspended & BEV_SUSPEND_BW)) { + if (bev->rate_limiting->limit.read_limit > 0) + bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); + else + again = 1; + } + if ((bev->write_suspended & BEV_SUSPEND_BW)) { + if (bev->rate_limiting->limit.write_limit > 0) + bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); + else + again = 1; + } + if (again) { + /* One or more of the buckets may need another refill if they + started negative. + + XXXX if we need to be quiet for more ticks, we should + maybe figure out what timeout we really want. + */ + /* XXXX Handle event_add failure somehow */ + event_add(&bev->rate_limiting->refill_bucket_event, &bev->rate_limiting->cfg->tick_timeout); + } + BEV_UNLOCK(&bev->bev); +} + +/** Helper: grab a random element from a bufferevent group. + * + * Requires that we hold the lock on the group. + */ +static struct bufferevent_private* bev_group_random_element_(struct bufferevent_rate_limit_group* group) +{ + int which; + struct bufferevent_private* bev; + + /* requires group lock */ + + if (!group->n_members) + return NULL; + + EVUTIL_ASSERT(!LIST_EMPTY(&group->members)); + + which = evutil_weakrand_range_(&group->weakrand_seed, group->n_members); + + bev = LIST_FIRST(&group->members); + while (which--) + bev = LIST_NEXT(bev, rate_limiting->next_in_group); + + return bev; +} + +/** Iterate over the elements of a rate-limiting group 'g' with a random + starting point, assigning each to the variable 'bev', and executing the + block 'block'. + + We do this in a half-baked effort to get fairness among group members. + XXX Round-robin or some kind of priority queue would be even more fair. + */ +#define FOREACH_RANDOM_ORDER(block) \ + do { \ + first = bev_group_random_element_(g); \ + for (bev = first; bev != LIST_END(&g->members); bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \ + block; \ + } \ + for (bev = LIST_FIRST(&g->members); bev && bev != first; bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \ + block; \ + } \ + } while (0) + +static void bev_group_unsuspend_reading_(struct bufferevent_rate_limit_group* g) +{ + int again = 0; + struct bufferevent_private *bev, *first; + + g->read_suspended = 0; + FOREACH_RANDOM_ORDER({ + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW_GROUP); + EVLOCK_UNLOCK(bev->lock, 0); + } else { + again = 1; + } + }); + g->pending_unsuspend_read = again; +} + +static void bev_group_unsuspend_writing_(struct bufferevent_rate_limit_group* g) +{ + int again = 0; + struct bufferevent_private *bev, *first; + g->write_suspended = 0; + + FOREACH_RANDOM_ORDER({ + if (EVLOCK_TRY_LOCK_(bev->lock)) { + bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW_GROUP); + EVLOCK_UNLOCK(bev->lock, 0); + } else { + again = 1; + } + }); + g->pending_unsuspend_write = again; +} + +/** Callback invoked every tick to add more elements to the group bucket + and unsuspend group members as needed. + */ +static void bev_group_refill_callback_(evutil_socket_t fd, short what, void* arg) +{ + struct bufferevent_rate_limit_group* g = arg; + unsigned tick; + struct timeval now; + + event_base_gettimeofday_cached(event_get_base(&g->master_refill_event), &now); + + LOCK_GROUP(g); + + tick = ev_token_bucket_get_tick_(&now, &g->rate_limit_cfg); + ev_token_bucket_update_(&g->rate_limit, &g->rate_limit_cfg, tick); + + if (g->pending_unsuspend_read || (g->read_suspended && (g->rate_limit.read_limit >= g->min_share))) { + bev_group_unsuspend_reading_(g); + } + if (g->pending_unsuspend_write || (g->write_suspended && (g->rate_limit.write_limit >= g->min_share))) { + bev_group_unsuspend_writing_(g); + } + + /* XXXX Rather than waiting to the next tick to unsuspend stuff + * with pending_unsuspend_write/read, we should do it on the + * next iteration of the mainloop. + */ + + UNLOCK_GROUP(g); +} + +int bufferevent_set_rate_limit(struct bufferevent* bev, struct ev_token_bucket_cfg* cfg) +{ + struct bufferevent_private* bevp = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + int r = -1; + struct bufferevent_rate_limit* rlim; + struct timeval now; + ev_uint32_t tick; + int reinit = 0, suspended = 0; + /* XXX reference-count cfg */ + + BEV_LOCK(bev); + + if (cfg == NULL) { + if (bevp->rate_limiting) { + rlim = bevp->rate_limiting; + rlim->cfg = NULL; + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); + if (event_initialized(&rlim->refill_bucket_event)) + event_del(&rlim->refill_bucket_event); + } + r = 0; + goto done; + } + + event_base_gettimeofday_cached(bev->ev_base, &now); + tick = ev_token_bucket_get_tick_(&now, cfg); + + if (bevp->rate_limiting && bevp->rate_limiting->cfg == cfg) { + /* no-op */ + r = 0; + goto done; + } + if (bevp->rate_limiting == NULL) { + rlim = mm_calloc(1, sizeof(struct bufferevent_rate_limit)); + if (!rlim) + goto done; + bevp->rate_limiting = rlim; + } else { + rlim = bevp->rate_limiting; + } + reinit = rlim->cfg != NULL; + + rlim->cfg = cfg; + ev_token_bucket_init_(&rlim->limit, cfg, tick, reinit); + + if (reinit) { + EVUTIL_ASSERT(event_initialized(&rlim->refill_bucket_event)); + event_del(&rlim->refill_bucket_event); + } + event_assign(&rlim->refill_bucket_event, bev->ev_base, -1, EV_FINALIZE, bev_refill_callback_, bevp); + + if (rlim->limit.read_limit > 0) { + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); + } else { + bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); + suspended = 1; + } + if (rlim->limit.write_limit > 0) { + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); + } else { + bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); + suspended = 1; + } + + if (suspended) + event_add(&rlim->refill_bucket_event, &cfg->tick_timeout); + + r = 0; + +done: + BEV_UNLOCK(bev); + return r; +} + +struct bufferevent_rate_limit_group* bufferevent_rate_limit_group_new(struct event_base* base, const struct ev_token_bucket_cfg* cfg) +{ + struct bufferevent_rate_limit_group* g; + struct timeval now; + ev_uint32_t tick; + + event_base_gettimeofday_cached(base, &now); + tick = ev_token_bucket_get_tick_(&now, cfg); + + g = mm_calloc(1, sizeof(struct bufferevent_rate_limit_group)); + if (!g) + return NULL; + memcpy(&g->rate_limit_cfg, cfg, sizeof(g->rate_limit_cfg)); + LIST_INIT(&g->members); + + ev_token_bucket_init_(&g->rate_limit, cfg, tick, 0); + + event_assign(&g->master_refill_event, base, -1, EV_PERSIST | EV_FINALIZE, bev_group_refill_callback_, g); + /*XXXX handle event_add failure */ + event_add(&g->master_refill_event, &cfg->tick_timeout); + + EVTHREAD_ALLOC_LOCK(g->lock, EVTHREAD_LOCKTYPE_RECURSIVE); + + bufferevent_rate_limit_group_set_min_share(g, 64); + + evutil_weakrand_seed_(&g->weakrand_seed, (ev_uint32_t)((now.tv_sec + now.tv_usec) + (ev_intptr_t)g)); + + return g; +} + +int bufferevent_rate_limit_group_set_cfg(struct bufferevent_rate_limit_group* g, const struct ev_token_bucket_cfg* cfg) +{ + int same_tick; + if (!g || !cfg) + return -1; + + LOCK_GROUP(g); + same_tick = evutil_timercmp(&g->rate_limit_cfg.tick_timeout, &cfg->tick_timeout, ==); + memcpy(&g->rate_limit_cfg, cfg, sizeof(g->rate_limit_cfg)); + + if (g->rate_limit.read_limit > (ev_ssize_t)cfg->read_maximum) + g->rate_limit.read_limit = cfg->read_maximum; + if (g->rate_limit.write_limit > (ev_ssize_t)cfg->write_maximum) + g->rate_limit.write_limit = cfg->write_maximum; + + if (!same_tick) { + /* This can cause a hiccup in the schedule */ + event_add(&g->master_refill_event, &cfg->tick_timeout); + } + + /* The new limits might force us to adjust min_share differently. */ + bufferevent_rate_limit_group_set_min_share(g, g->configured_min_share); + + UNLOCK_GROUP(g); + return 0; +} + +int bufferevent_rate_limit_group_set_min_share(struct bufferevent_rate_limit_group* g, size_t share) +{ + if (share > EV_SSIZE_MAX) + return -1; + + g->configured_min_share = share; + + /* Can't set share to less than the one-tick maximum. IOW, at steady + * state, at least one connection can go per tick. */ + if (share > g->rate_limit_cfg.read_rate) + share = g->rate_limit_cfg.read_rate; + if (share > g->rate_limit_cfg.write_rate) + share = g->rate_limit_cfg.write_rate; + + g->min_share = share; + return 0; +} + +void bufferevent_rate_limit_group_free(struct bufferevent_rate_limit_group* g) +{ + LOCK_GROUP(g); + EVUTIL_ASSERT(0 == g->n_members); + event_del(&g->master_refill_event); + UNLOCK_GROUP(g); + EVTHREAD_FREE_LOCK(g->lock, EVTHREAD_LOCKTYPE_RECURSIVE); + mm_free(g); +} + +int bufferevent_add_to_rate_limit_group(struct bufferevent* bev, struct bufferevent_rate_limit_group* g) +{ + int wsuspend, rsuspend; + struct bufferevent_private* bevp = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + BEV_LOCK(bev); + + if (!bevp->rate_limiting) { + struct bufferevent_rate_limit* rlim; + rlim = mm_calloc(1, sizeof(struct bufferevent_rate_limit)); + if (!rlim) { + BEV_UNLOCK(bev); + return -1; + } + event_assign(&rlim->refill_bucket_event, bev->ev_base, -1, EV_FINALIZE, bev_refill_callback_, bevp); + bevp->rate_limiting = rlim; + } + + if (bevp->rate_limiting->group == g) { + BEV_UNLOCK(bev); + return 0; + } + if (bevp->rate_limiting->group) + bufferevent_remove_from_rate_limit_group(bev); + + LOCK_GROUP(g); + bevp->rate_limiting->group = g; + ++g->n_members; + LIST_INSERT_HEAD(&g->members, bevp, rate_limiting->next_in_group); + + rsuspend = g->read_suspended; + wsuspend = g->write_suspended; + + UNLOCK_GROUP(g); + + if (rsuspend) + bufferevent_suspend_read_(bev, BEV_SUSPEND_BW_GROUP); + if (wsuspend) + bufferevent_suspend_write_(bev, BEV_SUSPEND_BW_GROUP); + + BEV_UNLOCK(bev); + return 0; +} + +int bufferevent_remove_from_rate_limit_group(struct bufferevent* bev) +{ + return bufferevent_remove_from_rate_limit_group_internal_(bev, 1); +} + +int bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent* bev, int unsuspend) +{ + struct bufferevent_private* bevp = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + BEV_LOCK(bev); + if (bevp->rate_limiting && bevp->rate_limiting->group) { + struct bufferevent_rate_limit_group* g = bevp->rate_limiting->group; + LOCK_GROUP(g); + bevp->rate_limiting->group = NULL; + --g->n_members; + LIST_REMOVE(bevp, rate_limiting->next_in_group); + UNLOCK_GROUP(g); + } + if (unsuspend) { + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW_GROUP); + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW_GROUP); + } + BEV_UNLOCK(bev); + return 0; +} + +/* === + * API functions to expose rate limits. + * + * Don't use these from inside Libevent; they're meant to be for use by + * the program. + * === */ + +/* Mostly you don't want to use this function from inside libevent; + * bufferevent_get_read_max_() is more likely what you want*/ +ev_ssize_t bufferevent_get_read_limit(struct bufferevent* bev) +{ + ev_ssize_t r; + struct bufferevent_private* bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + if (bevp->rate_limiting && bevp->rate_limiting->cfg) { + bufferevent_update_buckets(bevp); + r = bevp->rate_limiting->limit.read_limit; + } else { + r = EV_SSIZE_MAX; + } + BEV_UNLOCK(bev); + return r; +} + +/* Mostly you don't want to use this function from inside libevent; + * bufferevent_get_write_max_() is more likely what you want*/ +ev_ssize_t bufferevent_get_write_limit(struct bufferevent* bev) +{ + ev_ssize_t r; + struct bufferevent_private* bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + if (bevp->rate_limiting && bevp->rate_limiting->cfg) { + bufferevent_update_buckets(bevp); + r = bevp->rate_limiting->limit.write_limit; + } else { + r = EV_SSIZE_MAX; + } + BEV_UNLOCK(bev); + return r; +} + +int bufferevent_set_max_single_read(struct bufferevent* bev, size_t size) +{ + struct bufferevent_private* bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + if (size == 0 || size > EV_SSIZE_MAX) + bevp->max_single_read = MAX_SINGLE_READ_DEFAULT; + else + bevp->max_single_read = size; + BEV_UNLOCK(bev); + return 0; +} + +int bufferevent_set_max_single_write(struct bufferevent* bev, size_t size) +{ + struct bufferevent_private* bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + if (size == 0 || size > EV_SSIZE_MAX) + bevp->max_single_write = MAX_SINGLE_WRITE_DEFAULT; + else + bevp->max_single_write = size; + BEV_UNLOCK(bev); + return 0; +} + +ev_ssize_t bufferevent_get_max_single_read(struct bufferevent* bev) +{ + ev_ssize_t r; + + BEV_LOCK(bev); + r = BEV_UPCAST(bev)->max_single_read; + BEV_UNLOCK(bev); + return r; +} + +ev_ssize_t bufferevent_get_max_single_write(struct bufferevent* bev) +{ + ev_ssize_t r; + + BEV_LOCK(bev); + r = BEV_UPCAST(bev)->max_single_write; + BEV_UNLOCK(bev); + return r; +} + +ev_ssize_t bufferevent_get_max_to_read(struct bufferevent* bev) +{ + ev_ssize_t r; + BEV_LOCK(bev); + r = bufferevent_get_read_max_(BEV_UPCAST(bev)); + BEV_UNLOCK(bev); + return r; +} + +ev_ssize_t bufferevent_get_max_to_write(struct bufferevent* bev) +{ + ev_ssize_t r; + BEV_LOCK(bev); + r = bufferevent_get_write_max_(BEV_UPCAST(bev)); + BEV_UNLOCK(bev); + return r; +} + +const struct ev_token_bucket_cfg* bufferevent_get_token_bucket_cfg(const struct bufferevent* bev) +{ + struct bufferevent_private* bufev_private = BEV_UPCAST(bev); + struct ev_token_bucket_cfg* cfg; + + BEV_LOCK(bev); + + if (bufev_private->rate_limiting) { + cfg = bufev_private->rate_limiting->cfg; + } else { + cfg = NULL; + } + + BEV_UNLOCK(bev); + + return cfg; +} + +/* Mostly you don't want to use this function from inside libevent; + * bufferevent_get_read_max_() is more likely what you want*/ +ev_ssize_t bufferevent_rate_limit_group_get_read_limit(struct bufferevent_rate_limit_group* grp) +{ + ev_ssize_t r; + LOCK_GROUP(grp); + r = grp->rate_limit.read_limit; + UNLOCK_GROUP(grp); + return r; +} + +/* Mostly you don't want to use this function from inside libevent; + * bufferevent_get_write_max_() is more likely what you want. */ +ev_ssize_t bufferevent_rate_limit_group_get_write_limit(struct bufferevent_rate_limit_group* grp) +{ + ev_ssize_t r; + LOCK_GROUP(grp); + r = grp->rate_limit.write_limit; + UNLOCK_GROUP(grp); + return r; +} + +int bufferevent_decrement_read_limit(struct bufferevent* bev, ev_ssize_t decr) +{ + int r = 0; + ev_ssize_t old_limit, new_limit; + struct bufferevent_private* bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + EVUTIL_ASSERT(bevp->rate_limiting && bevp->rate_limiting->cfg); + old_limit = bevp->rate_limiting->limit.read_limit; + + new_limit = (bevp->rate_limiting->limit.read_limit -= decr); + if (old_limit > 0 && new_limit <= 0) { + bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); + if (event_add(&bevp->rate_limiting->refill_bucket_event, &bevp->rate_limiting->cfg->tick_timeout) < 0) + r = -1; + } else if (old_limit <= 0 && new_limit > 0) { + if (!(bevp->write_suspended & BEV_SUSPEND_BW)) + event_del(&bevp->rate_limiting->refill_bucket_event); + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); + } + + BEV_UNLOCK(bev); + return r; +} + +int bufferevent_decrement_write_limit(struct bufferevent* bev, ev_ssize_t decr) +{ + /* XXXX this is mostly copy-and-paste from + * bufferevent_decrement_read_limit */ + int r = 0; + ev_ssize_t old_limit, new_limit; + struct bufferevent_private* bevp; + BEV_LOCK(bev); + bevp = BEV_UPCAST(bev); + EVUTIL_ASSERT(bevp->rate_limiting && bevp->rate_limiting->cfg); + old_limit = bevp->rate_limiting->limit.write_limit; + + new_limit = (bevp->rate_limiting->limit.write_limit -= decr); + if (old_limit > 0 && new_limit <= 0) { + bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); + if (event_add(&bevp->rate_limiting->refill_bucket_event, &bevp->rate_limiting->cfg->tick_timeout) < 0) + r = -1; + } else if (old_limit <= 0 && new_limit > 0) { + if (!(bevp->read_suspended & BEV_SUSPEND_BW)) + event_del(&bevp->rate_limiting->refill_bucket_event); + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); + } + + BEV_UNLOCK(bev); + return r; +} + +int bufferevent_rate_limit_group_decrement_read(struct bufferevent_rate_limit_group* grp, ev_ssize_t decr) +{ + int r = 0; + ev_ssize_t old_limit, new_limit; + LOCK_GROUP(grp); + old_limit = grp->rate_limit.read_limit; + new_limit = (grp->rate_limit.read_limit -= decr); + + if (old_limit > 0 && new_limit <= 0) { + bev_group_suspend_reading_(grp); + } else if (old_limit <= 0 && new_limit > 0) { + bev_group_unsuspend_reading_(grp); + } + + UNLOCK_GROUP(grp); + return r; +} + +int bufferevent_rate_limit_group_decrement_write(struct bufferevent_rate_limit_group* grp, ev_ssize_t decr) +{ + int r = 0; + ev_ssize_t old_limit, new_limit; + LOCK_GROUP(grp); + old_limit = grp->rate_limit.write_limit; + new_limit = (grp->rate_limit.write_limit -= decr); + + if (old_limit > 0 && new_limit <= 0) { + bev_group_suspend_writing_(grp); + } else if (old_limit <= 0 && new_limit > 0) { + bev_group_unsuspend_writing_(grp); + } + + UNLOCK_GROUP(grp); + return r; +} + +void bufferevent_rate_limit_group_get_totals(struct bufferevent_rate_limit_group* grp, ev_uint64_t* total_read_out, ev_uint64_t* total_written_out) +{ + EVUTIL_ASSERT(grp != NULL); + if (total_read_out) + *total_read_out = grp->total_read; + if (total_written_out) + *total_written_out = grp->total_written; +} + +void bufferevent_rate_limit_group_reset_totals(struct bufferevent_rate_limit_group* grp) +{ + grp->total_read = grp->total_written = 0; +} + +int bufferevent_ratelim_init_(struct bufferevent_private* bev) +{ + bev->rate_limiting = NULL; + bev->max_single_read = MAX_SINGLE_READ_DEFAULT; + bev->max_single_write = MAX_SINGLE_WRITE_DEFAULT; + + return 0; +} diff --git a/asynio/event/bufferevent_sock.c b/asynio/event/bufferevent_sock.c new file mode 100644 index 0000000000000000000000000000000000000000..940376ddf394ae1eddeb169ab3be7cad7002a1d0 --- /dev/null +++ b/asynio/event/bufferevent_sock.c @@ -0,0 +1,646 @@ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * Copyright (c) 2002-2006 Niels Provos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#include + +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +#include +#include +#include +#include +#ifdef EVENT__HAVE_STDARG_H +#include +#endif +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif + +#ifdef _WIN32 +#include +#include +#endif + +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif +#ifdef EVENT__HAVE_NETINET_IN_H +#include +#endif +#ifdef EVENT__HAVE_NETINET_IN6_H +#include +#endif + +#include "util.h" +#include "bufferevent.h" +#include "buffer.h" +#include "bufferevent_struct.h" +#include "bufferevent_compat.h" +#include "eventbase.h" + +#include "evconfig-internal.h" + +/* prototypes */ +static int be_socket_enable(struct bufferevent*, short); +static int be_socket_disable(struct bufferevent*, short); +static void be_socket_destruct(struct bufferevent*); +static int be_socket_flush(struct bufferevent*, short, enum bufferevent_flush_mode); +static int be_socket_ctrl(struct bufferevent*, enum bufferevent_ctrl_op, union bufferevent_ctrl_data*); + +static void be_socket_setfd(struct bufferevent*, evutil_socket_t); + +const struct bufferevent_ops bufferevent_ops_socket = { + "socket", evutil_offsetof(struct bufferevent_private, bev), be_socket_enable, be_socket_disable, NULL, /* unlink */ + be_socket_destruct, bufferevent_generic_adj_existing_timeouts_, be_socket_flush, be_socket_ctrl, +}; + +const struct sockaddr* bufferevent_socket_get_conn_address_(struct bufferevent* bev) +{ + struct bufferevent_private* bev_p = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + + return (struct sockaddr*)&bev_p->conn_address; +} +static void bufferevent_socket_set_conn_address_fd(struct bufferevent_private* bev_p, int fd) +{ + socklen_t len = sizeof(bev_p->conn_address); + + struct sockaddr* addr = (struct sockaddr*)&bev_p->conn_address; + if (addr->sa_family != AF_UNSPEC) + getpeername(fd, addr, &len); +} +static void bufferevent_socket_set_conn_address(struct bufferevent_private* bev_p, struct sockaddr* addr, size_t addrlen) +{ + EVUTIL_ASSERT(addrlen <= sizeof(bev_p->conn_address)); + memcpy(&bev_p->conn_address, addr, addrlen); +} + +static void bufferevent_socket_outbuf_cb(struct evbuffer* buf, const struct evbuffer_cb_info* cbinfo, void* arg) +{ + struct bufferevent* bufev = arg; + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + + if (cbinfo->n_added && (bufev->enabled & EV_WRITE) && !event_pending(&bufev->ev_write, EV_WRITE, NULL) && !bufev_p->write_suspended) { + /* Somebody added data to the buffer, and we would like to + * write, and we were not writing. So, start writing. */ + if (bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) { + /* Should we log this? */ + } + } +} + +static void bufferevent_readcb(evutil_socket_t fd, short event, void* arg) +{ + struct bufferevent* bufev = arg; + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + struct evbuffer* input; + int res = 0; + short what = BEV_EVENT_READING; + ev_ssize_t howmuch = -1, readmax = -1; + + bufferevent_incref_and_lock_(bufev); + + if (event == EV_TIMEOUT) { + /* Note that we only check for event==EV_TIMEOUT. If + * event==EV_TIMEOUT|EV_READ, we can safely ignore the + * timeout, since a read has occurred */ + what |= BEV_EVENT_TIMEOUT; + goto error; + } + + input = bufev->input; + + /* + * If we have a high watermark configured then we don't want to + * read more data than would make us reach the watermark. + */ + if (bufev->wm_read.high != 0) { + howmuch = bufev->wm_read.high - evbuffer_get_length(input); + /* we somehow lowered the watermark, stop reading */ + if (howmuch <= 0) { + bufferevent_wm_suspend_read(bufev); + goto done; + } + } + readmax = bufferevent_get_read_max_(bufev_p); + if (howmuch < 0 || howmuch > readmax) /* The use of -1 for "unlimited" + * uglifies this code. XXXX */ + howmuch = readmax; + if (bufev_p->read_suspended) + goto done; + + evbuffer_unfreeze(input, 0); + res = evbuffer_read(input, fd, (int)howmuch); /* XXXX evbuffer_read would do better to take and return ev_ssize_t */ + evbuffer_freeze(input, 0); + + if (res == -1) { + int err = evutil_socket_geterror(fd); + if (EVUTIL_ERR_RW_RETRIABLE(err)) + goto reschedule; + if (EVUTIL_ERR_CONNECT_REFUSED(err)) { + bufev_p->connection_refused = 1; + goto done; + } + /* error case */ + what |= BEV_EVENT_ERROR; + } else if (res == 0) { + /* eof case */ + what |= BEV_EVENT_EOF; + } + + if (res <= 0) + goto error; + + bufferevent_decrement_read_buckets_(bufev_p, res); + + /* Invoke the user callback - must always be called last */ + bufferevent_trigger_nolock_(bufev, EV_READ, 0); + + goto done; + +reschedule: + goto done; + +error: + bufferevent_disable(bufev, EV_READ); + bufferevent_run_eventcb_(bufev, what, 0); + +done: + bufferevent_decref_and_unlock_(bufev); +} + +static void bufferevent_writecb(evutil_socket_t fd, short event, void* arg) +{ + struct bufferevent* bufev = arg; + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + int res = 0; + short what = BEV_EVENT_WRITING; + int connected = 0; + ev_ssize_t atmost = -1; + + bufferevent_incref_and_lock_(bufev); + + if (event == EV_TIMEOUT) { + /* Note that we only check for event==EV_TIMEOUT. If + * event==EV_TIMEOUT|EV_WRITE, we can safely ignore the + * timeout, since a read has occurred */ + what |= BEV_EVENT_TIMEOUT; + goto error; + } + if (bufev_p->connecting) { + int c = evutil_socket_finished_connecting_(fd); + /* we need to fake the error if the connection was refused + * immediately - usually connection to localhost on BSD */ + if (bufev_p->connection_refused) { + bufev_p->connection_refused = 0; + c = -1; + } + + if (c == 0) + goto done; + + bufev_p->connecting = 0; + if (c < 0) { + event_del(&bufev->ev_write); + event_del(&bufev->ev_read); + bufferevent_run_eventcb_(bufev, BEV_EVENT_ERROR, 0); + goto done; + } else { + connected = 1; + bufferevent_socket_set_conn_address_fd(bufev_p, fd); +#ifdef _WIN32 + if (BEV_IS_ASYNC(bufev)) { + event_del(&bufev->ev_write); + bufferevent_async_set_connected_(bufev); + bufferevent_run_eventcb_(bufev, BEV_EVENT_CONNECTED, 0); + goto done; + } +#endif + bufferevent_run_eventcb_(bufev, BEV_EVENT_CONNECTED, 0); + if (!(bufev->enabled & EV_WRITE) || bufev_p->write_suspended) { + event_del(&bufev->ev_write); + goto done; + } + } + } + + atmost = bufferevent_get_write_max_(bufev_p); + + if (bufev_p->write_suspended) + goto done; + + if (evbuffer_get_length(bufev->output)) { + evbuffer_unfreeze(bufev->output, 1); + res = evbuffer_write_atmost(bufev->output, fd, atmost); + evbuffer_freeze(bufev->output, 1); + if (res == -1) { + int err = evutil_socket_geterror(fd); + if (EVUTIL_ERR_RW_RETRIABLE(err)) + goto reschedule; + what |= BEV_EVENT_ERROR; + } else if (res == 0) { + /* eof case + XXXX Actually, a 0 on write doesn't indicate + an EOF. An ECONNRESET might be more typical. + */ + what |= BEV_EVENT_EOF; + } + if (res <= 0) + goto error; + + bufferevent_decrement_write_buckets_(bufev_p, res); + } + + if (evbuffer_get_length(bufev->output) == 0) { + event_del(&bufev->ev_write); + } + + /* + * Invoke the user callback if our buffer is drained or below the + * low watermark. + */ + if (res || !connected) { + bufferevent_trigger_nolock_(bufev, EV_WRITE, 0); + } + + goto done; + +reschedule: + if (evbuffer_get_length(bufev->output) == 0) { + event_del(&bufev->ev_write); + } + goto done; + +error: + bufferevent_disable(bufev, EV_WRITE); + bufferevent_run_eventcb_(bufev, what, 0); + +done: + bufferevent_decref_and_unlock_(bufev); +} + +struct bufferevent* bufferevent_socket_new(struct event_base* base, evutil_socket_t fd, int options) +{ + struct bufferevent_private* bufev_p; + struct bufferevent* bufev; + +#ifdef _WIN32 + if (base && event_base_get_iocp_(base)) + return bufferevent_async_new_(base, fd, options); +#endif + + if ((bufev_p = mm_calloc(1, sizeof(struct bufferevent_private))) == NULL) + return NULL; + + if (bufferevent_init_common_(bufev_p, base, &bufferevent_ops_socket, options) < 0) { + mm_free(bufev_p); + return NULL; + } + bufev = &bufev_p->bev; + evbuffer_set_flags(bufev->output, EVBUFFER_FLAG_DRAINS_TO_FD); + + event_assign(&bufev->ev_read, bufev->ev_base, fd, EV_READ | EV_PERSIST | EV_FINALIZE, bufferevent_readcb, bufev); + event_assign(&bufev->ev_write, bufev->ev_base, fd, EV_WRITE | EV_PERSIST | EV_FINALIZE, bufferevent_writecb, bufev); + + evbuffer_add_cb(bufev->output, bufferevent_socket_outbuf_cb, bufev); + + evbuffer_freeze(bufev->input, 0); + evbuffer_freeze(bufev->output, 1); + + return bufev; +} + +int bufferevent_socket_connect(struct bufferevent* bev, const struct sockaddr* sa, int socklen) +{ + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + + evutil_socket_t fd; + int r = 0; + int result = -1; + int ownfd = 0; + + bufferevent_incref_and_lock_(bev); + + if (!bufev_p) + goto done; + + fd = bufferevent_getfd(bev); + if (fd < 0) { + if (!sa) + goto done; + fd = evutil_socket_(sa->sa_family, SOCK_STREAM | EVUTIL_SOCK_NONBLOCK, 0); + if (fd < 0) + goto done; + ownfd = 1; + } + if (sa) { +#ifdef _WIN32 + if (bufferevent_async_can_connect_(bev)) { + bufferevent_setfd(bev, fd); + r = bufferevent_async_connect_(bev, fd, sa, socklen); + if (r < 0) + goto freesock; + bufev_p->connecting = 1; + result = 0; + goto done; + } else +#endif + r = evutil_socket_connect_(&fd, sa, socklen); + if (r < 0) + goto freesock; + } +#ifdef _WIN32 + /* ConnectEx() isn't always around, even when IOCP is enabled. + * Here, we borrow the socket object's write handler to fall back + * on a non-blocking connect() when ConnectEx() is unavailable. */ + if (BEV_IS_ASYNC(bev)) { + event_assign(&bev->ev_write, bev->ev_base, fd, EV_WRITE | EV_PERSIST | EV_FINALIZE, bufferevent_writecb, bev); + } +#endif + bufferevent_setfd(bev, fd); + if (r == 0) { + if (!be_socket_enable(bev, EV_WRITE)) { + bufev_p->connecting = 1; + result = 0; + goto done; + } + } else if (r == 1) { + /* The connect succeeded already. How very BSD of it. */ + result = 0; + bufev_p->connecting = 1; + bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS); + } else { + /* The connect failed already. How very BSD of it. */ + result = 0; + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, BEV_OPT_DEFER_CALLBACKS); + bufferevent_disable(bev, EV_WRITE | EV_READ); + } + + goto done; + +freesock: + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); + if (ownfd) + evutil_closesocket(fd); + /* do something about the error? */ +done: + bufferevent_decref_and_unlock_(bev); + return result; +} + +static void bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo* ai, void* arg) +{ + struct bufferevent* bev = arg; + struct bufferevent_private* bev_p = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + int r; + BEV_LOCK(bev); + + bufferevent_unsuspend_write_(bev, BEV_SUSPEND_LOOKUP); + bufferevent_unsuspend_read_(bev, BEV_SUSPEND_LOOKUP); + + bev_p->dns_request = NULL; + + if (result == EVUTIL_EAI_CANCEL) { + bev_p->dns_error = result; + bufferevent_decref_and_unlock_(bev); + return; + } + if (result != 0) { + bev_p->dns_error = result; + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); + bufferevent_decref_and_unlock_(bev); + if (ai) + evutil_freeaddrinfo(ai); + return; + } + + /* XXX use the other addrinfos? */ + /* XXX use this return value */ + bufferevent_socket_set_conn_address(bev_p, ai->ai_addr, (int)ai->ai_addrlen); + r = bufferevent_socket_connect(bev, ai->ai_addr, (int)ai->ai_addrlen); + (void)r; + bufferevent_decref_and_unlock_(bev); + evutil_freeaddrinfo(ai); +} + +int bufferevent_socket_connect_hostname(struct bufferevent* bev, struct evdns_base* evdns_base, int family, const char* hostname, int port) +{ + char portbuf[10]; + struct evutil_addrinfo hint; + struct bufferevent_private* bev_p = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + + if (family != AF_INET && family != AF_INET6 && family != AF_UNSPEC) + return -1; + if (port < 1 || port > 65535) + return -1; + + memset(&hint, 0, sizeof(hint)); + hint.ai_family = family; + hint.ai_protocol = IPPROTO_TCP; + hint.ai_socktype = SOCK_STREAM; + + evutil_snprintf(portbuf, sizeof(portbuf), "%d", port); + + BEV_LOCK(bev); + bev_p->dns_error = 0; + + bufferevent_suspend_write_(bev, BEV_SUSPEND_LOOKUP); + bufferevent_suspend_read_(bev, BEV_SUSPEND_LOOKUP); + + bufferevent_incref_(bev); + bev_p->dns_request = evutil_getaddrinfo_async_(evdns_base, hostname, portbuf, &hint, bufferevent_connect_getaddrinfo_cb, bev); + BEV_UNLOCK(bev); + + return 0; +} + +int bufferevent_socket_get_dns_error(struct bufferevent* bev) +{ + int rv; + struct bufferevent_private* bev_p = EVUTIL_UPCAST(bev, struct bufferevent_private, bev); + + BEV_LOCK(bev); + rv = bev_p->dns_error; + BEV_UNLOCK(bev); + + return rv; +} + +/* + * Create a new buffered event object. + * + * The read callback is invoked whenever we read new data. + * The write callback is invoked whenever the output buffer is drained. + * The error callback is invoked on a write/read error or on EOF. + * + * Both read and write callbacks maybe NULL. The error callback is not + * allowed to be NULL and have to be provided always. + */ + +struct bufferevent* + bufferevent_new(evutil_socket_t fd, bufferevent_data_cb readcb, bufferevent_data_cb writecb, bufferevent_event_cb eventcb, void* cbarg) +{ + struct bufferevent* bufev; + + if (!(bufev = bufferevent_socket_new(NULL, fd, 0))) + return NULL; + + bufferevent_setcb(bufev, readcb, writecb, eventcb, cbarg); + + return bufev; +} + +static int be_socket_enable(struct bufferevent* bufev, short event) +{ + if (event & EV_READ && bufferevent_add_event_(&bufev->ev_read, &bufev->timeout_read) == -1) + return -1; + if (event & EV_WRITE && bufferevent_add_event_(&bufev->ev_write, &bufev->timeout_write) == -1) + return -1; + return 0; +} + +static int be_socket_disable(struct bufferevent* bufev, short event) +{ + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + if (event & EV_READ) { + if (event_del(&bufev->ev_read) == -1) + return -1; + } + /* Don't actually disable the write if we are trying to connect. */ + if ((event & EV_WRITE) && !bufev_p->connecting) { + if (event_del(&bufev->ev_write) == -1) + return -1; + } + return 0; +} + +static void be_socket_destruct(struct bufferevent* bufev) +{ + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + evutil_socket_t fd; + EVUTIL_ASSERT(bufev->be_ops == &bufferevent_ops_socket); + + fd = event_get_fd(&bufev->ev_read); + + if ((bufev_p->options & BEV_OPT_CLOSE_ON_FREE) && fd >= 0) + EVUTIL_CLOSESOCKET(fd); + + evutil_getaddrinfo_cancel_async_(bufev_p->dns_request); +} + +static int be_socket_flush(struct bufferevent* bev, short iotype, enum bufferevent_flush_mode mode) +{ + return 0; +} + +static void be_socket_setfd(struct bufferevent* bufev, evutil_socket_t fd) +{ + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + + BEV_LOCK(bufev); + EVUTIL_ASSERT(bufev->be_ops == &bufferevent_ops_socket); + + event_del(&bufev->ev_read); + event_del(&bufev->ev_write); + + evbuffer_unfreeze(bufev->input, 0); + evbuffer_unfreeze(bufev->output, 1); + + event_assign(&bufev->ev_read, bufev->ev_base, fd, EV_READ | EV_PERSIST | EV_FINALIZE, bufferevent_readcb, bufev); + event_assign(&bufev->ev_write, bufev->ev_base, fd, EV_WRITE | EV_PERSIST | EV_FINALIZE, bufferevent_writecb, bufev); + + if (fd >= 0) + bufferevent_enable(bufev, bufev->enabled); + + evutil_getaddrinfo_cancel_async_(bufev_p->dns_request); + + BEV_UNLOCK(bufev); +} + +/* XXXX Should non-socket bufferevents support this? */ +int bufferevent_priority_set(struct bufferevent* bufev, int priority) +{ + int r = -1; + struct bufferevent_private* bufev_p = EVUTIL_UPCAST(bufev, struct bufferevent_private, bev); + + BEV_LOCK(bufev); + if (bufev->be_ops != &bufferevent_ops_socket) + goto done; + + if (event_priority_set(&bufev->ev_read, priority) == -1) + goto done; + if (event_priority_set(&bufev->ev_write, priority) == -1) + goto done; + + event_deferred_cb_set_priority_(&bufev_p->deferred, priority); + + r = 0; +done: + BEV_UNLOCK(bufev); + return r; +} + +/* XXXX Should non-socket bufferevents support this? */ +int bufferevent_base_set(struct event_base* base, struct bufferevent* bufev) +{ + int res = -1; + + BEV_LOCK(bufev); + if (bufev->be_ops != &bufferevent_ops_socket) + goto done; + + bufev->ev_base = base; + + res = event_base_set(base, &bufev->ev_read); + if (res == -1) + goto done; + + res = event_base_set(base, &bufev->ev_write); +done: + BEV_UNLOCK(bufev); + return res; +} + +static int be_socket_ctrl(struct bufferevent* bev, enum bufferevent_ctrl_op op, union bufferevent_ctrl_data* data) +{ + switch (op) { + case BEV_CTRL_SET_FD: + be_socket_setfd(bev, data->fd); + return 0; + case BEV_CTRL_GET_FD: + data->fd = event_get_fd(&bev->ev_read); + return 0; + case BEV_CTRL_GET_UNDERLYING: + case BEV_CTRL_CANCEL_ALL: + default: + return -1; + } +} diff --git a/asynio/event/bufferevent_ssl.c b/asynio/event/bufferevent_ssl.c new file mode 100644 index 0000000000000000000000000000000000000000..76aaf160eb5658db9689d6549740c7423d2d871f --- /dev/null +++ b/asynio/event/bufferevent_ssl.c @@ -0,0 +1,1153 @@ +/* + * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Get rid of OSX 10.7 and greater deprecation warnings. +#if defined(__APPLE__) && defined(__clang__) +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif + +#include "evconfig.h" + +#include + +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +#include +#include +#include +#include +#ifdef EVENT__HAVE_STDARG_H +#include +#endif +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif + +#ifdef _WIN32 +#include +#endif + +#include "bufferevent.h" +#include "bufferevent_struct.h" +#include "bufferevent_ssl.h" +#include "buffer.h" +#include "event.h" + +#include "mm-internal.h" +#include "bufferevent-internal.h" +#include "log-internal.h" +#include "ssl-compat.h" + +/* -------------------- + Now, here's the OpenSSL-based implementation of bufferevent. + + The implementation comes in two flavors: one that connects its SSL object + to an underlying bufferevent using a BIO_bufferevent, and one that has the + SSL object connect to a socket directly. The latter should generally be + faster, except on Windows, where your best bet is using a + bufferevent_async. + + (OpenSSL supports many other BIO types, too. But we can't use any unless + we have a good way to get notified when they become readable/writable.) + -------------------- */ + + +static int be_ssl_enable(struct bufferevent *, short); +static int be_ssl_disable(struct bufferevent *, short); +static void be_ssl_unlink(struct bufferevent *); +static void be_ssl_destruct(struct bufferevent *); +static int be_ssl_adj_timeouts(struct bufferevent *); +static int be_ssl_flush(struct bufferevent *bufev, + short iotype, enum bufferevent_flush_mode mode); +static int be_ssl_ctrl(struct bufferevent *, enum bufferevent_ctrl_op, union bufferevent_ctrl_data *); + +const struct bufferevent_ops bufferevent_ops_ssl = { + "ssl", + evutil_offsetof(struct bufferevent_ssl, bev.bev), + be_ssl_enable, + be_ssl_disable, + be_ssl_unlink, + be_ssl_destruct, + be_ssl_adj_timeouts, + be_ssl_flush, + be_ssl_ctrl, +}; + +/* Given a bufferevent, return a pointer to the bufferevent_ssl that + * contains it, if any. */ +struct bufferevent_ssl * +bufferevent_ssl_upcast(struct bufferevent *bev) +{ + struct bufferevent_ssl *bev_o; + if (!BEV_IS_SSL(bev)) + return NULL; + bev_o = (void*)( ((char*)bev) - + evutil_offsetof(struct bufferevent_ssl, bev.bev)); + EVUTIL_ASSERT(BEV_IS_SSL(&bev_o->bev.bev)); + return bev_o; +} + +void +bufferevent_ssl_put_error(struct bufferevent_ssl *bev_ssl, unsigned long err) +{ + if (bev_ssl->n_errors == NUM_ERRORS) + return; + /* The error type according to openssl is "unsigned long", but + openssl never uses more than 32 bits of it. It _can't_ use more + than 32 bits of it, since it needs to report errors on systems + where long is only 32 bits. + */ + bev_ssl->errors[bev_ssl->n_errors++] = (ev_uint32_t) err; +} + +/* Have the base communications channel (either the underlying bufferevent or + * ev_read and ev_write) start reading. Take the read-blocked-on-write flag + * into account. */ +static int +start_reading(struct bufferevent_ssl *bev_ssl) +{ + if (bev_ssl->underlying) { + bufferevent_unsuspend_read_(bev_ssl->underlying, + BEV_SUSPEND_FILT_READ); + return 0; + } else { + struct bufferevent *bev = &bev_ssl->bev.bev; + int r; + r = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); + if (r == 0 && bev_ssl->read_blocked_on_write) + r = bufferevent_add_event_(&bev->ev_write, + &bev->timeout_write); + return r; + } +} + +/* Have the base communications channel (either the underlying bufferevent or + * ev_read and ev_write) start writing. Take the write-blocked-on-read flag + * into account. */ +static int +start_writing(struct bufferevent_ssl *bev_ssl) +{ + int r = 0; + if (bev_ssl->underlying) { + if (bev_ssl->write_blocked_on_read) { + bufferevent_unsuspend_read_(bev_ssl->underlying, + BEV_SUSPEND_FILT_READ); + } + } else { + struct bufferevent *bev = &bev_ssl->bev.bev; + r = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); + if (!r && bev_ssl->write_blocked_on_read) + r = bufferevent_add_event_(&bev->ev_read, + &bev->timeout_read); + } + return r; +} + +void +bufferevent_ssl_stop_reading(struct bufferevent_ssl *bev_ssl) +{ + if (bev_ssl->write_blocked_on_read) + return; + if (bev_ssl->underlying) { + bufferevent_suspend_read_(bev_ssl->underlying, + BEV_SUSPEND_FILT_READ); + } else { + struct bufferevent *bev = &bev_ssl->bev.bev; + event_del(&bev->ev_read); + } +} + +void +bufferevent_ssl_stop_writing(struct bufferevent_ssl *bev_ssl) +{ + if (bev_ssl->read_blocked_on_write) + return; + if (bev_ssl->underlying) { + bufferevent_unsuspend_read_(bev_ssl->underlying, + BEV_SUSPEND_FILT_READ); + } else { + struct bufferevent *bev = &bev_ssl->bev.bev; + event_del(&bev->ev_write); + } +} + +static int +set_rbow(struct bufferevent_ssl *bev_ssl) +{ + if (!bev_ssl->underlying) + bufferevent_ssl_stop_reading(bev_ssl); + bev_ssl->read_blocked_on_write = 1; + return start_writing(bev_ssl); +} + +static int +set_wbor(struct bufferevent_ssl *bev_ssl) +{ + if (!bev_ssl->underlying) + bufferevent_ssl_stop_writing(bev_ssl); + bev_ssl->write_blocked_on_read = 1; + return start_reading(bev_ssl); +} + +static int +clear_rbow(struct bufferevent_ssl *bev_ssl) +{ + struct bufferevent *bev = &bev_ssl->bev.bev; + int r = 0; + bev_ssl->read_blocked_on_write = 0; + if (!(bev->enabled & EV_WRITE)) + bufferevent_ssl_stop_writing(bev_ssl); + if (bev->enabled & EV_READ) + r = start_reading(bev_ssl); + return r; +} + + +static int +clear_wbor(struct bufferevent_ssl *bev_ssl) +{ + struct bufferevent *bev = &bev_ssl->bev.bev; + int r = 0; + bev_ssl->write_blocked_on_read = 0; + if (!(bev->enabled & EV_READ)) + bufferevent_ssl_stop_reading(bev_ssl); + if (bev->enabled & EV_WRITE) + r = start_writing(bev_ssl); + return r; +} + +#define OP_MADE_PROGRESS 1 +#define OP_BLOCKED 2 +#define OP_ERR 4 + +/* Return a bitmask of OP_MADE_PROGRESS (if we read anything); OP_BLOCKED (if + we're now blocked); and OP_ERR (if an error occurred). */ +static int +do_read(struct bufferevent_ssl *bev_ssl, int n_to_read) { + /* Requires lock */ + struct bufferevent *bev = &bev_ssl->bev.bev; + struct evbuffer *input = bev->input; + int r, n, i, n_used = 0, atmost; + struct evbuffer_iovec space[2]; + int result = 0; + + if (bev_ssl->bev.read_suspended) + return 0; + + atmost = bufferevent_get_read_max_(&bev_ssl->bev); + if (n_to_read > atmost) + n_to_read = atmost; + + n = evbuffer_reserve_space(input, n_to_read, space, 2); + if (n < 0) + return OP_ERR; + + for (i=0; ibev.read_suspended) + break; + bev_ssl->ssl_ops->clear_error(); + r = bev_ssl->ssl_ops->read(bev_ssl->ssl, space[i].iov_base, space[i].iov_len); + if (r>0) { + result |= OP_MADE_PROGRESS; + if (bev_ssl->read_blocked_on_write) + if (clear_rbow(bev_ssl) < 0) + return OP_ERR | result; + ++n_used; + space[i].iov_len = r; + bev_ssl->ssl_ops->decrement_buckets(bev_ssl); + } else { + int err = bev_ssl->ssl_ops->get_error(bev_ssl->ssl, r); + bev_ssl->ssl_ops->print_err(err); + if (bev_ssl->ssl_ops->err_is_want_read(err)) { + /* Can't read until underlying has more data. */ + if (bev_ssl->read_blocked_on_write) + if (clear_rbow(bev_ssl) < 0) + return OP_ERR | result; + } else if(bev_ssl->ssl_ops->err_is_want_write(err)) { + /* This read operation requires a write, and the + * underlying is full */ + if (!bev_ssl->read_blocked_on_write) + if (set_rbow(bev_ssl) < 0) + return OP_ERR | result; + } else { + bev_ssl->ssl_ops->conn_closed(bev_ssl, BEV_EVENT_READING, err, r); + } + result |= OP_BLOCKED; + break; /* out of the loop */ + } + } + + if (n_used) { + evbuffer_commit_space(input, space, n_used); + if (bev_ssl->underlying) + BEV_RESET_GENERIC_READ_TIMEOUT(bev); + } + + return result; +} + +/* Return a bitmask of OP_MADE_PROGRESS (if we wrote anything); OP_BLOCKED (if + we're now blocked); and OP_ERR (if an error occurred). */ +static int +do_write(struct bufferevent_ssl *bev_ssl, int atmost) +{ + int i, r, n, n_written = 0; + struct bufferevent *bev = &bev_ssl->bev.bev; + struct evbuffer *output = bev->output; + struct evbuffer_iovec space[8]; + int result = 0; + + if (bev_ssl->last_write > 0) + atmost = bev_ssl->last_write; + else + atmost = bufferevent_get_write_max_(&bev_ssl->bev); + + if (bev_ssl->flags & BUFFEREVENT_SSL_BATCH_WRITE) { + /* Try to send as many as we can to avoid Nagle effect */ + evbuffer_pullup(output, -1); + } + + n = evbuffer_peek(output, atmost, NULL, space, 8); + if (n < 0) + return OP_ERR | result; + + if (n > 8) + n = 8; + for (i=0; i < n; ++i) { + if (bev_ssl->bev.write_suspended) + break; + + /* SSL_write will (reasonably) return 0 if we tell it to + send 0 data. Skip this case so we don't interpret the + result as an error */ + if (space[i].iov_len == 0) + continue; + + bev_ssl->ssl_ops->clear_error(); + r = bev_ssl->ssl_ops->write(bev_ssl->ssl, space[i].iov_base, + space[i].iov_len); + if (r > 0) { + result |= OP_MADE_PROGRESS; + if (bev_ssl->write_blocked_on_read) + if (clear_wbor(bev_ssl) < 0) + return OP_ERR | result; + n_written += r; + bev_ssl->last_write = -1; + bev_ssl->ssl_ops->decrement_buckets(bev_ssl); + } else { + int err = bev_ssl->ssl_ops->get_error(bev_ssl->ssl, r); + bev_ssl->ssl_ops->print_err(err); + if (bev_ssl->ssl_ops->err_is_want_write(err)) { + /* Can't read until underlying has more data. */ + if (bev_ssl->write_blocked_on_read) + if (clear_wbor(bev_ssl) < 0) + return OP_ERR | result; + bev_ssl->last_write = space[i].iov_len; + } else if (bev_ssl->ssl_ops->err_is_want_read(err)) { + /* This read operation requires a write, and the + * underlying is full */ + if (!bev_ssl->write_blocked_on_read) + if (set_wbor(bev_ssl) < 0) + return OP_ERR | result; + bev_ssl->last_write = space[i].iov_len; + } else { + bev_ssl->ssl_ops->conn_closed(bev_ssl, BEV_EVENT_WRITING, err, r); + bev_ssl->last_write = -1; + } + result |= OP_BLOCKED; + break; + } + } + if (n_written) { + if (evbuffer_drain(output, n_written)) + return OP_ERR | result; + + if (bev_ssl->underlying) + BEV_RESET_GENERIC_WRITE_TIMEOUT(bev); + + bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS); + } + return result; +} + +#define WRITE_FRAME 15000 + +#define READ_DEFAULT 4096 + +/* Try to figure out how many bytes to read; return 0 if we shouldn't be + * reading. */ +static int +bytes_to_read(struct bufferevent_ssl *bev) +{ + struct evbuffer *input = bev->bev.bev.input; + struct event_watermark *wm = &bev->bev.bev.wm_read; + int result = READ_DEFAULT; + ev_ssize_t limit; + /* XXX 99% of this is generic code that nearly all bufferevents will + * want. */ + + if (bev->write_blocked_on_read) { + return 0; + } + + if (! (bev->bev.bev.enabled & EV_READ)) { + return 0; + } + + if (bev->bev.read_suspended) { + return 0; + } + + if (wm->high) { + if (evbuffer_get_length(input) >= wm->high) { + return 0; + } + + result = wm->high - evbuffer_get_length(input); + } else { + result = READ_DEFAULT; + } + + /* Respect the rate limit */ + limit = bufferevent_get_read_max_(&bev->bev); + if (result > limit) { + result = limit; + } + + return result; +} + + +/* Things look readable. If write is blocked on read, write till it isn't. + * Read from the underlying buffer until we block or we hit our high-water + * mark. + */ +static void +consider_reading(struct bufferevent_ssl *bev_ssl) +{ + int r; + int n_to_read; + int all_result_flags = 0; + + while (bev_ssl->write_blocked_on_read) { + r = do_write(bev_ssl, WRITE_FRAME); + if (r & (OP_BLOCKED|OP_ERR)) + break; + } + if (bev_ssl->write_blocked_on_read) + return; + + n_to_read = bytes_to_read(bev_ssl); + + while (n_to_read) { + r = do_read(bev_ssl, n_to_read); + all_result_flags |= r; + + if (r & (OP_BLOCKED|OP_ERR)) + break; + + if (bev_ssl->bev.read_suspended) + break; + + /* Read all pending data. This won't hit the network + * again, and will (most importantly) put us in a state + * where we don't need to read anything else until the + * socket is readable again. It'll potentially make us + * overrun our read high-watermark (somewhat + * regrettable). The damage to the rate-limit has + * already been done, since OpenSSL went and read a + * whole SSL record anyway. */ + n_to_read = bev_ssl->ssl_ops->pending(bev_ssl->ssl); + + /* XXX This if statement is actually a bad bug, added to avoid + * XXX a worse bug. + * + * The bad bug: It can potentially cause resource unfairness + * by reading too much data from the underlying bufferevent; + * it can potentially cause read looping if the underlying + * bufferevent is a bufferevent_pair and deferred callbacks + * aren't used. + * + * The worse bug: If we didn't do this, then we would + * potentially not read any more from bev_ssl->underlying + * until more data arrived there, which could lead to us + * waiting forever. + */ + if (!n_to_read && bev_ssl->underlying) + n_to_read = bytes_to_read(bev_ssl); + } + + if (all_result_flags & OP_MADE_PROGRESS) { + struct bufferevent *bev = &bev_ssl->bev.bev; + + bufferevent_trigger_nolock_(bev, EV_READ, 0); + } + + if (!bev_ssl->underlying) { + /* Should be redundant, but let's avoid busy-looping */ + if (bev_ssl->bev.read_suspended || + !(bev_ssl->bev.bev.enabled & EV_READ)) { + event_del(&bev_ssl->bev.bev.ev_read); + } + } +} + +static void +consider_writing(struct bufferevent_ssl *bev_ssl) +{ + int r; + struct evbuffer *output = bev_ssl->bev.bev.output; + struct evbuffer *target = NULL; + struct event_watermark *wm = NULL; + + while (bev_ssl->read_blocked_on_write) { + r = do_read(bev_ssl, 1024); /* XXXX 1024 is a hack */ + if (r & OP_MADE_PROGRESS) { + struct bufferevent *bev = &bev_ssl->bev.bev; + + bufferevent_trigger_nolock_(bev, EV_READ, 0); + } + if (r & (OP_ERR|OP_BLOCKED)) + break; + } + if (bev_ssl->read_blocked_on_write) + return; + if (bev_ssl->underlying) { + target = bev_ssl->underlying->output; + wm = &bev_ssl->underlying->wm_write; + } + while ((bev_ssl->bev.bev.enabled & EV_WRITE) && + (! bev_ssl->bev.write_suspended) && + evbuffer_get_length(output) && + (!target || (! wm->high || evbuffer_get_length(target) < wm->high))) { + int n_to_write; + if (wm && wm->high) + n_to_write = wm->high - evbuffer_get_length(target); + else + n_to_write = WRITE_FRAME; + r = do_write(bev_ssl, n_to_write); + if (r & (OP_BLOCKED|OP_ERR)) + break; + } + + if (!bev_ssl->underlying) { + if (evbuffer_get_length(output) == 0) { + event_del(&bev_ssl->bev.bev.ev_write); + } else if (bev_ssl->bev.write_suspended || + !(bev_ssl->bev.bev.enabled & EV_WRITE)) { + /* Should be redundant, but let's avoid busy-looping */ + event_del(&bev_ssl->bev.bev.ev_write); + } + } +} + +static void +be_ssl_readcb(struct bufferevent *bev_base, void *ctx) +{ + struct bufferevent_ssl *bev_ssl = ctx; + consider_reading(bev_ssl); +} + +static void +be_ssl_writecb(struct bufferevent *bev_base, void *ctx) +{ + struct bufferevent_ssl *bev_ssl = ctx; + consider_writing(bev_ssl); +} + +static void +be_ssl_eventcb(struct bufferevent *bev_base, short what, void *ctx) +{ + struct bufferevent_ssl *bev_ssl = ctx; + int event = 0; + + if (what & BEV_EVENT_EOF) { + if (bev_ssl->flags & BUFFEREVENT_SSL_DIRTY_SHUTDOWN) + event = BEV_EVENT_EOF; + else + event = BEV_EVENT_ERROR; + } else if (what & BEV_EVENT_TIMEOUT) { + /* We sure didn't set this. Propagate it to the user. */ + event = what; + } else if (what & BEV_EVENT_ERROR) { + /* An error occurred on the connection. Propagate it to the user. */ + event = what; + } else if (what & BEV_EVENT_CONNECTED) { + /* Ignore it. We're saying SSL_connect() already, which will + eat it. */ + } + if (event) + bufferevent_run_eventcb_(&bev_ssl->bev.bev, event, 0); +} + +static void +be_ssl_readeventcb(evutil_socket_t fd, short what, void *ptr) +{ + struct bufferevent_ssl *bev_ssl = ptr; + bufferevent_incref_and_lock_(&bev_ssl->bev.bev); + if (what == EV_TIMEOUT) { + bufferevent_run_eventcb_(&bev_ssl->bev.bev, + BEV_EVENT_TIMEOUT|BEV_EVENT_READING, 0); + } else { + consider_reading(bev_ssl); + } + bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); +} + +static void +be_ssl_writeeventcb(evutil_socket_t fd, short what, void *ptr) +{ + struct bufferevent_ssl *bev_ssl = ptr; + bufferevent_incref_and_lock_(&bev_ssl->bev.bev); + if (what == EV_TIMEOUT) { + bufferevent_run_eventcb_(&bev_ssl->bev.bev, + BEV_EVENT_TIMEOUT|BEV_EVENT_WRITING, 0); + } else { + consider_writing(bev_ssl); + } + bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); +} + +static evutil_socket_t +be_ssl_auto_fd(struct bufferevent_ssl *bev_ssl, evutil_socket_t fd) +{ + if (!bev_ssl->underlying) { + struct bufferevent *bev = &bev_ssl->bev.bev; + if (event_initialized(&bev->ev_read) && fd < 0) { + fd = event_get_fd(&bev->ev_read); + } + } + return fd; +} + +static int +set_open_callbacks(struct bufferevent_ssl *bev_ssl, evutil_socket_t fd) +{ + if (bev_ssl->underlying) { + bufferevent_setcb(bev_ssl->underlying, + be_ssl_readcb, be_ssl_writecb, be_ssl_eventcb, + bev_ssl); + return 0; + } else { + struct bufferevent *bev = &bev_ssl->bev.bev; + int rpending=0, wpending=0, r1=0, r2=0; + + if (event_initialized(&bev->ev_read)) { + rpending = event_pending(&bev->ev_read, EV_READ, NULL); + wpending = event_pending(&bev->ev_write, EV_WRITE, NULL); + + event_del(&bev->ev_read); + event_del(&bev->ev_write); + } + + event_assign(&bev->ev_read, bev->ev_base, fd, + EV_READ|EV_PERSIST|EV_FINALIZE, + be_ssl_readeventcb, bev_ssl); + event_assign(&bev->ev_write, bev->ev_base, fd, + EV_WRITE|EV_PERSIST|EV_FINALIZE, + be_ssl_writeeventcb, bev_ssl); + + if (rpending) + r1 = bufferevent_add_event_(&bev->ev_read, &bev->timeout_read); + if (wpending) + r2 = bufferevent_add_event_(&bev->ev_write, &bev->timeout_write); + + return (r1<0 || r2<0) ? -1 : 0; + } +} + +static int +do_handshake(struct bufferevent_ssl *bev_ssl) +{ + int r; + + switch (bev_ssl->state) { + default: + case BUFFEREVENT_SSL_OPEN: + EVUTIL_ASSERT(0); + return -1; + case BUFFEREVENT_SSL_CONNECTING: + case BUFFEREVENT_SSL_ACCEPTING: + bev_ssl->ssl_ops->clear_error(); + r = bev_ssl->ssl_ops->handshake(bev_ssl->ssl); + break; + } + bev_ssl->ssl_ops->decrement_buckets(bev_ssl); + + if (bev_ssl->ssl_ops->err_is_ok(r)) { + evutil_socket_t fd = event_get_fd(&bev_ssl->bev.bev.ev_read); + /* We're done! */ + bev_ssl->state = BUFFEREVENT_SSL_OPEN; + set_open_callbacks(bev_ssl, fd); /* XXXX handle failure */ + /* Call do_read and do_write as needed */ + bufferevent_enable(&bev_ssl->bev.bev, bev_ssl->bev.bev.enabled); + bufferevent_run_eventcb_(&bev_ssl->bev.bev, + BEV_EVENT_CONNECTED, 0); + return 1; + } else { + int err = bev_ssl->ssl_ops->get_error(bev_ssl->ssl, r); + bev_ssl->ssl_ops->print_err(err); + if (bev_ssl->ssl_ops->err_is_want_write(err)) { + bufferevent_ssl_stop_reading(bev_ssl); + return start_writing(bev_ssl); + } else if (bev_ssl->ssl_ops->err_is_want_read(err)) { + bufferevent_ssl_stop_writing(bev_ssl); + return start_reading(bev_ssl); + } else { + bev_ssl->ssl_ops->conn_closed(bev_ssl, BEV_EVENT_READING, err, r); + return -1; + } + } +} + +static void +be_ssl_handshakecb(struct bufferevent *bev_base, void *ctx) +{ + struct bufferevent_ssl *bev_ssl = ctx; + do_handshake(bev_ssl);/* XXX handle failure */ +} + +static void +be_ssl_handshakeeventcb(evutil_socket_t fd, short what, void *ptr) +{ + struct bufferevent_ssl *bev_ssl = ptr; + + bufferevent_incref_and_lock_(&bev_ssl->bev.bev); + if (what & EV_TIMEOUT) { + bufferevent_run_eventcb_(&bev_ssl->bev.bev, BEV_EVENT_TIMEOUT, 0); + } else { + int c = evutil_socket_finished_connecting_(fd); + if (c < 0) + bufferevent_run_eventcb_(&bev_ssl->bev.bev, BEV_EVENT_ERROR, 0); + else + do_handshake(bev_ssl);/* XXX handle failure */ + } + bufferevent_decref_and_unlock_(&bev_ssl->bev.bev); +} + +static int +set_handshake_callbacks(struct bufferevent_ssl *bev_ssl, evutil_socket_t fd) +{ + if (bev_ssl->underlying) { + bufferevent_setcb(bev_ssl->underlying, + be_ssl_handshakecb, be_ssl_handshakecb, + be_ssl_eventcb, + bev_ssl); + + if (fd < 0) + return 0; + + if (bufferevent_setfd(bev_ssl->underlying, fd)) + return 1; + + return do_handshake(bev_ssl); + } else { + struct bufferevent *bev = &bev_ssl->bev.bev; + + if (event_initialized(&bev->ev_read)) { + event_del(&bev->ev_read); + event_del(&bev->ev_write); + } + + event_assign(&bev->ev_read, bev->ev_base, fd, + EV_READ|EV_PERSIST|EV_FINALIZE, + be_ssl_handshakeeventcb, bev_ssl); + event_assign(&bev->ev_write, bev->ev_base, fd, + EV_WRITE|EV_PERSIST|EV_FINALIZE, + be_ssl_handshakeeventcb, bev_ssl); + if (fd >= 0) + bufferevent_enable(bev, bev->enabled); + return 0; + } +} + +int +bufferevent_ssl_renegotiate_impl(struct bufferevent *bev) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bev); + if (!bev_ssl) + return -1; + if (bev_ssl->ssl_ops->renegotiate(bev_ssl->ssl) < 0) + return -1; + bev_ssl->state = BUFFEREVENT_SSL_CONNECTING; + if (set_handshake_callbacks(bev_ssl, be_ssl_auto_fd(bev_ssl, -1)) < 0) + return -1; + if (!bev_ssl->underlying) + return do_handshake(bev_ssl); + return 0; +} + +static void +be_ssl_outbuf_cb(struct evbuffer *buf, + const struct evbuffer_cb_info *cbinfo, void *arg) +{ + struct bufferevent_ssl *bev_ssl = arg; + int r = 0; + /* XXX need to hold a reference here. */ + + if (cbinfo->n_added && bev_ssl->state == BUFFEREVENT_SSL_OPEN) { + if (cbinfo->orig_size == 0) + r = bufferevent_add_event_(&bev_ssl->bev.bev.ev_write, + &bev_ssl->bev.bev.timeout_write); + + if (bev_ssl->underlying) + consider_writing(bev_ssl); + } + /* XXX Handle r < 0 */ + (void)r; +} + + +static int +be_ssl_enable(struct bufferevent *bev, short events) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bev); + int r1 = 0, r2 = 0; + + if (events & EV_READ) + r1 = start_reading(bev_ssl); + if (events & EV_WRITE) + r2 = start_writing(bev_ssl); + + if (bev_ssl->underlying) { + if (events & EV_READ) + BEV_RESET_GENERIC_READ_TIMEOUT(bev); + if (events & EV_WRITE) + BEV_RESET_GENERIC_WRITE_TIMEOUT(bev); + + if (events & EV_READ) + consider_reading(bev_ssl); + if (events & EV_WRITE) + consider_writing(bev_ssl); + } + return (r1 < 0 || r2 < 0) ? -1 : 0; +} + +static int +be_ssl_disable(struct bufferevent *bev, short events) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bev); + + if (events & EV_READ) + bufferevent_ssl_stop_reading(bev_ssl); + if (events & EV_WRITE) + bufferevent_ssl_stop_writing(bev_ssl); + + if (bev_ssl->underlying) { + if (events & EV_READ) + BEV_DEL_GENERIC_READ_TIMEOUT(bev); + if (events & EV_WRITE) + BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); + } + return 0; +} + +static void +be_ssl_unlink(struct bufferevent *bev) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bev); + + if (bev_ssl->bev.options & BEV_OPT_CLOSE_ON_FREE) { + if (bev_ssl->underlying) { + if (BEV_UPCAST(bev_ssl->underlying)->refcnt < 2) { + event_warnx("BEV_OPT_CLOSE_ON_FREE set on an " + "bufferevent with too few references"); + } else { + bufferevent_free(bev_ssl->underlying); + /* We still have a reference to it, via our + * BIO. So we don't drop this. */ + // bev_ssl->underlying = NULL; + } + } + } else { + if (bev_ssl->underlying) { + if (bev_ssl->underlying->errorcb == be_ssl_eventcb) + bufferevent_setcb(bev_ssl->underlying, + NULL,NULL,NULL,NULL); + bufferevent_unsuspend_read_(bev_ssl->underlying, + BEV_SUSPEND_FILT_READ); + } + } +} + +static void +be_ssl_destruct(struct bufferevent *bev) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bev); + + if (bev_ssl->bev.options & BEV_OPT_CLOSE_ON_FREE) { + if (! bev_ssl->underlying) { + evutil_socket_t fd = bev_ssl->ssl_ops->get_fd(bev_ssl); + if (fd >= 0) + evutil_closesocket(fd); + } + } + bev_ssl->ssl_ops->free(bev_ssl->ssl, bev_ssl->bev.options); +} + +static int +be_ssl_adj_timeouts(struct bufferevent *bev) +{ + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bev); + + if (bev_ssl->underlying) { + return bufferevent_generic_adj_timeouts_(bev); + } else { + return bufferevent_generic_adj_existing_timeouts_(bev); + } +} + +static int +be_ssl_flush(struct bufferevent *bufev, + short iotype, enum bufferevent_flush_mode mode) +{ + /* XXXX Implement this. */ + return 0; +} + +static int +be_ssl_set_fd(struct bufferevent_ssl *bev_ssl, + enum bufferevent_ssl_state state, evutil_socket_t fd) +{ + bev_ssl->state = state; + + switch (state) { + case BUFFEREVENT_SSL_ACCEPTING: + if (!bev_ssl->ssl_ops->clear(bev_ssl->ssl)) + return -1; + bev_ssl->ssl_ops->set_accept_state(bev_ssl->ssl); + if (set_handshake_callbacks(bev_ssl, fd) < 0) + return -1; + break; + case BUFFEREVENT_SSL_CONNECTING: + if (!bev_ssl->ssl_ops->clear(bev_ssl->ssl)) + return -1; + bev_ssl->ssl_ops->set_connect_state(bev_ssl->ssl); + if (set_handshake_callbacks(bev_ssl, fd) < 0) + return -1; + break; + case BUFFEREVENT_SSL_OPEN: + if (set_open_callbacks(bev_ssl, fd) < 0) + return -1; + break; + default: + return -1; + } + + return 0; +} + +static int +be_ssl_ctrl(struct bufferevent *bev, + enum bufferevent_ctrl_op op, union bufferevent_ctrl_data *data) +{ + int ret = 0; + struct bufferevent_ssl *bev_ssl = bufferevent_ssl_upcast(bev); + switch (op) { + case BEV_CTRL_SET_FD: + if ((ret = bev_ssl->ssl_ops->bio_set_fd(bev_ssl, data->fd)) != 0) + return ret; + return be_ssl_set_fd(bev_ssl, bev_ssl->old_state, data->fd); + case BEV_CTRL_GET_FD: + if (bev_ssl->underlying) { + data->fd = event_get_fd(&bev_ssl->underlying->ev_read); + } else { + data->fd = event_get_fd(&bev->ev_read); + } + return 0; + case BEV_CTRL_GET_UNDERLYING: + data->ptr = bev_ssl->underlying; + return 0; + case BEV_CTRL_CANCEL_ALL: + default: + return -1; + } +} + +struct bufferevent * +bufferevent_ssl_new_impl(struct event_base *base, + struct bufferevent *underlying, + evutil_socket_t fd, + void *ssl, + enum bufferevent_ssl_state state, + int options, + struct le_ssl_ops *ssl_ops) +{ + struct bufferevent_ssl *bev_ssl = NULL; + struct bufferevent_private *bev_p = NULL; + int tmp_options = options & ~BEV_OPT_THREADSAFE; + + /* Only one can be set. */ + if (underlying != NULL && fd >= 0) + goto err; + + if (!(bev_ssl = mm_calloc(1, sizeof(struct bufferevent_ssl)))) + goto err; + + bev_p = &bev_ssl->bev; + + if (bufferevent_init_common_(bev_p, base, + &bufferevent_ops_ssl, tmp_options) < 0) + goto err; + + bev_ssl->ssl_ops = ssl_ops; + + bev_ssl->ssl = bev_ssl->ssl_ops->init(ssl); + + bev_ssl->underlying = underlying; + + bev_ssl->outbuf_cb = evbuffer_add_cb(bev_p->bev.output, + be_ssl_outbuf_cb, bev_ssl); + + if (options & BEV_OPT_THREADSAFE) + bufferevent_enable_locking_(&bev_ssl->bev.bev, NULL); + + if (underlying) { + bufferevent_init_generic_timeout_cbs_(&bev_ssl->bev.bev); + bufferevent_incref_(underlying); + } + + bev_ssl->old_state = state; + bev_ssl->last_write = -1; + + bev_ssl->ssl_ops->init_bio_counts(bev_ssl); + + fd = be_ssl_auto_fd(bev_ssl, fd); + if (be_ssl_set_fd(bev_ssl, state, fd)) + goto err; + + if (underlying) { + bufferevent_setwatermark(underlying, EV_READ, 0, 0); + bufferevent_enable(underlying, EV_READ|EV_WRITE); + if (state == BUFFEREVENT_SSL_OPEN) + bufferevent_suspend_read_(underlying, + BEV_SUSPEND_FILT_READ); + } + + return &bev_ssl->bev.bev; +err: + if (bev_ssl) { + if (bev_ssl->ssl && (options & BEV_OPT_CLOSE_ON_FREE)) + bev_ssl->ssl_ops->free(bev_ssl->ssl, options); + bev_ssl->ssl = NULL; + bufferevent_free(&bev_ssl->bev.bev); + } else { + if (ssl && (options & BEV_OPT_CLOSE_ON_FREE)) + bev_ssl->ssl_ops->free_raw(bev_ssl->ssl); + } + return NULL; +} + +unsigned long +bufferevent_get_ssl_error(struct bufferevent *bev) +{ + unsigned long err = 0; + struct bufferevent_ssl *bev_ssl; + BEV_LOCK(bev); + bev_ssl = bufferevent_ssl_upcast(bev); + if (bev_ssl && bev_ssl->n_errors) { + err = bev_ssl->errors[--bev_ssl->n_errors]; + } + BEV_UNLOCK(bev); + return err; +} + +ev_uint64_t bufferevent_ssl_get_flags(struct bufferevent *bev) +{ + ev_uint64_t flags = EV_UINT64_MAX; + struct bufferevent_ssl *bev_ssl; + + BEV_LOCK(bev); + bev_ssl = bufferevent_ssl_upcast(bev); + if (bev_ssl) + flags = bev_ssl->flags; + BEV_UNLOCK(bev); + + return flags; +} +ev_uint64_t bufferevent_ssl_set_flags(struct bufferevent *bev, ev_uint64_t flags) +{ + ev_uint64_t old_flags = EV_UINT64_MAX; + struct bufferevent_ssl *bev_ssl; + + flags &= (BUFFEREVENT_SSL_DIRTY_SHUTDOWN|BUFFEREVENT_SSL_BATCH_WRITE); + if (!flags) + return old_flags; + + BEV_LOCK(bev); + bev_ssl = bufferevent_ssl_upcast(bev); + if (bev_ssl) { + old_flags = bev_ssl->flags; + bev_ssl->flags |= flags; + } + BEV_UNLOCK(bev); + + return old_flags; +} +ev_uint64_t bufferevent_ssl_clear_flags(struct bufferevent *bev, ev_uint64_t flags) +{ + ev_uint64_t old_flags = EV_UINT64_MAX; + struct bufferevent_ssl *bev_ssl; + + flags &= (BUFFEREVENT_SSL_DIRTY_SHUTDOWN|BUFFEREVENT_SSL_BATCH_WRITE); + if (!flags) + return old_flags; + + BEV_LOCK(bev); + bev_ssl = bufferevent_ssl_upcast(bev); + if (bev_ssl) { + old_flags = bev_ssl->flags; + bev_ssl->flags &= ~flags; + } + BEV_UNLOCK(bev); + + return old_flags; +} + +int +bufferevent_ssl_get_allow_dirty_shutdown(struct bufferevent *bev) +{ + ev_uint64_t flags = bufferevent_ssl_get_flags(bev); + if (flags == EV_UINT64_MAX) + return flags; + return !!(flags & BUFFEREVENT_SSL_DIRTY_SHUTDOWN); +} + +void +bufferevent_ssl_set_allow_dirty_shutdown( + struct bufferevent *bev, int allow_dirty_shutdown) +{ + BEV_LOCK(bev); + + if (allow_dirty_shutdown) + bufferevent_ssl_set_flags(bev, BUFFEREVENT_SSL_DIRTY_SHUTDOWN); + else + bufferevent_ssl_clear_flags(bev, BUFFEREVENT_SSL_DIRTY_SHUTDOWN); + + BEV_UNLOCK(bev); +} diff --git a/asynio/event/bufferevent_ssl.h b/asynio/event/bufferevent_ssl.h new file mode 100644 index 0000000000000000000000000000000000000000..ad53ac610201d6a9e22ce06eae2dec24a5060b38 --- /dev/null +++ b/asynio/event/bufferevent_ssl.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ + +#include "evconfig.h" +#include "bufferevent.h" +#include "util.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +enum bufferevent_ssl_state { + BUFFEREVENT_SSL_OPEN = 0, + BUFFEREVENT_SSL_CONNECTING = 1, + BUFFEREVENT_SSL_ACCEPTING = 2 +}; + + +#define BUFFEREVENT_SSL_DIRTY_SHUTDOWN 1 + +#define BUFFEREVENT_SSL_BATCH_WRITE 2 + +ev_uint64_t bufferevent_ssl_get_flags(struct bufferevent *bev); + +ev_uint64_t bufferevent_ssl_set_flags(struct bufferevent *bev, ev_uint64_t flags); + +ev_uint64_t bufferevent_ssl_clear_flags(struct bufferevent *bev, ev_uint64_t flags); + + +#if defined(EVENT__HAVE_OPENSSL) || defined(EVENT_IN_DOXYGEN_) +/* This is what openssl's SSL objects are underneath. */ +struct ssl_st; + + +struct bufferevent * +bufferevent_openssl_filter_new(struct event_base *base, + struct bufferevent *underlying, + struct ssl_st *ssl, + enum bufferevent_ssl_state state, + int options); + + +struct bufferevent * +bufferevent_openssl_socket_new(struct event_base *base, + evutil_socket_t fd, + struct ssl_st *ssl, + enum bufferevent_ssl_state state, + int options); + +int bufferevent_openssl_get_allow_dirty_shutdown(struct bufferevent *bev); + +void bufferevent_openssl_set_allow_dirty_shutdown(struct bufferevent *bev, + int allow_dirty_shutdown); + +struct ssl_st * +bufferevent_openssl_get_ssl(struct bufferevent *bufev); + +int bufferevent_ssl_renegotiate(struct bufferevent *bev); + +unsigned long bufferevent_get_openssl_error(struct bufferevent *bev); + +#endif + + +#if defined(EVENT__HAVE_MBEDTLS) || defined(EVENT_IN_DOXYGEN_) +struct mbedtls_ssl_context; + +struct bufferevent * +bufferevent_mbedtls_filter_new(struct event_base *base, + struct bufferevent *underlying, + struct mbedtls_ssl_context *ssl, + enum bufferevent_ssl_state state, + int options); + + +struct bufferevent * +bufferevent_mbedtls_socket_new(struct event_base *base, + evutil_socket_t fd, + struct mbedtls_ssl_context *ssl, + enum bufferevent_ssl_state state, + int options); + +int bufferevent_mbedtls_get_allow_dirty_shutdown(struct bufferevent *bev); + +void bufferevent_mbedtls_set_allow_dirty_shutdown(struct bufferevent *bev, + int allow_dirty_shutdown); + +struct mbedtls_ssl_context * +bufferevent_mbedtls_get_ssl(struct bufferevent *bufev); + +int bufferevent_mbedtls_renegotiate(struct bufferevent *bev); + +unsigned long bufferevent_get_mbedtls_error(struct bufferevent *bev); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT2_BUFFEREVENT_SSL_H_INCLUDED_ */ diff --git a/asynio/event/bufferevent_struct.h b/asynio/event/bufferevent_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..a480730ec7e13ee14242b81fd64203e4dc85a698 --- /dev/null +++ b/asynio/event/bufferevent_struct.h @@ -0,0 +1,74 @@ +#ifndef EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ +#define EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +/* For int types. */ +#include "util.h" +#include "bufferevent.h" +/* For struct event */ +#include "event_struct.h" + +struct event_watermark { + size_t low; + size_t high; +}; + +struct bufferevent { + /** Event base for which this bufferevent was created. */ + struct event_base* ev_base; + /** Pointer to a table of function pointers to set up how this + bufferevent behaves. */ + const struct bufferevent_ops* be_ops; + + /** A read event that triggers when a timeout has happened or a socket + is ready to read data. Only used by some subtypes of + bufferevent. */ + struct event ev_read; + /** A write event that triggers when a timeout has happened or a socket + is ready to write data. Only used by some subtypes of + bufferevent. */ + struct event ev_write; + + /** An input buffer. Only the bufferevent is allowed to add data to + this buffer, though the user is allowed to drain it. */ + struct evbuffer* input; + + /** An input buffer. Only the bufferevent is allowed to drain data + from this buffer, though the user is allowed to add it. */ + struct evbuffer* output; + + struct event_watermark wm_read; + struct event_watermark wm_write; + + bufferevent_data_cb readcb; + bufferevent_data_cb writecb; + /* This should be called 'eventcb', but renaming it would break + * backward compatibility */ + bufferevent_event_cb errorcb; + void* cbarg; + + struct timeval timeout_read; + struct timeval timeout_write; + + /** Events that are currently enabled: currently EV_READ and EV_WRITE + are supported. */ + short enabled; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT2_BUFFEREVENT_STRUCT_H_INCLUDED_ */ diff --git a/asynio/event/changelist-internal.h b/asynio/event/changelist-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..87f54d5c05723681a98d3f1ce544351474ffbc7f --- /dev/null +++ b/asynio/event/changelist-internal.h @@ -0,0 +1,50 @@ +#ifndef CHANGELIST_INTERNAL_H_INCLUDED_ +#define CHANGELIST_INTERNAL_H_INCLUDED_ + +#include "util.h" + +/** Represents a */ +struct event_change { + /** The fd or signal whose events are to be changed */ + evutil_socket_t fd; + /* The events that were enabled on the fd before any of these changes + were made. May include EV_READ or EV_WRITE. */ + short old_events; + + /* The changes that we want to make in reading and writing on this fd. + * If this is a signal, then read_change has EV_CHANGE_SIGNAL set, + * and write_change is unused. */ + ev_uint8_t read_change; + ev_uint8_t write_change; + ev_uint8_t close_change; +}; + +/* Flags for read_change and write_change. */ + +/* If set, add the event. */ +#define EV_CHANGE_ADD 0x01 +/* If set, delete the event. Exclusive with EV_CHANGE_ADD */ +#define EV_CHANGE_DEL 0x02 +/* If set, this event refers a signal, not an fd. */ +#define EV_CHANGE_SIGNAL EV_SIGNAL +/* Set for persistent events. Currently not used. */ +#define EV_CHANGE_PERSIST EV_PERSIST +/* Set for adding edge-triggered events. */ +#define EV_CHANGE_ET EV_ET + +/* The value of fdinfo_size that a backend should use if it is letting + * changelist handle its add and delete functions. */ +#define EVENT_CHANGELIST_FDINFO_SIZE sizeof(int) + +/** Set up the data fields in a changelist. */ +void event_changelist_init_(struct event_changelist* changelist); + +void event_changelist_remove_all_(struct event_changelist* changelist, struct event_base* base); + +void event_changelist_freemem_(struct event_changelist* changelist); + +int event_changelist_add_(struct event_base* base, evutil_socket_t fd, short old, short events, void* p); + +int event_changelist_del_(struct event_base* base, evutil_socket_t fd, short old, short events, void* p); + +#endif diff --git a/asynio/event/defer-internal.h b/asynio/event/defer-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..3b2b6709196f3c4cf7b794675f33d73f9ace955d --- /dev/null +++ b/asynio/event/defer-internal.h @@ -0,0 +1,27 @@ +#ifndef DEFER_INTERNAL_H_INCLUDED_ +#define DEFER_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#include "queue-internal.h" + +struct event_callback; +typedef void (*deferred_cb_fn)(struct event_callback*, void*); + +void event_deferred_cb_init_(struct event_callback*, ev_uint8_t, deferred_cb_fn, void*); + +void event_deferred_cb_set_priority_(struct event_callback*, ev_uint8_t); + +void event_deferred_cb_cancel_(struct event_base*, struct event_callback*); + +int event_deferred_cb_schedule_(struct event_base*, struct event_callback*); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/devpoll.c b/asynio/event/devpoll.c new file mode 100644 index 0000000000000000000000000000000000000000..7d62cbcef26b6927aa0576e558cdf2df4b22e0fd --- /dev/null +++ b/asynio/event/devpoll.c @@ -0,0 +1,302 @@ +/* + * Copyright 2000-2009 Niels Provos + * Copyright 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "event2/event-config.h" +#include "evconfig-private.h" + +#ifdef EVENT__HAVE_DEVPOLL + +#include +#include +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "eventbase.h" +#include "event_struct.h" +#include "thread.h" + +#include "event-internal.h" +#include "evsignal-internal.h" +#include "log-internal.h" +#include "evmap-internal.h" +#include "evthread-internal.h" + +struct devpollop { + struct pollfd* events; + int nevents; + int dpfd; + struct pollfd* changes; + int nchanges; +}; + +static void* devpoll_init(struct event_base*); +static int devpoll_add(struct event_base*, int fd, short old, short events, void*); +static int devpoll_del(struct event_base*, int fd, short old, short events, void*); +static int devpoll_dispatch(struct event_base*, struct timeval*); +static void devpoll_dealloc(struct event_base*); + +const struct eventop devpollops = { + "devpoll", + devpoll_init, + devpoll_add, + devpoll_del, + devpoll_dispatch, + devpoll_dealloc, + 1, /* need reinit */ + EV_FEATURE_FDS | EV_FEATURE_O1, + 0}; + +#define NEVENT 32000 + +static int devpoll_commit(struct devpollop* devpollop) +{ + /* + * Due to a bug in Solaris, we have to use pwrite with an offset of 0. + * Write is limited to 2GB of data, until it will fail. + */ + if (pwrite(devpollop->dpfd, devpollop->changes, sizeof(struct pollfd) * devpollop->nchanges, 0) == -1) + return (-1); + + devpollop->nchanges = 0; + return (0); +} + +static int devpoll_queue(struct devpollop* devpollop, int fd, int events) +{ + struct pollfd* pfd; + + if (devpollop->nchanges >= devpollop->nevents) { + /* + * Change buffer is full, must commit it to /dev/poll before + * adding more + */ + if (devpoll_commit(devpollop) != 0) + return (-1); + } + + pfd = &devpollop->changes[devpollop->nchanges++]; + pfd->fd = fd; + pfd->events = events; + pfd->revents = 0; + + return (0); +} + +static void* devpoll_init(struct event_base* base) +{ + int dpfd, nfiles = NEVENT; + struct rlimit rl; + struct devpollop* devpollop; + + if (!(devpollop = mm_calloc(1, sizeof(struct devpollop)))) + return (NULL); + + if (getrlimit(RLIMIT_NOFILE, &rl) == 0 && rl.rlim_cur != RLIM_INFINITY) + nfiles = rl.rlim_cur; + + /* Initialize the kernel queue */ + if ((dpfd = evutil_open_closeonexec_("/dev/poll", O_RDWR, 0)) == -1) { + event_warn("open: /dev/poll"); + mm_free(devpollop); + return (NULL); + } + + devpollop->dpfd = dpfd; + + /* Initialize fields */ + /* FIXME: allocating 'nfiles' worth of space here can be + * expensive and unnecessary. See how epoll.c does it instead. */ + devpollop->events = mm_calloc(nfiles, sizeof(struct pollfd)); + if (devpollop->events == NULL) { + mm_free(devpollop); + close(dpfd); + return (NULL); + } + devpollop->nevents = nfiles; + + devpollop->changes = mm_calloc(nfiles, sizeof(struct pollfd)); + if (devpollop->changes == NULL) { + mm_free(devpollop->events); + mm_free(devpollop); + close(dpfd); + return (NULL); + } + + evsig_init_(base); + + return (devpollop); +} + +static int devpoll_dispatch(struct event_base* base, struct timeval* tv) +{ + struct devpollop* devpollop = base->evbase; + struct pollfd* events = devpollop->events; + struct dvpoll dvp; + int i, res, timeout = -1; + + if (devpollop->nchanges) + devpoll_commit(devpollop); + + if (tv != NULL) + timeout = tv->tv_sec * 1000 + (tv->tv_usec + 999) / 1000; + + dvp.dp_fds = devpollop->events; + dvp.dp_nfds = devpollop->nevents; + dvp.dp_timeout = timeout; + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + res = ioctl(devpollop->dpfd, DP_POLL, &dvp); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (res == -1) { + if (errno != EINTR) { + event_warn("ioctl: DP_POLL"); + return (-1); + } + + return (0); + } + + event_debug(("%s: devpoll_wait reports %d", __func__, res)); + + for (i = 0; i < res; i++) { + int which = 0; + int what = events[i].revents; + + if (what & POLLHUP) + what |= POLLIN | POLLOUT; + else if (what & POLLERR) + what |= POLLIN | POLLOUT; + + if (what & POLLIN) + which |= EV_READ; + if (what & POLLOUT) + which |= EV_WRITE; + + if (!which) + continue; + + /* XXX(niels): not sure if this works for devpoll */ + evmap_io_active_(base, events[i].fd, which); + } + + return (0); +} + +static int devpoll_add(struct event_base* base, int fd, short old, short events, void* p) +{ + struct devpollop* devpollop = base->evbase; + int res; + (void)p; + + /* + * It's not necessary to OR the existing read/write events that we + * are currently interested in with the new event we are adding. + * The /dev/poll driver ORs any new events with the existing events + * that it has cached for the fd. + */ + + res = 0; + if (events & EV_READ) + res |= POLLIN; + if (events & EV_WRITE) + res |= POLLOUT; + + if (devpoll_queue(devpollop, fd, res) != 0) + return (-1); + + return (0); +} + +static int devpoll_del(struct event_base* base, int fd, short old, short events, void* p) +{ + struct devpollop* devpollop = base->evbase; + int res; + (void)p; + + res = 0; + if (events & EV_READ) + res |= POLLIN; + if (events & EV_WRITE) + res |= POLLOUT; + + /* + * The only way to remove an fd from the /dev/poll monitored set is + * to use POLLREMOVE by itself. This removes ALL events for the fd + * provided so if we care about two events and are only removing one + * we must re-add the other event after POLLREMOVE. + */ + + if (devpoll_queue(devpollop, fd, POLLREMOVE) != 0) + return (-1); + + if ((res & (POLLIN | POLLOUT)) != (POLLIN | POLLOUT)) { + /* + * We're not deleting all events, so we must resubmit the + * event that we are still interested in if one exists. + */ + + if ((res & POLLIN) && (old & EV_WRITE)) { + /* Deleting read, still care about write */ + devpoll_queue(devpollop, fd, POLLOUT); + } else if ((res & POLLOUT) && (old & EV_READ)) { + /* Deleting write, still care about read */ + devpoll_queue(devpollop, fd, POLLIN); + } + } + + return (0); +} + +static void devpoll_dealloc(struct event_base* base) +{ + struct devpollop* devpollop = base->evbase; + + evsig_dealloc_(base); + if (devpollop->events) + mm_free(devpollop->events); + if (devpollop->changes) + mm_free(devpollop->changes); + if (devpollop->dpfd >= 0) + close(devpollop->dpfd); + + memset(devpollop, 0, sizeof(struct devpollop)); + mm_free(devpollop); +} + +#endif /* EVENT__HAVE_DEVPOLL */ diff --git a/asynio/event/epoll.c b/asynio/event/epoll.c new file mode 100644 index 0000000000000000000000000000000000000000..c5d653c50d54a6ab1f8aeea81ed80f4e561e109e --- /dev/null +++ b/asynio/event/epoll.c @@ -0,0 +1,494 @@ +/* + * Copyright 2000-2007 Niels Provos + * Copyright 2007-2012 Niels Provos, Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "event-config.h" +#include "evconfig-private.h" + +#ifdef EVENT__HAVE_EPOLL + +#include +#include +#include +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef EVENT__HAVE_FCNTL_H +#include +#endif +#ifdef EVENT__HAVE_SYS_TIMERFD_H +#include +#endif + +#include "event-internal.h" +#include "evsignal-internal.h" + +#include "thread.h" + +#include "evthread-internal.h" +#include "log-internal.h" +#include "evmap-internal.h" +#include "changelist-internal.h" +#include "time-internal.h" + +/* Since Linux 2.6.17, epoll is able to report about peer half-closed connection + using special EPOLLRDHUP flag on a read event. +*/ +#if !defined(EPOLLRDHUP) +#define EPOLLRDHUP 0 +#define EARLY_CLOSE_IF_HAVE_RDHUP 0 +#else +#define EARLY_CLOSE_IF_HAVE_RDHUP EV_FEATURE_EARLY_CLOSE +#endif + +#include "epolltable-internal.h" + +#if defined(EVENT__HAVE_SYS_TIMERFD_H) && defined(EVENT__HAVE_TIMERFD_CREATE) && defined(HAVE_POSIX_MONOTONIC) && defined(TFD_NONBLOCK) \ + && defined(TFD_CLOEXEC) +/* Note that we only use timerfd if TFD_NONBLOCK and TFD_CLOEXEC are available + and working. This means that we can't support it on 2.6.25 (where timerfd + was introduced) or 2.6.26, since 2.6.27 introduced those flags. + */ +#define USING_TIMERFD +#endif + +struct epollop { + struct epoll_event* events; + int nevents; + int epfd; +#ifdef USING_TIMERFD + int timerfd; +#endif +}; + +static void* epoll_init(struct event_base*); +static int epoll_dispatch(struct event_base*, struct timeval*); +static void epoll_dealloc(struct event_base*); + +static const struct eventop epollops_changelist = { + "epoll (with changelist)", + epoll_init, + event_changelist_add_, + event_changelist_del_, + epoll_dispatch, + epoll_dealloc, + 1, /* need reinit */ + EV_FEATURE_ET | EV_FEATURE_O1 | EARLY_CLOSE_IF_HAVE_RDHUP, + EVENT_CHANGELIST_FDINFO_SIZE}; + +static int epoll_nochangelist_add(struct event_base* base, evutil_socket_t fd, short old, short events, void* p); +static int epoll_nochangelist_del(struct event_base* base, evutil_socket_t fd, short old, short events, void* p); + +const struct eventop epollops = { + "epoll", + epoll_init, + epoll_nochangelist_add, + epoll_nochangelist_del, + epoll_dispatch, + epoll_dealloc, + 1, /* need reinit */ + EV_FEATURE_ET | EV_FEATURE_O1 | EV_FEATURE_EARLY_CLOSE, + 0}; + +#define INITIAL_NEVENT 32 +#define MAX_NEVENT 4096 + +/* On Linux kernels at least up to 2.6.24.4, epoll can't handle timeout + * values bigger than (LONG_MAX - 999ULL)/HZ. HZ in the wild can be + * as big as 1000, and LONG_MAX can be as small as (1<<31)-1, so the + * largest number of msec we can support here is 2147482. Let's + * round that down by 47 seconds. + */ +#define MAX_EPOLL_TIMEOUT_MSEC (35 * 60 * 1000) + +static void* epoll_init(struct event_base* base) +{ + int epfd = -1; + struct epollop* epollop; + +#ifdef EVENT__HAVE_EPOLL_CREATE1 + /* First, try the shiny new epoll_create1 interface, if we have it. */ + epfd = epoll_create1(EPOLL_CLOEXEC); +#endif + if (epfd == -1) { + /* Initialize the kernel queue using the old interface. (The + size field is ignored since 2.6.8.) */ + if ((epfd = epoll_create(32000)) == -1) { + if (errno != ENOSYS) + event_warn("epoll_create"); + return (NULL); + } + evutil_make_socket_closeonexec(epfd); + } + + if (!(epollop = mm_calloc(1, sizeof(struct epollop)))) { + close(epfd); + return (NULL); + } + + epollop->epfd = epfd; + + /* Initialize fields */ + epollop->events = mm_calloc(INITIAL_NEVENT, sizeof(struct epoll_event)); + if (epollop->events == NULL) { + mm_free(epollop); + close(epfd); + return (NULL); + } + epollop->nevents = INITIAL_NEVENT; + + if ((base->flags & EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST) != 0 + || ((base->flags & EVENT_BASE_FLAG_IGNORE_ENV) == 0 && evutil_getenv_("EVENT_EPOLL_USE_CHANGELIST") != NULL)) { + base->evsel = &epollops_changelist; + } + +#ifdef USING_TIMERFD + /* + The epoll interface ordinarily gives us one-millisecond precision, + so on Linux it makes perfect sense to use the CLOCK_MONOTONIC_COARSE + timer. But when the user has set the new PRECISE_TIMER flag for an + event_base, we can try to use timerfd to give them finer granularity. + */ + if ((base->flags & EVENT_BASE_FLAG_PRECISE_TIMER) && base->monotonic_timer.monotonic_clock == CLOCK_MONOTONIC) { + int fd; + fd = epollop->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC); + if (epollop->timerfd >= 0) { + struct epoll_event epev; + memset(&epev, 0, sizeof(epev)); + epev.data.fd = epollop->timerfd; + epev.events = EPOLLIN; + if (epoll_ctl(epollop->epfd, EPOLL_CTL_ADD, fd, &epev) < 0) { + event_warn("epoll_ctl(timerfd)"); + close(fd); + epollop->timerfd = -1; + } + } else { + if (errno != EINVAL && errno != ENOSYS) { + /* These errors probably mean that we were + * compiled with timerfd/TFD_* support, but + * we're running on a kernel that lacks those. + */ + event_warn("timerfd_create"); + } + epollop->timerfd = -1; + } + } else { + epollop->timerfd = -1; + } +#endif + + evsig_init_(base); + + return (epollop); +} + +static const char* change_to_string(int change) +{ + change &= (EV_CHANGE_ADD | EV_CHANGE_DEL); + if (change == EV_CHANGE_ADD) { + return "add"; + } else if (change == EV_CHANGE_DEL) { + return "del"; + } else if (change == 0) { + return "none"; + } else { + return "???"; + } +} + +static const char* epoll_op_to_string(int op) +{ + return op == EPOLL_CTL_ADD ? "ADD" : op == EPOLL_CTL_DEL ? "DEL" : op == EPOLL_CTL_MOD ? "MOD" : "???"; +} + +#define PRINT_CHANGES(op, events, ch, status) \ + "Epoll %s(%d) on fd %d " status ". " \ + "Old events were %d; " \ + "read change was %d (%s); " \ + "write change was %d (%s); " \ + "close change was %d (%s)", \ + epoll_op_to_string(op), events, ch->fd, ch->old_events, ch->read_change, change_to_string(ch->read_change), ch->write_change, \ + change_to_string(ch->write_change), ch->close_change, change_to_string(ch->close_change) + +static int epoll_apply_one_change(struct event_base* base, struct epollop* epollop, const struct event_change* ch) +{ + struct epoll_event epev; + int op, events = 0; + int idx; + + idx = EPOLL_OP_TABLE_INDEX(ch); + op = epoll_op_table[idx].op; + events = epoll_op_table[idx].events; + + if (!events) { + EVUTIL_ASSERT(op == 0); + return 0; + } + + if ((ch->read_change | ch->write_change) & EV_CHANGE_ET) + events |= EPOLLET; + + memset(&epev, 0, sizeof(epev)); + epev.data.fd = ch->fd; + epev.events = events; + if (epoll_ctl(epollop->epfd, op, ch->fd, &epev) == 0) { + event_debug((PRINT_CHANGES(op, epev.events, ch, "okay"))); + return 0; + } + + switch (op) { + case EPOLL_CTL_MOD: + if (errno == ENOENT) { + /* If a MOD operation fails with ENOENT, the + * fd was probably closed and re-opened. We + * should retry the operation as an ADD. + */ + if (epoll_ctl(epollop->epfd, EPOLL_CTL_ADD, ch->fd, &epev) == -1) { + event_warn("Epoll MOD(%d) on %d retried as ADD; that failed too", (int)epev.events, ch->fd); + return -1; + } else { + event_debug(("Epoll MOD(%d) on %d retried as ADD; succeeded.", (int)epev.events, ch->fd)); + return 0; + } + } + break; + case EPOLL_CTL_ADD: + if (errno == EEXIST) { + /* If an ADD operation fails with EEXIST, + * either the operation was redundant (as with a + * precautionary add), or we ran into a fun + * kernel bug where using dup*() to duplicate the + * same file into the same fd gives you the same epitem + * rather than a fresh one. For the second case, + * we must retry with MOD. */ + if (epoll_ctl(epollop->epfd, EPOLL_CTL_MOD, ch->fd, &epev) == -1) { + event_warn("Epoll ADD(%d) on %d retried as MOD; that failed too", (int)epev.events, ch->fd); + return -1; + } else { + event_debug(("Epoll ADD(%d) on %d retried as MOD; succeeded.", (int)epev.events, ch->fd)); + return 0; + } + } + break; + case EPOLL_CTL_DEL: + if (errno == ENOENT || errno == EBADF || errno == EPERM) { + /* If a delete fails with one of these errors, + * that's fine too: we closed the fd before we + * got around to calling epoll_dispatch. */ + event_debug(("Epoll DEL(%d) on fd %d gave %s: DEL was unnecessary.", (int)epev.events, ch->fd, strerror(errno))); + return 0; + } + break; + default: + break; + } + + event_warn(PRINT_CHANGES(op, epev.events, ch, "failed")); + return -1; +} + +static int epoll_apply_changes(struct event_base* base) +{ + struct event_changelist* changelist = &base->changelist; + struct epollop* epollop = base->evbase; + struct event_change* ch; + + int r = 0; + int i; + + for (i = 0; i < changelist->n_changes; ++i) { + ch = &changelist->changes[i]; + if (epoll_apply_one_change(base, epollop, ch) < 0) + r = -1; + } + + return (r); +} + +static int epoll_nochangelist_add(struct event_base* base, evutil_socket_t fd, short old, short events, void* p) +{ + struct event_change ch; + ch.fd = fd; + ch.old_events = old; + ch.read_change = ch.write_change = ch.close_change = 0; + if (events & EV_WRITE) + ch.write_change = EV_CHANGE_ADD | (events & EV_ET); + if (events & EV_READ) + ch.read_change = EV_CHANGE_ADD | (events & EV_ET); + if (events & EV_CLOSED) + ch.close_change = EV_CHANGE_ADD | (events & EV_ET); + + return epoll_apply_one_change(base, base->evbase, &ch); +} + +static int epoll_nochangelist_del(struct event_base* base, evutil_socket_t fd, short old, short events, void* p) +{ + struct event_change ch; + ch.fd = fd; + ch.old_events = old; + ch.read_change = ch.write_change = ch.close_change = 0; + if (events & EV_WRITE) + ch.write_change = EV_CHANGE_DEL; + if (events & EV_READ) + ch.read_change = EV_CHANGE_DEL; + if (events & EV_CLOSED) + ch.close_change = EV_CHANGE_DEL; + + return epoll_apply_one_change(base, base->evbase, &ch); +} + +static int epoll_dispatch(struct event_base* base, struct timeval* tv) +{ + struct epollop* epollop = base->evbase; + struct epoll_event* events = epollop->events; + int i, res; + long timeout = -1; + +#ifdef USING_TIMERFD + if (epollop->timerfd >= 0) { + struct itimerspec is; + is.it_interval.tv_sec = 0; + is.it_interval.tv_nsec = 0; + if (tv == NULL) { + /* No timeout; disarm the timer. */ + is.it_value.tv_sec = 0; + is.it_value.tv_nsec = 0; + } else { + if (tv->tv_sec == 0 && tv->tv_usec == 0) { + /* we need to exit immediately; timerfd can't + * do that. */ + timeout = 0; + } + is.it_value.tv_sec = tv->tv_sec; + is.it_value.tv_nsec = tv->tv_usec * 1000; + } + /* TODO: we could avoid unnecessary syscalls here by only + calling timerfd_settime when the top timeout changes, or + when we're called with a different timeval. + */ + if (timerfd_settime(epollop->timerfd, 0, &is, NULL) < 0) { + event_warn("timerfd_settime"); + } + } else +#endif + if (tv != NULL) { + timeout = evutil_tv_to_msec_(tv); + if (timeout < 0 || timeout > MAX_EPOLL_TIMEOUT_MSEC) { + /* Linux kernels can wait forever if the timeout is + * too big; see comment on MAX_EPOLL_TIMEOUT_MSEC. */ + timeout = MAX_EPOLL_TIMEOUT_MSEC; + } + } + + epoll_apply_changes(base); + event_changelist_remove_all_(&base->changelist, base); + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + res = epoll_wait(epollop->epfd, events, epollop->nevents, timeout); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (res == -1) { + if (errno != EINTR) { + event_warn("epoll_wait"); + return (-1); + } + + return (0); + } + + event_debug(("%s: epoll_wait reports %d", __func__, res)); + EVUTIL_ASSERT(res <= epollop->nevents); + + for (i = 0; i < res; i++) { + int what = events[i].events; + short ev = 0; +#ifdef USING_TIMERFD + if (events[i].data.fd == epollop->timerfd) + continue; +#endif + + if (what & (EPOLLHUP | EPOLLERR)) { + ev = EV_READ | EV_WRITE; + } else { + if (what & EPOLLIN) + ev |= EV_READ; + if (what & EPOLLOUT) + ev |= EV_WRITE; + if (what & EPOLLRDHUP) + ev |= EV_CLOSED; + } + + if (!ev) + continue; + + evmap_io_active_(base, events[i].data.fd, ev | EV_ET); + } + + if (res == epollop->nevents && epollop->nevents < MAX_NEVENT) { + /* We used all of the event space this time. We should + be ready for more events next time. */ + int new_nevents = epollop->nevents * 2; + struct epoll_event* new_events; + + new_events = mm_realloc(epollop->events, new_nevents * sizeof(struct epoll_event)); + if (new_events) { + epollop->events = new_events; + epollop->nevents = new_nevents; + } + } + + return (0); +} + +static void epoll_dealloc(struct event_base* base) +{ + struct epollop* epollop = base->evbase; + + evsig_dealloc_(base); + if (epollop->events) + mm_free(epollop->events); + if (epollop->epfd >= 0) + close(epollop->epfd); +#ifdef USING_TIMERFD + if (epollop->timerfd >= 0) + close(epollop->timerfd); +#endif + + memset(epollop, 0, sizeof(struct epollop)); + mm_free(epollop); +} + +#endif /* EVENT__HAVE_EPOLL */ diff --git a/asynio/event/epoll_sub.c b/asynio/event/epoll_sub.c new file mode 100644 index 0000000000000000000000000000000000000000..8e0267e68169a1b38bb12ea8c847ad6040454739 --- /dev/null +++ b/asynio/event/epoll_sub.c @@ -0,0 +1,62 @@ +/* + * Copyright 2003-2009 Niels Provos + * Copyright 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "evconfig-private.h" +#include + +#include +#include +#include +#include +#include +#include + +int epoll_create(int size) +{ +#if !defined(__NR_epoll_create) && defined(__NR_epoll_create1) + if (size <= 0) { + errno = EINVAL; + return -1; + } + return (syscall(__NR_epoll_create1, 0)); +#else + return (syscall(__NR_epoll_create, size)); +#endif +} + +int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) +{ + return (syscall(__NR_epoll_ctl, epfd, op, fd, event)); +} + +int epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) +{ +#if !defined(__NR_epoll_wait) && defined(__NR_epoll_pwait) + return (syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL, 0)); +#else + return (syscall(__NR_epoll_wait, epfd, events, maxevents, timeout)); +#endif +} diff --git a/asynio/event/epolltable-internal.h b/asynio/event/epolltable-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..e97337ae9dfb2cd008d36678caadefd167efb71c --- /dev/null +++ b/asynio/event/epolltable-internal.h @@ -0,0 +1,1138 @@ + +#ifndef EPOLLTABLE_INTERNAL_H_INCLUDED_ +#define EPOLLTABLE_INTERNAL_H_INCLUDED_ + +/* + Here are the values we're masking off to decide what operations to do. + Note that since EV_READ|EV_WRITE. + + Note also that this table is a little sparse, since ADD+DEL is + nonsensical ("xxx" in the list below.) + + Note also also that we are shifting old_events by only 5 bits, since + EV_READ is 2 and EV_WRITE is 4. + + The table was auto-generated with a python script, according to this + pseudocode:[*0] + + If either the read or the write change is add+del: + This is impossible; Set op==-1, events=0. + Else, if either the read or the write change is add: + Set events to 0. + If the read change is add, or + (the read change is not del, and ev_read is in old_events): + Add EPOLLIN to events. + If the write change is add, or + (the write change is not del, and ev_write is in old_events): + Add EPOLLOUT to events. + + If old_events is set: + Set op to EPOLL_CTL_MOD [*1,*2] + Else: + Set op to EPOLL_CTL_ADD [*3] + + Else, if the read or the write change is del: + Set op to EPOLL_CTL_DEL. + If the read change is del: + If the write change is del: + Set events to EPOLLIN|EPOLLOUT + Else if ev_write is in old_events: + Set events to EPOLLOUT + Set op to EPOLL_CTL_MOD + Else + Set events to EPOLLIN + Else: + {The write change is del.} + If ev_read is in old_events: + Set events to EPOLLIN + Set op to EPOLL_CTL_MOD + Else: + Set the events to EPOLLOUT + + Else: + There is no read or write change; set op to 0 and events to 0. + + The logic is a little tricky, since we had no events set on the fd before, + we need to set op="ADD" and set events=the events we want to add. If we + had any events set on the fd before, and we want any events to remain on + the fd, we need to say op="MOD" and set events=the events we want to + remain. But if we want to delete the last event, we say op="DEL" and + set events=(any non-null pointer). + + [*0] Actually, the Python script has gotten a bit more complicated, to + support EPOLLRDHUP. + + [*1] This MOD is only a guess. MOD might fail with ENOENT if the file was + closed and a new file was opened with the same fd. If so, we'll retry + with ADD. + + [*2] We can't replace this with a no-op even if old_events is the same as + the new events: if the file was closed and reopened, we need to retry + with an ADD. (We do a MOD in this case since "no change" is more + common than "close and reopen", so we'll usually wind up doing 1 + syscalls instead of 2.) + + [*3] This ADD is only a guess. There is a fun Linux kernel issue where if + you have two fds for the same file (via dup) and you ADD one to an + epfd, then close it, then re-create it with the same fd (via dup2 or an + unlucky dup), then try to ADD it again, you'll get an EEXIST, since the + struct epitem is not actually removed from the struct eventpoll until + the file itself is closed. + + EV_CHANGE_ADD==1 + EV_CHANGE_DEL==2 + EV_READ ==2 + EV_WRITE ==4 + EV_CLOSED ==0x80 + + Bit 0: close change is add + Bit 1: close change is del + Bit 2: read change is add + Bit 3: read change is del + Bit 4: write change is add + Bit 5: write change is del + Bit 6: old events had EV_READ + Bit 7: old events had EV_WRITE + Bit 8: old events had EV_CLOSED +*/ + +#define EPOLL_OP_TABLE_INDEX(c) \ + ((((c)->close_change & (EV_CHANGE_ADD | EV_CHANGE_DEL))) | (((c)->read_change & (EV_CHANGE_ADD | EV_CHANGE_DEL)) << 2) \ + | (((c)->write_change & (EV_CHANGE_ADD | EV_CHANGE_DEL)) << 4) | (((c)->old_events & (EV_READ | EV_WRITE)) << 5) \ + | (((c)->old_events & (EV_CLOSED)) << 1)) + +#if EV_READ != 2 || EV_WRITE != 4 || EV_CLOSED != 0x80 || EV_CHANGE_ADD != 1 || EV_CHANGE_DEL != 2 +#error "Libevent's internals changed! Regenerate the op_table in epolltable-internal.h" +#endif + +static const struct operation { + int events; + int op; +} epoll_op_table[] = { + /* old= 0, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old= 0, write: 0, read: 0, close:add */ + {EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write: 0, read: 0, close:del */ + {EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= 0, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old= 0, write: 0, read:add, close: 0 */ + {EPOLLIN, EPOLL_CTL_ADD}, + /* old= 0, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write: 0, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_ADD}, + /* old= 0, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old= 0, write: 0, read:del, close: 0 */ + {EPOLLIN, EPOLL_CTL_DEL}, + /* old= 0, write: 0, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write: 0, read:del, close:del */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= 0, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old= 0, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old= 0, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old= 0, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old= 0, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old= 0, write:add, read: 0, close: 0 */ + {EPOLLOUT, EPOLL_CTL_ADD}, + /* old= 0, write:add, read: 0, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write:add, read: 0, close:del */ + {EPOLLOUT, EPOLL_CTL_ADD}, + /* old= 0, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old= 0, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_ADD}, + /* old= 0, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_ADD}, + /* old= 0, write:add, read:add, close:xxx */ + {0, 255 }, + /* old= 0, write:add, read:del, close: 0 */ + {EPOLLOUT, EPOLL_CTL_ADD}, + /* old= 0, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_ADD}, + /* old= 0, write:add, read:del, close:xxx */ + {0, 255 }, + /* old= 0, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old= 0, write:add, read:xxx, close:add */ + {0, 255 }, + /* old= 0, write:add, read:xxx, close:del */ + {0, 255 }, + /* old= 0, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old= 0, write:del, read: 0, close: 0 */ + {EPOLLOUT, EPOLL_CTL_DEL}, + /* old= 0, write:del, read: 0, close:add */ + {EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write:del, read: 0, close:del */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= 0, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old= 0, write:del, read:add, close: 0 */ + {EPOLLIN, EPOLL_CTL_ADD}, + /* old= 0, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_ADD}, + /* old= 0, write:del, read:add, close:xxx */ + {0, 255 }, + /* old= 0, write:del, read:del, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_DEL}, + /* old= 0, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_ADD}, + /* old= 0, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= 0, write:del, read:del, close:xxx */ + {0, 255 }, + /* old= 0, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old= 0, write:del, read:xxx, close:add */ + {0, 255 }, + /* old= 0, write:del, read:xxx, close:del */ + {0, 255 }, + /* old= 0, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old= 0, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old= 0, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old= 0, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old= 0, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old= 0, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old= 0, write:xxx, read:add, close:add */ + {0, 255 }, + /* old= 0, write:xxx, read:add, close:del */ + {0, 255 }, + /* old= 0, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old= 0, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old= 0, write:xxx, read:del, close:add */ + {0, 255 }, + /* old= 0, write:xxx, read:del, close:del */ + {0, 255 }, + /* old= 0, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old= 0, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old= 0, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old= 0, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old= 0, write:xxx, read:xxx, close:xxx */ + {0, 255 }, + /* old= r, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old= r, write: 0, read: 0, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write: 0, read: 0, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= r, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old= r, write: 0, read:add, close: 0 */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= r, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write: 0, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= r, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old= r, write: 0, read:del, close: 0 */ + {EPOLLIN, EPOLL_CTL_DEL}, + /* old= r, write: 0, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write: 0, read:del, close:del */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= r, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old= r, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old= r, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old= r, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old= r, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old= r, write:add, read: 0, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= r, write:add, read: 0, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write:add, read: 0, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= r, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old= r, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= r, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= r, write:add, read:add, close:xxx */ + {0, 255 }, + /* old= r, write:add, read:del, close: 0 */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= r, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= r, write:add, read:del, close:xxx */ + {0, 255 }, + /* old= r, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old= r, write:add, read:xxx, close:add */ + {0, 255 }, + /* old= r, write:add, read:xxx, close:del */ + {0, 255 }, + /* old= r, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old= r, write:del, read: 0, close: 0 */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= r, write:del, read: 0, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write:del, read: 0, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= r, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old= r, write:del, read:add, close: 0 */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= r, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= r, write:del, read:add, close:xxx */ + {0, 255 }, + /* old= r, write:del, read:del, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_DEL}, + /* old= r, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= r, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= r, write:del, read:del, close:xxx */ + {0, 255 }, + /* old= r, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old= r, write:del, read:xxx, close:add */ + {0, 255 }, + /* old= r, write:del, read:xxx, close:del */ + {0, 255 }, + /* old= r, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old= r, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old= r, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old= r, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old= r, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old= r, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old= r, write:xxx, read:add, close:add */ + {0, 255 }, + /* old= r, write:xxx, read:add, close:del */ + {0, 255 }, + /* old= r, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old= r, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old= r, write:xxx, read:del, close:add */ + {0, 255 }, + /* old= r, write:xxx, read:del, close:del */ + {0, 255 }, + /* old= r, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old= r, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old= r, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old= r, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old= r, write:xxx, read:xxx, close:xxx */ + {0, 255 }, + /* old= w, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old= w, write: 0, read: 0, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write: 0, read: 0, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old= w, write: 0, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write: 0, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old= w, write: 0, read:del, close: 0 */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write: 0, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write: 0, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old= w, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old= w, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old= w, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old= w, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old= w, write:add, read: 0, close: 0 */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write:add, read: 0, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write:add, read: 0, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old= w, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write:add, read:add, close:xxx */ + {0, 255 }, + /* old= w, write:add, read:del, close: 0 */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= w, write:add, read:del, close:xxx */ + {0, 255 }, + /* old= w, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old= w, write:add, read:xxx, close:add */ + {0, 255 }, + /* old= w, write:add, read:xxx, close:del */ + {0, 255 }, + /* old= w, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old= w, write:del, read: 0, close: 0 */ + {EPOLLOUT, EPOLL_CTL_DEL}, + /* old= w, write:del, read: 0, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write:del, read: 0, close:del */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= w, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old= w, write:del, read:add, close: 0 */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= w, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= w, write:del, read:add, close:xxx */ + {0, 255 }, + /* old= w, write:del, read:del, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_DEL}, + /* old= w, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= w, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= w, write:del, read:del, close:xxx */ + {0, 255 }, + /* old= w, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old= w, write:del, read:xxx, close:add */ + {0, 255 }, + /* old= w, write:del, read:xxx, close:del */ + {0, 255 }, + /* old= w, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old= w, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old= w, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old= w, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old= w, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old= w, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old= w, write:xxx, read:add, close:add */ + {0, 255 }, + /* old= w, write:xxx, read:add, close:del */ + {0, 255 }, + /* old= w, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old= w, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old= w, write:xxx, read:del, close:add */ + {0, 255 }, + /* old= w, write:xxx, read:del, close:del */ + {0, 255 }, + /* old= w, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old= w, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old= w, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old= w, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old= w, write:xxx, read:xxx, close:xxx */ + {0, 255 }, + /* old= rw, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old= rw, write: 0, read: 0, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read: 0, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old= rw, write: 0, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old= rw, write: 0, read:del, close: 0 */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old= rw, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old= rw, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old= rw, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old= rw, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old= rw, write:add, read: 0, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write:add, read: 0, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write:add, read: 0, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old= rw, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write:add, read:add, close:xxx */ + {0, 255 }, + /* old= rw, write:add, read:del, close: 0 */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= rw, write:add, read:del, close:xxx */ + {0, 255 }, + /* old= rw, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old= rw, write:add, read:xxx, close:add */ + {0, 255 }, + /* old= rw, write:add, read:xxx, close:del */ + {0, 255 }, + /* old= rw, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old= rw, write:del, read: 0, close: 0 */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= rw, write:del, read: 0, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write:del, read: 0, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= rw, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old= rw, write:del, read:add, close: 0 */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= rw, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= rw, write:del, read:add, close:xxx */ + {0, 255 }, + /* old= rw, write:del, read:del, close: 0 */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_DEL}, + /* old= rw, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= rw, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= rw, write:del, read:del, close:xxx */ + {0, 255 }, + /* old= rw, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old= rw, write:del, read:xxx, close:add */ + {0, 255 }, + /* old= rw, write:del, read:xxx, close:del */ + {0, 255 }, + /* old= rw, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old= rw, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old= rw, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old= rw, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old= rw, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old= rw, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old= rw, write:xxx, read:add, close:add */ + {0, 255 }, + /* old= rw, write:xxx, read:add, close:del */ + {0, 255 }, + /* old= rw, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old= rw, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old= rw, write:xxx, read:del, close:add */ + {0, 255 }, + /* old= rw, write:xxx, read:del, close:del */ + {0, 255 }, + /* old= rw, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old= rw, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old= rw, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old= rw, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old= rw, write:xxx, read:xxx, close:xxx */ + {0, 255 }, + /* old= c, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old= c, write: 0, read: 0, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write: 0, read: 0, close:del */ + {EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= c, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old= c, write: 0, read:add, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write: 0, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= c, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old= c, write: 0, read:del, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write: 0, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write: 0, read:del, close:del */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= c, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old= c, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old= c, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old= c, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old= c, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old= c, write:add, read: 0, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:add, read: 0, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:add, read: 0, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= c, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old= c, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= c, write:add, read:add, close:xxx */ + {0, 255 }, + /* old= c, write:add, read:del, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= c, write:add, read:del, close:xxx */ + {0, 255 }, + /* old= c, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old= c, write:add, read:xxx, close:add */ + {0, 255 }, + /* old= c, write:add, read:xxx, close:del */ + {0, 255 }, + /* old= c, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old= c, write:del, read: 0, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:del, read: 0, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:del, read: 0, close:del */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= c, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old= c, write:del, read:add, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= c, write:del, read:add, close:xxx */ + {0, 255 }, + /* old= c, write:del, read:del, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= c, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= c, write:del, read:del, close:xxx */ + {0, 255 }, + /* old= c, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old= c, write:del, read:xxx, close:add */ + {0, 255 }, + /* old= c, write:del, read:xxx, close:del */ + {0, 255 }, + /* old= c, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old= c, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old= c, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old= c, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old= c, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old= c, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old= c, write:xxx, read:add, close:add */ + {0, 255 }, + /* old= c, write:xxx, read:add, close:del */ + {0, 255 }, + /* old= c, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old= c, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old= c, write:xxx, read:del, close:add */ + {0, 255 }, + /* old= c, write:xxx, read:del, close:del */ + {0, 255 }, + /* old= c, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old= c, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old= c, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old= c, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old= c, write:xxx, read:xxx, close:xxx */ + {0, 255 }, + /* old= cr, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old= cr, write: 0, read: 0, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write: 0, read: 0, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= cr, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old= cr, write: 0, read:add, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write: 0, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= cr, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old= cr, write: 0, read:del, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write: 0, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write: 0, read:del, close:del */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= cr, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old= cr, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old= cr, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old= cr, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old= cr, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old= cr, write:add, read: 0, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:add, read: 0, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:add, read: 0, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cr, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old= cr, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cr, write:add, read:add, close:xxx */ + {0, 255 }, + /* old= cr, write:add, read:del, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cr, write:add, read:del, close:xxx */ + {0, 255 }, + /* old= cr, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old= cr, write:add, read:xxx, close:add */ + {0, 255 }, + /* old= cr, write:add, read:xxx, close:del */ + {0, 255 }, + /* old= cr, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old= cr, write:del, read: 0, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:del, read: 0, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:del, read: 0, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= cr, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old= cr, write:del, read:add, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= cr, write:del, read:add, close:xxx */ + {0, 255 }, + /* old= cr, write:del, read:del, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cr, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= cr, write:del, read:del, close:xxx */ + {0, 255 }, + /* old= cr, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old= cr, write:del, read:xxx, close:add */ + {0, 255 }, + /* old= cr, write:del, read:xxx, close:del */ + {0, 255 }, + /* old= cr, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old= cr, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old= cr, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old= cr, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old= cr, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old= cr, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old= cr, write:xxx, read:add, close:add */ + {0, 255 }, + /* old= cr, write:xxx, read:add, close:del */ + {0, 255 }, + /* old= cr, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old= cr, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old= cr, write:xxx, read:del, close:add */ + {0, 255 }, + /* old= cr, write:xxx, read:del, close:del */ + {0, 255 }, + /* old= cr, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old= cr, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old= cr, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old= cr, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old= cr, write:xxx, read:xxx, close:xxx */ + {0, 255 }, + /* old= cw, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old= cw, write: 0, read: 0, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read: 0, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old= cw, write: 0, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old= cw, write: 0, read:del, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cw, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old= cw, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old= cw, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old= cw, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old= cw, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old= cw, write:add, read: 0, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:add, read: 0, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:add, read: 0, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cw, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old= cw, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cw, write:add, read:add, close:xxx */ + {0, 255 }, + /* old= cw, write:add, read:del, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old= cw, write:add, read:del, close:xxx */ + {0, 255 }, + /* old= cw, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old= cw, write:add, read:xxx, close:add */ + {0, 255 }, + /* old= cw, write:add, read:xxx, close:del */ + {0, 255 }, + /* old= cw, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old= cw, write:del, read: 0, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:del, read: 0, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:del, read: 0, close:del */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= cw, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old= cw, write:del, read:add, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old= cw, write:del, read:add, close:xxx */ + {0, 255 }, + /* old= cw, write:del, read:del, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old= cw, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old= cw, write:del, read:del, close:xxx */ + {0, 255 }, + /* old= cw, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old= cw, write:del, read:xxx, close:add */ + {0, 255 }, + /* old= cw, write:del, read:xxx, close:del */ + {0, 255 }, + /* old= cw, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old= cw, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old= cw, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old= cw, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old= cw, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old= cw, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old= cw, write:xxx, read:add, close:add */ + {0, 255 }, + /* old= cw, write:xxx, read:add, close:del */ + {0, 255 }, + /* old= cw, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old= cw, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old= cw, write:xxx, read:del, close:add */ + {0, 255 }, + /* old= cw, write:xxx, read:del, close:del */ + {0, 255 }, + /* old= cw, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old= cw, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old= cw, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old= cw, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old= cw, write:xxx, read:xxx, close:xxx */ + {0, 255 }, + /* old=crw, write: 0, read: 0, close: 0 */ + {0, 0 }, + /* old=crw, write: 0, read: 0, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read: 0, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read: 0, close:xxx */ + {0, 255 }, + /* old=crw, write: 0, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read:add, close:xxx */ + {0, 255 }, + /* old=crw, write: 0, read:del, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old=crw, write: 0, read:del, close:xxx */ + {0, 255 }, + /* old=crw, write: 0, read:xxx, close: 0 */ + {0, 255 }, + /* old=crw, write: 0, read:xxx, close:add */ + {0, 255 }, + /* old=crw, write: 0, read:xxx, close:del */ + {0, 255 }, + /* old=crw, write: 0, read:xxx, close:xxx */ + {0, 255 }, + /* old=crw, write:add, read: 0, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:add, read: 0, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:add, read: 0, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old=crw, write:add, read: 0, close:xxx */ + {0, 255 }, + /* old=crw, write:add, read:add, close: 0 */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:add, read:add, close:add */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:add, read:add, close:del */ + {EPOLLIN | EPOLLOUT, EPOLL_CTL_MOD}, + /* old=crw, write:add, read:add, close:xxx */ + {0, 255 }, + /* old=crw, write:add, read:del, close: 0 */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:add, read:del, close:add */ + {EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:add, read:del, close:del */ + {EPOLLOUT, EPOLL_CTL_MOD}, + /* old=crw, write:add, read:del, close:xxx */ + {0, 255 }, + /* old=crw, write:add, read:xxx, close: 0 */ + {0, 255 }, + /* old=crw, write:add, read:xxx, close:add */ + {0, 255 }, + /* old=crw, write:add, read:xxx, close:del */ + {0, 255 }, + /* old=crw, write:add, read:xxx, close:xxx */ + {0, 255 }, + /* old=crw, write:del, read: 0, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:del, read: 0, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:del, read: 0, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old=crw, write:del, read: 0, close:xxx */ + {0, 255 }, + /* old=crw, write:del, read:add, close: 0 */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:del, read:add, close:add */ + {EPOLLIN | EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:del, read:add, close:del */ + {EPOLLIN, EPOLL_CTL_MOD}, + /* old=crw, write:del, read:add, close:xxx */ + {0, 255 }, + /* old=crw, write:del, read:del, close: 0 */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:del, read:del, close:add */ + {EPOLLRDHUP, EPOLL_CTL_MOD}, + /* old=crw, write:del, read:del, close:del */ + {EPOLLIN | EPOLLOUT | EPOLLRDHUP, EPOLL_CTL_DEL}, + /* old=crw, write:del, read:del, close:xxx */ + {0, 255 }, + /* old=crw, write:del, read:xxx, close: 0 */ + {0, 255 }, + /* old=crw, write:del, read:xxx, close:add */ + {0, 255 }, + /* old=crw, write:del, read:xxx, close:del */ + {0, 255 }, + /* old=crw, write:del, read:xxx, close:xxx */ + {0, 255 }, + /* old=crw, write:xxx, read: 0, close: 0 */ + {0, 255 }, + /* old=crw, write:xxx, read: 0, close:add */ + {0, 255 }, + /* old=crw, write:xxx, read: 0, close:del */ + {0, 255 }, + /* old=crw, write:xxx, read: 0, close:xxx */ + {0, 255 }, + /* old=crw, write:xxx, read:add, close: 0 */ + {0, 255 }, + /* old=crw, write:xxx, read:add, close:add */ + {0, 255 }, + /* old=crw, write:xxx, read:add, close:del */ + {0, 255 }, + /* old=crw, write:xxx, read:add, close:xxx */ + {0, 255 }, + /* old=crw, write:xxx, read:del, close: 0 */ + {0, 255 }, + /* old=crw, write:xxx, read:del, close:add */ + {0, 255 }, + /* old=crw, write:xxx, read:del, close:del */ + {0, 255 }, + /* old=crw, write:xxx, read:del, close:xxx */ + {0, 255 }, + /* old=crw, write:xxx, read:xxx, close: 0 */ + {0, 255 }, + /* old=crw, write:xxx, read:xxx, close:add */ + {0, 255 }, + /* old=crw, write:xxx, read:xxx, close:del */ + {0, 255 }, + /* old=crw, write:xxx, read:xxx, close:xxx */ + {0, 255 }, +}; + +#endif diff --git a/asynio/event/evbuffer-internal.h b/asynio/event/evbuffer-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..6a9425187a71846272482b36c6b2721164a97179 --- /dev/null +++ b/asynio/event/evbuffer-internal.h @@ -0,0 +1,310 @@ +#ifndef EVBUFFER_INTERNAL_H_INCLUDED_ +#define EVBUFFER_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#include "buffer.h" +#include "buffer_compat.h" +#include "evconfig-internal.h" + +/* Experimental cb flag: "never deferred." Implementation note: + * these callbacks may get an inaccurate view of n_del/n_added in their + * arguments. */ +#define EVBUFFER_CB_NODEFER 2 + +#ifdef _WIN32 +#include +#endif + +// #include + +/* Minimum allocation for a chain. We define this so that we're burning no + * more than 5% of each allocation on overhead. It would be nice to lose even + * less space, though. */ +#if EVENT__SIZEOF_VOID_P < 8 +#define MIN_BUFFER_SIZE 512 +#else +#define MIN_BUFFER_SIZE 1024 +#endif + +/** A single evbuffer callback for an evbuffer. This function will be invoked + * when bytes are added to or removed from the evbuffer. */ +struct evbuffer_cb_entry { + /** Structures to implement a doubly-linked queue of callbacks */ + LIST_ENTRY(evbuffer_cb_entry) next; + /** The callback function to invoke when this callback is called. + If EVBUFFER_CB_OBSOLETE is set in flags, the cb_obsolete field is + valid; otherwise, cb_func is valid. */ + union { + evbuffer_cb_func cb_func; + evbuffer_cb cb_obsolete; + } cb; + /** Argument to pass to cb. */ + void* cbarg; + /** Currently set flags on this callback. */ + ev_uint32_t flags; +}; + +struct bufferevent; +struct evbuffer_chain; +struct evbuffer { + /** The first chain in this buffer's linked list of chains. */ + struct evbuffer_chain* first; + /** The last chain in this buffer's linked list of chains. */ + struct evbuffer_chain* last; + + /** Pointer to the next pointer pointing at the 'last_with_data' chain. + * + * To unpack: + * + * The last_with_data chain is the last chain that has any data in it. + * If all chains in the buffer are empty, it is the first chain. + * If the buffer has no chains, it is NULL. + * + * The last_with_datap pointer points at _whatever 'next' pointer_ + * points at the last_with_datap chain. If the last_with_data chain + * is the first chain, or it is NULL, then the last_with_datap pointer + * is &buf->first. + */ + struct evbuffer_chain** last_with_datap; + + /** Total amount of bytes stored in all chains.*/ + size_t total_len; + + /** Number of bytes we have added to the buffer since we last tried to + * invoke callbacks. */ + size_t n_add_for_cb; + /** Number of bytes we have removed from the buffer since we last + * tried to invoke callbacks. */ + size_t n_del_for_cb; + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + /** A lock used to mediate access to this buffer. */ + void* lock; +#endif + /** True iff we should free the lock field when we free this + * evbuffer. */ + unsigned own_lock : 1; + /** True iff we should not allow changes to the front of the buffer + * (drains or prepends). */ + unsigned freeze_start : 1; + /** True iff we should not allow changes to the end of the buffer + * (appends) */ + unsigned freeze_end : 1; + /** True iff this evbuffer's callbacks are not invoked immediately + * upon a change in the buffer, but instead are deferred to be invoked + * from the event_base's loop. Useful for preventing enormous stack + * overflows when we have mutually recursive callbacks, and for + * serializing callbacks in a single thread. */ + unsigned deferred_cbs : 1; +#ifdef _WIN32 + /** True iff this buffer is set up for overlapped IO. */ + unsigned is_overlapped : 1; +#endif + /** Zero or more EVBUFFER_FLAG_* bits */ + ev_uint32_t flags; + + /** Used to implement deferred callbacks. */ + struct event_base* cb_queue; + + /** A reference count on this evbuffer. When the reference count + * reaches 0, the buffer is destroyed. Manipulated with + * evbuffer_incref and evbuffer_decref_and_unlock and + * evbuffer_free. */ + int refcnt; + + /** A struct event_callback handle to make all of this buffer's callbacks + * invoked from the event loop. */ + struct event_callback deferred; + + /** A doubly-linked-list of callback functions */ + LIST_HEAD(evbuffer_cb_queue, evbuffer_cb_entry) callbacks; + + /** The parent bufferevent object this evbuffer belongs to. + * NULL if the evbuffer stands alone. */ + struct bufferevent* parent; +}; + +#if EVENT__SIZEOF_OFF_T < EVENT__SIZEOF_SIZE_T +typedef ev_ssize_t ev_misalign_t; +#define EVBUFFER_CHAIN_MAX ((size_t)EV_SSIZE_MAX) +#else +typedef ev_off_t ev_misalign_t; +#if EVENT__SIZEOF_OFF_T > EVENT__SIZEOF_SIZE_T +#define EVBUFFER_CHAIN_MAX EV_SIZE_MAX +#else +#define EVBUFFER_CHAIN_MAX ((size_t)EV_SSIZE_MAX) +#endif +#endif + +/** A single item in an evbuffer. */ +struct evbuffer_chain { + /** points to next buffer in the chain */ + struct evbuffer_chain* next; + + /** total allocation available in the buffer field. */ + size_t buffer_len; + + /** unused space at the beginning of buffer or an offset into a + * file for sendfile buffers. */ + ev_misalign_t misalign; + + /** Offset into buffer + misalign at which to start writing. + * In other words, the total number of bytes actually stored + * in buffer. */ + size_t off; + + /** Set if special handling is required for this chain */ + unsigned flags; +#define EVBUFFER_FILESEGMENT 0x0001 /**< A chain used for a file segment */ +#define EVBUFFER_SENDFILE 0x0002 /**< a chain used with sendfile */ +#define EVBUFFER_REFERENCE 0x0004 /**< a chain with a mem reference */ +#define EVBUFFER_IMMUTABLE 0x0008 /**< read-only chain */ + /** a chain that mustn't be reallocated or freed, or have its contents + * memmoved, until the chain is un-pinned. */ +#define EVBUFFER_MEM_PINNED_R 0x0010 +#define EVBUFFER_MEM_PINNED_W 0x0020 +#define EVBUFFER_MEM_PINNED_ANY (EVBUFFER_MEM_PINNED_R | EVBUFFER_MEM_PINNED_W) + /** a chain that should be freed, but can't be freed until it is + * un-pinned. */ +#define EVBUFFER_DANGLING 0x0040 + /** a chain that is a referenced copy of another chain */ +#define EVBUFFER_MULTICAST 0x0080 + + /** number of references to this chain */ + int refcnt; + + /** Usually points to the read-write memory belonging to this + * buffer allocated as part of the evbuffer_chain allocation. + * For mmap, this can be a read-only buffer and + * EVBUFFER_IMMUTABLE will be set in flags. For sendfile, it + * may point to NULL. + */ + unsigned char* buffer; +}; + +/** callback for a reference chain; lets us know what to do with it when + * we're done with it. Lives at the end of an evbuffer_chain with the + * EVBUFFER_REFERENCE flag set */ +struct evbuffer_chain_reference { + evbuffer_ref_cleanup_cb cleanupfn; + void* extra; +}; + +/** File segment for a file-segment chain. Lives at the end of an + * evbuffer_chain with the EVBUFFER_FILESEGMENT flag set. */ +struct evbuffer_chain_file_segment { + struct evbuffer_file_segment* segment; +#ifdef _WIN32 + /** If we're using CreateFileMapping, this is the handle to the view. */ + HANDLE view_handle; +#endif +}; + +/* Declared in event2/buffer.h; defined here. */ +struct evbuffer_file_segment { + void* lock; /**< lock prevent concurrent access to refcnt */ + int refcnt; /**< Reference count for this file segment */ + unsigned flags; /**< combination of EVBUF_FS_* flags */ + + /** What kind of file segment is this? */ + unsigned can_sendfile : 1; + unsigned is_mapping : 1; + + /** The fd that we read the data from. */ + int fd; + /** If we're using mmap, this is the raw mapped memory. */ + void* mapping; +#ifdef _WIN32 + /** If we're using CreateFileMapping, this is the mapping */ + HANDLE mapping_handle; +#endif + /** If we're using mmap or IO, this is the content of the file + * segment. */ + char* contents; + /** Position of this segment within the file. */ + ev_off_t file_offset; + /** If we're using mmap, this is the offset within 'mapping' where + * this data segment begins. */ + ev_off_t mmap_offset; + /** The length of this segment. */ + ev_off_t length; + /** Cleanup callback function */ + evbuffer_file_segment_cleanup_cb cleanup_cb; + /** Argument to be pass to cleanup callback function */ + void* cleanup_cb_arg; +}; + +/** Information about the multicast parent of a chain. Lives at the + * end of an evbuffer_chain with the EVBUFFER_MULTICAST flag set. */ +struct evbuffer_multicast_parent { + /** source buffer the multicast parent belongs to */ + struct evbuffer* source; + /** multicast parent for this chain */ + struct evbuffer_chain* parent; +}; + +#define EVBUFFER_CHAIN_SIZE sizeof(struct evbuffer_chain) +/** Return a pointer to extra data allocated along with an evbuffer. */ +#define EVBUFFER_CHAIN_EXTRA(t, c) (t*)((struct evbuffer_chain*)(c) + 1) + +/** Assert that we are holding the lock on an evbuffer */ +#define ASSERT_EVBUFFER_LOCKED(buffer) EVLOCK_ASSERT_LOCKED((buffer)->lock) + +#define EVBUFFER_LOCK(buffer) \ + do { \ + EVLOCK_LOCK((buffer)->lock, 0); \ + } while (0) +#define EVBUFFER_UNLOCK(buffer) \ + do { \ + EVLOCK_UNLOCK((buffer)->lock, 0); \ + } while (0) +#define EVBUFFER_LOCK2(buffer1, buffer2) \ + do { \ + EVLOCK_LOCK2((buffer1)->lock, (buffer2)->lock, 0, 0); \ + } while (0) +#define EVBUFFER_UNLOCK2(buffer1, buffer2) \ + do { \ + EVLOCK_UNLOCK2((buffer1)->lock, (buffer2)->lock, 0, 0); \ + } while (0) + +void evbuffer_incref_(struct evbuffer* buf); + +void evbuffer_incref_and_lock_(struct evbuffer* buf); + +void evbuffer_chain_pin_(struct evbuffer_chain* chain, unsigned flag); + +void evbuffer_chain_unpin_(struct evbuffer_chain* chain, unsigned flag); + +void evbuffer_decref_and_unlock_(struct evbuffer* buffer); + +int evbuffer_expand_fast_(struct evbuffer*, size_t, int); + +int evbuffer_read_setup_vecs_( + struct evbuffer* buf, ev_ssize_t howmuch, struct evbuffer_iovec* vecs, int n_vecs, struct evbuffer_chain*** chainp, int exact); + +/* Helper macro: copies an evbuffer_iovec in ei to a win32 WSABUF in i. */ +#define WSABUF_FROM_EVBUFFER_IOV(i, ei) \ + do { \ + (i)->buf = (ei)->iov_base; \ + (i)->len = (unsigned long)(ei)->iov_len; \ + } while (0) +/* XXXX the cast above is safe for now, but not if we allow mmaps on win64. + * See note in buffer_iocp's launch_write function */ + +/** Set the parent bufferevent object for buf to bev */ +void evbuffer_set_parent_(struct evbuffer* buf, struct bufferevent* bev); + +void evbuffer_invoke_callbacks_(struct evbuffer* buf); + +int evbuffer_get_callbacks_(struct evbuffer* buffer, struct event_callback** cbs, int max_cbs); + +#ifdef __cplusplus +} +#endif + +#endif /* EVBUFFER_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/evconfig-internal.h b/asynio/event/evconfig-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..c80591d94de838f28b8849d68c831836668279cb --- /dev/null +++ b/asynio/event/evconfig-internal.h @@ -0,0 +1,41 @@ +#ifndef _EV_CONFIG_INTERNAL_H_ +#define _EV_CONFIG_INTERNAL_H_ + +#ifdef _WIN32 +#include "queue-internal.h" +#endif + +#include "defer-internal.h" +#include "evthread-internal.h" +#include "thread-internal.h" + +#define HT_NO_CACHE_HASH_VALUES +#include "ht-internal.h" + +#include "thread-internal.h" +#include "log-internal.h" +#include "util-internal.h" +#include "defer-internal.h" +#include "minheap-internal.h" +#include "evsignal-internal.h" +#include "mm-internal.h" +#include "evmap-internal.h" +#include "ratelim-internal.h" + +#include "evbuffer-internal.h" + +#include "bufferevent-internal.h" +#include "evmap-internal.h" +#include "event-internal.h" +#include "changelist-internal.h" +#include "ipv6-internal.h" + +#ifdef _WIN32 +#include "iocp-internal.h" +#endif + +#ifdef EVENT__HAVE_WORKING_KQUEUE +#include "kqueue-internal.h" +#endif + +#endif diff --git a/asynio/event/evconfig-private.h b/asynio/event/evconfig-private.h new file mode 100644 index 0000000000000000000000000000000000000000..1b14bc8f5f855c6a1dc7d4bcbd1b8a5ce900b193 --- /dev/null +++ b/asynio/event/evconfig-private.h @@ -0,0 +1,35 @@ + +#ifndef EVCONFIG_PRIVATE_H_INCLUDED_ +#define EVCONFIG_PRIVATE_H_INCLUDED_ + +/* Enable extensions on AIX 3, Interix. */ +/* #undef _ALL_SOURCE */ + +/* Enable GNU extensions on systems that have them. */ +/* #undef _GNU_SOURCE */ + +/* Enable threading extensions on Solaris. */ +/* #undef _POSIX_PTHREAD_SEMANTICS */ + +/* Enable extensions on HP NonStop. */ +/* #undef _TANDEM_SOURCE */ + +/* Enable general extensions on Solaris. */ +/* #undef __EXTENSIONS__ */ + +/* Number of bits in a file offset, on hosts where this is settable. */ +/* #undef _FILE_OFFSET_BITS */ +/* Define for large files, on AIX-style hosts. */ +/* #undef _LARGE_FILES */ + +/* Define to 1 if on MINIX. */ +/* #undef _MINIX */ + +/* Define to 2 if the system does not provide POSIX.1 features except with + this defined. */ +/* #undef _POSIX_1_SOURCE */ + +/* Define to 1 if you need to in order for `stat' and other things to work. */ +/* #undef _POSIX_SOURCE */ + +#endif diff --git a/asynio/event/evconfig.h b/asynio/event/evconfig.h new file mode 100644 index 0000000000000000000000000000000000000000..11ae6d0b848e25e88bf2e3537c19a46b1420e7c2 --- /dev/null +++ b/asynio/event/evconfig.h @@ -0,0 +1,7 @@ +#ifndef _EV_CONFIG_H_ +#define _EV_CONFIG_H_ + +#include "event-config.h" +#include "evconfig-private.h" + +#endif diff --git a/asynio/event/event-config.h b/asynio/event/event-config.h new file mode 100644 index 0000000000000000000000000000000000000000..04e4264c35af368da6ec3e18d1c99b2ac4f61fe1 --- /dev/null +++ b/asynio/event/event-config.h @@ -0,0 +1,531 @@ +/* event-config.h + * + * This file was generated by cmake when the makefiles were generated. + * + * DO NOT EDIT THIS FILE. + * + * Do not rely on macros in this file existing in later versions. + */ +#ifndef EVENT2_EVENT_CONFIG_H_INCLUDED_ +#define EVENT2_EVENT_CONFIG_H_INCLUDED_ + +/* Numeric representation of the version */ +#define EVENT__NUMERIC_VERSION 0x02010800 +#define EVENT__PACKAGE_VERSION "2.1.8" + +#define EVENT__VERSION_MAJOR 2 +#define EVENT__VERSION_MINOR 1 +#define EVENT__VERSION_PATCH 8 + +/* Version number of package */ +#define EVENT__VERSION "2.1.8-beta" + +/* Name of package */ +#define EVENT__PACKAGE "libevent" + +/* Define to the address where bug reports for this package should be sent. */ +#define EVENT__PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define EVENT__PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define EVENT__PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define EVENT__PACKAGE_TARNAME "" + +/* Define if libevent should build without support for a debug mode */ +/* #undef EVENT__DISABLE_DEBUG_MODE */ + +/* Define if libevent should not allow replacing the mm functions */ +/* #undef EVENT__DISABLE_MM_REPLACEMENT */ + +/* Define if libevent should not be compiled with thread support */ +/* #undef EVENT__DISABLE_THREAD_SUPPORT */ + +/* Define to 1 if you have the `accept4' function. */ +/* #undef EVENT__HAVE_ACCEPT4 */ + +/* Define to 1 if you have the `arc4random' function. */ +#define EVENT__HAVE_ARC4RANDOM + +/* Define to 1 if you have the `arc4random_buf' function. */ +#define EVENT__HAVE_ARC4RANDOM_BUF + +/* Define if clock_gettime is available in libc */ +#define EVENT__DNS_USE_CPU_CLOCK_FOR_ID + +/* Define is no secure id variant is available */ +/* #undef EVENT__DNS_USE_GETTIMEOFDAY_FOR_ID */ +/* #undef EVENT__DNS_USE_FTIME_FOR_ID */ + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_ARPA_INET_H + +/* Define to 1 if you have the `clock_gettime' function. */ +#define EVENT__HAVE_CLOCK_GETTIME + +/* Define to 1 if you have the declaration of `CTL_KERN'. */ +#define EVENT__HAVE_DECL_CTL_KERN + +/* Define to 1 if you have the declaration of `KERN_ARND'. */ +/* #undef EVENT__HAVE_DECL_KERN_ARND */ + +/* Define to 1 if you have the declaration of `KERN_RANDOM'. */ +/* #undef EVENT__HAVE_DECL_KERN_RANDOM */ + +/* Define if /dev/poll is available */ +/* #undef EVENT__HAVE_DEVPOLL */ + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_NETDB_H + +/* Define to 1 if fd_mask type is defined */ +#define EVENT__HAVE_FD_MASK + +/* Define to 1 if the header file defines TAILQ_FOREACH. */ +#define EVENT__HAVE_TAILQFOREACH + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_DLFCN_H + +/* Define if your system supports the epoll system calls */ +/* #undef EVENT__HAVE_EPOLL */ + +/* Define to 1 if you have the `epoll_create1' function. */ +/* #undef EVENT__HAVE_EPOLL_CREATE1 */ + +/* Define to 1 if you have the `epoll_ctl' function. */ +/* #undef EVENT__HAVE_EPOLL_CTL */ + +/* Define to 1 if you have the `eventfd' function. */ +/* #undef EVENT__HAVE_EVENTFD */ + +/* Define if your system supports event ports */ +/* #undef EVENT__HAVE_EVENT_PORTS */ + +/* Define to 1 if you have the `fcntl' function. */ +#define EVENT__HAVE_FCNTL + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_FCNTL_H + +/* Define to 1 if you have the `getaddrinfo' function. */ +#define EVENT__HAVE_GETADDRINFO + +/* Define to 1 if you have the `getegid' function. */ +#define EVENT__HAVE_GETEGID + +/* Define to 1 if you have the `geteuid' function. */ +#define EVENT__HAVE_GETEUID + +/* TODO: Check for different gethostname argument counts. CheckPrototypeDefinition.cmake can be used. */ +/* Define this if you have any gethostbyname_r() */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R */ + +/* Define this if gethostbyname_r takes 3 arguments */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_3_ARG */ + +/* Define this if gethostbyname_r takes 5 arguments */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_5_ARG */ + +/* Define this if gethostbyname_r takes 6 arguments */ +/* #undef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG */ + +/* Define to 1 if you have the `getifaddrs' function. */ +#define EVENT__HAVE_GETIFADDRS + +/* Define to 1 if you have the `getnameinfo' function. */ +#define EVENT__HAVE_GETNAMEINFO + +/* Define to 1 if you have the `getprotobynumber' function. */ +#define EVENT__HAVE_GETPROTOBYNUMBER + +/* Define to 1 if you have the `getservbyname' function. */ +#define EVENT__HAVE_GETSERVBYNAME + +/* Define to 1 if you have the `gettimeofday' function. */ +#define EVENT__HAVE_GETTIMEOFDAY + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_IFADDRS_H + +/* Define to 1 if you have the `inet_ntop' function. */ +#define EVENT__HAVE_INET_NTOP + +/* Define to 1 if you have the `inet_pton' function. */ +#define EVENT__HAVE_INET_PTON + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_INTTYPES_H + +/* Define to 1 if you have the `issetugid' function. */ +#define EVENT__HAVE_ISSETUGID + +/* Define to 1 if you have the `kqueue' function. */ +#define EVENT__HAVE_KQUEUE + +/* Define if the system has zlib */ +/* #undef EVENT__HAVE_LIBZ */ + +/* Define to 1 if you have the `mach_absolute_time' function. */ +#define EVENT__HAVE_MACH_ABSOLUTE_TIME + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_MACH_MACH_TIME_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_MEMORY_H + +/* Define to 1 if you have the `mmap' function. */ +#define EVENT__HAVE_MMAP + +/* Define to 1 if you have the `nanosleep' function. */ +#define EVENT__HAVE_NANOSLEEP + +/* Define to 1 if you have the `usleep' function. */ +#define EVENT__HAVE_USLEEP + +/* Define to 1 if you have the header file. */ +/* #undef EVENT__HAVE_NETINET_IN6_H */ + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_NETINET_IN_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_NETINET_TCP_H + +/* Define if the system has openssl */ +/* #undef EVENT__HAVE_OPENSSL */ + +/* Define to 1 if you have the `pipe' function. */ +#define EVENT__HAVE_PIPE + +/* Define to 1 if you have the `pipe2' function. */ +/* #undef EVENT__HAVE_PIPE2 */ + +/* Define to 1 if you have the `poll' function. */ +#define EVENT__HAVE_POLL + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_POLL_H + +/* Define to 1 if you have the `port_create' function. */ +/* #undef EVENT__HAVE_PORT_CREATE */ + +/* Define to 1 if you have the header file. */ +/* #undef EVENT__HAVE_PORT_H */ + +/* Define if we have pthreads on this system */ +#define EVENT__HAVE_PTHREADS + +/* Define to 1 if you have the `putenv' function. */ +#define EVENT__HAVE_PUTENV + +/* Define to 1 if the system has the type `sa_family_t'. */ +#define EVENT__HAVE_SA_FAMILY_T + +/* Define to 1 if you have the `select' function. */ +#define EVENT__HAVE_SELECT + +/* Define to 1 if you have the `setenv' function. */ +#define EVENT__HAVE_SETENV + +/* Define if F_SETFD is defined in */ +#define EVENT__HAVE_SETFD + +/* Define to 1 if you have the `setrlimit' function. */ +#define EVENT__HAVE_SETRLIMIT + +/* Define to 1 if you have the `sendfile' function. */ +#define EVENT__HAVE_SENDFILE + +/* Define if F_SETFD is defined in */ +#define EVENT__HAVE_SETFD + +/* Define to 1 if you have the `sigaction' function. */ +#define EVENT__HAVE_SIGACTION + +/* Define to 1 if you have the `signal' function. */ +#define EVENT__HAVE_SIGNAL + +/* Define to 1 if you have the `splice' function. */ +/* #undef EVENT__HAVE_SPLICE */ + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_STDARG_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_STDDEF_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_STRING_H + +/* Define to 1 if you have the `strlcpy' function. */ +#define EVENT__HAVE_STRLCPY + +/* Define to 1 if you have the `strsep' function. */ +#define EVENT__HAVE_STRSEP + +/* Define to 1 if you have the `strtok_r' function. */ +#define EVENT__HAVE_STRTOK_R + +/* Define to 1 if you have the `strtoll' function. */ +#define EVENT__HAVE_STRTOLL + +/* Define to 1 if the system has the type `struct addrinfo'. */ +#define EVENT__HAVE_STRUCT_ADDRINFO + +/* Define to 1 if the system has the type `struct in6_addr'. */ +#define EVENT__HAVE_STRUCT_IN6_ADDR + +/* Define to 1 if `s6_addr16' is member of `struct in6_addr'. */ +/* #undef EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16 */ + +/* Define to 1 if `s6_addr32' is member of `struct in6_addr'. */ +/* #undef EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32 */ + +/* Define to 1 if the system has the type `struct sockaddr_in6'. */ +#define EVENT__HAVE_STRUCT_SOCKADDR_IN6 + +/* Define to 1 if `sin6_len' is member of `struct sockaddr_in6'. */ +#define EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN + +/* Define to 1 if `sin_len' is member of `struct sockaddr_in'. */ +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ + +/* Define to 1 if the system has the type `struct sockaddr_storage'. */ +#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE + +/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */ +#define EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY + +/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */ +/* #undef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */ + +/* Define to 1 if you have the `sysctl' function. */ +#define EVENT__HAVE_SYSCTL + +/* Define to 1 if you have the header file. */ +/* #undef EVENT__HAVE_SYS_DEVPOLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef EVENT__HAVE_SYS_EPOLL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef EVENT__HAVE_SYS_EVENTFD_H */ + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_EVENT_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_IOCTL_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_MMAN_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_PARAM_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_QUEUE_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_RESOURCE_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_SELECT_H + +/* Define to 1 if you have the header file. */ +/* #undef EVENT__HAVE_SYS_SENDFILE_H */ + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_SYSCTL_H + +/* Define to 1 if you have the header file. */ +/* #undef EVENT__HAVE_SYS_TIMERFD_H */ + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_TIME_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_UIO_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_SYS_WAIT_H + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_ERRNO_H + +/* Define if TAILQ_FOREACH is defined in */ +#define EVENT__HAVE_TAILQFOREACH + +/* Define if timeradd is defined in */ +/* #undef EVENT__HAVE_TIMERADD */ + +/* Define if timerclear is defined in */ +/* #undef EVENT__HAVE_TIMERCLEAR */ + +/* Define if timercmp is defined in */ +/* #undef EVENT__HAVE_TIMERCMP */ + +/* Define to 1 if you have the `timerfd_create' function. */ +/* #undef EVENT__HAVE_TIMERFD_CREATE */ + +/* Define if timerisset is defined in */ +/* #undef EVENT__HAVE_TIMERISSET */ + +/* Define to 1 if the system has the type `uint8_t'. */ +#define EVENT__HAVE_UINT8_T + +/* Define to 1 if the system has the type `uint16_t'. */ +#define EVENT__HAVE_UINT16_T + +/* Define to 1 if the system has the type `uint32_t'. */ +#define EVENT__HAVE_UINT32_T + +/* Define to 1 if the system has the type `uint64_t'. */ +#define EVENT__HAVE_UINT64_T + +/* Define to 1 if the system has the type `uintptr_t'. */ +#define EVENT__HAVE_UINTPTR_T + +/* Define to 1 if you have the `umask' function. */ +#define EVENT__HAVE_UMASK + +/* Define to 1 if you have the header file. */ +#define EVENT__HAVE_UNISTD_H + +/* Define to 1 if you have the `unsetenv' function. */ +#define EVENT__HAVE_UNSETENV + +/* Define to 1 if you have the `vasprintf' function. */ +#define EVENT__HAVE_VASPRINTF + +/* Define if kqueue works correctly with pipes */ +#define EVENT__HAVE_WORKING_KQUEUE + +#ifdef __USE_UNUSED_DEFINITIONS__ +/* Define to necessary symbol if this constant uses a non-standard name on your system. */ +/* XXX: Hello, this isn't even used, nor is it defined anywhere... - Ellzey */ +#define EVENT__PTHREAD_CREATE_JOINABLE +#endif + +/* The size of `pthread_t', as computed by sizeof. */ +#define EVENT__SIZEOF_PTHREAD_T 8 + +/* The size of a `int', as computed by sizeof. */ +#define EVENT__SIZEOF_INT 4 + +/* The size of a `long', as computed by sizeof. */ +#define EVENT__SIZEOF_LONG 8 + +/* The size of a `long long', as computed by sizeof. */ +#define EVENT__SIZEOF_LONG_LONG 8 + +/* The size of `off_t', as computed by sizeof. */ +#define EVENT__SIZEOF_OFF_T 8 + +#define EVENT__SIZEOF_SSIZE_T 8 + +/* The size of a `short', as computed by sizeof. */ +#define EVENT__SIZEOF_SHORT 2 + +/* The size of `size_t', as computed by sizeof. */ +#define EVENT__SIZEOF_SIZE_T 4 + +/* Define to 1 if you have the ANSI C header files. */ +/* #undef EVENT__STDC_HEADERS */ + +/* Define to 1 if you can safely include both and . */ +/* #undef EVENT__TIME_WITH_SYS_TIME */ + +/* The size of `socklen_t', as computed by sizeof. */ +#define EVENT__SIZEOF_SOCKLEN_T 4 + +/* The size of 'void *', as computer by sizeof */ +#define EVENT__SIZEOF_VOID_P 8 + +/* set an alias for whatever __func__ __FUNCTION__ is, what sillyness */ +#if defined(__func__) +#define EVENT____func__ __func__ +#elif defined(__FUNCTION__) +#define EVENT____func__ __FUNCTION__ +#else +#define EVENT____func__ __FILE__ +#endif + +#ifdef __THESE_ARE_NOT_CONFIG_H_THINGS_THEY_ARE_DASH_D_THINGS__ +/* Number of bits in a file offset, on hosts where this is settable. */ +/* Ellzey is not satisfied */ +#define EVENT___FILE_OFFSET_BITS + +/* Define for large files, on AIX-style hosts. */ +#define +#endif + +#ifdef _WhAT_DOES_THIS_EVEN_DO_ +/* Define to empty if `const' does not conform to ANSI C. */ +/* lolwut? - ellzey */ +#undef EVENT__const +#endif + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* why not c++? + * + * and are we really expected to use EVENT__inline everywhere, + * shouldn't we just do: + * ifdef EVENT__inline + * define inline EVENT__inline + * + * - Ellzey + */ + +#define EVENT__inline inline +#endif + +/* Define to `int' if does not define. */ +#define EVENT__pid_t pid_t + +/* Define to `unsigned' if does not define. */ +#define EVENT__size_t unsigned + +/* Define to unsigned int if you dont have it */ +#define EVENT__socklen_t socklen_t + +/* Define to `int' if does not define. */ +#define EVENT__ssize_t ssize_t + +/* #undef EVENT__NEED_DLLIMPORT */ + +/* Define to 1 if you have ERR_remove_thread_stat(). */ +/* #undef EVENT__HAVE_ERR_REMOVE_THREAD_STATE */ + +/* Define if waitpid() supports WNOWAIT */ +/* #undef EVENT__HAVE_WAITPID_WITH_WNOWAIT */ + + +#define EVENT__HAVE_MBEDTLS + +#endif diff --git a/asynio/event/event-internal.h b/asynio/event/event-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..d8b2130f1eecb724827cd0752213138d1d6acfbd --- /dev/null +++ b/asynio/event/event-internal.h @@ -0,0 +1,465 @@ +/* + * Copyright (c) 2000-2007 Niels Provos + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT_INTERNAL_H_INCLUDED_ +#define EVENT_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#include + +#include "event_struct.h" +#include "minheap-internal.h" +#include "evsignal-internal.h" +#include "mm-internal.h" +#include "defer-internal.h" + +/* map union members back */ + +/* mutually exclusive */ +#define ev_signal_next ev_.ev_signal.ev_signal_next +#define ev_io_next ev_.ev_io.ev_io_next +#define ev_io_timeout ev_.ev_io.ev_timeout + +/* used only by signals */ +#define ev_ncalls ev_.ev_signal.ev_ncalls +#define ev_pncalls ev_.ev_signal.ev_pncalls + +#define ev_pri ev_evcallback.evcb_pri +#define ev_flags ev_evcallback.evcb_flags +#define ev_closure ev_evcallback.evcb_closure +#define ev_callback ev_evcallback.evcb_cb_union.evcb_callback +#define ev_arg ev_evcallback.evcb_arg + +/** @name Event closure codes + + Possible values for evcb_closure in struct event_callback + + @{ + */ +/** A regular event. Uses the evcb_callback callback */ +#define EV_CLOSURE_EVENT 0 +/** A signal event. Uses the evcb_callback callback */ +#define EV_CLOSURE_EVENT_SIGNAL 1 +/** A persistent non-signal event. Uses the evcb_callback callback */ +#define EV_CLOSURE_EVENT_PERSIST 2 +/** A simple callback. Uses the evcb_selfcb callback. */ +#define EV_CLOSURE_CB_SELF 3 +/** A finalizing callback. Uses the evcb_cbfinalize callback. */ +#define EV_CLOSURE_CB_FINALIZE 4 +/** A finalizing event. Uses the evcb_evfinalize callback. */ +#define EV_CLOSURE_EVENT_FINALIZE 5 +/** A finalizing event that should get freed after. Uses the evcb_evfinalize + * callback. */ +#define EV_CLOSURE_EVENT_FINALIZE_FREE 6 +/** @} */ + +/** Structure to define the backend of a given event_base. */ +struct eventop { + /** The name of this backend. */ + const char* name; + /** Function to set up an event_base to use this backend. It should + * create a new structure holding whatever information is needed to + * run the backend, and return it. The returned pointer will get + * stored by event_init into the event_base.evbase field. On failure, + * this function should return NULL. */ + void* (*init)(struct event_base*); + /** Enable reading/writing on a given fd or signal. 'events' will be + * the events that we're trying to enable: one or more of EV_READ, + * EV_WRITE, EV_SIGNAL, and EV_ET. 'old' will be those events that + * were enabled on this fd previously. 'fdinfo' will be a structure + * associated with the fd by the evmap; its size is defined by the + * fdinfo field below. It will be set to 0 the first time the fd is + * added. The function should return 0 on success and -1 on error. + */ + int (*add)(struct event_base*, evutil_socket_t fd, short old, short events, void* fdinfo); + /** As "add", except 'events' contains the events we mean to disable. */ + int (*del)(struct event_base*, evutil_socket_t fd, short old, short events, void* fdinfo); + /** Function to implement the core of an event loop. It must see which + added events are ready, and cause event_active to be called for each + active event (usually via event_io_active or such). It should + return 0 on success and -1 on error. + */ + int (*dispatch)(struct event_base*, struct timeval*); + /** Function to clean up and free our data from the event_base. */ + void (*dealloc)(struct event_base*); + /** Flag: set if we need to reinitialize the event base after we fork. + */ + int need_reinit; + /** Bit-array of supported event_method_features that this backend can + * provide. */ + enum event_method_feature features; + /** Length of the extra information we should record for each fd that + has one or more active events. This information is recorded + as part of the evmap entry for each fd, and passed as an argument + to the add and del functions above. + */ + size_t fdinfo_len; +}; + +#ifdef _WIN32 +/* If we're on win32, then file descriptors are not nice low densely packed + integers. Instead, they are pointer-like windows handles, and we want to + use a hashtable instead of an array to map fds to events. +*/ +#define EVMAP_USE_HT +#endif + +/* #define HT_CACHE_HASH_VALS */ + +#ifdef EVMAP_USE_HT +#define HT_NO_CACHE_HASH_VALUES +#include "ht-internal.h" +struct event_map_entry; +HT_HEAD(event_io_map, event_map_entry); +#else +#define event_io_map event_signal_map +#endif + +/* Used to map signal numbers to a list of events. If EVMAP_USE_HT is not + defined, this structure is also used as event_io_map, which maps fds to a + list of events. +*/ +struct event_signal_map { + /* An array of evmap_io * or of evmap_signal *; empty entries are + * set to NULL. */ + void** entries; + /* The number of entries available in entries */ + int nentries; +}; + +/* A list of events waiting on a given 'common' timeout value. Ordinarily, + * events waiting for a timeout wait on a minheap. Sometimes, however, a + * queue can be faster. + **/ +struct common_timeout_list { + /* List of events currently waiting in the queue. */ + struct event_list events; + /* 'magic' timeval used to indicate the duration of events in this + * queue. */ + struct timeval duration; + /* Event that triggers whenever one of the events in the queue is + * ready to activate */ + struct event timeout_event; + /* The event_base that this timeout list is part of */ + struct event_base* base; +}; + +/** Mask used to get the real tv_usec value from a common timeout. */ +#define COMMON_TIMEOUT_MICROSECONDS_MASK 0x000fffff + +struct event_change; + +/* List of 'changes' since the last call to eventop.dispatch. Only maintained + * if the backend is using changesets. */ +struct event_changelist { + struct event_change* changes; + int n_changes; + int changes_size; +}; + +#ifndef EVENT__DISABLE_DEBUG_MODE +/* Global internal flag: set to one if debug mode is on. */ +extern int event_debug_mode_on_; +#define EVENT_DEBUG_MODE_IS_ON() (event_debug_mode_on_) +#else +#define EVENT_DEBUG_MODE_IS_ON() (0) +#endif + +TAILQ_HEAD(evcallback_list, event_callback); + +/* Sets up an event for processing once */ +struct event_once { + LIST_ENTRY(event_once) next_once; + struct event ev; + + void (*cb)(evutil_socket_t, short, void*); + void* arg; +}; + +struct event_base { + /** Function pointers and other data to describe this event_base's + * backend. */ + const struct eventop* evsel; + /** Pointer to backend-specific data. */ + void* evbase; + + /** List of changes to tell backend about at next dispatch. Only used + * by the O(1) backends. */ + struct event_changelist changelist; + + /** Function pointers used to describe the backend that this event_base + * uses for signals */ + const struct eventop* evsigsel; + /** Data to implement the common signal handelr code. */ + struct evsig_info sig; + + /** Number of virtual events */ + int virtual_event_count; + /** Maximum number of virtual events active */ + int virtual_event_count_max; + /** Number of total events added to this event_base */ + int event_count; + /** Maximum number of total events added to this event_base */ + int event_count_max; + /** Number of total events active in this event_base */ + int event_count_active; + /** Maximum number of total events active in this event_base */ + int event_count_active_max; + + /** Set if we should terminate the loop once we're done processing + * events. */ + int event_gotterm; + /** Set if we should terminate the loop immediately */ + int event_break; + /** Set if we should start a new instance of the loop immediately. */ + int event_continue; + + /** The currently running priority of events */ + int event_running_priority; + + /** Set if we're running the event_base_loop function, to prevent + * reentrant invocation. */ + int running_loop; + + /** Set to the number of deferred_cbs we've made 'active' in the + * loop. This is a hack to prevent starvation; it would be smarter + * to just use event_config_set_max_dispatch_interval's max_callbacks + * feature */ + int n_deferreds_queued; + + /* Active event management. */ + /** An array of nactivequeues queues for active event_callbacks (ones + * that have triggered, and whose callbacks need to be called). Low + * priority numbers are more important, and stall higher ones. + */ + struct evcallback_list* activequeues; + /** The length of the activequeues array */ + int nactivequeues; + /** A list of event_callbacks that should become active the next time + * we process events, but not this time. */ + struct evcallback_list active_later_queue; + + /* common timeout logic */ + + /** An array of common_timeout_list* for all of the common timeout + * values we know. */ + struct common_timeout_list** common_timeout_queues; + /** The number of entries used in common_timeout_queues */ + int n_common_timeouts; + /** The total size of common_timeout_queues. */ + int n_common_timeouts_allocated; + + /** Mapping from file descriptors to enabled (added) events */ + struct event_io_map io; + + /** Mapping from signal numbers to enabled (added) events. */ + struct event_signal_map sigmap; + + /** Priority queue of events with timeouts. */ + struct min_heap timeheap; + + /** Stored timeval: used to avoid calling gettimeofday/clock_gettime + * too often. */ + struct timeval tv_cache; + + struct evutil_monotonic_timer monotonic_timer; + + /** Difference between internal time (maybe from clock_gettime) and + * gettimeofday. */ + struct timeval tv_clock_diff; + /** Second in which we last updated tv_clock_diff, in monotonic time. */ + time_t last_updated_clock_diff; + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + /* threading support */ + /** The thread currently running the event_loop for this base */ + unsigned long th_owner_id; + /** A lock to prevent conflicting accesses to this event_base */ + void* th_base_lock; + /** A condition that gets signalled when we're done processing an + * event with waiters on it. */ + void* current_event_cond; + /** Number of threads blocking on current_event_cond. */ + int current_event_waiters; +#endif + /** The event whose callback is executing right now */ + struct event_callback* current_event; + +#ifdef _WIN32 + /** IOCP support structure, if IOCP is enabled. */ + struct event_iocp_port* iocp; +#endif + + /** Flags that this base was configured with */ + enum event_base_config_flag flags; + + struct timeval max_dispatch_time; + int max_dispatch_callbacks; + int limit_callbacks_after_prio; + + /* Notify main thread to wake up break, etc. */ + /** True if the base already has a pending notify, and we don't need + * to add any more. */ + int is_notify_pending; + /** A socketpair used by some th_notify functions to wake up the main + * thread. */ + evutil_socket_t th_notify_fd[2]; + /** An event used by some th_notify functions to wake up the main + * thread. */ + struct event th_notify; + /** A function used to wake up the main thread from another thread. */ + int (*th_notify_fn)(struct event_base* base); + + /** Saved seed for weak random number generator. Some backends use + * this to produce fairness among sockets. Protected by th_base_lock. */ + struct evutil_weakrand_state weakrand_seed; + + /** List of event_onces that have not yet fired. */ + LIST_HEAD(once_event_list, event_once) once_events; +}; + +struct event_config_entry { + TAILQ_ENTRY(event_config_entry) next; + + const char* avoid_method; +}; + +/** Internal structure: describes the configuration we want for an event_base + * that we're about to allocate. */ +struct event_config { + TAILQ_HEAD(event_configq, event_config_entry) entries; + + int n_cpus_hint; + struct timeval max_dispatch_interval; + int max_dispatch_callbacks; + int limit_callbacks_after_prio; + enum event_method_feature require_features; + enum event_base_config_flag flags; +}; + +/* Internal use only: Functions that might be missing from */ +#ifndef TAILQ_FIRST +#define TAILQ_FIRST(head) ((head)->tqh_first) +#endif +#ifndef TAILQ_END +#define TAILQ_END(head) NULL +#endif +#ifndef TAILQ_NEXT +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#endif + +#ifndef TAILQ_FOREACH +#define TAILQ_FOREACH(var, head, field) for ((var) = TAILQ_FIRST(head); (var) != TAILQ_END(head); (var) = TAILQ_NEXT(var, field)) +#endif + +#ifndef TAILQ_INSERT_BEFORE +#define TAILQ_INSERT_BEFORE(listelm, elm, field) \ + do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ + } while (0) +#endif + +#define N_ACTIVE_CALLBACKS(base) ((base)->event_count_active) + +int evsig_set_handler_(struct event_base* base, int evsignal, void (*fn)(int)); +int evsig_restore_handler_(struct event_base* base, int evsignal); + +int event_add_nolock_(struct event* ev, const struct timeval* tv, int tv_is_absolute); +/** Argument for event_del_nolock_. Tells event_del not to block on the event + * if it's running in another thread. */ +#define EVENT_DEL_NOBLOCK 0 +/** Argument for event_del_nolock_. Tells event_del to block on the event + * if it's running in another thread, regardless of its value for EV_FINALIZE + */ +#define EVENT_DEL_BLOCK 1 +/** Argument for event_del_nolock_. Tells event_del to block on the event + * if it is running in another thread and it doesn't have EV_FINALIZE set. + */ +#define EVENT_DEL_AUTOBLOCK 2 +/** Argument for event_del_nolock_. Tells event_del to procede even if the + * event is set up for finalization rather for regular use.*/ +#define EVENT_DEL_EVEN_IF_FINALIZING 3 +int event_del_nolock_(struct event* ev, int blocking); +int event_remove_timer_nolock_(struct event* ev); + +void event_active_nolock_(struct event* ev, int res, short count); +int event_callback_activate_(struct event_base*, struct event_callback*); +int event_callback_activate_nolock_(struct event_base*, struct event_callback*); +int event_callback_cancel_(struct event_base* base, struct event_callback* evcb); + +void event_callback_finalize_nolock_(struct event_base* base, unsigned flags, struct event_callback* evcb, void (*cb)(struct event_callback*, void*)); +void event_callback_finalize_(struct event_base* base, unsigned flags, struct event_callback* evcb, void (*cb)(struct event_callback*, void*)); +int event_callback_finalize_many_(struct event_base* base, int n_cbs, struct event_callback** evcb, void (*cb)(struct event_callback*, void*)); + +void event_active_later_(struct event* ev, int res); +void event_active_later_nolock_(struct event* ev, int res); +int event_callback_activate_later_nolock_(struct event_base* base, struct event_callback* evcb); +int event_callback_cancel_nolock_(struct event_base* base, struct event_callback* evcb, int even_if_finalizing); +void event_callback_init_(struct event_base* base, struct event_callback* cb); + +/* FIXME document. */ +void event_base_add_virtual_(struct event_base* base); +void event_base_del_virtual_(struct event_base* base); + +/** For debugging: unless assertions are disabled, verify the referential + integrity of the internal data structures of 'base'. This operation can + be expensive. + + Returns on success; aborts on failure. +*/ +void event_base_assert_ok_(struct event_base* base); +void event_base_assert_ok_nolock_(struct event_base* base); + +/* Helper function: Call 'fn' exactly once every inserted or active event in + * the event_base 'base'. + * + * If fn returns 0, continue on to the next event. Otherwise, return the same + * value that fn returned. + * + * Requires that 'base' be locked. + */ +int event_base_foreach_event_nolock_(struct event_base* base, event_base_foreach_event_cb cb, void* arg); + +/* Cleanup function to reset debug mode during shutdown. + * + * Calling this function doesn't mean it'll be possible to re-enable + * debug mode if any events were added. + */ +void event_disable_debug_mode(void); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/event.c b/asynio/event/event.c new file mode 100644 index 0000000000000000000000000000000000000000..22d22ba8e7eb1ae2fcfa48b41b962bcb32e4ce04 --- /dev/null +++ b/asynio/event/event.c @@ -0,0 +1,3553 @@ +/* + * Copyright (c) 2000-2007 Niels Provos + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef _WIN32 +#include +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#endif +#include +#if !defined(_WIN32) && defined(EVENT__HAVE_SYS_TIME_H) +#include +#endif +#include +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif +#include +#include +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "eventbase.h" +#include "event_struct.h" +#include "event_compat.h" + +#include "evconfig-internal.h" + +/* +#include "event-internal.h" +#include "defer-internal.h" +#include "evthread-internal.h" +#include "thread-internal.h" +#include "util.h" +#include "log-internal.h" +#include "evmap-internal.h" +#include "iocp-internal.h" +#include "changelist-internal.h" +#define HT_NO_CACHE_HASH_VALUES +#include "ht-internal.h" +#include "util-internal.h" +*/ + +#ifdef EVENT__HAVE_EVENT_PORTS +extern const struct eventop evportops; +#endif +#ifdef EVENT__HAVE_SELECT +extern const struct eventop selectops; +#endif +#ifdef EVENT__HAVE_POLL +extern const struct eventop pollops; +#endif +#ifdef EVENT__HAVE_EPOLL +extern const struct eventop epollops; +#endif +#ifdef EVENT__HAVE_WORKING_KQUEUE +extern const struct eventop kqops; +#endif +#ifdef EVENT__HAVE_DEVPOLL +extern const struct eventop devpollops; +#endif +#ifdef _WIN32 +extern const struct eventop win32ops; +#endif + +/* Array of backends in order of preference. */ +static const struct eventop* eventops[] = { +#ifdef EVENT__HAVE_EVENT_PORTS + &evportops, +#endif +#ifdef EVENT__HAVE_WORKING_KQUEUE + &kqops, +#endif +#ifdef EVENT__HAVE_EPOLL + &epollops, +#endif +#ifdef EVENT__HAVE_DEVPOLL + &devpollops, +#endif +#ifdef EVENT__HAVE_POLL + &pollops, +#endif +#ifdef EVENT__HAVE_SELECT + &selectops, +#endif +#ifdef _WIN32 + &win32ops, +#endif + NULL}; + +/* Global state; deprecated */ +struct event_base* event_global_current_base_ = NULL; +#define current_base event_global_current_base_ + +/* Global state */ + +static void* event_self_cbarg_ptr_ = NULL; + +/* Prototypes */ +static void event_queue_insert_active(struct event_base*, struct event_callback*); +static void event_queue_insert_active_later(struct event_base*, struct event_callback*); +static void event_queue_insert_timeout(struct event_base*, struct event*); +static void event_queue_insert_inserted(struct event_base*, struct event*); +static void event_queue_remove_active(struct event_base*, struct event_callback*); +static void event_queue_remove_active_later(struct event_base*, struct event_callback*); +static void event_queue_remove_timeout(struct event_base*, struct event*); +static void event_queue_remove_inserted(struct event_base*, struct event*); +static void event_queue_make_later_events_active(struct event_base* base); + +static int evthread_make_base_notifiable_nolock_(struct event_base* base); +static int event_del_(struct event* ev, int blocking); + +#ifdef USE_REINSERT_TIMEOUT +/* This code seems buggy; only turn it on if we find out what the trouble is. */ +static void event_queue_reinsert_timeout(struct event_base*, struct event*, int was_common, int is_common, int old_timeout_idx); +#endif + +static int event_haveevents(struct event_base*); + +static int event_process_active(struct event_base*); + +static int timeout_next(struct event_base*, struct timeval**); +static void timeout_process(struct event_base*); + +static inline void event_signal_closure(struct event_base*, struct event* ev); +static inline void event_persist_closure(struct event_base*, struct event* ev); + +static int evthread_notify_base(struct event_base* base); + +static void insert_common_timeout_inorder(struct common_timeout_list* ctl, struct event* ev); + +#ifndef EVENT__DISABLE_DEBUG_MODE +/* These functions implement a hashtable of which 'struct event *' structures + * have been setup or added. We don't want to trust the content of the struct + * event itself, since we're trying to work through cases where an event gets + * clobbered or freed. Instead, we keep a hashtable indexed by the pointer. + */ + +struct event_debug_entry { + HT_ENTRY(event_debug_entry) node; + const struct event* ptr; + unsigned added : 1; +}; + +static inline unsigned hash_debug_entry(const struct event_debug_entry* e) +{ + /* We need to do this silliness to convince compilers that we + * honestly mean to cast e->ptr to an integer, and discard any + * part of it that doesn't fit in an unsigned. + */ + unsigned u = (unsigned)((ev_uintptr_t)e->ptr); + /* Our hashtable implementation is pretty sensitive to low bits, + * and every struct event is over 64 bytes in size, so we can + * just say >>6. */ + return (u >> 6); +} + +static inline int eq_debug_entry(const struct event_debug_entry* a, const struct event_debug_entry* b) +{ + return a->ptr == b->ptr; +} + +int event_debug_mode_on_ = 0; + +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) && !defined(EVENT__DISABLE_DEBUG_MODE) +/** + * @brief debug mode variable which is set for any function/structure that needs + * to be shared across threads (if thread support is enabled). + * + * When and if evthreads are initialized, this variable will be evaluated, + * and if set to something other than zero, this means the evthread setup + * functions were called out of order. + * + * See: "Locks and threading" in the documentation. + */ +int event_debug_created_threadable_ctx_ = 0; +#endif + +/* Set if it's too late to enable event_debug_mode. */ +static int event_debug_mode_too_late = 0; +#ifndef EVENT__DISABLE_THREAD_SUPPORT +static void* event_debug_map_lock_ = NULL; +#endif +static HT_HEAD(event_debug_map, event_debug_entry) global_debug_map = HT_INITIALIZER(); + +HT_PROTOTYPE(event_debug_map, event_debug_entry, node, hash_debug_entry, eq_debug_entry) +HT_GENERATE(event_debug_map, event_debug_entry, node, hash_debug_entry, eq_debug_entry, 0.5, mm_malloc, mm_realloc, mm_free) + +/* Macro: record that ev is now setup (that is, ready for an add) */ +#define event_debug_note_setup_(ev) \ + do { \ + if (event_debug_mode_on_) { \ + struct event_debug_entry *dent, find; \ + find.ptr = (ev); \ + EVLOCK_LOCK(event_debug_map_lock_, 0); \ + dent = HT_FIND(event_debug_map, &global_debug_map, &find); \ + if (dent) { \ + dent->added = 0; \ + } else { \ + dent = mm_malloc(sizeof(*dent)); \ + if (!dent) \ + event_err(1, "Out of memory in debugging code"); \ + dent->ptr = (ev); \ + dent->added = 0; \ + HT_INSERT(event_debug_map, &global_debug_map, dent); \ + } \ + EVLOCK_UNLOCK(event_debug_map_lock_, 0); \ + } \ + event_debug_mode_too_late = 1; \ + } while (0) +/* Macro: record that ev is no longer setup */ +#define event_debug_note_teardown_(ev) \ + do { \ + if (event_debug_mode_on_) { \ + struct event_debug_entry *dent, find; \ + find.ptr = (ev); \ + EVLOCK_LOCK(event_debug_map_lock_, 0); \ + dent = HT_REMOVE(event_debug_map, &global_debug_map, &find); \ + if (dent) \ + mm_free(dent); \ + EVLOCK_UNLOCK(event_debug_map_lock_, 0); \ + } \ + event_debug_mode_too_late = 1; \ + } while (0) +/* Macro: record that ev is now added */ +#define event_debug_note_add_(ev) \ + do { \ + if (event_debug_mode_on_) { \ + struct event_debug_entry *dent, find; \ + find.ptr = (ev); \ + EVLOCK_LOCK(event_debug_map_lock_, 0); \ + dent = HT_FIND(event_debug_map, &global_debug_map, &find); \ + if (dent) { \ + dent->added = 1; \ + } else { \ + event_errx( \ + EVENT_ERR_ABORT_, \ + "%s: noting an add on a non-setup event %p" \ + " (events: 0x%x, fd: " EV_SOCK_FMT ", flags: 0x%x)", \ + __func__, (ev), (ev)->ev_events, EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \ + } \ + EVLOCK_UNLOCK(event_debug_map_lock_, 0); \ + } \ + event_debug_mode_too_late = 1; \ + } while (0) +/* Macro: record that ev is no longer added */ +#define event_debug_note_del_(ev) \ + do { \ + if (event_debug_mode_on_) { \ + struct event_debug_entry *dent, find; \ + find.ptr = (ev); \ + EVLOCK_LOCK(event_debug_map_lock_, 0); \ + dent = HT_FIND(event_debug_map, &global_debug_map, &find); \ + if (dent) { \ + dent->added = 0; \ + } else { \ + event_errx( \ + EVENT_ERR_ABORT_, \ + "%s: noting a del on a non-setup event %p" \ + " (events: 0x%x, fd: " EV_SOCK_FMT ", flags: 0x%x)", \ + __func__, (ev), (ev)->ev_events, EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \ + } \ + EVLOCK_UNLOCK(event_debug_map_lock_, 0); \ + } \ + event_debug_mode_too_late = 1; \ + } while (0) +/* Macro: assert that ev is setup (i.e., okay to add or inspect) */ +#define event_debug_assert_is_setup_(ev) \ + do { \ + if (event_debug_mode_on_) { \ + struct event_debug_entry *dent, find; \ + find.ptr = (ev); \ + EVLOCK_LOCK(event_debug_map_lock_, 0); \ + dent = HT_FIND(event_debug_map, &global_debug_map, &find); \ + if (!dent) { \ + event_errx( \ + EVENT_ERR_ABORT_, \ + "%s called on a non-initialized event %p" \ + " (events: 0x%x, fd: " EV_SOCK_FMT ", flags: 0x%x)", \ + __func__, (ev), (ev)->ev_events, EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \ + } \ + EVLOCK_UNLOCK(event_debug_map_lock_, 0); \ + } \ + } while (0) +/* Macro: assert that ev is not added (i.e., okay to tear down or set + * up again) */ +#define event_debug_assert_not_added_(ev) \ + do { \ + if (event_debug_mode_on_) { \ + struct event_debug_entry *dent, find; \ + find.ptr = (ev); \ + EVLOCK_LOCK(event_debug_map_lock_, 0); \ + dent = HT_FIND(event_debug_map, &global_debug_map, &find); \ + if (dent && dent->added) { \ + event_errx( \ + EVENT_ERR_ABORT_, \ + "%s called on an already added event %p" \ + " (events: 0x%x, fd: " EV_SOCK_FMT ", " \ + "flags: 0x%x)", \ + __func__, (ev), (ev)->ev_events, EV_SOCK_ARG((ev)->ev_fd), (ev)->ev_flags); \ + } \ + EVLOCK_UNLOCK(event_debug_map_lock_, 0); \ + } \ + } while (0) +#else +#define event_debug_note_setup_(ev) ((void)0) +#define event_debug_note_teardown_(ev) ((void)0) +#define event_debug_note_add_(ev) ((void)0) +#define event_debug_note_del_(ev) ((void)0) +#define event_debug_assert_is_setup_(ev) ((void)0) +#define event_debug_assert_not_added_(ev) ((void)0) +#endif + +#define EVENT_BASE_ASSERT_LOCKED(base) EVLOCK_ASSERT_LOCKED((base)->th_base_lock) + +/* How often (in seconds) do we check for changes in wall clock time relative + * to monotonic time? Set this to -1 for 'never.' */ +#define CLOCK_SYNC_INTERVAL 5 + +/** Set 'tp' to the current time according to 'base'. We must hold the lock + * on 'base'. If there is a cached time, return it. Otherwise, use + * clock_gettime or gettimeofday as appropriate to find out the right time. + * Return 0 on success, -1 on failure. + */ +static int gettime(struct event_base* base, struct timeval* tp) +{ + EVENT_BASE_ASSERT_LOCKED(base); + + if (base->tv_cache.tv_sec) { + *tp = base->tv_cache; + return (0); + } + + if (evutil_gettime_monotonic_(&base->monotonic_timer, tp) == -1) { + return -1; + } + + if (base->last_updated_clock_diff + CLOCK_SYNC_INTERVAL < tp->tv_sec) { + struct timeval tv; + evutil_gettimeofday(&tv, NULL); + evutil_timersub(&tv, tp, &base->tv_clock_diff); + base->last_updated_clock_diff = tp->tv_sec; + } + + return 0; +} + +int event_base_gettimeofday_cached(struct event_base* base, struct timeval* tv) +{ + int r; + if (!base) { + base = current_base; + if (!current_base) + return evutil_gettimeofday(tv, NULL); + } + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (base->tv_cache.tv_sec == 0) { + r = evutil_gettimeofday(tv, NULL); + } else { + evutil_timeradd(&base->tv_cache, &base->tv_clock_diff, tv); + r = 0; + } + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +/** Make 'base' have no current cached time. */ +static inline void clear_time_cache(struct event_base* base) +{ + base->tv_cache.tv_sec = 0; +} + +/** Replace the cached time in 'base' with the current time. */ +static inline void update_time_cache(struct event_base* base) +{ + base->tv_cache.tv_sec = 0; + if (!(base->flags & EVENT_BASE_FLAG_NO_CACHE_TIME)) + gettime(base, &base->tv_cache); +} + +int event_base_update_cache_time(struct event_base* base) +{ + if (!base) { + base = current_base; + if (!current_base) + return -1; + } + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (base->running_loop) + update_time_cache(base); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return 0; +} + +static inline struct event* event_callback_to_event(struct event_callback* evcb) +{ + EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_INIT)); + return EVUTIL_UPCAST(evcb, struct event, ev_evcallback); +} + +static inline struct event_callback* event_to_event_callback(struct event* ev) +{ + return &ev->ev_evcallback; +} + +struct event_base* event_init(void) +{ + struct event_base* base = event_base_new_with_config(NULL); + + if (base == NULL) { + event_errx(1, "%s: Unable to construct event_base", __func__); + return NULL; + } + + current_base = base; + + return (base); +} + +struct event_base* event_base_new(void) +{ + struct event_base* base = NULL; + struct event_config* cfg = event_config_new(); + if (cfg) { + base = event_base_new_with_config(cfg); + event_config_free(cfg); + } + return base; +} + +/** Return true iff 'method' is the name of a method that 'cfg' tells us to + * avoid. */ +static int event_config_is_avoided_method(const struct event_config* cfg, const char* method) +{ + struct event_config_entry* entry; + + TAILQ_FOREACH(entry, &cfg->entries, next) + { + if (entry->avoid_method != NULL && strcmp(entry->avoid_method, method) == 0) + return (1); + } + + return (0); +} + +/** Return true iff 'method' is disabled according to the environment. */ +static int event_is_method_disabled(const char* name) +{ + char environment[64]; + int i; + + evutil_snprintf(environment, sizeof(environment), "EVENT_NO%s", name); + for (i = 8; environment[i] != '\0'; ++i) + environment[i] = EVUTIL_TOUPPER_(environment[i]); + /* Note that evutil_getenv_() ignores the environment entirely if + * we're setuid */ + return (evutil_getenv_(environment) != NULL); +} + +int event_base_get_features(const struct event_base* base) +{ + return base->evsel->features; +} + +void event_enable_debug_mode(void) +{ +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) + event_errx(1, "%s was called twice!", __func__); + if (event_debug_mode_too_late) + event_errx( + 1, + "%s must be called *before* creating any events " + "or event_bases", + __func__); + + event_debug_mode_on_ = 1; + + HT_INIT(event_debug_map, &global_debug_map); +#endif +} + +void event_disable_debug_mode(void) +{ +#ifndef EVENT__DISABLE_DEBUG_MODE + struct event_debug_entry **ent, *victim; + + EVLOCK_LOCK(event_debug_map_lock_, 0); + for (ent = HT_START(event_debug_map, &global_debug_map); ent;) { + victim = *ent; + ent = HT_NEXT_RMV(event_debug_map, &global_debug_map, ent); + mm_free(victim); + } + HT_CLEAR(event_debug_map, &global_debug_map); + EVLOCK_UNLOCK(event_debug_map_lock_, 0); + + event_debug_mode_on_ = 0; +#endif +} + +struct event_base* event_base_new_with_config(const struct event_config* cfg) +{ + int i; + struct event_base* base; + int should_check_environment; + +#ifndef EVENT__DISABLE_DEBUG_MODE + event_debug_mode_too_late = 1; +#endif + + if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL) { + event_warn("%s: calloc", __func__); + return NULL; + } + + if (cfg) + base->flags = cfg->flags; + + should_check_environment = !(cfg && (cfg->flags & EVENT_BASE_FLAG_IGNORE_ENV)); + + { + struct timeval tmp; + int precise_time = cfg && (cfg->flags & EVENT_BASE_FLAG_PRECISE_TIMER); + int flags; + if (should_check_environment && !precise_time) { + precise_time = evutil_getenv_("EVENT_PRECISE_TIMER") != NULL; + base->flags |= EVENT_BASE_FLAG_PRECISE_TIMER; + } + flags = precise_time ? EV_MONOT_PRECISE : 0; + evutil_configure_monotonic_time_(&base->monotonic_timer, flags); + + gettime(base, &tmp); + } + + min_heap_ctor_(&base->timeheap); + + base->sig.ev_signal_pair[0] = -1; + base->sig.ev_signal_pair[1] = -1; + base->th_notify_fd[0] = -1; + base->th_notify_fd[1] = -1; + + TAILQ_INIT(&base->active_later_queue); + + evmap_io_initmap_(&base->io); + evmap_signal_initmap_(&base->sigmap); + event_changelist_init_(&base->changelist); + + base->evbase = NULL; + + if (cfg) { + memcpy(&base->max_dispatch_time, &cfg->max_dispatch_interval, sizeof(struct timeval)); + base->limit_callbacks_after_prio = cfg->limit_callbacks_after_prio; + } else { + base->max_dispatch_time.tv_sec = -1; + base->limit_callbacks_after_prio = 1; + } + if (cfg && cfg->max_dispatch_callbacks >= 0) { + base->max_dispatch_callbacks = cfg->max_dispatch_callbacks; + } else { + base->max_dispatch_callbacks = INT_MAX; + } + if (base->max_dispatch_callbacks == INT_MAX && base->max_dispatch_time.tv_sec == -1) + base->limit_callbacks_after_prio = INT_MAX; + + for (i = 0; eventops[i] && !base->evbase; i++) { + if (cfg != NULL) { + /* determine if this backend should be avoided */ + if (event_config_is_avoided_method(cfg, eventops[i]->name)) + continue; + if ((eventops[i]->features & cfg->require_features) != cfg->require_features) + continue; + } + + /* also obey the environment variables */ + if (should_check_environment && event_is_method_disabled(eventops[i]->name)) + continue; + + base->evsel = eventops[i]; + + base->evbase = base->evsel->init(base); + } + + if (base->evbase == NULL) { + event_warnx("%s: no event mechanism available", __func__); + base->evsel = NULL; + event_base_free(base); + return NULL; + } + + if (evutil_getenv_("EVENT_SHOW_METHOD")) + event_msgx("libevent using: %s", base->evsel->name); + + /* allocate a single active event queue */ + if (event_base_priority_init(base, 1) < 0) { + event_base_free(base); + return NULL; + } + + /* prepare for threading */ + +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) && !defined(EVENT__DISABLE_DEBUG_MODE) + event_debug_created_threadable_ctx_ = 1; +#endif + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (EVTHREAD_LOCKING_ENABLED() && (!cfg || !(cfg->flags & EVENT_BASE_FLAG_NOLOCK))) { + int r; + EVTHREAD_ALLOC_LOCK(base->th_base_lock, 0); + EVTHREAD_ALLOC_COND(base->current_event_cond); + r = evthread_make_base_notifiable(base); + if (r < 0) { + event_warnx("%s: Unable to make base notifiable.", __func__); + event_base_free(base); + return NULL; + } + } +#endif + +#ifdef _WIN32 + if (cfg && (cfg->flags & EVENT_BASE_FLAG_STARTUP_IOCP)) + event_base_start_iocp_(base, cfg->n_cpus_hint); +#endif + + return (base); +} + +int event_base_start_iocp_(struct event_base* base, int n_cpus) +{ +#ifdef _WIN32 + if (base->iocp) + return 0; + base->iocp = event_iocp_port_launch_(n_cpus); + if (!base->iocp) { + event_warnx("%s: Couldn't launch IOCP", __func__); + return -1; + } + return 0; +#else + return -1; +#endif +} + +void event_base_stop_iocp_(struct event_base* base) +{ +#ifdef _WIN32 + int rv; + + if (!base->iocp) + return; + rv = event_iocp_shutdown_(base->iocp, -1); + EVUTIL_ASSERT(rv >= 0); + base->iocp = NULL; +#endif +} + +static int event_base_cancel_single_callback_(struct event_base* base, struct event_callback* evcb, int run_finalizers) +{ + int result = 0; + + if (evcb->evcb_flags & EVLIST_INIT) { + struct event* ev = event_callback_to_event(evcb); + if (!(ev->ev_flags & EVLIST_INTERNAL)) { + event_del_(ev, EVENT_DEL_EVEN_IF_FINALIZING); + result = 1; + } + } else { + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + event_callback_cancel_nolock_(base, evcb, 1); + EVBASE_RELEASE_LOCK(base, th_base_lock); + result = 1; + } + + if (run_finalizers && (evcb->evcb_flags & EVLIST_FINALIZING)) { + switch (evcb->evcb_closure) { + case EV_CLOSURE_EVENT_FINALIZE: + case EV_CLOSURE_EVENT_FINALIZE_FREE: { + struct event* ev = event_callback_to_event(evcb); + ev->ev_evcallback.evcb_cb_union.evcb_evfinalize(ev, ev->ev_arg); + if (evcb->evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE) + mm_free(ev); + break; + } + case EV_CLOSURE_CB_FINALIZE: + evcb->evcb_cb_union.evcb_cbfinalize(evcb, evcb->evcb_arg); + break; + default: + break; + } + } + return result; +} + +static int event_base_free_queues_(struct event_base* base, int run_finalizers) +{ + int deleted = 0, i; + + for (i = 0; i < base->nactivequeues; ++i) { + struct event_callback *evcb, *next; + for (evcb = TAILQ_FIRST(&base->activequeues[i]); evcb;) { + next = TAILQ_NEXT(evcb, evcb_active_next); + deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); + evcb = next; + } + } + + { + struct event_callback* evcb; + while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { + deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); + } + } + + return deleted; +} + +static void event_base_free_(struct event_base* base, int run_finalizers) +{ + int i, n_deleted = 0; + struct event* ev; + /* XXXX grab the lock? If there is contention when one thread frees + * the base, then the contending thread will be very sad soon. */ + + /* event_base_free(NULL) is how to free the current_base if we + * made it with event_init and forgot to hold a reference to it. */ + if (base == NULL && current_base) + base = current_base; + /* Don't actually free NULL. */ + if (base == NULL) { + event_warnx("%s: no base to free", __func__); + return; + } + /* XXX(niels) - check for internal events first */ + +#ifdef _WIN32 + event_base_stop_iocp_(base); +#endif + + /* threading fds if we have them */ + if (base->th_notify_fd[0] != -1) { + event_del(&base->th_notify); + EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); + if (base->th_notify_fd[1] != -1) + EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); + base->th_notify_fd[0] = -1; + base->th_notify_fd[1] = -1; + event_debug_unassign(&base->th_notify); + } + + /* Delete all non-internal events. */ + evmap_delete_all_(base); + + while ((ev = min_heap_top_(&base->timeheap)) != NULL) { + event_del(ev); + ++n_deleted; + } + for (i = 0; i < base->n_common_timeouts; ++i) { + struct common_timeout_list* ctl = base->common_timeout_queues[i]; + event_del(&ctl->timeout_event); /* Internal; doesn't count */ + event_debug_unassign(&ctl->timeout_event); + for (ev = TAILQ_FIRST(&ctl->events); ev;) { + struct event* next = TAILQ_NEXT(ev, ev_timeout_pos.ev_next_with_common_timeout); + if (!(ev->ev_flags & EVLIST_INTERNAL)) { + event_del(ev); + ++n_deleted; + } + ev = next; + } + mm_free(ctl); + } + if (base->common_timeout_queues) + mm_free(base->common_timeout_queues); + + for (;;) { + /* For finalizers we can register yet another finalizer out from + * finalizer, and iff finalizer will be in active_later_queue we can + * add finalizer to activequeues, and we will have events in + * activequeues after this function returns, which is not what we want + * (we even have an assertion for this). + * + * A simple case is bufferevent with underlying (i.e. filters). + */ + int i = event_base_free_queues_(base, run_finalizers); + if (!i) { + break; + } + n_deleted += i; + } + + if (n_deleted) + event_debug(("%s: %d events were still set in base", __func__, n_deleted)); + + while (LIST_FIRST(&base->once_events)) { + struct event_once* eonce = LIST_FIRST(&base->once_events); + LIST_REMOVE(eonce, next_once); + mm_free(eonce); + } + + if (base->evsel != NULL && base->evsel->dealloc != NULL) + base->evsel->dealloc(base); + + for (i = 0; i < base->nactivequeues; ++i) + EVUTIL_ASSERT(TAILQ_EMPTY(&base->activequeues[i])); + + EVUTIL_ASSERT(min_heap_empty_(&base->timeheap)); + min_heap_dtor_(&base->timeheap); + + mm_free(base->activequeues); + + evmap_io_clear_(&base->io); + evmap_signal_clear_(&base->sigmap); + event_changelist_freemem_(&base->changelist); + + EVTHREAD_FREE_LOCK(base->th_base_lock, 0); + EVTHREAD_FREE_COND(base->current_event_cond); + + /* If we're freeing current_base, there won't be a current_base. */ + if (base == current_base) + current_base = NULL; + mm_free(base); +} + +void event_base_free_nofinalize(struct event_base* base) +{ + event_base_free_(base, 0); +} + +void event_base_free(struct event_base* base) +{ + event_base_free_(base, 1); +} + +/* Fake eventop; used to disable the backend temporarily inside event_reinit + * so that we can call event_del() on an event without telling the backend. + */ +static int nil_backend_del(struct event_base* b, evutil_socket_t fd, short old, short events, void* fdinfo) +{ + return 0; +} +const struct eventop nil_eventop = { + "nil", + NULL, /* init: unused. */ + NULL, /* add: unused. */ + nil_backend_del, /* del: used, so needs to be killed. */ + NULL, /* dispatch: unused. */ + NULL, /* dealloc: unused. */ + 0, + 0, + 0}; + +/* reinitialize the event base after a fork */ +int event_reinit(struct event_base* base) +{ + const struct eventop* evsel; + int res = 0; + int was_notifiable = 0; + int had_signal_added = 0; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + evsel = base->evsel; + + /* check if this event mechanism requires reinit on the backend */ + if (evsel->need_reinit) { + /* We're going to call event_del() on our notify events (the + * ones that tell about signals and wakeup events). But we + * don't actually want to tell the backend to change its + * state, since it might still share some resource (a kqueue, + * an epoll fd) with the parent process, and we don't want to + * delete the fds from _that_ backend, we temporarily stub out + * the evsel with a replacement. + */ + base->evsel = &nil_eventop; + } + + /* We need to re-create a new signal-notification fd and a new + * thread-notification fd. Otherwise, we'll still share those with + * the parent process, which would make any notification sent to them + * get received by one or both of the event loops, more or less at + * random. + */ + if (base->sig.ev_signal_added) { + event_del_nolock_(&base->sig.ev_signal, EVENT_DEL_AUTOBLOCK); + event_debug_unassign(&base->sig.ev_signal); + memset(&base->sig.ev_signal, 0, sizeof(base->sig.ev_signal)); + had_signal_added = 1; + base->sig.ev_signal_added = 0; + } + if (base->sig.ev_signal_pair[0] != -1) + EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); + if (base->sig.ev_signal_pair[1] != -1) + EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); + if (base->th_notify_fn != NULL) { + was_notifiable = 1; + base->th_notify_fn = NULL; + } + if (base->th_notify_fd[0] != -1) { + event_del_nolock_(&base->th_notify, EVENT_DEL_AUTOBLOCK); + EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); + if (base->th_notify_fd[1] != -1) + EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); + base->th_notify_fd[0] = -1; + base->th_notify_fd[1] = -1; + event_debug_unassign(&base->th_notify); + } + + /* Replace the original evsel. */ + base->evsel = evsel; + + if (evsel->need_reinit) { + /* Reconstruct the backend through brute-force, so that we do + * not share any structures with the parent process. For some + * backends, this is necessary: epoll and kqueue, for + * instance, have events associated with a kernel + * structure. If didn't reinitialize, we'd share that + * structure with the parent process, and any changes made by + * the parent would affect our backend's behavior (and vice + * versa). + */ + if (base->evsel->dealloc != NULL) + base->evsel->dealloc(base); + base->evbase = evsel->init(base); + if (base->evbase == NULL) { + event_errx(1, "%s: could not reinitialize event mechanism", __func__); + res = -1; + goto done; + } + + /* Empty out the changelist (if any): we are starting from a + * blank slate. */ + event_changelist_freemem_(&base->changelist); + + /* Tell the event maps to re-inform the backend about all + * pending events. This will make the signal notification + * event get re-created if necessary. */ + if (evmap_reinit_(base) < 0) + res = -1; + } else { + res = evsig_init_(base); + if (res == 0 && had_signal_added) { + res = event_add_nolock_(&base->sig.ev_signal, NULL, 0); + if (res == 0) + base->sig.ev_signal_added = 1; + } + } + + /* If we were notifiable before, and nothing just exploded, become + * notifiable again. */ + if (was_notifiable && res == 0) + res = evthread_make_base_notifiable_nolock_(base); + +done: + EVBASE_RELEASE_LOCK(base, th_base_lock); + return (res); +} + +/* Get the monotonic time for this event_base' timer */ +int event_gettime_monotonic(struct event_base* base, struct timeval* tv) +{ + int rv = -1; + + if (base && tv) { + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + rv = evutil_gettime_monotonic_(&(base->monotonic_timer), tv); + EVBASE_RELEASE_LOCK(base, th_base_lock); + } + + return rv; +} + +const char** event_get_supported_methods(void) +{ + static const char** methods = NULL; + const struct eventop** method; + const char** tmp; + int i = 0, k; + + /* count all methods */ + for (method = &eventops[0]; *method != NULL; ++method) { + ++i; + } + + /* allocate one more than we need for the NULL pointer */ + tmp = mm_calloc((i + 1), sizeof(char*)); + if (tmp == NULL) + return (NULL); + + /* populate the array with the supported methods */ + for (k = 0, i = 0; eventops[k] != NULL; ++k) { + tmp[i++] = eventops[k]->name; + } + tmp[i] = NULL; + + if (methods != NULL) + mm_free((char**)methods); + + methods = tmp; + + return (methods); +} + +struct event_config* event_config_new(void) +{ + struct event_config* cfg = mm_calloc(1, sizeof(*cfg)); + + if (cfg == NULL) + return (NULL); + + TAILQ_INIT(&cfg->entries); + cfg->max_dispatch_interval.tv_sec = -1; + cfg->max_dispatch_callbacks = INT_MAX; + cfg->limit_callbacks_after_prio = 1; + + return (cfg); +} + +static void event_config_entry_free(struct event_config_entry* entry) +{ + if (entry->avoid_method != NULL) + mm_free((char*)entry->avoid_method); + mm_free(entry); +} + +void event_config_free(struct event_config* cfg) +{ + struct event_config_entry* entry; + + while ((entry = TAILQ_FIRST(&cfg->entries)) != NULL) { + TAILQ_REMOVE(&cfg->entries, entry, next); + event_config_entry_free(entry); + } + mm_free(cfg); +} + +int event_config_set_flag(struct event_config* cfg, int flag) +{ + if (!cfg) + return -1; + cfg->flags |= flag; + return 0; +} + +int event_config_avoid_method(struct event_config* cfg, const char* method) +{ + struct event_config_entry* entry = mm_malloc(sizeof(*entry)); + if (entry == NULL) + return (-1); + + if ((entry->avoid_method = mm_strdup(method)) == NULL) { + mm_free(entry); + return (-1); + } + + TAILQ_INSERT_TAIL(&cfg->entries, entry, next); + + return (0); +} + +int event_config_require_features(struct event_config* cfg, int features) +{ + if (!cfg) + return (-1); + cfg->require_features = features; + return (0); +} + +int event_config_set_num_cpus_hint(struct event_config* cfg, int cpus) +{ + if (!cfg) + return (-1); + cfg->n_cpus_hint = cpus; + return (0); +} + +int event_config_set_max_dispatch_interval(struct event_config* cfg, const struct timeval* max_interval, int max_callbacks, int min_priority) +{ + if (max_interval) + memcpy(&cfg->max_dispatch_interval, max_interval, sizeof(struct timeval)); + else + cfg->max_dispatch_interval.tv_sec = -1; + cfg->max_dispatch_callbacks = max_callbacks >= 0 ? max_callbacks : INT_MAX; + if (min_priority < 0) + min_priority = 0; + cfg->limit_callbacks_after_prio = min_priority; + return (0); +} + +int event_priority_init(int npriorities) +{ + return event_base_priority_init(current_base, npriorities); +} + +int event_base_priority_init(struct event_base* base, int npriorities) +{ + int i, r; + r = -1; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (N_ACTIVE_CALLBACKS(base) || npriorities < 1 || npriorities >= EVENT_MAX_PRIORITIES) + goto err; + + if (npriorities == base->nactivequeues) + goto ok; + + if (base->nactivequeues) { + mm_free(base->activequeues); + base->nactivequeues = 0; + } + + /* Allocate our priority queues */ + base->activequeues = (struct evcallback_list*)mm_calloc(npriorities, sizeof(struct evcallback_list)); + if (base->activequeues == NULL) { + event_warn("%s: calloc", __func__); + goto err; + } + base->nactivequeues = npriorities; + + for (i = 0; i < base->nactivequeues; ++i) { + TAILQ_INIT(&base->activequeues[i]); + } + +ok: + r = 0; +err: + EVBASE_RELEASE_LOCK(base, th_base_lock); + return (r); +} + +int event_base_get_npriorities(struct event_base* base) +{ + int n; + if (base == NULL) + base = current_base; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + n = base->nactivequeues; + EVBASE_RELEASE_LOCK(base, th_base_lock); + return (n); +} + +int event_base_get_num_events(struct event_base* base, unsigned int type) +{ + int r = 0; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (type & EVENT_BASE_COUNT_ACTIVE) + r += base->event_count_active; + + if (type & EVENT_BASE_COUNT_VIRTUAL) + r += base->virtual_event_count; + + if (type & EVENT_BASE_COUNT_ADDED) + r += base->event_count; + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + return r; +} + +int event_base_get_max_events(struct event_base* base, unsigned int type, int clear) +{ + int r = 0; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (type & EVENT_BASE_COUNT_ACTIVE) { + r += base->event_count_active_max; + if (clear) + base->event_count_active_max = 0; + } + + if (type & EVENT_BASE_COUNT_VIRTUAL) { + r += base->virtual_event_count_max; + if (clear) + base->virtual_event_count_max = 0; + } + + if (type & EVENT_BASE_COUNT_ADDED) { + r += base->event_count_max; + if (clear) + base->event_count_max = 0; + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + return r; +} + +/* Returns true iff we're currently watching any events. */ +static int event_haveevents(struct event_base* base) +{ + /* Caller must hold th_base_lock */ + return (base->virtual_event_count > 0 || base->event_count > 0); +} + +/* "closure" function called when processing active signal events */ +static inline void event_signal_closure(struct event_base* base, struct event* ev) +{ + short ncalls; + int should_break; + + /* Allows deletes to work */ + ncalls = ev->ev_ncalls; + if (ncalls != 0) + ev->ev_pncalls = &ncalls; + EVBASE_RELEASE_LOCK(base, th_base_lock); + while (ncalls) { + ncalls--; + ev->ev_ncalls = ncalls; + if (ncalls == 0) + ev->ev_pncalls = NULL; + (*ev->ev_callback)(ev->ev_fd, ev->ev_res, ev->ev_arg); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + should_break = base->event_break; + EVBASE_RELEASE_LOCK(base, th_base_lock); + + if (should_break) { + if (ncalls != 0) + ev->ev_pncalls = NULL; + return; + } + } +} + +/* Common timeouts are special timeouts that are handled as queues rather than + * in the minheap. This is more efficient than the minheap if we happen to + * know that we're going to get several thousands of timeout events all with + * the same timeout value. + * + * Since all our timeout handling code assumes timevals can be copied, + * assigned, etc, we can't use "magic pointer" to encode these common + * timeouts. Searching through a list to see if every timeout is common could + * also get inefficient. Instead, we take advantage of the fact that tv_usec + * is 32 bits long, but only uses 20 of those bits (since it can never be over + * 999999.) We use the top bits to encode 4 bites of magic number, and 8 bits + * of index into the event_base's aray of common timeouts. + */ + +#define MICROSECONDS_MASK COMMON_TIMEOUT_MICROSECONDS_MASK +#define COMMON_TIMEOUT_IDX_MASK 0x0ff00000 +#define COMMON_TIMEOUT_IDX_SHIFT 20 +#define COMMON_TIMEOUT_MASK 0xf0000000 +#define COMMON_TIMEOUT_MAGIC 0x50000000 + +#define COMMON_TIMEOUT_IDX(tv) (((tv)->tv_usec & COMMON_TIMEOUT_IDX_MASK) >> COMMON_TIMEOUT_IDX_SHIFT) + +/** Return true iff if 'tv' is a common timeout in 'base' */ +static inline int is_common_timeout(const struct timeval* tv, const struct event_base* base) +{ + int idx; + if ((tv->tv_usec & COMMON_TIMEOUT_MASK) != COMMON_TIMEOUT_MAGIC) + return 0; + idx = COMMON_TIMEOUT_IDX(tv); + return idx < base->n_common_timeouts; +} + +/* True iff tv1 and tv2 have the same common-timeout index, or if neither + * one is a common timeout. */ +static inline int is_same_common_timeout(const struct timeval* tv1, const struct timeval* tv2) +{ + return (tv1->tv_usec & ~MICROSECONDS_MASK) == (tv2->tv_usec & ~MICROSECONDS_MASK); +} + +/** Requires that 'tv' is a common timeout. Return the corresponding + * common_timeout_list. */ +static inline struct common_timeout_list* get_common_timeout_list(struct event_base* base, const struct timeval* tv) +{ + return base->common_timeout_queues[COMMON_TIMEOUT_IDX(tv)]; +} + +#if 0 +static inline int +common_timeout_ok(const struct timeval *tv, + struct event_base *base) +{ + const struct timeval *expect = + &get_common_timeout_list(base, tv)->duration; + return tv->tv_sec == expect->tv_sec && + tv->tv_usec == expect->tv_usec; +} +#endif + +/* Add the timeout for the first event in given common timeout list to the + * event_base's minheap. */ +static void common_timeout_schedule(struct common_timeout_list* ctl, const struct timeval* now, struct event* head) +{ + struct timeval timeout = head->ev_timeout; + timeout.tv_usec &= MICROSECONDS_MASK; + event_add_nolock_(&ctl->timeout_event, &timeout, 1); +} + +/* Callback: invoked when the timeout for a common timeout queue triggers. + * This means that (at least) the first event in that queue should be run, + * and the timeout should be rescheduled if there are more events. */ +static void common_timeout_callback(evutil_socket_t fd, short what, void* arg) +{ + struct timeval now; + struct common_timeout_list* ctl = arg; + struct event_base* base = ctl->base; + struct event* ev = NULL; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + gettime(base, &now); + while (1) { + ev = TAILQ_FIRST(&ctl->events); + if (!ev || ev->ev_timeout.tv_sec > now.tv_sec + || (ev->ev_timeout.tv_sec == now.tv_sec && (ev->ev_timeout.tv_usec & MICROSECONDS_MASK) > now.tv_usec)) + break; + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + event_active_nolock_(ev, EV_TIMEOUT, 1); + } + if (ev) + common_timeout_schedule(ctl, &now, ev); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +#define MAX_COMMON_TIMEOUTS 256 + +const struct timeval* event_base_init_common_timeout(struct event_base* base, const struct timeval* duration) +{ + int i; + struct timeval tv; + const struct timeval* result = NULL; + struct common_timeout_list* new_ctl; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (duration->tv_usec > 1000000) { + memcpy(&tv, duration, sizeof(struct timeval)); + if (is_common_timeout(duration, base)) + tv.tv_usec &= MICROSECONDS_MASK; + tv.tv_sec += tv.tv_usec / 1000000; + tv.tv_usec %= 1000000; + duration = &tv; + } + for (i = 0; i < base->n_common_timeouts; ++i) { + const struct common_timeout_list* ctl = base->common_timeout_queues[i]; + if (duration->tv_sec == ctl->duration.tv_sec && duration->tv_usec == (ctl->duration.tv_usec & MICROSECONDS_MASK)) { + EVUTIL_ASSERT(is_common_timeout(&ctl->duration, base)); + result = &ctl->duration; + goto done; + } + } + if (base->n_common_timeouts == MAX_COMMON_TIMEOUTS) { + event_warnx( + "%s: Too many common timeouts already in use; " + "we only support %d per event_base", + __func__, MAX_COMMON_TIMEOUTS); + goto done; + } + if (base->n_common_timeouts_allocated == base->n_common_timeouts) { + int n = base->n_common_timeouts < 16 ? 16 : base->n_common_timeouts * 2; + struct common_timeout_list** newqueues = mm_realloc(base->common_timeout_queues, n * sizeof(struct common_timeout_queue*)); + if (!newqueues) { + event_warn("%s: realloc", __func__); + goto done; + } + base->n_common_timeouts_allocated = n; + base->common_timeout_queues = newqueues; + } + new_ctl = mm_calloc(1, sizeof(struct common_timeout_list)); + if (!new_ctl) { + event_warn("%s: calloc", __func__); + goto done; + } + TAILQ_INIT(&new_ctl->events); + new_ctl->duration.tv_sec = duration->tv_sec; + new_ctl->duration.tv_usec = duration->tv_usec | COMMON_TIMEOUT_MAGIC | (base->n_common_timeouts << COMMON_TIMEOUT_IDX_SHIFT); + evtimer_assign(&new_ctl->timeout_event, base, common_timeout_callback, new_ctl); + new_ctl->timeout_event.ev_flags |= EVLIST_INTERNAL; + event_priority_set(&new_ctl->timeout_event, 0); + new_ctl->base = base; + base->common_timeout_queues[base->n_common_timeouts++] = new_ctl; + result = &new_ctl->duration; + +done: + if (result) + EVUTIL_ASSERT(is_common_timeout(result, base)); + + EVBASE_RELEASE_LOCK(base, th_base_lock); + return result; +} + +/* Closure function invoked when we're activating a persistent event. */ +static inline void event_persist_closure(struct event_base* base, struct event* ev) +{ + void (*evcb_callback)(evutil_socket_t, short, void*); + + // Other fields of *ev that must be stored before executing + evutil_socket_t evcb_fd; + short evcb_res; + void* evcb_arg; + + /* reschedule the persistent event if we have a timeout. */ + if (ev->ev_io_timeout.tv_sec || ev->ev_io_timeout.tv_usec) { + /* If there was a timeout, we want it to run at an interval of + * ev_io_timeout after the last time it was _scheduled_ for, + * not ev_io_timeout after _now_. If it fired for another + * reason, though, the timeout ought to start ticking _now_. */ + struct timeval run_at, relative_to, delay, now; + ev_uint32_t usec_mask = 0; + EVUTIL_ASSERT(is_same_common_timeout(&ev->ev_timeout, &ev->ev_io_timeout)); + gettime(base, &now); + if (is_common_timeout(&ev->ev_timeout, base)) { + delay = ev->ev_io_timeout; + usec_mask = delay.tv_usec & ~MICROSECONDS_MASK; + delay.tv_usec &= MICROSECONDS_MASK; + if (ev->ev_res & EV_TIMEOUT) { + relative_to = ev->ev_timeout; + relative_to.tv_usec &= MICROSECONDS_MASK; + } else { + relative_to = now; + } + } else { + delay = ev->ev_io_timeout; + if (ev->ev_res & EV_TIMEOUT) { + relative_to = ev->ev_timeout; + } else { + relative_to = now; + } + } + evutil_timeradd(&relative_to, &delay, &run_at); + if (evutil_timercmp(&run_at, &now, <)) { + /* Looks like we missed at least one invocation due to + * a clock jump, not running the event loop for a + * while, really slow callbacks, or + * something. Reschedule relative to now. + */ + evutil_timeradd(&now, &delay, &run_at); + } + run_at.tv_usec |= usec_mask; + event_add_nolock_(ev, &run_at, 1); + } + + // Save our callback before we release the lock + evcb_callback = ev->ev_callback; + evcb_fd = ev->ev_fd; + evcb_res = ev->ev_res; + evcb_arg = ev->ev_arg; + + // Release the lock + EVBASE_RELEASE_LOCK(base, th_base_lock); + + // Execute the callback + (evcb_callback)(evcb_fd, evcb_res, evcb_arg); +} + +/* + Helper for event_process_active to process all the events in a single queue, + releasing the lock as we go. This function requires that the lock be held + when it's invoked. Returns -1 if we get a signal or an event_break that + means we should stop processing any active events now. Otherwise returns + the number of non-internal event_callbacks that we processed. +*/ +static int + event_process_active_single_queue(struct event_base* base, struct evcallback_list* activeq, int max_to_process, const struct timeval* endtime) +{ + struct event_callback* evcb; + int count = 0; + + EVUTIL_ASSERT(activeq != NULL); + + for (evcb = TAILQ_FIRST(activeq); evcb; evcb = TAILQ_FIRST(activeq)) { + struct event* ev = NULL; + if (evcb->evcb_flags & EVLIST_INIT) { + ev = event_callback_to_event(evcb); + + if (ev->ev_events & EV_PERSIST || ev->ev_flags & EVLIST_FINALIZING) + event_queue_remove_active(base, evcb); + else + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + event_debug( + ("event_process_active: event: %p, %s%s%scall %p", ev, ev->ev_res & EV_READ ? "EV_READ " : " ", + ev->ev_res & EV_WRITE ? "EV_WRITE " : " ", ev->ev_res & EV_CLOSED ? "EV_CLOSED " : " ", ev->ev_callback)); + } else { + event_queue_remove_active(base, evcb); + event_debug( + ("event_process_active: event_callback %p, " + "closure %d, call %p", + evcb, evcb->evcb_closure, evcb->evcb_cb_union.evcb_callback)); + } + + if (!(evcb->evcb_flags & EVLIST_INTERNAL)) + ++count; + + base->current_event = evcb; +#ifndef EVENT__DISABLE_THREAD_SUPPORT + base->current_event_waiters = 0; +#endif + + switch (evcb->evcb_closure) { + case EV_CLOSURE_EVENT_SIGNAL: + EVUTIL_ASSERT(ev != NULL); + event_signal_closure(base, ev); + break; + case EV_CLOSURE_EVENT_PERSIST: + EVUTIL_ASSERT(ev != NULL); + event_persist_closure(base, ev); + break; + case EV_CLOSURE_EVENT: { + void (*evcb_callback)(evutil_socket_t, short, void*); + EVUTIL_ASSERT(ev != NULL); + evcb_callback = *ev->ev_callback; + EVBASE_RELEASE_LOCK(base, th_base_lock); + evcb_callback(ev->ev_fd, ev->ev_res, ev->ev_arg); + } break; + case EV_CLOSURE_CB_SELF: { + void (*evcb_selfcb)(struct event_callback*, void*) = evcb->evcb_cb_union.evcb_selfcb; + EVBASE_RELEASE_LOCK(base, th_base_lock); + evcb_selfcb(evcb, evcb->evcb_arg); + } break; + case EV_CLOSURE_EVENT_FINALIZE: + case EV_CLOSURE_EVENT_FINALIZE_FREE: { + void (*evcb_evfinalize)(struct event*, void*); + int evcb_closure = evcb->evcb_closure; + EVUTIL_ASSERT(ev != NULL); + base->current_event = NULL; + evcb_evfinalize = ev->ev_evcallback.evcb_cb_union.evcb_evfinalize; + EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_FINALIZING)); + EVBASE_RELEASE_LOCK(base, th_base_lock); + evcb_evfinalize(ev, ev->ev_arg); + event_debug_note_teardown_(ev); + if (evcb_closure == EV_CLOSURE_EVENT_FINALIZE_FREE) + mm_free(ev); + } break; + case EV_CLOSURE_CB_FINALIZE: { + void (*evcb_cbfinalize)(struct event_callback*, void*) = evcb->evcb_cb_union.evcb_cbfinalize; + base->current_event = NULL; + EVUTIL_ASSERT((evcb->evcb_flags & EVLIST_FINALIZING)); + EVBASE_RELEASE_LOCK(base, th_base_lock); + evcb_cbfinalize(evcb, evcb->evcb_arg); + } break; + default: + EVUTIL_ASSERT(0); + } + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + base->current_event = NULL; +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (base->current_event_waiters) { + base->current_event_waiters = 0; + EVTHREAD_COND_BROADCAST(base->current_event_cond); + } +#endif + + if (base->event_break) + return -1; + if (count >= max_to_process) + return count; + if (count && endtime) { + struct timeval now; + update_time_cache(base); + gettime(base, &now); + if (evutil_timercmp(&now, endtime, >=)) + return count; + } + if (base->event_continue) + break; + } + return count; +} + +/* + * Active events are stored in priority queues. Lower priorities are always + * process before higher priorities. Low priority events can starve high + * priority ones. + */ + +static int event_process_active(struct event_base* base) +{ + /* Caller must hold th_base_lock */ + struct evcallback_list* activeq = NULL; + int i, c = 0; + const struct timeval* endtime; + struct timeval tv; + const int maxcb = base->max_dispatch_callbacks; + const int limit_after_prio = base->limit_callbacks_after_prio; + if (base->max_dispatch_time.tv_sec >= 0) { + update_time_cache(base); + gettime(base, &tv); + evutil_timeradd(&base->max_dispatch_time, &tv, &tv); + endtime = &tv; + } else { + endtime = NULL; + } + + for (i = 0; i < base->nactivequeues; ++i) { + if (TAILQ_FIRST(&base->activequeues[i]) != NULL) { + base->event_running_priority = i; + activeq = &base->activequeues[i]; + if (i < limit_after_prio) + c = event_process_active_single_queue(base, activeq, INT_MAX, NULL); + else + c = event_process_active_single_queue(base, activeq, maxcb, endtime); + if (c < 0) { + goto done; + } else if (c > 0) + break; /* Processed a real event; do not + * consider lower-priority events */ + /* If we get here, all of the events we processed + * were internal. Continue. */ + } + } + +done: + base->event_running_priority = -1; + + return c; +} + +/* + * Wait continuously for events. We exit only if no events are left. + */ + +int event_dispatch(void) +{ + return (event_loop(0)); +} + +int event_base_dispatch(struct event_base* event_base) +{ + return (event_base_loop(event_base, 0)); +} + +const char* event_base_get_method(const struct event_base* base) +{ + EVUTIL_ASSERT(base); + return (base->evsel->name); +} + +/** Callback: used to implement event_base_loopexit by telling the event_base + * that it's time to exit its loop. */ +static void event_loopexit_cb(evutil_socket_t fd, short what, void* arg) +{ + struct event_base* base = arg; + base->event_gotterm = 1; +} + +int event_loopexit(const struct timeval* tv) +{ + return (event_once(-1, EV_TIMEOUT, event_loopexit_cb, current_base, tv)); +} + +int event_base_loopexit(struct event_base* event_base, const struct timeval* tv) +{ + return (event_base_once(event_base, -1, EV_TIMEOUT, event_loopexit_cb, event_base, tv)); +} + +int event_loopbreak(void) +{ + return (event_base_loopbreak(current_base)); +} + +int event_base_loopbreak(struct event_base* event_base) +{ + int r = 0; + if (event_base == NULL) + return (-1); + + EVBASE_ACQUIRE_LOCK(event_base, th_base_lock); + event_base->event_break = 1; + + if (EVBASE_NEED_NOTIFY(event_base)) { + r = evthread_notify_base(event_base); + } else { + r = (0); + } + EVBASE_RELEASE_LOCK(event_base, th_base_lock); + return r; +} + +int event_base_loopcontinue(struct event_base* event_base) +{ + int r = 0; + if (event_base == NULL) + return (-1); + + EVBASE_ACQUIRE_LOCK(event_base, th_base_lock); + event_base->event_continue = 1; + + if (EVBASE_NEED_NOTIFY(event_base)) { + r = evthread_notify_base(event_base); + } else { + r = (0); + } + EVBASE_RELEASE_LOCK(event_base, th_base_lock); + return r; +} + +int event_base_got_break(struct event_base* event_base) +{ + int res; + EVBASE_ACQUIRE_LOCK(event_base, th_base_lock); + res = event_base->event_break; + EVBASE_RELEASE_LOCK(event_base, th_base_lock); + return res; +} + +int event_base_got_exit(struct event_base* event_base) +{ + int res; + EVBASE_ACQUIRE_LOCK(event_base, th_base_lock); + res = event_base->event_gotterm; + EVBASE_RELEASE_LOCK(event_base, th_base_lock); + return res; +} + +/* not thread safe */ + +int event_loop(int flags) +{ + return event_base_loop(current_base, flags); +} + +int event_base_loop(struct event_base* base, int flags) +{ + const struct eventop* evsel = base->evsel; + struct timeval tv; + struct timeval* tv_p; + int res, done, retval = 0; + + /* Grab the lock. We will release it inside evsel.dispatch, and again + * as we invoke user callbacks. */ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (base->running_loop) { + event_warnx( + "%s: reentrant invocation. Only one event_base_loop" + " can run on each event_base at once.", + __func__); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return -1; + } + + base->running_loop = 1; + + clear_time_cache(base); + + if (base->sig.ev_signal_added && base->sig.ev_n_signals_added) + evsig_set_base_(base); + + done = 0; + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + base->th_owner_id = EVTHREAD_GET_ID(); +#endif + + base->event_gotterm = base->event_break = 0; + + while (!done) { + base->event_continue = 0; + base->n_deferreds_queued = 0; + + /* Terminate the loop if we have been asked to */ + if (base->event_gotterm) { + break; + } + + if (base->event_break) { + break; + } + + tv_p = &tv; + if (!N_ACTIVE_CALLBACKS(base) && !(flags & EVLOOP_NONBLOCK)) { + timeout_next(base, &tv_p); + } else { + /* + * if we have active events, we just poll new events + * without waiting. + */ + evutil_timerclear(&tv); + } + + /* If we have no events, we just exit */ + if (0 == (flags & EVLOOP_NO_EXIT_ON_EMPTY) && !event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) { + event_debug(("%s: no events registered.", __func__)); + retval = 1; + goto done; + } + + event_queue_make_later_events_active(base); + + clear_time_cache(base); + + res = evsel->dispatch(base, tv_p); + + if (res == -1) { + event_debug(("%s: dispatch returned unsuccessfully.", __func__)); + retval = -1; + goto done; + } + + update_time_cache(base); + + timeout_process(base); + + if (N_ACTIVE_CALLBACKS(base)) { + int n = event_process_active(base); + if ((flags & EVLOOP_ONCE) && N_ACTIVE_CALLBACKS(base) == 0 && n != 0) + done = 1; + } else if (flags & EVLOOP_NONBLOCK) + done = 1; + } + event_debug(("%s: asked to terminate loop.", __func__)); + +done: + clear_time_cache(base); + base->running_loop = 0; + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + return (retval); +} + +/* One-time callback to implement event_base_once: invokes the user callback, + * then deletes the allocated storage */ +static void event_once_cb(evutil_socket_t fd, short events, void* arg) +{ + struct event_once* eonce = arg; + + (*eonce->cb)(fd, events, eonce->arg); + EVBASE_ACQUIRE_LOCK(eonce->ev.ev_base, th_base_lock); + LIST_REMOVE(eonce, next_once); + EVBASE_RELEASE_LOCK(eonce->ev.ev_base, th_base_lock); + event_debug_unassign(&eonce->ev); + mm_free(eonce); +} + +/* not threadsafe, event scheduled once. */ +int event_once(evutil_socket_t fd, short events, void (*callback)(evutil_socket_t, short, void*), void* arg, const struct timeval* tv) +{ + return event_base_once(current_base, fd, events, callback, arg, tv); +} + +/* Schedules an event once */ +int event_base_once( + struct event_base* base, evutil_socket_t fd, short events, void (*callback)(evutil_socket_t, short, void*), void* arg, const struct timeval* tv) +{ + struct event_once* eonce; + int res = 0; + int activate = 0; + + /* We cannot support signals that just fire once, or persistent + * events. */ + if (events & (EV_SIGNAL | EV_PERSIST)) + return (-1); + + if ((eonce = mm_calloc(1, sizeof(struct event_once))) == NULL) + return (-1); + + eonce->cb = callback; + eonce->arg = arg; + + if ((events & (EV_TIMEOUT | EV_SIGNAL | EV_READ | EV_WRITE | EV_CLOSED)) == EV_TIMEOUT) { + evtimer_assign(&eonce->ev, base, event_once_cb, eonce); + + if (tv == NULL || !evutil_timerisset(tv)) { + /* If the event is going to become active immediately, + * don't put it on the timeout queue. This is one + * idiom for scheduling a callback, so let's make + * it fast (and order-preserving). */ + activate = 1; + } + } else if (events & (EV_READ | EV_WRITE | EV_CLOSED)) { + events &= EV_READ | EV_WRITE | EV_CLOSED; + + event_assign(&eonce->ev, base, fd, events, event_once_cb, eonce); + } else { + /* Bad event combination */ + mm_free(eonce); + return (-1); + } + + if (res == 0) { + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (activate) + event_active_nolock_(&eonce->ev, EV_TIMEOUT, 1); + else + res = event_add_nolock_(&eonce->ev, tv, 0); + + if (res != 0) { + mm_free(eonce); + return (res); + } else { + LIST_INSERT_HEAD(&base->once_events, eonce, next_once); + } + EVBASE_RELEASE_LOCK(base, th_base_lock); + } + + return (0); +} + +int event_assign( + struct event* ev, struct event_base* base, evutil_socket_t fd, short events, void (*callback)(evutil_socket_t, short, void*), void* arg) +{ + if (!base) + base = current_base; + if (arg == &event_self_cbarg_ptr_) + arg = ev; + + event_debug_assert_not_added_(ev); + + ev->ev_base = base; + + ev->ev_callback = callback; + ev->ev_arg = arg; + ev->ev_fd = fd; + ev->ev_events = events; + ev->ev_res = 0; + ev->ev_flags = EVLIST_INIT; + ev->ev_ncalls = 0; + ev->ev_pncalls = NULL; + + if (events & EV_SIGNAL) { + if ((events & (EV_READ | EV_WRITE | EV_CLOSED)) != 0) { + event_warnx( + "%s: EV_SIGNAL is not compatible with " + "EV_READ, EV_WRITE or EV_CLOSED", + __func__); + return -1; + } + ev->ev_closure = EV_CLOSURE_EVENT_SIGNAL; + } else { + if (events & EV_PERSIST) { + evutil_timerclear(&ev->ev_io_timeout); + ev->ev_closure = EV_CLOSURE_EVENT_PERSIST; + } else { + ev->ev_closure = EV_CLOSURE_EVENT; + } + } + + min_heap_elem_init_(ev); + + if (base != NULL) { + /* by default, we put new events into the middle priority */ + ev->ev_pri = base->nactivequeues / 2; + } + + event_debug_note_setup_(ev); + + return 0; +} + +int event_base_set(struct event_base* base, struct event* ev) +{ + /* Only innocent events may be assigned to a different base */ + if (ev->ev_flags != EVLIST_INIT) + return (-1); + + event_debug_assert_is_setup_(ev); + + ev->ev_base = base; + ev->ev_pri = base->nactivequeues / 2; + + return (0); +} + +void event_set(struct event* ev, evutil_socket_t fd, short events, void (*callback)(evutil_socket_t, short, void*), void* arg) +{ + int r; + r = event_assign(ev, current_base, fd, events, callback, arg); + EVUTIL_ASSERT(r == 0); +} + +void* event_self_cbarg(void) +{ + return &event_self_cbarg_ptr_; +} + +struct event* event_base_get_running_event(struct event_base* base) +{ + struct event* ev = NULL; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (EVBASE_IN_THREAD(base)) { + struct event_callback* evcb = base->current_event; + if (evcb->evcb_flags & EVLIST_INIT) + ev = event_callback_to_event(evcb); + } + EVBASE_RELEASE_LOCK(base, th_base_lock); + return ev; +} + +struct event* event_new(struct event_base* base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, short, void*), void* arg) +{ + struct event* ev; + ev = mm_malloc(sizeof(struct event)); + if (ev == NULL) + return (NULL); + if (event_assign(ev, base, fd, events, cb, arg) < 0) { + mm_free(ev); + return (NULL); + } + + return (ev); +} + +void event_free(struct event* ev) +{ + /* This is disabled, so that events which have been finalized be a + * valid target for event_free(). That's */ + // event_debug_assert_is_setup_(ev); + + /* make sure that this event won't be coming back to haunt us. */ + event_del(ev); + event_debug_note_teardown_(ev); + mm_free(ev); +} + +void event_debug_unassign(struct event* ev) +{ + event_debug_assert_not_added_(ev); + event_debug_note_teardown_(ev); + + ev->ev_flags &= ~EVLIST_INIT; +} + +#define EVENT_FINALIZE_FREE_ 0x10000 +static int event_finalize_nolock_(struct event_base* base, unsigned flags, struct event* ev, event_finalize_callback_fn cb) +{ + ev_uint8_t closure = (flags & EVENT_FINALIZE_FREE_) ? EV_CLOSURE_EVENT_FINALIZE_FREE : EV_CLOSURE_EVENT_FINALIZE; + + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + ev->ev_closure = closure; + ev->ev_evcallback.evcb_cb_union.evcb_evfinalize = cb; + event_active_nolock_(ev, EV_FINALIZE, 1); + ev->ev_flags |= EVLIST_FINALIZING; + return 0; +} + +static int event_finalize_impl_(unsigned flags, struct event* ev, event_finalize_callback_fn cb) +{ + int r; + struct event_base* base = ev->ev_base; + if (EVUTIL_FAILURE_CHECK(!base)) { + event_warnx("%s: event has no event_base set.", __func__); + return -1; + } + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_finalize_nolock_(base, flags, ev, cb); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +int event_finalize(unsigned flags, struct event* ev, event_finalize_callback_fn cb) +{ + return event_finalize_impl_(flags, ev, cb); +} + +int event_free_finalize(unsigned flags, struct event* ev, event_finalize_callback_fn cb) +{ + return event_finalize_impl_(flags | EVENT_FINALIZE_FREE_, ev, cb); +} + +void event_callback_finalize_nolock_(struct event_base* base, unsigned flags, struct event_callback* evcb, void (*cb)(struct event_callback*, void*)) +{ + struct event* ev = NULL; + if (evcb->evcb_flags & EVLIST_INIT) { + ev = event_callback_to_event(evcb); + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + } else { + event_callback_cancel_nolock_(base, evcb, 0); /*XXX can this fail?*/ + } + + evcb->evcb_closure = EV_CLOSURE_CB_FINALIZE; + evcb->evcb_cb_union.evcb_cbfinalize = cb; + event_callback_activate_nolock_(base, evcb); /* XXX can this really fail?*/ + evcb->evcb_flags |= EVLIST_FINALIZING; +} + +void event_callback_finalize_(struct event_base* base, unsigned flags, struct event_callback* evcb, void (*cb)(struct event_callback*, void*)) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + event_callback_finalize_nolock_(base, flags, evcb, cb); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +/** Internal: Finalize all of the n_cbs callbacks in evcbs. The provided + * callback will be invoked on *one of them*, after they have *all* been + * finalized. */ +int event_callback_finalize_many_(struct event_base* base, int n_cbs, struct event_callback** evcbs, void (*cb)(struct event_callback*, void*)) +{ + int n_pending = 0, i; + + if (base == NULL) + base = current_base; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + event_debug(("%s: %d events finalizing", __func__, n_cbs)); + + /* At most one can be currently executing; the rest we just + * cancel... But we always make sure that the finalize callback + * runs. */ + for (i = 0; i < n_cbs; ++i) { + struct event_callback* evcb = evcbs[i]; + if (evcb == base->current_event) { + event_callback_finalize_nolock_(base, 0, evcb, cb); + ++n_pending; + } else { + event_callback_cancel_nolock_(base, evcb, 0); + } + } + + if (n_pending == 0) { + /* Just do the first one. */ + event_callback_finalize_nolock_(base, 0, evcbs[0], cb); + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + return 0; +} + +/* + * Set's the priority of an event - if an event is already scheduled + * changing the priority is going to fail. + */ + +int event_priority_set(struct event* ev, int pri) +{ + event_debug_assert_is_setup_(ev); + + if (ev->ev_flags & EVLIST_ACTIVE) + return (-1); + if (pri < 0 || pri >= ev->ev_base->nactivequeues) + return (-1); + + ev->ev_pri = pri; + + return (0); +} + +/* + * Checks if a specific event is pending or scheduled. + */ + +int event_pending(const struct event* ev, short event, struct timeval* tv) +{ + int flags = 0; + + if (EVUTIL_FAILURE_CHECK(ev->ev_base == NULL)) { + event_warnx("%s: event has no event_base set.", __func__); + return 0; + } + + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + event_debug_assert_is_setup_(ev); + + if (ev->ev_flags & EVLIST_INSERTED) + flags |= (ev->ev_events & (EV_READ | EV_WRITE | EV_CLOSED | EV_SIGNAL)); + if (ev->ev_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER)) + flags |= ev->ev_res; + if (ev->ev_flags & EVLIST_TIMEOUT) + flags |= EV_TIMEOUT; + + event &= (EV_TIMEOUT | EV_READ | EV_WRITE | EV_CLOSED | EV_SIGNAL); + + /* See if there is a timeout that we should report */ + if (tv != NULL && (flags & event & EV_TIMEOUT)) { + struct timeval tmp = ev->ev_timeout; + tmp.tv_usec &= MICROSECONDS_MASK; + /* correctly remamp to real time */ + evutil_timeradd(&ev->ev_base->tv_clock_diff, &tmp, tv); + } + + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); + + return (flags & event); +} + +int event_initialized(const struct event* ev) +{ + if (!(ev->ev_flags & EVLIST_INIT)) + return 0; + + return 1; +} + +void event_get_assignment( + const struct event* event, + struct event_base** base_out, + evutil_socket_t* fd_out, + short* events_out, + event_callback_fn* callback_out, + void** arg_out) +{ + event_debug_assert_is_setup_(event); + + if (base_out) + *base_out = event->ev_base; + if (fd_out) + *fd_out = event->ev_fd; + if (events_out) + *events_out = event->ev_events; + if (callback_out) + *callback_out = event->ev_callback; + if (arg_out) + *arg_out = event->ev_arg; +} + +size_t event_get_struct_event_size(void) +{ + return sizeof(struct event); +} + +evutil_socket_t event_get_fd(const struct event* ev) +{ + event_debug_assert_is_setup_(ev); + return ev->ev_fd; +} + +struct event_base* event_get_base(const struct event* ev) +{ + event_debug_assert_is_setup_(ev); + return ev->ev_base; +} + +short event_get_events(const struct event* ev) +{ + event_debug_assert_is_setup_(ev); + return ev->ev_events; +} + +event_callback_fn event_get_callback(const struct event* ev) +{ + event_debug_assert_is_setup_(ev); + return ev->ev_callback; +} + +void* event_get_callback_arg(const struct event* ev) +{ + event_debug_assert_is_setup_(ev); + return ev->ev_arg; +} + +int event_get_priority(const struct event* ev) +{ + event_debug_assert_is_setup_(ev); + return ev->ev_pri; +} + +int event_add(struct event* ev, const struct timeval* tv) +{ + int res; + + if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { + event_warnx("%s: event has no event_base set.", __func__); + return -1; + } + + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + + res = event_add_nolock_(ev, tv, 0); + + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); + + return (res); +} + +/* Helper callback: wake an event_base from another thread. This version + * works by writing a byte to one end of a socketpair, so that the event_base + * listening on the other end will wake up as the corresponding event + * triggers */ +static int evthread_notify_base_default(struct event_base* base) +{ + char buf[1]; + int r; + buf[0] = (char)0; +#ifdef _WIN32 + r = send(base->th_notify_fd[1], buf, 1, 0); +#else + r = write(base->th_notify_fd[1], buf, 1); +#endif + return (r < 0 && !EVUTIL_ERR_IS_EAGAIN(errno)) ? -1 : 0; +} + +#ifdef EVENT__HAVE_EVENTFD +/* Helper callback: wake an event_base from another thread. This version + * assumes that you have a working eventfd() implementation. */ +static int evthread_notify_base_eventfd(struct event_base* base) +{ + ev_uint64_t msg = 1; + int r; + do { + r = write(base->th_notify_fd[0], (void*)&msg, sizeof(msg)); + } while (r < 0 && errno == EAGAIN); + + return (r < 0) ? -1 : 0; +} +#endif + +/** Tell the thread currently running the event_loop for base (if any) that it + * needs to stop waiting in its dispatch function (if it is) and process all + * active callbacks. */ +static int evthread_notify_base(struct event_base* base) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (!base->th_notify_fn) + return -1; + if (base->is_notify_pending) + return 0; + base->is_notify_pending = 1; + return base->th_notify_fn(base); +} + +/* Implementation function to remove a timeout on a currently pending event. + */ +int event_remove_timer_nolock_(struct event* ev) +{ + struct event_base* base = ev->ev_base; + + EVENT_BASE_ASSERT_LOCKED(base); + event_debug_assert_is_setup_(ev); + + event_debug(("event_remove_timer_nolock: event: %p", ev)); + + /* If it's not pending on a timeout, we don't need to do anything. */ + if (ev->ev_flags & EVLIST_TIMEOUT) { + event_queue_remove_timeout(base, ev); + evutil_timerclear(&ev->ev_.ev_io.ev_timeout); + } + + return (0); +} + +int event_remove_timer(struct event* ev) +{ + int res; + + if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { + event_warnx("%s: event has no event_base set.", __func__); + return -1; + } + + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + + res = event_remove_timer_nolock_(ev); + + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); + + return (res); +} + +/* Implementation function to add an event. Works just like event_add, + * except: 1) it requires that we have the lock. 2) if tv_is_absolute is set, + * we treat tv as an absolute time, not as an interval to add to the current + * time */ +int event_add_nolock_(struct event* ev, const struct timeval* tv, int tv_is_absolute) +{ + struct event_base* base = ev->ev_base; + int res = 0; + int notify = 0; + + EVENT_BASE_ASSERT_LOCKED(base); + event_debug_assert_is_setup_(ev); + + event_debug( + ("event_add: event: %p (fd " EV_SOCK_FMT "), %s%s%s%scall %p", ev, EV_SOCK_ARG(ev->ev_fd), ev->ev_events & EV_READ ? "EV_READ " : " ", + ev->ev_events & EV_WRITE ? "EV_WRITE " : " ", ev->ev_events & EV_CLOSED ? "EV_CLOSED " : " ", tv ? "EV_TIMEOUT " : " ", ev->ev_callback)); + + EVUTIL_ASSERT(!(ev->ev_flags & ~EVLIST_ALL)); + + if (ev->ev_flags & EVLIST_FINALIZING) { + /* XXXX debug */ + return (-1); + } + + /* + * prepare for timeout insertion further below, if we get a + * failure on any step, we should not change any state. + */ + if (tv != NULL && !(ev->ev_flags & EVLIST_TIMEOUT)) { + if (min_heap_reserve_(&base->timeheap, 1 + min_heap_size_(&base->timeheap)) == -1) + return (-1); /* ENOMEM == errno */ + } + + /* If the main thread is currently executing a signal event's + * callback, and we are not the main thread, then we want to wait + * until the callback is done before we mess with the event, or else + * we can race on ev_ncalls and ev_pncalls below. */ +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (base->current_event == event_to_event_callback(ev) && (ev->ev_events & EV_SIGNAL) && !EVBASE_IN_THREAD(base)) { + ++base->current_event_waiters; + EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); + } +#endif + + if ((ev->ev_events & (EV_READ | EV_WRITE | EV_CLOSED | EV_SIGNAL)) && !(ev->ev_flags & (EVLIST_INSERTED | EVLIST_ACTIVE | EVLIST_ACTIVE_LATER))) { + if (ev->ev_events & (EV_READ | EV_WRITE | EV_CLOSED)) + res = evmap_io_add_(base, ev->ev_fd, ev); + else if (ev->ev_events & EV_SIGNAL) + res = evmap_signal_add_(base, (int)ev->ev_fd, ev); + if (res != -1) + event_queue_insert_inserted(base, ev); + if (res == 1) { + /* evmap says we need to notify the main thread. */ + notify = 1; + res = 0; + } + } + + /* + * we should change the timeout state only if the previous event + * addition succeeded. + */ + if (res != -1 && tv != NULL) { + struct timeval now; + int common_timeout; +#ifdef USE_REINSERT_TIMEOUT + int was_common; + int old_timeout_idx; +#endif + + /* + * for persistent timeout events, we remember the + * timeout value and re-add the event. + * + * If tv_is_absolute, this was already set. + */ + if (ev->ev_closure == EV_CLOSURE_EVENT_PERSIST && !tv_is_absolute) + ev->ev_io_timeout = *tv; + +#ifndef USE_REINSERT_TIMEOUT + if (ev->ev_flags & EVLIST_TIMEOUT) { + event_queue_remove_timeout(base, ev); + } +#endif + + /* Check if it is active due to a timeout. Rescheduling + * this timeout before the callback can be executed + * removes it from the active list. */ + if ((ev->ev_flags & EVLIST_ACTIVE) && (ev->ev_res & EV_TIMEOUT)) { + if (ev->ev_events & EV_SIGNAL) { + /* See if we are just active executing + * this event in a loop + */ + if (ev->ev_ncalls && ev->ev_pncalls) { + /* Abort loop */ + *ev->ev_pncalls = 0; + } + } + + event_queue_remove_active(base, event_to_event_callback(ev)); + } + + gettime(base, &now); + + common_timeout = is_common_timeout(tv, base); +#ifdef USE_REINSERT_TIMEOUT + was_common = is_common_timeout(&ev->ev_timeout, base); + old_timeout_idx = COMMON_TIMEOUT_IDX(&ev->ev_timeout); +#endif + + if (tv_is_absolute) { + ev->ev_timeout = *tv; + } else if (common_timeout) { + struct timeval tmp = *tv; + tmp.tv_usec &= MICROSECONDS_MASK; + evutil_timeradd(&now, &tmp, &ev->ev_timeout); + ev->ev_timeout.tv_usec |= (tv->tv_usec & ~MICROSECONDS_MASK); + } else { + evutil_timeradd(&now, tv, &ev->ev_timeout); + } + + event_debug(("event_add: event %p, timeout in %d seconds %d useconds, call %p", ev, (int)tv->tv_sec, (int)tv->tv_usec, ev->ev_callback)); + +#ifdef USE_REINSERT_TIMEOUT + event_queue_reinsert_timeout(base, ev, was_common, common_timeout, old_timeout_idx); +#else + event_queue_insert_timeout(base, ev); +#endif + + if (common_timeout) { + struct common_timeout_list* ctl = get_common_timeout_list(base, &ev->ev_timeout); + if (ev == TAILQ_FIRST(&ctl->events)) { + common_timeout_schedule(ctl, &now, ev); + } + } else { + struct event* top = NULL; + /* See if the earliest timeout is now earlier than it + * was before: if so, we will need to tell the main + * thread to wake up earlier than it would otherwise. + * We double check the timeout of the top element to + * handle time distortions due to system suspension. + */ + if (min_heap_elt_is_top_(ev)) + notify = 1; + else if ((top = min_heap_top_(&base->timeheap)) != NULL && evutil_timercmp(&top->ev_timeout, &now, <)) + notify = 1; + } + } + + /* if we are not in the right thread, we need to wake up the loop */ + if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) + evthread_notify_base(base); + + event_debug_note_add_(ev); + + return (res); +} + +static int event_del_(struct event* ev, int blocking) +{ + int res; + + if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { + event_warnx("%s: event has no event_base set.", __func__); + return -1; + } + + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + + res = event_del_nolock_(ev, blocking); + + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); + + return (res); +} + +int event_del(struct event* ev) +{ + return event_del_(ev, EVENT_DEL_AUTOBLOCK); +} + +int event_del_block(struct event* ev) +{ + return event_del_(ev, EVENT_DEL_BLOCK); +} + +int event_del_noblock(struct event* ev) +{ + return event_del_(ev, EVENT_DEL_NOBLOCK); +} + +/** Helper for event_del: always called with th_base_lock held. + * + * "blocking" must be one of the EVENT_DEL_{BLOCK, NOBLOCK, AUTOBLOCK, + * EVEN_IF_FINALIZING} values. See those for more information. + */ +int event_del_nolock_(struct event* ev, int blocking) +{ + struct event_base* base; + int res = 0, notify = 0; + + event_debug(("event_del: %p (fd " EV_SOCK_FMT "), callback %p", ev, EV_SOCK_ARG(ev->ev_fd), ev->ev_callback)); + + /* An event without a base has not been added */ + if (ev->ev_base == NULL) + return (-1); + + EVENT_BASE_ASSERT_LOCKED(ev->ev_base); + + if (blocking != EVENT_DEL_EVEN_IF_FINALIZING) { + if (ev->ev_flags & EVLIST_FINALIZING) { + /* XXXX Debug */ + return 0; + } + } + + /* If the main thread is currently executing this event's callback, + * and we are not the main thread, then we want to wait until the + * callback is done before we start removing the event. That way, + * when this function returns, it will be safe to free the + * user-supplied argument. */ + base = ev->ev_base; +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (blocking != EVENT_DEL_NOBLOCK && base->current_event == event_to_event_callback(ev) && !EVBASE_IN_THREAD(base) + && (blocking == EVENT_DEL_BLOCK || !(ev->ev_events & EV_FINALIZE))) { + ++base->current_event_waiters; + EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); + } +#endif + + EVUTIL_ASSERT(!(ev->ev_flags & ~EVLIST_ALL)); + + /* See if we are just active executing this event in a loop */ + if (ev->ev_events & EV_SIGNAL) { + if (ev->ev_ncalls && ev->ev_pncalls) { + /* Abort loop */ + *ev->ev_pncalls = 0; + } + } + + if (ev->ev_flags & EVLIST_TIMEOUT) { + /* NOTE: We never need to notify the main thread because of a + * deleted timeout event: all that could happen if we don't is + * that the dispatch loop might wake up too early. But the + * point of notifying the main thread _is_ to wake up the + * dispatch loop early anyway, so we wouldn't gain anything by + * doing it. + */ + event_queue_remove_timeout(base, ev); + } + + if (ev->ev_flags & EVLIST_ACTIVE) + event_queue_remove_active(base, event_to_event_callback(ev)); + else if (ev->ev_flags & EVLIST_ACTIVE_LATER) + event_queue_remove_active_later(base, event_to_event_callback(ev)); + + if (ev->ev_flags & EVLIST_INSERTED) { + event_queue_remove_inserted(base, ev); + if (ev->ev_events & (EV_READ | EV_WRITE | EV_CLOSED)) + res = evmap_io_del_(base, ev->ev_fd, ev); + else + res = evmap_signal_del_(base, (int)ev->ev_fd, ev); + if (res == 1) { + /* evmap says we need to notify the main thread. */ + notify = 1; + res = 0; + } + } + + /* if we are not in the right thread, we need to wake up the loop */ + if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) + evthread_notify_base(base); + + event_debug_note_del_(ev); + + return (res); +} + +void event_active(struct event* ev, int res, short ncalls) +{ + if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { + event_warnx("%s: event has no event_base set.", __func__); + return; + } + + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + + event_debug_assert_is_setup_(ev); + + event_active_nolock_(ev, res, ncalls); + + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); +} + +void event_active_nolock_(struct event* ev, int res, short ncalls) +{ + struct event_base* base; + + event_debug(("event_active: %p (fd " EV_SOCK_FMT "), res %d, callback %p", ev, EV_SOCK_ARG(ev->ev_fd), (int)res, ev->ev_callback)); + + base = ev->ev_base; + EVENT_BASE_ASSERT_LOCKED(base); + + if (ev->ev_flags & EVLIST_FINALIZING) { + /* XXXX debug */ + return; + } + + switch ((ev->ev_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER))) { + default: + case EVLIST_ACTIVE | EVLIST_ACTIVE_LATER: + EVUTIL_ASSERT(0); + break; + case EVLIST_ACTIVE: + /* We get different kinds of events, add them together */ + ev->ev_res |= res; + return; + case EVLIST_ACTIVE_LATER: + ev->ev_res |= res; + break; + case 0: + ev->ev_res = res; + break; + } + + if (ev->ev_pri < base->event_running_priority) + base->event_continue = 1; + + if (ev->ev_events & EV_SIGNAL) { +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (base->current_event == event_to_event_callback(ev) && !EVBASE_IN_THREAD(base)) { + ++base->current_event_waiters; + EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); + } +#endif + ev->ev_ncalls = ncalls; + ev->ev_pncalls = NULL; + } + + event_callback_activate_nolock_(base, event_to_event_callback(ev)); +} + +void event_active_later_(struct event* ev, int res) +{ + EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); + event_active_later_nolock_(ev, res); + EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); +} + +void event_active_later_nolock_(struct event* ev, int res) +{ + struct event_base* base = ev->ev_base; + EVENT_BASE_ASSERT_LOCKED(base); + + if (ev->ev_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER)) { + /* We get different kinds of events, add them together */ + ev->ev_res |= res; + return; + } + + ev->ev_res = res; + + event_callback_activate_later_nolock_(base, event_to_event_callback(ev)); +} + +int event_callback_activate_(struct event_base* base, struct event_callback* evcb) +{ + int r; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_callback_activate_nolock_(base, evcb); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +int event_callback_activate_nolock_(struct event_base* base, struct event_callback* evcb) +{ + int r = 1; + + if (evcb->evcb_flags & EVLIST_FINALIZING) + return 0; + + switch (evcb->evcb_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER)) { + default: + EVUTIL_ASSERT(0); + case EVLIST_ACTIVE_LATER: + event_queue_remove_active_later(base, evcb); + r = 0; + break; + case EVLIST_ACTIVE: + return 0; + case 0: + break; + } + + event_queue_insert_active(base, evcb); + + if (EVBASE_NEED_NOTIFY(base)) + evthread_notify_base(base); + + return r; +} + +int event_callback_activate_later_nolock_(struct event_base* base, struct event_callback* evcb) +{ + if (evcb->evcb_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER)) + return 0; + + event_queue_insert_active_later(base, evcb); + if (EVBASE_NEED_NOTIFY(base)) + evthread_notify_base(base); + return 1; +} + +void event_callback_init_(struct event_base* base, struct event_callback* cb) +{ + memset(cb, 0, sizeof(*cb)); + cb->evcb_pri = base->nactivequeues - 1; +} + +int event_callback_cancel_(struct event_base* base, struct event_callback* evcb) +{ + int r; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_callback_cancel_nolock_(base, evcb, 0); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +int event_callback_cancel_nolock_(struct event_base* base, struct event_callback* evcb, int even_if_finalizing) +{ + if ((evcb->evcb_flags & EVLIST_FINALIZING) && !even_if_finalizing) + return 0; + + if (evcb->evcb_flags & EVLIST_INIT) + return event_del_nolock_(event_callback_to_event(evcb), even_if_finalizing ? EVENT_DEL_EVEN_IF_FINALIZING : EVENT_DEL_AUTOBLOCK); + + switch ((evcb->evcb_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER))) { + default: + case EVLIST_ACTIVE | EVLIST_ACTIVE_LATER: + EVUTIL_ASSERT(0); + break; + case EVLIST_ACTIVE: + /* We get different kinds of events, add them together */ + event_queue_remove_active(base, evcb); + return 0; + case EVLIST_ACTIVE_LATER: + event_queue_remove_active_later(base, evcb); + break; + case 0: + break; + } + + return 0; +} + +void event_deferred_cb_init_(struct event_callback* cb, ev_uint8_t priority, deferred_cb_fn fn, void* arg) +{ + memset(cb, 0, sizeof(*cb)); + cb->evcb_cb_union.evcb_selfcb = fn; + cb->evcb_arg = arg; + cb->evcb_pri = priority; + cb->evcb_closure = EV_CLOSURE_CB_SELF; +} + +void event_deferred_cb_set_priority_(struct event_callback* cb, ev_uint8_t priority) +{ + cb->evcb_pri = priority; +} + +void event_deferred_cb_cancel_(struct event_base* base, struct event_callback* cb) +{ + if (!base) + base = current_base; + event_callback_cancel_(base, cb); +} + +#define MAX_DEFERREDS_QUEUED 32 +int event_deferred_cb_schedule_(struct event_base* base, struct event_callback* cb) +{ + int r = 1; + if (!base) + base = current_base; + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + if (base->n_deferreds_queued > MAX_DEFERREDS_QUEUED) { + r = event_callback_activate_later_nolock_(base, cb); + } else { + r = event_callback_activate_nolock_(base, cb); + if (r) { + ++base->n_deferreds_queued; + } + } + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +static int timeout_next(struct event_base* base, struct timeval** tv_p) +{ + /* Caller must hold th_base_lock */ + struct timeval now; + struct event* ev; + struct timeval* tv = *tv_p; + int res = 0; + + ev = min_heap_top_(&base->timeheap); + + if (ev == NULL) { + /* if no time-based events are active wait for I/O */ + *tv_p = NULL; + goto out; + } + + if (gettime(base, &now) == -1) { + res = -1; + goto out; + } + + if (evutil_timercmp(&ev->ev_timeout, &now, <=)) { + evutil_timerclear(tv); + goto out; + } + + evutil_timersub(&ev->ev_timeout, &now, tv); + + EVUTIL_ASSERT(tv->tv_sec >= 0); + EVUTIL_ASSERT(tv->tv_usec >= 0); + event_debug(("timeout_next: event: %p, in %d seconds, %d useconds", ev, (int)tv->tv_sec, (int)tv->tv_usec)); + +out: + return (res); +} + +/* Activate every event whose timeout has elapsed. */ +static void timeout_process(struct event_base* base) +{ + /* Caller must hold lock. */ + struct timeval now; + struct event* ev; + + if (min_heap_empty_(&base->timeheap)) { + return; + } + + gettime(base, &now); + + while ((ev = min_heap_top_(&base->timeheap))) { + if (evutil_timercmp(&ev->ev_timeout, &now, >)) + break; + + /* delete this event from the I/O queues */ + event_del_nolock_(ev, EVENT_DEL_NOBLOCK); + + event_debug(("timeout_process: event: %p, call %p", ev, ev->ev_callback)); + event_active_nolock_(ev, EV_TIMEOUT, 1); + } +} + +#if (EVLIST_INTERNAL >> 4) != 1 +#error "Mismatch for value of EVLIST_INTERNAL" +#endif + +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +#define MAX_EVENT_COUNT(var, v) var = MAX(var, v) + +/* These are a fancy way to spell + if (flags & EVLIST_INTERNAL) + base->event_count--/++; +*/ +#define DECR_EVENT_COUNT(base, flags) ((base)->event_count -= (~((flags) >> 4) & 1)) +#define INCR_EVENT_COUNT(base, flags) \ + do { \ + ((base)->event_count += (~((flags) >> 4) & 1)); \ + MAX_EVENT_COUNT((base)->event_count_max, (base)->event_count); \ + } while (0) + +static void event_queue_remove_inserted(struct event_base* base, struct event* ev) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_INSERTED))) { + event_errx(1, "%s: %p(fd " EV_SOCK_FMT ") not on queue %x", __func__, ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_INSERTED); + return; + } + DECR_EVENT_COUNT(base, ev->ev_flags); + ev->ev_flags &= ~EVLIST_INSERTED; +} +static void event_queue_remove_active(struct event_base* base, struct event_callback* evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (EVUTIL_FAILURE_CHECK(!(evcb->evcb_flags & EVLIST_ACTIVE))) { + event_errx(1, "%s: %p not on queue %x", __func__, evcb, EVLIST_ACTIVE); + return; + } + DECR_EVENT_COUNT(base, evcb->evcb_flags); + evcb->evcb_flags &= ~EVLIST_ACTIVE; + base->event_count_active--; + + TAILQ_REMOVE(&base->activequeues[evcb->evcb_pri], evcb, evcb_active_next); +} +static void event_queue_remove_active_later(struct event_base* base, struct event_callback* evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (EVUTIL_FAILURE_CHECK(!(evcb->evcb_flags & EVLIST_ACTIVE_LATER))) { + event_errx(1, "%s: %p not on queue %x", __func__, evcb, EVLIST_ACTIVE_LATER); + return; + } + DECR_EVENT_COUNT(base, evcb->evcb_flags); + evcb->evcb_flags &= ~EVLIST_ACTIVE_LATER; + base->event_count_active--; + + TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); +} +static void event_queue_remove_timeout(struct event_base* base, struct event* ev) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_TIMEOUT))) { + event_errx(1, "%s: %p(fd " EV_SOCK_FMT ") not on queue %x", __func__, ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_TIMEOUT); + return; + } + DECR_EVENT_COUNT(base, ev->ev_flags); + ev->ev_flags &= ~EVLIST_TIMEOUT; + + if (is_common_timeout(&ev->ev_timeout, base)) { + struct common_timeout_list* ctl = get_common_timeout_list(base, &ev->ev_timeout); + TAILQ_REMOVE(&ctl->events, ev, ev_timeout_pos.ev_next_with_common_timeout); + } else { + min_heap_erase_(&base->timeheap, ev); + } +} + +#ifdef USE_REINSERT_TIMEOUT +/* Remove and reinsert 'ev' into the timeout queue. */ +static void event_queue_reinsert_timeout(struct event_base* base, struct event* ev, int was_common, int is_common, int old_timeout_idx) +{ + struct common_timeout_list* ctl; + if (!(ev->ev_flags & EVLIST_TIMEOUT)) { + event_queue_insert_timeout(base, ev); + return; + } + + switch ((was_common << 1) | is_common) { + case 3: /* Changing from one common timeout to another */ + ctl = base->common_timeout_queues[old_timeout_idx]; + TAILQ_REMOVE(&ctl->events, ev, ev_timeout_pos.ev_next_with_common_timeout); + ctl = get_common_timeout_list(base, &ev->ev_timeout); + insert_common_timeout_inorder(ctl, ev); + break; + case 2: /* Was common; is no longer common */ + ctl = base->common_timeout_queues[old_timeout_idx]; + TAILQ_REMOVE(&ctl->events, ev, ev_timeout_pos.ev_next_with_common_timeout); + min_heap_push_(&base->timeheap, ev); + break; + case 1: /* Wasn't common; has become common. */ + min_heap_erase_(&base->timeheap, ev); + ctl = get_common_timeout_list(base, &ev->ev_timeout); + insert_common_timeout_inorder(ctl, ev); + break; + case 0: /* was in heap; is still on heap. */ + min_heap_adjust_(&base->timeheap, ev); + break; + default: + EVUTIL_ASSERT(0); /* unreachable */ + break; + } +} +#endif + +/* Add 'ev' to the common timeout list in 'ev'. */ +static void insert_common_timeout_inorder(struct common_timeout_list* ctl, struct event* ev) +{ + struct event* e; + /* By all logic, we should just be able to append 'ev' to the end of + * ctl->events, since the timeout on each 'ev' is set to {the common + * timeout} + {the time when we add the event}, and so the events + * should arrive in order of their timeeouts. But just in case + * there's some wacky threading issue going on, we do a search from + * the end of 'ev' to find the right insertion point. + */ + TAILQ_FOREACH_REVERSE(e, &ctl->events, event_list, ev_timeout_pos.ev_next_with_common_timeout) + { + /* This timercmp is a little sneaky, since both ev and e have + * magic values in tv_usec. Fortunately, they ought to have + * the _same_ magic values in tv_usec. Let's assert for that. + */ + EVUTIL_ASSERT(is_same_common_timeout(&e->ev_timeout, &ev->ev_timeout)); + if (evutil_timercmp(&ev->ev_timeout, &e->ev_timeout, >=)) { + TAILQ_INSERT_AFTER(&ctl->events, e, ev, ev_timeout_pos.ev_next_with_common_timeout); + return; + } + } + TAILQ_INSERT_HEAD(&ctl->events, ev, ev_timeout_pos.ev_next_with_common_timeout); +} + +static void event_queue_insert_inserted(struct event_base* base, struct event* ev) +{ + EVENT_BASE_ASSERT_LOCKED(base); + + if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_INSERTED)) { + event_errx(1, "%s: %p(fd " EV_SOCK_FMT ") already inserted", __func__, ev, EV_SOCK_ARG(ev->ev_fd)); + return; + } + + INCR_EVENT_COUNT(base, ev->ev_flags); + + ev->ev_flags |= EVLIST_INSERTED; +} + +static void event_queue_insert_active(struct event_base* base, struct event_callback* evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + + if (evcb->evcb_flags & EVLIST_ACTIVE) { + /* Double insertion is possible for active events */ + return; + } + + INCR_EVENT_COUNT(base, evcb->evcb_flags); + + evcb->evcb_flags |= EVLIST_ACTIVE; + + base->event_count_active++; + MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); + EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); + TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], evcb, evcb_active_next); +} + +static void event_queue_insert_active_later(struct event_base* base, struct event_callback* evcb) +{ + EVENT_BASE_ASSERT_LOCKED(base); + if (evcb->evcb_flags & (EVLIST_ACTIVE_LATER | EVLIST_ACTIVE)) { + /* Double insertion is possible */ + return; + } + + INCR_EVENT_COUNT(base, evcb->evcb_flags); + evcb->evcb_flags |= EVLIST_ACTIVE_LATER; + base->event_count_active++; + MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); + EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); + TAILQ_INSERT_TAIL(&base->active_later_queue, evcb, evcb_active_next); +} + +static void event_queue_insert_timeout(struct event_base* base, struct event* ev) +{ + EVENT_BASE_ASSERT_LOCKED(base); + + if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_TIMEOUT)) { + event_errx(1, "%s: %p(fd " EV_SOCK_FMT ") already on timeout", __func__, ev, EV_SOCK_ARG(ev->ev_fd)); + return; + } + + INCR_EVENT_COUNT(base, ev->ev_flags); + + ev->ev_flags |= EVLIST_TIMEOUT; + + if (is_common_timeout(&ev->ev_timeout, base)) { + struct common_timeout_list* ctl = get_common_timeout_list(base, &ev->ev_timeout); + insert_common_timeout_inorder(ctl, ev); + } else { + min_heap_push_(&base->timeheap, ev); + } +} + +static void event_queue_make_later_events_active(struct event_base* base) +{ + struct event_callback* evcb; + EVENT_BASE_ASSERT_LOCKED(base); + + while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { + TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); + evcb->evcb_flags = (evcb->evcb_flags & ~EVLIST_ACTIVE_LATER) | EVLIST_ACTIVE; + EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); + TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], evcb, evcb_active_next); + base->n_deferreds_queued += (evcb->evcb_closure == EV_CLOSURE_CB_SELF); + } +} + +/* Functions for debugging */ + +const char* event_get_version(void) +{ + return (EVENT__VERSION); +} + +ev_uint32_t event_get_version_number(void) +{ + return (EVENT__NUMERIC_VERSION); +} + +/* + * No thread-safe interface needed - the information should be the same + * for all threads. + */ + +const char* event_get_method(void) +{ + return (current_base->evsel->name); +} + +#ifdef EVENT__HAVE_EVENTFD +static void evthread_notify_drain_eventfd(evutil_socket_t fd, short what, void* arg) +{ + ev_uint64_t msg; + ev_ssize_t r; + struct event_base* base = arg; + + r = read(fd, (void*)&msg, sizeof(msg)); + if (r < 0 && errno != EAGAIN) { + event_sock_warn(fd, "Error reading from eventfd"); + } + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + base->is_notify_pending = 0; + EVBASE_RELEASE_LOCK(base, th_base_lock); +} +#endif + +static void evthread_notify_drain_default(evutil_socket_t fd, short what, void* arg) +{ + unsigned char buf[1024]; + struct event_base* base = arg; +#ifdef _WIN32 + while (recv(fd, (char*)buf, sizeof(buf), 0) > 0) + ; +#else + while (read(fd, (char*)buf, sizeof(buf)) > 0) + ; +#endif + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + base->is_notify_pending = 0; + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +int evthread_make_base_notifiable(struct event_base* base) +{ + int r; + if (!base) + return -1; + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = evthread_make_base_notifiable_nolock_(base); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +static int evthread_make_base_notifiable_nolock_(struct event_base* base) +{ + void (*cb)(evutil_socket_t, short, void*); + int (*notify)(struct event_base*); + + if (base->th_notify_fn != NULL) { + /* The base is already notifiable: we're doing fine. */ + return 0; + } + +#if defined(EVENT__HAVE_WORKING_KQUEUE) + if (base->evsel == &kqops && event_kq_add_notify_event_(base) == 0) { + base->th_notify_fn = event_kq_notify_base_; + /* No need to add an event here; the backend can wake + * itself up just fine. */ + return 0; + } +#endif + +#ifdef EVENT__HAVE_EVENTFD + base->th_notify_fd[0] = evutil_eventfd_(0, EVUTIL_EFD_CLOEXEC | EVUTIL_EFD_NONBLOCK); + if (base->th_notify_fd[0] >= 0) { + base->th_notify_fd[1] = -1; + notify = evthread_notify_base_eventfd; + cb = evthread_notify_drain_eventfd; + } else +#endif + if (evutil_make_internal_pipe_(base->th_notify_fd) == 0) { + notify = evthread_notify_base_default; + cb = evthread_notify_drain_default; + } else { + return -1; + } + + base->th_notify_fn = notify; + + /* prepare an event that we can use for wakeup */ + event_assign(&base->th_notify, base, base->th_notify_fd[0], EV_READ | EV_PERSIST, cb, base); + + /* we need to mark this as internal event */ + base->th_notify.ev_flags |= EVLIST_INTERNAL; + event_priority_set(&base->th_notify, 0); + + return event_add_nolock_(&base->th_notify, NULL, 0); +} + +int event_base_foreach_event_nolock_(struct event_base* base, event_base_foreach_event_cb fn, void* arg) +{ + int r, i; + unsigned u; + struct event* ev; + + /* Start out with all the EVLIST_INSERTED events. */ + if ((r = evmap_foreach_event_(base, fn, arg))) + return r; + + /* Okay, now we deal with those events that have timeouts and are in + * the min-heap. */ + for (u = 0; u < base->timeheap.n; ++u) { + ev = base->timeheap.p[u]; + if (ev->ev_flags & EVLIST_INSERTED) { + /* we already processed this one */ + continue; + } + if ((r = fn(base, ev, arg))) + return r; + } + + /* Now for the events in one of the timeout queues. + * the min-heap. */ + for (i = 0; i < base->n_common_timeouts; ++i) { + struct common_timeout_list* ctl = base->common_timeout_queues[i]; + TAILQ_FOREACH(ev, &ctl->events, ev_timeout_pos.ev_next_with_common_timeout) + { + if (ev->ev_flags & EVLIST_INSERTED) { + /* we already processed this one */ + continue; + } + if ((r = fn(base, ev, arg))) + return r; + } + } + + /* Finally, we deal wit all the active events that we haven't touched + * yet. */ + for (i = 0; i < base->nactivequeues; ++i) { + struct event_callback* evcb; + TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) + { + if ((evcb->evcb_flags & (EVLIST_INIT | EVLIST_INSERTED | EVLIST_TIMEOUT)) != EVLIST_INIT) { + /* This isn't an event (evlist_init clear), or + * we already processed it. (inserted or + * timeout set */ + continue; + } + ev = event_callback_to_event(evcb); + if ((r = fn(base, ev, arg))) + return r; + } + } + + return 0; +} + +/* Helper for event_base_dump_events: called on each event in the event base; + * dumps only the inserted events. */ +static int dump_inserted_event_fn(const struct event_base* base, const struct event* e, void* arg) +{ + FILE* output = arg; + const char* gloss = (e->ev_events & EV_SIGNAL) ? "sig" : "fd "; + + if (!(e->ev_flags & (EVLIST_INSERTED | EVLIST_TIMEOUT))) + return 0; + + fprintf( + output, " %p [%s " EV_SOCK_FMT "]%s%s%s%s%s%s", (void*)e, gloss, EV_SOCK_ARG(e->ev_fd), (e->ev_events & EV_READ) ? " Read" : "", + (e->ev_events & EV_WRITE) ? " Write" : "", (e->ev_events & EV_CLOSED) ? " EOF" : "", (e->ev_events & EV_SIGNAL) ? " Signal" : "", + (e->ev_events & EV_PERSIST) ? " Persist" : "", (e->ev_flags & EVLIST_INTERNAL) ? " Internal" : ""); + if (e->ev_flags & EVLIST_TIMEOUT) { + struct timeval tv; + tv.tv_sec = e->ev_timeout.tv_sec; + tv.tv_usec = e->ev_timeout.tv_usec & MICROSECONDS_MASK; + evutil_timeradd(&tv, &base->tv_clock_diff, &tv); + fprintf(output, " Timeout=%ld.%06d", (long)tv.tv_sec, (int)(tv.tv_usec & MICROSECONDS_MASK)); + } + fputc('\n', output); + + return 0; +} + +/* Helper for event_base_dump_events: called on each event in the event base; + * dumps only the active events. */ +static int dump_active_event_fn(const struct event_base* base, const struct event* e, void* arg) +{ + FILE* output = arg; + const char* gloss = (e->ev_events & EV_SIGNAL) ? "sig" : "fd "; + + if (!(e->ev_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER))) + return 0; + + fprintf( + output, " %p [%s " EV_SOCK_FMT ", priority=%d]%s%s%s%s%s active%s%s\n", (void*)e, gloss, EV_SOCK_ARG(e->ev_fd), e->ev_pri, + (e->ev_res & EV_READ) ? " Read" : "", (e->ev_res & EV_WRITE) ? " Write" : "", (e->ev_res & EV_CLOSED) ? " EOF" : "", + (e->ev_res & EV_SIGNAL) ? " Signal" : "", (e->ev_res & EV_TIMEOUT) ? " Timeout" : "", (e->ev_flags & EVLIST_INTERNAL) ? " [Internal]" : "", + (e->ev_flags & EVLIST_ACTIVE_LATER) ? " [NextTime]" : ""); + + return 0; +} + +int event_base_foreach_event(struct event_base* base, event_base_foreach_event_cb fn, void* arg) +{ + int r; + if ((!fn) || (!base)) { + return -1; + } + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + r = event_base_foreach_event_nolock_(base, fn, arg); + EVBASE_RELEASE_LOCK(base, th_base_lock); + return r; +} + +void event_base_dump_events(struct event_base* base, FILE* output) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + fprintf(output, "Inserted events:\n"); + event_base_foreach_event_nolock_(base, dump_inserted_event_fn, output); + + fprintf(output, "Active events:\n"); + event_base_foreach_event_nolock_(base, dump_active_event_fn, output); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +void event_base_active_by_fd(struct event_base* base, evutil_socket_t fd, short events) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + evmap_io_active_(base, fd, events & (EV_READ | EV_WRITE | EV_CLOSED)); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +void event_base_active_by_signal(struct event_base* base, int sig) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + evmap_signal_active_(base, sig, 1); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +void event_base_add_virtual_(struct event_base* base) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + base->virtual_event_count++; + MAX_EVENT_COUNT(base->virtual_event_count_max, base->virtual_event_count); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +void event_base_del_virtual_(struct event_base* base) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + EVUTIL_ASSERT(base->virtual_event_count > 0); + base->virtual_event_count--; + if (base->virtual_event_count == 0 && EVBASE_NEED_NOTIFY(base)) + evthread_notify_base(base); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +static void event_free_debug_globals_locks(void) +{ +#ifndef EVENT__DISABLE_THREAD_SUPPORT +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_map_lock_ != NULL) { + EVTHREAD_FREE_LOCK(event_debug_map_lock_, 0); + event_debug_map_lock_ = NULL; + evthreadimpl_disable_lock_debugging_(); + } +#endif /* EVENT__DISABLE_DEBUG_MODE */ +#endif /* EVENT__DISABLE_THREAD_SUPPORT */ + return; +} + +static void event_free_debug_globals(void) +{ + event_free_debug_globals_locks(); +} + +static void event_free_evsig_globals(void) +{ + evsig_free_globals_(); +} + +static void event_free_evutil_globals(void) +{ + evutil_free_globals_(); +} + +static void event_free_globals(void) +{ + event_free_debug_globals(); + event_free_evsig_globals(); + event_free_evutil_globals(); +} + +void libevent_global_shutdown(void) +{ + event_disable_debug_mode(); + event_free_globals(); +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +int event_global_setup_locks_(const int enable_locks) +{ +#ifndef EVENT__DISABLE_DEBUG_MODE + EVTHREAD_SETUP_GLOBAL_LOCK(event_debug_map_lock_, 0); +#endif + if (evsig_global_setup_locks_(enable_locks) < 0) + return -1; + if (evutil_global_setup_locks_(enable_locks) < 0) + return -1; + if (evutil_secure_rng_global_setup_locks_(enable_locks) < 0) + return -1; + return 0; +} +#endif + +void event_base_assert_ok_(struct event_base* base) +{ + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + event_base_assert_ok_nolock_(base); + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +void event_base_assert_ok_nolock_(struct event_base* base) +{ + int i; + int count; + + /* First do checks on the per-fd and per-signal lists */ + evmap_check_integrity_(base); + + /* Check the heap property */ + for (i = 1; i < (int)base->timeheap.n; ++i) { + int parent = (i - 1) / 2; + struct event *ev, *p_ev; + ev = base->timeheap.p[i]; + p_ev = base->timeheap.p[parent]; + EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); + EVUTIL_ASSERT(evutil_timercmp(&p_ev->ev_timeout, &ev->ev_timeout, <=)); + EVUTIL_ASSERT(ev->ev_timeout_pos.min_heap_idx == i); + } + + /* Check that the common timeouts are fine */ + for (i = 0; i < base->n_common_timeouts; ++i) { + struct common_timeout_list* ctl = base->common_timeout_queues[i]; + struct event *last = NULL, *ev; + + EVUTIL_ASSERT_TAILQ_OK(&ctl->events, event, ev_timeout_pos.ev_next_with_common_timeout); + + TAILQ_FOREACH(ev, &ctl->events, ev_timeout_pos.ev_next_with_common_timeout) + { + if (last) + EVUTIL_ASSERT(evutil_timercmp(&last->ev_timeout, &ev->ev_timeout, <=)); + EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); + EVUTIL_ASSERT(is_common_timeout(&ev->ev_timeout, base)); + EVUTIL_ASSERT(COMMON_TIMEOUT_IDX(&ev->ev_timeout) == i); + last = ev; + } + } + + /* Check the active queues. */ + count = 0; + for (i = 0; i < base->nactivequeues; ++i) { + struct event_callback* evcb; + EVUTIL_ASSERT_TAILQ_OK(&base->activequeues[i], event_callback, evcb_active_next); + TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) + { + EVUTIL_ASSERT((evcb->evcb_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER)) == EVLIST_ACTIVE); + EVUTIL_ASSERT(evcb->evcb_pri == i); + ++count; + } + } + + { + struct event_callback* evcb; + TAILQ_FOREACH(evcb, &base->active_later_queue, evcb_active_next) + { + EVUTIL_ASSERT((evcb->evcb_flags & (EVLIST_ACTIVE | EVLIST_ACTIVE_LATER)) == EVLIST_ACTIVE_LATER); + ++count; + } + } + EVUTIL_ASSERT(count == base->event_count_active); +} diff --git a/asynio/event/event.h b/asynio/event/event.h new file mode 100644 index 0000000000000000000000000000000000000000..73d5fad7c9ead12679a5ebf1440f93584002f1e9 --- /dev/null +++ b/asynio/event/event.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2000-2007 Niels Provos + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef EVENT1_EVENT_H_INCLUDED_ +#define EVENT1_EVENT_H_INCLUDED_ + +/** @file event.h + + A library for writing event-driven network servers. + + The header is deprecated in Libevent 2.0 and later; please + use instead. Depending on what functionality you + need, you may also want to include more of the other event2/ + headers. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#ifdef EVENT__HAVE_STDINT_H +#include +#endif +#include + +/* For int types. */ +#include "util.h" + +#ifdef _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#include +#undef WIN32_LEAN_AND_MEAN +#endif + +#include "event_struct.h" +#include "eventbase.h" +#include "event_compat.h" +#include "buffer.h" +#include "buffer_compat.h" +#include "bufferevent.h" +#include "bufferevent_struct.h" +#include "bufferevent_compat.h" + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT1_EVENT_H_INCLUDED_ */ diff --git a/asynio/event/event_compat.h b/asynio/event/event_compat.h new file mode 100644 index 0000000000000000000000000000000000000000..7d79056819e48fd5bcbf16def02f0707c1b020c9 --- /dev/null +++ b/asynio/event/event_compat.h @@ -0,0 +1,62 @@ +#ifndef EVENT2_EVENT_COMPAT_H_INCLUDED_ +#define EVENT2_EVENT_COMPAT_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +/* For int types. */ +#include "util.h" + +struct event_base* event_init(void); + +int event_dispatch(void); + +int event_loop(int); + +int event_loopexit(const struct timeval*); + +int event_loopbreak(void); + +int event_once(evutil_socket_t, short, void (*)(evutil_socket_t, short, void*), void*, const struct timeval*); + +const char* event_get_method(void); + +int event_priority_init(int); + +void event_set(struct event*, evutil_socket_t, short, void (*)(evutil_socket_t, short, void*), void*); + +#define evtimer_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) +#define evsignal_set(ev, x, cb, arg) event_set((ev), (x), EV_SIGNAL | EV_PERSIST, (cb), (arg)) +#define timeout_add(ev, tv) event_add((ev), (tv)) +#define timeout_set(ev, cb, arg) event_set((ev), -1, 0, (cb), (arg)) +#define timeout_del(ev) event_del(ev) +#define timeout_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv)) +#define timeout_initialized(ev) event_initialized(ev) + +#define signal_add(ev, tv) event_add((ev), (tv)) +#define signal_set(ev, x, cb, arg) event_set((ev), (x), EV_SIGNAL | EV_PERSIST, (cb), (arg)) +#define signal_del(ev) event_del(ev) +#define signal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv)) +#define signal_initialized(ev) event_initialized(ev) + +#ifndef EVENT_FD +/* These macros are obsolete; use event_get_fd and event_get_signal instead. */ +#define EVENT_FD(ev) ((int)event_get_fd(ev)) +#define EVENT_SIGNAL(ev) event_get_signal(ev) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT2_EVENT_COMPAT_H_INCLUDED_ */ diff --git a/asynio/event/event_iocp.c b/asynio/event/event_iocp.c new file mode 100644 index 0000000000000000000000000000000000000000..8e3440329c33570f9e06e5dfaf93fbd3fabbbeed --- /dev/null +++ b/asynio/event/event_iocp.c @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2009-2012 Niels Provos, Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "evconfig-private.h" + +#ifndef _WIN32_WINNT +/* Minimum required for InitializeCriticalSectionAndSpinCount */ +#define _WIN32_WINNT 0x0403 +#endif +#include +#include +#include +#include +#include + +#include "util.h" +#include "util-internal.h" +#include "iocp-internal.h" +#include "log-internal.h" +#include "mm-internal.h" +#include "event-internal.h" +#include "evthread-internal.h" + +#define NOTIFICATION_KEY ((ULONG_PTR)-1) + +void event_overlapped_init_(struct event_overlapped* o, iocp_callback cb) +{ + memset(o, 0, sizeof(struct event_overlapped)); + o->cb = cb; +} + +static void handle_entry(OVERLAPPED* o, ULONG_PTR completion_key, DWORD nBytes, int ok) +{ + struct event_overlapped* eo = EVUTIL_UPCAST(o, struct event_overlapped, overlapped); + eo->cb(eo, completion_key, nBytes, ok); +} + +static void loop(void* port_) +{ + struct event_iocp_port* port = port_; + long ms = port->ms; + HANDLE p = port->port; + + if (ms <= 0) + ms = INFINITE; + + while (1) { + OVERLAPPED* overlapped = NULL; + ULONG_PTR key = 0; + DWORD bytes = 0; + int ok = GetQueuedCompletionStatus(p, &bytes, &key, &overlapped, ms); + EnterCriticalSection(&port->lock); + if (port->shutdown) { + if (--port->n_live_threads == 0) + ReleaseSemaphore(port->shutdownSemaphore, 1, NULL); + LeaveCriticalSection(&port->lock); + return; + } + LeaveCriticalSection(&port->lock); + + if (key != NOTIFICATION_KEY && overlapped) + handle_entry(overlapped, key, bytes, ok); + else if (!overlapped) + break; + } + event_warnx("GetQueuedCompletionStatus exited with no event."); + EnterCriticalSection(&port->lock); + if (--port->n_live_threads == 0) + ReleaseSemaphore(port->shutdownSemaphore, 1, NULL); + LeaveCriticalSection(&port->lock); +} + +int event_iocp_port_associate_(struct event_iocp_port* port, evutil_socket_t fd, ev_uintptr_t key) +{ + HANDLE h; + h = CreateIoCompletionPort((HANDLE)fd, port->port, key, port->n_threads); + if (!h) + return -1; + return 0; +} + +static void* get_extension_function(SOCKET s, const GUID* which_fn) +{ + void* ptr = NULL; + DWORD bytes = 0; + WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, (GUID*)which_fn, sizeof(*which_fn), &ptr, sizeof(ptr), &bytes, NULL, NULL); + + /* No need to detect errors here: if ptr is set, then we have a good + function pointer. Otherwise, we should behave as if we had no + function pointer. + */ + return ptr; +} + +/* Mingw doesn't have these in its mswsock.h. The values are copied from + wine.h. Perhaps if we copy them exactly, the cargo will come again. +*/ +#ifndef WSAID_ACCEPTEX +#define WSAID_ACCEPTEX \ + { \ + 0xb5367df1, 0xcbac, 0x11cf, \ + { \ + 0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \ + } \ + } +#endif +#ifndef WSAID_CONNECTEX +#define WSAID_CONNECTEX \ + { \ + 0x25a207b9, 0xddf3, 0x4660, \ + { \ + 0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e \ + } \ + } +#endif +#ifndef WSAID_GETACCEPTEXSOCKADDRS +#define WSAID_GETACCEPTEXSOCKADDRS \ + { \ + 0xb5367df2, 0xcbac, 0x11cf, \ + { \ + 0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \ + } \ + } +#endif + +static int extension_fns_initialized = 0; + +static void init_extension_functions(struct win32_extension_fns* ext) +{ + const GUID acceptex = WSAID_ACCEPTEX; + const GUID connectex = WSAID_CONNECTEX; + const GUID getacceptexsockaddrs = WSAID_GETACCEPTEXSOCKADDRS; + SOCKET s = socket(AF_INET, SOCK_STREAM, 0); + if (s == INVALID_SOCKET) + return; + ext->AcceptEx = get_extension_function(s, &acceptex); + ext->ConnectEx = get_extension_function(s, &connectex); + ext->GetAcceptExSockaddrs = get_extension_function(s, &getacceptexsockaddrs); + closesocket(s); + + extension_fns_initialized = 1; +} + +static struct win32_extension_fns the_extension_fns; + +const struct win32_extension_fns* event_get_win32_extension_fns_(void) +{ + return &the_extension_fns; +} + +#define N_CPUS_DEFAULT 1 + +struct event_iocp_port* event_iocp_port_launch_(int n_cpus) +{ + struct event_iocp_port* port; + int i; + + if (!extension_fns_initialized) + init_extension_functions(&the_extension_fns); + + if (!(port = mm_calloc(1, sizeof(struct event_iocp_port)))) + return NULL; + + if (n_cpus <= 0) + n_cpus = N_CPUS_DEFAULT; + port->n_threads = n_cpus; + port->threads = mm_calloc(port->n_threads, sizeof(HANDLE)); + if (!port->threads) + goto err; + + port->port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, n_cpus); + port->ms = -1; + if (!port->port) + goto err; + + port->shutdownSemaphore = CreateSemaphore(NULL, 0, 1, NULL); + if (!port->shutdownSemaphore) + goto err; + + for (i = 0; i < port->n_threads; ++i) { + ev_uintptr_t th = _beginthread(loop, 0, port); + if (th == (ev_uintptr_t)-1) + goto err; + port->threads[i] = (HANDLE)th; + ++port->n_live_threads; + } + + InitializeCriticalSectionAndSpinCount(&port->lock, 1000); + + return port; +err: + if (port->port) + CloseHandle(port->port); + if (port->threads) + mm_free(port->threads); + if (port->shutdownSemaphore) + CloseHandle(port->shutdownSemaphore); + mm_free(port); + return NULL; +} + +static void event_iocp_port_unlock_and_free_(struct event_iocp_port* port) +{ + DeleteCriticalSection(&port->lock); + CloseHandle(port->port); + CloseHandle(port->shutdownSemaphore); + mm_free(port->threads); + mm_free(port); +} + +static int event_iocp_notify_all(struct event_iocp_port* port) +{ + int i, r, ok = 1; + for (i = 0; i < port->n_threads; ++i) { + r = PostQueuedCompletionStatus(port->port, 0, NOTIFICATION_KEY, NULL); + if (!r) + ok = 0; + } + return ok ? 0 : -1; +} + +int event_iocp_shutdown_(struct event_iocp_port* port, long waitMsec) +{ + DWORD ms = INFINITE; + int n; + + EnterCriticalSection(&port->lock); + port->shutdown = 1; + LeaveCriticalSection(&port->lock); + event_iocp_notify_all(port); + + if (waitMsec >= 0) + ms = waitMsec; + + WaitForSingleObject(port->shutdownSemaphore, ms); + EnterCriticalSection(&port->lock); + n = port->n_live_threads; + LeaveCriticalSection(&port->lock); + if (n == 0) { + event_iocp_port_unlock_and_free_(port); + return 0; + } else { + return -1; + } +} + +int event_iocp_activate_overlapped_(struct event_iocp_port* port, struct event_overlapped* o, ev_uintptr_t key, ev_uint32_t n) +{ + BOOL r; + + r = PostQueuedCompletionStatus(port->port, n, key, &o->overlapped); + return (r == 0) ? -1 : 0; +} + +struct event_iocp_port* event_base_get_iocp_(struct event_base* base) +{ +#ifdef _WIN32 + return base->iocp; +#else + return NULL; +#endif +} diff --git a/asynio/event/event_struct.h b/asynio/event/event_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..fe57923fa3e2914f2c222ffb34c9bcde511bddb0 --- /dev/null +++ b/asynio/event/event_struct.h @@ -0,0 +1,155 @@ +#ifndef EVENT2_EVENT_STRUCT_H_INCLUDED_ +#define EVENT2_EVENT_STRUCT_H_INCLUDED_ + +/** @file event2/event_struct.h + + Structures used by event.h. Using these structures directly WILL harm + forward compatibility: be careful. + + No field declared in this file should be used directly in user code. Except + for historical reasons, these fields would not be exposed at all. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +/* For int types. */ +#include "util.h" + +/* For evkeyvalq */ +#include "keyvalq_struct.h" + +#define EVLIST_TIMEOUT 0x01 +#define EVLIST_INSERTED 0x02 +#define EVLIST_SIGNAL 0x04 +#define EVLIST_ACTIVE 0x08 +#define EVLIST_INTERNAL 0x10 +#define EVLIST_ACTIVE_LATER 0x20 +#define EVLIST_FINALIZING 0x40 +#define EVLIST_INIT 0x80 + +#define EVLIST_ALL 0xff + +/* Fix so that people don't have to run with */ +#ifndef TAILQ_ENTRY +#define EVENT_DEFINED_TQENTRY_ +#define TAILQ_ENTRY(type) \ + struct { \ + struct type* tqe_next; /* next element */ \ + struct type** tqe_prev; /* address of previous next element */ \ + } +#endif /* !TAILQ_ENTRY */ + +#ifndef TAILQ_HEAD +#define EVENT_DEFINED_TQHEAD_ +#define TAILQ_HEAD(name, type) \ + struct name { \ + struct type* tqh_first; \ + struct type** tqh_last; \ + } +#endif + +/* Fix so that people don't have to run with */ +#ifndef LIST_ENTRY +#define EVENT_DEFINED_LISTENTRY_ +#define LIST_ENTRY(type) \ + struct { \ + struct type* le_next; /* next element */ \ + struct type** le_prev; /* address of previous next element */ \ + } +#endif /* !LIST_ENTRY */ + +#ifndef LIST_HEAD +#define EVENT_DEFINED_LISTHEAD_ +#define LIST_HEAD(name, type) \ + struct name { \ + struct type* lh_first; /* first element */ \ + } +#endif /* !LIST_HEAD */ + +struct event; + +struct event_callback { + TAILQ_ENTRY(event_callback) evcb_active_next; + short evcb_flags; + ev_uint8_t evcb_pri; /* smaller numbers are higher priority */ + ev_uint8_t evcb_closure; + /* allows us to adopt for different types of events */ + union { + void (*evcb_callback)(evutil_socket_t, short, void*); + void (*evcb_selfcb)(struct event_callback*, void*); + void (*evcb_evfinalize)(struct event*, void*); + void (*evcb_cbfinalize)(struct event_callback*, void*); + } evcb_cb_union; + void* evcb_arg; +}; + +struct event_base; +struct event { + struct event_callback ev_evcallback; + + /* for managing timeouts */ + union { + TAILQ_ENTRY(event) ev_next_with_common_timeout; + int min_heap_idx; + } ev_timeout_pos; + evutil_socket_t ev_fd; + + struct event_base* ev_base; + + union { + /* used for io events */ + struct { + LIST_ENTRY(event) ev_io_next; + struct timeval ev_timeout; + } ev_io; + + /* used by signal events */ + struct { + LIST_ENTRY(event) ev_signal_next; + short ev_ncalls; + /* Allows deletes in callback */ + short* ev_pncalls; + } ev_signal; + } ev_; + + short ev_events; + short ev_res; /* result passed to event callback */ + struct timeval ev_timeout; +}; + +TAILQ_HEAD(event_list, event); + +#ifdef EVENT_DEFINED_TQENTRY_ +#undef TAILQ_ENTRY +#endif + +#ifdef EVENT_DEFINED_TQHEAD_ +#undef TAILQ_HEAD +#endif + +LIST_HEAD(event_dlist, event); + +#ifdef EVENT_DEFINED_LISTENTRY_ +#undef LIST_ENTRY +#endif + +#ifdef EVENT_DEFINED_LISTHEAD_ +#undef LIST_HEAD +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */ diff --git a/asynio/event/eventbase.h b/asynio/event/eventbase.h new file mode 100644 index 0000000000000000000000000000000000000000..c52f6d71aa7fe6a21ba1c18d0f6a729b4d9f4392 --- /dev/null +++ b/asynio/event/eventbase.h @@ -0,0 +1,324 @@ +#ifndef EVENT2_EVENT_H_INCLUDED_ +#define EVENT2_EVENT_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif + +#include + +/* For int types. */ +#include "util.h" + +struct event_base +#ifdef EVENT_IN_DOXYGEN_ +{ /*Empty body so that doxygen will generate documentation here.*/ +} +#endif +; + +struct event +#ifdef EVENT_IN_DOXYGEN_ +{ /*Empty body so that doxygen will generate documentation here.*/ +} +#endif +; + +struct event_config +#ifdef EVENT_IN_DOXYGEN_ +{ /*Empty body so that doxygen will generate documentation here.*/ +} +#endif +; + +void event_enable_debug_mode(void); + +void event_debug_unassign(struct event*); + +struct event_base* event_base_new(void); + +int event_reinit(struct event_base* base); + +int event_base_dispatch(struct event_base*); + +const char* event_base_get_method(const struct event_base*); + +const char** event_get_supported_methods(void); + +int event_gettime_monotonic(struct event_base* base, struct timeval* tp); + +#define EVENT_BASE_COUNT_ACTIVE 1U + +#define EVENT_BASE_COUNT_VIRTUAL 2U + +#define EVENT_BASE_COUNT_ADDED 4U + +int event_base_get_num_events(struct event_base*, unsigned int); + +int event_base_get_max_events(struct event_base*, unsigned int, int); + +struct event_config* event_config_new(void); + +void event_config_free(struct event_config* cfg); + +int event_config_avoid_method(struct event_config* cfg, const char* method); + +enum event_method_feature { + /** Require an event method that allows edge-triggered events with EV_ET. */ + EV_FEATURE_ET = 0x01, + /** Require an event method where having one event triggered among + * many is [approximately] an O(1) operation. This excludes (for + * example) select and poll, which are approximately O(N) for N + * equal to the total number of possible events. */ + EV_FEATURE_O1 = 0x02, + /** Require an event method that allows file descriptors as well as + * sockets. */ + EV_FEATURE_FDS = 0x04, + /** Require an event method that allows you to use EV_CLOSED to detect + * connection close without the necessity of reading all the pending data. + * + * Methods that do support EV_CLOSED may not be able to provide support on + * all kernel versions. + **/ + EV_FEATURE_EARLY_CLOSE = 0x08 +}; + +enum event_base_config_flag { + /** Do not allocate a lock for the event base, even if we have + locking set up. + + Setting this option will make it unsafe and nonfunctional to call + functions on the base concurrently from multiple threads. + */ + EVENT_BASE_FLAG_NOLOCK = 0x01, + /** Do not check the EVENT_* environment variables when configuring + an event_base */ + EVENT_BASE_FLAG_IGNORE_ENV = 0x02, + /** Windows only: enable the IOCP dispatcher at startup + + If this flag is set then bufferevent_socket_new() and + evconn_listener_new() will use IOCP-backed implementations + instead of the usual select-based one on Windows. + */ + EVENT_BASE_FLAG_STARTUP_IOCP = 0x04, + /** Instead of checking the current time every time the event loop is + ready to run timeout callbacks, check after each timeout callback. + */ + EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08, + + /** If we are using the epoll backend, this flag says that it is + safe to use Libevent's internal change-list code to batch up + adds and deletes in order to try to do as few syscalls as + possible. Setting this flag can make your code run faster, but + it may trigger a Linux bug: it is not safe to use this flag + if you have any fds cloned by dup() or its variants. Doing so + will produce strange and hard-to-diagnose bugs. + + This flag can also be activated by setting the + EVENT_EPOLL_USE_CHANGELIST environment variable. + + This flag has no effect if you wind up using a backend other than + epoll. + */ + EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST = 0x10, + + /** Ordinarily, Libevent implements its time and timeout code using + the fastest monotonic timer that we have. If this flag is set, + however, we use less efficient more precise timer, assuming one is + present. + */ + EVENT_BASE_FLAG_PRECISE_TIMER = 0x20 +}; + +int event_base_get_features(const struct event_base* base); + +int event_config_require_features(struct event_config* cfg, int feature); + +int event_config_set_flag(struct event_config* cfg, int flag); + +int event_config_set_num_cpus_hint(struct event_config* cfg, int cpus); + +int event_config_set_max_dispatch_interval(struct event_config* cfg, const struct timeval* max_interval, int max_callbacks, int min_priority); + +struct event_base* event_base_new_with_config(const struct event_config*); + +void event_base_free(struct event_base*); + +void event_base_free_nofinalize(struct event_base*); + +#define EVENT_LOG_DEBUG 0 +#define EVENT_LOG_MSG 1 +#define EVENT_LOG_WARN 2 +#define EVENT_LOG_ERR 3 + +#define _EVENT_LOG_DEBUG EVENT_LOG_DEBUG +#define _EVENT_LOG_MSG EVENT_LOG_MSG +#define _EVENT_LOG_WARN EVENT_LOG_WARN +#define _EVENT_LOG_ERR EVENT_LOG_ERR + +typedef void (*event_log_cb)(int severity, const char* msg); + +void event_set_log_callback(event_log_cb cb); + +typedef void (*event_fatal_cb)(int err); + +void event_set_fatal_callback(event_fatal_cb cb); + +#define EVENT_DBG_ALL 0xffffffffu +#define EVENT_DBG_NONE 0 + +void event_enable_debug_logging(ev_uint32_t which); + +int event_base_set(struct event_base*, struct event*); + +#define EVLOOP_ONCE 0x01 + +#define EVLOOP_NONBLOCK 0x02 + +#define EVLOOP_NO_EXIT_ON_EMPTY 0x04 + +int event_base_loop(struct event_base*, int); + +int event_base_loopexit(struct event_base*, const struct timeval*); + +int event_base_loopbreak(struct event_base*); + +int event_base_loopcontinue(struct event_base*); + +int event_base_got_exit(struct event_base*); + +int event_base_got_break(struct event_base*); + +#define EV_TIMEOUT 0x01 +#define EV_READ 0x02 +#define EV_WRITE 0x04 +#define EV_SIGNAL 0x08 +#define EV_PERSIST 0x10 +#define EV_ET 0x20 +#define EV_FINALIZE 0x40 +#define EV_CLOSED 0x80 + +#define evtimer_assign(ev, b, cb, arg) event_assign((ev), (b), -1, 0, (cb), (arg)) +#define evtimer_new(b, cb, arg) event_new((b), -1, 0, (cb), (arg)) +#define evtimer_add(ev, tv) event_add((ev), (tv)) +#define evtimer_del(ev) event_del(ev) +#define evtimer_pending(ev, tv) event_pending((ev), EV_TIMEOUT, (tv)) +#define evtimer_initialized(ev) event_initialized(ev) + +#define evsignal_add(ev, tv) event_add((ev), (tv)) +#define evsignal_assign(ev, b, x, cb, arg) event_assign((ev), (b), (x), EV_SIGNAL | EV_PERSIST, cb, (arg)) +#define evsignal_new(b, x, cb, arg) event_new((b), (x), EV_SIGNAL | EV_PERSIST, (cb), (arg)) +#define evsignal_del(ev) event_del(ev) +#define evsignal_pending(ev, tv) event_pending((ev), EV_SIGNAL, (tv)) +#define evsignal_initialized(ev) event_initialized(ev) + +typedef void (*event_callback_fn)(evutil_socket_t, short, void*); + +void* event_self_cbarg(void); + +struct event* event_new(struct event_base*, evutil_socket_t, short, event_callback_fn, void*); + +int event_assign(struct event*, struct event_base*, evutil_socket_t, short, event_callback_fn, void*); + +void event_free(struct event*); + +typedef void (*event_finalize_callback_fn)(struct event*, void*); + +int event_finalize(unsigned, struct event*, event_finalize_callback_fn); + +int event_free_finalize(unsigned, struct event*, event_finalize_callback_fn); + +int event_base_once(struct event_base*, evutil_socket_t, short, event_callback_fn, void*, const struct timeval*); + +int event_add(struct event* ev, const struct timeval* timeout); + +int event_remove_timer(struct event* ev); + +int event_del(struct event*); + +int event_del_noblock(struct event* ev); + +int event_del_block(struct event* ev); + +void event_active(struct event* ev, int res, short ncalls); + +int event_pending(const struct event* ev, short events, struct timeval* tv); + +struct event* event_base_get_running_event(struct event_base* base); + +int event_initialized(const struct event* ev); + +#define event_get_signal(ev) ((int)event_get_fd(ev)) + +evutil_socket_t event_get_fd(const struct event* ev); + +struct event_base* event_get_base(const struct event* ev); + +short event_get_events(const struct event* ev); + +event_callback_fn event_get_callback(const struct event* ev); + +void* event_get_callback_arg(const struct event* ev); + +int event_get_priority(const struct event* ev); + +void event_get_assignment( + const struct event* event, + struct event_base** base_out, + evutil_socket_t* fd_out, + short* events_out, + event_callback_fn* callback_out, + void** arg_out); + +size_t event_get_struct_event_size(void); + +const char* event_get_version(void); + +ev_uint32_t event_get_version_number(void); + +#define LIBEVENT_VERSION EVENT__VERSION +#define LIBEVENT_VERSION_NUMBER EVENT__NUMERIC_VERSION +#define EVENT_MAX_PRIORITIES 256 + +int event_base_priority_init(struct event_base*, int); + +int event_base_get_npriorities(struct event_base* eb); + +int event_priority_set(struct event*, int); + +const struct timeval* event_base_init_common_timeout(struct event_base* base, const struct timeval* duration); + +#if !defined(EVENT__DISABLE_MM_REPLACEMENT) || defined(EVENT_IN_DOXYGEN_) +void event_set_mem_functions(void* (*malloc_fn)(size_t sz), void* (*realloc_fn)(void* ptr, size_t sz), void (*free_fn)(void* ptr)); +#define EVENT_SET_MEM_FUNCTIONS_IMPLEMENTED +#endif + +void event_base_dump_events(struct event_base*, FILE*); +void event_base_active_by_fd(struct event_base* base, evutil_socket_t fd, short events); + +void event_base_active_by_signal(struct event_base* base, int sig); + +typedef int (*event_base_foreach_event_cb)(const struct event_base*, const struct event*, void*); + +int event_base_foreach_event(struct event_base* base, event_base_foreach_event_cb fn, void* arg); + +int event_base_gettimeofday_cached(struct event_base* base, struct timeval* tv); + +int event_base_update_cache_time(struct event_base* base); + +void libevent_global_shutdown(void); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT2_EVENT_H_INCLUDED_ */ diff --git a/asynio/event/evmap-internal.h b/asynio/event/evmap-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..03d2568ac509b04b4958b53543ba101ee8409348 --- /dev/null +++ b/asynio/event/evmap-internal.h @@ -0,0 +1,34 @@ + +#ifndef EVMAP_INTERNAL_H_INCLUDED_ +#define EVMAP_INTERNAL_H_INCLUDED_ + +struct event_base; +struct event; + +void evmap_io_initmap_(struct event_io_map* ctx); +void evmap_signal_initmap_(struct event_signal_map* ctx); + +void evmap_io_clear_(struct event_io_map* ctx); +void evmap_signal_clear_(struct event_signal_map* ctx); + +int evmap_io_add_(struct event_base* base, evutil_socket_t fd, struct event* ev); + +int evmap_io_del_(struct event_base* base, evutil_socket_t fd, struct event* ev); + +void evmap_io_active_(struct event_base* base, evutil_socket_t fd, short events); + +int evmap_signal_add_(struct event_base* base, int signum, struct event* ev); +int evmap_signal_del_(struct event_base* base, int signum, struct event* ev); +void evmap_signal_active_(struct event_base* base, evutil_socket_t signum, int ncalls); + +void* evmap_io_get_fdinfo_(struct event_io_map* ctx, evutil_socket_t fd); + +int evmap_reinit_(struct event_base* base); + +void evmap_delete_all_(struct event_base* base); + +void evmap_check_integrity_(struct event_base* base); + +int evmap_foreach_event_(struct event_base* base, event_base_foreach_event_cb fn, void* arg); + +#endif /* EVMAP_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/evmap.c b/asynio/event/evmap.c new file mode 100644 index 0000000000000000000000000000000000000000..8ed8509f3d92822b9080cebcd2bbe606415cc2eb --- /dev/null +++ b/asynio/event/evmap.c @@ -0,0 +1,969 @@ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef _WIN32 +#include +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#endif +#include +#if !defined(_WIN32) && defined(EVENT__HAVE_SYS_TIME_H) +#include +#endif +#include +#include +#include +#ifndef _WIN32 +#include +#endif +#include +#include +#include +#include + +#include "buffer.h" +#include "bufferevent.h" + +#include "event-internal.h" +#include "evconfig-internal.h" + +/** An entry for an evmap_io list: notes all the events that want to read or + write on a given fd, and the number of each. + */ +struct evmap_io { + struct event_dlist events; + ev_uint16_t nread; + ev_uint16_t nwrite; + ev_uint16_t nclose; +}; + +/* An entry for an evmap_signal list: notes all the events that want to know + when a signal triggers. */ +struct evmap_signal { + struct event_dlist events; +}; + +/* On some platforms, fds start at 0 and increment by 1 as they are + allocated, and old numbers get used. For these platforms, we + implement io maps just like signal maps: as an array of pointers to + struct evmap_io. But on other platforms (windows), sockets are not + 0-indexed, not necessarily consecutive, and not necessarily reused. + There, we use a hashtable to implement evmap_io. +*/ +#ifdef EVMAP_USE_HT +struct event_map_entry { + HT_ENTRY(event_map_entry) map_node; + evutil_socket_t fd; + union { /* This is a union in case we need to make more things that can + be in the hashtable. */ + struct evmap_io evmap_io; + } ent; +}; + +/* Helper used by the event_io_map hashtable code; tries to return a good hash + * of the fd in e->fd. */ +static inline unsigned hashsocket(struct event_map_entry* e) +{ + /* On win32, in practice, the low 2-3 bits of a SOCKET seem not to + * matter. Our hashtable implementation really likes low-order bits, + * though, so let's do the rotate-and-add trick. */ + unsigned h = (unsigned)e->fd; + h += (h >> 2) | (h << 30); + return h; +} + +/* Helper used by the event_io_map hashtable code; returns true iff e1 and e2 + * have the same e->fd. */ +static inline int eqsocket(struct event_map_entry* e1, struct event_map_entry* e2) +{ + return e1->fd == e2->fd; +} + +HT_PROTOTYPE(event_io_map, event_map_entry, map_node, hashsocket, eqsocket) +HT_GENERATE(event_io_map, event_map_entry, map_node, hashsocket, eqsocket, 0.5, mm_malloc, mm_realloc, mm_free) + +#define GET_IO_SLOT(x, map, slot, type) \ + do { \ + struct event_map_entry key_, *ent_; \ + key_.fd = slot; \ + ent_ = HT_FIND(event_io_map, map, &key_); \ + (x) = ent_ ? &ent_->ent.type : NULL; \ + } while (0); + +#define GET_IO_SLOT_AND_CTOR(x, map, slot, type, ctor, fdinfo_len) \ + do { \ + struct event_map_entry key_, *ent_; \ + key_.fd = slot; \ + HT_FIND_OR_INSERT_( \ + event_io_map, map_node, hashsocket, map, event_map_entry, &key_, ptr, { ent_ = *ptr; }, \ + { \ + ent_ = mm_calloc(1, sizeof(struct event_map_entry) + fdinfo_len); \ + if (EVUTIL_UNLIKELY(ent_ == NULL)) \ + return (-1); \ + ent_->fd = slot; \ + (ctor)(&ent_->ent.type); \ + HT_FOI_INSERT_(map_node, map, &key_, ent_, ptr) \ + }); \ + (x) = &ent_->ent.type; \ + } while (0) + +void evmap_io_initmap_(struct event_io_map* ctx) +{ + HT_INIT(event_io_map, ctx); +} + +void evmap_io_clear_(struct event_io_map* ctx) +{ + struct event_map_entry **ent, **next, *this; + for (ent = HT_START(event_io_map, ctx); ent; ent = next) { + this = *ent; + next = HT_NEXT_RMV(event_io_map, ctx, ent); + mm_free(this); + } + HT_CLEAR(event_io_map, ctx); /* remove all storage held by the ctx. */ +} +#endif + +/* Set the variable 'x' to the field in event_map 'map' with fields of type + 'struct type *' corresponding to the fd or signal 'slot'. Set 'x' to NULL + if there are no entries for 'slot'. Does no bounds-checking. */ +#define GET_SIGNAL_SLOT(x, map, slot, type) (x) = (struct type*)((map)->entries[slot]) +/* As GET_SLOT, but construct the entry for 'slot' if it is not present, + by allocating enough memory for a 'struct type', and initializing the new + value by calling the function 'ctor' on it. Makes the function + return -1 on allocation failure. + */ +#define GET_SIGNAL_SLOT_AND_CTOR(x, map, slot, type, ctor, fdinfo_len) \ + do { \ + if ((map)->entries[slot] == NULL) { \ + (map)->entries[slot] = mm_calloc(1, sizeof(struct type) + fdinfo_len); \ + if (EVUTIL_UNLIKELY((map)->entries[slot] == NULL)) \ + return (-1); \ + (ctor)((struct type*)(map)->entries[slot]); \ + } \ + (x) = (struct type*)((map)->entries[slot]); \ + } while (0) + +/* If we aren't using hashtables, then define the IO_SLOT macros and functions + as thin aliases over the SIGNAL_SLOT versions. */ +#ifndef EVMAP_USE_HT +#define GET_IO_SLOT(x, map, slot, type) GET_SIGNAL_SLOT(x, map, slot, type) +#define GET_IO_SLOT_AND_CTOR(x, map, slot, type, ctor, fdinfo_len) GET_SIGNAL_SLOT_AND_CTOR(x, map, slot, type, ctor, fdinfo_len) +#define FDINFO_OFFSET sizeof(struct evmap_io) +void evmap_io_initmap_(struct event_io_map* ctx) +{ + evmap_signal_initmap_(ctx); +} +void evmap_io_clear_(struct event_io_map* ctx) +{ + evmap_signal_clear_(ctx); +} +#endif + +/** Expand 'map' with new entries of width 'msize' until it is big enough + to store a value in 'slot'. + */ +static int evmap_make_space(struct event_signal_map* map, int slot, int msize) +{ + if (map->nentries <= slot) { + int nentries = map->nentries ? map->nentries : 32; + void** tmp; + + while (nentries <= slot) + nentries <<= 1; + + tmp = (void**)mm_realloc(map->entries, nentries * msize); + if (tmp == NULL) + return (-1); + + memset(&tmp[map->nentries], 0, (nentries - map->nentries) * msize); + + map->nentries = nentries; + map->entries = tmp; + } + + return (0); +} + +void evmap_signal_initmap_(struct event_signal_map* ctx) +{ + ctx->nentries = 0; + ctx->entries = NULL; +} + +void evmap_signal_clear_(struct event_signal_map* ctx) +{ + if (ctx->entries != NULL) { + int i; + for (i = 0; i < ctx->nentries; ++i) { + if (ctx->entries[i] != NULL) + mm_free(ctx->entries[i]); + } + mm_free(ctx->entries); + ctx->entries = NULL; + } + ctx->nentries = 0; +} + +/* code specific to file descriptors */ + +/** Constructor for struct evmap_io */ +static void evmap_io_init(struct evmap_io* entry) +{ + LIST_INIT(&entry->events); + entry->nread = 0; + entry->nwrite = 0; + entry->nclose = 0; +} + +/* return -1 on error, 0 on success if nothing changed in the event backend, + * and 1 on success if something did. */ +int evmap_io_add_(struct event_base* base, evutil_socket_t fd, struct event* ev) +{ + const struct eventop* evsel = base->evsel; + struct event_io_map* io = &base->io; + struct evmap_io* ctx = NULL; + int nread, nwrite, nclose, retval = 0; + short res = 0, old = 0; + struct event* old_ev; + + EVUTIL_ASSERT(fd == ev->ev_fd); + + if (fd < 0) + return 0; + +#ifndef EVMAP_USE_HT + if (fd >= io->nentries) { + if (evmap_make_space(io, fd, sizeof(struct evmap_io*)) == -1) + return (-1); + } +#endif + GET_IO_SLOT_AND_CTOR(ctx, io, fd, evmap_io, evmap_io_init, evsel->fdinfo_len); + + nread = ctx->nread; + nwrite = ctx->nwrite; + nclose = ctx->nclose; + + if (nread) + old |= EV_READ; + if (nwrite) + old |= EV_WRITE; + if (nclose) + old |= EV_CLOSED; + + if (ev->ev_events & EV_READ) { + if (++nread == 1) + res |= EV_READ; + } + if (ev->ev_events & EV_WRITE) { + if (++nwrite == 1) + res |= EV_WRITE; + } + if (ev->ev_events & EV_CLOSED) { + if (++nclose == 1) + res |= EV_CLOSED; + } + if (EVUTIL_UNLIKELY(nread > 0xffff || nwrite > 0xffff || nclose > 0xffff)) { + event_warnx("Too many events reading or writing on fd %d", (int)fd); + return -1; + } + if (EVENT_DEBUG_MODE_IS_ON() && (old_ev = LIST_FIRST(&ctx->events)) && (old_ev->ev_events & EV_ET) != (ev->ev_events & EV_ET)) { + event_warnx( + "Tried to mix edge-triggered and non-edge-triggered" + " events on fd %d", + (int)fd); + return -1; + } + + if (res) { + void* extra = ((char*)ctx) + sizeof(struct evmap_io); + /* XXX(niels): we cannot mix edge-triggered and + * level-triggered, we should probably assert on + * this. */ + if (evsel->add(base, ev->ev_fd, old, (ev->ev_events & EV_ET) | res, extra) == -1) + return (-1); + retval = 1; + } + + ctx->nread = (ev_uint16_t)nread; + ctx->nwrite = (ev_uint16_t)nwrite; + ctx->nclose = (ev_uint16_t)nclose; + LIST_INSERT_HEAD(&ctx->events, ev, ev_io_next); + + return (retval); +} + +/* return -1 on error, 0 on success if nothing changed in the event backend, + * and 1 on success if something did. */ +int evmap_io_del_(struct event_base* base, evutil_socket_t fd, struct event* ev) +{ + const struct eventop* evsel = base->evsel; + struct event_io_map* io = &base->io; + struct evmap_io* ctx; + int nread, nwrite, nclose, retval = 0; + short res = 0, old = 0; + + if (fd < 0) + return 0; + + EVUTIL_ASSERT(fd == ev->ev_fd); + +#ifndef EVMAP_USE_HT + if (fd >= io->nentries) + return (-1); +#endif + + GET_IO_SLOT(ctx, io, fd, evmap_io); + + nread = ctx->nread; + nwrite = ctx->nwrite; + nclose = ctx->nclose; + + if (nread) + old |= EV_READ; + if (nwrite) + old |= EV_WRITE; + if (nclose) + old |= EV_CLOSED; + + if (ev->ev_events & EV_READ) { + if (--nread == 0) + res |= EV_READ; + EVUTIL_ASSERT(nread >= 0); + } + if (ev->ev_events & EV_WRITE) { + if (--nwrite == 0) + res |= EV_WRITE; + EVUTIL_ASSERT(nwrite >= 0); + } + if (ev->ev_events & EV_CLOSED) { + if (--nclose == 0) + res |= EV_CLOSED; + EVUTIL_ASSERT(nclose >= 0); + } + + if (res) { + void* extra = ((char*)ctx) + sizeof(struct evmap_io); + if (evsel->del(base, ev->ev_fd, old, res, extra) == -1) { + retval = -1; + } else { + retval = 1; + } + } + + ctx->nread = nread; + ctx->nwrite = nwrite; + ctx->nclose = nclose; + LIST_REMOVE(ev, ev_io_next); + + return (retval); +} + +void evmap_io_active_(struct event_base* base, evutil_socket_t fd, short events) +{ + struct event_io_map* io = &base->io; + struct evmap_io* ctx; + struct event* ev; + +#ifndef EVMAP_USE_HT + if (fd < 0 || fd >= io->nentries) + return; +#endif + GET_IO_SLOT(ctx, io, fd, evmap_io); + + if (NULL == ctx) + return; + LIST_FOREACH(ev, &ctx->events, ev_io_next) + { + if (ev->ev_events & events) + event_active_nolock_(ev, ev->ev_events & events, 1); + } +} + +/* code specific to signals */ + +static void evmap_signal_init(struct evmap_signal* entry) +{ + LIST_INIT(&entry->events); +} + +int evmap_signal_add_(struct event_base* base, int sig, struct event* ev) +{ + const struct eventop* evsel = base->evsigsel; + struct event_signal_map* map = &base->sigmap; + struct evmap_signal* ctx = NULL; + + if (sig >= map->nentries) { + if (evmap_make_space(map, sig, sizeof(struct evmap_signal*)) == -1) + return (-1); + } + GET_SIGNAL_SLOT_AND_CTOR(ctx, map, sig, evmap_signal, evmap_signal_init, base->evsigsel->fdinfo_len); + + if (LIST_EMPTY(&ctx->events)) { + if (evsel->add(base, ev->ev_fd, 0, EV_SIGNAL, NULL) == -1) + return (-1); + } + + LIST_INSERT_HEAD(&ctx->events, ev, ev_signal_next); + + return (1); +} + +int evmap_signal_del_(struct event_base* base, int sig, struct event* ev) +{ + const struct eventop* evsel = base->evsigsel; + struct event_signal_map* map = &base->sigmap; + struct evmap_signal* ctx; + + if (sig >= map->nentries) + return (-1); + + GET_SIGNAL_SLOT(ctx, map, sig, evmap_signal); + + LIST_REMOVE(ev, ev_signal_next); + + if (LIST_FIRST(&ctx->events) == NULL) { + if (evsel->del(base, ev->ev_fd, 0, EV_SIGNAL, NULL) == -1) + return (-1); + } + + return (1); +} + +void evmap_signal_active_(struct event_base* base, evutil_socket_t sig, int ncalls) +{ + struct event_signal_map* map = &base->sigmap; + struct evmap_signal* ctx; + struct event* ev; + + if (sig < 0 || sig >= map->nentries) + return; + GET_SIGNAL_SLOT(ctx, map, sig, evmap_signal); + + if (!ctx) + return; + LIST_FOREACH(ev, &ctx->events, ev_signal_next) + event_active_nolock_(ev, EV_SIGNAL, ncalls); +} + +void* evmap_io_get_fdinfo_(struct event_io_map* map, evutil_socket_t fd) +{ + struct evmap_io* ctx; + GET_IO_SLOT(ctx, map, fd, evmap_io); + if (ctx) + return ((char*)ctx) + sizeof(struct evmap_io); + else + return NULL; +} + +/* Callback type for evmap_io_foreach_fd */ +typedef int (*evmap_io_foreach_fd_cb)(struct event_base*, evutil_socket_t, struct evmap_io*, void*); + +/* Multipurpose helper function: Iterate over every file descriptor event_base + * for which we could have EV_READ or EV_WRITE events. For each such fd, call + * fn(base, signum, evmap_io, arg), where fn is the user-provided + * function, base is the event_base, signum is the signal number, evmap_io + * is an evmap_io structure containing a list of events pending on the + * file descriptor, and arg is the user-supplied argument. + * + * If fn returns 0, continue on to the next signal. Otherwise, return the same + * value that fn returned. + * + * Note that there is no guarantee that the file descriptors will be processed + * in any particular order. + */ +static int evmap_io_foreach_fd(struct event_base* base, evmap_io_foreach_fd_cb fn, void* arg) +{ + evutil_socket_t fd; + struct event_io_map* iomap = &base->io; + int r = 0; +#ifdef EVMAP_USE_HT + struct event_map_entry** mapent; + HT_FOREACH(mapent, event_io_map, iomap) + { + struct evmap_io* ctx = &(*mapent)->ent.evmap_io; + fd = (*mapent)->fd; +#else + for (fd = 0; fd < iomap->nentries; ++fd) { + struct evmap_io* ctx = iomap->entries[fd]; + if (!ctx) + continue; +#endif + if ((r = fn(base, fd, ctx, arg))) + break; + } + return r; +} + +/* Callback type for evmap_signal_foreach_signal */ +typedef int (*evmap_signal_foreach_signal_cb)(struct event_base*, int, struct evmap_signal*, void*); + +/* Multipurpose helper function: Iterate over every signal number in the + * event_base for which we could have signal events. For each such signal, + * call fn(base, signum, evmap_signal, arg), where fn is the user-provided + * function, base is the event_base, signum is the signal number, evmap_signal + * is an evmap_signal structure containing a list of events pending on the + * signal, and arg is the user-supplied argument. + * + * If fn returns 0, continue on to the next signal. Otherwise, return the same + * value that fn returned. + */ +static int evmap_signal_foreach_signal(struct event_base* base, evmap_signal_foreach_signal_cb fn, void* arg) +{ + struct event_signal_map* sigmap = &base->sigmap; + int r = 0; + int signum; + + for (signum = 0; signum < sigmap->nentries; ++signum) { + struct evmap_signal* ctx = sigmap->entries[signum]; + if (!ctx) + continue; + if ((r = fn(base, signum, ctx, arg))) + break; + } + return r; +} + +/* Helper for evmap_reinit_: tell the backend to add every fd for which we have + * pending events, with the appropriate combination of EV_READ, EV_WRITE, and + * EV_ET. */ +static int evmap_io_reinit_iter_fn(struct event_base* base, evutil_socket_t fd, struct evmap_io* ctx, void* arg) +{ + const struct eventop* evsel = base->evsel; + void* extra; + int* result = arg; + short events = 0; + struct event* ev; + EVUTIL_ASSERT(ctx); + + extra = ((char*)ctx) + sizeof(struct evmap_io); + if (ctx->nread) + events |= EV_READ; + if (ctx->nwrite) + events |= EV_WRITE; + if (ctx->nclose) + events |= EV_CLOSED; + if (evsel->fdinfo_len) + memset(extra, 0, evsel->fdinfo_len); + if (events && (ev = LIST_FIRST(&ctx->events)) && (ev->ev_events & EV_ET)) + events |= EV_ET; + if (evsel->add(base, fd, 0, events, extra) == -1) + *result = -1; + + return 0; +} + +/* Helper for evmap_reinit_: tell the backend to add every signal for which we + * have pending events. */ +static int evmap_signal_reinit_iter_fn(struct event_base* base, int signum, struct evmap_signal* ctx, void* arg) +{ + const struct eventop* evsel = base->evsigsel; + int* result = arg; + + if (!LIST_EMPTY(&ctx->events)) { + if (evsel->add(base, signum, 0, EV_SIGNAL, NULL) == -1) + *result = -1; + } + return 0; +} + +int evmap_reinit_(struct event_base* base) +{ + int result = 0; + + evmap_io_foreach_fd(base, evmap_io_reinit_iter_fn, &result); + if (result < 0) + return -1; + evmap_signal_foreach_signal(base, evmap_signal_reinit_iter_fn, &result); + if (result < 0) + return -1; + return 0; +} + +/* Helper for evmap_delete_all_: delete every event in an event_dlist. */ +static int delete_all_in_dlist(struct event_dlist* dlist) +{ + struct event* ev; + while ((ev = LIST_FIRST(dlist))) + event_del(ev); + return 0; +} + +/* Helper for evmap_delete_all_: delete every event pending on an fd. */ +static int evmap_io_delete_all_iter_fn(struct event_base* base, evutil_socket_t fd, struct evmap_io* io_info, void* arg) +{ + return delete_all_in_dlist(&io_info->events); +} + +/* Helper for evmap_delete_all_: delete every event pending on a signal. */ +static int evmap_signal_delete_all_iter_fn(struct event_base* base, int signum, struct evmap_signal* sig_info, void* arg) +{ + return delete_all_in_dlist(&sig_info->events); +} + +void evmap_delete_all_(struct event_base* base) +{ + evmap_signal_foreach_signal(base, evmap_signal_delete_all_iter_fn, NULL); + evmap_io_foreach_fd(base, evmap_io_delete_all_iter_fn, NULL); +} + +/** Per-fd structure for use with changelists. It keeps track, for each fd or + * signal using the changelist, of where its entry in the changelist is. + */ +struct event_changelist_fdinfo { + int idxplus1; /* this is the index +1, so that memset(0) will make it + * a no-such-element */ +}; + +void event_changelist_init_(struct event_changelist* changelist) +{ + changelist->changes = NULL; + changelist->changes_size = 0; + changelist->n_changes = 0; +} + +/** Helper: return the changelist_fdinfo corresponding to a given change. */ +static inline struct event_changelist_fdinfo* event_change_get_fdinfo(struct event_base* base, const struct event_change* change) +{ + char* ptr; + if (change->read_change & EV_CHANGE_SIGNAL) { + struct evmap_signal* ctx; + GET_SIGNAL_SLOT(ctx, &base->sigmap, change->fd, evmap_signal); + ptr = ((char*)ctx) + sizeof(struct evmap_signal); + } else { + struct evmap_io* ctx; + GET_IO_SLOT(ctx, &base->io, change->fd, evmap_io); + ptr = ((char*)ctx) + sizeof(struct evmap_io); + } + return (void*)ptr; +} + +/** Callback helper for event_changelist_assert_ok */ +static int event_changelist_assert_ok_foreach_iter_fn(struct event_base* base, evutil_socket_t fd, struct evmap_io* io, void* arg) +{ + struct event_changelist* changelist = &base->changelist; + struct event_changelist_fdinfo* f; + f = (void*)(((char*)io) + sizeof(struct evmap_io)); + if (f->idxplus1) { + struct event_change* c = &changelist->changes[f->idxplus1 - 1]; + EVUTIL_ASSERT(c->fd == fd); + } + return 0; +} + +/** Make sure that the changelist is consistent with the evmap structures. */ +static void event_changelist_assert_ok(struct event_base* base) +{ + int i; + struct event_changelist* changelist = &base->changelist; + + EVUTIL_ASSERT(changelist->changes_size >= changelist->n_changes); + for (i = 0; i < changelist->n_changes; ++i) { + struct event_change* c = &changelist->changes[i]; + struct event_changelist_fdinfo* f; + EVUTIL_ASSERT(c->fd >= 0); + f = event_change_get_fdinfo(base, c); + EVUTIL_ASSERT(f); + EVUTIL_ASSERT(f->idxplus1 == i + 1); + } + + evmap_io_foreach_fd(base, event_changelist_assert_ok_foreach_iter_fn, NULL); +} + +#ifdef DEBUG_CHANGELIST +#define event_changelist_check(base) event_changelist_assert_ok((base)) +#else +#define event_changelist_check(base) ((void)0) +#endif + +void event_changelist_remove_all_(struct event_changelist* changelist, struct event_base* base) +{ + int i; + + event_changelist_check(base); + + for (i = 0; i < changelist->n_changes; ++i) { + struct event_change* ch = &changelist->changes[i]; + struct event_changelist_fdinfo* fdinfo = event_change_get_fdinfo(base, ch); + EVUTIL_ASSERT(fdinfo->idxplus1 == i + 1); + fdinfo->idxplus1 = 0; + } + + changelist->n_changes = 0; + + event_changelist_check(base); +} + +void event_changelist_freemem_(struct event_changelist* changelist) +{ + if (changelist->changes) + mm_free(changelist->changes); + event_changelist_init_(changelist); /* zero it all out. */ +} + +/** Increase the size of 'changelist' to hold more changes. */ +static int event_changelist_grow(struct event_changelist* changelist) +{ + int new_size; + struct event_change* new_changes; + if (changelist->changes_size < 64) + new_size = 64; + else + new_size = changelist->changes_size * 2; + + new_changes = mm_realloc(changelist->changes, new_size * sizeof(struct event_change)); + + if (EVUTIL_UNLIKELY(new_changes == NULL)) + return (-1); + + changelist->changes = new_changes; + changelist->changes_size = new_size; + + return (0); +} + +/** Return a pointer to the changelist entry for the file descriptor or signal + * 'fd', whose fdinfo is 'fdinfo'. If none exists, construct it, setting its + * old_events field to old_events. + */ +static struct event_change* event_changelist_get_or_construct( + struct event_changelist* changelist, evutil_socket_t fd, short old_events, struct event_changelist_fdinfo* fdinfo) +{ + struct event_change* change; + + if (fdinfo->idxplus1 == 0) { + int idx; + EVUTIL_ASSERT(changelist->n_changes <= changelist->changes_size); + + if (changelist->n_changes == changelist->changes_size) { + if (event_changelist_grow(changelist) < 0) + return NULL; + } + + idx = changelist->n_changes++; + change = &changelist->changes[idx]; + fdinfo->idxplus1 = idx + 1; + + memset(change, 0, sizeof(struct event_change)); + change->fd = fd; + change->old_events = old_events; + } else { + change = &changelist->changes[fdinfo->idxplus1 - 1]; + EVUTIL_ASSERT(change->fd == fd); + } + return change; +} + +int event_changelist_add_(struct event_base* base, evutil_socket_t fd, short old, short events, void* p) +{ + struct event_changelist* changelist = &base->changelist; + struct event_changelist_fdinfo* fdinfo = p; + struct event_change* change; + + event_changelist_check(base); + + change = event_changelist_get_or_construct(changelist, fd, old, fdinfo); + if (!change) + return -1; + + /* An add replaces any previous delete, but doesn't result in a no-op, + * since the delete might fail (because the fd had been closed since + * the last add, for instance. */ + + if (events & (EV_READ | EV_SIGNAL)) { + change->read_change = EV_CHANGE_ADD | (events & (EV_ET | EV_PERSIST | EV_SIGNAL)); + } + if (events & EV_WRITE) { + change->write_change = EV_CHANGE_ADD | (events & (EV_ET | EV_PERSIST | EV_SIGNAL)); + } + if (events & EV_CLOSED) { + change->close_change = EV_CHANGE_ADD | (events & (EV_ET | EV_PERSIST | EV_SIGNAL)); + } + + event_changelist_check(base); + return (0); +} + +int event_changelist_del_(struct event_base* base, evutil_socket_t fd, short old, short events, void* p) +{ + struct event_changelist* changelist = &base->changelist; + struct event_changelist_fdinfo* fdinfo = p; + struct event_change* change; + + event_changelist_check(base); + change = event_changelist_get_or_construct(changelist, fd, old, fdinfo); + event_changelist_check(base); + if (!change) + return -1; + + /* A delete on an event set that doesn't contain the event to be + deleted produces a no-op. This effectively emoves any previous + uncommitted add, rather than replacing it: on those platforms where + "add, delete, dispatch" is not the same as "no-op, dispatch", we + want the no-op behavior. + + If we have a no-op item, we could remove it it from the list + entirely, but really there's not much point: skipping the no-op + change when we do the dispatch later is far cheaper than rejuggling + the array now. + + As this stands, it also lets through deletions of events that are + not currently set. + */ + + if (events & (EV_READ | EV_SIGNAL)) { + if (!(change->old_events & (EV_READ | EV_SIGNAL))) + change->read_change = 0; + else + change->read_change = EV_CHANGE_DEL; + } + if (events & EV_WRITE) { + if (!(change->old_events & EV_WRITE)) + change->write_change = 0; + else + change->write_change = EV_CHANGE_DEL; + } + if (events & EV_CLOSED) { + if (!(change->old_events & EV_CLOSED)) + change->close_change = 0; + else + change->close_change = EV_CHANGE_DEL; + } + + event_changelist_check(base); + return (0); +} + +/* Helper for evmap_check_integrity_: verify that all of the events pending on + * given fd are set up correctly, and that the nread and nwrite counts on that + * fd are correct. */ +static int evmap_io_check_integrity_fn(struct event_base* base, evutil_socket_t fd, struct evmap_io* io_info, void* arg) +{ + struct event* ev; + int n_read = 0, n_write = 0, n_close = 0; + + /* First, make sure the list itself isn't corrupt. Otherwise, + * running LIST_FOREACH could be an exciting adventure. */ + EVUTIL_ASSERT_LIST_OK(&io_info->events, event, ev_io_next); + + LIST_FOREACH(ev, &io_info->events, ev_io_next) + { + EVUTIL_ASSERT(ev->ev_flags & EVLIST_INSERTED); + EVUTIL_ASSERT(ev->ev_fd == fd); + EVUTIL_ASSERT(!(ev->ev_events & EV_SIGNAL)); + EVUTIL_ASSERT((ev->ev_events & (EV_READ | EV_WRITE | EV_CLOSED))); + if (ev->ev_events & EV_READ) + ++n_read; + if (ev->ev_events & EV_WRITE) + ++n_write; + if (ev->ev_events & EV_CLOSED) + ++n_close; + } + + EVUTIL_ASSERT(n_read == io_info->nread); + EVUTIL_ASSERT(n_write == io_info->nwrite); + EVUTIL_ASSERT(n_close == io_info->nclose); + + return 0; +} + +/* Helper for evmap_check_integrity_: verify that all of the events pending + * on given signal are set up correctly. */ +static int evmap_signal_check_integrity_fn(struct event_base* base, int signum, struct evmap_signal* sig_info, void* arg) +{ + struct event* ev; + /* First, make sure the list itself isn't corrupt. */ + EVUTIL_ASSERT_LIST_OK(&sig_info->events, event, ev_signal_next); + + LIST_FOREACH(ev, &sig_info->events, ev_io_next) + { + EVUTIL_ASSERT(ev->ev_flags & EVLIST_INSERTED); + EVUTIL_ASSERT(ev->ev_fd == signum); + EVUTIL_ASSERT((ev->ev_events & EV_SIGNAL)); + EVUTIL_ASSERT(!(ev->ev_events & (EV_READ | EV_WRITE | EV_CLOSED))); + } + return 0; +} + +void evmap_check_integrity_(struct event_base* base) +{ + evmap_io_foreach_fd(base, evmap_io_check_integrity_fn, NULL); + evmap_signal_foreach_signal(base, evmap_signal_check_integrity_fn, NULL); + + if (base->evsel->add == event_changelist_add_) + event_changelist_assert_ok(base); +} + +/* Helper type for evmap_foreach_event_: Bundles a function to call on every + * event, and the user-provided void* to use as its third argument. */ +struct evmap_foreach_event_helper { + event_base_foreach_event_cb fn; + void* arg; +}; + +/* Helper for evmap_foreach_event_: calls a provided function on every event + * pending on a given fd. */ +static int evmap_io_foreach_event_fn(struct event_base* base, evutil_socket_t fd, struct evmap_io* io_info, void* arg) +{ + struct evmap_foreach_event_helper* h = arg; + struct event* ev; + int r; + LIST_FOREACH(ev, &io_info->events, ev_io_next) + { + if ((r = h->fn(base, ev, h->arg))) + return r; + } + return 0; +} + +/* Helper for evmap_foreach_event_: calls a provided function on every event + * pending on a given signal. */ +static int evmap_signal_foreach_event_fn(struct event_base* base, int signum, struct evmap_signal* sig_info, void* arg) +{ + struct event* ev; + struct evmap_foreach_event_helper* h = arg; + int r; + LIST_FOREACH(ev, &sig_info->events, ev_signal_next) + { + if ((r = h->fn(base, ev, h->arg))) + return r; + } + return 0; +} + +int evmap_foreach_event_(struct event_base* base, event_base_foreach_event_cb fn, void* arg) +{ + struct evmap_foreach_event_helper h; + int r; + h.fn = fn; + h.arg = arg; + if ((r = evmap_io_foreach_fd(base, evmap_io_foreach_event_fn, &h))) + return r; + return evmap_signal_foreach_signal(base, evmap_signal_foreach_event_fn, &h); +} diff --git a/asynio/event/evport.c b/asynio/event/evport.c new file mode 100644 index 0000000000000000000000000000000000000000..461c42d86d359240142e3552f8e5bb4b129bfed2 --- /dev/null +++ b/asynio/event/evport.c @@ -0,0 +1,427 @@ +/* + * Submitted by David Pacheco (dp.spambait@gmail.com) + * + * Copyright 2006-2007 Niels Provos + * Copyright 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY SUN MICROSYSTEMS, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 2007 Sun Microsystems. All rights reserved. + * Use is subject to license terms. + */ + +/* + * evport.c: event backend using Solaris 10 event ports. See port_create(3C). + * This implementation is loosely modeled after the one used for select(2) (in + * select.c). + * + * The outstanding events are tracked in a data structure called evport_data. + * Each entry in the ed_fds array corresponds to a file descriptor, and contains + * pointers to the read and write events that correspond to that fd. (That is, + * when the file is readable, the "read" event should handle it, etc.) + * + * evport_add and evport_del update this data structure. evport_dispatch uses it + * to determine where to callback when an event occurs (which it gets from + * port_getn). + * + * Helper functions are used: grow() grows the file descriptor array as + * necessary when large fd's come in. reassociate() takes care of maintaining + * the proper file-descriptor/event-port associations. + * + * As in the select(2) implementation, signals are handled by evsignal. + */ + +#include "evconfig.h" + +#ifdef EVENT__HAVE_EVENT_PORTS + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "event-internal.h" + +#define INITIAL_EVENTS_PER_GETN 8 +#define MAX_EVENTS_PER_GETN 4096 + +/* + * Per-file-descriptor information about what events we're subscribed to. These + * fields are NULL if no event is subscribed to either of them. + */ + +struct fd_info { + /* combinations of EV_READ and EV_WRITE */ + short fdi_what; + /* Index of this fd within ed_pending, plus 1. Zero if this fd is + * not in ed_pending. (The +1 is a hack so that memset(0) will set + * it to a nil index. */ + int pending_idx_plus_1; +}; + +#define FDI_HAS_READ(fdi) ((fdi)->fdi_what & EV_READ) +#define FDI_HAS_WRITE(fdi) ((fdi)->fdi_what & EV_WRITE) +#define FDI_HAS_EVENTS(fdi) (FDI_HAS_READ(fdi) || FDI_HAS_WRITE(fdi)) +#define FDI_TO_SYSEVENTS(fdi) (FDI_HAS_READ(fdi) ? POLLIN : 0) | (FDI_HAS_WRITE(fdi) ? POLLOUT : 0) + +struct evport_data { + int ed_port; /* event port for system events */ + /* How many elements of ed_pending should we look at? */ + int ed_npending; + /* How many elements are allocated in ed_pending and pevtlist? */ + int ed_maxevents; + /* fdi's that we need to reassoc */ + int* ed_pending; + /* storage space for incoming events. */ + port_event_t* ed_pevtlist; +}; + +static void* evport_init(struct event_base*); +static int evport_add(struct event_base*, int fd, short old, short events, void*); +static int evport_del(struct event_base*, int fd, short old, short events, void*); +static int evport_dispatch(struct event_base*, struct timeval*); +static void evport_dealloc(struct event_base*); +static int grow(struct evport_data*, int min_events); + +const struct eventop evportops = { + "evport", + evport_init, + evport_add, + evport_del, + evport_dispatch, + evport_dealloc, + 1, /* need reinit */ + 0, /* features */ + sizeof(struct fd_info), /* fdinfo length */ +}; + +/* + * Initialize the event port implementation. + */ + +static void* evport_init(struct event_base* base) +{ + struct evport_data* evpd; + + if (!(evpd = mm_calloc(1, sizeof(struct evport_data)))) + return (NULL); + + if ((evpd->ed_port = port_create()) == -1) { + mm_free(evpd); + return (NULL); + } + + if (grow(evpd, INITIAL_EVENTS_PER_GETN) < 0) { + close(evpd->ed_port); + mm_free(evpd); + return NULL; + } + + evpd->ed_npending = 0; + + evsig_init_(base); + + return (evpd); +} + +static int grow(struct evport_data* data, int min_events) +{ + int newsize; + int* new_pending; + port_event_t* new_pevtlist; + if (data->ed_maxevents) { + newsize = data->ed_maxevents; + do { + newsize *= 2; + } while (newsize < min_events); + } else { + newsize = min_events; + } + + new_pending = mm_realloc(data->ed_pending, sizeof(int) * newsize); + if (new_pending == NULL) + return -1; + data->ed_pending = new_pending; + new_pevtlist = mm_realloc(data->ed_pevtlist, sizeof(port_event_t) * newsize); + if (new_pevtlist == NULL) + return -1; + data->ed_pevtlist = new_pevtlist; + + data->ed_maxevents = newsize; + return 0; +} + +#ifdef CHECK_INVARIANTS +/* + * Checks some basic properties about the evport_data structure. Because it + * checks all file descriptors, this function can be expensive when the maximum + * file descriptor ever used is rather large. + */ + +static void check_evportop(struct evport_data* evpd) +{ + EVUTIL_ASSERT(evpd); + EVUTIL_ASSERT(evpd->ed_port > 0); +} + +/* + * Verifies very basic integrity of a given port_event. + */ +static void check_event(port_event_t* pevt) +{ + /* + * We've only registered for PORT_SOURCE_FD events. The only + * other thing we can legitimately receive is PORT_SOURCE_ALERT, + * but since we're not using port_alert either, we can assume + * PORT_SOURCE_FD. + */ + EVUTIL_ASSERT(pevt->portev_source == PORT_SOURCE_FD); +} + +#else +#define check_evportop(epop) +#define check_event(pevt) +#endif /* CHECK_INVARIANTS */ + +/* + * (Re)associates the given file descriptor with the event port. The OS events + * are specified (implicitly) from the fd_info struct. + */ +static int reassociate(struct evport_data* epdp, struct fd_info* fdip, int fd) +{ + int sysevents = FDI_TO_SYSEVENTS(fdip); + + if (sysevents != 0) { + if (port_associate(epdp->ed_port, PORT_SOURCE_FD, fd, sysevents, fdip) == -1) { + event_warn("port_associate"); + return (-1); + } + } + + check_evportop(epdp); + + return (0); +} + +/* + * Main event loop - polls port_getn for some number of events, and processes + * them. + */ + +static int evport_dispatch(struct event_base* base, struct timeval* tv) +{ + int i, res; + struct evport_data* epdp = base->evbase; + port_event_t* pevtlist = epdp->ed_pevtlist; + + /* + * port_getn will block until it has at least nevents events. It will + * also return how many it's given us (which may be more than we asked + * for, as long as it's less than our maximum (ed_maxevents)) in + * nevents. + */ + int nevents = 1; + + /* + * We have to convert a struct timeval to a struct timespec + * (only difference is nanoseconds vs. microseconds). If no time-based + * events are active, we should wait for I/O (and tv == NULL). + */ + struct timespec ts; + struct timespec* ts_p = NULL; + if (tv != NULL) { + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + ts_p = &ts; + } + + /* + * Before doing anything else, we need to reassociate the events we hit + * last time which need reassociation. See comment at the end of the + * loop below. + */ + for (i = 0; i < epdp->ed_npending; ++i) { + struct fd_info* fdi = NULL; + const int fd = epdp->ed_pending[i]; + if (fd != -1) { + /* We might have cleared out this event; we need + * to be sure that it's still set. */ + fdi = evmap_io_get_fdinfo_(&base->io, fd); + } + + if (fdi != NULL && FDI_HAS_EVENTS(fdi)) { + reassociate(epdp, fdi, fd); + /* epdp->ed_pending[i] = -1; */ + fdi->pending_idx_plus_1 = 0; + } + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + res = port_getn(epdp->ed_port, pevtlist, epdp->ed_maxevents, (unsigned int*)&nevents, ts_p); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (res == -1) { + if (errno == EINTR || errno == EAGAIN) { + return (0); + } else if (errno == ETIME) { + if (nevents == 0) + return (0); + } else { + event_warn("port_getn"); + return (-1); + } + } + + event_debug(("%s: port_getn reports %d events", __func__, nevents)); + + for (i = 0; i < nevents; ++i) { + port_event_t* pevt = &pevtlist[i]; + int fd = (int)pevt->portev_object; + struct fd_info* fdi = pevt->portev_user; + /*EVUTIL_ASSERT(evmap_io_get_fdinfo_(&base->io, fd) == fdi);*/ + + check_evportop(epdp); + check_event(pevt); + epdp->ed_pending[i] = fd; + fdi->pending_idx_plus_1 = i + 1; + + /* + * Figure out what kind of event it was + * (because we have to pass this to the callback) + */ + res = 0; + if (pevt->portev_events & (POLLERR | POLLHUP)) { + res = EV_READ | EV_WRITE; + } else { + if (pevt->portev_events & POLLIN) + res |= EV_READ; + if (pevt->portev_events & POLLOUT) + res |= EV_WRITE; + } + + /* + * Check for the error situations or a hangup situation + */ + if (pevt->portev_events & (POLLERR | POLLHUP | POLLNVAL)) + res |= EV_READ | EV_WRITE; + + evmap_io_active_(base, fd, res); + } /* end of all events gotten */ + epdp->ed_npending = nevents; + + if (nevents == epdp->ed_maxevents && epdp->ed_maxevents < MAX_EVENTS_PER_GETN) { + /* we used all the space this time. We should be ready + * for more events next time around. */ + grow(epdp, epdp->ed_maxevents * 2); + } + + check_evportop(epdp); + + return (0); +} + +/* + * Adds the given event (so that you will be notified when it happens via + * the callback function). + */ + +static int evport_add(struct event_base* base, int fd, short old, short events, void* p) +{ + struct evport_data* evpd = base->evbase; + struct fd_info* fdi = p; + + check_evportop(evpd); + + fdi->fdi_what |= events; + + return reassociate(evpd, fdi, fd); +} + +/* + * Removes the given event from the list of events to wait for. + */ + +static int evport_del(struct event_base* base, int fd, short old, short events, void* p) +{ + struct evport_data* evpd = base->evbase; + struct fd_info* fdi = p; + int associated = !fdi->pending_idx_plus_1; + + check_evportop(evpd); + + fdi->fdi_what &= ~(events & (EV_READ | EV_WRITE)); + + if (associated) { + if (!FDI_HAS_EVENTS(fdi) && port_dissociate(evpd->ed_port, PORT_SOURCE_FD, fd) == -1) { + /* + * Ignore EBADFD error the fd could have been closed + * before event_del() was called. + */ + if (errno != EBADFD) { + event_warn("port_dissociate"); + return (-1); + } + } else { + if (FDI_HAS_EVENTS(fdi)) { + return (reassociate(evpd, fdi, fd)); + } + } + } else { + if ((fdi->fdi_what & (EV_READ | EV_WRITE)) == 0) { + const int i = fdi->pending_idx_plus_1 - 1; + EVUTIL_ASSERT(evpd->ed_pending[i] == fd); + evpd->ed_pending[i] = -1; + fdi->pending_idx_plus_1 = 0; + } + } + return 0; +} + +static void evport_dealloc(struct event_base* base) +{ + struct evport_data* evpd = base->evbase; + + evsig_dealloc_(base); + + close(evpd->ed_port); + + if (evpd->ed_pending) + mm_free(evpd->ed_pending); + if (evpd->ed_pevtlist) + mm_free(evpd->ed_pevtlist); + + mm_free(evpd); +} + +#endif /* EVENT__HAVE_EVENT_PORTS */ diff --git a/asynio/event/evsignal-internal.h b/asynio/event/evsignal-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..ec6b6301856123cb6b148e0eb5ce507260ad9212 --- /dev/null +++ b/asynio/event/evsignal-internal.h @@ -0,0 +1,39 @@ +#ifndef EVSIGNAL_INTERNAL_H_INCLUDED_ +#define EVSIGNAL_INTERNAL_H_INCLUDED_ + +#ifndef evutil_socket_t +// #include "event2/util.h" +#endif +#include + +typedef void (*ev_sighandler_t)(int); + +/* Data structure for the default signal-handling implementation in signal.c + */ +struct evsig_info { + /* Event watching ev_signal_pair[1] */ + struct event ev_signal; + /* Socketpair used to send notifications from the signal handler */ + evutil_socket_t ev_signal_pair[2]; + /* True iff we've added the ev_signal event yet. */ + int ev_signal_added; + /* Count of the number of signals we're currently watching. */ + int ev_n_signals_added; + + /* Array of previous signal handler objects before Libevent started + * messing with them. Used to restore old signal handlers. */ +#ifdef EVENT__HAVE_SIGACTION + struct sigaction** sh_old; +#else + ev_sighandler_t** sh_old; +#endif + /* Size of sh_old. */ + int sh_old_max; +}; +int evsig_init_(struct event_base*); +void evsig_dealloc_(struct event_base*); + +void evsig_set_base_(struct event_base* base); +void evsig_free_globals_(void); + +#endif /* EVSIGNAL_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/evthread-internal.h b/asynio/event/evthread-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..780ea438176549552e3b347e31f6b3e62bb888f5 --- /dev/null +++ b/asynio/event/evthread-internal.h @@ -0,0 +1,343 @@ +#ifndef EVTHREAD_INTERNAL_H_INCLUDED_ +#define EVTHREAD_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#include "thread-internal.h" +#include "util-internal.h" + +struct event_base; + +#ifndef _WIN32 +/* On Windows, the way we currently make DLLs, it's not allowed for us to + * have shared global structures. Thus, we only do the direct-call-to-function + * code path if we know that the local shared library system supports it. + */ +#define EVTHREAD_EXPOSE_STRUCTS +#endif + +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) && defined(EVTHREAD_EXPOSE_STRUCTS) +/* Global function pointers to lock-related functions. NULL if locking isn't + enabled. */ +extern struct evthread_lock_callbacks evthread_lock_fns_; +extern struct evthread_condition_callbacks evthread_cond_fns_; +extern unsigned long (*evthread_id_fn_)(void); +extern int evthread_lock_debugging_enabled_; + +/** Return the ID of the current thread, or 1 if threading isn't enabled. */ +#define EVTHREAD_GET_ID() (evthread_id_fn_ ? evthread_id_fn_() : 1) + +/** Return true iff we're in the thread that is currently (or most recently) + * running a given event_base's loop. Requires lock. */ +#define EVBASE_IN_THREAD(base) (evthread_id_fn_ == NULL || (base)->th_owner_id == evthread_id_fn_()) + +/** Return true iff we need to notify the base's main thread about changes to + * its state, because it's currently running the main loop in another + * thread. Requires lock. */ +#define EVBASE_NEED_NOTIFY(base) (evthread_id_fn_ != NULL && (base)->running_loop && (base)->th_owner_id != evthread_id_fn_()) + +/** Allocate a new lock, and store it in lockvar, a void*. Sets lockvar to + NULL if locking is not enabled. */ +#define EVTHREAD_ALLOC_LOCK(lockvar, locktype) ((lockvar) = evthread_lock_fns_.alloc ? evthread_lock_fns_.alloc(locktype) : NULL) + +/** Free a given lock, if it is present and locking is enabled. */ +#define EVTHREAD_FREE_LOCK(lockvar, locktype) \ + do { \ + void* lock_tmp_ = (lockvar); \ + if (lock_tmp_ && evthread_lock_fns_.free) \ + evthread_lock_fns_.free(lock_tmp_, (locktype)); \ + } while (0) + +/** Acquire a lock. */ +#define EVLOCK_LOCK(lockvar, mode) \ + do { \ + if (lockvar) \ + evthread_lock_fns_.lock(mode, lockvar); \ + } while (0) + +/** Release a lock */ +#define EVLOCK_UNLOCK(lockvar, mode) \ + do { \ + if (lockvar) \ + evthread_lock_fns_.unlock(mode, lockvar); \ + } while (0) + +/** Helper: put lockvar1 and lockvar2 into pointerwise ascending order. */ +#define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \ + do { \ + if (lockvar1 && lockvar2 && lockvar1 > lockvar2) { \ + void* tmp = lockvar1; \ + lockvar1 = lockvar2; \ + lockvar2 = tmp; \ + } \ + } while (0) + +/** Lock an event_base, if it is set up for locking. Acquires the lock + in the base structure whose field is named 'lockvar'. */ +#define EVBASE_ACQUIRE_LOCK(base, lockvar) \ + do { \ + EVLOCK_LOCK((base)->lockvar, 0); \ + } while (0) + +/** Unlock an event_base, if it is set up for locking. */ +#define EVBASE_RELEASE_LOCK(base, lockvar) \ + do { \ + EVLOCK_UNLOCK((base)->lockvar, 0); \ + } while (0) + +/** If lock debugging is enabled, and lock is non-null, assert that 'lock' is + * locked and held by us. */ +#define EVLOCK_ASSERT_LOCKED(lock) \ + do { \ + if ((lock) && evthread_lock_debugging_enabled_) { \ + EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \ + } \ + } while (0) + +/** Try to grab the lock for 'lockvar' without blocking, and return 1 if we + * manage to get it. */ +static inline int EVLOCK_TRY_LOCK_(void* lock); +static inline int EVLOCK_TRY_LOCK_(void* lock) +{ + if (lock && evthread_lock_fns_.lock) { + int r = evthread_lock_fns_.lock(EVTHREAD_TRY, lock); + return !r; + } else { + /* Locking is disabled either globally or for this thing; + * of course we count as having the lock. */ + return 1; + } +} + +/** Allocate a new condition variable and store it in the void *, condvar */ +#define EVTHREAD_ALLOC_COND(condvar) \ + do { \ + (condvar) = evthread_cond_fns_.alloc_condition ? evthread_cond_fns_.alloc_condition(0) : NULL; \ + } while (0) +/** Deallocate and free a condition variable in condvar */ +#define EVTHREAD_FREE_COND(cond) \ + do { \ + if (cond) \ + evthread_cond_fns_.free_condition((cond)); \ + } while (0) +/** Signal one thread waiting on cond */ +#define EVTHREAD_COND_SIGNAL(cond) ((cond) ? evthread_cond_fns_.signal_condition((cond), 0) : 0) +/** Signal all threads waiting on cond */ +#define EVTHREAD_COND_BROADCAST(cond) ((cond) ? evthread_cond_fns_.signal_condition((cond), 1) : 0) +/** Wait until the condition 'cond' is signalled. Must be called while + * holding 'lock'. The lock will be released until the condition is + * signalled, at which point it will be acquired again. Returns 0 for + * success, -1 for failure. */ +#define EVTHREAD_COND_WAIT(cond, lock) ((cond) ? evthread_cond_fns_.wait_condition((cond), (lock), NULL) : 0) +/** As EVTHREAD_COND_WAIT, but gives up after 'tv' has elapsed. Returns 1 + * on timeout. */ +#define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) ((cond) ? evthread_cond_fns_.wait_condition((cond), (lock), (tv)) : 0) + +/** True iff locking functions have been configured. */ +#define EVTHREAD_LOCKING_ENABLED() (evthread_lock_fns_.lock != NULL) + +#elif !defined(EVENT__DISABLE_THREAD_SUPPORT) + +unsigned long evthreadimpl_get_id_(void); +int evthreadimpl_is_lock_debugging_enabled_(void); +void* evthreadimpl_lock_alloc_(unsigned locktype); +void evthreadimpl_lock_free_(void* lock, unsigned locktype); +int evthreadimpl_lock_lock_(unsigned mode, void* lock); +int evthreadimpl_lock_unlock_(unsigned mode, void* lock); +void* evthreadimpl_cond_alloc_(unsigned condtype); +void evthreadimpl_cond_free_(void* cond); +int evthreadimpl_cond_signal_(void* cond, int broadcast); +int evthreadimpl_cond_wait_(void* cond, void* lock, const struct timeval* tv); +int evthreadimpl_locking_enabled_(void); + +#define EVTHREAD_GET_ID() evthreadimpl_get_id_() +#define EVBASE_IN_THREAD(base) ((base)->th_owner_id == evthreadimpl_get_id_()) +#define EVBASE_NEED_NOTIFY(base) ((base)->running_loop && ((base)->th_owner_id != evthreadimpl_get_id_())) + +#define EVTHREAD_ALLOC_LOCK(lockvar, locktype) ((lockvar) = evthreadimpl_lock_alloc_(locktype)) + +#define EVTHREAD_FREE_LOCK(lockvar, locktype) \ + do { \ + void* lock_tmp_ = (lockvar); \ + if (lock_tmp_) \ + evthreadimpl_lock_free_(lock_tmp_, (locktype)); \ + } while (0) + +/** Acquire a lock. */ +#define EVLOCK_LOCK(lockvar, mode) \ + do { \ + if (lockvar) \ + evthreadimpl_lock_lock_(mode, lockvar); \ + } while (0) + +/** Release a lock */ +#define EVLOCK_UNLOCK(lockvar, mode) \ + do { \ + if (lockvar) \ + evthreadimpl_lock_unlock_(mode, lockvar); \ + } while (0) + +/** Lock an event_base, if it is set up for locking. Acquires the lock + in the base structure whose field is named 'lockvar'. */ +#define EVBASE_ACQUIRE_LOCK(base, lockvar) \ + do { \ + EVLOCK_LOCK((base)->lockvar, 0); \ + } while (0) + +/** Unlock an event_base, if it is set up for locking. */ +#define EVBASE_RELEASE_LOCK(base, lockvar) \ + do { \ + EVLOCK_UNLOCK((base)->lockvar, 0); \ + } while (0) + +/** If lock debugging is enabled, and lock is non-null, assert that 'lock' is + * locked and held by us. */ +#define EVLOCK_ASSERT_LOCKED(lock) \ + do { \ + if ((lock) && evthreadimpl_is_lock_debugging_enabled_()) { \ + EVUTIL_ASSERT(evthread_is_debug_lock_held_(lock)); \ + } \ + } while (0) + +/** Try to grab the lock for 'lockvar' without blocking, and return 1 if we + * manage to get it. */ +static inline int EVLOCK_TRY_LOCK_(void* lock); +static inline int EVLOCK_TRY_LOCK_(void* lock) +{ + if (lock) { + int r = evthreadimpl_lock_lock_(EVTHREAD_TRY, lock); + return !r; + } else { + /* Locking is disabled either globally or for this thing; + * of course we count as having the lock. */ + return 1; + } +} + +/** Allocate a new condition variable and store it in the void *, condvar */ +#define EVTHREAD_ALLOC_COND(condvar) \ + do { \ + (condvar) = evthreadimpl_cond_alloc_(0); \ + } while (0) +/** Deallocate and free a condition variable in condvar */ +#define EVTHREAD_FREE_COND(cond) \ + do { \ + if (cond) \ + evthreadimpl_cond_free_((cond)); \ + } while (0) +/** Signal one thread waiting on cond */ +#define EVTHREAD_COND_SIGNAL(cond) ((cond) ? evthreadimpl_cond_signal_((cond), 0) : 0) +/** Signal all threads waiting on cond */ +#define EVTHREAD_COND_BROADCAST(cond) ((cond) ? evthreadimpl_cond_signal_((cond), 1) : 0) +/** Wait until the condition 'cond' is signalled. Must be called while + * holding 'lock'. The lock will be released until the condition is + * signalled, at which point it will be acquired again. Returns 0 for + * success, -1 for failure. */ +#define EVTHREAD_COND_WAIT(cond, lock) ((cond) ? evthreadimpl_cond_wait_((cond), (lock), NULL) : 0) +/** As EVTHREAD_COND_WAIT, but gives up after 'tv' has elapsed. Returns 1 + * on timeout. */ +#define EVTHREAD_COND_WAIT_TIMED(cond, lock, tv) ((cond) ? evthreadimpl_cond_wait_((cond), (lock), (tv)) : 0) + +#define EVTHREAD_LOCKING_ENABLED() (evthreadimpl_locking_enabled_()) + +#else /* EVENT__DISABLE_THREAD_SUPPORT */ + +#define EVTHREAD_GET_ID() 1 +#define EVTHREAD_ALLOC_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_ +#define EVTHREAD_FREE_LOCK(lockvar, locktype) EVUTIL_NIL_STMT_ + +#define EVLOCK_LOCK(lockvar, mode) EVUTIL_NIL_STMT_ +#define EVLOCK_UNLOCK(lockvar, mode) EVUTIL_NIL_STMT_ +#define EVLOCK_LOCK2(lock1, lock2, mode1, mode2) EVUTIL_NIL_STMT_ +#define EVLOCK_UNLOCK2(lock1, lock2, mode1, mode2) EVUTIL_NIL_STMT_ + +#define EVBASE_IN_THREAD(base) 1 +#define EVBASE_NEED_NOTIFY(base) 0 +#define EVBASE_ACQUIRE_LOCK(base, lock) EVUTIL_NIL_STMT_ +#define EVBASE_RELEASE_LOCK(base, lock) EVUTIL_NIL_STMT_ +#define EVLOCK_ASSERT_LOCKED(lock) EVUTIL_NIL_STMT_ + +#define EVLOCK_TRY_LOCK_(lock) 1 + +#define EVTHREAD_ALLOC_COND(condvar) EVUTIL_NIL_STMT_ +#define EVTHREAD_FREE_COND(cond) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_SIGNAL(cond) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_BROADCAST(cond) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_WAIT(cond, lock) EVUTIL_NIL_STMT_ +#define EVTHREAD_COND_WAIT_TIMED(cond, lock, howlong) EVUTIL_NIL_STMT_ + +#define EVTHREAD_LOCKING_ENABLED() 0 + +#endif + +/* This code is shared between both lock impls */ +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) +/** Helper: put lockvar1 and lockvar2 into pointerwise ascending order. */ +#define EVLOCK_SORTLOCKS_(lockvar1, lockvar2) \ + do { \ + if (lockvar1 && lockvar2 && lockvar1 > lockvar2) { \ + void* tmp = lockvar1; \ + lockvar1 = lockvar2; \ + lockvar2 = tmp; \ + } \ + } while (0) + +/** Acquire both lock1 and lock2. Always allocates locks in the same order, + * so that two threads locking two locks with LOCK2 will not deadlock. */ +#define EVLOCK_LOCK2(lock1, lock2, mode1, mode2) \ + do { \ + void* lock1_tmplock_ = (lock1); \ + void* lock2_tmplock_ = (lock2); \ + EVLOCK_SORTLOCKS_(lock1_tmplock_, lock2_tmplock_); \ + EVLOCK_LOCK(lock1_tmplock_, mode1); \ + if (lock2_tmplock_ != lock1_tmplock_) \ + EVLOCK_LOCK(lock2_tmplock_, mode2); \ + } while (0) +/** Release both lock1 and lock2. */ +#define EVLOCK_UNLOCK2(lock1, lock2, mode1, mode2) \ + do { \ + void* lock1_tmplock_ = (lock1); \ + void* lock2_tmplock_ = (lock2); \ + EVLOCK_SORTLOCKS_(lock1_tmplock_, lock2_tmplock_); \ + if (lock2_tmplock_ != lock1_tmplock_) \ + EVLOCK_UNLOCK(lock2_tmplock_, mode2); \ + EVLOCK_UNLOCK(lock1_tmplock_, mode1); \ + } while (0) + +int evthread_is_debug_lock_held_(void* lock); +void* evthread_debug_get_real_lock_(void* lock); + +void* evthread_setup_global_lock_(void* lock_, unsigned locktype, int enable_locks); + +#define EVTHREAD_SETUP_GLOBAL_LOCK(lockvar, locktype) \ + do { \ + lockvar = evthread_setup_global_lock_(lockvar, (locktype), enable_locks); \ + if (!lockvar) { \ + event_warn("Couldn't allocate %s", #lockvar); \ + return -1; \ + } \ + } while (0); + +int event_global_setup_locks_(const int enable_locks); +int evsig_global_setup_locks_(const int enable_locks); +int evutil_global_setup_locks_(const int enable_locks); +int evutil_secure_rng_global_setup_locks_(const int enable_locks); + +/** Return current evthread_lock_callbacks */ +struct evthread_lock_callbacks* evthread_get_lock_callbacks(void); +/** Return current evthread_condition_callbacks */ +struct evthread_condition_callbacks* evthread_get_condition_callbacks(void); +/** Disable locking for internal usage (like global shutdown) */ +void evthreadimpl_disable_lock_debugging_(void); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* EVTHREAD_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/evthread.c b/asynio/event/evthread.c new file mode 100644 index 0000000000000000000000000000000000000000..20fea68f33d7233325f2ea07eeda769ec02acaf4 --- /dev/null +++ b/asynio/event/evthread.c @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2008-2012 Niels Provos, Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + +#include +#include + +#include "evbuffer-internal.h" +#include "evconfig-internal.h" + +#ifdef EVTHREAD_EXPOSE_STRUCTS +#define GLOBAL +#else +#define GLOBAL static +#endif + +#ifndef EVENT__DISABLE_DEBUG_MODE +extern int event_debug_created_threadable_ctx_; +extern int event_debug_mode_on_; +#endif + +/* globals */ +GLOBAL int evthread_lock_debugging_enabled_ = 0; +GLOBAL struct evthread_lock_callbacks evthread_lock_fns_ = {0, 0, NULL, NULL, NULL, NULL}; +GLOBAL unsigned long (*evthread_id_fn_)(void) = NULL; +GLOBAL struct evthread_condition_callbacks evthread_cond_fns_ = {0, NULL, NULL, NULL, NULL}; + +/* Used for debugging */ +static struct evthread_lock_callbacks original_lock_fns_ = {0, 0, NULL, NULL, NULL, NULL}; +static struct evthread_condition_callbacks original_cond_fns_ = {0, NULL, NULL, NULL, NULL}; + +void evthread_set_id_callback(unsigned long (*id_fn)(void)) +{ + evthread_id_fn_ = id_fn; +} + +struct evthread_lock_callbacks* evthread_get_lock_callbacks() +{ + return evthread_lock_debugging_enabled_ ? &original_lock_fns_ : &evthread_lock_fns_; +} +struct evthread_condition_callbacks* evthread_get_condition_callbacks() +{ + return evthread_lock_debugging_enabled_ ? &original_cond_fns_ : &evthread_cond_fns_; +} +void evthreadimpl_disable_lock_debugging_(void) +{ + evthread_lock_debugging_enabled_ = 0; +} + +int evthread_set_lock_callbacks(const struct evthread_lock_callbacks* cbs) +{ + struct evthread_lock_callbacks* target = evthread_get_lock_callbacks(); + +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + if (event_debug_created_threadable_ctx_) { + event_errx(1, "evthread initialization must be called BEFORE anything else!"); + } + } +#endif + + if (!cbs) { + if (target->alloc) + event_warnx("Trying to disable lock functions after " + "they have been set up will probaby not work."); + memset(target, 0, sizeof(evthread_lock_fns_)); + return 0; + } + if (target->alloc) { + /* Uh oh; we already had locking callbacks set up.*/ + if (target->lock_api_version == cbs->lock_api_version && target->supported_locktypes == cbs->supported_locktypes + && target->alloc == cbs->alloc && target->free == cbs->free && target->lock == cbs->lock && target->unlock == cbs->unlock) { + /* no change -- allow this. */ + return 0; + } + event_warnx("Can't change lock callbacks once they have been " + "initialized."); + return -1; + } + if (cbs->alloc && cbs->free && cbs->lock && cbs->unlock) { + memcpy(target, cbs, sizeof(evthread_lock_fns_)); + return event_global_setup_locks_(1); + } else { + return -1; + } +} + +int evthread_set_condition_callbacks(const struct evthread_condition_callbacks* cbs) +{ + struct evthread_condition_callbacks* target = evthread_get_condition_callbacks(); + +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + if (event_debug_created_threadable_ctx_) { + event_errx(1, "evthread initialization must be called BEFORE anything else!"); + } + } +#endif + + if (!cbs) { + if (target->alloc_condition) + event_warnx("Trying to disable condition functions " + "after they have been set up will probaby not " + "work."); + memset(target, 0, sizeof(evthread_cond_fns_)); + return 0; + } + if (target->alloc_condition) { + /* Uh oh; we already had condition callbacks set up.*/ + if (target->condition_api_version == cbs->condition_api_version && target->alloc_condition == cbs->alloc_condition + && target->free_condition == cbs->free_condition && target->signal_condition == cbs->signal_condition + && target->wait_condition == cbs->wait_condition) { + /* no change -- allow this. */ + return 0; + } + event_warnx("Can't change condition callbacks once they " + "have been initialized."); + return -1; + } + if (cbs->alloc_condition && cbs->free_condition && cbs->signal_condition && cbs->wait_condition) { + memcpy(target, cbs, sizeof(evthread_cond_fns_)); + } + if (evthread_lock_debugging_enabled_) { + evthread_cond_fns_.alloc_condition = cbs->alloc_condition; + evthread_cond_fns_.free_condition = cbs->free_condition; + evthread_cond_fns_.signal_condition = cbs->signal_condition; + } + return 0; +} + +#define DEBUG_LOCK_SIG 0xdeb0b10c + +struct debug_lock { + unsigned signature; + unsigned locktype; + unsigned long held_by; + /* XXXX if we ever use read-write locks, we will need a separate + * lock to protect count. */ + int count; + void* lock; +}; + +static void* debug_lock_alloc(unsigned locktype) +{ + struct debug_lock* result = mm_malloc(sizeof(struct debug_lock)); + if (!result) + return NULL; + if (original_lock_fns_.alloc) { + if (!(result->lock = original_lock_fns_.alloc(locktype | EVTHREAD_LOCKTYPE_RECURSIVE))) { + mm_free(result); + return NULL; + } + } else { + result->lock = NULL; + } + result->signature = DEBUG_LOCK_SIG; + result->locktype = locktype; + result->count = 0; + result->held_by = 0; + return result; +} + +static void debug_lock_free(void* lock_, unsigned locktype) +{ + struct debug_lock* lock = lock_; + EVUTIL_ASSERT(lock->count == 0); + EVUTIL_ASSERT(locktype == lock->locktype); + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + if (original_lock_fns_.free) { + original_lock_fns_.free(lock->lock, lock->locktype | EVTHREAD_LOCKTYPE_RECURSIVE); + } + lock->lock = NULL; + lock->count = -100; + lock->signature = 0x12300fda; + mm_free(lock); +} + +static void evthread_debug_lock_mark_locked(unsigned mode, struct debug_lock* lock) +{ + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + ++lock->count; + if (!(lock->locktype & EVTHREAD_LOCKTYPE_RECURSIVE)) + EVUTIL_ASSERT(lock->count == 1); + if (evthread_id_fn_) { + unsigned long me; + me = evthread_id_fn_(); + if (lock->count > 1) + EVUTIL_ASSERT(lock->held_by == me); + lock->held_by = me; + } +} + +static int debug_lock_lock(unsigned mode, void* lock_) +{ + struct debug_lock* lock = lock_; + int res = 0; + if (lock->locktype & EVTHREAD_LOCKTYPE_READWRITE) + EVUTIL_ASSERT(mode & (EVTHREAD_READ | EVTHREAD_WRITE)); + else + EVUTIL_ASSERT((mode & (EVTHREAD_READ | EVTHREAD_WRITE)) == 0); + if (original_lock_fns_.lock) + res = original_lock_fns_.lock(mode, lock->lock); + if (!res) { + evthread_debug_lock_mark_locked(mode, lock); + } + return res; +} + +static void evthread_debug_lock_mark_unlocked(unsigned mode, struct debug_lock* lock) +{ + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + if (lock->locktype & EVTHREAD_LOCKTYPE_READWRITE) + EVUTIL_ASSERT(mode & (EVTHREAD_READ | EVTHREAD_WRITE)); + else + EVUTIL_ASSERT((mode & (EVTHREAD_READ | EVTHREAD_WRITE)) == 0); + if (evthread_id_fn_) { + unsigned long me; + me = evthread_id_fn_(); + EVUTIL_ASSERT(lock->held_by == me); + if (lock->count == 1) + lock->held_by = 0; + } + --lock->count; + EVUTIL_ASSERT(lock->count >= 0); +} + +static int debug_lock_unlock(unsigned mode, void* lock_) +{ + struct debug_lock* lock = lock_; + int res = 0; + evthread_debug_lock_mark_unlocked(mode, lock); + if (original_lock_fns_.unlock) + res = original_lock_fns_.unlock(mode, lock->lock); + return res; +} + +static int debug_cond_wait(void* cond_, void* lock_, const struct timeval* tv) +{ + int r; + struct debug_lock* lock = lock_; + EVUTIL_ASSERT(lock); + EVUTIL_ASSERT(DEBUG_LOCK_SIG == lock->signature); + EVLOCK_ASSERT_LOCKED(lock_); + evthread_debug_lock_mark_unlocked(0, lock); + r = original_cond_fns_.wait_condition(cond_, lock->lock, tv); + evthread_debug_lock_mark_locked(0, lock); + return r; +} + +/* misspelled version for backward compatibility */ +void evthread_enable_lock_debuging(void) +{ + evthread_enable_lock_debugging(); +} + +void evthread_enable_lock_debugging(void) +{ + struct evthread_lock_callbacks cbs = {EVTHREAD_LOCK_API_VERSION, EVTHREAD_LOCKTYPE_RECURSIVE, debug_lock_alloc, debug_lock_free, debug_lock_lock, + debug_lock_unlock}; + if (evthread_lock_debugging_enabled_) + return; + memcpy(&original_lock_fns_, &evthread_lock_fns_, sizeof(struct evthread_lock_callbacks)); + memcpy(&evthread_lock_fns_, &cbs, sizeof(struct evthread_lock_callbacks)); + + memcpy(&original_cond_fns_, &evthread_cond_fns_, sizeof(struct evthread_condition_callbacks)); + evthread_cond_fns_.wait_condition = debug_cond_wait; + evthread_lock_debugging_enabled_ = 1; + + /* XXX return value should get checked. */ + event_global_setup_locks_(0); +} + +int evthread_is_debug_lock_held_(void* lock_) +{ + struct debug_lock* lock = lock_; + if (!lock->count) + return 0; + if (evthread_id_fn_) { + unsigned long me = evthread_id_fn_(); + if (lock->held_by != me) + return 0; + } + return 1; +} + +void* evthread_debug_get_real_lock_(void* lock_) +{ + struct debug_lock* lock = lock_; + return lock->lock; +} + +void* evthread_setup_global_lock_(void* lock_, unsigned locktype, int enable_locks) +{ + /* there are four cases here: + 1) we're turning on debugging; locking is not on. + 2) we're turning on debugging; locking is on. + 3) we're turning on locking; debugging is not on. + 4) we're turning on locking; debugging is on. */ + + if (!enable_locks && original_lock_fns_.alloc == NULL) { + /* Case 1: allocate a debug lock. */ + EVUTIL_ASSERT(lock_ == NULL); + return debug_lock_alloc(locktype); + } else if (!enable_locks && original_lock_fns_.alloc != NULL) { + /* Case 2: wrap the lock in a debug lock. */ + struct debug_lock* lock; + EVUTIL_ASSERT(lock_ != NULL); + + if (!(locktype & EVTHREAD_LOCKTYPE_RECURSIVE)) { + /* We can't wrap it: We need a recursive lock */ + original_lock_fns_.free(lock_, locktype); + return debug_lock_alloc(locktype); + } + lock = mm_malloc(sizeof(struct debug_lock)); + if (!lock) { + original_lock_fns_.free(lock_, locktype); + return NULL; + } + lock->lock = lock_; + lock->locktype = locktype; + lock->count = 0; + lock->held_by = 0; + return lock; + } else if (enable_locks && !evthread_lock_debugging_enabled_) { + /* Case 3: allocate a regular lock */ + EVUTIL_ASSERT(lock_ == NULL); + return evthread_lock_fns_.alloc(locktype); + } else { + /* Case 4: Fill in a debug lock with a real lock */ + struct debug_lock* lock = lock_ ? lock_ : debug_lock_alloc(locktype); + EVUTIL_ASSERT(enable_locks && evthread_lock_debugging_enabled_); + EVUTIL_ASSERT(lock->locktype == locktype); + if (!lock->lock) { + lock->lock = original_lock_fns_.alloc(locktype | EVTHREAD_LOCKTYPE_RECURSIVE); + if (!lock->lock) { + lock->count = -200; + mm_free(lock); + return NULL; + } + } + return lock; + } +} + +#ifndef EVTHREAD_EXPOSE_STRUCTS +unsigned long evthreadimpl_get_id_() +{ + return evthread_id_fn_ ? evthread_id_fn_() : 1; +} +void* evthreadimpl_lock_alloc_(unsigned locktype) +{ +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + event_debug_created_threadable_ctx_ = 1; + } +#endif + + return evthread_lock_fns_.alloc ? evthread_lock_fns_.alloc(locktype) : NULL; +} +void evthreadimpl_lock_free_(void* lock, unsigned locktype) +{ + if (evthread_lock_fns_.free) + evthread_lock_fns_.free(lock, locktype); +} +int evthreadimpl_lock_lock_(unsigned mode, void* lock) +{ + if (evthread_lock_fns_.lock) + return evthread_lock_fns_.lock(mode, lock); + else + return 0; +} +int evthreadimpl_lock_unlock_(unsigned mode, void* lock) +{ + if (evthread_lock_fns_.unlock) + return evthread_lock_fns_.unlock(mode, lock); + else + return 0; +} +void* evthreadimpl_cond_alloc_(unsigned condtype) +{ +#ifndef EVENT__DISABLE_DEBUG_MODE + if (event_debug_mode_on_) { + event_debug_created_threadable_ctx_ = 1; + } +#endif + + return evthread_cond_fns_.alloc_condition ? evthread_cond_fns_.alloc_condition(condtype) : NULL; +} +void evthreadimpl_cond_free_(void* cond) +{ + if (evthread_cond_fns_.free_condition) + evthread_cond_fns_.free_condition(cond); +} +int evthreadimpl_cond_signal_(void* cond, int broadcast) +{ + if (evthread_cond_fns_.signal_condition) + return evthread_cond_fns_.signal_condition(cond, broadcast); + else + return 0; +} +int evthreadimpl_cond_wait_(void* cond, void* lock, const struct timeval* tv) +{ + if (evthread_cond_fns_.wait_condition) + return evthread_cond_fns_.wait_condition(cond, lock, tv); + else + return 0; +} +int evthreadimpl_is_lock_debugging_enabled_(void) +{ + return evthread_lock_debugging_enabled_; +} + +int evthreadimpl_locking_enabled_(void) +{ + return evthread_lock_fns_.lock != NULL; +} +#endif + +#endif diff --git a/asynio/event/evthread_pthread.c b/asynio/event/evthread_pthread.c new file mode 100644 index 0000000000000000000000000000000000000000..b4cabdbb3b32a1f3ef2614e5f055de05acdd6dda --- /dev/null +++ b/asynio/event/evthread_pthread.c @@ -0,0 +1,170 @@ +/* + * Copyright 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +/* With glibc we need to define _GNU_SOURCE to get PTHREAD_MUTEX_RECURSIVE. + * This comes from evconfig-private.h + */ +#include + +struct event_base; + +#include +#include + +#include "mm-internal.h" +#include "evthread-internal.h" + +static pthread_mutexattr_t attr_recursive; + +static void* evthread_posix_lock_alloc(unsigned locktype) +{ + pthread_mutexattr_t* attr = NULL; + pthread_mutex_t* lock = mm_malloc(sizeof(pthread_mutex_t)); + if (!lock) + return NULL; + if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) + attr = &attr_recursive; + if (pthread_mutex_init(lock, attr)) { + mm_free(lock); + return NULL; + } + return lock; +} + +static void evthread_posix_lock_free(void* lock_, unsigned locktype) +{ + pthread_mutex_t* lock = lock_; + pthread_mutex_destroy(lock); + mm_free(lock); +} + +static int evthread_posix_lock(unsigned mode, void* lock_) +{ + pthread_mutex_t* lock = lock_; + if (mode & EVTHREAD_TRY) + return pthread_mutex_trylock(lock); + else + return pthread_mutex_lock(lock); +} + +static int evthread_posix_unlock(unsigned mode, void* lock_) +{ + pthread_mutex_t* lock = lock_; + return pthread_mutex_unlock(lock); +} + +static unsigned long evthread_posix_get_id(void) +{ + union { + pthread_t thr; +#if EVENT__SIZEOF_PTHREAD_T > EVENT__SIZEOF_LONG + ev_uint64_t id; +#else + unsigned long id; +#endif + } r; +#if EVENT__SIZEOF_PTHREAD_T < EVENT__SIZEOF_LONG + memset(&r, 0, sizeof(r)); +#endif + r.thr = pthread_self(); + return (unsigned long)r.id; +} + +static void* evthread_posix_cond_alloc(unsigned condflags) +{ + pthread_cond_t* cond = mm_malloc(sizeof(pthread_cond_t)); + if (!cond) + return NULL; + if (pthread_cond_init(cond, NULL)) { + mm_free(cond); + return NULL; + } + return cond; +} + +static void evthread_posix_cond_free(void* cond_) +{ + pthread_cond_t* cond = cond_; + pthread_cond_destroy(cond); + mm_free(cond); +} + +static int evthread_posix_cond_signal(void* cond_, int broadcast) +{ + pthread_cond_t* cond = cond_; + int r; + if (broadcast) + r = pthread_cond_broadcast(cond); + else + r = pthread_cond_signal(cond); + return r ? -1 : 0; +} + +static int evthread_posix_cond_wait(void* cond_, void* lock_, const struct timeval* tv) +{ + int r; + pthread_cond_t* cond = cond_; + pthread_mutex_t* lock = lock_; + + if (tv) { + struct timeval now, abstime; + struct timespec ts; + evutil_gettimeofday(&now, NULL); + evutil_timeradd(&now, tv, &abstime); + ts.tv_sec = abstime.tv_sec; + ts.tv_nsec = abstime.tv_usec * 1000; + r = pthread_cond_timedwait(cond, lock, &ts); + if (r == ETIMEDOUT) + return 1; + else if (r) + return -1; + else + return 0; + } else { + r = pthread_cond_wait(cond, lock); + return r ? -1 : 0; + } +} + +int evthread_use_pthreads(void) +{ + struct evthread_lock_callbacks cbs = {EVTHREAD_LOCK_API_VERSION, EVTHREAD_LOCKTYPE_RECURSIVE, evthread_posix_lock_alloc, + evthread_posix_lock_free, evthread_posix_lock, evthread_posix_unlock}; + struct evthread_condition_callbacks cond_cbs = { + EVTHREAD_CONDITION_API_VERSION, evthread_posix_cond_alloc, evthread_posix_cond_free, evthread_posix_cond_signal, evthread_posix_cond_wait}; + /* Set ourselves up to get recursive locks. */ + if (pthread_mutexattr_init(&attr_recursive)) + return -1; + if (pthread_mutexattr_settype(&attr_recursive, PTHREAD_MUTEX_RECURSIVE)) + return -1; + + evthread_set_lock_callbacks(&cbs); + evthread_set_condition_callbacks(&cond_cbs); + evthread_set_id_callback(evthread_posix_get_id); + return 0; +} diff --git a/asynio/event/evthread_win32.c b/asynio/event/evthread_win32.c new file mode 100644 index 0000000000000000000000000000000000000000..49727b3badc86538d1a7c7e781e131a8687cc102 --- /dev/null +++ b/asynio/event/evthread_win32.c @@ -0,0 +1,304 @@ +/* + * Copyright 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "event-config.h" +#include "evconfig-private.h" + +#ifdef _WIN32 +#ifndef _WIN32_WINNT +/* Minimum required for InitializeCriticalSectionAndSpinCount */ +#define _WIN32_WINNT 0x0403 +#endif +#include +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#include +#endif + +struct event_base; +#include "thread.h" + +#include "mm-internal.h" +#include "evthread-internal.h" +#include "time-internal.h" + +#define SPIN_COUNT 2000 + +static void* evthread_win32_lock_create(unsigned locktype) +{ + CRITICAL_SECTION* lock = mm_malloc(sizeof(CRITICAL_SECTION)); + if (!lock) + return NULL; + if (InitializeCriticalSectionAndSpinCount(lock, SPIN_COUNT) == 0) { + mm_free(lock); + return NULL; + } + return lock; +} + +static void evthread_win32_lock_free(void* lock_, unsigned locktype) +{ + CRITICAL_SECTION* lock = lock_; + DeleteCriticalSection(lock); + mm_free(lock); +} + +static int evthread_win32_lock(unsigned mode, void* lock_) +{ + CRITICAL_SECTION* lock = lock_; + if ((mode & EVTHREAD_TRY)) { + return !TryEnterCriticalSection(lock); + } else { + EnterCriticalSection(lock); + return 0; + } +} + +static int evthread_win32_unlock(unsigned mode, void* lock_) +{ + CRITICAL_SECTION* lock = lock_; + LeaveCriticalSection(lock); + return 0; +} + +static unsigned long evthread_win32_get_id(void) +{ + return (unsigned long)GetCurrentThreadId(); +} + +#ifdef WIN32_HAVE_CONDITION_VARIABLES +static void WINAPI (*InitializeConditionVariable_fn)(PCONDITION_VARIABLE) = NULL; +static BOOL WINAPI (*SleepConditionVariableCS_fn)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD) = NULL; +static void WINAPI (*WakeAllConditionVariable_fn)(PCONDITION_VARIABLE) = NULL; +static void WINAPI (*WakeConditionVariable_fn)(PCONDITION_VARIABLE) = NULL; + +static int evthread_win32_condvar_init(void) +{ + HANDLE lib; + + lib = GetModuleHandle(TEXT("kernel32.dll")); + if (lib == NULL) + return 0; + +#define LOAD(name) name##_fn = GetProcAddress(lib, #name) + LOAD(InitializeConditionVariable); + LOAD(SleepConditionVariableCS); + LOAD(WakeAllConditionVariable); + LOAD(WakeConditionVariable); + + return InitializeConditionVariable_fn && SleepConditionVariableCS_fn && WakeAllConditionVariable_fn && WakeConditionVariable_fn; +} + +/* XXXX Even if we can build this, we don't necessarily want to: the functions + * in question didn't exist before Vista, so we'd better LoadProc them. */ +static void* evthread_win32_condvar_alloc(unsigned condflags) +{ + CONDITION_VARIABLE* cond = mm_malloc(sizeof(CONDITION_VARIABLE)); + if (!cond) + return NULL; + InitializeConditionVariable_fn(cond); + return cond; +} + +static void evthread_win32_condvar_free(void* cond_) +{ + CONDITION_VARIABLE* cond = cond_; + /* There doesn't _seem_ to be a cleaup fn here... */ + mm_free(cond); +} + +static int evthread_win32_condvar_signal(void* cond, int broadcast) +{ + CONDITION_VARIABLE* cond = cond_; + if (broadcast) + WakeAllConditionVariable_fn(cond); + else + WakeConditionVariable_fn(cond); + return 0; +} + +static int evthread_win32_condvar_wait(void* cond_, void* lock_, const struct timeval* tv) +{ + CONDITION_VARIABLE* cond = cond_; + CRITICAL_SECTION* lock = lock_; + DWORD ms, err; + BOOL result; + + if (tv) + ms = evutil_tv_to_msec_(tv); + else + ms = INFINITE; + result = SleepConditionVariableCS_fn(cond, lock, ms); + if (result) { + if (GetLastError() == WAIT_TIMEOUT) + return 1; + else + return -1; + } else { + return 0; + } +} +#endif + +struct evthread_win32_cond { + HANDLE event; + + CRITICAL_SECTION lock; + int n_waiting; + int n_to_wake; + int generation; +}; + +static void* evthread_win32_cond_alloc(unsigned flags) +{ + struct evthread_win32_cond* cond; + if (!(cond = mm_malloc(sizeof(struct evthread_win32_cond)))) + return NULL; + if (InitializeCriticalSectionAndSpinCount(&cond->lock, SPIN_COUNT) == 0) { + mm_free(cond); + return NULL; + } + if ((cond->event = CreateEvent(NULL, TRUE, FALSE, NULL)) == NULL) { + DeleteCriticalSection(&cond->lock); + mm_free(cond); + return NULL; + } + cond->n_waiting = cond->n_to_wake = cond->generation = 0; + return cond; +} + +static void evthread_win32_cond_free(void* cond_) +{ + struct evthread_win32_cond* cond = cond_; + DeleteCriticalSection(&cond->lock); + CloseHandle(cond->event); + mm_free(cond); +} + +static int evthread_win32_cond_signal(void* cond_, int broadcast) +{ + struct evthread_win32_cond* cond = cond_; + EnterCriticalSection(&cond->lock); + if (broadcast) + cond->n_to_wake = cond->n_waiting; + else + ++cond->n_to_wake; + cond->generation++; + SetEvent(cond->event); + LeaveCriticalSection(&cond->lock); + return 0; +} + +static int evthread_win32_cond_wait(void* cond_, void* lock_, const struct timeval* tv) +{ + struct evthread_win32_cond* cond = cond_; + CRITICAL_SECTION* lock = lock_; + int generation_at_start; + int waiting = 1; + int result = -1; + DWORD ms = INFINITE, ms_orig = INFINITE, startTime, endTime; + if (tv) + ms_orig = ms = evutil_tv_to_msec_(tv); + + EnterCriticalSection(&cond->lock); + ++cond->n_waiting; + generation_at_start = cond->generation; + LeaveCriticalSection(&cond->lock); + + LeaveCriticalSection(lock); + + startTime = GetTickCount(); + do { + DWORD res; + res = WaitForSingleObject(cond->event, ms); + EnterCriticalSection(&cond->lock); + if (cond->n_to_wake && cond->generation != generation_at_start) { + --cond->n_to_wake; + --cond->n_waiting; + result = 0; + waiting = 0; + goto out; + } else if (res != WAIT_OBJECT_0) { + result = (res == WAIT_TIMEOUT) ? 1 : -1; + --cond->n_waiting; + waiting = 0; + goto out; + } else if (ms != INFINITE) { + endTime = GetTickCount(); + if (startTime + ms_orig <= endTime) { + result = 1; /* Timeout */ + --cond->n_waiting; + waiting = 0; + goto out; + } else { + ms = startTime + ms_orig - endTime; + } + } + /* If we make it here, we are still waiting. */ + if (cond->n_to_wake == 0) { + /* There is nobody else who should wake up; reset + * the event. */ + ResetEvent(cond->event); + } + out: + LeaveCriticalSection(&cond->lock); + } while (waiting); + + EnterCriticalSection(lock); + + EnterCriticalSection(&cond->lock); + if (!cond->n_waiting) + ResetEvent(cond->event); + LeaveCriticalSection(&cond->lock); + + return result; +} + +int evthread_use_windows_threads(void) +{ + struct evthread_lock_callbacks cbs = {EVTHREAD_LOCK_API_VERSION, EVTHREAD_LOCKTYPE_RECURSIVE, evthread_win32_lock_create, + evthread_win32_lock_free, evthread_win32_lock, evthread_win32_unlock}; + + struct evthread_condition_callbacks cond_cbs = { + EVTHREAD_CONDITION_API_VERSION, evthread_win32_cond_alloc, evthread_win32_cond_free, evthread_win32_cond_signal, evthread_win32_cond_wait}; +#ifdef WIN32_HAVE_CONDITION_VARIABLES + struct evthread_condition_callbacks condvar_cbs = { + EVTHREAD_CONDITION_API_VERSION, evthread_win32_condvar_alloc, evthread_win32_condvar_free, evthread_win32_condvar_signal, + evthread_win32_condvar_wait}; +#endif + + evthread_set_lock_callbacks(&cbs); + evthread_set_id_callback(evthread_win32_get_id); +#ifdef WIN32_HAVE_CONDITION_VARIABLES + if (evthread_win32_condvar_init()) { + evthread_set_condition_callbacks(&condvar_cbs); + return 0; + } +#endif + evthread_set_condition_callbacks(&cond_cbs); + + return 0; +} diff --git a/asynio/event/evutil.c b/asynio/event/evutil.c new file mode 100644 index 0000000000000000000000000000000000000000..6fc1302a47a48d97a971bc0f98510fe5407f13d1 --- /dev/null +++ b/asynio/event/evutil.c @@ -0,0 +1,2535 @@ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef _WIN32 +#include +#include +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#include +#include +#include +#undef _WIN32_WINNT +/* For structs needed by GetAdaptersAddresses */ +#define _WIN32_WINNT 0x0501 +#include +#endif + +#include +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif +#ifdef EVENT__HAVE_FCNTL_H +#include +#endif +#ifdef EVENT__HAVE_STDLIB_H +#include +#endif +#include +#include +#include +#include +#ifdef EVENT__HAVE_NETINET_IN_H +#include +#endif +#ifdef EVENT__HAVE_NETINET_IN6_H +#include +#endif +#ifdef EVENT__HAVE_NETINET_TCP_H +#include +#endif +#ifdef EVENT__HAVE_ARPA_INET_H +#include +#endif +#include +#include +#ifdef EVENT__HAVE_IFADDRS_H +#include +#endif + +#include "evconfig-internal.h" + +#ifdef _WIN32 +#define HT_NO_CACHE_HASH_VALUES +#include "ht-internal.h" +#define open _open +#define read _read +#define close _close +#ifndef fstat +#define fstat _fstati64 +#endif +#ifndef stat +#define stat _stati64 +#endif +#define mode_t int +#endif + +int evutil_open_closeonexec_(const char* pathname, int flags, unsigned mode) +{ + int fd; + +#ifdef O_CLOEXEC + fd = open(pathname, flags | O_CLOEXEC, (mode_t)mode); + if (fd >= 0 || errno == EINVAL) + return fd; + /* If we got an EINVAL, fall through and try without O_CLOEXEC */ +#endif + fd = open(pathname, flags, (mode_t)mode); + if (fd < 0) + return -1; + +#if defined(FD_CLOEXEC) + if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) { + close(fd); + return -1; + } +#endif + + return fd; +} + +/** + Read the contents of 'filename' into a newly allocated NUL-terminated + string. Set *content_out to hold this string, and *len_out to hold its + length (not including the appended NUL). If 'is_binary', open the file in + binary mode. + + Returns 0 on success, -1 if the open fails, and -2 for all other failures. + + Used internally only; may go away in a future version. + */ +int evutil_read_file_(const char* filename, char** content_out, size_t* len_out, int is_binary) +{ + int fd, r; + struct stat st; + char* mem; + size_t read_so_far = 0; + int mode = O_RDONLY; + + EVUTIL_ASSERT(content_out); + EVUTIL_ASSERT(len_out); + *content_out = NULL; + *len_out = 0; + +#ifdef O_BINARY + if (is_binary) + mode |= O_BINARY; +#endif + + fd = evutil_open_closeonexec_(filename, mode, 0); + if (fd < 0) + return -1; + if (fstat(fd, &st) || st.st_size < 0 || st.st_size > EV_SSIZE_MAX - 1) { + close(fd); + return -2; + } + mem = mm_malloc((size_t)st.st_size + 1); + if (!mem) { + close(fd); + return -2; + } + read_so_far = 0; +#ifdef _WIN32 +#define N_TO_READ(x) ((x) > INT_MAX) ? INT_MAX : ((int)(x)) +#else +#define N_TO_READ(x) (x) +#endif + while ((r = read(fd, mem + read_so_far, N_TO_READ(st.st_size - read_so_far))) > 0) { + read_so_far += r; + if (read_so_far >= (size_t)st.st_size) + break; + EVUTIL_ASSERT(read_so_far < (size_t)st.st_size); + } + close(fd); + if (r < 0) { + mm_free(mem); + return -2; + } + mem[read_so_far] = 0; + + *len_out = read_so_far; + *content_out = mem; + return 0; +} + +int evutil_socketpair(int family, int type, int protocol, evutil_socket_t fd[2]) +{ +#ifndef _WIN32 + return socketpair(family, type, protocol, fd); +#else + return evutil_ersatz_socketpair_(family, type, protocol, fd); +#endif +} + +int evutil_ersatz_socketpair_(int family, int type, int protocol, evutil_socket_t fd[2]) +{ + /* This code is originally from Tor. Used with permission. */ + + /* This socketpair does not work when localhost is down. So + * it's really not the same thing at all. But it's close enough + * for now, and really, when localhost is down sometimes, we + * have other problems too. + */ +#ifdef _WIN32 +#define ERR(e) WSA##e +#else +#define ERR(e) e +#endif + evutil_socket_t listener = -1; + evutil_socket_t connector = -1; + evutil_socket_t acceptor = -1; + struct sockaddr_in listen_addr; + struct sockaddr_in connect_addr; + ev_socklen_t size; + int saved_errno = -1; + int family_test; + + family_test = family != AF_INET; +#ifdef AF_UNIX + family_test = family_test && (family != AF_UNIX); +#endif + if (protocol || family_test) { + EVUTIL_SET_SOCKET_ERROR(ERR(EAFNOSUPPORT)); + return -1; + } + + if (!fd) { + EVUTIL_SET_SOCKET_ERROR(ERR(EINVAL)); + return -1; + } + + listener = socket(AF_INET, type, 0); + if (listener < 0) + return -1; + memset(&listen_addr, 0, sizeof(listen_addr)); + listen_addr.sin_family = AF_INET; + listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + listen_addr.sin_port = 0; /* kernel chooses port. */ + if (bind(listener, (struct sockaddr*)&listen_addr, sizeof(listen_addr)) == -1) + goto tidy_up_and_fail; + if (listen(listener, 1) == -1) + goto tidy_up_and_fail; + + connector = socket(AF_INET, type, 0); + if (connector < 0) + goto tidy_up_and_fail; + + memset(&connect_addr, 0, sizeof(connect_addr)); + + /* We want to find out the port number to connect to. */ + size = sizeof(connect_addr); + if (getsockname(listener, (struct sockaddr*)&connect_addr, &size) == -1) + goto tidy_up_and_fail; + if (size != sizeof(connect_addr)) + goto abort_tidy_up_and_fail; + if (connect(connector, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) == -1) + goto tidy_up_and_fail; + + size = sizeof(listen_addr); + acceptor = accept(listener, (struct sockaddr*)&listen_addr, &size); + if (acceptor < 0) + goto tidy_up_and_fail; + if (size != sizeof(listen_addr)) + goto abort_tidy_up_and_fail; + /* Now check we are talking to ourself by matching port and host on the + two sockets. */ + if (getsockname(connector, (struct sockaddr*)&connect_addr, &size) == -1) + goto tidy_up_and_fail; + if (size != sizeof(connect_addr) || listen_addr.sin_family != connect_addr.sin_family + || listen_addr.sin_addr.s_addr != connect_addr.sin_addr.s_addr || listen_addr.sin_port != connect_addr.sin_port) + goto abort_tidy_up_and_fail; + evutil_closesocket(listener); + fd[0] = connector; + fd[1] = acceptor; + + return 0; + +abort_tidy_up_and_fail: + saved_errno = ERR(ECONNABORTED); +tidy_up_and_fail: + if (saved_errno < 0) + saved_errno = EVUTIL_SOCKET_ERROR(); + if (listener != -1) + evutil_closesocket(listener); + if (connector != -1) + evutil_closesocket(connector); + if (acceptor != -1) + evutil_closesocket(acceptor); + + EVUTIL_SET_SOCKET_ERROR(saved_errno); + return -1; +#undef ERR +} + +int evutil_make_socket_nonblocking(evutil_socket_t fd) +{ +#ifdef _WIN32 + { + unsigned long nonblocking = 1; + if (ioctlsocket(fd, FIONBIO, &nonblocking) == SOCKET_ERROR) { + event_sock_warn(fd, "fcntl(%d, F_GETFL)", (int)fd); + return -1; + } + } +#else + { + int flags; + if ((flags = fcntl(fd, F_GETFL, NULL)) < 0) { + event_warn("fcntl(%d, F_GETFL)", fd); + return -1; + } + if (!(flags & O_NONBLOCK)) { + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { + event_warn("fcntl(%d, F_SETFL)", fd); + return -1; + } + } + } +#endif + return 0; +} + +/* Faster version of evutil_make_socket_nonblocking for internal use. + * + * Requires that no F_SETFL flags were previously set on the fd. + */ +static int evutil_fast_socket_nonblocking(evutil_socket_t fd) +{ +#ifdef _WIN32 + return evutil_make_socket_nonblocking(fd); +#else + if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + event_warn("fcntl(%d, F_SETFL)", fd); + return -1; + } + return 0; +#endif +} + +int evutil_make_listen_socket_reuseable(evutil_socket_t sock) +{ +#if defined(SO_REUSEADDR) && !defined(_WIN32) + int one = 1; + /* REUSEADDR on Unix means, "don't hang on to this address after the + * listener is closed." On Windows, though, it means "don't keep other + * processes from binding to this address while we're using it. */ + return setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*)&one, (ev_socklen_t)sizeof(one)); +#else + return 0; +#endif +} + +int evutil_make_listen_socket_reuseable_port(evutil_socket_t sock) +{ +#if defined __linux__ && defined(SO_REUSEPORT) + int one = 1; + /* REUSEPORT on Linux 3.9+ means, "Multiple servers (processes or + * threads) can bind to the same port if they each set the option. */ + return setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void*)&one, (ev_socklen_t)sizeof(one)); +#else + return 0; +#endif +} + +int evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock) +{ +#if defined(EVENT__HAVE_NETINET_TCP_H) && defined(TCP_DEFER_ACCEPT) + int one = 1; + + /* TCP_DEFER_ACCEPT tells the kernel to call defer accept() only after data + * has arrived and ready to read */ + return setsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, &one, (ev_socklen_t)sizeof(one)); +#endif + return 0; +} + +int evutil_make_socket_closeonexec(evutil_socket_t fd) +{ +#if !defined(_WIN32) && defined(EVENT__HAVE_SETFD) + int flags; + if ((flags = fcntl(fd, F_GETFD, NULL)) < 0) { + event_warn("fcntl(%d, F_GETFD)", fd); + return -1; + } + if (!(flags & FD_CLOEXEC)) { + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) { + event_warn("fcntl(%d, F_SETFD)", fd); + return -1; + } + } +#endif + return 0; +} + +/* Faster version of evutil_make_socket_closeonexec for internal use. + * + * Requires that no F_SETFD flags were previously set on the fd. + */ +static int evutil_fast_socket_closeonexec(evutil_socket_t fd) +{ +#if !defined(_WIN32) && defined(EVENT__HAVE_SETFD) + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { + event_warn("fcntl(%d, F_SETFD)", fd); + return -1; + } +#endif + return 0; +} + +int evutil_closesocket(evutil_socket_t sock) +{ +#ifndef _WIN32 + return close(sock); +#else + return closesocket(sock); +#endif +} + +ev_int64_t evutil_strtoll(const char* s, char** endptr, int base) +{ +#ifdef EVENT__HAVE_STRTOLL + return (ev_int64_t)strtoll(s, endptr, base); +#elif EVENT__SIZEOF_LONG == 8 + return (ev_int64_t)strtol(s, endptr, base); +#elif defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1300 + /* XXXX on old versions of MS APIs, we only support base + * 10. */ + ev_int64_t r; + if (base != 10) + return 0; + r = (ev_int64_t)_atoi64(s); + while (isspace(*s)) + ++s; + if (*s == '-') + ++s; + while (isdigit(*s)) + ++s; + if (endptr) + *endptr = (char*)s; + return r; +#elif defined(_WIN32) + return (ev_int64_t)_strtoi64(s, endptr, base); +#elif defined(EVENT__SIZEOF_LONG_LONG) && EVENT__SIZEOF_LONG_LONG == 8 + long long r; + int n; + if (base != 10 && base != 16) + return 0; + if (base == 10) { + n = sscanf(s, "%lld", &r); + } else { + unsigned long long ru = 0; + n = sscanf(s, "%llx", &ru); + if (ru > EV_INT64_MAX) + return 0; + r = (long long)ru; + } + if (n != 1) + return 0; + while (EVUTIL_ISSPACE_(*s)) + ++s; + if (*s == '-') + ++s; + if (base == 10) { + while (EVUTIL_ISDIGIT_(*s)) + ++s; + } else { + while (EVUTIL_ISXDIGIT_(*s)) + ++s; + } + if (endptr) + *endptr = (char*)s; + return r; +#else +#error "I don't know how to parse 64-bit integers." +#endif +} + +#ifdef _WIN32 +int evutil_socket_geterror(evutil_socket_t sock) +{ + int optval, optvallen = sizeof(optval); + int err = WSAGetLastError(); + if (err == WSAEWOULDBLOCK && sock >= 0) { + if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*)&optval, &optvallen)) + return err; + if (optval) + return optval; + } + return err; +} +#endif + +/* XXX we should use an enum here. */ +/* 2 for connection refused, 1 for connected, 0 for not yet, -1 for error. */ +int evutil_socket_connect_(evutil_socket_t* fd_ptr, const struct sockaddr* sa, int socklen) +{ + int made_fd = 0; + + if (*fd_ptr < 0) { + if ((*fd_ptr = socket(sa->sa_family, SOCK_STREAM, 0)) < 0) + goto err; + made_fd = 1; + if (evutil_make_socket_nonblocking(*fd_ptr) < 0) { + goto err; + } + } + + if (connect(*fd_ptr, sa, socklen) < 0) { + int e = evutil_socket_geterror(*fd_ptr); + if (EVUTIL_ERR_CONNECT_RETRIABLE(e)) + return 0; + if (EVUTIL_ERR_CONNECT_REFUSED(e)) + return 2; + goto err; + } else { + return 1; + } + +err: + if (made_fd) { + evutil_closesocket(*fd_ptr); + *fd_ptr = -1; + } + return -1; +} + +/* Check whether a socket on which we called connect() is done + connecting. Return 1 for connected, 0 for not yet, -1 for error. In the + error case, set the current socket errno to the error that happened during + the connect operation. */ +int evutil_socket_finished_connecting_(evutil_socket_t fd) +{ + int e; + ev_socklen_t elen = sizeof(e); + + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&e, &elen) < 0) + return -1; + + if (e) { + if (EVUTIL_ERR_CONNECT_RETRIABLE(e)) + return 0; + EVUTIL_SET_SOCKET_ERROR(e); + return -1; + } + + return 1; +} + +#if ( \ + EVUTIL_AI_PASSIVE | EVUTIL_AI_CANONNAME | EVUTIL_AI_NUMERICHOST | EVUTIL_AI_NUMERICSERV | EVUTIL_AI_V4MAPPED | EVUTIL_AI_ALL \ + | EVUTIL_AI_ADDRCONFIG) \ + != (EVUTIL_AI_PASSIVE ^ EVUTIL_AI_CANONNAME ^ EVUTIL_AI_NUMERICHOST ^ EVUTIL_AI_NUMERICSERV ^ EVUTIL_AI_V4MAPPED ^ EVUTIL_AI_ALL \ + ^ EVUTIL_AI_ADDRCONFIG) +#error "Some of our EVUTIL_AI_* flags seem to overlap with system AI_* flags" +#endif + +/* We sometimes need to know whether we have an ipv4 address and whether we + have an ipv6 address. If 'have_checked_interfaces', then we've already done + the test. If 'had_ipv4_address', then it turns out we had an ipv4 address. + If 'had_ipv6_address', then it turns out we had an ipv6 address. These are + set by evutil_check_interfaces. */ +static int have_checked_interfaces, had_ipv4_address, had_ipv6_address; + +/* Macro: True iff the IPv4 address 'addr', in host order, is in 127.0.0.0/8 + */ +#define EVUTIL_V4ADDR_IS_LOCALHOST(addr) (((addr) >> 24) == 127) + +/* Macro: True iff the IPv4 address 'addr', in host order, is a class D + * (multiclass) address. + */ +#define EVUTIL_V4ADDR_IS_CLASSD(addr) ((((addr) >> 24) & 0xf0) == 0xe0) + +static void evutil_found_ifaddr(const struct sockaddr* sa) +{ + const char ZEROES[] = "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00"; + + if (sa->sa_family == AF_INET) { + const struct sockaddr_in* sin = (struct sockaddr_in*)sa; + ev_uint32_t addr = ntohl(sin->sin_addr.s_addr); + if (addr == 0 || EVUTIL_V4ADDR_IS_LOCALHOST(addr) || EVUTIL_V4ADDR_IS_CLASSD(addr)) { + /* Not actually a usable external address. */ + } else { + event_debug(("Detected an IPv4 interface")); + had_ipv4_address = 1; + } + } else if (sa->sa_family == AF_INET6) { + const struct sockaddr_in6* sin6 = (struct sockaddr_in6*)sa; + const unsigned char* addr = (unsigned char*)sin6->sin6_addr.s6_addr; + if (!memcmp(addr, ZEROES, 8) || ((addr[0] & 0xfe) == 0xfc) || (addr[0] == 0xfe && (addr[1] & 0xc0) == 0x80) + || (addr[0] == 0xfe && (addr[1] & 0xc0) == 0xc0) || (addr[0] == 0xff)) { + /* This is a reserved, ipv4compat, ipv4map, loopback, + * link-local, multicast, or unspecified address. */ + } else { + event_debug(("Detected an IPv6 interface")); + had_ipv6_address = 1; + } + } +} + +#ifdef _WIN32 +typedef ULONG(WINAPI* GetAdaptersAddresses_fn_t)(ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG); +#endif + +static int evutil_check_ifaddrs(void) +{ +#if defined(EVENT__HAVE_GETIFADDRS) + /* Most free Unixy systems provide getifaddrs, which gives us a linked list + * of struct ifaddrs. */ + struct ifaddrs* ifa = NULL; + const struct ifaddrs* i; + if (getifaddrs(&ifa) < 0) { + event_warn("Unable to call getifaddrs()"); + return -1; + } + + for (i = ifa; i; i = i->ifa_next) { + if (!i->ifa_addr) + continue; + evutil_found_ifaddr(i->ifa_addr); + } + + freeifaddrs(ifa); + return 0; +#elif defined(_WIN32) + /* Windows XP began to provide GetAdaptersAddresses. Windows 2000 had a + "GetAdaptersInfo", but that's deprecated; let's just try + GetAdaptersAddresses and fall back to connect+getsockname. + */ + HMODULE lib = evutil_load_windows_system_library_(TEXT("ihplapi.dll")); + GetAdaptersAddresses_fn_t fn; + ULONG size, res; + IP_ADAPTER_ADDRESSES *addresses = NULL, *address; + int result = -1; + +#define FLAGS (GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER) + + if (!lib) + goto done; + + if (!(fn = (GetAdaptersAddresses_fn_t)GetProcAddress(lib, "GetAdaptersAddresses"))) + goto done; + + /* Guess how much space we need. */ + size = 15 * 1024; + addresses = mm_malloc(size); + if (!addresses) + goto done; + res = fn(AF_UNSPEC, FLAGS, NULL, addresses, &size); + if (res == ERROR_BUFFER_OVERFLOW) { + /* we didn't guess that we needed enough space; try again */ + mm_free(addresses); + addresses = mm_malloc(size); + if (!addresses) + goto done; + res = fn(AF_UNSPEC, FLAGS, NULL, addresses, &size); + } + if (res != NO_ERROR) + goto done; + + for (address = addresses; address; address = address->Next) { + IP_ADAPTER_UNICAST_ADDRESS* a; + for (a = address->FirstUnicastAddress; a; a = a->Next) { + /* Yes, it's a linked list inside a linked list */ + struct sockaddr* sa = a->Address.lpSockaddr; + evutil_found_ifaddr(sa); + } + } + + result = 0; +done: + if (lib) + FreeLibrary(lib); + if (addresses) + mm_free(addresses); + return result; +#else + return -1; +#endif +} + +/* Test whether we have an ipv4 interface and an ipv6 interface. Return 0 if + * the test seemed successful. */ +static int evutil_check_interfaces(int force_recheck) +{ + evutil_socket_t fd = -1; + struct sockaddr_in sin, sin_out; + struct sockaddr_in6 sin6, sin6_out; + ev_socklen_t sin_out_len = sizeof(sin_out); + ev_socklen_t sin6_out_len = sizeof(sin6_out); + int r; + if (have_checked_interfaces && !force_recheck) + return 0; + + if (evutil_check_ifaddrs() == 0) { + /* Use a nice sane interface, if this system has one. */ + return 0; + } + + /* Ugh. There was no nice sane interface. So to check whether we have + * an interface open for a given protocol, will try to make a UDP + * 'connection' to a remote host on the internet. We don't actually + * use it, so the address doesn't matter, but we want to pick one that + * keep us from using a host- or link-local interface. */ + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(53); + r = evutil_inet_pton(AF_INET, "18.244.0.188", &sin.sin_addr); + EVUTIL_ASSERT(r); + + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(53); + r = evutil_inet_pton(AF_INET6, "2001:4860:b002::68", &sin6.sin6_addr); + EVUTIL_ASSERT(r); + + memset(&sin_out, 0, sizeof(sin_out)); + memset(&sin6_out, 0, sizeof(sin6_out)); + + /* XXX some errnos mean 'no address'; some mean 'not enough sockets'. */ + if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) >= 0 && connect(fd, (struct sockaddr*)&sin, sizeof(sin)) == 0 + && getsockname(fd, (struct sockaddr*)&sin_out, &sin_out_len) == 0) { + /* We might have an IPv4 interface. */ + evutil_found_ifaddr((struct sockaddr*)&sin_out); + } + if (fd >= 0) + evutil_closesocket(fd); + + if ((fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) >= 0 && connect(fd, (struct sockaddr*)&sin6, sizeof(sin6)) == 0 + && getsockname(fd, (struct sockaddr*)&sin6_out, &sin6_out_len) == 0) { + /* We might have an IPv6 interface. */ + evutil_found_ifaddr((struct sockaddr*)&sin6_out); + } + + if (fd >= 0) + evutil_closesocket(fd); + + return 0; +} + +/* Internal addrinfo flag. This one is set when we allocate the addrinfo from + * inside libevent. Otherwise, the built-in getaddrinfo() function allocated + * it, and we should trust what they said. + **/ +#define EVUTIL_AI_LIBEVENT_ALLOCATED 0x80000000 + +/* Helper: construct a new addrinfo containing the socket address in + * 'sa', which must be a sockaddr_in or a sockaddr_in6. Take the + * socktype and protocol info from hints. If they weren't set, then + * allocate both a TCP and a UDP addrinfo. + */ +struct evutil_addrinfo* evutil_new_addrinfo_(struct sockaddr* sa, ev_socklen_t socklen, const struct evutil_addrinfo* hints) +{ + struct evutil_addrinfo* res; + EVUTIL_ASSERT(hints); + + if (hints->ai_socktype == 0 && hints->ai_protocol == 0) { + /* Indecisive user! Give them a UDP and a TCP. */ + struct evutil_addrinfo *r1, *r2; + struct evutil_addrinfo tmp; + memcpy(&tmp, hints, sizeof(tmp)); + tmp.ai_socktype = SOCK_STREAM; + tmp.ai_protocol = IPPROTO_TCP; + r1 = evutil_new_addrinfo_(sa, socklen, &tmp); + if (!r1) + return NULL; + tmp.ai_socktype = SOCK_DGRAM; + tmp.ai_protocol = IPPROTO_UDP; + r2 = evutil_new_addrinfo_(sa, socklen, &tmp); + if (!r2) { + evutil_freeaddrinfo(r1); + return NULL; + } + r1->ai_next = r2; + return r1; + } + + /* We're going to allocate extra space to hold the sockaddr. */ + res = mm_calloc(1, sizeof(struct evutil_addrinfo) + socklen); + if (!res) + return NULL; + res->ai_addr = (struct sockaddr*)(((char*)res) + sizeof(struct evutil_addrinfo)); + memcpy(res->ai_addr, sa, socklen); + res->ai_addrlen = socklen; + res->ai_family = sa->sa_family; /* Same or not? XXX */ + res->ai_flags = EVUTIL_AI_LIBEVENT_ALLOCATED; + res->ai_socktype = hints->ai_socktype; + res->ai_protocol = hints->ai_protocol; + + return res; +} + +/* Append the addrinfo 'append' to the end of 'first', and return the start of + * the list. Either element can be NULL, in which case we return the element + * that is not NULL. */ +struct evutil_addrinfo* evutil_addrinfo_append_(struct evutil_addrinfo* first, struct evutil_addrinfo* append) +{ + struct evutil_addrinfo* ai = first; + if (!ai) + return append; + while (ai->ai_next) + ai = ai->ai_next; + ai->ai_next = append; + + return first; +} + +static int parse_numeric_servname(const char* servname) +{ + int n; + char* endptr = NULL; + n = (int)strtol(servname, &endptr, 10); + if (n >= 0 && n <= 65535 && servname[0] && endptr && !endptr[0]) + return n; + else + return -1; +} + +/** Parse a service name in 'servname', which can be a decimal port. + * Return the port number, or -1 on error. + */ +static int evutil_parse_servname(const char* servname, const char* protocol, const struct evutil_addrinfo* hints) +{ + int n = parse_numeric_servname(servname); + if (n >= 0) + return n; +#if defined(EVENT__HAVE_GETSERVBYNAME) || defined(_WIN32) + if (!(hints->ai_flags & EVUTIL_AI_NUMERICSERV)) { + struct servent* ent = getservbyname(servname, protocol); + if (ent) { + return ntohs(ent->s_port); + } + } +#endif + return -1; +} + +/* Return a string corresponding to a protocol number that we can pass to + * getservyname. */ +static const char* evutil_unparse_protoname(int proto) +{ + switch (proto) { + case 0: + return NULL; + case IPPROTO_TCP: + return "tcp"; + case IPPROTO_UDP: + return "udp"; +#ifdef IPPROTO_SCTP + case IPPROTO_SCTP: + return "sctp"; +#endif + default: +#ifdef EVENT__HAVE_GETPROTOBYNUMBER + { + struct protoent* ent = getprotobynumber(proto); + if (ent) + return ent->p_name; + } +#endif + return NULL; + } +} + +static void evutil_getaddrinfo_infer_protocols(struct evutil_addrinfo* hints) +{ + /* If we can guess the protocol from the socktype, do so. */ + if (!hints->ai_protocol && hints->ai_socktype) { + if (hints->ai_socktype == SOCK_DGRAM) + hints->ai_protocol = IPPROTO_UDP; + else if (hints->ai_socktype == SOCK_STREAM) + hints->ai_protocol = IPPROTO_TCP; + } + + /* Set the socktype if it isn't set. */ + if (!hints->ai_socktype && hints->ai_protocol) { + if (hints->ai_protocol == IPPROTO_UDP) + hints->ai_socktype = SOCK_DGRAM; + else if (hints->ai_protocol == IPPROTO_TCP) + hints->ai_socktype = SOCK_STREAM; +#ifdef IPPROTO_SCTP + else if (hints->ai_protocol == IPPROTO_SCTP) + hints->ai_socktype = SOCK_STREAM; +#endif + } +} + +#if AF_UNSPEC != PF_UNSPEC +#error "I cannot build on a system where AF_UNSPEC != PF_UNSPEC" +#endif + +/** Implements the part of looking up hosts by name that's common to both + * the blocking and nonblocking resolver: + * - Adjust 'hints' to have a reasonable socktype and protocol. + * - Look up the port based on 'servname', and store it in *portnum, + * - Handle the nodename==NULL case + * - Handle some invalid arguments cases. + * - Handle the cases where nodename is an IPv4 or IPv6 address. + * + * If we need the resolver to look up the hostname, we return + * EVUTIL_EAI_NEED_RESOLVE. Otherwise, we can completely implement + * getaddrinfo: we return 0 or an appropriate EVUTIL_EAI_* error, and + * set *res as getaddrinfo would. + */ +int evutil_getaddrinfo_common_(const char* nodename, const char* servname, struct evutil_addrinfo* hints, struct evutil_addrinfo** res, int* portnum) +{ + int port = 0; + const char* pname; + + if (nodename == NULL && servname == NULL) + return EVUTIL_EAI_NONAME; + + /* We only understand 3 families */ + if (hints->ai_family != PF_UNSPEC && hints->ai_family != PF_INET && hints->ai_family != PF_INET6) + return EVUTIL_EAI_FAMILY; + + evutil_getaddrinfo_infer_protocols(hints); + + /* Look up the port number and protocol, if possible. */ + pname = evutil_unparse_protoname(hints->ai_protocol); + if (servname) { + /* XXXX We could look at the protocol we got back from + * getservbyname, but it doesn't seem too useful. */ + port = evutil_parse_servname(servname, pname, hints); + if (port < 0) { + return EVUTIL_EAI_NONAME; + } + } + + /* If we have no node name, then we're supposed to bind to 'any' and + * connect to localhost. */ + if (nodename == NULL) { + struct evutil_addrinfo *res4 = NULL, *res6 = NULL; + if (hints->ai_family != PF_INET) { /* INET6 or UNSPEC. */ + struct sockaddr_in6 sin6; + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(port); + if (hints->ai_flags & EVUTIL_AI_PASSIVE) { + /* Bind to :: */ + } else { + /* connect to ::1 */ + sin6.sin6_addr.s6_addr[15] = 1; + } + res6 = evutil_new_addrinfo_((struct sockaddr*)&sin6, sizeof(sin6), hints); + if (!res6) + return EVUTIL_EAI_MEMORY; + } + + if (hints->ai_family != PF_INET6) { /* INET or UNSPEC */ + struct sockaddr_in sin; + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + if (hints->ai_flags & EVUTIL_AI_PASSIVE) { + /* Bind to 0.0.0.0 */ + } else { + /* connect to 127.0.0.1 */ + sin.sin_addr.s_addr = htonl(0x7f000001); + } + res4 = evutil_new_addrinfo_((struct sockaddr*)&sin, sizeof(sin), hints); + if (!res4) { + if (res6) + evutil_freeaddrinfo(res6); + return EVUTIL_EAI_MEMORY; + } + } + *res = evutil_addrinfo_append_(res4, res6); + return 0; + } + + /* If we can, we should try to parse the hostname without resolving + * it. */ + /* Try ipv6. */ + if (hints->ai_family == PF_INET6 || hints->ai_family == PF_UNSPEC) { + struct sockaddr_in6 sin6; + memset(&sin6, 0, sizeof(sin6)); + if (1 == evutil_inet_pton(AF_INET6, nodename, &sin6.sin6_addr)) { + /* Got an ipv6 address. */ + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(port); + *res = evutil_new_addrinfo_((struct sockaddr*)&sin6, sizeof(sin6), hints); + if (!*res) + return EVUTIL_EAI_MEMORY; + return 0; + } + } + + /* Try ipv4. */ + if (hints->ai_family == PF_INET || hints->ai_family == PF_UNSPEC) { + struct sockaddr_in sin; + memset(&sin, 0, sizeof(sin)); + if (1 == evutil_inet_pton(AF_INET, nodename, &sin.sin_addr)) { + /* Got an ipv6 address. */ + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + *res = evutil_new_addrinfo_((struct sockaddr*)&sin, sizeof(sin), hints); + if (!*res) + return EVUTIL_EAI_MEMORY; + return 0; + } + } + + /* If we have reached this point, we definitely need to do a DNS + * lookup. */ + if ((hints->ai_flags & EVUTIL_AI_NUMERICHOST)) { + /* If we're not allowed to do one, then say so. */ + return EVUTIL_EAI_NONAME; + } + *portnum = port; + return EVUTIL_EAI_NEED_RESOLVE; +} + +#ifdef EVENT__HAVE_GETADDRINFO +#define USE_NATIVE_GETADDRINFO +#endif + +#ifdef USE_NATIVE_GETADDRINFO +/* A mask of all the flags that we declare, so we can clear them before calling + * the native getaddrinfo */ +static const unsigned int ALL_NONNATIVE_AI_FLAGS = +#ifndef AI_PASSIVE + EVUTIL_AI_PASSIVE | +#endif +#ifndef AI_CANONNAME + EVUTIL_AI_CANONNAME | +#endif +#ifndef AI_NUMERICHOST + EVUTIL_AI_NUMERICHOST | +#endif +#ifndef AI_NUMERICSERV + EVUTIL_AI_NUMERICSERV | +#endif +#ifndef AI_ADDRCONFIG + EVUTIL_AI_ADDRCONFIG | +#endif +#ifndef AI_ALL + EVUTIL_AI_ALL | +#endif +#ifndef AI_V4MAPPED + EVUTIL_AI_V4MAPPED | +#endif + EVUTIL_AI_LIBEVENT_ALLOCATED; + +static const unsigned int ALL_NATIVE_AI_FLAGS = +#ifdef AI_PASSIVE + AI_PASSIVE | +#endif +#ifdef AI_CANONNAME + AI_CANONNAME | +#endif +#ifdef AI_NUMERICHOST + AI_NUMERICHOST | +#endif +#ifdef AI_NUMERICSERV + AI_NUMERICSERV | +#endif +#ifdef AI_ADDRCONFIG + AI_ADDRCONFIG | +#endif +#ifdef AI_ALL + AI_ALL | +#endif +#ifdef AI_V4MAPPED + AI_V4MAPPED | +#endif + 0; +#endif + +#ifndef USE_NATIVE_GETADDRINFO +/* Helper for systems with no getaddrinfo(): make one or more addrinfos out of + * a struct hostent. + */ +static struct evutil_addrinfo* addrinfo_from_hostent(const struct hostent* ent, int port, const struct evutil_addrinfo* hints) +{ + int i; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + struct sockaddr* sa; + int socklen; + struct evutil_addrinfo *res = NULL, *ai; + void* addrp; + + if (ent->h_addrtype == PF_INET) { + memset(&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + sa = (struct sockaddr*)&sin; + socklen = sizeof(struct sockaddr_in); + addrp = &sin.sin_addr; + if (ent->h_length != sizeof(sin.sin_addr)) { + event_warnx("Weird h_length from gethostbyname"); + return NULL; + } + } else if (ent->h_addrtype == PF_INET6) { + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(port); + sa = (struct sockaddr*)&sin6; + socklen = sizeof(struct sockaddr_in6); + addrp = &sin6.sin6_addr; + if (ent->h_length != sizeof(sin6.sin6_addr)) { + event_warnx("Weird h_length from gethostbyname"); + return NULL; + } + } else + return NULL; + + for (i = 0; ent->h_addr_list[i]; ++i) { + memcpy(addrp, ent->h_addr_list[i], ent->h_length); + ai = evutil_new_addrinfo_(sa, socklen, hints); + if (!ai) { + evutil_freeaddrinfo(res); + return NULL; + } + res = evutil_addrinfo_append_(res, ai); + } + + if (res && ((hints->ai_flags & EVUTIL_AI_CANONNAME) && ent->h_name)) { + res->ai_canonname = mm_strdup(ent->h_name); + if (res->ai_canonname == NULL) { + evutil_freeaddrinfo(res); + return NULL; + } + } + + return res; +} +#endif + +/* If the EVUTIL_AI_ADDRCONFIG flag is set on hints->ai_flags, and + * hints->ai_family is PF_UNSPEC, then revise the value of hints->ai_family so + * that we'll only get addresses we could maybe connect to. + */ +void evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo* hints) +{ + if (!(hints->ai_flags & EVUTIL_AI_ADDRCONFIG)) + return; + if (hints->ai_family != PF_UNSPEC) + return; + if (!have_checked_interfaces) + evutil_check_interfaces(0); + if (had_ipv4_address && !had_ipv6_address) { + hints->ai_family = PF_INET; + } else if (!had_ipv4_address && had_ipv6_address) { + hints->ai_family = PF_INET6; + } +} + +#ifdef USE_NATIVE_GETADDRINFO +static int need_numeric_port_hack_ = 0; +static int need_socktype_protocol_hack_ = 0; +static int tested_for_getaddrinfo_hacks = 0; + +/* Some older BSDs (like OpenBSD up to 4.6) used to believe that + giving a numeric port without giving an ai_socktype was verboten. + We test for this so we can apply an appropriate workaround. If it + turns out that the bug is present, then: + + - If nodename==NULL and servname is numeric, we build an answer + ourselves using evutil_getaddrinfo_common_(). + + - If nodename!=NULL and servname is numeric, then we set + servname=NULL when calling getaddrinfo, and post-process the + result to set the ports on it. + + We test for this bug at runtime, since otherwise we can't have the + same binary run on multiple BSD versions. + + - Some versions of Solaris believe that it's nice to leave to protocol + field set to 0. We test for this so we can apply an appropriate + workaround. +*/ +static struct evutil_addrinfo* ai_find_protocol(struct evutil_addrinfo* ai) +{ + while (ai) { + if (ai->ai_protocol) + return ai; + ai = ai->ai_next; + } + return NULL; +} +static void test_for_getaddrinfo_hacks(void) +{ + int r, r2; + struct evutil_addrinfo *ai = NULL, *ai2 = NULL, *ai3 = NULL; + struct evutil_addrinfo hints; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_flags = +#ifdef AI_NUMERICHOST + AI_NUMERICHOST | +#endif +#ifdef AI_NUMERICSERV + AI_NUMERICSERV | +#endif + 0; + r = getaddrinfo("1.2.3.4", "80", &hints, &ai); + getaddrinfo("1.2.3.4", NULL, &hints, &ai3); + hints.ai_socktype = SOCK_STREAM; + r2 = getaddrinfo("1.2.3.4", "80", &hints, &ai2); + if (r2 == 0 && r != 0) { + need_numeric_port_hack_ = 1; + } + if (!ai_find_protocol(ai2) || !ai_find_protocol(ai3)) { + need_socktype_protocol_hack_ = 1; + } + + if (ai) + freeaddrinfo(ai); + if (ai2) + freeaddrinfo(ai2); + if (ai3) + freeaddrinfo(ai3); + tested_for_getaddrinfo_hacks = 1; +} + +static inline int need_numeric_port_hack(void) +{ + if (!tested_for_getaddrinfo_hacks) + test_for_getaddrinfo_hacks(); + return need_numeric_port_hack_; +} + +static inline int need_socktype_protocol_hack(void) +{ + if (!tested_for_getaddrinfo_hacks) + test_for_getaddrinfo_hacks(); + return need_socktype_protocol_hack_; +} + +static void apply_numeric_port_hack(int port, struct evutil_addrinfo** ai) +{ + /* Now we run through the list and set the ports on all of the + * results where ports would make sense. */ + for (; *ai; ai = &(*ai)->ai_next) { + struct sockaddr* sa = (*ai)->ai_addr; + if (sa && sa->sa_family == AF_INET) { + struct sockaddr_in* sin = (struct sockaddr_in*)sa; + sin->sin_port = htons(port); + } else if (sa && sa->sa_family == AF_INET6) { + struct sockaddr_in6* sin6 = (struct sockaddr_in6*)sa; + sin6->sin6_port = htons(port); + } else { + /* A numeric port makes no sense here; remove this one + * from the list. */ + struct evutil_addrinfo* victim = *ai; + *ai = victim->ai_next; + victim->ai_next = NULL; + freeaddrinfo(victim); + } + } +} + +static int apply_socktype_protocol_hack(struct evutil_addrinfo* ai) +{ + struct evutil_addrinfo* ai_new; + for (; ai; ai = ai->ai_next) { + evutil_getaddrinfo_infer_protocols(ai); + if (ai->ai_socktype || ai->ai_protocol) + continue; + ai_new = mm_malloc(sizeof(*ai_new)); + if (!ai_new) + return -1; + memcpy(ai_new, ai, sizeof(*ai_new)); + ai->ai_socktype = SOCK_STREAM; + ai->ai_protocol = IPPROTO_TCP; + ai_new->ai_socktype = SOCK_DGRAM; + ai_new->ai_protocol = IPPROTO_UDP; + + ai_new->ai_next = ai->ai_next; + ai->ai_next = ai_new; + } + return 0; +} +#endif + +int evutil_getaddrinfo(const char* nodename, const char* servname, const struct evutil_addrinfo* hints_in, struct evutil_addrinfo** res) +{ +#ifdef USE_NATIVE_GETADDRINFO + struct evutil_addrinfo hints; + int portnum = -1, need_np_hack, err; + + if (hints_in) { + memcpy(&hints, hints_in, sizeof(hints)); + } else { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + } + +#ifndef AI_ADDRCONFIG + /* Not every system has AI_ADDRCONFIG, so fake it. */ + if (hints.ai_family == PF_UNSPEC && (hints.ai_flags & EVUTIL_AI_ADDRCONFIG)) { + evutil_adjust_hints_for_addrconfig_(&hints); + } +#endif + +#ifndef AI_NUMERICSERV + /* Not every system has AI_NUMERICSERV, so fake it. */ + if (hints.ai_flags & EVUTIL_AI_NUMERICSERV) { + if (servname && parse_numeric_servname(servname) < 0) + return EVUTIL_EAI_NONAME; + } +#endif + + /* Enough operating systems handle enough common non-resolve + * cases here weirdly enough that we are better off just + * overriding them. For example: + * + * - Windows doesn't like to infer the protocol from the + * socket type, or fill in socket or protocol types much at + * all. It also seems to do its own broken implicit + * always-on version of AI_ADDRCONFIG that keeps it from + * ever resolving even a literal IPv6 address when + * ai_addrtype is PF_UNSPEC. + */ +#ifdef _WIN32 + { + int tmp_port; + err = evutil_getaddrinfo_common_(nodename, servname, &hints, res, &tmp_port); + if (err == 0 || err == EVUTIL_EAI_MEMORY || err == EVUTIL_EAI_NONAME) + return err; + /* If we make it here, the system getaddrinfo can + * have a crack at it. */ + } +#endif + + /* See documentation for need_numeric_port_hack above.*/ + need_np_hack = need_numeric_port_hack() && servname && !hints.ai_socktype && ((portnum = parse_numeric_servname(servname)) >= 0); + if (need_np_hack) { + if (!nodename) + return evutil_getaddrinfo_common_(NULL, servname, &hints, res, &portnum); + servname = NULL; + } + + if (need_socktype_protocol_hack()) { + evutil_getaddrinfo_infer_protocols(&hints); + } + + /* Make sure that we didn't actually steal any AI_FLAGS values that + * the system is using. (This is a constant expression, and should ge + * optimized out.) + * + * XXXX Turn this into a compile-time failure rather than a run-time + * failure. + */ + EVUTIL_ASSERT((ALL_NONNATIVE_AI_FLAGS & ALL_NATIVE_AI_FLAGS) == 0); + + /* Clear any flags that only libevent understands. */ + hints.ai_flags &= ~ALL_NONNATIVE_AI_FLAGS; + + err = getaddrinfo(nodename, servname, &hints, res); + if (need_np_hack) + apply_numeric_port_hack(portnum, res); + + if (need_socktype_protocol_hack()) { + if (apply_socktype_protocol_hack(*res) < 0) { + evutil_freeaddrinfo(*res); + *res = NULL; + return EVUTIL_EAI_MEMORY; + } + } + return err; +#else + int port = 0, err; + struct hostent* ent = NULL; + struct evutil_addrinfo hints; + + if (hints_in) { + memcpy(&hints, hints_in, sizeof(hints)); + } else { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + } + + evutil_adjust_hints_for_addrconfig_(&hints); + + err = evutil_getaddrinfo_common_(nodename, servname, &hints, res, &port); + if (err != EVUTIL_EAI_NEED_RESOLVE) { + /* We either succeeded or failed. No need to continue */ + return err; + } + + err = 0; + /* Use any of the various gethostbyname_r variants as available. */ + { +#ifdef EVENT__HAVE_GETHOSTBYNAME_R_6_ARG + /* This one is what glibc provides. */ + char buf[2048]; + struct hostent hostent; + int r; + r = gethostbyname_r(nodename, &hostent, buf, sizeof(buf), &ent, &err); +#elif defined(EVENT__HAVE_GETHOSTBYNAME_R_5_ARG) + char buf[2048]; + struct hostent hostent; + ent = gethostbyname_r(nodename, &hostent, buf, sizeof(buf), &err); +#elif defined(EVENT__HAVE_GETHOSTBYNAME_R_3_ARG) + struct hostent_data data; + struct hostent hostent; + memset(&data, 0, sizeof(data)); + err = gethostbyname_r(nodename, &hostent, &data); + ent = err ? NULL : &hostent; +#else + /* fall back to gethostbyname. */ + /* XXXX This needs a lock everywhere but Windows. */ + ent = gethostbyname(nodename); +#ifdef _WIN32 + err = WSAGetLastError(); +#else + err = h_errno; +#endif +#endif + + /* Now we have either ent or err set. */ + if (!ent) { + /* XXX is this right for windows ? */ + switch (err) { + case TRY_AGAIN: + return EVUTIL_EAI_AGAIN; + case NO_RECOVERY: + default: + return EVUTIL_EAI_FAIL; + case HOST_NOT_FOUND: + return EVUTIL_EAI_NONAME; + case NO_ADDRESS: +#if NO_DATA != NO_ADDRESS + case NO_DATA: +#endif + return EVUTIL_EAI_NODATA; + } + } + + if (ent->h_addrtype != hints.ai_family && hints.ai_family != PF_UNSPEC) { + /* This wasn't the type we were hoping for. Too bad + * we never had a chance to ask gethostbyname for what + * we wanted. */ + return EVUTIL_EAI_NONAME; + } + + /* Make sure we got _some_ answers. */ + if (ent->h_length == 0) + return EVUTIL_EAI_NODATA; + + /* If we got an address type we don't know how to make a + sockaddr for, give up. */ + if (ent->h_addrtype != PF_INET && ent->h_addrtype != PF_INET6) + return EVUTIL_EAI_FAMILY; + + *res = addrinfo_from_hostent(ent, port, &hints); + if (!*res) + return EVUTIL_EAI_MEMORY; + } + + return 0; +#endif +} + +void evutil_freeaddrinfo(struct evutil_addrinfo* ai) +{ +#ifdef EVENT__HAVE_GETADDRINFO + if (!(ai->ai_flags & EVUTIL_AI_LIBEVENT_ALLOCATED)) { + freeaddrinfo(ai); + return; + } +#endif + while (ai) { + struct evutil_addrinfo* next = ai->ai_next; + if (ai->ai_canonname) + mm_free(ai->ai_canonname); + mm_free(ai); + ai = next; + } +} + +static evdns_getaddrinfo_fn evdns_getaddrinfo_impl = NULL; +static evdns_getaddrinfo_cancel_fn evdns_getaddrinfo_cancel_impl = NULL; + +void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn) +{ + if (!evdns_getaddrinfo_impl) + evdns_getaddrinfo_impl = fn; +} +void evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn) +{ + if (!evdns_getaddrinfo_cancel_impl) + evdns_getaddrinfo_cancel_impl = fn; +} + +/* Internal helper function: act like evdns_getaddrinfo if dns_base is set; + * otherwise do a blocking resolve and pass the result to the callback in the + * way that evdns_getaddrinfo would. + */ +struct evdns_getaddrinfo_request* evutil_getaddrinfo_async_( + struct evdns_base* dns_base, + const char* nodename, + const char* servname, + const struct evutil_addrinfo* hints_in, + void (*cb)(int, struct evutil_addrinfo*, void*), + void* arg) +{ + if (dns_base && evdns_getaddrinfo_impl) { + return evdns_getaddrinfo_impl(dns_base, nodename, servname, hints_in, cb, arg); + } else { + struct evutil_addrinfo* ai = NULL; + int err; + err = evutil_getaddrinfo(nodename, servname, hints_in, &ai); + cb(err, ai, arg); + return NULL; + } +} + +void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request* data) +{ + if (evdns_getaddrinfo_cancel_impl && data) { + evdns_getaddrinfo_cancel_impl(data); + } +} + +const char* evutil_gai_strerror(int err) +{ + /* As a sneaky side-benefit, this case statement will get most + * compilers to tell us if any of the error codes we defined + * conflict with the platform's native error codes. */ + switch (err) { + case EVUTIL_EAI_CANCEL: + return "Request canceled"; + case 0: + return "No error"; + + case EVUTIL_EAI_ADDRFAMILY: + return "address family for nodename not supported"; + case EVUTIL_EAI_AGAIN: + return "temporary failure in name resolution"; + case EVUTIL_EAI_BADFLAGS: + return "invalid value for ai_flags"; + case EVUTIL_EAI_FAIL: + return "non-recoverable failure in name resolution"; + case EVUTIL_EAI_FAMILY: + return "ai_family not supported"; + case EVUTIL_EAI_MEMORY: + return "memory allocation failure"; + case EVUTIL_EAI_NODATA: + return "no address associated with nodename"; + case EVUTIL_EAI_NONAME: + return "nodename nor servname provided, or not known"; + case EVUTIL_EAI_SERVICE: + return "servname not supported for ai_socktype"; + case EVUTIL_EAI_SOCKTYPE: + return "ai_socktype not supported"; + case EVUTIL_EAI_SYSTEM: + return "system error"; + default: +#if defined(USE_NATIVE_GETADDRINFO) && defined(_WIN32) + return gai_strerrorA(err); +#elif defined(USE_NATIVE_GETADDRINFO) + return gai_strerror(err); +#else + return "Unknown error code"; +#endif + } +} + +#ifdef _WIN32 +/* destructively remove a trailing line terminator from s */ +static void chomp(char* s) +{ + size_t len; + if (s && (len = strlen(s)) > 0 && s[len - 1] == '\n') { + s[--len] = 0; + if (len > 0 && s[len - 1] == '\r') + s[--len] = 0; + } +} + +/* FormatMessage returns allocated strings, but evutil_socket_error_to_string + * is supposed to return a string which is good indefinitely without having + * to be freed. To make this work without leaking memory, we cache the + * string the first time FormatMessage is called on a particular error + * code, and then return the cached string on subsequent calls with the + * same code. The strings aren't freed until libevent_global_shutdown + * (or never). We use a linked list to cache the errors, because we + * only expect there to be a few dozen, and that should be fast enough. + */ + +struct cached_sock_errs_entry { + HT_ENTRY(cached_sock_errs_entry) node; + DWORD code; + char* msg; /* allocated with LocalAlloc; free with LocalFree */ +}; + +static inline unsigned hash_cached_sock_errs(const struct cached_sock_errs_entry* e) +{ + /* Use Murmur3's 32-bit finalizer as an integer hash function */ + DWORD h = e->code; + h ^= h >> 16; + h *= 0x85ebca6b; + h ^= h >> 13; + h *= 0xc2b2ae35; + h ^= h >> 16; + return h; +} + +static inline int eq_cached_sock_errs(const struct cached_sock_errs_entry* a, const struct cached_sock_errs_entry* b) +{ + return a->code == b->code; +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +static void* windows_socket_errors_lock_ = NULL; +#endif + +static HT_HEAD(cached_sock_errs_map, cached_sock_errs_entry) windows_socket_errors = HT_INITIALIZER(); + +HT_PROTOTYPE(cached_sock_errs_map, cached_sock_errs_entry, node, hash_cached_sock_errs, eq_cached_sock_errs); + +HT_GENERATE(cached_sock_errs_map, cached_sock_errs_entry, node, hash_cached_sock_errs, eq_cached_sock_errs, 0.5, mm_malloc, mm_realloc, mm_free); + +/** Equivalent to strerror, but for windows socket errors. */ +const char* evutil_socket_error_to_string(int errcode) +{ + struct cached_sock_errs_entry *errs, *newerr, find; + char* msg = NULL; + + EVLOCK_LOCK(windows_socket_errors_lock_, 0); + + find.code = errcode; + errs = HT_FIND(cached_sock_errs_map, &windows_socket_errors, &find); + if (errs) { + msg = errs->msg; + goto done; + } + + if (0 + != FormatMessageA( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, errcode, 0, (char*)&msg, 0, NULL)) + chomp(msg); /* because message has trailing newline */ + else { + size_t len = 50; + /* use LocalAlloc because FormatMessage does */ + msg = LocalAlloc(LMEM_FIXED, len); + if (!msg) { + msg = (char*)"LocalAlloc failed during Winsock error"; + goto done; + } + evutil_snprintf(msg, len, "winsock error 0x%08x", errcode); + } + + newerr = (struct cached_sock_errs_entry*)mm_malloc(sizeof(struct cached_sock_errs_entry)); + + if (!newerr) { + LocalFree(msg); + msg = (char*)"malloc failed during Winsock error"; + goto done; + } + + newerr->code = errcode; + newerr->msg = msg; + HT_INSERT(cached_sock_errs_map, &windows_socket_errors, newerr); + +done: + EVLOCK_UNLOCK(windows_socket_errors_lock_, 0); + + return msg; +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +int evutil_global_setup_locks_(const int enable_locks) +{ + EVTHREAD_SETUP_GLOBAL_LOCK(windows_socket_errors_lock_, 0); + return 0; +} +#endif + +static void evutil_free_sock_err_globals(void) +{ + struct cached_sock_errs_entry **errs, *tofree; + + for (errs = HT_START(cached_sock_errs_map, &windows_socket_errors); errs;) { + tofree = *errs; + errs = HT_NEXT_RMV(cached_sock_errs_map, &windows_socket_errors, errs); + LocalFree(tofree->msg); + mm_free(tofree); + } + + HT_CLEAR(cached_sock_errs_map, &windows_socket_errors); + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (windows_socket_errors_lock_ != NULL) { + EVTHREAD_FREE_LOCK(windows_socket_errors_lock_, 0); + windows_socket_errors_lock_ = NULL; + } +#endif +} + +#else + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +int evutil_global_setup_locks_(const int enable_locks) +{ + return 0; +} +#endif + +static void evutil_free_sock_err_globals(void) +{ +} + +#endif + +int evutil_snprintf(char* buf, size_t buflen, const char* format, ...) +{ + int r; + va_list ap; + va_start(ap, format); + r = evutil_vsnprintf(buf, buflen, format, ap); + va_end(ap); + return r; +} + +int evutil_vsnprintf(char* buf, size_t buflen, const char* format, va_list ap) +{ + int r; + if (!buflen) + return 0; +#if defined(_MSC_VER) || defined(_WIN32) + r = _vsnprintf(buf, buflen, format, ap); + if (r < 0) + r = _vscprintf(format, ap); +#elif defined(sgi) + /* Make sure we always use the correct vsnprintf on IRIX */ + extern int _xpg5_vsnprintf(char* __restrict, __SGI_LIBC_NAMESPACE_QUALIFIER size_t, const char* __restrict, /* va_list */ char*); + + r = _xpg5_vsnprintf(buf, buflen, format, ap); +#else + r = vsnprintf(buf, buflen, format, ap); +#endif + buf[buflen - 1] = '\0'; + return r; +} + +#define USE_INTERNAL_NTOP +#define USE_INTERNAL_PTON + +const char* evutil_inet_ntop(int af, const void* src, char* dst, size_t len) +{ +#if defined(EVENT__HAVE_INET_NTOP) && !defined(USE_INTERNAL_NTOP) + return inet_ntop(af, src, dst, len); +#else + if (af == AF_INET) { + const struct in_addr* in = src; + const ev_uint32_t a = ntohl(in->s_addr); + int r; + r = evutil_snprintf( + dst, len, "%d.%d.%d.%d", (int)(ev_uint8_t)((a >> 24) & 0xff), (int)(ev_uint8_t)((a >> 16) & 0xff), (int)(ev_uint8_t)((a >> 8) & 0xff), + (int)(ev_uint8_t)((a)&0xff)); + if (r < 0 || (size_t)r >= len) + return NULL; + else + return dst; +#ifdef AF_INET6 + } else if (af == AF_INET6) { + const struct in6_addr* addr = src; + char buf[64], *cp; + int longestGapLen = 0, longestGapPos = -1, i, curGapPos = -1, curGapLen = 0; + ev_uint16_t words[8]; + for (i = 0; i < 8; ++i) { + words[i] = (((ev_uint16_t)addr->s6_addr[2 * i]) << 8) + addr->s6_addr[2 * i + 1]; + } + if (words[0] == 0 && words[1] == 0 && words[2] == 0 && words[3] == 0 && words[4] == 0 + && ((words[5] == 0 && words[6] && words[7]) || (words[5] == 0xffff))) { + /* This is an IPv4 address. */ + if (words[5] == 0) { + evutil_snprintf(buf, sizeof(buf), "::%d.%d.%d.%d", addr->s6_addr[12], addr->s6_addr[13], addr->s6_addr[14], addr->s6_addr[15]); + } else { + evutil_snprintf( + buf, sizeof(buf), "::%x:%d.%d.%d.%d", words[5], addr->s6_addr[12], addr->s6_addr[13], addr->s6_addr[14], addr->s6_addr[15]); + } + if (strlen(buf) > len) + return NULL; + strlcpy(dst, buf, len); + return dst; + } + i = 0; + while (i < 8) { + if (words[i] == 0) { + curGapPos = i++; + curGapLen = 1; + while (i < 8 && words[i] == 0) { + ++i; + ++curGapLen; + } + if (curGapLen > longestGapLen) { + longestGapPos = curGapPos; + longestGapLen = curGapLen; + } + } else { + ++i; + } + } + if (longestGapLen <= 1) + longestGapPos = -1; + + cp = buf; + for (i = 0; i < 8; ++i) { + if (words[i] == 0 && longestGapPos == i) { + if (i == 0) + *cp++ = ':'; + *cp++ = ':'; + while (i < 8 && words[i] == 0) + ++i; + --i; /* to compensate for loop increment. */ + } else { + evutil_snprintf(cp, sizeof(buf) - (cp - buf), "%x", (unsigned)words[i]); + cp += strlen(cp); + if (i != 7) + *cp++ = ':'; + } + } + *cp = '\0'; + if (strlen(buf) > len) + return NULL; + strlcpy(dst, buf, len); + return dst; +#endif + } else { + return NULL; + } +#endif +} + +int evutil_inet_pton(int af, const char* src, void* dst) +{ +#if defined(EVENT__HAVE_INET_PTON) && !defined(USE_INTERNAL_PTON) + return inet_pton(af, src, dst); +#else + if (af == AF_INET) { + unsigned a, b, c, d; + char more; + struct in_addr* addr = dst; + if (sscanf(src, "%u.%u.%u.%u%c", &a, &b, &c, &d, &more) != 4) + return 0; + if (a > 255) + return 0; + if (b > 255) + return 0; + if (c > 255) + return 0; + if (d > 255) + return 0; + addr->s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d); + return 1; +#ifdef AF_INET6 + } else if (af == AF_INET6) { + struct in6_addr* out = dst; + ev_uint16_t words[8]; + int gapPos = -1, i, setWords = 0; + const char* dot = strchr(src, '.'); + const char* eow; /* end of words. */ + if (dot == src) + return 0; + else if (!dot) + eow = src + strlen(src); + else { + unsigned byte1, byte2, byte3, byte4; + char more; + for (eow = dot - 1; eow >= src && EVUTIL_ISDIGIT_(*eow); --eow) + ; + ++eow; + + /* We use "scanf" because some platform inet_aton()s are too lax + * about IPv4 addresses of the form "1.2.3" */ + if (sscanf(eow, "%u.%u.%u.%u%c", &byte1, &byte2, &byte3, &byte4, &more) != 4) + return 0; + + if (byte1 > 255 || byte2 > 255 || byte3 > 255 || byte4 > 255) + return 0; + + words[6] = (byte1 << 8) | byte2; + words[7] = (byte3 << 8) | byte4; + setWords += 2; + } + + i = 0; + while (src < eow) { + if (i > 7) + return 0; + if (EVUTIL_ISXDIGIT_(*src)) { + char* next; + long r = strtol(src, &next, 16); + if (next > 4 + src) + return 0; + if (next == src) + return 0; + if (r < 0 || r > 65536) + return 0; + + words[i++] = (ev_uint16_t)r; + setWords++; + src = next; + if (*src != ':' && src != eow) + return 0; + ++src; + } else if (*src == ':' && i > 0 && gapPos == -1) { + gapPos = i; + ++src; + } else if (*src == ':' && i == 0 && src[1] == ':' && gapPos == -1) { + gapPos = i; + src += 2; + } else { + return 0; + } + } + + if (setWords > 8 || (setWords == 8 && gapPos != -1) || (setWords < 8 && gapPos == -1)) + return 0; + + if (gapPos >= 0) { + int nToMove = setWords - (dot ? 2 : 0) - gapPos; + int gapLen = 8 - setWords; + /* assert(nToMove >= 0); */ + if (nToMove < 0) + return -1; /* should be impossible */ + memmove(&words[gapPos + gapLen], &words[gapPos], sizeof(ev_uint16_t) * nToMove); + memset(&words[gapPos], 0, sizeof(ev_uint16_t) * gapLen); + } + for (i = 0; i < 8; ++i) { + out->s6_addr[2 * i] = words[i] >> 8; + out->s6_addr[2 * i + 1] = words[i] & 0xff; + } + + return 1; +#endif + } else { + return -1; + } +#endif +} + +int evutil_parse_sockaddr_port(const char* ip_as_string, struct sockaddr* out, int* outlen) +{ + int port; + char buf[128]; + const char *cp, *addr_part, *port_part; + int is_ipv6; + /* recognized formats are: + * [ipv6]:port + * ipv6 + * [ipv6] + * ipv4:port + * ipv4 + */ + + cp = strchr(ip_as_string, ':'); + if (*ip_as_string == '[') { + size_t len; + if (!(cp = strchr(ip_as_string, ']'))) { + return -1; + } + len = (cp - (ip_as_string + 1)); + if (len > sizeof(buf) - 1) { + return -1; + } + memcpy(buf, ip_as_string + 1, len); + buf[len] = '\0'; + addr_part = buf; + if (cp[1] == ':') + port_part = cp + 2; + else + port_part = NULL; + is_ipv6 = 1; + } else if (cp && strchr(cp + 1, ':')) { + is_ipv6 = 1; + addr_part = ip_as_string; + port_part = NULL; + } else if (cp) { + is_ipv6 = 0; + if (cp - ip_as_string > (int)sizeof(buf) - 1) { + return -1; + } + memcpy(buf, ip_as_string, cp - ip_as_string); + buf[cp - ip_as_string] = '\0'; + addr_part = buf; + port_part = cp + 1; + } else { + addr_part = ip_as_string; + port_part = NULL; + is_ipv6 = 0; + } + + if (port_part == NULL) { + port = 0; + } else { + port = atoi(port_part); + if (port <= 0 || port > 65535) { + return -1; + } + } + + if (!addr_part) + return -1; /* Should be impossible. */ +#ifdef AF_INET6 + if (is_ipv6) { + struct sockaddr_in6 sin6; + memset(&sin6, 0, sizeof(sin6)); +#ifdef EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN + sin6.sin6_len = sizeof(sin6); +#endif + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(port); + if (1 != evutil_inet_pton(AF_INET6, addr_part, &sin6.sin6_addr)) + return -1; + if ((int)sizeof(sin6) > *outlen) + return -1; + memset(out, 0, *outlen); + memcpy(out, &sin6, sizeof(sin6)); + *outlen = sizeof(sin6); + return 0; + } else +#endif + { + struct sockaddr_in sin; + memset(&sin, 0, sizeof(sin)); +#ifdef EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN + sin.sin_len = sizeof(sin); +#endif + sin.sin_family = AF_INET; + sin.sin_port = htons(port); + if (1 != evutil_inet_pton(AF_INET, addr_part, &sin.sin_addr)) + return -1; + if ((int)sizeof(sin) > *outlen) + return -1; + memset(out, 0, *outlen); + memcpy(out, &sin, sizeof(sin)); + *outlen = sizeof(sin); + return 0; + } +} + +const char* evutil_format_sockaddr_port_(const struct sockaddr* sa, char* out, size_t outlen) +{ + char b[128]; + const char* res = NULL; + int port; + if (sa->sa_family == AF_INET) { + const struct sockaddr_in* sin = (const struct sockaddr_in*)sa; + res = evutil_inet_ntop(AF_INET, &sin->sin_addr, b, sizeof(b)); + port = ntohs(sin->sin_port); + if (res) { + evutil_snprintf(out, outlen, "%s:%d", b, port); + return out; + } + } else if (sa->sa_family == AF_INET6) { + const struct sockaddr_in6* sin6 = (const struct sockaddr_in6*)sa; + res = evutil_inet_ntop(AF_INET6, &sin6->sin6_addr, b, sizeof(b)); + port = ntohs(sin6->sin6_port); + if (res) { + evutil_snprintf(out, outlen, "[%s]:%d", b, port); + return out; + } + } + + evutil_snprintf(out, outlen, "", (int)sa->sa_family); + return out; +} + +int evutil_sockaddr_cmp(const struct sockaddr* sa1, const struct sockaddr* sa2, int include_port) +{ + int r; + if (0 != (r = (sa1->sa_family - sa2->sa_family))) + return r; + + if (sa1->sa_family == AF_INET) { + const struct sockaddr_in *sin1, *sin2; + sin1 = (const struct sockaddr_in*)sa1; + sin2 = (const struct sockaddr_in*)sa2; + if (sin1->sin_addr.s_addr < sin2->sin_addr.s_addr) + return -1; + else if (sin1->sin_addr.s_addr > sin2->sin_addr.s_addr) + return 1; + else if (include_port && (r = ((int)sin1->sin_port - (int)sin2->sin_port))) + return r; + else + return 0; + } +#ifdef AF_INET6 + else if (sa1->sa_family == AF_INET6) { + const struct sockaddr_in6 *sin1, *sin2; + sin1 = (const struct sockaddr_in6*)sa1; + sin2 = (const struct sockaddr_in6*)sa2; + if ((r = memcmp(sin1->sin6_addr.s6_addr, sin2->sin6_addr.s6_addr, 16))) + return r; + else if (include_port && (r = ((int)sin1->sin6_port - (int)sin2->sin6_port))) + return r; + else + return 0; + } +#endif + return 1; +} + +/* Tables to implement ctypes-replacement EVUTIL_IS*() functions. Each table + * has 256 bits to look up whether a character is in some set or not. This + * fails on non-ASCII platforms, but so does every other place where we + * take a char and write it onto the network. + **/ +static const ev_uint32_t EVUTIL_ISALPHA_TABLE[8] = {0, 0, 0x7fffffe, 0x7fffffe, 0, 0, 0, 0}; +static const ev_uint32_t EVUTIL_ISALNUM_TABLE[8] = {0, 0x3ff0000, 0x7fffffe, 0x7fffffe, 0, 0, 0, 0}; +static const ev_uint32_t EVUTIL_ISSPACE_TABLE[8] = {0x3e00, 0x1, 0, 0, 0, 0, 0, 0}; +static const ev_uint32_t EVUTIL_ISXDIGIT_TABLE[8] = {0, 0x3ff0000, 0x7e, 0x7e, 0, 0, 0, 0}; +static const ev_uint32_t EVUTIL_ISDIGIT_TABLE[8] = {0, 0x3ff0000, 0, 0, 0, 0, 0, 0}; +static const ev_uint32_t EVUTIL_ISPRINT_TABLE[8] = {0, 0xffffffff, 0xffffffff, 0x7fffffff, 0, 0, 0, 0x0}; +static const ev_uint32_t EVUTIL_ISUPPER_TABLE[8] = {0, 0, 0x7fffffe, 0, 0, 0, 0, 0}; +static const ev_uint32_t EVUTIL_ISLOWER_TABLE[8] = {0, 0, 0, 0x7fffffe, 0, 0, 0, 0}; +/* Upper-casing and lowercasing tables to map characters to upper/lowercase + * equivalents. */ +static const unsigned char EVUTIL_TOUPPER_TABLE[256] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, + 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, + 84, 85, 86, 87, 88, 89, 90, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, + 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, + 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, +}; +static const unsigned char EVUTIL_TOLOWER_TABLE[256] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, + 119, 120, 121, 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, + 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, + 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, + 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, +}; + +#define IMPL_CTYPE_FN(name) \ + int EVUTIL_##name##_(char c) \ + { \ + ev_uint8_t u = c; \ + return !!(EVUTIL_##name##_TABLE[(u >> 5) & 7] & (1 << (u & 31))); \ + } +IMPL_CTYPE_FN(ISALPHA) +IMPL_CTYPE_FN(ISALNUM) +IMPL_CTYPE_FN(ISSPACE) +IMPL_CTYPE_FN(ISDIGIT) +IMPL_CTYPE_FN(ISXDIGIT) +IMPL_CTYPE_FN(ISPRINT) +IMPL_CTYPE_FN(ISLOWER) +IMPL_CTYPE_FN(ISUPPER) + +char EVUTIL_TOLOWER_(char c) +{ + return ((char)EVUTIL_TOLOWER_TABLE[(ev_uint8_t)c]); +} +char EVUTIL_TOUPPER_(char c) +{ + return ((char)EVUTIL_TOUPPER_TABLE[(ev_uint8_t)c]); +} +int evutil_ascii_strcasecmp(const char* s1, const char* s2) +{ + char c1, c2; + while (1) { + c1 = EVUTIL_TOLOWER_(*s1++); + c2 = EVUTIL_TOLOWER_(*s2++); + if (c1 < c2) + return -1; + else if (c1 > c2) + return 1; + else if (c1 == 0) + return 0; + } +} +int evutil_ascii_strncasecmp(const char* s1, const char* s2, size_t n) +{ + char c1, c2; + while (n--) { + c1 = EVUTIL_TOLOWER_(*s1++); + c2 = EVUTIL_TOLOWER_(*s2++); + if (c1 < c2) + return -1; + else if (c1 > c2) + return 1; + else if (c1 == 0) + return 0; + } + return 0; +} + +void evutil_rtrim_lws_(char* str) +{ + char* cp; + + if (str == NULL) + return; + + if ((cp = strchr(str, '\0')) == NULL || (cp == str)) + return; + + --cp; + + while (*cp == ' ' || *cp == '\t') { + *cp = '\0'; + if (cp == str) + break; + --cp; + } +} + +static int evutil_issetugid(void) +{ +#ifdef EVENT__HAVE_ISSETUGID + return issetugid(); +#else + +#ifdef EVENT__HAVE_GETEUID + if (getuid() != geteuid()) + return 1; +#endif +#ifdef EVENT__HAVE_GETEGID + if (getgid() != getegid()) + return 1; +#endif + return 0; +#endif +} + +const char* evutil_getenv_(const char* varname) +{ + if (evutil_issetugid()) + return NULL; + + return getenv(varname); +} + +ev_uint32_t evutil_weakrand_seed_(struct evutil_weakrand_state* state, ev_uint32_t seed) +{ + if (seed == 0) { + struct timeval tv; + evutil_gettimeofday(&tv, NULL); + seed = (ev_uint32_t)tv.tv_sec + (ev_uint32_t)tv.tv_usec; +#ifdef _WIN32 + seed += (ev_uint32_t)_getpid(); +#else + seed += (ev_uint32_t)getpid(); +#endif + } + state->seed = seed; + return seed; +} + +ev_int32_t evutil_weakrand_(struct evutil_weakrand_state* state) +{ + /* This RNG implementation is a linear congruential generator, with + * modulus 2^31, multiplier 1103515245, and addend 12345. It's also + * used by OpenBSD, and by Glibc's TYPE_0 RNG. + * + * The linear congruential generator is not an industrial-strength + * RNG! It's fast, but it can have higher-order patterns. Notably, + * the low bits tend to have periodicity. + */ + state->seed = ((state->seed) * 1103515245 + 12345) & 0x7fffffff; + return (ev_int32_t)(state->seed); +} + +ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state* state, ev_int32_t top) +{ + ev_int32_t divisor, result; + + /* We can't just do weakrand() % top, since the low bits of the LCG + * are less random than the high ones. (Specifically, since the LCG + * modulus is 2^N, every 2^m for m= top); + return result; +} + +/** + * Volatile pointer to memset: we use this to keep the compiler from + * eliminating our call to memset. + */ +void* (*volatile evutil_memset_volatile_)(void*, int, size_t) = memset; + +void evutil_memclear_(void* mem, size_t len) +{ + evutil_memset_volatile_(mem, 0, len); +} + +int evutil_sockaddr_is_loopback_(const struct sockaddr* addr) +{ + static const char LOOPBACK_S6[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1"; + if (addr->sa_family == AF_INET) { + struct sockaddr_in* sin = (struct sockaddr_in*)addr; + return (ntohl(sin->sin_addr.s_addr) & 0xff000000) == 0x7f000000; + } else if (addr->sa_family == AF_INET6) { + struct sockaddr_in6* sin6 = (struct sockaddr_in6*)addr; + return !memcmp(sin6->sin6_addr.s6_addr, LOOPBACK_S6, 16); + } + return 0; +} + +int evutil_hex_char_to_int_(char c) +{ + switch (c) { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'A': + case 'a': + return 10; + case 'B': + case 'b': + return 11; + case 'C': + case 'c': + return 12; + case 'D': + case 'd': + return 13; + case 'E': + case 'e': + return 14; + case 'F': + case 'f': + return 15; + } + return -1; +} + +#ifdef _WIN32 +HMODULE +evutil_load_windows_system_library_(const TCHAR* library_name) +{ + TCHAR path[MAX_PATH]; + unsigned n; + n = GetSystemDirectory(path, MAX_PATH); + if (n == 0 || n + _tcslen(library_name) + 2 >= MAX_PATH) + return 0; + _tcscat(path, TEXT("\\")); + _tcscat(path, library_name); + return LoadLibrary(path); +} +#endif + +/* Internal wrapper around 'socket' to provide Linux-style support for + * syscall-saving methods where available. + * + * In addition to regular socket behavior, you can use a bitwise or to set the + * flags EVUTIL_SOCK_NONBLOCK and EVUTIL_SOCK_CLOEXEC in the 'type' argument, + * to make the socket nonblocking or close-on-exec with as few syscalls as + * possible. + */ +evutil_socket_t evutil_socket_(int domain, int type, int protocol) +{ + evutil_socket_t r; +#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC) + r = socket(domain, type, protocol); + if (r >= 0) + return r; + else if ((type & (SOCK_NONBLOCK | SOCK_CLOEXEC)) == 0) + return -1; +#endif +#define SOCKET_TYPE_MASK (~(EVUTIL_SOCK_NONBLOCK | EVUTIL_SOCK_CLOEXEC)) + r = socket(domain, type & SOCKET_TYPE_MASK, protocol); + if (r < 0) + return -1; + if (type & EVUTIL_SOCK_NONBLOCK) { + if (evutil_fast_socket_nonblocking(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + if (type & EVUTIL_SOCK_CLOEXEC) { + if (evutil_fast_socket_closeonexec(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + return r; +} + +/* Internal wrapper around 'accept' or 'accept4' to provide Linux-style + * support for syscall-saving methods where available. + * + * In addition to regular accept behavior, you can set one or more of flags + * EVUTIL_SOCK_NONBLOCK and EVUTIL_SOCK_CLOEXEC in the 'flags' argument, to + * make the socket nonblocking or close-on-exec with as few syscalls as + * possible. + */ +evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr* addr, ev_socklen_t* addrlen, int flags) +{ + evutil_socket_t result; +#if defined(EVENT__HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) && defined(SOCK_NONBLOCK) + result = accept4(sockfd, addr, addrlen, flags); + if (result >= 0 || (errno != EINVAL && errno != ENOSYS)) { + /* A nonnegative result means that we succeeded, so return. + * Failing with EINVAL means that an option wasn't supported, + * and failing with ENOSYS means that the syscall wasn't + * there: in those cases we want to fall back. Otherwise, we + * got a real error, and we should return. */ + return result; + } +#endif + result = accept(sockfd, addr, addrlen); + if (result < 0) + return result; + + if (flags & EVUTIL_SOCK_CLOEXEC) { + if (evutil_fast_socket_closeonexec(result) < 0) { + evutil_closesocket(result); + return -1; + } + } + if (flags & EVUTIL_SOCK_NONBLOCK) { + if (evutil_fast_socket_nonblocking(result) < 0) { + evutil_closesocket(result); + return -1; + } + } + return result; +} + +/* Internal function: Set fd[0] and fd[1] to a pair of fds such that writes on + * fd[0] get read from fd[1]. Make both fds nonblocking and close-on-exec. + * Return 0 on success, -1 on failure. + */ +int evutil_make_internal_pipe_(evutil_socket_t fd[2]) +{ + /* + Making the second socket nonblocking is a bit subtle, given that we + ignore any EAGAIN returns when writing to it, and you don't usally + do that for a nonblocking socket. But if the kernel gives us EAGAIN, + then there's no need to add any more data to the buffer, since + the main thread is already either about to wake up and drain it, + or woken up and in the process of draining it. + */ + +#if defined(EVENT__HAVE_PIPE2) + if (pipe2(fd, O_NONBLOCK | O_CLOEXEC) == 0) + return 0; +#endif +#if defined(EVENT__HAVE_PIPE) + if (pipe(fd) == 0) { + if (evutil_fast_socket_nonblocking(fd[0]) < 0 || evutil_fast_socket_nonblocking(fd[1]) < 0 || evutil_fast_socket_closeonexec(fd[0]) < 0 + || evutil_fast_socket_closeonexec(fd[1]) < 0) { + close(fd[0]); + close(fd[1]); + fd[0] = fd[1] = -1; + return -1; + } + return 0; + } else { + event_warn("%s: pipe", __func__); + } +#endif + +#ifdef _WIN32 +#define LOCAL_SOCKETPAIR_AF AF_INET +#else +#define LOCAL_SOCKETPAIR_AF AF_UNIX +#endif + if (evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, fd) == 0) { + if (evutil_fast_socket_nonblocking(fd[0]) < 0 || evutil_fast_socket_nonblocking(fd[1]) < 0 || evutil_fast_socket_closeonexec(fd[0]) < 0 + || evutil_fast_socket_closeonexec(fd[1]) < 0) { + evutil_closesocket(fd[0]); + evutil_closesocket(fd[1]); + fd[0] = fd[1] = -1; + return -1; + } + return 0; + } + fd[0] = fd[1] = -1; + return -1; +} + +/* Wrapper around eventfd on systems that provide it. Unlike the system + * eventfd, it always supports EVUTIL_EFD_CLOEXEC and EVUTIL_EFD_NONBLOCK as + * flags. Returns -1 on error or if eventfd is not supported. + */ +evutil_socket_t evutil_eventfd_(unsigned initval, int flags) +{ +#if defined(EVENT__HAVE_EVENTFD) && defined(EVENT__HAVE_SYS_EVENTFD_H) + int r; +#if defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK) + r = eventfd(initval, flags); + if (r >= 0 || flags == 0) + return r; +#endif + r = eventfd(initval, 0); + if (r < 0) + return r; + if (flags & EVUTIL_EFD_CLOEXEC) { + if (evutil_fast_socket_closeonexec(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + if (flags & EVUTIL_EFD_NONBLOCK) { + if (evutil_fast_socket_nonblocking(r) < 0) { + evutil_closesocket(r); + return -1; + } + } + return r; +#else + return -1; +#endif +} + +void evutil_free_globals_(void) +{ + evutil_free_secure_rng_globals_(); + evutil_free_sock_err_globals(); +} diff --git a/asynio/event/evutil.h b/asynio/event/evutil.h new file mode 100644 index 0000000000000000000000000000000000000000..8b8c4d78b0d2865defa28e0f2ceb702a167ad28b --- /dev/null +++ b/asynio/event/evutil.h @@ -0,0 +1,6 @@ +#ifndef EVENT1_EVUTIL_H_INCLUDED_ +#define EVENT1_EVUTIL_H_INCLUDED_ + +#include 鈥渦til.h鈥 + +#endif /* EVENT1_EVUTIL_H_INCLUDED_ */ diff --git a/asynio/event/evutil_rand.c b/asynio/event/evutil_rand.c new file mode 100644 index 0000000000000000000000000000000000000000..e5b7c8dadec8a9c825b2e256022c4199cda208a4 --- /dev/null +++ b/asynio/event/evutil_rand.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* This file has our secure PRNG code. On platforms that have arc4random(), + * we just use that. Otherwise, we include arc4random.c as a bunch of static + * functions, and wrap it lightly. We don't expose the arc4random*() APIs + * because A) they aren't in our namespace, and B) it's not nice to name your + * APIs after their implementations. We keep them in a separate file + * so that other people can rip it out and use it for whatever. + */ + +#include "evconfig.h" + +#include + +#include "evconfig-internal.h" + +#ifdef EVENT__HAVE_ARC4RANDOM +#include +#include +int evutil_secure_rng_set_urandom_device_file(char* fname) +{ + (void)fname; + return -1; +} +int evutil_secure_rng_init(void) +{ + /* call arc4random() now to force it to self-initialize */ + (void)arc4random(); + return 0; +} +#ifndef EVENT__DISABLE_THREAD_SUPPORT +int evutil_secure_rng_global_setup_locks_(const int enable_locks) +{ + return 0; +} +#endif +static void evutil_free_secure_rng_globals_locks(void) +{ +} + +static void ev_arc4random_buf(void* buf, size_t n) +{ +#if defined(EVENT__HAVE_ARC4RANDOM_BUF) && !defined(__APPLE__) + arc4random_buf(buf, n); + return; +#else + unsigned char* b = buf; + +#if defined(EVENT__HAVE_ARC4RANDOM_BUF) + /* OSX 10.7 introducd arc4random_buf, so if you build your program + * there, you'll get surprised when older versions of OSX fail to run. + * To solve this, we can check whether the function pointer is set, + * and fall back otherwise. (OSX does this using some linker + * trickery.) + */ + { + void (*tptr)(void*, size_t) = (void (*)(void*, size_t))arc4random_buf; + if (tptr != NULL) { + arc4random_buf(buf, n); + return; + } + } +#endif + /* Make sure that we start out with b at a 4-byte alignment; plenty + * of CPUs care about this for 32-bit access. */ + if (n >= 4 && ((ev_uintptr_t)b) & 3) { + ev_uint32_t u = arc4random(); + int n_bytes = 4 - (((ev_uintptr_t)b) & 3); + memcpy(b, &u, n_bytes); + b += n_bytes; + n -= n_bytes; + } + while (n >= 4) { + *(ev_uint32_t*)b = arc4random(); + b += 4; + n -= 4; + } + if (n) { + ev_uint32_t u = arc4random(); + memcpy(b, &u, n); + } +#endif +} + +#else /* !EVENT__HAVE_ARC4RANDOM { */ + +#ifdef EVENT__ssize_t +#define ssize_t EVENT__ssize_t +#endif +#define ARC4RANDOM_EXPORT static +#define ARC4_LOCK_() EVLOCK_LOCK(arc4rand_lock, 0) +#define ARC4_UNLOCK_() EVLOCK_UNLOCK(arc4rand_lock, 0) +#ifndef EVENT__DISABLE_THREAD_SUPPORT +static void* arc4rand_lock; +#endif + +#define ARC4RANDOM_UINT32 ev_uint32_t +#define ARC4RANDOM_NOSTIR +#define ARC4RANDOM_NORANDOM +#define ARC4RANDOM_NOUNIFORM + +#include "./arc4random.c" + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +int evutil_secure_rng_global_setup_locks_(const int enable_locks) +{ + EVTHREAD_SETUP_GLOBAL_LOCK(arc4rand_lock, 0); + return 0; +} +#endif + +static void evutil_free_secure_rng_globals_locks(void) +{ +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (arc4rand_lock != NULL) { + EVTHREAD_FREE_LOCK(arc4rand_lock, 0); + arc4rand_lock = NULL; + } +#endif + return; +} + +int evutil_secure_rng_set_urandom_device_file(char* fname) +{ +#ifdef TRY_SEED_URANDOM + ARC4_LOCK_(); + arc4random_urandom_filename = fname; + ARC4_UNLOCK_(); +#endif + return 0; +} + +int evutil_secure_rng_init(void) +{ + int val; + + ARC4_LOCK_(); + if (!arc4_seeded_ok) + arc4_stir(); + val = arc4_seeded_ok ? 0 : -1; + ARC4_UNLOCK_(); + return val; +} + +static void ev_arc4random_buf(void* buf, size_t n) +{ + arc4random_buf(buf, n); +} + +#endif /* } !EVENT__HAVE_ARC4RANDOM */ + +void evutil_secure_rng_get_bytes(void* buf, size_t n) +{ + ev_arc4random_buf(buf, n); +} + +void evutil_secure_rng_add_bytes(const char* buf, size_t n) +{ + arc4random_addrandom((unsigned char*)buf, n > (size_t)INT_MAX ? INT_MAX : (int)n); +} + +void evutil_free_secure_rng_globals_(void) +{ + evutil_free_secure_rng_globals_locks(); +} diff --git a/asynio/event/evutil_time.c b/asynio/event/evutil_time.c new file mode 100644 index 0000000000000000000000000000000000000000..4e5b46fcf4cb773a8e247122544b37478d784271 --- /dev/null +++ b/asynio/event/evutil_time.c @@ -0,0 +1,529 @@ +/* + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef _WIN32 +#include +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#endif + +#include +#ifdef EVENT__HAVE_STDLIB_H +#include +#endif +#include +#include +#ifndef EVENT__HAVE_GETTIMEOFDAY +#include +#endif +#if !defined(EVENT__HAVE_NANOSLEEP) && !defined(EVENT_HAVE_USLEEP) && !defined(_WIN32) +#include +#endif +#include +#include +#include + +/** evutil_usleep_() */ +#if defined(_WIN32) +#elif defined(EVENT__HAVE_NANOSLEEP) +#elif defined(EVENT__HAVE_USLEEP) +#include +#endif + +#include "evconfig-internal.h" + +#ifndef EVENT__HAVE_GETTIMEOFDAY +/* No gettimeofday; this must be windows. */ +int evutil_gettimeofday(struct timeval* tv, struct timezone* tz) +{ +#ifdef _MSC_VER +#define U64_LITERAL(n) n##ui64 +#else +#define U64_LITERAL(n) n##llu +#endif + + /* Conversion logic taken from Tor, which in turn took it + * from Perl. GetSystemTimeAsFileTime returns its value as + * an unaligned (!) 64-bit value containing the number of + * 100-nanosecond intervals since 1 January 1601 UTC. */ +#define EPOCH_BIAS U64_LITERAL(116444736000000000) +#define UNITS_PER_SEC U64_LITERAL(10000000) +#define USEC_PER_SEC U64_LITERAL(1000000) +#define UNITS_PER_USEC U64_LITERAL(10) + union { + FILETIME ft_ft; + ev_uint64_t ft_64; + } ft; + + if (tv == NULL) + return -1; + + GetSystemTimeAsFileTime(&ft.ft_ft); + + if (EVUTIL_UNLIKELY(ft.ft_64 < EPOCH_BIAS)) { + /* Time before the unix epoch. */ + return -1; + } + ft.ft_64 -= EPOCH_BIAS; + tv->tv_sec = (long)(ft.ft_64 / UNITS_PER_SEC); + tv->tv_usec = (long)((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC); + return 0; +} +#endif + +#define MAX_SECONDS_IN_MSEC_LONG (((LONG_MAX)-999) / 1000) + +long evutil_tv_to_msec_(const struct timeval* tv) +{ + if (tv->tv_usec > 1000000 || tv->tv_sec > MAX_SECONDS_IN_MSEC_LONG) + return -1; + + return (tv->tv_sec * 1000) + ((tv->tv_usec + 999) / 1000); +} + +/* + Replacement for usleep on platforms that don't have one. Not guaranteed to + be any more finegrained than 1 msec. + */ +void evutil_usleep_(const struct timeval* tv) +{ + if (!tv) + return; +#if defined(_WIN32) + { + long msec = evutil_tv_to_msec_(tv); + Sleep((DWORD)msec); + } +#elif defined(EVENT__HAVE_NANOSLEEP) + { + struct timespec ts; + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + nanosleep(&ts, NULL); + } +#elif defined(EVENT__HAVE_USLEEP) + /* Some systems don't like to usleep more than 999999 usec */ + sleep(tv->tv_sec); + usleep(tv->tv_usec); +#else + select(0, NULL, NULL, NULL, tv); +#endif +} + +int evutil_date_rfc1123(char* date, const size_t datelen, const struct tm* tm) +{ + static const char* DAYS[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + static const char* MONTHS[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + + time_t t = time(NULL); + +#ifndef _WIN32 + struct tm sys; +#endif + + /* If `tm` is null, set system's current time. */ + if (tm == NULL) { +#ifdef _WIN32 + /** TODO: detect _gmtime64()/_gmtime64_s() */ + tm = gmtime(&t); +#else + gmtime_r(&t, &sys); + tm = &sys; +#endif + } + + return evutil_snprintf( + date, datelen, "%s, %02d %s %4d %02d:%02d:%02d GMT", DAYS[tm->tm_wday], tm->tm_mday, MONTHS[tm->tm_mon], 1900 + tm->tm_year, tm->tm_hour, + tm->tm_min, tm->tm_sec); +} + +/* + This function assumes it's called repeatedly with a + not-actually-so-monotonic time source whose outputs are in 'tv'. It + implements a trivial ratcheting mechanism so that the values never go + backwards. + */ +static void adjust_monotonic_time(struct evutil_monotonic_timer* base, struct timeval* tv) +{ + evutil_timeradd(tv, &base->adjust_monotonic_clock, tv); + + if (evutil_timercmp(tv, &base->last_time, <)) { + /* Guess it wasn't monotonic after all. */ + struct timeval adjust; + evutil_timersub(&base->last_time, tv, &adjust); + evutil_timeradd(&adjust, &base->adjust_monotonic_clock, &base->adjust_monotonic_clock); + *tv = base->last_time; + } + base->last_time = *tv; +} + +/* + Allocate a new struct evutil_monotonic_timer + */ +struct evutil_monotonic_timer* evutil_monotonic_timer_new(void) +{ + struct evutil_monotonic_timer* p = NULL; + + p = mm_malloc(sizeof(*p)); + if (!p) + goto done; + + memset(p, 0, sizeof(*p)); + +done: + return p; +} + +/* + Free a struct evutil_monotonic_timer + */ +void evutil_monotonic_timer_free(struct evutil_monotonic_timer* timer) +{ + if (timer) { + mm_free(timer); + } +} + +/* + Set up a struct evutil_monotonic_timer for initial use + */ +int evutil_configure_monotonic_time(struct evutil_monotonic_timer* timer, int flags) +{ + return evutil_configure_monotonic_time_(timer, flags); +} + +/* + Query the current monotonic time + */ +int evutil_gettime_monotonic(struct evutil_monotonic_timer* timer, struct timeval* tp) +{ + return evutil_gettime_monotonic_(timer, tp); +} + +#if defined(HAVE_POSIX_MONOTONIC) +/* ===== + The POSIX clock_gettime() interface provides a few ways to get at a + monotonic clock. CLOCK_MONOTONIC is most widely supported. Linux also + provides a CLOCK_MONOTONIC_COARSE with accuracy of about 1-4 msec. + + On all platforms I'm aware of, CLOCK_MONOTONIC really is monotonic. + Platforms don't agree about whether it should jump on a sleep/resume. + */ + +int evutil_configure_monotonic_time_(struct evutil_monotonic_timer* base, int flags) +{ + /* CLOCK_MONOTONIC exists on FreeBSD, Linux, and Solaris. You need to + * check for it at runtime, because some older kernel versions won't + * have it working. */ +#ifdef CLOCK_MONOTONIC_COARSE + const int precise = flags & EV_MONOT_PRECISE; +#endif + const int fallback = flags & EV_MONOT_FALLBACK; + struct timespec ts; + +#ifdef CLOCK_MONOTONIC_COARSE + if (CLOCK_MONOTONIC_COARSE < 0) { + /* Technically speaking, nothing keeps CLOCK_* from being + * negative (as far as I know). This check and the one below + * make sure that it's safe for us to use -1 as an "unset" + * value. */ + event_errx(1, "I didn't expect CLOCK_MONOTONIC_COARSE to be < 0"); + } + if (!precise && !fallback) { + if (clock_gettime(CLOCK_MONOTONIC_COARSE, &ts) == 0) { + base->monotonic_clock = CLOCK_MONOTONIC_COARSE; + return 0; + } + } +#endif + if (!fallback && clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { + base->monotonic_clock = CLOCK_MONOTONIC; + return 0; + } + + if (CLOCK_MONOTONIC < 0) { + event_errx(1, "I didn't expect CLOCK_MONOTONIC to be < 0"); + } + + base->monotonic_clock = -1; + return 0; +} + +int evutil_gettime_monotonic_(struct evutil_monotonic_timer* base, struct timeval* tp) +{ + struct timespec ts; + + if (base->monotonic_clock < 0) { + if (evutil_gettimeofday(tp, NULL) < 0) + return -1; + adjust_monotonic_time(base, tp); + return 0; + } + + if (clock_gettime(base->monotonic_clock, &ts) == -1) + return -1; + tp->tv_sec = ts.tv_sec; + tp->tv_usec = ts.tv_nsec / 1000; + + return 0; +} +#endif + +#if defined(HAVE_MACH_MONOTONIC) +/* ====== + Apple is a little late to the POSIX party. And why not? Instead of + clock_gettime(), they provide mach_absolute_time(). Its units are not + fixed; we need to use mach_timebase_info() to get the right functions to + convert its units into nanoseconds. + + To all appearances, mach_absolute_time() seems to be honest-to-goodness + monotonic. Whether it stops during sleep or not is unspecified in + principle, and dependent on CPU architecture in practice. + */ + +int evutil_configure_monotonic_time_(struct evutil_monotonic_timer* base, int flags) +{ + const int fallback = flags & EV_MONOT_FALLBACK; + struct mach_timebase_info mi; + memset(base, 0, sizeof(*base)); + /* OSX has mach_absolute_time() */ + if (!fallback && mach_timebase_info(&mi) == 0 && mach_absolute_time() != 0) { + /* mach_timebase_info tells us how to convert + * mach_absolute_time() into nanoseconds, but we + * want to use microseconds instead. */ + mi.denom *= 1000; + memcpy(&base->mach_timebase_units, &mi, sizeof(mi)); + } else { + base->mach_timebase_units.numer = 0; + } + return 0; +} + +int evutil_gettime_monotonic_(struct evutil_monotonic_timer* base, struct timeval* tp) +{ + ev_uint64_t abstime, usec; + if (base->mach_timebase_units.numer == 0) { + if (evutil_gettimeofday(tp, NULL) < 0) + return -1; + adjust_monotonic_time(base, tp); + return 0; + } + + abstime = mach_absolute_time(); + usec = (abstime * base->mach_timebase_units.numer) / (base->mach_timebase_units.denom); + tp->tv_sec = usec / 1000000; + tp->tv_usec = usec % 1000000; + + return 0; +} +#endif + +#if defined(HAVE_WIN32_MONOTONIC) +/* ===== + Turn we now to Windows. Want monontonic time on Windows? + + Windows has QueryPerformanceCounter(), which gives time most high- + resolution time. It's a pity it's not so monotonic in practice; it's + also got some fun bugs, especially: with older Windowses, under + virtualizations, with funny hardware, on multiprocessor systems, and so + on. PEP418 [1] has a nice roundup of the issues here. + + There's GetTickCount64() on Vista and later, which gives a number of 1-msec + ticks since startup. The accuracy here might be as bad as 10-20 msec, I + hear. There's an undocumented function (NtSetTimerResolution) that + allegedly increases the accuracy. Good luck! + + There's also GetTickCount(), which is only 32 bits, but seems to be + supported on pre-Vista versions of Windows. Apparently, you can coax + another 14 bits out of it, giving you 2231 years before rollover. + + The less said about timeGetTime() the better. + + "We don't care. We don't have to. We're the Phone Company." + -- Lily Tomlin, SNL + + Our strategy, if precise timers are turned off, is to just use the best + GetTickCount equivalent available. If we've been asked for precise timing, + then we mostly[2] assume that GetTickCount is monotonic, and correct + GetPerformanceCounter to approximate it. + + [1] http://www.python.org/dev/peps/pep-0418 + [2] Of course, we feed the Windows stuff into adjust_monotonic_time() + anyway, just in case it isn't. + + */ +/* + Parts of our logic in the win32 timer code here are closely based on + BitTorrent's libUTP library. That code is subject to the following + license: + + Copyright (c) 2010 BitTorrent, Inc. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +static ev_uint64_t evutil_GetTickCount_(struct evutil_monotonic_timer* base) +{ + if (base->GetTickCount64_fn) { + /* Let's just use GetTickCount64 if we can. */ + return base->GetTickCount64_fn(); + } else if (base->GetTickCount_fn) { + /* Greg Hazel assures me that this works, that BitTorrent has + * done it for years, and this it won't turn around and + * bite us. He says they found it on some game programmers' + * forum some time around 2007. + */ + ev_uint64_t v = base->GetTickCount_fn(); + return (DWORD)v | ((v >> 18) & 0xFFFFFFFF00000000); + } else { + /* Here's the fallback implementation. We have to use + * GetTickCount() with its given signature, so we only get + * 32 bits worth of milliseconds, which will roll ove every + * 49 days or so. */ + DWORD ticks = GetTickCount(); + if (ticks < base->last_tick_count) { + base->adjust_tick_count += ((ev_uint64_t)1) << 32; + } + base->last_tick_count = ticks; + return ticks + base->adjust_tick_count; + } +} + +int evutil_configure_monotonic_time_(struct evutil_monotonic_timer* base, int flags) +{ + const int precise = flags & EV_MONOT_PRECISE; + const int fallback = flags & EV_MONOT_FALLBACK; + HANDLE h; + memset(base, 0, sizeof(*base)); + + h = evutil_load_windows_system_library_(TEXT("kernel32.dll")); + if (h != NULL && !fallback) { + base->GetTickCount64_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount64"); + base->GetTickCount_fn = (ev_GetTickCount_func)GetProcAddress(h, "GetTickCount"); + } + + base->first_tick = base->last_tick_count = evutil_GetTickCount_(base); + if (precise && !fallback) { + LARGE_INTEGER freq; + if (QueryPerformanceFrequency(&freq)) { + LARGE_INTEGER counter; + QueryPerformanceCounter(&counter); + base->first_counter = counter.QuadPart; + base->usec_per_count = 1.0e6 / freq.QuadPart; + base->use_performance_counter = 1; + } + } + + return 0; +} + +static inline ev_int64_t abs64(ev_int64_t i) +{ + return i < 0 ? -i : i; +} + +int evutil_gettime_monotonic_(struct evutil_monotonic_timer* base, struct timeval* tp) +{ + ev_uint64_t ticks = evutil_GetTickCount_(base); + if (base->use_performance_counter) { + /* Here's a trick we took from BitTorrent's libutp, at Greg + * Hazel's recommendation. We use QueryPerformanceCounter for + * our high-resolution timer, but use GetTickCount*() to keep + * it sane, and adjust_monotonic_time() to keep it monotonic. + */ + LARGE_INTEGER counter; + ev_int64_t counter_elapsed, counter_usec_elapsed, ticks_elapsed; + QueryPerformanceCounter(&counter); + counter_elapsed = (ev_int64_t)(counter.QuadPart - base->first_counter); + ticks_elapsed = ticks - base->first_tick; + /* TODO: This may upset VC6. If you need this to work with + * VC6, please supply an appropriate patch. */ + counter_usec_elapsed = (ev_int64_t)(counter_elapsed * base->usec_per_count); + + if (abs64(ticks_elapsed * 1000 - counter_usec_elapsed) > 1000000) { + /* It appears that the QueryPerformanceCounter() + * result is more than 1 second away from + * GetTickCount() result. Let's adjust it to be as + * accurate as we can; adjust_monotnonic_time() below + * will keep it monotonic. */ + counter_usec_elapsed = ticks_elapsed * 1000; + base->first_counter = (ev_uint64_t)(counter.QuadPart - counter_usec_elapsed / base->usec_per_count); + } + tp->tv_sec = (time_t)(counter_usec_elapsed / 1000000); + tp->tv_usec = counter_usec_elapsed % 1000000; + + } else { + /* We're just using GetTickCount(). */ + tp->tv_sec = (time_t)(ticks / 1000); + tp->tv_usec = (ticks % 1000) * 1000; + } + adjust_monotonic_time(base, tp); + + return 0; +} +#endif + +#if defined(HAVE_FALLBACK_MONOTONIC) +/* ===== + And if none of the other options work, let's just use gettimeofday(), and + ratchet it forward so that it acts like a monotonic timer, whether it + wants to or not. + */ + +int evutil_configure_monotonic_time_(struct evutil_monotonic_timer* base, int precise) +{ + memset(base, 0, sizeof(*base)); + return 0; +} + +int evutil_gettime_monotonic_(struct evutil_monotonic_timer* base, struct timeval* tp) +{ + if (evutil_gettimeofday(tp, NULL) < 0) + return -1; + adjust_monotonic_time(base, tp); + return 0; +} +#endif diff --git a/asynio/event/ht-internal.h b/asynio/event/ht-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..0029f8b38fbe14643338c193faaf632a2ea2534a --- /dev/null +++ b/asynio/event/ht-internal.h @@ -0,0 +1,415 @@ +/* Copyright 2002 Christopher Clark */ +/* Copyright 2005-2012 Nick Mathewson */ +/* Copyright 2009-2012 Niels Provos and Nick Mathewson */ +/* See license at end. */ + +/* Based on ideas by Christopher Clark and interfaces from Niels Provos. */ + +#ifndef HT_INTERNAL_H_INCLUDED_ +#define HT_INTERNAL_H_INCLUDED_ + +#define HT_HEAD(name, type) \ + struct name { \ + /* The hash table itself. */ \ + struct type** hth_table; \ + /* How long is the hash table? */ \ + unsigned hth_table_length; \ + /* How many elements does the table contain? */ \ + unsigned hth_n_entries; \ + /* How many elements will we allow in the table before resizing it? */ \ + unsigned hth_load_limit; \ + /* Position of hth_table_length in the primes table. */ \ + int hth_prime_idx; \ + } + +#define HT_INITIALIZER() \ + { \ + NULL, 0, 0, 0, -1 \ + } + +#ifdef HT_NO_CACHE_HASH_VALUES +#define HT_ENTRY(type) \ + struct { \ + struct type* hte_next; \ + } +#else +#define HT_ENTRY(type) \ + struct { \ + struct type* hte_next; \ + unsigned hte_hash; \ + } +#endif + +#define HT_EMPTY(head) ((head)->hth_n_entries == 0) + +/* How many elements in 'head'? */ +#define HT_SIZE(head) ((head)->hth_n_entries) + +/* Return memory usage for a hashtable (not counting the entries themselves) */ +#define HT_MEM_USAGE(head) (sizeof(*head) + (head)->hth_table_length * sizeof(void*)) + +#define HT_FIND(name, head, elm) name##_HT_FIND((head), (elm)) +#define HT_INSERT(name, head, elm) name##_HT_INSERT((head), (elm)) +#define HT_REPLACE(name, head, elm) name##_HT_REPLACE((head), (elm)) +#define HT_REMOVE(name, head, elm) name##_HT_REMOVE((head), (elm)) +#define HT_START(name, head) name##_HT_START(head) +#define HT_NEXT(name, head, elm) name##_HT_NEXT((head), (elm)) +#define HT_NEXT_RMV(name, head, elm) name##_HT_NEXT_RMV((head), (elm)) +#define HT_CLEAR(name, head) name##_HT_CLEAR(head) +#define HT_INIT(name, head) name##_HT_INIT(head) +/* Helper: */ +static inline unsigned ht_improve_hash_(unsigned h) +{ + /* Aim to protect against poor hash functions by adding logic here + * - logic taken from java 1.4 hashtable source */ + h += ~(h << 9); + h ^= ((h >> 14) | (h << 18)); /* >>> */ + h += (h << 4); + h ^= ((h >> 10) | (h << 22)); /* >>> */ + return h; +} + +#if 0 +/** Basic string hash function, from Java standard String.hashCode(). */ +static inline unsigned +ht_string_hash_(const char *s) +{ + unsigned h = 0; + int m = 1; + while (*s) { + h += ((signed char)*s++)*m; + m = (m<<5)-1; /* m *= 31 */ + } + return h; +} +#endif + +/** Basic string hash function, from Python's str.__hash__() */ +static inline unsigned ht_string_hash_(const char* s) +{ + unsigned h; + const unsigned char* cp = (const unsigned char*)s; + h = *cp << 7; + while (*cp) { + h = (1000003 * h) ^ *cp++; + } + /* This conversion truncates the length of the string, but that's ok. */ + h ^= (unsigned)(cp - (const unsigned char*)s); + return h; +} + +#ifndef HT_NO_CACHE_HASH_VALUES +#define HT_SET_HASH_(elm, field, hashfn) \ + do { \ + (elm)->field.hte_hash = hashfn(elm); \ + } while (0) +#define HT_SET_HASHVAL_(elm, field, val) \ + do { \ + (elm)->field.hte_hash = (val); \ + } while (0) +#define HT_ELT_HASH_(elm, field, hashfn) ((elm)->field.hte_hash) +#else +#define HT_SET_HASH_(elm, field, hashfn) ((void)0) +#define HT_ELT_HASH_(elm, field, hashfn) (hashfn(elm)) +#define HT_SET_HASHVAL_(elm, field, val) ((void)0) +#endif + +/* Helper: alias for the bucket containing 'elm'. */ +#define HT_BUCKET_(head, field, elm, hashfn) ((head)->hth_table[HT_ELT_HASH_(elm, field, hashfn) % head->hth_table_length]) + +#define HT_FOREACH(x, name, head) for ((x) = HT_START(name, head); (x) != NULL; (x) = HT_NEXT(name, head, x)) + +#define HT_PROTOTYPE(name, type, field, hashfn, eqfn) \ + int name##_HT_GROW(struct name* ht, unsigned min_capacity); \ + void name##_HT_CLEAR(struct name* ht); \ + int name##_HT_REP_IS_BAD_(const struct name* ht); \ + static inline void name##_HT_INIT(struct name* head) \ + { \ + head->hth_table_length = 0; \ + head->hth_table = NULL; \ + head->hth_n_entries = 0; \ + head->hth_load_limit = 0; \ + head->hth_prime_idx = -1; \ + } \ + /* Helper: returns a pointer to the right location in the table \ + * 'head' to find or insert the element 'elm'. */ \ + static inline struct type** name##_HT_FIND_P_(struct name* head, struct type* elm) \ + { \ + struct type** p; \ + if (!head->hth_table) \ + return NULL; \ + p = &HT_BUCKET_(head, field, elm, hashfn); \ + while (*p) { \ + if (eqfn(*p, elm)) \ + return p; \ + p = &(*p)->field.hte_next; \ + } \ + return p; \ + } \ + /* Return a pointer to the element in the table 'head' matching 'elm', \ + * or NULL if no such element exists */ \ + static inline struct type* name##_HT_FIND(const struct name* head, struct type* elm) \ + { \ + struct type** p; \ + struct name* h = (struct name*)head; \ + HT_SET_HASH_(elm, field, hashfn); \ + p = name##_HT_FIND_P_(h, elm); \ + return p ? *p : NULL; \ + } \ + /* Insert the element 'elm' into the table 'head'. Do not call this \ + * function if the table might already contain a matching element. */ \ + static inline void name##_HT_INSERT(struct name* head, struct type* elm) \ + { \ + struct type** p; \ + if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \ + name##_HT_GROW(head, head->hth_n_entries + 1); \ + ++head->hth_n_entries; \ + HT_SET_HASH_(elm, field, hashfn); \ + p = &HT_BUCKET_(head, field, elm, hashfn); \ + elm->field.hte_next = *p; \ + *p = elm; \ + } \ + /* Insert the element 'elm' into the table 'head'. If there already \ + * a matching element in the table, replace that element and return \ + * it. */ \ + static inline struct type* name##_HT_REPLACE(struct name* head, struct type* elm) \ + { \ + struct type **p, *r; \ + if (!head->hth_table || head->hth_n_entries >= head->hth_load_limit) \ + name##_HT_GROW(head, head->hth_n_entries + 1); \ + HT_SET_HASH_(elm, field, hashfn); \ + p = name##_HT_FIND_P_(head, elm); \ + r = *p; \ + *p = elm; \ + if (r && (r != elm)) { \ + elm->field.hte_next = r->field.hte_next; \ + r->field.hte_next = NULL; \ + return r; \ + } else { \ + ++head->hth_n_entries; \ + return NULL; \ + } \ + } \ + /* Remove any element matching 'elm' from the table 'head'. If such \ + * an element is found, return it; otherwise return NULL. */ \ + static inline struct type* name##_HT_REMOVE(struct name* head, struct type* elm) \ + { \ + struct type **p, *r; \ + HT_SET_HASH_(elm, field, hashfn); \ + p = name##_HT_FIND_P_(head, elm); \ + if (!p || !*p) \ + return NULL; \ + r = *p; \ + *p = r->field.hte_next; \ + r->field.hte_next = NULL; \ + --head->hth_n_entries; \ + return r; \ + } \ + /* Invoke the function 'fn' on every element of the table 'head', \ + * using 'data' as its second argument. If the function returns \ + * nonzero, remove the most recently examined element before invoking \ + * the function again. */ \ + static inline void name##_HT_FOREACH_FN(struct name* head, int (*fn)(struct type*, void*), void* data) \ + { \ + unsigned idx; \ + struct type **p, **nextp, *next; \ + if (!head->hth_table) \ + return; \ + for (idx = 0; idx < head->hth_table_length; ++idx) { \ + p = &head->hth_table[idx]; \ + while (*p) { \ + nextp = &(*p)->field.hte_next; \ + next = *nextp; \ + if (fn(*p, data)) { \ + --head->hth_n_entries; \ + *p = next; \ + } else { \ + p = nextp; \ + } \ + } \ + } \ + } \ + /* Return a pointer to the first element in the table 'head', under \ + * an arbitrary order. This order is stable under remove operations, \ + * but not under others. If the table is empty, return NULL. */ \ + static inline struct type** name##_HT_START(struct name* head) \ + { \ + unsigned b = 0; \ + while (b < head->hth_table_length) { \ + if (head->hth_table[b]) \ + return &head->hth_table[b]; \ + ++b; \ + } \ + return NULL; \ + } \ + /* Return the next element in 'head' after 'elm', under the arbitrary \ + * order used by HT_START. If there are no more elements, return \ + * NULL. If 'elm' is to be removed from the table, you must call \ + * this function for the next value before you remove it. \ + */ \ + static inline struct type** name##_HT_NEXT(struct name* head, struct type** elm) \ + { \ + if ((*elm)->field.hte_next) { \ + return &(*elm)->field.hte_next; \ + } else { \ + unsigned b = (HT_ELT_HASH_(*elm, field, hashfn) % head->hth_table_length) + 1; \ + while (b < head->hth_table_length) { \ + if (head->hth_table[b]) \ + return &head->hth_table[b]; \ + ++b; \ + } \ + return NULL; \ + } \ + } \ + static inline struct type** name##_HT_NEXT_RMV(struct name* head, struct type** elm) \ + { \ + unsigned h = HT_ELT_HASH_(*elm, field, hashfn); \ + *elm = (*elm)->field.hte_next; \ + --head->hth_n_entries; \ + if (*elm) { \ + return elm; \ + } else { \ + unsigned b = (h % head->hth_table_length) + 1; \ + while (b < head->hth_table_length) { \ + if (head->hth_table[b]) \ + return &head->hth_table[b]; \ + ++b; \ + } \ + return NULL; \ + } \ + } + +#define HT_GENERATE(name, type, field, hashfn, eqfn, load, mallocfn, reallocfn, freefn) \ + static unsigned name##_PRIMES[] = {53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, \ + 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, \ + 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741}; \ + static unsigned name##_N_PRIMES = (unsigned)(sizeof(name##_PRIMES) / sizeof(name##_PRIMES[0])); \ + /* Expand the internal table of 'head' until it is large enough to \ + * hold 'size' elements. Return 0 on success, -1 on allocation \ + * failure. */ \ + int name##_HT_GROW(struct name* head, unsigned size) \ + { \ + unsigned new_len, new_load_limit; \ + int prime_idx; \ + struct type** new_table; \ + if (head->hth_prime_idx == (int)name##_N_PRIMES - 1) \ + return 0; \ + if (head->hth_load_limit > size) \ + return 0; \ + prime_idx = head->hth_prime_idx; \ + do { \ + new_len = name##_PRIMES[++prime_idx]; \ + new_load_limit = (unsigned)(load * new_len); \ + } while (new_load_limit <= size && prime_idx < (int)name##_N_PRIMES); \ + if ((new_table = mallocfn(new_len * sizeof(struct type*)))) { \ + unsigned b; \ + memset(new_table, 0, new_len * sizeof(struct type*)); \ + for (b = 0; b < head->hth_table_length; ++b) { \ + struct type *elm, *next; \ + unsigned b2; \ + elm = head->hth_table[b]; \ + while (elm) { \ + next = elm->field.hte_next; \ + b2 = HT_ELT_HASH_(elm, field, hashfn) % new_len; \ + elm->field.hte_next = new_table[b2]; \ + new_table[b2] = elm; \ + elm = next; \ + } \ + } \ + if (head->hth_table) \ + freefn(head->hth_table); \ + head->hth_table = new_table; \ + } else { \ + unsigned b, b2; \ + new_table = reallocfn(head->hth_table, new_len * sizeof(struct type*)); \ + if (!new_table) \ + return -1; \ + memset(new_table + head->hth_table_length, 0, (new_len - head->hth_table_length) * sizeof(struct type*)); \ + for (b = 0; b < head->hth_table_length; ++b) { \ + struct type *e, **pE; \ + for (pE = &new_table[b], e = *pE; e != NULL; e = *pE) { \ + b2 = HT_ELT_HASH_(e, field, hashfn) % new_len; \ + if (b2 == b) { \ + pE = &e->field.hte_next; \ + } else { \ + *pE = e->field.hte_next; \ + e->field.hte_next = new_table[b2]; \ + new_table[b2] = e; \ + } \ + } \ + } \ + head->hth_table = new_table; \ + } \ + head->hth_table_length = new_len; \ + head->hth_prime_idx = prime_idx; \ + head->hth_load_limit = new_load_limit; \ + return 0; \ + } \ + /* Free all storage held by 'head'. Does not free 'head' itself, or \ + * individual elements. */ \ + void name##_HT_CLEAR(struct name* head) \ + { \ + if (head->hth_table) \ + freefn(head->hth_table); \ + name##_HT_INIT(head); \ + } \ + /* Debugging helper: return false iff the representation of 'head' is \ + * internally consistent. */ \ + int name##_HT_REP_IS_BAD_(const struct name* head) \ + { \ + unsigned n, i; \ + struct type* elm; \ + if (!head->hth_table_length) { \ + if (!head->hth_table && !head->hth_n_entries && !head->hth_load_limit && head->hth_prime_idx == -1) \ + return 0; \ + else \ + return 1; \ + } \ + if (!head->hth_table || head->hth_prime_idx < 0 || !head->hth_load_limit) \ + return 2; \ + if (head->hth_n_entries > head->hth_load_limit) \ + return 3; \ + if (head->hth_table_length != name##_PRIMES[head->hth_prime_idx]) \ + return 4; \ + if (head->hth_load_limit != (unsigned)(load * head->hth_table_length)) \ + return 5; \ + for (n = i = 0; i < head->hth_table_length; ++i) { \ + for (elm = head->hth_table[i]; elm; elm = elm->field.hte_next) { \ + if (HT_ELT_HASH_(elm, field, hashfn) != hashfn(elm)) \ + return 1000 + i; \ + if ((HT_ELT_HASH_(elm, field, hashfn) % head->hth_table_length) != i) \ + return 10000 + i; \ + ++n; \ + } \ + } \ + if (n != head->hth_n_entries) \ + return 6; \ + return 0; \ + } + +/** Implements an over-optimized "find and insert if absent" block; + * not meant for direct usage by typical code, or usage outside the critical + * path.*/ +#define HT_FIND_OR_INSERT_(name, field, hashfn, head, eltype, elm, var, y, n) \ + { \ + struct name* var##_head_ = head; \ + struct eltype** var; \ + if (!var##_head_->hth_table || var##_head_->hth_n_entries >= var##_head_->hth_load_limit) \ + name##_HT_GROW(var##_head_, var##_head_->hth_n_entries + 1); \ + HT_SET_HASH_((elm), field, hashfn); \ + var = name##_HT_FIND_P_(var##_head_, (elm)); \ + if (*var) { \ + y; \ + } else { \ + n; \ + } \ + } +#define HT_FOI_INSERT_(field, head, elm, newent, var) \ + { \ + HT_SET_HASHVAL_(newent, field, (elm)->field.hte_hash); \ + newent->field.hte_next = NULL; \ + *var = newent; \ + ++((head)->hth_n_entries); \ + } + +#endif diff --git a/asynio/event/iocp-internal.h b/asynio/event/iocp-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..71170653b355dd9a945142c8429eda8d09add647 --- /dev/null +++ b/asynio/event/iocp-internal.h @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2009-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef IOCP_INTERNAL_H_INCLUDED_ +#define IOCP_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct event_overlapped; +struct event_iocp_port; +struct evbuffer; +typedef void (*iocp_callback)(struct event_overlapped*, ev_uintptr_t, ev_ssize_t, int success); + +/* This whole file is actually win32 only. We wrap the structures in a win32 + * ifdef so that we can test-compile code that uses these interfaces on + * non-win32 platforms. */ +#ifdef _WIN32 + +/** + Internal use only. Wraps an OVERLAPPED that we're using for libevent + functionality. Whenever an event_iocp_port gets an event for a given + OVERLAPPED*, it upcasts the pointer to an event_overlapped, and calls the + iocp_callback function with the event_overlapped, the iocp key, and the + number of bytes transferred as arguments. + */ +struct event_overlapped { + OVERLAPPED overlapped; + iocp_callback cb; +}; + +/* Mingw's headers don't define LPFN_ACCEPTEX. */ + +typedef BOOL(WINAPI* AcceptExPtr)(SOCKET, SOCKET, PVOID, DWORD, DWORD, DWORD, LPDWORD, LPOVERLAPPED); +typedef BOOL(WINAPI* ConnectExPtr)(SOCKET, const struct sockaddr*, int, PVOID, DWORD, LPDWORD, LPOVERLAPPED); +typedef void(WINAPI* GetAcceptExSockaddrsPtr)(PVOID, DWORD, DWORD, DWORD, LPSOCKADDR*, LPINT, LPSOCKADDR*, LPINT); + +/** Internal use only. Holds pointers to functions that only some versions of + Windows provide. + */ +struct win32_extension_fns { + AcceptExPtr AcceptEx; + ConnectExPtr ConnectEx; + GetAcceptExSockaddrsPtr GetAcceptExSockaddrs; +}; + +/** + Internal use only. Stores a Windows IO Completion port, along with + related data. + */ +struct event_iocp_port { + /** The port itself */ + HANDLE port; + /* A lock to cover internal structures. */ + CRITICAL_SECTION lock; + /** Number of threads ever open on the port. */ + short n_threads; + /** True iff we're shutting down all the threads on this port */ + short shutdown; + /** How often the threads on this port check for shutdown and other + * conditions */ + long ms; + /* The threads that are waiting for events. */ + HANDLE* threads; + /** Number of threads currently open on this port. */ + short n_live_threads; + /** A semaphore to signal when we are done shutting down. */ + HANDLE* shutdownSemaphore; +}; + +const struct win32_extension_fns* event_get_win32_extension_fns_(void); +#else +/* Dummy definition so we can test-compile more things on unix. */ +struct event_overlapped { + iocp_callback cb; +}; +#endif + +/** Initialize the fields in an event_overlapped. + + @param overlapped The struct event_overlapped to initialize + @param cb The callback that should be invoked once the IO operation has + finished. + */ +void event_overlapped_init_(struct event_overlapped*, iocp_callback cb); + +/** Allocate and return a new evbuffer that supports overlapped IO on a given + socket. The socket must be associated with an IO completion port using + event_iocp_port_associate_. +*/ +struct evbuffer* evbuffer_overlapped_new_(evutil_socket_t fd); + +/** XXXX Document (nickm) */ +evutil_socket_t evbuffer_overlapped_get_fd_(struct evbuffer* buf); + +void evbuffer_overlapped_set_fd_(struct evbuffer* buf, evutil_socket_t fd); + +/** Start reading data onto the end of an overlapped evbuffer. + + An evbuffer can only have one read pending at a time. While the read + is in progress, no other data may be added to the end of the buffer. + The buffer must be created with event_overlapped_init_(). + evbuffer_commit_read_() must be called in the completion callback. + + @param buf The buffer to read onto + @param n The number of bytes to try to read. + @param ol Overlapped object with associated completion callback. + @return 0 on success, -1 on error. + */ +int evbuffer_launch_read_(struct evbuffer* buf, size_t n, struct event_overlapped* ol); + +/** Start writing data from the start of an evbuffer. + + An evbuffer can only have one write pending at a time. While the write is + in progress, no other data may be removed from the front of the buffer. + The buffer must be created with event_overlapped_init_(). + evbuffer_commit_write_() must be called in the completion callback. + + @param buf The buffer to read onto + @param n The number of bytes to try to read. + @param ol Overlapped object with associated completion callback. + @return 0 on success, -1 on error. + */ +int evbuffer_launch_write_(struct evbuffer* buf, ev_ssize_t n, struct event_overlapped* ol); + +/** XXX document */ +void evbuffer_commit_read_(struct evbuffer*, ev_ssize_t); +void evbuffer_commit_write_(struct evbuffer*, ev_ssize_t); + +/** Create an IOCP, and launch its worker threads. Internal use only. + + This interface is unstable, and will change. + */ +struct event_iocp_port* event_iocp_port_launch_(int n_cpus); + +/** Associate a file descriptor with an iocp, such that overlapped IO on the + fd will happen on one of the iocp's worker threads. +*/ +int event_iocp_port_associate_(struct event_iocp_port* port, evutil_socket_t fd, ev_uintptr_t key); + +/** Tell all threads serving an iocp to stop. Wait for up to waitMsec for all + the threads to finish whatever they're doing. If waitMsec is -1, wait + as long as required. If all the threads are done, free the port and return + 0. Otherwise, return -1. If you get a -1 return value, it is safe to call + this function again. +*/ +int event_iocp_shutdown_(struct event_iocp_port* port, long waitMsec); + +/* FIXME document. */ +int event_iocp_activate_overlapped_(struct event_iocp_port* port, struct event_overlapped* o, ev_uintptr_t key, ev_uint32_t n_bytes); + +struct event_base; +/* FIXME document. */ +struct event_iocp_port* event_base_get_iocp_(struct event_base* base); + +/* FIXME document. */ +int event_base_start_iocp_(struct event_base* base, int n_cpus); +void event_base_stop_iocp_(struct event_base* base); + +/* FIXME document. */ +struct bufferevent* bufferevent_async_new_(struct event_base* base, evutil_socket_t fd, int options); + +/* FIXME document. */ +void bufferevent_async_set_connected_(struct bufferevent* bev); +int bufferevent_async_can_connect_(struct bufferevent* bev); +int bufferevent_async_connect_(struct bufferevent* bev, evutil_socket_t fd, const struct sockaddr* sa, int socklen); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/ipv6-internal.h b/asynio/event/ipv6-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..520ac1c97f19296014699d98a059cf3c6e524e2b --- /dev/null +++ b/asynio/event/ipv6-internal.h @@ -0,0 +1,49 @@ +#ifndef IPV6_INTERNAL_H_INCLUDED_ +#define IPV6_INTERNAL_H_INCLUDED_ + +#include "evconfig.h" + +#include + +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif + +#include "util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef EVENT__HAVE_STRUCT_IN6_ADDR +struct in6_addr { + ev_uint8_t s6_addr[16]; +}; +#endif + +#ifndef EVENT__HAVE_SA_FAMILY_T +// typedef int sa_family_t; +#endif + +#ifndef EVENT__HAVE_STRUCT_SOCKADDR_IN6 +struct sockaddr_in6 { + /* This will fail if we find a struct sockaddr that doesn't have + * sa_family as the first element. */ + sa_family_t sin6_family; + ev_uint16_t sin6_port; + struct in6_addr sin6_addr; +}; +#endif + +#ifndef AF_INET6 +#define AF_INET6 3333 +#endif +#ifndef PF_INET6 +#define PF_INET6 AF_INET6 +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/keyvalq_struct.h b/asynio/event/keyvalq_struct.h new file mode 100644 index 0000000000000000000000000000000000000000..6811e8580d890f1f0b867b8eedc71d1d2da699af --- /dev/null +++ b/asynio/event/keyvalq_struct.h @@ -0,0 +1,54 @@ +#ifndef EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ +#define EVENT2_KEYVALQ_STRUCT_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Fix so that people don't have to run with */ +/* XXXX This code is duplicated with event_struct.h */ +#ifndef TAILQ_ENTRY +#define EVENT_DEFINED_TQENTRY_ +#define TAILQ_ENTRY(type) \ + struct { \ + struct type* tqe_next; /* next element */ \ + struct type** tqe_prev; /* address of previous next element */ \ + } +#endif /* !TAILQ_ENTRY */ + +#ifndef TAILQ_HEAD +#define EVENT_DEFINED_TQHEAD_ +#define TAILQ_HEAD(name, type) \ + struct name { \ + struct type* tqh_first; \ + struct type** tqh_last; \ + } +#endif + +/* + * Key-Value pairs. Can be used for HTTP headers but also for + * query argument parsing. + */ +struct evkeyval { + TAILQ_ENTRY(evkeyval) next; + + char* key; + char* value; +}; + +TAILQ_HEAD(evkeyvalq, evkeyval); + +/* XXXX This code is duplicated with event_struct.h */ +#ifdef EVENT_DEFINED_TQENTRY_ +#undef TAILQ_ENTRY +#endif + +#ifdef EVENT_DEFINED_TQHEAD_ +#undef TAILQ_HEAD +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/kqueue-internal.h b/asynio/event/kqueue-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..e170b2cdcfd1e9fcf305fd09f337db5090a4d482 --- /dev/null +++ b/asynio/event/kqueue-internal.h @@ -0,0 +1,14 @@ +#ifndef KQUEUE_INTERNAL_H_INCLUDED_ +#define KQUEUE_INTERNAL_H_INCLUDED_ + +/** Notification function, used to tell an event base to wake up from another + * thread. Only works when event_kq_add_notify_event_() has previously been + * called successfully on that base. */ +int event_kq_notify_base_(struct event_base* base); + +/** Prepare a kqueue-using event base to receive notifications via an internal + * EVFILT_USER event. Return 0 on sucess, -1 on failure. + */ +int event_kq_add_notify_event_(struct event_base* base); + +#endif diff --git a/asynio/event/kqueue.c b/asynio/event/kqueue.c new file mode 100644 index 0000000000000000000000000000000000000000..e25af689cb79ecd7b4fa4aafe3df283a35311a4f --- /dev/null +++ b/asynio/event/kqueue.c @@ -0,0 +1,528 @@ +/* $OpenBSD: kqueue.c,v 1.5 2002/07/10 14:41:31 art Exp $ */ + +/* + * Copyright 2000-2007 Niels Provos + * Copyright 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef EVENT__HAVE_KQUEUE + +#include +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef EVENT__HAVE_INTTYPES_H +#include +#endif + +/* Some platforms apparently define the udata field of struct kevent as + * intptr_t, whereas others define it as void*. There doesn't seem to be an + * easy way to tell them apart via autoconf, so we need to use OS macros. */ +#if defined(EVENT__HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__) \ + && !defined(__CloudABI__) +#define PTR_TO_UDATA(x) ((intptr_t)(x)) +#define INT_TO_UDATA(x) ((intptr_t)(x)) +#else +#define PTR_TO_UDATA(x) (x) +#define INT_TO_UDATA(x) ((void*)(x)) +#endif + +#include "evconfig-internal.h" + +#define NEVENT 64 + +struct kqop { + struct kevent* changes; + int changes_size; + + struct kevent* events; + int events_size; + int kq; + int notify_event_added; + pid_t pid; +}; + +static void kqop_free(struct kqop* kqop); + +static void* kq_init(struct event_base*); +static int kq_sig_add(struct event_base*, int, short, short, void*); +static int kq_sig_del(struct event_base*, int, short, short, void*); +static int kq_dispatch(struct event_base*, struct timeval*); +static void kq_dealloc(struct event_base*); + +const struct eventop kqops = { + "kqueue", + kq_init, + event_changelist_add_, + event_changelist_del_, + kq_dispatch, + kq_dealloc, + 1 /* need reinit */, + EV_FEATURE_ET | EV_FEATURE_O1 | EV_FEATURE_FDS, + EVENT_CHANGELIST_FDINFO_SIZE}; + +static const struct eventop kqsigops = {"kqueue_signal", NULL, kq_sig_add, kq_sig_del, NULL, NULL, 1 /* need reinit */, 0, 0}; + +static void* kq_init(struct event_base* base) +{ + int kq = -1; + struct kqop* kqueueop = NULL; + + if (!(kqueueop = mm_calloc(1, sizeof(struct kqop)))) + return (NULL); + + /* Initialize the kernel queue */ + + if ((kq = kqueue()) == -1) { + event_warn("kqueue"); + goto err; + } + + kqueueop->kq = kq; + + kqueueop->pid = getpid(); + + /* Initialize fields */ + kqueueop->changes = mm_calloc(NEVENT, sizeof(struct kevent)); + if (kqueueop->changes == NULL) + goto err; + kqueueop->events = mm_calloc(NEVENT, sizeof(struct kevent)); + if (kqueueop->events == NULL) + goto err; + kqueueop->events_size = kqueueop->changes_size = NEVENT; + + /* Check for Mac OS X kqueue bug. */ + memset(&kqueueop->changes[0], 0, sizeof kqueueop->changes[0]); + kqueueop->changes[0].ident = -1; + kqueueop->changes[0].filter = EVFILT_READ; + kqueueop->changes[0].flags = EV_ADD; + /* + * If kqueue works, then kevent will succeed, and it will + * stick an error in events[0]. If kqueue is broken, then + * kevent will fail. + */ + if (kevent(kq, kqueueop->changes, 1, kqueueop->events, NEVENT, NULL) != 1 || (int)kqueueop->events[0].ident != -1 + || !(kqueueop->events[0].flags & EV_ERROR)) { + event_warn("%s: detected broken kqueue; not using.", __func__); + goto err; + } + + base->evsigsel = &kqsigops; + + return (kqueueop); +err: + if (kqueueop) + kqop_free(kqueueop); + + return (NULL); +} + +#define ADD_UDATA 0x30303 + +static void kq_setup_kevent(struct kevent* out, evutil_socket_t fd, int filter, short change) +{ + memset(out, 0, sizeof(struct kevent)); + out->ident = fd; + out->filter = filter; + + if (change & EV_CHANGE_ADD) { + out->flags = EV_ADD; + /* We set a magic number here so that we can tell 'add' + * errors from 'del' errors. */ + out->udata = INT_TO_UDATA(ADD_UDATA); + if (change & EV_ET) + out->flags |= EV_CLEAR; +#ifdef NOTE_EOF + /* Make it behave like select() and poll() */ + if (filter == EVFILT_READ) + out->fflags = NOTE_EOF; +#endif + } else { + EVUTIL_ASSERT(change & EV_CHANGE_DEL); + out->flags = EV_DELETE; + } +} + +static int kq_build_changes_list(const struct event_changelist* changelist, struct kqop* kqop) +{ + int i; + int n_changes = 0; + + for (i = 0; i < changelist->n_changes; ++i) { + struct event_change* in_ch = &changelist->changes[i]; + struct kevent* out_ch; + if (n_changes >= kqop->changes_size - 1) { + int newsize = kqop->changes_size * 2; + struct kevent* newchanges; + + newchanges = mm_realloc(kqop->changes, newsize * sizeof(struct kevent)); + if (newchanges == NULL) { + event_warn("%s: realloc", __func__); + return (-1); + } + kqop->changes = newchanges; + kqop->changes_size = newsize; + } + if (in_ch->read_change) { + out_ch = &kqop->changes[n_changes++]; + kq_setup_kevent(out_ch, in_ch->fd, EVFILT_READ, in_ch->read_change); + } + if (in_ch->write_change) { + out_ch = &kqop->changes[n_changes++]; + kq_setup_kevent(out_ch, in_ch->fd, EVFILT_WRITE, in_ch->write_change); + } + } + return n_changes; +} + +static int kq_grow_events(struct kqop* kqop, size_t new_size) +{ + struct kevent* newresult; + + newresult = mm_realloc(kqop->events, new_size * sizeof(struct kevent)); + + if (newresult) { + kqop->events = newresult; + kqop->events_size = new_size; + return 0; + } else { + return -1; + } +} + +static int kq_dispatch(struct event_base* base, struct timeval* tv) +{ + struct kqop* kqop = base->evbase; + struct kevent* events = kqop->events; + struct kevent* changes; + struct timespec ts, *ts_p = NULL; + int i, n_changes, res; + + if (tv != NULL) { + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + ts_p = &ts; + } + + /* Build "changes" from "base->changes" */ + EVUTIL_ASSERT(kqop->changes); + n_changes = kq_build_changes_list(&base->changelist, kqop); + if (n_changes < 0) + return -1; + + event_changelist_remove_all_(&base->changelist, base); + + /* steal the changes array in case some broken code tries to call + * dispatch twice at once. */ + changes = kqop->changes; + kqop->changes = NULL; + + /* Make sure that 'events' is at least as long as the list of changes: + * otherwise errors in the changes can get reported as a -1 return + * value from kevent() rather than as EV_ERROR events in the events + * array. + * + * (We could instead handle -1 return values from kevent() by + * retrying with a smaller changes array or a larger events array, + * but this approach seems less risky for now.) + */ + if (kqop->events_size < n_changes) { + int new_size = kqop->events_size; + do { + new_size *= 2; + } while (new_size < n_changes); + + kq_grow_events(kqop, new_size); + events = kqop->events; + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + res = kevent(kqop->kq, changes, n_changes, events, kqop->events_size, ts_p); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + EVUTIL_ASSERT(kqop->changes == NULL); + kqop->changes = changes; + + if (res == -1) { + if (errno != EINTR) { + event_warn("kevent"); + return (-1); + } + + return (0); + } + + event_debug(("%s: kevent reports %d", __func__, res)); + + for (i = 0; i < res; i++) { + int which = 0; + + if (events[i].flags & EV_ERROR) { + switch (events[i].data) { + /* Can occur on delete if we are not currently + * watching any events on this fd. That can + * happen when the fd was closed and another + * file was opened with that fd. */ + case ENOENT: + /* Can occur for reasons not fully understood + * on FreeBSD. */ + case EINVAL: + continue; +#if defined(__FreeBSD__) + /* + * This currently occurs if an FD is closed + * before the EV_DELETE makes it out via kevent(). + * The FreeBSD capabilities code sees the blank + * capability set and rejects the request to + * modify an event. + * + * To be strictly correct - when an FD is closed, + * all the registered events are also removed. + * Queuing EV_DELETE to a closed FD is wrong. + * The event(s) should just be deleted from + * the pending changelist. + */ + case ENOTCAPABLE: + continue; +#endif + + /* Can occur on a delete if the fd is closed. */ + case EBADF: + /* XXXX On NetBSD, we can also get EBADF if we + * try to add the write side of a pipe, but + * the read side has already been closed. + * Other BSDs call this situation 'EPIPE'. It + * would be good if we had a way to report + * this situation. */ + continue; + /* These two can occur on an add if the fd was one side + * of a pipe, and the other side was closed. */ + case EPERM: + case EPIPE: + /* Report read events, if we're listening for + * them, so that the user can learn about any + * add errors. (If the operation was a + * delete, then udata should be cleared.) */ + if (events[i].udata) { + /* The operation was an add: + * report the error as a read. */ + which |= EV_READ; + break; + } else { + /* The operation was a del: + * report nothing. */ + continue; + } + + /* Other errors shouldn't occur. */ + default: + errno = events[i].data; + return (-1); + } + } else if (events[i].filter == EVFILT_READ) { + which |= EV_READ; + } else if (events[i].filter == EVFILT_WRITE) { + which |= EV_WRITE; + } else if (events[i].filter == EVFILT_SIGNAL) { + which |= EV_SIGNAL; +#ifdef EVFILT_USER + } else if (events[i].filter == EVFILT_USER) { + base->is_notify_pending = 0; +#endif + } + + if (!which) + continue; + + if (events[i].filter == EVFILT_SIGNAL) { + evmap_signal_active_(base, events[i].ident, 1); + } else { + evmap_io_active_(base, events[i].ident, which | EV_ET); + } + } + + if (res == kqop->events_size) { + /* We used all the events space that we have. Maybe we should + make it bigger. */ + kq_grow_events(kqop, kqop->events_size * 2); + } + + return (0); +} + +static void kqop_free(struct kqop* kqop) +{ + if (kqop->changes) + mm_free(kqop->changes); + if (kqop->events) + mm_free(kqop->events); + if (kqop->kq >= 0 && kqop->pid == getpid()) + close(kqop->kq); + memset(kqop, 0, sizeof(struct kqop)); + mm_free(kqop); +} + +static void kq_dealloc(struct event_base* base) +{ + struct kqop* kqop = base->evbase; + evsig_dealloc_(base); + kqop_free(kqop); +} + +/* signal handling */ +static int kq_sig_add(struct event_base* base, int nsignal, short old, short events, void* p) +{ + struct kqop* kqop = base->evbase; + struct kevent kev; + struct timespec timeout = {0, 0}; + (void)p; + + EVUTIL_ASSERT(nsignal >= 0 && nsignal < NSIG); + + memset(&kev, 0, sizeof(kev)); + kev.ident = nsignal; + kev.filter = EVFILT_SIGNAL; + kev.flags = EV_ADD; + + /* Be ready for the signal if it is sent any + * time between now and the next call to + * kq_dispatch. */ + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) + return (-1); + + /* We can set the handler for most signals to SIG_IGN and + * still have them reported to us in the queue. However, + * if the handler for SIGCHLD is SIG_IGN, the system reaps + * zombie processes for us, and we don't get any notification. + * This appears to be the only signal with this quirk. */ + if (evsig_set_handler_(base, nsignal, nsignal == SIGCHLD ? SIG_DFL : SIG_IGN) == -1) + return (-1); + + return (0); +} + +static int kq_sig_del(struct event_base* base, int nsignal, short old, short events, void* p) +{ + struct kqop* kqop = base->evbase; + struct kevent kev; + + struct timespec timeout = {0, 0}; + (void)p; + + EVUTIL_ASSERT(nsignal >= 0 && nsignal < NSIG); + + memset(&kev, 0, sizeof(kev)); + kev.ident = nsignal; + kev.filter = EVFILT_SIGNAL; + kev.flags = EV_DELETE; + + /* Because we insert signal events + * immediately, we need to delete them + * immediately, too */ + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) + return (-1); + + if (evsig_restore_handler_(base, nsignal) == -1) + return (-1); + + return (0); +} + +/* OSX 10.6 and FreeBSD 8.1 add support for EVFILT_USER, which we can use + * to wake up the event loop from another thread. */ + +/* Magic number we use for our filter ID. */ +#define NOTIFY_IDENT 42 + +int event_kq_add_notify_event_(struct event_base* base) +{ + struct kqop* kqop = base->evbase; +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + struct kevent kev; + struct timespec timeout = {0, 0}; +#endif + + if (kqop->notify_event_added) + return 0; + +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + memset(&kev, 0, sizeof(kev)); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.flags = EV_ADD | EV_CLEAR; + + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { + event_warn("kevent: adding EVFILT_USER event"); + return -1; + } + + kqop->notify_event_added = 1; + + return 0; +#else + return -1; +#endif +} + +int event_kq_notify_base_(struct event_base* base) +{ + struct kqop* kqop = base->evbase; +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + struct kevent kev; + struct timespec timeout = {0, 0}; +#endif + if (!kqop->notify_event_added) + return -1; + +#if defined(EVFILT_USER) && defined(NOTE_TRIGGER) + memset(&kev, 0, sizeof(kev)); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.fflags = NOTE_TRIGGER; + + if (kevent(kqop->kq, &kev, 1, NULL, 0, &timeout) == -1) { + event_warn("kevent: triggering EVFILT_USER event"); + return -1; + } + + return 0; +#else + return -1; +#endif +} + +#endif /* EVENT__HAVE_KQUEUE */ diff --git a/asynio/event/listener.c b/asynio/event/listener.c new file mode 100644 index 0000000000000000000000000000000000000000..d4bc67b756519f7ecaaf12ff916761d4d72a13b3 --- /dev/null +++ b/asynio/event/listener.c @@ -0,0 +1,804 @@ +/* + * Copyright (c) 2009-2012 Niels Provos, Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#include + +#ifdef _WIN32 +#ifndef _WIN32_WINNT +/* Minimum required for InitializeCriticalSectionAndSpinCount */ +#define _WIN32_WINNT 0x0403 +#endif +#include +#include +#include +#endif +#include +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif +#ifdef EVENT__HAVE_FCNTL_H +#include +#endif +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif + +#include "listener.h" +#include "util.h" +#include "eventbase.h" +#include "event_struct.h" + +#include "evconfig-internal.h" + +#ifdef _WIN32 +#include "iocp-internal.h" +#include "defer-internal.h" +#include "event-internal.h" +#endif + +struct evconnlistener_ops { + int (*enable)(struct evconnlistener*); + int (*disable)(struct evconnlistener*); + void (*destroy)(struct evconnlistener*); + void (*shutdown)(struct evconnlistener*); + evutil_socket_t (*getfd)(struct evconnlistener*); + struct event_base* (*getbase)(struct evconnlistener*); +}; + +struct evconnlistener { + const struct evconnlistener_ops* ops; + void* lock; + evconnlistener_cb cb; + evconnlistener_errorcb errorcb; + void* user_data; + unsigned flags; + short refcnt; + int accept4_flags; + unsigned enabled : 1; +}; + +struct evconnlistener_event { + struct evconnlistener base; + struct event listener; +}; + +#ifdef _WIN32 +struct evconnlistener_iocp { + struct evconnlistener base; + evutil_socket_t fd; + struct event_base* event_base; + struct event_iocp_port* port; + short n_accepting; + unsigned shutting_down : 1; + unsigned event_added : 1; + struct accepting_socket** accepting; +}; +#endif + +#define LOCK(listener) EVLOCK_LOCK((listener)->lock, 0) +#define UNLOCK(listener) EVLOCK_UNLOCK((listener)->lock, 0) + +struct evconnlistener* evconnlistener_new_async( + struct event_base* base, evconnlistener_cb cb, void* ptr, unsigned flags, int backlog, evutil_socket_t fd); /* XXXX export this? */ + +static int event_listener_enable(struct evconnlistener*); +static int event_listener_disable(struct evconnlistener*); +static void event_listener_destroy(struct evconnlistener*); +static evutil_socket_t event_listener_getfd(struct evconnlistener*); +static struct event_base* event_listener_getbase(struct evconnlistener*); + +#if 0 +static void +listener_incref_and_lock(struct evconnlistener *listener) +{ + LOCK(listener); + ++listener->refcnt; +} +#endif + +static int listener_decref_and_unlock(struct evconnlistener* listener) +{ + int refcnt = --listener->refcnt; + if (refcnt == 0) { + listener->ops->destroy(listener); + UNLOCK(listener); + EVTHREAD_FREE_LOCK(listener->lock, EVTHREAD_LOCKTYPE_RECURSIVE); + mm_free(listener); + return 1; + } else { + UNLOCK(listener); + return 0; + } +} + +static const struct evconnlistener_ops evconnlistener_event_ops = {event_listener_enable, event_listener_disable, + event_listener_destroy, NULL, /* shutdown */ + event_listener_getfd, event_listener_getbase}; + +static void listener_read_cb(evutil_socket_t, short, void*); + +struct evconnlistener* evconnlistener_new(struct event_base* base, evconnlistener_cb cb, void* ptr, unsigned flags, int backlog, evutil_socket_t fd) +{ + struct evconnlistener_event* lev; + +#ifdef _WIN32 + if (base && event_base_get_iocp_(base)) { + const struct win32_extension_fns* ext = event_get_win32_extension_fns_(); + if (ext->AcceptEx && ext->GetAcceptExSockaddrs) + return evconnlistener_new_async(base, cb, ptr, flags, backlog, fd); + } +#endif + + if (backlog > 0) { + if (listen(fd, backlog) < 0) + return NULL; + } else if (backlog < 0) { + if (listen(fd, 128) < 0) + return NULL; + } + + lev = mm_calloc(1, sizeof(struct evconnlistener_event)); + if (!lev) + return NULL; + + lev->base.ops = &evconnlistener_event_ops; + lev->base.cb = cb; + lev->base.user_data = ptr; + lev->base.flags = flags; + lev->base.refcnt = 1; + + lev->base.accept4_flags = 0; + if (!(flags & LEV_OPT_LEAVE_SOCKETS_BLOCKING)) + lev->base.accept4_flags |= EVUTIL_SOCK_NONBLOCK; + if (flags & LEV_OPT_CLOSE_ON_EXEC) + lev->base.accept4_flags |= EVUTIL_SOCK_CLOEXEC; + + if (flags & LEV_OPT_THREADSAFE) { + EVTHREAD_ALLOC_LOCK(lev->base.lock, EVTHREAD_LOCKTYPE_RECURSIVE); + } + + event_assign(&lev->listener, base, fd, EV_READ | EV_PERSIST, listener_read_cb, lev); + + if (!(flags & LEV_OPT_DISABLED)) + evconnlistener_enable(&lev->base); + + return &lev->base; +} + +struct evconnlistener* evconnlistener_new_bind( + struct event_base* base, evconnlistener_cb cb, void* ptr, unsigned flags, int backlog, const struct sockaddr* sa, int socklen) +{ + struct evconnlistener* listener; + evutil_socket_t fd; + int on = 1; + int family = sa ? sa->sa_family : AF_UNSPEC; + int socktype = SOCK_STREAM | EVUTIL_SOCK_NONBLOCK; + + if (backlog == 0) + return NULL; + + if (flags & LEV_OPT_CLOSE_ON_EXEC) + socktype |= EVUTIL_SOCK_CLOEXEC; + + fd = evutil_socket_(family, socktype, 0); + if (fd == -1) + return NULL; + + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on)) < 0) + goto err; + + if (flags & LEV_OPT_REUSEABLE) { + if (evutil_make_listen_socket_reuseable(fd) < 0) + goto err; + } + + if (flags & LEV_OPT_REUSEABLE_PORT) { + if (evutil_make_listen_socket_reuseable_port(fd) < 0) + goto err; + } + + if (flags & LEV_OPT_DEFERRED_ACCEPT) { + if (evutil_make_tcp_listen_socket_deferred(fd) < 0) + goto err; + } + + if (sa) { + if (bind(fd, sa, socklen) < 0) + goto err; + } + + listener = evconnlistener_new(base, cb, ptr, flags, backlog, fd); + if (!listener) + goto err; + + return listener; +err: + evutil_closesocket(fd); + return NULL; +} + +void evconnlistener_free(struct evconnlistener* lev) +{ + LOCK(lev); + lev->cb = NULL; + lev->errorcb = NULL; + if (lev->ops->shutdown) + lev->ops->shutdown(lev); + listener_decref_and_unlock(lev); +} + +static void event_listener_destroy(struct evconnlistener* lev) +{ + struct evconnlistener_event* lev_e = EVUTIL_UPCAST(lev, struct evconnlistener_event, base); + + event_del(&lev_e->listener); + if (lev->flags & LEV_OPT_CLOSE_ON_FREE) + evutil_closesocket(event_get_fd(&lev_e->listener)); + event_debug_unassign(&lev_e->listener); +} + +int evconnlistener_enable(struct evconnlistener* lev) +{ + int r; + LOCK(lev); + lev->enabled = 1; + if (lev->cb) + r = lev->ops->enable(lev); + else + r = 0; + UNLOCK(lev); + return r; +} + +int evconnlistener_disable(struct evconnlistener* lev) +{ + int r; + LOCK(lev); + lev->enabled = 0; + r = lev->ops->disable(lev); + UNLOCK(lev); + return r; +} + +static int event_listener_enable(struct evconnlistener* lev) +{ + struct evconnlistener_event* lev_e = EVUTIL_UPCAST(lev, struct evconnlistener_event, base); + return event_add(&lev_e->listener, NULL); +} + +static int event_listener_disable(struct evconnlistener* lev) +{ + struct evconnlistener_event* lev_e = EVUTIL_UPCAST(lev, struct evconnlistener_event, base); + return event_del(&lev_e->listener); +} + +evutil_socket_t evconnlistener_get_fd(struct evconnlistener* lev) +{ + evutil_socket_t fd; + LOCK(lev); + fd = lev->ops->getfd(lev); + UNLOCK(lev); + return fd; +} + +static evutil_socket_t event_listener_getfd(struct evconnlistener* lev) +{ + struct evconnlistener_event* lev_e = EVUTIL_UPCAST(lev, struct evconnlistener_event, base); + return event_get_fd(&lev_e->listener); +} + +struct event_base* evconnlistener_get_base(struct evconnlistener* lev) +{ + struct event_base* base; + LOCK(lev); + base = lev->ops->getbase(lev); + UNLOCK(lev); + return base; +} + +static struct event_base* event_listener_getbase(struct evconnlistener* lev) +{ + struct evconnlistener_event* lev_e = EVUTIL_UPCAST(lev, struct evconnlistener_event, base); + return event_get_base(&lev_e->listener); +} + +void evconnlistener_set_cb(struct evconnlistener* lev, evconnlistener_cb cb, void* arg) +{ + int enable = 0; + LOCK(lev); + if (lev->enabled && !lev->cb) + enable = 1; + lev->cb = cb; + lev->user_data = arg; + if (enable) + evconnlistener_enable(lev); + UNLOCK(lev); +} + +void evconnlistener_set_error_cb(struct evconnlistener* lev, evconnlistener_errorcb errorcb) +{ + LOCK(lev); + lev->errorcb = errorcb; + UNLOCK(lev); +} + +static void listener_read_cb(evutil_socket_t fd, short what, void* p) +{ + struct evconnlistener* lev = p; + int err; + evconnlistener_cb cb; + evconnlistener_errorcb errorcb; + void* user_data; + LOCK(lev); + while (1) { + struct sockaddr_storage ss; + ev_socklen_t socklen = sizeof(ss); + evutil_socket_t new_fd = evutil_accept4_(fd, (struct sockaddr*)&ss, &socklen, lev->accept4_flags); + if (new_fd < 0) + break; + if (socklen == 0) { + /* This can happen with some older linux kernels in + * response to nmap. */ + evutil_closesocket(new_fd); + continue; + } + + if (lev->cb == NULL) { + evutil_closesocket(new_fd); + UNLOCK(lev); + return; + } + ++lev->refcnt; + cb = lev->cb; + user_data = lev->user_data; + UNLOCK(lev); + cb(lev, new_fd, (struct sockaddr*)&ss, (int)socklen, user_data); + LOCK(lev); + if (lev->refcnt == 1) { + int freed = listener_decref_and_unlock(lev); + EVUTIL_ASSERT(freed); + + evutil_closesocket(new_fd); + return; + } + --lev->refcnt; + } + err = evutil_socket_geterror(fd); + if (EVUTIL_ERR_ACCEPT_RETRIABLE(err)) { + UNLOCK(lev); + return; + } + if (lev->errorcb != NULL) { + ++lev->refcnt; + errorcb = lev->errorcb; + user_data = lev->user_data; + UNLOCK(lev); + errorcb(lev, user_data); + LOCK(lev); + listener_decref_and_unlock(lev); + } else { + event_sock_warn(fd, "Error from accept() call"); + UNLOCK(lev); + } +} + +#ifdef _WIN32 +struct accepting_socket { + CRITICAL_SECTION lock; + struct event_overlapped overlapped; + SOCKET s; + int error; + struct event_callback deferred; + struct evconnlistener_iocp* lev; + ev_uint8_t buflen; + ev_uint8_t family; + unsigned free_on_cb : 1; + char addrbuf[1]; +}; + +static void accepted_socket_cb(struct event_overlapped* o, ev_uintptr_t key, ev_ssize_t n, int ok); +static void accepted_socket_invoke_user_cb(struct event_callback* cb, void* arg); + +static void iocp_listener_event_add(struct evconnlistener_iocp* lev) +{ + if (lev->event_added) + return; + + lev->event_added = 1; + event_base_add_virtual_(lev->event_base); +} + +static void iocp_listener_event_del(struct evconnlistener_iocp* lev) +{ + if (!lev->event_added) + return; + + lev->event_added = 0; + event_base_del_virtual_(lev->event_base); +} + +static struct accepting_socket* new_accepting_socket(struct evconnlistener_iocp* lev, int family) +{ + struct accepting_socket* res; + int addrlen; + int buflen; + + if (family == AF_INET) + addrlen = sizeof(struct sockaddr_in); + else if (family == AF_INET6) + addrlen = sizeof(struct sockaddr_in6); + else + return NULL; + buflen = (addrlen + 16) * 2; + + res = mm_calloc(1, sizeof(struct accepting_socket) - 1 + buflen); + if (!res) + return NULL; + + event_overlapped_init_(&res->overlapped, accepted_socket_cb); + res->s = INVALID_SOCKET; + res->lev = lev; + res->buflen = buflen; + res->family = family; + + event_deferred_cb_init_(&res->deferred, event_base_get_npriorities(lev->event_base) / 2, accepted_socket_invoke_user_cb, res); + + InitializeCriticalSectionAndSpinCount(&res->lock, 1000); + + return res; +} + +static void free_and_unlock_accepting_socket(struct accepting_socket* as) +{ + /* requires lock. */ + if (as->s != INVALID_SOCKET) + closesocket(as->s); + + LeaveCriticalSection(&as->lock); + DeleteCriticalSection(&as->lock); + mm_free(as); +} + +static int start_accepting(struct accepting_socket* as) +{ + /* requires lock */ + const struct win32_extension_fns* ext = event_get_win32_extension_fns_(); + DWORD pending = 0; + SOCKET s = socket(as->family, SOCK_STREAM, 0); + int error = 0; + + if (!as->lev->base.enabled) + return 0; + + if (s == INVALID_SOCKET) { + error = WSAGetLastError(); + goto report_err; + } + + /* XXXX It turns out we need to do this again later. Does this call + * have any effect? */ + setsockopt(s, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char*)&as->lev->fd, sizeof(&as->lev->fd)); + + if (!(as->lev->base.flags & LEV_OPT_LEAVE_SOCKETS_BLOCKING)) + evutil_make_socket_nonblocking(s); + + if (event_iocp_port_associate_(as->lev->port, s, 1) < 0) { + closesocket(s); + return -1; + } + + as->s = s; + + if (ext->AcceptEx(as->lev->fd, s, as->addrbuf, 0, as->buflen / 2, as->buflen / 2, &pending, &as->overlapped.overlapped)) { + /* Immediate success! */ + accepted_socket_cb(&as->overlapped, 1, 0, 1); + } else { + error = WSAGetLastError(); + if (error != ERROR_IO_PENDING) { + goto report_err; + } + } + + return 0; + +report_err: + as->error = error; + event_deferred_cb_schedule_(as->lev->event_base, &as->deferred); + return 0; +} + +static void stop_accepting(struct accepting_socket* as) +{ + /* requires lock. */ + SOCKET s = as->s; + as->s = INVALID_SOCKET; + closesocket(s); +} + +static void accepted_socket_invoke_user_cb(struct event_callback* dcb, void* arg) +{ + struct accepting_socket* as = arg; + + struct sockaddr *sa_local = NULL, *sa_remote = NULL; + int socklen_local = 0, socklen_remote = 0; + const struct win32_extension_fns* ext = event_get_win32_extension_fns_(); + struct evconnlistener* lev = &as->lev->base; + evutil_socket_t sock = -1; + void* data; + evconnlistener_cb cb = NULL; + evconnlistener_errorcb errorcb = NULL; + int error; + + EVUTIL_ASSERT(ext->GetAcceptExSockaddrs); + + LOCK(lev); + EnterCriticalSection(&as->lock); + if (as->free_on_cb) { + free_and_unlock_accepting_socket(as); + listener_decref_and_unlock(lev); + return; + } + + ++lev->refcnt; + + error = as->error; + if (error) { + as->error = 0; + errorcb = lev->errorcb; + } else { + ext->GetAcceptExSockaddrs(as->addrbuf, 0, as->buflen / 2, as->buflen / 2, &sa_local, &socklen_local, &sa_remote, &socklen_remote); + sock = as->s; + cb = lev->cb; + as->s = INVALID_SOCKET; + + /* We need to call this so getsockname, getpeername, and + * shutdown work correctly on the accepted socket. */ + /* XXXX handle error? */ + setsockopt(sock, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char*)&as->lev->fd, sizeof(&as->lev->fd)); + } + data = lev->user_data; + + LeaveCriticalSection(&as->lock); + UNLOCK(lev); + + if (errorcb) { + WSASetLastError(error); + errorcb(lev, data); + } else if (cb) { + cb(lev, sock, sa_remote, socklen_remote, data); + } + + LOCK(lev); + if (listener_decref_and_unlock(lev)) + return; + + EnterCriticalSection(&as->lock); + start_accepting(as); + LeaveCriticalSection(&as->lock); +} + +static void accepted_socket_cb(struct event_overlapped* o, ev_uintptr_t key, ev_ssize_t n, int ok) +{ + struct accepting_socket* as = EVUTIL_UPCAST(o, struct accepting_socket, overlapped); + + LOCK(&as->lev->base); + EnterCriticalSection(&as->lock); + if (ok) { + /* XXXX Don't do this if some EV_MT flag is set. */ + event_deferred_cb_schedule_(as->lev->event_base, &as->deferred); + LeaveCriticalSection(&as->lock); + } else if (as->free_on_cb) { + struct evconnlistener* lev = &as->lev->base; + free_and_unlock_accepting_socket(as); + listener_decref_and_unlock(lev); + return; + } else if (as->s == INVALID_SOCKET) { + /* This is okay; we were disabled by iocp_listener_disable. */ + LeaveCriticalSection(&as->lock); + } else { + /* Some error on accept that we couldn't actually handle. */ + BOOL ok; + DWORD transfer = 0, flags = 0; + event_sock_warn(as->s, "Unexpected error on AcceptEx"); + ok = WSAGetOverlappedResult(as->s, &o->overlapped, &transfer, FALSE, &flags); + if (ok) { + /* well, that was confusing! */ + as->error = 1; + } else { + as->error = WSAGetLastError(); + } + event_deferred_cb_schedule_(as->lev->event_base, &as->deferred); + LeaveCriticalSection(&as->lock); + } + UNLOCK(&as->lev->base); +} + +static int iocp_listener_enable(struct evconnlistener* lev) +{ + int i; + struct evconnlistener_iocp* lev_iocp = EVUTIL_UPCAST(lev, struct evconnlistener_iocp, base); + + LOCK(lev); + iocp_listener_event_add(lev_iocp); + for (i = 0; i < lev_iocp->n_accepting; ++i) { + struct accepting_socket* as = lev_iocp->accepting[i]; + if (!as) + continue; + EnterCriticalSection(&as->lock); + if (!as->free_on_cb && as->s == INVALID_SOCKET) + start_accepting(as); + LeaveCriticalSection(&as->lock); + } + UNLOCK(lev); + return 0; +} + +static int iocp_listener_disable_impl(struct evconnlistener* lev, int shutdown) +{ + int i; + struct evconnlistener_iocp* lev_iocp = EVUTIL_UPCAST(lev, struct evconnlistener_iocp, base); + + LOCK(lev); + iocp_listener_event_del(lev_iocp); + for (i = 0; i < lev_iocp->n_accepting; ++i) { + struct accepting_socket* as = lev_iocp->accepting[i]; + if (!as) + continue; + EnterCriticalSection(&as->lock); + if (!as->free_on_cb && as->s != INVALID_SOCKET) { + if (shutdown) + as->free_on_cb = 1; + stop_accepting(as); + } + LeaveCriticalSection(&as->lock); + } + + if (shutdown && lev->flags & LEV_OPT_CLOSE_ON_FREE) + evutil_closesocket(lev_iocp->fd); + + UNLOCK(lev); + return 0; +} + +static int iocp_listener_disable(struct evconnlistener* lev) +{ + return iocp_listener_disable_impl(lev, 0); +} + +static void iocp_listener_destroy(struct evconnlistener* lev) +{ + struct evconnlistener_iocp* lev_iocp = EVUTIL_UPCAST(lev, struct evconnlistener_iocp, base); + + if (!lev_iocp->shutting_down) { + lev_iocp->shutting_down = 1; + iocp_listener_disable_impl(lev, 1); + } +} + +static evutil_socket_t iocp_listener_getfd(struct evconnlistener* lev) +{ + struct evconnlistener_iocp* lev_iocp = EVUTIL_UPCAST(lev, struct evconnlistener_iocp, base); + return lev_iocp->fd; +} +static struct event_base* iocp_listener_getbase(struct evconnlistener* lev) +{ + struct evconnlistener_iocp* lev_iocp = EVUTIL_UPCAST(lev, struct evconnlistener_iocp, base); + return lev_iocp->event_base; +} + +static const struct evconnlistener_ops evconnlistener_iocp_ops = {iocp_listener_enable, iocp_listener_disable, + iocp_listener_destroy, iocp_listener_destroy, /* shutdown */ + iocp_listener_getfd, iocp_listener_getbase}; + +/* XXX define some way to override this. */ +#define N_SOCKETS_PER_LISTENER 4 + +struct evconnlistener* + evconnlistener_new_async(struct event_base* base, evconnlistener_cb cb, void* ptr, unsigned flags, int backlog, evutil_socket_t fd) +{ + struct sockaddr_storage ss; + int socklen = sizeof(ss); + struct evconnlistener_iocp* lev; + int i; + + flags |= LEV_OPT_THREADSAFE; + + if (!base || !event_base_get_iocp_(base)) + goto err; + + /* XXXX duplicate code */ + if (backlog > 0) { + if (listen(fd, backlog) < 0) + goto err; + } else if (backlog < 0) { + if (listen(fd, 128) < 0) + goto err; + } + if (getsockname(fd, (struct sockaddr*)&ss, &socklen)) { + event_sock_warn(fd, "getsockname"); + goto err; + } + lev = mm_calloc(1, sizeof(struct evconnlistener_iocp)); + if (!lev) { + event_warn("calloc"); + goto err; + } + lev->base.ops = &evconnlistener_iocp_ops; + lev->base.cb = cb; + lev->base.user_data = ptr; + lev->base.flags = flags; + lev->base.refcnt = 1; + lev->base.enabled = 1; + + lev->port = event_base_get_iocp_(base); + lev->fd = fd; + lev->event_base = base; + + if (event_iocp_port_associate_(lev->port, fd, 1) < 0) + goto err_free_lev; + + EVTHREAD_ALLOC_LOCK(lev->base.lock, EVTHREAD_LOCKTYPE_RECURSIVE); + + lev->n_accepting = N_SOCKETS_PER_LISTENER; + lev->accepting = mm_calloc(lev->n_accepting, sizeof(struct accepting_socket*)); + if (!lev->accepting) { + event_warn("calloc"); + goto err_delete_lock; + } + for (i = 0; i < lev->n_accepting; ++i) { + lev->accepting[i] = new_accepting_socket(lev, ss.ss_family); + if (!lev->accepting[i]) { + event_warnx("Couldn't create accepting socket"); + goto err_free_accepting; + } + if (cb && start_accepting(lev->accepting[i]) < 0) { + event_warnx("Couldn't start accepting on socket"); + EnterCriticalSection(&lev->accepting[i]->lock); + free_and_unlock_accepting_socket(lev->accepting[i]); + goto err_free_accepting; + } + ++lev->base.refcnt; + } + + iocp_listener_event_add(lev); + + return &lev->base; + +err_free_accepting: + mm_free(lev->accepting); + /* XXXX free the other elements. */ +err_delete_lock: + EVTHREAD_FREE_LOCK(lev->base.lock, EVTHREAD_LOCKTYPE_RECURSIVE); +err_free_lev: + mm_free(lev); +err: + /* Don't close the fd, it is caller's responsibility. */ + return NULL; +} + +#endif diff --git a/asynio/event/listener.h b/asynio/event/listener.h new file mode 100644 index 0000000000000000000000000000000000000000..c7a0798d9c19b29cd09a110933f58e416d884ef2 --- /dev/null +++ b/asynio/event/listener.h @@ -0,0 +1,52 @@ + +#ifndef EVENT2_LISTENER_H_INCLUDED_ +#define EVENT2_LISTENER_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "event.h" + +struct sockaddr; +struct evconnlistener; + +typedef void (*evconnlistener_cb)(struct evconnlistener*, evutil_socket_t, struct sockaddr*, int socklen, void*); + +typedef void (*evconnlistener_errorcb)(struct evconnlistener*, void*); + +#define LEV_OPT_LEAVE_SOCKETS_BLOCKING (1u << 0) +#define LEV_OPT_CLOSE_ON_FREE (1u << 1) +#define LEV_OPT_CLOSE_ON_EXEC (1u << 2) +#define LEV_OPT_REUSEABLE (1u << 3) +#define LEV_OPT_THREADSAFE (1u << 4) +#define LEV_OPT_DISABLED (1u << 5) +#define LEV_OPT_DEFERRED_ACCEPT (1u << 6) +#define LEV_OPT_REUSEABLE_PORT (1u << 7) + +struct evconnlistener* evconnlistener_new(struct event_base* base, evconnlistener_cb cb, void* ptr, unsigned flags, int backlog, evutil_socket_t fd); + +struct evconnlistener* evconnlistener_new_bind( + struct event_base* base, evconnlistener_cb cb, void* ptr, unsigned flags, int backlog, const struct sockaddr* sa, int socklen); + +void evconnlistener_free(struct evconnlistener* lev); + +int evconnlistener_enable(struct evconnlistener* lev); + +int evconnlistener_disable(struct evconnlistener* lev); + +struct event_base* evconnlistener_get_base(struct evconnlistener* lev); + +evutil_socket_t evconnlistener_get_fd(struct evconnlistener* lev); + +void evconnlistener_set_cb(struct evconnlistener* lev, evconnlistener_cb cb, void* arg); + +void evconnlistener_set_error_cb(struct evconnlistener* lev, evconnlistener_errorcb errorcb); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/log-internal.h b/asynio/event/log-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..c9fae42f3ed5b3ffb656825599f31c2d4bcd5734 --- /dev/null +++ b/asynio/event/log-internal.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2000-2007 Niels Provos + * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef LOG_INTERNAL_H_INCLUDED_ +#define LOG_INTERNAL_H_INCLUDED_ + +#include "util.h" + +#ifdef __GNUC__ +#define EV_CHECK_FMT(a, b) __attribute__((format(printf, a, b))) +#define EV_NORETURN __attribute__((noreturn)) +#else +#define EV_CHECK_FMT(a, b) +#define EV_NORETURN +#endif + +#define EVENT_ERR_ABORT_ ((int)0xdeaddead) + +#define USE_GLOBAL_FOR_DEBUG_LOGGING + +#if !defined(EVENT__DISABLE_DEBUG_MODE) || defined(USE_DEBUG) +#define EVENT_DEBUG_LOGGING_ENABLED +#endif + +#ifdef EVENT_DEBUG_LOGGING_ENABLED +#ifdef USE_GLOBAL_FOR_DEBUG_LOGGING +extern ev_uint32_t event_debug_logging_mask_; +#define event_debug_get_logging_mask_() (event_debug_logging_mask_) +#else +ev_uint32_t event_debug_get_logging_mask_(void); +#endif +#else +#define event_debug_get_logging_mask_() (0) +#endif + +void event_err(int eval, const char* fmt, ...) EV_CHECK_FMT(2, 3) EV_NORETURN; +void event_warn(const char* fmt, ...) EV_CHECK_FMT(1, 2); +void event_sock_err(int eval, evutil_socket_t sock, const char* fmt, ...) EV_CHECK_FMT(3, 4) EV_NORETURN; +void event_sock_warn(evutil_socket_t sock, const char* fmt, ...) EV_CHECK_FMT(2, 3); +void event_errx(int eval, const char* fmt, ...) EV_CHECK_FMT(2, 3) EV_NORETURN; +void event_warnx(const char* fmt, ...) EV_CHECK_FMT(1, 2); +void event_msgx(const char* fmt, ...) EV_CHECK_FMT(1, 2); +void event_debugx_(const char* fmt, ...) EV_CHECK_FMT(1, 2); + +void event_logv_(int severity, const char* errstr, const char* fmt, va_list ap) EV_CHECK_FMT(3, 0); + +#ifdef EVENT_DEBUG_LOGGING_ENABLED +#define event_debug(x) \ + do { \ + if (event_debug_get_logging_mask_()) { \ + event_debugx_ x; \ + } \ + } while (0) +#else +#define event_debug(x) ((void)0) +#endif + +#undef EV_CHECK_FMT + +#endif diff --git a/asynio/event/log.c b/asynio/event/log.c new file mode 100644 index 0000000000000000000000000000000000000000..80dc308f3a77c68d200c08c4b8d79163e9ce0a3b --- /dev/null +++ b/asynio/event/log.c @@ -0,0 +1,237 @@ +/* $OpenBSD: err.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */ + +/* + * log.c + * + * Based on err.c, which was adapted from OpenBSD libc *err* *warn* code. + * + * Copyright (c) 2005-2012 Niels Provos and Nick Mathewson + * + * Copyright (c) 2000 Dug Song + * + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef _WIN32 +#include +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#endif +#include +#include +#include +#include +#include +#include +#include "eventbase.h" +#include "util.h" + +#include "evconfig-internal.h" + +static void event_log(int severity, const char* msg); +static void event_exit(int errcode) EV_NORETURN; + +static event_fatal_cb fatal_fn = NULL; + +#ifdef EVENT_DEBUG_LOGGING_ENABLED +#ifdef USE_DEBUG +#define DEFAULT_MASK EVENT_DBG_ALL +#else +#define DEFAULT_MASK 0 +#endif + +#ifdef USE_GLOBAL_FOR_DEBUG_LOGGING +ev_uint32_t event_debug_logging_mask_ = DEFAULT_MASK; +#else +static ev_uint32_t event_debug_logging_mask_ = DEFAULT_MASK; +ev_uint32_t event_debug_get_logging_mask_(void) +{ + return event_debug_logging_mask_; +} +#endif +#endif /* EVENT_DEBUG_LOGGING_ENABLED */ + +void event_enable_debug_logging(ev_uint32_t which) +{ +#ifdef EVENT_DEBUG_LOGGING_ENABLED + event_debug_logging_mask_ = which; +#endif +} + +void event_set_fatal_callback(event_fatal_cb cb) +{ + fatal_fn = cb; +} + +static void event_exit(int errcode) +{ + if (fatal_fn) { + fatal_fn(errcode); + exit(errcode); /* should never be reached */ + } else if (errcode == EVENT_ERR_ABORT_) + abort(); + else + exit(errcode); +} + +void event_err(int eval, const char* fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + event_logv_(EVENT_LOG_ERR, strerror(errno), fmt, ap); + va_end(ap); + event_exit(eval); +} + +void event_warn(const char* fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + event_logv_(EVENT_LOG_WARN, strerror(errno), fmt, ap); + va_end(ap); +} + +void event_sock_err(int eval, evutil_socket_t sock, const char* fmt, ...) +{ + va_list ap; + int err = evutil_socket_geterror(sock); + + va_start(ap, fmt); + event_logv_(EVENT_LOG_ERR, evutil_socket_error_to_string(err), fmt, ap); + va_end(ap); + event_exit(eval); +} + +void event_sock_warn(evutil_socket_t sock, const char* fmt, ...) +{ + va_list ap; + int err = evutil_socket_geterror(sock); + + va_start(ap, fmt); + event_logv_(EVENT_LOG_WARN, evutil_socket_error_to_string(err), fmt, ap); + va_end(ap); +} + +void event_errx(int eval, const char* fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + event_logv_(EVENT_LOG_ERR, NULL, fmt, ap); + va_end(ap); + event_exit(eval); +} + +void event_warnx(const char* fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + event_logv_(EVENT_LOG_WARN, NULL, fmt, ap); + va_end(ap); +} + +void event_msgx(const char* fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + event_logv_(EVENT_LOG_MSG, NULL, fmt, ap); + va_end(ap); +} + +void event_debugx_(const char* fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + event_logv_(EVENT_LOG_DEBUG, NULL, fmt, ap); + va_end(ap); +} + +void event_logv_(int severity, const char* errstr, const char* fmt, va_list ap) +{ + char buf[1024]; + size_t len; + + if (severity == EVENT_LOG_DEBUG && !event_debug_get_logging_mask_()) + return; + + if (fmt != NULL) + evutil_vsnprintf(buf, sizeof(buf), fmt, ap); + else + buf[0] = '\0'; + + if (errstr) { + len = strlen(buf); + if (len < sizeof(buf) - 3) { + evutil_snprintf(buf + len, sizeof(buf) - len, ": %s", errstr); + } + } + + event_log(severity, buf); +} + +static event_log_cb log_fn = NULL; + +void event_set_log_callback(event_log_cb cb) +{ + log_fn = cb; +} + +static void event_log(int severity, const char* msg) +{ + if (log_fn) + log_fn(severity, msg); + else { + const char* severity_str; + switch (severity) { + case EVENT_LOG_DEBUG: + severity_str = "debug"; + break; + case EVENT_LOG_MSG: + severity_str = "msg"; + break; + case EVENT_LOG_WARN: + severity_str = "warn"; + break; + case EVENT_LOG_ERR: + severity_str = "err"; + break; + default: + severity_str = "???"; + break; + } + (void)fprintf(stderr, "[%s] %s\n", severity_str, msg); + } +} diff --git a/asynio/event/mbedtls-compat.h b/asynio/event/mbedtls-compat.h new file mode 100644 index 0000000000000000000000000000000000000000..f24f02ff959c46af57e1115ac2f3162f2adb59f0 --- /dev/null +++ b/asynio/event/mbedtls-compat.h @@ -0,0 +1,32 @@ +#ifndef MBEDTLS_COMPAT_H +#define MBEDTLS_COMPAT_H + + +#if MBEDTLS_VERSION_MAJOR >= 3 +# if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wcpp" +# elif defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wcpp" +# endif + + +#include +#include +#include +#include +#include +#include +#include +#include + +# if defined(__clang__) +# pragma clang diagnostic pop +# elif defined(__GNUC__) +# pragma GCC diagnostic pop +# endif +#endif // MBEDTLS_VERSION_MAJOR >= 3 + + +#endif // LIBEVENT_MBEDTLS_COMPAT_H diff --git a/asynio/event/minheap-internal.h b/asynio/event/minheap-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..220b9b808bc40e2d63a6af9787400b22374b004e --- /dev/null +++ b/asynio/event/minheap-internal.h @@ -0,0 +1,174 @@ +#ifndef MINHEAP_INTERNAL_H_INCLUDED_ +#define MINHEAP_INTERNAL_H_INCLUDED_ + +#include "evconfig.h" + +#include "eventbase.h" +#include "event_struct.h" +#include "util.h" +#include "util-internal.h" +#include "mm-internal.h" + +typedef struct min_heap { + struct event** p; + unsigned n, a; +} min_heap_t; + +static inline void min_heap_ctor_(min_heap_t* s); +static inline void min_heap_dtor_(min_heap_t* s); +static inline void min_heap_elem_init_(struct event* e); +static inline int min_heap_elt_is_top_(const struct event* e); +static inline int min_heap_empty_(min_heap_t* s); +static inline unsigned min_heap_size_(min_heap_t* s); +static inline struct event* min_heap_top_(min_heap_t* s); +static inline int min_heap_reserve_(min_heap_t* s, unsigned n); +static inline int min_heap_push_(min_heap_t* s, struct event* e); +static inline struct event* min_heap_pop_(min_heap_t* s); +static inline int min_heap_adjust_(min_heap_t* s, struct event* e); +static inline int min_heap_erase_(min_heap_t* s, struct event* e); +static inline void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e); +static inline void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e); +static inline void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e); + +#define min_heap_elem_greater(a, b) (evutil_timercmp(&(a)->ev_timeout, &(b)->ev_timeout, >)) + +void min_heap_ctor_(min_heap_t* s) +{ + s->p = 0; + s->n = 0; + s->a = 0; +} +void min_heap_dtor_(min_heap_t* s) +{ + if (s->p) + mm_free(s->p); +} +void min_heap_elem_init_(struct event* e) +{ + e->ev_timeout_pos.min_heap_idx = -1; +} +int min_heap_empty_(min_heap_t* s) +{ + return 0u == s->n; +} +unsigned min_heap_size_(min_heap_t* s) +{ + return s->n; +} +struct event* min_heap_top_(min_heap_t* s) +{ + return s->n ? *s->p : 0; +} + +int min_heap_push_(min_heap_t* s, struct event* e) +{ + if (min_heap_reserve_(s, s->n + 1)) + return -1; + min_heap_shift_up_(s, s->n++, e); + return 0; +} + +struct event* min_heap_pop_(min_heap_t* s) +{ + if (s->n) { + struct event* e = *s->p; + min_heap_shift_down_(s, 0u, s->p[--s->n]); + e->ev_timeout_pos.min_heap_idx = -1; + return e; + } + return 0; +} + +int min_heap_elt_is_top_(const struct event* e) +{ + return e->ev_timeout_pos.min_heap_idx == 0; +} + +int min_heap_erase_(min_heap_t* s, struct event* e) +{ + if (-1 != e->ev_timeout_pos.min_heap_idx) { + struct event* last = s->p[--s->n]; + unsigned parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; + /* we replace e with the last element in the heap. We might need to + shift it upward if it is less than its parent, or downward if it is + greater than one or both its children. Since the children are known + to be less than the parent, it can't need to shift both up and + down. */ + if (e->ev_timeout_pos.min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], last)) + min_heap_shift_up_unconditional_(s, e->ev_timeout_pos.min_heap_idx, last); + else + min_heap_shift_down_(s, e->ev_timeout_pos.min_heap_idx, last); + e->ev_timeout_pos.min_heap_idx = -1; + return 0; + } + return -1; +} + +int min_heap_adjust_(min_heap_t* s, struct event* e) +{ + if (-1 == e->ev_timeout_pos.min_heap_idx) { + return min_heap_push_(s, e); + } else { + unsigned parent = (e->ev_timeout_pos.min_heap_idx - 1) / 2; + /* The position of e has changed; we shift it up or down + * as needed. We can't need to do both. */ + if (e->ev_timeout_pos.min_heap_idx > 0 && min_heap_elem_greater(s->p[parent], e)) + min_heap_shift_up_unconditional_(s, e->ev_timeout_pos.min_heap_idx, e); + else + min_heap_shift_down_(s, e->ev_timeout_pos.min_heap_idx, e); + return 0; + } +} + +int min_heap_reserve_(min_heap_t* s, unsigned n) +{ + if (s->a < n) { + struct event** p; + unsigned a = s->a ? s->a * 2 : 8; + if (a < n) + a = n; + if (!(p = (struct event**)mm_realloc(s->p, a * sizeof *p))) + return -1; + s->p = p; + s->a = a; + } + return 0; +} + +void min_heap_shift_up_unconditional_(min_heap_t* s, unsigned hole_index, struct event* e) +{ + unsigned parent = (hole_index - 1) / 2; + do { + (s->p[hole_index] = s->p[parent])->ev_timeout_pos.min_heap_idx = hole_index; + hole_index = parent; + parent = (hole_index - 1) / 2; + } while (hole_index && min_heap_elem_greater(s->p[parent], e)); + (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; +} + +void min_heap_shift_up_(min_heap_t* s, unsigned hole_index, struct event* e) +{ + unsigned parent = (hole_index - 1) / 2; + while (hole_index && min_heap_elem_greater(s->p[parent], e)) { + (s->p[hole_index] = s->p[parent])->ev_timeout_pos.min_heap_idx = hole_index; + hole_index = parent; + parent = (hole_index - 1) / 2; + } + (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; +} + +void min_heap_shift_down_(min_heap_t* s, unsigned hole_index, struct event* e) +{ + unsigned min_child = 2 * (hole_index + 1); + while (min_child <= s->n) { + min_child -= min_child == s->n || min_heap_elem_greater(s->p[min_child], s->p[min_child - 1]); + if (!(min_heap_elem_greater(e, s->p[min_child]))) + break; + (s->p[hole_index] = s->p[min_child])->ev_timeout_pos.min_heap_idx = hole_index; + hole_index = min_child; + min_child = 2 * (hole_index + 1); + } + (s->p[hole_index] = e)->ev_timeout_pos.min_heap_idx = hole_index; +} + +#endif /* MINHEAP_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/mm-internal.h b/asynio/event/mm-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..85ed68d90959a0b76ecdd0808c170740e113b79f --- /dev/null +++ b/asynio/event/mm-internal.h @@ -0,0 +1,20 @@ +#ifndef MM_INTERNAL_H_INCLUDED_ +#define MM_INTERNAL_H_INCLUDED_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define mm_malloc(sz) malloc(sz) +#define mm_calloc(n, sz) calloc((n), (sz)) +#define mm_strdup(s) strdup(s) +#define mm_realloc(p, sz) realloc((p), (sz)) +#define mm_free(p) free(p) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/poll.c b/asynio/event/poll.c new file mode 100644 index 0000000000000000000000000000000000000000..c2ebd2e4f15f7cd1ed36c3397e2549f77280026c --- /dev/null +++ b/asynio/event/poll.c @@ -0,0 +1,325 @@ +/* $OpenBSD: poll.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */ + +/* + * Copyright 2000-2007 Niels Provos + * Copyright 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef EVENT__HAVE_POLL + +#include +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "evconfig-internal.h" + +struct pollidx { + int idxplus1; +}; + +struct pollop { + int event_count; /* Highest number alloc */ + int nfds; /* Highest number used */ + int realloc_copy; /* True iff we must realloc + * event_set_copy */ + struct pollfd* event_set; + struct pollfd* event_set_copy; +}; + +static void* poll_init(struct event_base*); +static int poll_add(struct event_base*, int, short old, short events, void* idx); +static int poll_del(struct event_base*, int, short old, short events, void* idx); +static int poll_dispatch(struct event_base*, struct timeval*); +static void poll_dealloc(struct event_base*); + +const struct eventop pollops = { + "poll", + poll_init, + poll_add, + poll_del, + poll_dispatch, + poll_dealloc, + 0, /* doesn't need_reinit */ + EV_FEATURE_FDS, + sizeof(struct pollidx), +}; + +static void* poll_init(struct event_base* base) +{ + struct pollop* pollop; + + if (!(pollop = mm_calloc(1, sizeof(struct pollop)))) + return (NULL); + + evsig_init_(base); + + evutil_weakrand_seed_(&base->weakrand_seed, 0); + + return (pollop); +} + +#ifdef CHECK_INVARIANTS +static void poll_check_ok(struct pollop* pop) +{ + int i, idx; + struct event* ev; + + for (i = 0; i < pop->fd_count; ++i) { + idx = pop->idxplus1_by_fd[i] - 1; + if (idx < 0) + continue; + EVUTIL_ASSERT(pop->event_set[idx].fd == i); + } + for (i = 0; i < pop->nfds; ++i) { + struct pollfd* pfd = &pop->event_set[i]; + EVUTIL_ASSERT(pop->idxplus1_by_fd[pfd->fd] == i + 1); + } +} +#else +#define poll_check_ok(pop) +#endif + +static int poll_dispatch(struct event_base* base, struct timeval* tv) +{ + int res, i, j, nfds; + long msec = -1; + struct pollop* pop = base->evbase; + struct pollfd* event_set; + + poll_check_ok(pop); + + nfds = pop->nfds; + +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (base->th_base_lock) { + /* If we're using this backend in a multithreaded setting, + * then we need to work on a copy of event_set, so that we can + * let other threads modify the main event_set while we're + * polling. If we're not multithreaded, then we'll skip the + * copy step here to save memory and time. */ + if (pop->realloc_copy) { + struct pollfd* tmp = mm_realloc(pop->event_set_copy, pop->event_count * sizeof(struct pollfd)); + if (tmp == NULL) { + event_warn("realloc"); + return -1; + } + pop->event_set_copy = tmp; + pop->realloc_copy = 0; + } + memcpy(pop->event_set_copy, pop->event_set, sizeof(struct pollfd) * nfds); + event_set = pop->event_set_copy; + } else { + event_set = pop->event_set; + } +#else + event_set = pop->event_set; +#endif + + if (tv != NULL) { + msec = evutil_tv_to_msec_(tv); + if (msec < 0 || msec > INT_MAX) + msec = INT_MAX; + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + res = poll(event_set, nfds, msec); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + if (res == -1) { + if (errno != EINTR) { + event_warn("poll"); + return (-1); + } + + return (0); + } + + event_debug(("%s: poll reports %d", __func__, res)); + + if (res == 0 || nfds == 0) + return (0); + + i = evutil_weakrand_range_(&base->weakrand_seed, nfds); + for (j = 0; j < nfds; j++) { + int what; + if (++i == nfds) + i = 0; + what = event_set[i].revents; + if (!what) + continue; + + res = 0; + + /* If the file gets closed notify */ + if (what & (POLLHUP | POLLERR | POLLNVAL)) + what |= POLLIN | POLLOUT; + if (what & POLLIN) + res |= EV_READ; + if (what & POLLOUT) + res |= EV_WRITE; + if (res == 0) + continue; + + evmap_io_active_(base, event_set[i].fd, res); + } + + return (0); +} + +static int poll_add(struct event_base* base, int fd, short old, short events, void* idx_) +{ + struct pollop* pop = base->evbase; + struct pollfd* pfd = NULL; + struct pollidx* idx = idx_; + int i; + + EVUTIL_ASSERT((events & EV_SIGNAL) == 0); + if (!(events & (EV_READ | EV_WRITE))) + return (0); + + poll_check_ok(pop); + if (pop->nfds + 1 >= pop->event_count) { + struct pollfd* tmp_event_set; + int tmp_event_count; + + if (pop->event_count < 32) + tmp_event_count = 32; + else + tmp_event_count = pop->event_count * 2; + + /* We need more file descriptors */ + tmp_event_set = mm_realloc(pop->event_set, tmp_event_count * sizeof(struct pollfd)); + if (tmp_event_set == NULL) { + event_warn("realloc"); + return (-1); + } + pop->event_set = tmp_event_set; + + pop->event_count = tmp_event_count; + pop->realloc_copy = 1; + } + + i = idx->idxplus1 - 1; + + if (i >= 0) { + pfd = &pop->event_set[i]; + } else { + i = pop->nfds++; + pfd = &pop->event_set[i]; + pfd->events = 0; + pfd->fd = fd; + idx->idxplus1 = i + 1; + } + + pfd->revents = 0; + if (events & EV_WRITE) + pfd->events |= POLLOUT; + if (events & EV_READ) + pfd->events |= POLLIN; + poll_check_ok(pop); + + return (0); +} + +/* + * Nothing to be done here. + */ + +static int poll_del(struct event_base* base, int fd, short old, short events, void* idx_) +{ + struct pollop* pop = base->evbase; + struct pollfd* pfd = NULL; + struct pollidx* idx = idx_; + int i; + + EVUTIL_ASSERT((events & EV_SIGNAL) == 0); + if (!(events & (EV_READ | EV_WRITE))) + return (0); + + poll_check_ok(pop); + i = idx->idxplus1 - 1; + if (i < 0) + return (-1); + + /* Do we still want to read or write? */ + pfd = &pop->event_set[i]; + if (events & EV_READ) + pfd->events &= ~POLLIN; + if (events & EV_WRITE) + pfd->events &= ~POLLOUT; + poll_check_ok(pop); + if (pfd->events) + /* Another event cares about that fd. */ + return (0); + + /* Okay, so we aren't interested in that fd anymore. */ + idx->idxplus1 = 0; + + --pop->nfds; + if (i != pop->nfds) { + /* + * Shift the last pollfd down into the now-unoccupied + * position. + */ + memcpy(&pop->event_set[i], &pop->event_set[pop->nfds], sizeof(struct pollfd)); + idx = evmap_io_get_fdinfo_(&base->io, pop->event_set[i].fd); + EVUTIL_ASSERT(idx); + EVUTIL_ASSERT(idx->idxplus1 == pop->nfds + 1); + idx->idxplus1 = i + 1; + } + + poll_check_ok(pop); + return (0); +} + +static void poll_dealloc(struct event_base* base) +{ + struct pollop* pop = base->evbase; + + evsig_dealloc_(base); + if (pop->event_set) + mm_free(pop->event_set); + if (pop->event_set_copy) + mm_free(pop->event_set_copy); + + memset(pop, 0, sizeof(struct pollop)); + mm_free(pop); +} + +#endif /* EVENT__HAVE_POLL */ diff --git a/asynio/event/queue-internal.h b/asynio/event/queue-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..0971d4638edd7a56da19ddb5d380abe8079253fe --- /dev/null +++ b/asynio/event/queue-internal.h @@ -0,0 +1,409 @@ + +#ifndef SYS_QUEUE_H__ +#define SYS_QUEUE_H__ + +#define SLIST_HEAD(name, type) \ + struct name { \ + struct type* slh_first; /* first element */ \ + } + +#define SLIST_HEAD_INITIALIZER(head) \ + { \ + NULL \ + } + +#ifndef _WIN32 +#define SLIST_ENTRY(type) \ + struct { \ + struct type* sle_next; /* next element */ \ + } +#endif + +/* + * Singly-linked List access methods. + */ +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_END(head) NULL +#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_FOREACH(var, head, field) for ((var) = SLIST_FIRST(head); (var) != SLIST_END(head); (var) = SLIST_NEXT(var, field)) + +/* + * Singly-linked List functions. + */ +#define SLIST_INIT(head) \ + { \ + SLIST_FIRST(head) = SLIST_END(head); \ + } + +#define SLIST_INSERT_AFTER(slistelm, elm, field) \ + do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ + } while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) \ + do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ + } while (0) + +#define SLIST_REMOVE_HEAD(head, field) \ + do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ + } while (0) + +/* + * List definitions. + */ +#define LIST_HEAD(name, type) \ + struct name { \ + struct type* lh_first; /* first element */ \ + } + +#define LIST_HEAD_INITIALIZER(head) \ + { \ + NULL \ + } + +#define LIST_ENTRY(type) \ + struct { \ + struct type* le_next; /* next element */ \ + struct type** le_prev; /* address of previous next element */ \ + } + +/* + * List access methods + */ +#define LIST_FIRST(head) ((head)->lh_first) +#define LIST_END(head) NULL +#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_FOREACH(var, head, field) for ((var) = LIST_FIRST(head); (var) != LIST_END(head); (var) = LIST_NEXT(var, field)) + +/* + * List functions. + */ +#define LIST_INIT(head) \ + do { \ + LIST_FIRST(head) = LIST_END(head); \ + } while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) \ + do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ + } while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) \ + do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ + } while (0) + +#define LIST_INSERT_HEAD(head, elm, field) \ + do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next; \ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ + } while (0) + +#define LIST_REMOVE(elm, field) \ + do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ + } while (0) + +#define LIST_REPLACE(elm, elm2, field) \ + do { \ + if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ + (elm2)->field.le_next->field.le_prev = &(elm2)->field.le_next; \ + (elm2)->field.le_prev = (elm)->field.le_prev; \ + *(elm2)->field.le_prev = (elm2); \ + } while (0) + +/* + * Simple queue definitions. + */ +#define SIMPLEQ_HEAD(name, type) \ + struct name { \ + struct type* sqh_first; /* first element */ \ + struct type** sqh_last; /* addr of last next element */ \ + } + +#define SIMPLEQ_HEAD_INITIALIZER(head) \ + { \ + NULL, &(head).sqh_first \ + } + +#define SIMPLEQ_ENTRY(type) \ + struct { \ + struct type* sqe_next; /* next element */ \ + } + +/* + * Simple queue access methods. + */ +#define SIMPLEQ_FIRST(head) ((head)->sqh_first) +#define SIMPLEQ_END(head) NULL +#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + +#define SIMPLEQ_FOREACH(var, head, field) for ((var) = SIMPLEQ_FIRST(head); (var) != SIMPLEQ_END(head); (var) = SIMPLEQ_NEXT(var, field)) + +/* + * Simple queue functions. + */ +#define SIMPLEQ_INIT(head) \ + do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ + } while (0) + +#define SIMPLEQ_INSERT_HEAD(head, elm, field) \ + do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ + } while (0) + +#define SIMPLEQ_INSERT_TAIL(head, elm, field) \ + do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + } while (0) + +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) \ + do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ + } while (0) + +#define SIMPLEQ_REMOVE_HEAD(head, elm, field) \ + do { \ + if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ + } while (0) + +/* + * Tail queue definitions. + */ +#define TAILQ_HEAD(name, type) \ + struct name { \ + struct type* tqh_first; /* first element */ \ + struct type** tqh_last; /* addr of last next element */ \ + } + +#define TAILQ_HEAD_INITIALIZER(head) \ + { \ + NULL, &(head).tqh_first \ + } + +#define TAILQ_ENTRY(type) \ + struct { \ + struct type* tqe_next; /* next element */ \ + struct type** tqe_prev; /* address of previous next element */ \ + } + +/* + * tail queue access methods + */ +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_END(head) NULL +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define TAILQ_LAST(head, headname) (*(((struct headname*)((head)->tqh_last))->tqh_last)) +/* XXX */ +#define TAILQ_PREV(elm, headname, field) (*(((struct headname*)((elm)->field.tqe_prev))->tqh_last)) +#define TAILQ_EMPTY(head) (TAILQ_FIRST(head) == TAILQ_END(head)) + +#define TAILQ_FOREACH(var, head, field) for ((var) = TAILQ_FIRST(head); (var) != TAILQ_END(head); (var) = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST(head, headname); (var) != TAILQ_END(head); (var) = TAILQ_PREV(var, headname, field)) + +/* + * Tail queue functions. + */ +#define TAILQ_INIT(head) \ + do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ + } while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) \ + do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ + } while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) \ + do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + } while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) \ + do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ + } while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) \ + do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ + } while (0) + +#define TAILQ_REMOVE(head, elm, field) \ + do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + } while (0) + +#define TAILQ_REPLACE(head, elm, elm2, field) \ + do { \ + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ + (elm2)->field.tqe_next->field.tqe_prev = &(elm2)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm2)->field.tqe_next; \ + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ + *(elm2)->field.tqe_prev = (elm2); \ + } while (0) + +/* + * Circular queue definitions. + */ +#define CIRCLEQ_HEAD(name, type) \ + struct name { \ + struct type* cqh_first; /* first element */ \ + struct type* cqh_last; /* last element */ \ + } + +#define CIRCLEQ_HEAD_INITIALIZER(head) \ + { \ + CIRCLEQ_END(&head), CIRCLEQ_END(&head) \ + } + +#define CIRCLEQ_ENTRY(type) \ + struct { \ + struct type* cqe_next; /* next element */ \ + struct type* cqe_prev; /* previous element */ \ + } + +/* + * Circular queue access methods + */ +#define CIRCLEQ_FIRST(head) ((head)->cqh_first) +#define CIRCLEQ_LAST(head) ((head)->cqh_last) +#define CIRCLEQ_END(head) ((void*)(head)) +#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) +#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) +#define CIRCLEQ_EMPTY(head) (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head)) + +#define CIRCLEQ_FOREACH(var, head, field) for ((var) = CIRCLEQ_FIRST(head); (var) != CIRCLEQ_END(head); (var) = CIRCLEQ_NEXT(var, field)) + +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) for ((var) = CIRCLEQ_LAST(head); (var) != CIRCLEQ_END(head); (var) = CIRCLEQ_PREV(var, field)) + +/* + * Circular queue functions. + */ +#define CIRCLEQ_INIT(head) \ + do { \ + (head)->cqh_first = CIRCLEQ_END(head); \ + (head)->cqh_last = CIRCLEQ_END(head); \ + } while (0) + +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) \ + do { \ + (elm)->field.cqe_next = (listelm)->field.cqe_next; \ + (elm)->field.cqe_prev = (listelm); \ + if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm); \ + else \ + (listelm)->field.cqe_next->field.cqe_prev = (elm); \ + (listelm)->field.cqe_next = (elm); \ + } while (0) + +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) \ + do { \ + (elm)->field.cqe_next = (listelm); \ + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ + if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm); \ + else \ + (listelm)->field.cqe_prev->field.cqe_next = (elm); \ + (listelm)->field.cqe_prev = (elm); \ + } while (0) + +#define CIRCLEQ_INSERT_HEAD(head, elm, field) \ + do { \ + (elm)->field.cqe_next = (head)->cqh_first; \ + (elm)->field.cqe_prev = CIRCLEQ_END(head); \ + if ((head)->cqh_last == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm); \ + else \ + (head)->cqh_first->field.cqe_prev = (elm); \ + (head)->cqh_first = (elm); \ + } while (0) + +#define CIRCLEQ_INSERT_TAIL(head, elm, field) \ + do { \ + (elm)->field.cqe_next = CIRCLEQ_END(head); \ + (elm)->field.cqe_prev = (head)->cqh_last; \ + if ((head)->cqh_first == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm); \ + else \ + (head)->cqh_last->field.cqe_next = (elm); \ + (head)->cqh_last = (elm); \ + } while (0) + +#define CIRCLEQ_REMOVE(head, elm, field) \ + do { \ + if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \ + (head)->cqh_last = (elm)->field.cqe_prev; \ + else \ + (elm)->field.cqe_next->field.cqe_prev = (elm)->field.cqe_prev; \ + if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \ + (head)->cqh_first = (elm)->field.cqe_next; \ + else \ + (elm)->field.cqe_prev->field.cqe_next = (elm)->field.cqe_next; \ + } while (0) + +#define CIRCLEQ_REPLACE(head, elm, elm2, field) \ + do { \ + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == CIRCLEQ_END(head)) \ + (head).cqh_last = (elm2); \ + else \ + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \ + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == CIRCLEQ_END(head)) \ + (head).cqh_first = (elm2); \ + else \ + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ + } while (0) + +#endif /* !SYS_QUEUE_H__ */ diff --git a/asynio/event/ratelim-internal.h b/asynio/event/ratelim-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..d9b305a6dbffe73f62a3c256e4b8794078c41076 --- /dev/null +++ b/asynio/event/ratelim-internal.h @@ -0,0 +1,60 @@ +#ifndef RATELIM_INTERNAL_H_INCLUDED_ +#define RATELIM_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "util.h" + +struct ev_token_bucket { + /** How many bytes are we willing to read or write right now? These + * values are signed so that we can do "defecit spending" */ + ev_ssize_t read_limit, write_limit; + /** When was this bucket last updated? Measured in abstract 'ticks' + * relative to the token bucket configuration. */ + ev_uint32_t last_updated; +}; + +struct ev_token_bucket_cfg { + /** How many bytes are we willing to read on average per tick? */ + size_t read_rate; + /** How many bytes are we willing to read at most in any one tick? */ + size_t read_maximum; + /** How many bytes are we willing to write on average per tick? */ + size_t write_rate; + /** How many bytes are we willing to write at most in any one tick? */ + size_t write_maximum; + + /* How long is a tick? Note that fractions of a millisecond are + * ignored. */ + struct timeval tick_timeout; + + /* How long is a tick, in milliseconds? Derived from tick_timeout. */ + unsigned msec_per_tick; +}; + +int ev_token_bucket_update_(struct ev_token_bucket* bucket, const struct ev_token_bucket_cfg* cfg, ev_uint32_t current_tick); + +ev_uint32_t ev_token_bucket_get_tick_(const struct timeval* tv, const struct ev_token_bucket_cfg* cfg); + +int ev_token_bucket_init_(struct ev_token_bucket* bucket, const struct ev_token_bucket_cfg* cfg, ev_uint32_t current_tick, int reinitialize); + +int bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent* bev, int unsuspend); + +/** Decrease the read limit of 'b' by 'n' bytes */ +#define ev_token_bucket_decrement_read(b, n) \ + do { \ + (b)->read_limit -= (n); \ + } while (0) +/** Decrease the write limit of 'b' by 'n' bytes */ +#define ev_token_bucket_decrement_write(b, n) \ + do { \ + (b)->write_limit -= (n); \ + } while (0) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/select.c b/asynio/event/select.c new file mode 100644 index 0000000000000000000000000000000000000000..4c70f61af584d758d3dad4e507f531de73786f64 --- /dev/null +++ b/asynio/event/select.c @@ -0,0 +1,322 @@ +/* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */ + +/* + * Copyright 2000-2007 Niels Provos + * Copyright 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef EVENT__HAVE_SELECT + +#ifdef __APPLE__ +/* Apple wants us to define this if we might ever pass more than + * FD_SETSIZE bits to select(). */ +#define _DARWIN_UNLIMITED_SELECT +#endif + +#include +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#ifdef EVENT__HAVE_SYS_SELECT_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include + +#include "evconfig-internal.h" + +#ifndef EVENT__HAVE_FD_MASK +/* This type is mandatory, but Android doesn't define it. */ +typedef unsigned long fd_mask; +#endif + +#ifndef NFDBITS +#define NFDBITS (sizeof(fd_mask) * 8) +#endif + +/* Divide positive x by y, rounding up. */ +#define DIV_ROUNDUP(x, y) (((x) + ((y)-1)) / (y)) + +/* How many bytes to allocate for N fds? */ +#define SELECT_ALLOC_SIZE(n) (DIV_ROUNDUP(n, NFDBITS) * sizeof(fd_mask)) + +struct selectop { + int event_fds; /* Highest fd in fd set */ + int event_fdsz; + int resize_out_sets; + fd_set* event_readset_in; + fd_set* event_writeset_in; + fd_set* event_readset_out; + fd_set* event_writeset_out; +}; + +static void* select_init(struct event_base*); +static int select_add(struct event_base*, int, short old, short events, void*); +static int select_del(struct event_base*, int, short old, short events, void*); +static int select_dispatch(struct event_base*, struct timeval*); +static void select_dealloc(struct event_base*); + +const struct eventop selectops = { + "select", select_init, select_add, select_del, select_dispatch, select_dealloc, 0, /* doesn't need reinit. */ + EV_FEATURE_FDS, 0, +}; + +static int select_resize(struct selectop* sop, int fdsz); +static void select_free_selectop(struct selectop* sop); + +static void* select_init(struct event_base* base) +{ + struct selectop* sop; + + if (!(sop = mm_calloc(1, sizeof(struct selectop)))) + return (NULL); + + if (select_resize(sop, SELECT_ALLOC_SIZE(32 + 1))) { + select_free_selectop(sop); + return (NULL); + } + + evsig_init_(base); + + evutil_weakrand_seed_(&base->weakrand_seed, 0); + + return (sop); +} + +#ifdef CHECK_INVARIANTS +static void check_selectop(struct selectop* sop) +{ + /* nothing to be done here */ +} +#else +#define check_selectop(sop) \ + do { \ + (void)sop; \ + } while (0) +#endif + +static int select_dispatch(struct event_base* base, struct timeval* tv) +{ + int res = 0, i, j, nfds; + struct selectop* sop = base->evbase; + + check_selectop(sop); + if (sop->resize_out_sets) { + fd_set *readset_out = NULL, *writeset_out = NULL; + size_t sz = sop->event_fdsz; + if (!(readset_out = mm_realloc(sop->event_readset_out, sz))) + return (-1); + sop->event_readset_out = readset_out; + if (!(writeset_out = mm_realloc(sop->event_writeset_out, sz))) { + /* We don't free readset_out here, since it was + * already successfully reallocated. The next time + * we call select_dispatch, the realloc will be a + * no-op. */ + return (-1); + } + sop->event_writeset_out = writeset_out; + sop->resize_out_sets = 0; + } + + memcpy(sop->event_readset_out, sop->event_readset_in, sop->event_fdsz); + memcpy(sop->event_writeset_out, sop->event_writeset_in, sop->event_fdsz); + + nfds = sop->event_fds + 1; + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + res = select(nfds, sop->event_readset_out, sop->event_writeset_out, NULL, tv); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + check_selectop(sop); + + if (res == -1) { + if (errno != EINTR) { + event_warn("select"); + return (-1); + } + + return (0); + } + + event_debug(("%s: select reports %d", __func__, res)); + + check_selectop(sop); + i = evutil_weakrand_range_(&base->weakrand_seed, nfds); + for (j = 0; j < nfds; ++j) { + if (++i >= nfds) + i = 0; + res = 0; + if (FD_ISSET(i, sop->event_readset_out)) + res |= EV_READ; + if (FD_ISSET(i, sop->event_writeset_out)) + res |= EV_WRITE; + + if (res == 0) + continue; + + evmap_io_active_(base, i, res); + } + check_selectop(sop); + + return (0); +} + +static int select_resize(struct selectop* sop, int fdsz) +{ + fd_set* readset_in = NULL; + fd_set* writeset_in = NULL; + + if (sop->event_readset_in) + check_selectop(sop); + + if ((readset_in = mm_realloc(sop->event_readset_in, fdsz)) == NULL) + goto error; + sop->event_readset_in = readset_in; + if ((writeset_in = mm_realloc(sop->event_writeset_in, fdsz)) == NULL) { + /* Note that this will leave event_readset_in expanded. + * That's okay; we wouldn't want to free it, since that would + * change the semantics of select_resize from "expand the + * readset_in and writeset_in, or return -1" to "expand the + * *set_in members, or trash them and return -1." + */ + goto error; + } + sop->event_writeset_in = writeset_in; + sop->resize_out_sets = 1; + + memset((char*)sop->event_readset_in + sop->event_fdsz, 0, fdsz - sop->event_fdsz); + memset((char*)sop->event_writeset_in + sop->event_fdsz, 0, fdsz - sop->event_fdsz); + + sop->event_fdsz = fdsz; + check_selectop(sop); + + return (0); + +error: + event_warn("malloc"); + return (-1); +} + +static int select_add(struct event_base* base, int fd, short old, short events, void* p) +{ + struct selectop* sop = base->evbase; + (void)p; + + EVUTIL_ASSERT((events & EV_SIGNAL) == 0); + check_selectop(sop); + /* + * Keep track of the highest fd, so that we can calculate the size + * of the fd_sets for select(2) + */ + if (sop->event_fds < fd) { + int fdsz = sop->event_fdsz; + + if (fdsz < (int)sizeof(fd_mask)) + fdsz = (int)sizeof(fd_mask); + + /* In theory we should worry about overflow here. In + * reality, though, the highest fd on a unixy system will + * not overflow here. XXXX */ + while (fdsz < (int)SELECT_ALLOC_SIZE(fd + 1)) + fdsz *= 2; + + if (fdsz != sop->event_fdsz) { + if (select_resize(sop, fdsz)) { + check_selectop(sop); + return (-1); + } + } + + sop->event_fds = fd; + } + + if (events & EV_READ) + FD_SET(fd, sop->event_readset_in); + if (events & EV_WRITE) + FD_SET(fd, sop->event_writeset_in); + check_selectop(sop); + + return (0); +} + +/* + * Nothing to be done here. + */ + +static int select_del(struct event_base* base, int fd, short old, short events, void* p) +{ + struct selectop* sop = base->evbase; + (void)p; + + EVUTIL_ASSERT((events & EV_SIGNAL) == 0); + check_selectop(sop); + + if (sop->event_fds < fd) { + check_selectop(sop); + return (0); + } + + if (events & EV_READ) + FD_CLR(fd, sop->event_readset_in); + + if (events & EV_WRITE) + FD_CLR(fd, sop->event_writeset_in); + + check_selectop(sop); + return (0); +} + +static void select_free_selectop(struct selectop* sop) +{ + if (sop->event_readset_in) + mm_free(sop->event_readset_in); + if (sop->event_writeset_in) + mm_free(sop->event_writeset_in); + if (sop->event_readset_out) + mm_free(sop->event_readset_out); + if (sop->event_writeset_out) + mm_free(sop->event_writeset_out); + + memset(sop, 0, sizeof(struct selectop)); + mm_free(sop); +} + +static void select_dealloc(struct event_base* base) +{ + evsig_dealloc_(base); + + select_free_selectop(base->evbase); +} + +#endif /* EVENT__HAVE_SELECT */ diff --git a/asynio/event/signal.c b/asynio/event/signal.c new file mode 100644 index 0000000000000000000000000000000000000000..cda5fe3a3709fc5a43a3b5eca16a9042b45a88a8 --- /dev/null +++ b/asynio/event/signal.c @@ -0,0 +1,450 @@ +/* $OpenBSD: select.c,v 1.2 2002/06/25 15:50:15 mickey Exp $ */ + +/* + * Copyright 2000-2007 Niels Provos + * Copyright 2007-2012 Niels Provos and Nick Mathewson + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "evconfig.h" + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#include +#undef WIN32_LEAN_AND_MEAN +#endif +#include +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#include +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif +#include +#include +#include +#include +#ifdef EVENT__HAVE_UNISTD_H +#include +#endif +#include +#ifdef EVENT__HAVE_FCNTL_H +#include +#endif + +#include "eventbase.h" +#include "event_struct.h" +#include "event-internal.h" +#include "util.h" + +#include "evconfig-internal.h" + +/* + signal.c + + This is the signal-handling implementation we use for backends that don't + have a better way to do signal handling. It uses sigaction() or signal() + to set a signal handler, and a socket pair to tell the event base when + + Note that I said "the event base" : only one event base can be set up to use + this at a time. For historical reasons and backward compatibility, if you + add an event for a signal to event_base A, then add an event for a signal + (any signal!) to event_base B, event_base B will get informed about the + signal, but event_base A won't. + + It would be neat to change this behavior in some future version of Libevent. + kqueue already does something far more sensible. We can make all backends + on Linux do a reasonable thing using signalfd. +*/ + +#ifndef _WIN32 +/* Windows wants us to call our signal handlers as __cdecl. Nobody else + * expects you to do anything crazy like this. */ +#define __cdecl +#endif + +static int evsig_add(struct event_base*, evutil_socket_t, short, short, void*); +static int evsig_del(struct event_base*, evutil_socket_t, short, short, void*); + +static const struct eventop evsigops = {"signal", NULL, evsig_add, evsig_del, NULL, NULL, 0, 0, 0}; + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +/* Lock for evsig_base and evsig_base_n_signals_added fields. */ +static void* evsig_base_lock = NULL; +#endif +/* The event base that's currently getting informed about signals. */ +static struct event_base* evsig_base = NULL; +/* A copy of evsig_base->sigev_n_signals_added. */ +static int evsig_base_n_signals_added = 0; +static evutil_socket_t evsig_base_fd = -1; + +static void __cdecl evsig_handler(int sig); + +#define EVSIGBASE_LOCK() EVLOCK_LOCK(evsig_base_lock, 0) +#define EVSIGBASE_UNLOCK() EVLOCK_UNLOCK(evsig_base_lock, 0) + +void evsig_set_base_(struct event_base* base) +{ + EVSIGBASE_LOCK(); + evsig_base = base; + evsig_base_n_signals_added = base->sig.ev_n_signals_added; + evsig_base_fd = base->sig.ev_signal_pair[1]; + EVSIGBASE_UNLOCK(); +} + +/* Callback for when the signal handler write a byte to our signaling socket */ +static void evsig_cb(evutil_socket_t fd, short what, void* arg) +{ + static char signals[1024]; + ev_ssize_t n; + int i; + int ncaught[NSIG]; + struct event_base* base; + + base = arg; + + memset(&ncaught, 0, sizeof(ncaught)); + + while (1) { +#ifdef _WIN32 + n = recv(fd, signals, sizeof(signals), 0); +#else + n = read(fd, signals, sizeof(signals)); +#endif + if (n == -1) { + int err = evutil_socket_geterror(fd); + if (!EVUTIL_ERR_RW_RETRIABLE(err)) + event_sock_err(1, fd, "%s: recv", __func__); + break; + } else if (n == 0) { + /* XXX warn? */ + break; + } + for (i = 0; i < n; ++i) { + ev_uint8_t sig = signals[i]; + if (sig < NSIG) + ncaught[sig]++; + } + } + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + for (i = 0; i < NSIG; ++i) { + if (ncaught[i]) + evmap_signal_active_(base, i, ncaught[i]); + } + EVBASE_RELEASE_LOCK(base, th_base_lock); +} + +int evsig_init_(struct event_base* base) +{ + /* + * Our signal handler is going to write to one end of the socket + * pair to wake up our event loop. The event loop then scans for + * signals that got delivered. + */ + if (evutil_make_internal_pipe_(base->sig.ev_signal_pair) == -1) { +#ifdef _WIN32 + /* Make this nonfatal on win32, where sometimes people + have localhost firewalled. */ + event_sock_warn(-1, "%s: socketpair", __func__); +#else + event_sock_err(1, -1, "%s: socketpair", __func__); +#endif + return -1; + } + + if (base->sig.sh_old) { + mm_free(base->sig.sh_old); + } + base->sig.sh_old = NULL; + base->sig.sh_old_max = 0; + + event_assign(&base->sig.ev_signal, base, base->sig.ev_signal_pair[0], EV_READ | EV_PERSIST, evsig_cb, base); + + base->sig.ev_signal.ev_flags |= EVLIST_INTERNAL; + event_priority_set(&base->sig.ev_signal, 0); + + base->evsigsel = &evsigops; + + return 0; +} + +/* Helper: set the signal handler for evsignal to handler in base, so that + * we can restore the original handler when we clear the current one. */ +int evsig_set_handler_(struct event_base* base, int evsignal, void(__cdecl* handler)(int)) +{ +#ifdef EVENT__HAVE_SIGACTION + struct sigaction sa; +#else + ev_sighandler_t sh; +#endif + struct evsig_info* sig = &base->sig; + void* p; + + /* + * resize saved signal handler array up to the highest signal number. + * a dynamic array is used to keep footprint on the low side. + */ + if (evsignal >= sig->sh_old_max) { + int new_max = evsignal + 1; + event_debug(("%s: evsignal (%d) >= sh_old_max (%d), resizing", __func__, evsignal, sig->sh_old_max)); + p = mm_realloc(sig->sh_old, new_max * sizeof(*sig->sh_old)); + if (p == NULL) { + event_warn("realloc"); + return (-1); + } + + memset((char*)p + sig->sh_old_max * sizeof(*sig->sh_old), 0, (new_max - sig->sh_old_max) * sizeof(*sig->sh_old)); + + sig->sh_old_max = new_max; + sig->sh_old = p; + } + + /* allocate space for previous handler out of dynamic array */ + sig->sh_old[evsignal] = mm_malloc(sizeof *sig->sh_old[evsignal]); + if (sig->sh_old[evsignal] == NULL) { + event_warn("malloc"); + return (-1); + } + + /* save previous handler and setup new handler */ +#ifdef EVENT__HAVE_SIGACTION + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = handler; + sa.sa_flags |= SA_RESTART; + sigfillset(&sa.sa_mask); + + if (sigaction(evsignal, &sa, sig->sh_old[evsignal]) == -1) { + event_warn("sigaction"); + mm_free(sig->sh_old[evsignal]); + sig->sh_old[evsignal] = NULL; + return (-1); + } +#else + if ((sh = signal(evsignal, handler)) == SIG_ERR) { + event_warn("signal"); + mm_free(sig->sh_old[evsignal]); + sig->sh_old[evsignal] = NULL; + return (-1); + } + *sig->sh_old[evsignal] = sh; +#endif + + return (0); +} + +static int evsig_add(struct event_base* base, evutil_socket_t evsignal, short old, short events, void* p) +{ + struct evsig_info* sig = &base->sig; + (void)p; + + EVUTIL_ASSERT(evsignal >= 0 && evsignal < NSIG); + + /* catch signals if they happen quickly */ + EVSIGBASE_LOCK(); + if (evsig_base != base && evsig_base_n_signals_added) { + event_warnx( + "Added a signal to event base %p with signals " + "already added to event_base %p. Only one can have " + "signals at a time with the %s backend. The base with " + "the most recently added signal or the most recent " + "event_base_loop() call gets preference; do " + "not rely on this behavior in future Libevent versions.", + base, evsig_base, base->evsel->name); + } + evsig_base = base; + evsig_base_n_signals_added = ++sig->ev_n_signals_added; + evsig_base_fd = base->sig.ev_signal_pair[1]; + EVSIGBASE_UNLOCK(); + + event_debug(("%s: %d: changing signal handler", __func__, (int)evsignal)); + if (evsig_set_handler_(base, (int)evsignal, evsig_handler) == -1) { + goto err; + } + + if (!sig->ev_signal_added) { + if (event_add_nolock_(&sig->ev_signal, NULL, 0)) + goto err; + sig->ev_signal_added = 1; + } + + return (0); + +err: + EVSIGBASE_LOCK(); + --evsig_base_n_signals_added; + --sig->ev_n_signals_added; + EVSIGBASE_UNLOCK(); + return (-1); +} + +int evsig_restore_handler_(struct event_base* base, int evsignal) +{ + int ret = 0; + struct evsig_info* sig = &base->sig; +#ifdef EVENT__HAVE_SIGACTION + struct sigaction* sh; +#else + ev_sighandler_t* sh; +#endif + + if (evsignal >= sig->sh_old_max) { + /* Can't actually restore. */ + /* XXXX.*/ + return 0; + } + + /* restore previous handler */ + sh = sig->sh_old[evsignal]; + sig->sh_old[evsignal] = NULL; +#ifdef EVENT__HAVE_SIGACTION + if (sigaction(evsignal, sh, NULL) == -1) { + event_warn("sigaction"); + ret = -1; + } +#else + if (signal(evsignal, *sh) == SIG_ERR) { + event_warn("signal"); + ret = -1; + } +#endif + + mm_free(sh); + + return ret; +} + +static int evsig_del(struct event_base* base, evutil_socket_t evsignal, short old, short events, void* p) +{ + EVUTIL_ASSERT(evsignal >= 0 && evsignal < NSIG); + + event_debug(("%s: " EV_SOCK_FMT ": restoring signal handler", __func__, EV_SOCK_ARG(evsignal))); + + EVSIGBASE_LOCK(); + --evsig_base_n_signals_added; + --base->sig.ev_n_signals_added; + EVSIGBASE_UNLOCK(); + + return (evsig_restore_handler_(base, (int)evsignal)); +} + +static void __cdecl evsig_handler(int sig) +{ + int save_errno = errno; +#ifdef _WIN32 + int socket_errno = EVUTIL_SOCKET_ERROR(); +#endif + ev_uint8_t msg; + + if (evsig_base == NULL) { + event_warnx("%s: received signal %d, but have no base configured", __func__, sig); + return; + } + +#ifndef EVENT__HAVE_SIGACTION + signal(sig, evsig_handler); +#endif + + /* Wake up our notification mechanism */ + msg = sig; +#ifdef _WIN32 + send(evsig_base_fd, (char*)&msg, 1, 0); +#else + { + int r = write(evsig_base_fd, (char*)&msg, 1); + (void)r; /* Suppress 'unused return value' and 'unused var' */ + } +#endif + errno = save_errno; +#ifdef _WIN32 + EVUTIL_SET_SOCKET_ERROR(socket_errno); +#endif +} + +void evsig_dealloc_(struct event_base* base) +{ + int i = 0; + if (base->sig.ev_signal_added) { + event_del(&base->sig.ev_signal); + base->sig.ev_signal_added = 0; + } + /* debug event is created in evsig_init_/event_assign even when + * ev_signal_added == 0, so unassign is required */ + event_debug_unassign(&base->sig.ev_signal); + + for (i = 0; i < NSIG; ++i) { + if (i < base->sig.sh_old_max && base->sig.sh_old[i] != NULL) + evsig_restore_handler_(base, i); + } + EVSIGBASE_LOCK(); + if (base == evsig_base) { + evsig_base = NULL; + evsig_base_n_signals_added = 0; + evsig_base_fd = -1; + } + EVSIGBASE_UNLOCK(); + + if (base->sig.ev_signal_pair[0] != -1) { + evutil_closesocket(base->sig.ev_signal_pair[0]); + base->sig.ev_signal_pair[0] = -1; + } + if (base->sig.ev_signal_pair[1] != -1) { + evutil_closesocket(base->sig.ev_signal_pair[1]); + base->sig.ev_signal_pair[1] = -1; + } + base->sig.sh_old_max = 0; + + /* per index frees are handled in evsig_del() */ + if (base->sig.sh_old) { + mm_free(base->sig.sh_old); + base->sig.sh_old = NULL; + } +} + +static void evsig_free_globals_locks(void) +{ +#ifndef EVENT__DISABLE_THREAD_SUPPORT + if (evsig_base_lock != NULL) { + EVTHREAD_FREE_LOCK(evsig_base_lock, 0); + evsig_base_lock = NULL; + } +#endif + return; +} + +void evsig_free_globals_(void) +{ + evsig_free_globals_locks(); +} + +#ifndef EVENT__DISABLE_THREAD_SUPPORT +int evsig_global_setup_locks_(const int enable_locks) +{ + EVTHREAD_SETUP_GLOBAL_LOCK(evsig_base_lock, 0); + return 0; +} + +#endif diff --git a/asynio/event/ssl-compat.h b/asynio/event/ssl-compat.h new file mode 100644 index 0000000000000000000000000000000000000000..0f7afba021ec27911cedcf87be6f62ca37b5aaab --- /dev/null +++ b/asynio/event/ssl-compat.h @@ -0,0 +1,102 @@ +#ifndef SSL_COMPACT_H +#define SSL_COMPACT_H + +#include "event.h" +#include "bufferevent-internal.h" +#include "bufferevent_ssl.h" + +struct bufferevent_ssl; + +struct le_ssl_ops { + void *(*init)(void *ssl); + void (*free)(void *ssl, int flags); + void (*free_raw)(void *ssl); + int (*renegotiate)(void *ssl); + int (*write)(void *ssl, const unsigned char *buf, size_t len); + int (*read)(void *ssl, unsigned char *buf, size_t len); + size_t (*pending)(void *ssl); + int (*handshake)(void *ssl); + int (*get_error)(void *ssl, int ret); + void (*clear_error)(void); + int (*clear)(void *ssl); + void (*set_connect_state)(void *ssl); + void (*set_accept_state)(void *ssl); + int (*err_is_ok)(int err); + int (*err_is_want_read)(int err); + int (*err_is_want_write)(int err); + evutil_socket_t (*get_fd)(void *ssl); + int (*bio_set_fd)(struct bufferevent_ssl *ssl, evutil_socket_t fd); + void (*init_bio_counts)(struct bufferevent_ssl *bev); + void (*decrement_buckets)(struct bufferevent_ssl *bev); + void (*conn_closed)( + struct bufferevent_ssl *bev, int when, int errcode, int ret); + void (*print_err)(int err); +}; + +struct bio_data_counts { + unsigned long n_written; + unsigned long n_read; +}; + +struct bufferevent_ssl { + /* Shared fields with common bufferevent implementation code. + If we were set up with an underlying bufferevent, we use the + events here as timers only. If we have an SSL, then we use + the events as socket events. + */ + struct bufferevent_private bev; + /* An underlying bufferevent that we're directing our output to. + If it's NULL, then we're connected to an fd, not an evbuffer. */ + struct bufferevent *underlying; + /* The SSL context doing our encryption. */ + void *ssl; + /* The SSL operations doing on ssl. */ + struct le_ssl_ops *ssl_ops; + + /* A callback that's invoked when data arrives on our outbuf so we + know to write data to the SSL. */ + struct evbuffer_cb_entry *outbuf_cb; + + /* A count of how much data the bios have read/written total. Used + for rate-limiting. */ + struct bio_data_counts counts; + + /* If this value is greater than 0, then the last SSL_write blocked, + * and we need to try it again with this many bytes. */ + ev_ssize_t last_write; + +#define NUM_ERRORS 3 + ev_uint32_t errors[NUM_ERRORS]; + + /* When we next get available space, we should say "read" instead of + "write". This can happen if there's a renegotiation during a read + operation. */ + unsigned read_blocked_on_write : 1; + /* When we next get data, we should say "write" instead of "read". */ + unsigned write_blocked_on_read : 1; + /* XXX */ + unsigned n_errors : 2; + + /* Are we currently connecting, accepting, or doing IO? */ + unsigned state : 2; + /* If we reset fd, we sould reset state too */ + unsigned old_state : 2; + + ev_uint64_t flags; +}; + +struct bufferevent *bufferevent_ssl_new_impl(struct event_base *base, + struct bufferevent *underlying, evutil_socket_t fd, void *ssl, + enum bufferevent_ssl_state state, int options, struct le_ssl_ops *ssl_ops); +struct bufferevent_ssl *bufferevent_ssl_upcast(struct bufferevent *bev); +void bufferevent_ssl_put_error( + struct bufferevent_ssl *bev_ssl, unsigned long err); +void bufferevent_ssl_stop_reading(struct bufferevent_ssl *bev_ssl); +void bufferevent_ssl_stop_writing(struct bufferevent_ssl *bev_ssl); +int bufferevent_ssl_renegotiate_impl(struct bufferevent *bev); +unsigned long bufferevent_get_ssl_error(struct bufferevent *bev); +int bufferevent_ssl_get_allow_dirty_shutdown(struct bufferevent *bev); +void bufferevent_ssl_set_allow_dirty_shutdown( + struct bufferevent *bev, int allow_dirty_shutdown); + +#endif /* SSL_COMPACT_H */ diff --git a/asynio/event/strlcpy-internal.h b/asynio/event/strlcpy-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..a3859ad83fe78edca7cd5f37bf145df3af9af69e --- /dev/null +++ b/asynio/event/strlcpy-internal.h @@ -0,0 +1,20 @@ +#ifndef STRLCPY_INTERNAL_H_INCLUDED_ +#define STRLCPY_INTERNAL_H_INCLUDED_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "evconfig.h" + +#ifndef EVENT__HAVE_STRLCPY +#include +size_t event_strlcpy_(char* dst, const char* src, size_t siz); +#define strlcpy event_strlcpy_ +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/strlcpy.c b/asynio/event/strlcpy.c new file mode 100644 index 0000000000000000000000000000000000000000..04e63c6c70e32ffc6709df4e7ac9f339dd0c5429 --- /dev/null +++ b/asynio/event/strlcpy.c @@ -0,0 +1,73 @@ +/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char* rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include "evconfig.h" + +#include + +#ifndef EVENT__HAVE_STRLCPY +#include "strlcpy-internal.h" + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t event_strlcpy_(dst, src, siz) +char* dst; +const char* src; +size_t siz; +{ + register char* d = dst; + register const char* s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return (s - src - 1); /* count does not include NUL */ +} +#endif diff --git a/asynio/event/thread-internal.h b/asynio/event/thread-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..9952ee1472b273687df33ceeda9a4ae4a80ce097 --- /dev/null +++ b/asynio/event/thread-internal.h @@ -0,0 +1,116 @@ +#ifndef EVENT2_THREAD_H_INCLUDED_ +#define EVENT2_THREAD_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define EVTHREAD_WRITE 0x04 +#define EVTHREAD_READ 0x08 +#define EVTHREAD_TRY 0x10 + +#if !defined(EVENT__DISABLE_THREAD_SUPPORT) || defined(EVENT_IN_DOXYGEN_) + +#define EVTHREAD_LOCK_API_VERSION 1 +#define EVTHREAD_LOCKTYPE_RECURSIVE 1 +#define EVTHREAD_LOCKTYPE_READWRITE 2 + +struct evthread_lock_callbacks { + /** The current version of the locking API. Set this to + * EVTHREAD_LOCK_API_VERSION */ + int lock_api_version; + /** Which kinds of locks does this version of the locking API + * support? A bitfield of EVTHREAD_LOCKTYPE_RECURSIVE and + * EVTHREAD_LOCKTYPE_READWRITE. + * + * (Note that RECURSIVE locks are currently mandatory, and + * READWRITE locks are not currently used.) + **/ + unsigned supported_locktypes; + /** Function to allocate and initialize new lock of type 'locktype'. + * Returns NULL on failure. */ + void* (*alloc)(unsigned locktype); + /** Funtion to release all storage held in 'lock', which was created + * with type 'locktype'. */ + void (*free)(void* lock, unsigned locktype); + /** Acquire an already-allocated lock at 'lock' with mode 'mode'. + * Returns 0 on success, and nonzero on failure. */ + int (*lock)(unsigned mode, void* lock); + /** Release a lock at 'lock' using mode 'mode'. Returns 0 on success, + * and nonzero on failure. */ + int (*unlock)(unsigned mode, void* lock); +}; + +int evthread_set_lock_callbacks(const struct evthread_lock_callbacks*); + +#define EVTHREAD_CONDITION_API_VERSION 1 + +struct timeval; + +struct evthread_condition_callbacks { + /** The current version of the conditions API. Set this to + * EVTHREAD_CONDITION_API_VERSION */ + int condition_api_version; + /** Function to allocate and initialize a new condition variable. + * Returns the condition variable on success, and NULL on failure. + * The 'condtype' argument will be 0 with this API version. + */ + void* (*alloc_condition)(unsigned condtype); + /** Function to free a condition variable. */ + void (*free_condition)(void* cond); + /** Function to signal a condition variable. If 'broadcast' is 1, all + * threads waiting on 'cond' should be woken; otherwise, only on one + * thread is worken. Should return 0 on success, -1 on failure. + * This function will only be called while holding the associated + * lock for the condition. + */ + int (*signal_condition)(void* cond, int broadcast); + /** Function to wait for a condition variable. The lock 'lock' + * will be held when this function is called; should be released + * while waiting for the condition to be come signalled, and + * should be held again when this function returns. + * If timeout is provided, it is interval of seconds to wait for + * the event to become signalled; if it is NULL, the function + * should wait indefinitely. + * + * The function should return -1 on error; 0 if the condition + * was signalled, or 1 on a timeout. */ + int (*wait_condition)(void* cond, void* lock, const struct timeval* timeout); +}; + +int evthread_set_condition_callbacks(const struct evthread_condition_callbacks*); + +void evthread_set_id_callback(unsigned long (*id_fn)(void)); + +#if (defined(_WIN32) && !defined(EVENT__DISABLE_THREAD_SUPPORT)) || defined(EVENT_IN_DOXYGEN_) + +int evthread_use_windows_threads(void); + +#define EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED 1 +#endif + +#if defined(EVENT__HAVE_PTHREADS) || defined(EVENT_IN_DOXYGEN_) + +int evthread_use_pthreads(void); +/** Defined if Libevent was built with support for evthread_use_pthreads() */ +#define EVTHREAD_USE_PTHREADS_IMPLEMENTED 1 + +#endif + +void evthread_enable_lock_debugging(void); + +void evthread_enable_lock_debuging(void); + +#endif /* EVENT__DISABLE_THREAD_SUPPORT */ + +struct event_base; + +int evthread_make_base_notifiable(struct event_base* base); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT2_THREAD_H_INCLUDED_ */ diff --git a/asynio/event/time-internal.h b/asynio/event/time-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..a6f3357646c80300c353b735e238e5fc049bd481 --- /dev/null +++ b/asynio/event/time-internal.h @@ -0,0 +1,68 @@ +#ifndef TIME_INTERNAL_H_INCLUDED_ +#define TIME_INTERNAL_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef EVENT__HAVE_MACH_MACH_TIME_H +/* For mach_timebase_info */ +#include +#endif + +#include + +#include "util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(EVENT__HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) +#define HAVE_POSIX_MONOTONIC +#elif defined(EVENT__HAVE_MACH_ABSOLUTE_TIME) +#define HAVE_MACH_MONOTONIC +#elif defined(_WIN32) +#define HAVE_WIN32_MONOTONIC +#else +#define HAVE_FALLBACK_MONOTONIC +#endif + +long evutil_tv_to_msec_(const struct timeval* tv); +void evutil_usleep_(const struct timeval* tv); + +#ifdef _WIN32 +typedef ULONGLONG(WINAPI* ev_GetTickCount_func)(void); +#endif + +struct evutil_monotonic_timer { +#ifdef HAVE_MACH_MONOTONIC + struct mach_timebase_info mach_timebase_units; +#endif + +#ifdef HAVE_POSIX_MONOTONIC + int monotonic_clock; +#endif + +#ifdef HAVE_WIN32_MONOTONIC + ev_GetTickCount_func GetTickCount64_fn; + ev_GetTickCount_func GetTickCount_fn; + ev_uint64_t last_tick_count; + ev_uint64_t adjust_tick_count; + + ev_uint64_t first_tick; + ev_uint64_t first_counter; + double usec_per_count; + int use_performance_counter; +#endif + + struct timeval adjust_monotonic_clock; + struct timeval last_time; +}; + +int evutil_configure_monotonic_time_(struct evutil_monotonic_timer* mt, int flags); +int evutil_gettime_monotonic_(struct evutil_monotonic_timer* mt, struct timeval* tv); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT_INTERNAL_H_INCLUDED_ */ diff --git a/asynio/event/util-internal.h b/asynio/event/util-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..1b4539f1aa68228134d1e2e6483d9893c4fcdde2 --- /dev/null +++ b/asynio/event/util-internal.h @@ -0,0 +1,436 @@ +#ifndef UTIL_INTERNAL_H_INCLUDED_ +#define UTIL_INTERNAL_H_INCLUDED_ + +#include "evconfig.h" + +#include + +/* For EVUTIL_ASSERT */ +#include "log-internal.h" + +#include +#include + +#ifdef EVENT__HAVE_SYS_SOCKET_H +#include +#endif +#ifdef EVENT__HAVE_SYS_EVENTFD_H +#include +#endif +#include "util.h" + +#include "time-internal.h" +#include "ipv6-internal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* If we need magic to say "inline", get it for free internally. */ +#ifdef EVENT__inline +#define inline EVENT__inline +#endif +#if defined(EVENT____func__) && !defined(__func__) +#define __func__ EVENT____func__ +#endif + +/* A good no-op to use in macro definitions. */ +#define EVUTIL_NIL_STMT_ ((void)0) +/* A no-op that tricks the compiler into thinking a condition is used while + * definitely not making any code for it. Used to compile out asserts while + * avoiding "unused variable" warnings. The "!" forces the compiler to + * do the sizeof() on an int, in case "condition" is a bitfield value. + */ +#define EVUTIL_NIL_CONDITION_(condition) \ + do { \ + (void)sizeof(!(condition)); \ + } while (0) + +/* Internal use only: macros to match patterns of error codes in a + cross-platform way. We need these macros because of two historical + reasons: first, nonblocking IO functions are generally written to give an + error on the "blocked now, try later" case, so sometimes an error from a + read, write, connect, or accept means "no error; just wait for more + data," and we need to look at the error code. Second, Windows defines + a different set of error codes for sockets. */ + +#ifndef _WIN32 + +#if EAGAIN == EWOULDBLOCK +#define EVUTIL_ERR_IS_EAGAIN(e) ((e) == EAGAIN) +#else +#define EVUTIL_ERR_IS_EAGAIN(e) ((e) == EAGAIN || (e) == EWOULDBLOCK) +#endif + +/* True iff e is an error that means a read/write operation can be retried. */ +#define EVUTIL_ERR_RW_RETRIABLE(e) ((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e)) +/* True iff e is an error that means an connect can be retried. */ +#define EVUTIL_ERR_CONNECT_RETRIABLE(e) ((e) == EINTR || (e) == EINPROGRESS) +/* True iff e is an error that means a accept can be retried. */ +#define EVUTIL_ERR_ACCEPT_RETRIABLE(e) ((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e) || (e) == ECONNABORTED) + +/* True iff e is an error that means the connection was refused */ +#define EVUTIL_ERR_CONNECT_REFUSED(e) ((e) == ECONNREFUSED) + +#else +/* Win32 */ + +#define EVUTIL_ERR_IS_EAGAIN(e) ((e) == WSAEWOULDBLOCK || (e) == EAGAIN) + +#define EVUTIL_ERR_RW_RETRIABLE(e) ((e) == WSAEWOULDBLOCK || (e) == WSAEINTR) + +#define EVUTIL_ERR_CONNECT_RETRIABLE(e) ((e) == WSAEWOULDBLOCK || (e) == WSAEINTR || (e) == WSAEINPROGRESS || (e) == WSAEINVAL) + +#define EVUTIL_ERR_ACCEPT_RETRIABLE(e) EVUTIL_ERR_RW_RETRIABLE(e) + +#define EVUTIL_ERR_CONNECT_REFUSED(e) ((e) == WSAECONNREFUSED) + +#endif + +/* Arguments for shutdown() */ +#ifdef SHUT_RD +#define EVUTIL_SHUT_RD SHUT_RD +#else +#define EVUTIL_SHUT_RD 0 +#endif +#ifdef SHUT_WR +#define EVUTIL_SHUT_WR SHUT_WR +#else +#define EVUTIL_SHUT_WR 1 /* SD_SEND */ +#endif +#ifdef SHUT_BOTH +#define EVUTIL_SHUT_BOTH SHUT_BOTH +#else +#define EVUTIL_SHUT_BOTH 2 +#endif + +/* Helper: Verify that all the elements in 'dlist' are internally consistent. + * Checks for circular lists and bad prev/next pointers. + * + * Example usage: + * EVUTIL_ASSERT_LIST_OK(eventlist, event, ev_next); + */ +#define EVUTIL_ASSERT_LIST_OK(dlist, type, field) \ + do { \ + struct type *elm1, *elm2, **nextp; \ + if (LIST_EMPTY((dlist))) \ + break; \ +\ + /* Check list for circularity using Floyd's */ \ + /* 'Tortoise and Hare' algorithm */ \ + elm1 = LIST_FIRST((dlist)); \ + elm2 = LIST_NEXT(elm1, field); \ + while (elm1 && elm2) { \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm1 = LIST_NEXT(elm1, field); \ + elm2 = LIST_NEXT(elm2, field); \ + if (!elm2) \ + break; \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm2 = LIST_NEXT(elm2, field); \ + } \ +\ + /* Now check next and prev pointers for consistency. */ \ + nextp = &LIST_FIRST((dlist)); \ + elm1 = LIST_FIRST((dlist)); \ + while (elm1) { \ + EVUTIL_ASSERT(*nextp == elm1); \ + EVUTIL_ASSERT(nextp == elm1->field.le_prev); \ + nextp = &LIST_NEXT(elm1, field); \ + elm1 = *nextp; \ + } \ + } while (0) + +/* Helper: Verify that all the elements in a TAILQ are internally consistent. + * Checks for circular lists and bad prev/next pointers. + * + * Example usage: + * EVUTIL_ASSERT_TAILQ_OK(activelist, event, ev_active_next); + */ +#define EVUTIL_ASSERT_TAILQ_OK(tailq, type, field) \ + do { \ + struct type *elm1, *elm2, **nextp; \ + if (TAILQ_EMPTY((tailq))) \ + break; \ +\ + /* Check list for circularity using Floyd's */ \ + /* 'Tortoise and Hare' algorithm */ \ + elm1 = TAILQ_FIRST((tailq)); \ + elm2 = TAILQ_NEXT(elm1, field); \ + while (elm1 && elm2) { \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm1 = TAILQ_NEXT(elm1, field); \ + elm2 = TAILQ_NEXT(elm2, field); \ + if (!elm2) \ + break; \ + EVUTIL_ASSERT(elm1 != elm2); \ + elm2 = TAILQ_NEXT(elm2, field); \ + } \ +\ + /* Now check next and prev pointers for consistency. */ \ + nextp = &TAILQ_FIRST((tailq)); \ + elm1 = TAILQ_FIRST((tailq)); \ + while (elm1) { \ + EVUTIL_ASSERT(*nextp == elm1); \ + EVUTIL_ASSERT(nextp == elm1->field.tqe_prev); \ + nextp = &TAILQ_NEXT(elm1, field); \ + elm1 = *nextp; \ + } \ + EVUTIL_ASSERT(nextp == (tailq)->tqh_last); \ + } while (0) + +/* Locale-independent replacements for some ctypes functions. Use these + * when you care about ASCII's notion of character types, because you are about + * to send those types onto the wire. + */ +int EVUTIL_ISALPHA_(char c); +int EVUTIL_ISALNUM_(char c); +int EVUTIL_ISSPACE_(char c); +int EVUTIL_ISDIGIT_(char c); +int EVUTIL_ISXDIGIT_(char c); +int EVUTIL_ISPRINT_(char c); +int EVUTIL_ISLOWER_(char c); +int EVUTIL_ISUPPER_(char c); +char EVUTIL_TOUPPER_(char c); +char EVUTIL_TOLOWER_(char c); + +/** Remove all trailing horizontal whitespace (space or tab) from the end of a + * string */ +void evutil_rtrim_lws_(char*); + +/** Helper macro. If we know that a given pointer points to a field in a + structure, return a pointer to the structure itself. Used to implement + our half-baked C OO. Example: + + struct subtype { + int x; + struct supertype common; + int y; + }; + ... + void fn(struct supertype *super) { + struct subtype *sub = EVUTIL_UPCAST(super, struct subtype, common); + ... + } + */ +#define EVUTIL_UPCAST(ptr, type, field) ((type*)(((char*)(ptr)) - evutil_offsetof(type, field))) + +/* As open(pathname, flags, mode), except that the file is always opened with + * the close-on-exec flag set. (And the mode argument is mandatory.) + */ +int evutil_open_closeonexec_(const char* pathname, int flags, unsigned mode); + +int evutil_read_file_(const char* filename, char** content_out, size_t* len_out, int is_binary); + +int evutil_socket_connect_(evutil_socket_t* fd_ptr, const struct sockaddr* sa, int socklen); + +int evutil_socket_finished_connecting_(evutil_socket_t fd); + +int evutil_ersatz_socketpair_(int, int, int, evutil_socket_t[]); + +int evutil_resolve_(int family, const char* hostname, struct sockaddr* sa, ev_socklen_t* socklen, int port); + +const char* evutil_getenv_(const char* name); + +/* Structure to hold the state of our weak random number generator. + */ +struct evutil_weakrand_state { + ev_uint32_t seed; +}; + +#define EVUTIL_WEAKRAND_MAX EV_INT32_MAX + +/* Initialize the state of a week random number generator based on 'seed'. If + * the seed is 0, construct a new seed based on not-very-strong platform + * entropy, like the PID and the time of day. + * + * This function, and the other evutil_weakrand* functions, are meant for + * speed, not security or statistical strength. If you need a RNG which an + * attacker can't predict, or which passes strong statistical tests, use the + * evutil_secure_rng* functions instead. + */ +ev_uint32_t evutil_weakrand_seed_(struct evutil_weakrand_state* state, ev_uint32_t seed); +/* Return a pseudorandom value between 0 and EVUTIL_WEAKRAND_MAX inclusive. + * Updates the state in 'seed' as needed -- this value must be protected by a + * lock. + */ +ev_int32_t evutil_weakrand_(struct evutil_weakrand_state* seed); +/* Return a pseudorandom value x such that 0 <= x < top. top must be no more + * than EVUTIL_WEAKRAND_MAX. Updates the state in 'seed' as needed -- this + * value must be proteced by a lock */ +ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state* seed, ev_int32_t top); + +/* Evaluates to the same boolean value as 'p', and hints to the compiler that + * we expect this value to be false. */ +#if defined(__GNUC__) && __GNUC__ >= 3 /* gcc 3.0 or later */ +#define EVUTIL_UNLIKELY(p) __builtin_expect(!!(p), 0) +#else +#define EVUTIL_UNLIKELY(p) (p) +#endif + +/* Replacement for assert() that calls event_errx on failure. */ +#ifdef NDEBUG +#define EVUTIL_ASSERT(cond) EVUTIL_NIL_CONDITION_(cond) +#define EVUTIL_FAILURE_CHECK(cond) 0 +#else +#define EVUTIL_ASSERT(cond) \ + do { \ + if (EVUTIL_UNLIKELY(!(cond))) { \ + event_errx(EVENT_ERR_ABORT_, "%s:%d: Assertion %s failed in %s", __FILE__, __LINE__, #cond, __func__); \ + /* In case a user-supplied handler tries to */ \ + /* return control to us, log and abort here. */ \ + (void)fprintf(stderr, "%s:%d: Assertion %s failed in %s", __FILE__, __LINE__, #cond, __func__); \ + abort(); \ + } \ + } while (0) +#define EVUTIL_FAILURE_CHECK(cond) EVUTIL_UNLIKELY(cond) +#endif + +#ifndef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE +/* Replacement for sockaddr storage that we can use internally on platforms + * that lack it. It is not space-efficient, but neither is sockaddr_storage. + */ +struct sockaddr_storage { + union { + struct sockaddr ss_sa; + struct sockaddr_in ss_sin; + struct sockaddr_in6 ss_sin6; + char ss_padding[128]; + } ss_union; +}; +#define ss_family ss_union.ss_sa.sa_family +#endif + +/* Internal addrinfo error code. This one is returned from only from + * evutil_getaddrinfo_common_, when we are sure that we'll have to hit a DNS + * server. */ +#define EVUTIL_EAI_NEED_RESOLVE -90002 + +struct evdns_base; +struct evdns_getaddrinfo_request; +typedef struct evdns_getaddrinfo_request* (*evdns_getaddrinfo_fn)( + struct evdns_base* base, + const char* nodename, + const char* servname, + const struct evutil_addrinfo* hints_in, + void (*cb)(int, struct evutil_addrinfo*, void*), + void* arg); +void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn); +typedef void (*evdns_getaddrinfo_cancel_fn)(struct evdns_getaddrinfo_request* req); +void evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn); + +struct evutil_addrinfo* evutil_new_addrinfo_(struct sockaddr* sa, ev_socklen_t socklen, const struct evutil_addrinfo* hints); +struct evutil_addrinfo* evutil_addrinfo_append_(struct evutil_addrinfo* first, struct evutil_addrinfo* append); +void evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo* hints); +int evutil_getaddrinfo_common_(const char* nodename, const char* servname, struct evutil_addrinfo* hints, struct evutil_addrinfo** res, int* portnum); + +struct evdns_getaddrinfo_request* evutil_getaddrinfo_async_( + struct evdns_base* dns_base, + const char* nodename, + const char* servname, + const struct evutil_addrinfo* hints_in, + void (*cb)(int, struct evutil_addrinfo*, void*), + void* arg); +void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request* data); + +/** Return true iff sa is a looback address. (That is, it is 127.0.0.1/8, or + * ::1). */ +int evutil_sockaddr_is_loopback_(const struct sockaddr* sa); + +/** + Formats a sockaddr sa into a string buffer of size outlen stored in out. + Returns a pointer to out. Always writes something into out, so it's safe + to use the output of this function without checking it for NULL. + */ +const char* evutil_format_sockaddr_port_(const struct sockaddr* sa, char* out, size_t outlen); + +int evutil_hex_char_to_int_(char c); + +void evutil_free_secure_rng_globals_(void); +void evutil_free_globals_(void); + +#ifdef _WIN32 +HMODULE evutil_load_windows_system_library_(const TCHAR* library_name); +#endif + +#ifndef EV_SIZE_FMT +#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) +#define EV_U64_FMT "%I64u" +#define EV_I64_FMT "%I64d" +#define EV_I64_ARG(x) ((__int64)(x)) +#define EV_U64_ARG(x) ((unsigned __int64)(x)) +#else +#define EV_U64_FMT "%llu" +#define EV_I64_FMT "%lld" +#define EV_I64_ARG(x) ((long long)(x)) +#define EV_U64_ARG(x) ((unsigned long long)(x)) +#endif +#endif + +#ifdef _WIN32 +#define EV_SOCK_FMT EV_I64_FMT +#define EV_SOCK_ARG(x) EV_I64_ARG((x)) +#else +#define EV_SOCK_FMT "%d" +#define EV_SOCK_ARG(x) (x) +#endif + +#if defined(__STDC__) && defined(__STDC_VERSION__) && !defined(__MINGW64_VERSION_MAJOR) +#if (__STDC_VERSION__ >= 199901L) +#define EV_SIZE_FMT "%zu" +#define EV_SSIZE_FMT "%zd" +#define EV_SIZE_ARG(x) (x) +#define EV_SSIZE_ARG(x) (x) +#endif +#endif + +#ifndef EV_SIZE_FMT +#if (EVENT__SIZEOF_SIZE_T <= EVENT__SIZEOF_LONG) +#define EV_SIZE_FMT "%lu" +#define EV_SSIZE_FMT "%ld" +#define EV_SIZE_ARG(x) ((unsigned long)(x)) +#define EV_SSIZE_ARG(x) ((long)(x)) +#else +#define EV_SIZE_FMT EV_U64_FMT +#define EV_SSIZE_FMT EV_I64_FMT +#define EV_SIZE_ARG(x) EV_U64_ARG(x) +#define EV_SSIZE_ARG(x) EV_I64_ARG(x) +#endif +#endif + +evutil_socket_t evutil_socket_(int domain, int type, int protocol); +evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr* addr, ev_socklen_t* addrlen, int flags); + +/* used by one of the test programs.. */ + +int evutil_make_internal_pipe_(evutil_socket_t fd[2]); +evutil_socket_t evutil_eventfd_(unsigned initval, int flags); + +#ifdef SOCK_NONBLOCK +#define EVUTIL_SOCK_NONBLOCK SOCK_NONBLOCK +#else +#define EVUTIL_SOCK_NONBLOCK 0x4000000 +#endif +#ifdef SOCK_CLOEXEC +#define EVUTIL_SOCK_CLOEXEC SOCK_CLOEXEC +#else +#define EVUTIL_SOCK_CLOEXEC 0x80000000 +#endif +#ifdef EFD_NONBLOCK +#define EVUTIL_EFD_NONBLOCK EFD_NONBLOCK +#else +#define EVUTIL_EFD_NONBLOCK 0x4000 +#endif +#ifdef EFD_CLOEXEC +#define EVUTIL_EFD_CLOEXEC EFD_CLOEXEC +#else +#define EVUTIL_EFD_CLOEXEC 0x8000 +#endif + +void evutil_memclear_(void* mem, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/asynio/event/util.h b/asynio/event/util.h new file mode 100644 index 0000000000000000000000000000000000000000..67c8012a914c16375772108521d6ec0bf33bd19c --- /dev/null +++ b/asynio/event/util.h @@ -0,0 +1,525 @@ +#ifndef EVENT2_UTIL_H_INCLUDED_ +#define EVENT2_UTIL_H_INCLUDED_ + +#include "evconfig.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef EVENT__HAVE_SYS_TIME_H +#include +#endif +#ifdef EVENT__HAVE_STDINT_H +#include +#elif defined(EVENT__HAVE_INTTYPES_H) +#include +#endif +#ifdef EVENT__HAVE_SYS_TYPES_H +#include +#endif +#ifdef EVENT__HAVE_STDDEF_H +#include +#endif +#ifdef _MSC_VER +#include +#endif +#include +#ifdef EVENT__HAVE_NETDB_H +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif +#include +#endif + +#ifdef _WIN32 +#include +#ifdef EVENT__HAVE_GETADDRINFO +/* for EAI_* definitions. */ +#include +#endif +#else +#ifdef EVENT__HAVE_ERRNO_H +#include +#endif +#include +#endif + +#include + +/* Some openbsd autoconf versions get the name of this macro wrong. */ +#if defined(EVENT__SIZEOF_VOID__) && !defined(EVENT__SIZEOF_VOID_P) +#define EVENT__SIZEOF_VOID_P EVENT__SIZEOF_VOID__ +#endif + +#ifdef EVENT__HAVE_UINT64_T +#define ev_uint64_t uint64_t +#define ev_int64_t int64_t +#elif defined(_WIN32) +#define ev_uint64_t unsigned __int64 +#define ev_int64_t signed __int64 +#elif EVENT__SIZEOF_LONG_LONG == 8 +#define ev_uint64_t unsigned long long +#define ev_int64_t long long +#elif EVENT__SIZEOF_LONG == 8 +#define ev_uint64_t unsigned long +#define ev_int64_t long +#elif defined(EVENT_IN_DOXYGEN_) +#define ev_uint64_t ... +#define ev_int64_t ... +#else +#error "No way to define ev_uint64_t" +#endif + +#ifdef EVENT__HAVE_UINT32_T +#define ev_uint32_t uint32_t +#define ev_int32_t int32_t +#elif defined(_WIN32) +#define ev_uint32_t unsigned int +#define ev_int32_t signed int +#elif EVENT__SIZEOF_LONG == 4 +#define ev_uint32_t unsigned long +#define ev_int32_t signed long +#elif EVENT__SIZEOF_INT == 4 +#define ev_uint32_t unsigned int +#define ev_int32_t signed int +#elif defined(EVENT_IN_DOXYGEN_) +#define ev_uint32_t ... +#define ev_int32_t ... +#else +#error "No way to define ev_uint32_t" +#endif + +#ifdef EVENT__HAVE_UINT16_T +#define ev_uint16_t uint16_t +#define ev_int16_t int16_t +#elif defined(_WIN32) +#define ev_uint16_t unsigned short +#define ev_int16_t signed short +#elif EVENT__SIZEOF_INT == 2 +#define ev_uint16_t unsigned int +#define ev_int16_t signed int +#elif EVENT__SIZEOF_SHORT == 2 +#define ev_uint16_t unsigned short +#define ev_int16_t signed short +#elif defined(EVENT_IN_DOXYGEN_) +#define ev_uint16_t ... +#define ev_int16_t ... +#else +#error "No way to define ev_uint16_t" +#endif + +#ifdef EVENT__HAVE_UINT8_T +#define ev_uint8_t uint8_t +#define ev_int8_t int8_t +#elif defined(EVENT_IN_DOXYGEN_) +#define ev_uint8_t ... +#define ev_int8_t ... +#else +#define ev_uint8_t unsigned char +#define ev_int8_t signed char +#endif + +#ifdef EVENT__HAVE_UINTPTR_T +#define ev_uintptr_t uintptr_t +#define ev_intptr_t intptr_t +#elif EVENT__SIZEOF_VOID_P <= 4 +#define ev_uintptr_t ev_uint32_t +#define ev_intptr_t ev_int32_t +#elif EVENT__SIZEOF_VOID_P <= 8 +#define ev_uintptr_t ev_uint64_t +#define ev_intptr_t ev_int64_t +#elif defined(EVENT_IN_DOXYGEN_) +#define ev_uintptr_t ... +#define ev_intptr_t ... +#else +#error "No way to define ev_uintptr_t" +#endif + +#ifdef EVENT__ssize_t +#define ev_ssize_t EVENT__ssize_t +#else +#define ev_ssize_t ssize_t +#endif + +#ifdef _WIN32 +#define ev_off_t ev_int64_t +#elif EVENT__SIZEOF_OFF_T == 8 +#define ev_off_t ev_int64_t +#elif EVENT__SIZEOF_OFF_T == 4 +#define ev_off_t ev_int32_t +#elif defined(EVENT_IN_DOXYGEN_) +#define ev_off_t ... +#else +#define ev_off_t off_t +#endif + +#ifndef EVENT__HAVE_STDINT_H +#define EV_UINT64_MAX ((((ev_uint64_t)0xffffffffUL) << 32) | 0xffffffffUL) +#define EV_INT64_MAX ((((ev_int64_t)0x7fffffffL) << 32) | 0xffffffffL) +#define EV_INT64_MIN ((-EV_INT64_MAX) - 1) +#define EV_UINT32_MAX ((ev_uint32_t)0xffffffffUL) +#define EV_INT32_MAX ((ev_int32_t)0x7fffffffL) +#define EV_INT32_MIN ((-EV_INT32_MAX) - 1) +#define EV_UINT16_MAX ((ev_uint16_t)0xffffUL) +#define EV_INT16_MAX ((ev_int16_t)0x7fffL) +#define EV_INT16_MIN ((-EV_INT16_MAX) - 1) +#define EV_UINT8_MAX 255 +#define EV_INT8_MAX 127 +#define EV_INT8_MIN ((-EV_INT8_MAX) - 1) +#else +#define EV_UINT64_MAX UINT64_MAX +#define EV_INT64_MAX INT64_MAX +#define EV_INT64_MIN INT64_MIN +#define EV_UINT32_MAX UINT32_MAX +#define EV_INT32_MAX INT32_MAX +#define EV_INT32_MIN INT32_MIN +#define EV_UINT16_MAX UINT16_MAX +#define EV_INT16_MAX INT16_MAX +#define EV_UINT8_MAX UINT8_MAX +#define EV_INT8_MAX INT8_MAX +#define EV_INT8_MIN INT8_MIN + +#endif + +#if EVENT__SIZEOF_SIZE_T == 8 +#define EV_SIZE_MAX EV_UINT64_MAX +#define EV_SSIZE_MAX EV_INT64_MAX +#elif EVENT__SIZEOF_SIZE_T == 4 +#define EV_SIZE_MAX EV_UINT32_MAX +#define EV_SSIZE_MAX EV_INT32_MAX +#elif defined(EVENT_IN_DOXYGEN_) +#define EV_SIZE_MAX ... +#define EV_SSIZE_MAX ... +#else +#error "No way to define SIZE_MAX" +#endif + +#define EV_SSIZE_MIN ((-EV_SSIZE_MAX) - 1) + +#ifdef _WIN32 +#define ev_socklen_t int +#elif defined(EVENT__socklen_t) +#define ev_socklen_t EVENT__socklen_t +#else +#define ev_socklen_t socklen_t +#endif + +#ifdef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY +#if !defined(EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) && !defined(ss_family) +#define ss_family __ss_family +#endif +#endif + +#ifdef _WIN32 +#define evutil_socket_t intptr_t +#else +#define evutil_socket_t int +#endif + +struct evutil_monotonic_timer +#ifdef EVENT_IN_DOXYGEN_ +{ /*Empty body so that doxygen will generate documentation here.*/ +} +#endif +; + +#define EV_MONOT_PRECISE 1 +#define EV_MONOT_FALLBACK 2 + +int evutil_date_rfc1123(char* date, const size_t datelen, const struct tm* tm); + +struct evutil_monotonic_timer* evutil_monotonic_timer_new(void); + +void evutil_monotonic_timer_free(struct evutil_monotonic_timer* timer); + +int evutil_configure_monotonic_time(struct evutil_monotonic_timer* timer, int flags); + +int evutil_gettime_monotonic(struct evutil_monotonic_timer* timer, struct timeval* tp); + +int evutil_socketpair(int d, int type, int protocol, evutil_socket_t sv[2]); + +int evutil_make_socket_nonblocking(evutil_socket_t sock); + +int evutil_make_listen_socket_reuseable(evutil_socket_t sock); + +int evutil_make_listen_socket_reuseable_port(evutil_socket_t sock); + +int evutil_make_socket_closeonexec(evutil_socket_t sock); + +int evutil_closesocket(evutil_socket_t sock); +#define EVUTIL_CLOSESOCKET(s) evutil_closesocket(s) + +int evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock); + +#ifdef _WIN32 +/** Return the most recent socket error. Not idempotent on all platforms. */ +#define EVUTIL_SOCKET_ERROR() WSAGetLastError() +/** Replace the most recent socket error with errcode */ +#define EVUTIL_SET_SOCKET_ERROR(errcode) \ + do { \ + WSASetLastError(errcode); \ + } while (0) +/** Return the most recent socket error to occur on sock. */ + +int evutil_socket_geterror(evutil_socket_t sock); +/** Convert a socket error to a string. */ + +const char* evutil_socket_error_to_string(int errcode); +#elif defined(EVENT_IN_DOXYGEN_) + +#define EVUTIL_SOCKET_ERROR() ... +/** Replace the most recent socket error with errcode */ +#define EVUTIL_SET_SOCKET_ERROR(errcode) ... +/** Return the most recent socket error to occur on sock. */ +#define evutil_socket_geterror(sock) ... +/** Convert a socket error to a string. */ +#define evutil_socket_error_to_string(errcode) ... +/**@}*/ +#else +#define EVUTIL_SOCKET_ERROR() (errno) +#define EVUTIL_SET_SOCKET_ERROR(errcode) \ + do { \ + errno = (errcode); \ + } while (0) +#define evutil_socket_geterror(sock) (errno) +#define evutil_socket_error_to_string(errcode) (strerror(errcode)) +#endif + +#ifdef EVENT__HAVE_TIMERADD +#define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp)) +#define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp)) +#else +#define evutil_timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define evutil_timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) +#endif /* !EVENT__HAVE_TIMERADD */ + +#ifdef EVENT__HAVE_TIMERCLEAR +#define evutil_timerclear(tvp) timerclear(tvp) +#else +#define evutil_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +#endif +/**@}*/ + +/** Return true iff the tvp is related to uvp according to the relational + * operator cmp. Recognized values for cmp are ==, <=, <, >=, and >. */ +#define evutil_timercmp(tvp, uvp, cmp) (((tvp)->tv_sec == (uvp)->tv_sec) ? ((tvp)->tv_usec cmp(uvp)->tv_usec) : ((tvp)->tv_sec cmp(uvp)->tv_sec)) + +#ifdef EVENT__HAVE_TIMERISSET +#define evutil_timerisset(tvp) timerisset(tvp) +#else +#define evutil_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#endif + +/** Replacement for offsetof on platforms that don't define it. */ +#ifdef offsetof +#define evutil_offsetof(type, field) offsetof(type, field) +#else +#define evutil_offsetof(type, field) ((off_t)(&((type*)0)->field)) +#endif + +/* big-int related functions */ +/** Parse a 64-bit value from a string. Arguments are as for strtol. */ + +ev_int64_t evutil_strtoll(const char* s, char** endptr, int base); + +/** Replacement for gettimeofday on platforms that lack it. */ +#ifdef EVENT__HAVE_GETTIMEOFDAY +#define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz)) +#else +struct timezone; + +int evutil_gettimeofday(struct timeval* tv, struct timezone* tz); +#endif + +int evutil_snprintf(char* buf, size_t buflen, const char* format, ...) +#ifdef __GNUC__ + __attribute__((format(printf, 3, 4))) +#endif + ; + +int evutil_vsnprintf(char* buf, size_t buflen, const char* format, va_list ap) +#ifdef __GNUC__ + __attribute__((format(printf, 3, 0))) +#endif + ; + +/** Replacement for inet_ntop for platforms which lack it. */ + +const char* evutil_inet_ntop(int af, const void* src, char* dst, size_t len); +/** Replacement for inet_pton for platforms which lack it. */ + +int evutil_inet_pton(int af, const char* src, void* dst); +struct sockaddr; + +int evutil_parse_sockaddr_port(const char* str, struct sockaddr* out, int* outlen); + +int evutil_sockaddr_cmp(const struct sockaddr* sa1, const struct sockaddr* sa2, int include_port); + +int evutil_ascii_strcasecmp(const char* str1, const char* str2); + +int evutil_ascii_strncasecmp(const char* str1, const char* str2, size_t n); + +/* Here we define evutil_addrinfo to the native addrinfo type, or redefine it + * if this system has no getaddrinfo(). */ +#ifdef EVENT__HAVE_STRUCT_ADDRINFO +#define evutil_addrinfo addrinfo +#else +/** A definition of struct addrinfo for systems that lack it. + + (This is just an alias for struct addrinfo if the system defines + struct addrinfo.) +*/ +struct evutil_addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char* ai_canonname; /* canonical name for nodename */ + struct sockaddr* ai_addr; /* binary address */ + struct evutil_addrinfo* ai_next; /* next structure in linked list */ +}; +#endif +/** @name evutil_getaddrinfo() error codes + + These values are possible error codes for evutil_getaddrinfo() and + related functions. + + @{ +*/ +#if defined(EAI_ADDRFAMILY) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_ADDRFAMILY EAI_ADDRFAMILY +#else +#define EVUTIL_EAI_ADDRFAMILY -901 +#endif +#if defined(EAI_AGAIN) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_AGAIN EAI_AGAIN +#else +#define EVUTIL_EAI_AGAIN -902 +#endif +#if defined(EAI_BADFLAGS) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_BADFLAGS EAI_BADFLAGS +#else +#define EVUTIL_EAI_BADFLAGS -903 +#endif +#if defined(EAI_FAIL) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_FAIL EAI_FAIL +#else +#define EVUTIL_EAI_FAIL -904 +#endif +#if defined(EAI_FAMILY) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_FAMILY EAI_FAMILY +#else +#define EVUTIL_EAI_FAMILY -905 +#endif +#if defined(EAI_MEMORY) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_MEMORY EAI_MEMORY +#else +#define EVUTIL_EAI_MEMORY -906 +#endif +/* This test is a bit complicated, since some MS SDKs decide to + * remove NODATA or redefine it to be the same as NONAME, in a + * fun interpretation of RFC 2553 and RFC 3493. */ +#if defined(EAI_NODATA) && defined(EVENT__HAVE_GETADDRINFO) && (!defined(EAI_NONAME) || EAI_NODATA != EAI_NONAME) +#define EVUTIL_EAI_NODATA EAI_NODATA +#else +#define EVUTIL_EAI_NODATA -907 +#endif +#if defined(EAI_NONAME) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_NONAME EAI_NONAME +#else +#define EVUTIL_EAI_NONAME -908 +#endif +#if defined(EAI_SERVICE) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_SERVICE EAI_SERVICE +#else +#define EVUTIL_EAI_SERVICE -909 +#endif +#if defined(EAI_SOCKTYPE) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_SOCKTYPE EAI_SOCKTYPE +#else +#define EVUTIL_EAI_SOCKTYPE -910 +#endif +#if defined(EAI_SYSTEM) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_EAI_SYSTEM EAI_SYSTEM +#else +#define EVUTIL_EAI_SYSTEM -911 +#endif + +#define EVUTIL_EAI_CANCEL -90001 + +#if defined(AI_PASSIVE) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_AI_PASSIVE AI_PASSIVE +#else +#define EVUTIL_AI_PASSIVE 0x1000 +#endif +#if defined(AI_CANONNAME) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_AI_CANONNAME AI_CANONNAME +#else +#define EVUTIL_AI_CANONNAME 0x2000 +#endif +#if defined(AI_NUMERICHOST) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_AI_NUMERICHOST AI_NUMERICHOST +#else +#define EVUTIL_AI_NUMERICHOST 0x4000 +#endif +#if defined(AI_NUMERICSERV) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_AI_NUMERICSERV AI_NUMERICSERV +#else +#define EVUTIL_AI_NUMERICSERV 0x8000 +#endif +#if defined(AI_V4MAPPED) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_AI_V4MAPPED AI_V4MAPPED +#else +#define EVUTIL_AI_V4MAPPED 0x10000 +#endif +#if defined(AI_ALL) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_AI_ALL AI_ALL +#else +#define EVUTIL_AI_ALL 0x20000 +#endif +#if defined(AI_ADDRCONFIG) && defined(EVENT__HAVE_GETADDRINFO) +#define EVUTIL_AI_ADDRCONFIG AI_ADDRCONFIG +#else +#define EVUTIL_AI_ADDRCONFIG 0x40000 +#endif +/**@}*/ + +struct evutil_addrinfo; + +int evutil_getaddrinfo(const char* nodename, const char* servname, const struct evutil_addrinfo* hints_in, struct evutil_addrinfo** res); + +void evutil_freeaddrinfo(struct evutil_addrinfo* ai); + +const char* evutil_gai_strerror(int err); + +void evutil_secure_rng_get_bytes(void* buf, size_t n); + +int evutil_secure_rng_init(void); + +int evutil_secure_rng_set_urandom_device_file(char* fname); + +void evutil_secure_rng_add_bytes(const char* dat, size_t datlen); + +#ifdef __cplusplus +} +#endif + +#endif /* EVENT1_EVUTIL_H_INCLUDED_ */ diff --git a/asynio/event/win32select.c b/asynio/event/win32select.c new file mode 100644 index 0000000000000000000000000000000000000000..23f14e5a06dd1ed7f96e71d0845a02eed919f7da --- /dev/null +++ b/asynio/event/win32select.c @@ -0,0 +1,369 @@ +/* + * Copyright 2007-2012 Niels Provos and Nick Mathewson + * Copyright 2000-2007 Niels Provos + * Copyright 2003 Michael A. Davis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "event-config.h" +#include "evconfig-private.h" + +#ifdef _WIN32 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "util-internal.h" +#include "log-internal.h" +#include "eventbase.h" +#include "event-internal.h" +#include "evmap-internal.h" +#include "thread.h" +#include "evthread-internal.h" +#include "time-internal.h" + +#define XFREE(ptr) \ + do { \ + if (ptr) \ + mm_free(ptr); \ + } while (0) + +extern struct event_list timequeue; +extern struct event_list addqueue; + +struct win_fd_set { + unsigned int fd_count; + SOCKET fd_array[1]; +}; + +/* MSDN says this is required to handle SIGFPE */ +volatile double SIGFPE_REQ = 0.0f; + +struct idx_info { + int read_pos_plus1; + int write_pos_plus1; +}; + +struct win32op { + unsigned num_fds_in_fd_sets; + int resize_out_sets; + struct win_fd_set* readset_in; + struct win_fd_set* writeset_in; + struct win_fd_set* readset_out; + struct win_fd_set* writeset_out; + struct win_fd_set* exset_out; + unsigned signals_are_broken : 1; +}; + +static void* win32_init(struct event_base*); +static int win32_add(struct event_base*, evutil_socket_t, short old, short events, void* idx_); +static int win32_del(struct event_base*, evutil_socket_t, short old, short events, void* idx_); +static int win32_dispatch(struct event_base* base, struct timeval*); +static void win32_dealloc(struct event_base*); + +struct eventop win32ops = { + "win32", + win32_init, + win32_add, + win32_del, + win32_dispatch, + win32_dealloc, + 0, /* doesn't need reinit */ + 0, /* No features supported. */ + sizeof(struct idx_info), +}; + +#define FD_SET_ALLOC_SIZE(n) ((sizeof(struct win_fd_set) + ((n)-1) * sizeof(SOCKET))) + +static int grow_fd_sets(struct win32op* op, unsigned new_num_fds) +{ + size_t size; + + EVUTIL_ASSERT(new_num_fds >= op->readset_in->fd_count && new_num_fds >= op->writeset_in->fd_count); + EVUTIL_ASSERT(new_num_fds >= 1); + + size = FD_SET_ALLOC_SIZE(new_num_fds); + if (!(op->readset_in = mm_realloc(op->readset_in, size))) + return (-1); + if (!(op->writeset_in = mm_realloc(op->writeset_in, size))) + return (-1); + op->resize_out_sets = 1; + op->num_fds_in_fd_sets = new_num_fds; + return (0); +} + +static int do_fd_set(struct win32op* op, struct idx_info* ent, evutil_socket_t s, int read) +{ + struct win_fd_set* set = read ? op->readset_in : op->writeset_in; + if (read) { + if (ent->read_pos_plus1 > 0) + return (0); + } else { + if (ent->write_pos_plus1 > 0) + return (0); + } + if (set->fd_count == op->num_fds_in_fd_sets) { + if (grow_fd_sets(op, op->num_fds_in_fd_sets * 2)) + return (-1); + /* set pointer will have changed and needs reiniting! */ + set = read ? op->readset_in : op->writeset_in; + } + set->fd_array[set->fd_count] = s; + if (read) + ent->read_pos_plus1 = set->fd_count + 1; + else + ent->write_pos_plus1 = set->fd_count + 1; + return (set->fd_count++); +} + +static int do_fd_clear(struct event_base* base, struct win32op* op, struct idx_info* ent, int read) +{ + int i; + struct win_fd_set* set = read ? op->readset_in : op->writeset_in; + if (read) { + i = ent->read_pos_plus1 - 1; + ent->read_pos_plus1 = 0; + } else { + i = ent->write_pos_plus1 - 1; + ent->write_pos_plus1 = 0; + } + if (i < 0) + return (0); + if (--set->fd_count != (unsigned)i) { + struct idx_info* ent2; + SOCKET s2; + s2 = set->fd_array[i] = set->fd_array[set->fd_count]; + + ent2 = evmap_io_get_fdinfo_(&base->io, s2); + + if (!ent2) /* This indicates a bug. */ + return (0); + if (read) + ent2->read_pos_plus1 = i + 1; + else + ent2->write_pos_plus1 = i + 1; + } + return (0); +} + +#define NEVENT 32 +void* win32_init(struct event_base* base) +{ + struct win32op* winop; + size_t size; + if (!(winop = mm_calloc(1, sizeof(struct win32op)))) + return NULL; + winop->num_fds_in_fd_sets = NEVENT; + size = FD_SET_ALLOC_SIZE(NEVENT); + if (!(winop->readset_in = mm_malloc(size))) + goto err; + if (!(winop->writeset_in = mm_malloc(size))) + goto err; + if (!(winop->readset_out = mm_malloc(size))) + goto err; + if (!(winop->writeset_out = mm_malloc(size))) + goto err; + if (!(winop->exset_out = mm_malloc(size))) + goto err; + winop->readset_in->fd_count = winop->writeset_in->fd_count = 0; + winop->readset_out->fd_count = winop->writeset_out->fd_count = winop->exset_out->fd_count = 0; + + if (evsig_init_(base) < 0) + winop->signals_are_broken = 1; + + evutil_weakrand_seed_(&base->weakrand_seed, 0); + + return (winop); +err: + XFREE(winop->readset_in); + XFREE(winop->writeset_in); + XFREE(winop->readset_out); + XFREE(winop->writeset_out); + XFREE(winop->exset_out); + XFREE(winop); + return (NULL); +} + +int win32_add(struct event_base* base, evutil_socket_t fd, short old, short events, void* idx_) +{ + struct win32op* win32op = base->evbase; + struct idx_info* idx = idx_; + + if ((events & EV_SIGNAL) && win32op->signals_are_broken) + return (-1); + + if (!(events & (EV_READ | EV_WRITE))) + return (0); + + event_debug(("%s: adding event for %d", __func__, (int)fd)); + if (events & EV_READ) { + if (do_fd_set(win32op, idx, fd, 1) < 0) + return (-1); + } + if (events & EV_WRITE) { + if (do_fd_set(win32op, idx, fd, 0) < 0) + return (-1); + } + return (0); +} + +int win32_del(struct event_base* base, evutil_socket_t fd, short old, short events, void* idx_) +{ + struct win32op* win32op = base->evbase; + struct idx_info* idx = idx_; + + event_debug(("%s: Removing event for " EV_SOCK_FMT, __func__, EV_SOCK_ARG(fd))); + if (events & EV_READ) + do_fd_clear(base, win32op, idx, 1); + if (events & EV_WRITE) + do_fd_clear(base, win32op, idx, 0); + + return 0; +} + +static void fd_set_copy(struct win_fd_set* out, const struct win_fd_set* in) +{ + out->fd_count = in->fd_count; + memcpy(out->fd_array, in->fd_array, in->fd_count * (sizeof(SOCKET))); +} + +/* + static void dump_fd_set(struct win_fd_set *s) + { + unsigned int i; + printf("[ "); + for(i=0;ifd_count;++i) + printf("%d ",(int)s->fd_array[i]); + printf("]\n"); + } +*/ + +int win32_dispatch(struct event_base* base, struct timeval* tv) +{ + struct win32op* win32op = base->evbase; + int res = 0; + unsigned j, i; + int fd_count; + SOCKET s; + + if (win32op->resize_out_sets) { + size_t size = FD_SET_ALLOC_SIZE(win32op->num_fds_in_fd_sets); + if (!(win32op->readset_out = mm_realloc(win32op->readset_out, size))) + return (-1); + if (!(win32op->exset_out = mm_realloc(win32op->exset_out, size))) + return (-1); + if (!(win32op->writeset_out = mm_realloc(win32op->writeset_out, size))) + return (-1); + win32op->resize_out_sets = 0; + } + + fd_set_copy(win32op->readset_out, win32op->readset_in); + fd_set_copy(win32op->exset_out, win32op->writeset_in); + fd_set_copy(win32op->writeset_out, win32op->writeset_in); + + fd_count = (win32op->readset_out->fd_count > win32op->writeset_out->fd_count) ? win32op->readset_out->fd_count : win32op->writeset_out->fd_count; + + if (!fd_count) { + long msec = tv ? evutil_tv_to_msec_(tv) : LONG_MAX; + /* Sleep's DWORD argument is unsigned long */ + if (msec < 0) + msec = LONG_MAX; + /* Windows doesn't like you to call select() with no sockets */ + Sleep(msec); + return (0); + } + + EVBASE_RELEASE_LOCK(base, th_base_lock); + + res = select(fd_count, (struct fd_set*)win32op->readset_out, (struct fd_set*)win32op->writeset_out, (struct fd_set*)win32op->exset_out, tv); + + EVBASE_ACQUIRE_LOCK(base, th_base_lock); + + event_debug(("%s: select returned %d", __func__, res)); + + if (res <= 0) { + return res; + } + + if (win32op->readset_out->fd_count) { + i = evutil_weakrand_range_(&base->weakrand_seed, win32op->readset_out->fd_count); + for (j = 0; j < win32op->readset_out->fd_count; ++j) { + if (++i >= win32op->readset_out->fd_count) + i = 0; + s = win32op->readset_out->fd_array[i]; + evmap_io_active_(base, s, EV_READ); + } + } + if (win32op->exset_out->fd_count) { + i = evutil_weakrand_range_(&base->weakrand_seed, win32op->exset_out->fd_count); + for (j = 0; j < win32op->exset_out->fd_count; ++j) { + if (++i >= win32op->exset_out->fd_count) + i = 0; + s = win32op->exset_out->fd_array[i]; + evmap_io_active_(base, s, EV_WRITE); + } + } + if (win32op->writeset_out->fd_count) { + SOCKET s; + i = evutil_weakrand_range_(&base->weakrand_seed, win32op->writeset_out->fd_count); + for (j = 0; j < win32op->writeset_out->fd_count; ++j) { + if (++i >= win32op->writeset_out->fd_count) + i = 0; + s = win32op->writeset_out->fd_array[i]; + evmap_io_active_(base, s, EV_WRITE); + } + } + return (0); +} + +void win32_dealloc(struct event_base* base) +{ + struct win32op* win32op = base->evbase; + + evsig_dealloc_(base); + if (win32op->readset_in) + mm_free(win32op->readset_in); + if (win32op->writeset_in) + mm_free(win32op->writeset_in); + if (win32op->readset_out) + mm_free(win32op->readset_out); + if (win32op->writeset_out) + mm_free(win32op->writeset_out); + if (win32op->exset_out) + mm_free(win32op->exset_out); + /* XXXXX free the tree. */ + + memset(win32op, 0, sizeof(*win32op)); + mm_free(win32op); +} + +#endif diff --git a/asynio/fileimpl.cpp b/asynio/fileimpl.cpp deleted file mode 100644 index cbdbe3375bfe96f96fd8cb53121309d0b95b0930..0000000000000000000000000000000000000000 --- a/asynio/fileimpl.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "fileimpl.h" - -CFileImpl::CFileImpl(void) -{ - m_hFile = FILE_INVALID; -} -CFileImpl::~CFileImpl(void) -{ -} -HRESULT CFileImpl::LoadFile( - const basic_tchar* pszLoadFile, - unsigned long ulwDesiredAccess, - unsigned long ulShareMode, - unsigned long ulCreationDisposition, - unsigned long ulFlagsAndAttributes) -{ - HRESULT hr = S_OK; - m_hFile = _file_open(pszLoadFile, O_RDWR, 0644); - return hr; -} -HRESULT CFileImpl::CloseFile() -{ - HRESULT hr = S_OK; - _file_close(m_hFile); - return hr; -} -int64 CFileImpl::GetFileSize() -{ - return _file_fsize(m_hFile); -} - -HRESULT CFileImpl::ReadBuffer(char* szBuffer, int64 ulReadFileLen, int64* ulReadSize) -{ - HRESULT hr = S_OK; - - size_t size = ulReadFileLen & UINT32_MAX; - - *ulReadSize = _file_read(m_hFile, szBuffer, size); - - return hr; -} -HRESULT CFileImpl::WriteBuffer(char* szBuffer, int64 ulWriteSize) -{ - HRESULT hr = S_OK; - - size_t size = ulWriteSize & UINT32_MAX; - - _file_write(m_hFile, szBuffer, size); - - return hr; -} diff --git a/asynio/fileimpl.h b/asynio/fileimpl.h deleted file mode 100644 index f1370b8cfb5f654b92aff27fe42f3d36444ae6eb..0000000000000000000000000000000000000000 --- a/asynio/fileimpl.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _FILEIMPL_H_ -#define _FILEIMPL_H_ - -#include "stdafx.h" - -class CFileImpl : public IFile, - public CUnknownImp -{ -public: - CFileImpl(void); - virtual ~CFileImpl(void); - - BEGIN_STDCOM_MAP - STDCOM_INTERFACE_ENTRY(IFile) - STDCOM_INTERFACE_ENTRY_UNKNOWN_(IFile) - END_STDCOM_MAP - - // IFile - std_method(LoadFile)( - const basic_tchar* pszLoadFile, - unsigned long ulwDesiredAccess, - unsigned long ulShareMode, - unsigned long ulCreationDisposition, - unsigned long ulFlagsAndAttributes); - std_method(CloseFile)(); - std_method_(int64, GetFileSize)(); - std_method(ReadBuffer)(char* szBuffer, int64 ulReadFileLen, int64* ulReadSize); - std_method(WriteBuffer)(char* szBuffer, int64 ulWriteSize); - -private: - _fd_t m_hFile; -}; -#endif diff --git a/asynio/interface.cpp b/asynio/interface.cpp index 9fe8f6468658b8133c3638f6f29301d2b05c8cd2..c6dce452a73632c1741c28d8209f13bb7d9539a3 100644 --- a/asynio/interface.cpp +++ b/asynio/interface.cpp @@ -49,13 +49,12 @@ _DEF_CLSID_IMPL(StdCom::IID_IMsgPlugin, 0x5f8488ed, 0x8dba, 0x4c96, 0x92, 0x84, // {FEB12B33-7344-45CD-A375-2495C7BEBD88} _DEF_IID_IMPL(IID_IOperation, 0xfeb12b33, 0x7344, 0x45cd, 0xa3, 0x75, 0x24, 0x95, 0xc7, 0xbe, 0xbd, 0x88); // {0470327E-5ACF-40EC-BAED-FE2AAE877B4B} -_DEF_IID_IMPL(IID_IOperationEvent, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); - -// ifile.h -// {978D055C-CF46-44C4-BE6C-E537C0E698C5} -_DEF_IID_IMPL(IID_IFile, 0x978d055c, 0xcf46, 0x44c4, 0xbe, 0x6c, 0xe5, 0x37, 0xc0, 0xe6, 0x98, 0xc5); +_DEF_IID_IMPL(IID_IOperationProc, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); // isocket.h + +// {9C926805-64F5-4728-86A4-AB0208AA1487} +_DEF_IID_IMPL(IID_ISockProc, 0x9c926805, 0x64f5, 0x4728, 0x86, 0xa4, 0xab, 0x2, 0x8, 0xaa, 0x14, 0x87); // {BB9DA617-80BE-4E04-8EB4-13CF43F1EBD1} _DEF_IID_IMPL(IID_IListen, 0xbb9da617, 0x80be, 0x4e04, 0x8e, 0xb4, 0x13, 0xcf, 0x43, 0xf1, 0xeb, 0xd1); // {4337751F-F25B-406C-9FB9-7BA540481BB1} @@ -83,7 +82,7 @@ _DEF_CLSID_IMPL(CLSID_CAsynFrame, 0xf170a724, 0xaaca, 0x4603, 0xbb, 0x1c, 0xa, 0 // itimer.h // {B5819C73-6EF7-4F25-B053-F6F6D4DCBE00} -_DEF_IID_IMPL(IID_ITimerEvent, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); +_DEF_IID_IMPL(IID_ITimerProc, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); // {F36A3734-C9CA-46C9-8F03-AD02AD24058F} _DEF_IID_IMPL(IID_ITimer, 0xf36a3734, 0xc9ca, 0x46c9, 0x8f, 0x3, 0xad, 0x2, 0xad, 0x24, 0x5, 0x8f); diff --git a/asynio/ioev.cpp b/asynio/ioev.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f5fcedc41d621ae507085ffc64108c7732affd2 --- /dev/null +++ b/asynio/ioev.cpp @@ -0,0 +1,286 @@ +#include "ioevdef.h" +#include "bufferevent-internal.h" +#include "bufferevent_ssl.h" + +static void on_tcperrorcb(evlistenptr listener, void* arg) +{ + ioevtcp_t* tcp = (ioevtcp_t*)(arg); + c_assert(tcp != NULL); + c_assert(tcp->event != NULL); + tcp->event(tcp, IOEVTCP_ERROR); +} +static void on_tcpacceptcb(evlistenptr listen, _sock_t fd, struct sockaddr* addr, int sl, void* arg) +{ + ioevtcp_t* tcp = (ioevtcp_t*)(arg); + c_assert(tcp != NULL); + c_assert(tcp->accept != NULL); + tcp->accept(tcp, addr, sl, fd); + logi("on_tcpacceptcb"); +} +static void on_readcb(struct bufferevent* bev, void* arg) +{ + ioevstream_t* stream = (ioevstream_t*)(arg); + c_assert(stream != NULL); + size_t len = evbuffer_get_length(bufferevent_get_input(bev)); + len = bufferevent_read(bev, stream->out.ptr, stream->out.len); + + bufferevent_disable(stream->bev, EV_READ); + c_assert(stream->read != NULL); + + stream->read(stream, IOEVTCP_SUCCESS, stream->out.ptr, len); +} +static void on_writecb(struct bufferevent* bev, void* arg) +{ + ioevstream_t* stream = (ioevstream_t*)(arg); + c_assert(stream != NULL); + size_t len = evbuffer_get_length(bufferevent_get_output(bev)); + bufferevent_disable(stream->bev, EV_WRITE); + c_assert(stream->write != NULL); + stream->write(stream, IOEVTCP_SUCCESS, NULL, len); +} +static void on_eventcb(struct bufferevent* bev, short what, void* arg) +{ + ioevstream_t* stream = (ioevstream_t*)(arg); + c_assert(stream != NULL); + c_assert(stream->event != NULL); + + _sock_t fd = bufferevent_getfd(stream->bev); + int ret = evutil_socket_finished_connecting_(bufferevent_getfd(stream->bev)); + short code = ret == 1 ? IOEVTCP_SUCCESS : IOEV_STREAM_EOF; + + if (what & BEV_EVENT_EOF) { + stream->event(stream, IOEVTCP_ERROR, IOEV_STREAM_EOF, fd); + } else if (what & BEV_EVENT_TIMEOUT) { + stream->event(stream, IOEVTCP_ERROR, BEV_EVENT_TIMEOUT, fd); + } else if(what & BEV_EVENT_CONNECTED) { + stream->event(stream, code, IOEVSTREAM_OPEN, fd); + } + +} +static int stream_connsock(ioevstream_t* stream, SOCKADDR_PTR sa, socklen_t sl, TVL_PTR tv) +{ + rc_assert(stream != NULL, S_ERROR); + bufferevent_set_timeouts(stream->bev, tv, tv); + bufferevent_setcb(stream->bev, on_readcb, on_writecb, on_eventcb, stream); + bufferevent_socket_connect(stream->bev, sa, sl); + return S_SUCCESS; +} +int ioevloop_setctx(ioevloop_t* loop, void* ctx) +{ + rc_assert(loop != NULL, S_ERROR); + loop->ctx = ctx; + return S_SUCCESS; +} +void* ioevloop_getctx(ioevloop_t* loop) +{ + rc_assert(loop != NULL, NULL); + return loop->ctx; +} +int ioevtcp_init(ioevtcp_t* tcp, ioevloop_t* evloop, _sock_t sock) +{ + rc_assert(tcp != NULL, S_ERROR); + + tcp->listen = evconnlistener_new(evloop->loop, NULL, NULL, IOEV_TCP_OPTIONS, 0, sock); + + //| LEV_OPT_DISABLED + rc_assert(tcp->listen != NULL, S_ERROR); + + evconnlistener_set_cb(tcp->listen, on_tcpacceptcb, tcp); + evconnlistener_set_error_cb(tcp->listen, on_tcperrorcb); + + return S_SUCCESS; +} +int ioevtcp_uninit(ioevtcp_t* tcp) +{ + rc_assert(tcp != NULL, S_ERROR); + evconnlistener_disable(tcp->listen); + evconnlistener_free(tcp->listen); + return S_SUCCESS; +} +int ioevtcp_setctx(ioevtcp_t* tcp, void* ctx) +{ + rc_assert(tcp != NULL, S_ERROR); + tcp->ctx = ctx; + return S_SUCCESS; +} +void* ioevtcp_getctx(ioevtcp_t* tcp) +{ + rc_assert(tcp != NULL, NULL); + return tcp->ctx; +} +int ioevtcp_seteventcb(ioevtcp_t* tcp, tcp_eventcb cb) +{ + rc_assert(tcp != NULL, S_ERROR); + tcp->event = cb; + return S_SUCCESS; +} +int ioevtcp_setacceptcb(ioevtcp_t* tcp, tcp_acceptcb cb) +{ + rc_assert(tcp != NULL, S_ERROR); + tcp->accept = cb; + return S_SUCCESS; +} +int ioevtcp_bind(ioevtcp_t* tcp, NET_ADDR ip, NET_ADDR_PORT port) +{ + rc_assert(tcp != NULL, S_ERROR); + + evutil_socket_t sock = evconnlistener_get_fd(tcp->listen); + _bind_stcpsockv4(sock, ip, s_strlen(ip), 128, port); + return S_SUCCESS; +} +int ioevtcp_bind6(ioevtcp_t* tcp, NET_ADDR ip, NET_ADDR_PORT port) +{ + rc_assert(tcp != NULL, S_ERROR); + evutil_socket_t sock = evconnlistener_get_fd(tcp->listen); + _bind_stcpsockv6(sock, ip, s_strlen(ip), 128, port); + return S_SUCCESS; +} +int ioevtcp_enable(ioevtcp_t* tcp) +{ + rc_assert(tcp != NULL, S_ERROR); + evconnlistener_set_cb(tcp->listen, on_tcpacceptcb, tcp); + evconnlistener_enable(tcp->listen); + return S_SUCCESS; +} +int ioevtcp_disable(ioevtcp_t* tcp) +{ + rc_assert(tcp != NULL, S_ERROR); + evconnlistener_set_cb(tcp->listen, NULL, NULL); + evconnlistener_disable(tcp->listen); + return S_SUCCESS; +} + +int ioevstream_init(ioevstream_t* stream, ioevloop_t* evloop, _sock_t sock) +{ + stream->bev = bufferevent_socket_new(evloop->loop, sock, IOEV_STREAM_OPTIONS); + rc_assert(stream != NULL, S_ERROR); + rc_assert(stream->bev != NULL, S_ERROR); + + bufferevent_setcb(stream->bev, on_readcb, on_writecb, on_eventcb, stream); + bufferevent_disable(stream->bev, EV_READ | EV_WRITE | EV_ET ); + + return S_SUCCESS; +} +int ioevstream_uninit(ioevstream_t* stream) +{ + rc_assert(stream != NULL, S_ERROR); + bufferevent_free(stream->bev); + return S_SUCCESS; +} +int ioevstream_assign(ioevstream_t* stream, _sock_t sock) +{ + rc_assert(stream != NULL, S_ERROR); + bufferevent_setfd(stream->bev, sock); + return S_SUCCESS; +} +int ioevstream_setctx(ioevstream_t* stream, void* ctx) +{ + rc_assert(stream != NULL, S_ERROR); + stream->ctx = ctx; + return S_SUCCESS; +} +void* ioevstream_getctx(ioevstream_t* stream) +{ + rc_assert(stream != NULL, NULL); + return stream->ctx; +} +int ioevstream_seteventcb(ioevstream_t* stream, stream_eventcb cb) +{ + rc_assert(stream != NULL, S_ERROR); + stream->event = cb; + return S_SUCCESS; +} +int ioevstream_setreadcb(ioevstream_t* stream, stream_readcb cb) +{ + rc_assert(stream != NULL, S_ERROR); + stream->read = cb; + return S_SUCCESS; +} +int ioevstream_setwritecb(ioevstream_t* stream, stream_writecb cb) +{ + rc_assert(stream != NULL, S_ERROR); + stream->write = cb; + return S_SUCCESS; +} +int ioevstream_write(ioevstream_t* stream, BUF_PTR ptr, BUF_SIZE len, int sec) +{ + struct timeval timeout; + + rc_assert(stream != NULL, S_ERROR); + + timeout.tv_sec = sec; + timeout.tv_usec = 0; + + //bufferevent_set_timeouts(stream->bev, NULL, &timeout); + + stream->in.ptr = ptr; + stream->in.len = len; + + + //bufferevent_setwatermark(stream->bev, EV_WRITE, 0, 1024); + bufferevent_write(stream->bev, stream->in.ptr, stream->in.len); + bufferevent_enable(stream->bev, EV_WRITE); + + return S_SUCCESS; +} +int ioevstream_read(ioevstream_t* stream, BUF_PTR ptr, BUF_SIZE len, int sec) +{ + struct timeval tv; + + rc_assert(stream != NULL, S_ERROR); + + tv.tv_sec = sec; + tv.tv_usec = 0; + + bufferevent_set_timeouts(stream->bev, &tv, &tv); + + stream->out.ptr = ptr; + stream->out.len = len; + + bufferevent_setwatermark(stream->bev, EV_READ, len, len); + bufferevent_enable(stream->bev, EV_READ); + + return S_SUCCESS; +} +int ioevstream_connectsock(ioevstream_t* stream, NET_ADDR ip, NET_ADDR_PORT port, int sec) +{ + struct sockaddr_in saddr; + struct timeval tv; + + rc_assert(stream != NULL, S_ERROR); + + tv.tv_sec = sec; + tv.tv_usec = 0; + + s_memset(&saddr, 0, sizeof(struct sockaddr_in)); + saddr.sin_family = AF_INET; + saddr.sin_addr.s_addr = inet_addr(ip); + saddr.sin_port = htons(port); + + stream_connsock(stream, (struct sockaddr*)&saddr, sizeof(saddr), &tv); + + return S_SUCCESS; +} +int ioevstream_connect6sock(ioevstream_t* stream, NET_ADDR ip, NET_ADDR_PORT port, int sec) +{ + struct sockaddr_in6 saddr6; + struct timeval tv; + + rc_assert(stream != NULL, S_ERROR); + + tv.tv_sec = sec; + tv.tv_usec = 0; + + s_memset(&saddr6, 0, sizeof(struct sockaddr_in6)); + + saddr6.sin6_family = AF_INET6; + _inet_pton(AF_INET6, ip, (char*)&saddr6.sin6_addr); + saddr6.sin6_port = htons(port); + + stream_connsock(stream, (struct sockaddr*)&saddr6, sizeof(saddr6), &tv); + + return S_SUCCESS; +} + + + diff --git a/asynio/ioevdef.h b/asynio/ioevdef.h new file mode 100644 index 0000000000000000000000000000000000000000..3d0c0db7299de1b8aa9be0b17295005818a10cd1 --- /dev/null +++ b/asynio/ioevdef.h @@ -0,0 +1,96 @@ +#ifndef _IOEVDEF_H_ +#define _IOEVDEF_H_ + +#include "event.h" +#include "thread-internal.h" +#include "listener.h" + +#include "crt_util.h" + +typedef struct evconnlistener* evlistenptr; +typedef struct event_base* eventbaseptr; +typedef struct bufferevent* bevptr; + +#define IOEVTCP_OK 0 +#define IOEVTCP_SUCCESS 0x00 +#define IOEVTCP_ERROR 0x01 + +#define IOEV_NOTIFY_TYPE_WORK 1 +#define IOEV_NOTIFY_TYPE_EXIT 0 + +typedef struct ioevloop_s ioevloop_t; +typedef int (*evloop_notify)(ioevloop_t* evloop, int index); +struct ioevloop_s { + void* ctx; + eventbaseptr loop; + evloop_notify notify; +}; + +int ioevloop_setctx(ioevloop_t* loop, void* ctx); +void* ioevloop_getctx(ioevloop_t* loop); + + +#define IOEV_TCP_OPTIONS (LEV_OPT_THREADSAFE | LEV_OPT_DISABLED) + +typedef struct ioevtcp_s ioevtcp_t; +typedef int (*tcp_eventcb)(ioevtcp_t* tcp, short err); +typedef int (*tcp_acceptcb)(ioevtcp_t* tcp, SOCKADDR_PTR sa, socklen_t sl, _sock_t sock); +struct ioevtcp_s { + void* ctx; + evlistenptr listen; + tcp_eventcb event; + tcp_acceptcb accept; +}; + +int ioevtcp_init(ioevtcp_t* tcp, ioevloop_t* evloop, _sock_t sock); +int ioevtcp_uninit(ioevtcp_t* tcp); +int ioevtcp_setctx(ioevtcp_t* tcp, void* ctx); +void* ioevtcp_getctx(ioevtcp_t* tcp); +int ioevtcp_seteventcb(ioevtcp_t* tcp, tcp_eventcb cb); +int ioevtcp_setacceptcb(ioevtcp_t* tcp, tcp_acceptcb cb); +int ioevtcp_bind(ioevtcp_t* tcp, NET_ADDR ip, NET_ADDR_PORT port); +int ioevtcp_bind6(ioevtcp_t* tcp, NET_ADDR ip, NET_ADDR_PORT port); +int ioevtcp_enable(ioevtcp_t* tcp); +int ioevtcp_disable(ioevtcp_t* tcp); + +#define IOEV_STREAM_EOF 0x00 +#define IOEV_STREAM_OPEN 0x01 +#define IOEV_STREAM_ERROR 0x02 +#define IOEV_STREAM_WRITE 0x04 +#define IOEV_STREAM_READ 0x08 +#define IOEV_STREAM_TMOUT 0x10 + +#define IOEVSTREAM_OPEN 0x01 +#define IOEVSSLSTREAM_OPEN 0x02 + +#define IOEV_STREAM_OPTIONS (BEV_OPT_DEFER_CALLBACKS | BEV_OPT_UNLOCK_CALLBACKS | BEV_OPT_THREADSAFE) + +typedef struct ioevstream_s ioevstream_t; +typedef int (*stream_eventcb)(ioevstream_t* stream, short err, short what, _sock_t fd); +typedef int (*stream_readcb)(ioevstream_t* stream, short err, BUF_PTR ptr, BUF_SIZE len); +typedef int (*stream_writecb)(ioevstream_t* stream, short err, BUF_PTR ptr, BUF_SIZE len); +struct ioevstream_s { + void* ctx; + bevptr bev; + _buffer_t in; + _buffer_t out; + stream_eventcb event; + stream_readcb read; + stream_writecb write; +}; + +int ioevstream_init(ioevstream_t* stream, ioevloop_t* evloop, _sock_t sock); +int ioevstream_uninit(ioevstream_t* stream); +int ioevstream_assign(ioevstream_t* stream, _sock_t sock); +int ioevstream_setctx(ioevstream_t* stream, void* ctx); +void* ioevstream_getctx(ioevstream_t* stream); +int ioevstream_seteventcb(ioevstream_t* stream, stream_eventcb cb); +int ioevstream_setreadcb(ioevstream_t* stream, stream_readcb cb); +int ioevstream_setwritecb(ioevstream_t* stream, stream_writecb cb); +int ioevstream_write(ioevstream_t* stream, BUF_PTR ptr, BUF_SIZE len, int sec); +int ioevstream_read(ioevstream_t* stream, BUF_PTR ptr, BUF_SIZE len, int sec); +int ioevstream_connectsock(ioevstream_t* stream, NET_ADDR ip, NET_ADDR_PORT port, int sec); +int ioevstream_connect6sock(ioevstream_t* stream, NET_ADDR ip, NET_ADDR_PORT port, int sec); + + +#endif diff --git a/asynio/iooperationimpl.cpp b/asynio/iooperationimpl.cpp index b970cb3643e6728d6fe41e6d1dc363756ace1fd0..8d16b373246aacb624daf6f54c7dc814c583d4b9 100644 --- a/asynio/iooperationimpl.cpp +++ b/asynio/iooperationimpl.cpp @@ -32,7 +32,7 @@ HRESULT CIoOperationImpl::QueryIBaseIID(REFIID riid, void** ppv) HRESULT CIoOperationImpl::BindEvent(IBase* pEvents) { HRESULT hr = S_OK; - hr = pEvents->QueryInterface(IID_IOperationEvent, (void**)&m_pEvent); + hr = pEvents->QueryInterface(IID_IOperationProc, (void**)&m_pEvent); rc_assert(hr == S_OK, E_FAIL); return hr; } @@ -41,12 +41,12 @@ HRESULT CIoOperationImpl::UnBindEvent() m_pEvent.dispose(); return S_OK; } -HRESULT CIoOperationImpl::SetId(ULONG uId) +HRESULT CIoOperationImpl::SetId(evid id) { - m_id = uId; + m_id = id; return S_OK; } -ULONG CIoOperationImpl::GetId() +evid CIoOperationImpl::GetId() { return m_id; } diff --git a/asynio/iooperationimpl.h b/asynio/iooperationimpl.h index 22f63eaedfc96a163ca822874c0c1815d8816e02..0a5a367d59ea5bfe43b21bde8f8c89c1b6b38152 100644 --- a/asynio/iooperationimpl.h +++ b/asynio/iooperationimpl.h @@ -22,8 +22,8 @@ public: std_method(QueryIBaseIID)(REFIID riid, void** ppv); std_method(BindEvent)(IBase* pEvents); std_method(UnBindEvent)(); - std_method(SetId)(ULONG uId); - std_method_(ULONG, GetId)(); + std_method(SetId)(evid id); + std_method_(evid, GetId)(); std_method(SetResult)(everr Error, BUF_SIZE uTransferedBytes); std_method(GetResult)(everr* Error, BUF_SIZE* pTransferedBytes); std_method(SetIoParam)(BUF_SIZE uStartPos, BUF_SIZE uExpectBytes); @@ -46,12 +46,12 @@ public: private: everr m_Errorcode; BUF_SIZE m_pTransferedBytes; - BUF_SIZE m_id; + evid m_id; BUF_SIZE m_uStartPos; BUF_SIZE m_uExpectBytes; BUF_SIZE m_pBufLen; UCharArrayPtr m_pBuf; - OperationEventPtr m_pEvent; + _lComPtr m_pEvent; _lComPtr m_pBase; }; #endif diff --git a/asynio/stdafx.h b/asynio/stdafx.h index d39953e7a2e3d0629098a8063f205760ed4e0bcd..dd7f849b9afaf7f83c460dfb651b15632ee43ef4 100644 --- a/asynio/stdafx.h +++ b/asynio/stdafx.h @@ -5,10 +5,13 @@ #ifndef _STDAFX_H_ #define _STDAFX_H_ -#include #include -typedef map SockOptionTable; -typedef SockOptionTable::iterator SockOption; +#include +#include +#include +#include +#include +#include #endif diff --git a/asynio/tcplistensocketimpl.cpp b/asynio/tcplistensocketimpl.cpp index 575ed46945d6c2beb170b25cc73492137459da83..5ec174b97fb111dec1f4800f41b4b023e8593c49 100644 --- a/asynio/tcplistensocketimpl.cpp +++ b/asynio/tcplistensocketimpl.cpp @@ -1,39 +1,82 @@ #include "tcplistensocketimpl.h" #include "tcpsocketimpl.h" +static int tcplisten_eventcb(ioevtcp_t* tcp, short err) +{ + rc_assert(tcp != NULL, S_ERROR); + CTcpListenSocketImpl* listen = (CTcpListenSocketImpl*)ioevtcp_getctx(tcp); + listen->Acceptcb(INVALID_SOCKET, NULL, 0, S_ERROR); + return S_SUCCESS; +} +static int tcplisten_acceptcb(ioevtcp_t* tcp, SOCKADDR_PTR sa, socklen_t sl, _sock_t sock) +{ + rc_assert(tcp != NULL, S_ERROR); + CTcpListenSocketImpl* listen = (CTcpListenSocketImpl*)ioevtcp_getctx(tcp); + listen->Acceptcb(sock, sa, sl, S_SUCCESS); + return S_SUCCESS; +} CTcpListenSocketImpl::CTcpListenSocketImpl() { + m_tcp = (ioevtcp_t*)heap_malloc(sizeof(ioevtcp_t)); } CTcpListenSocketImpl::~CTcpListenSocketImpl() { logi("CTcpListenSocketImpl::~CTcpListenSocketImpl"); } +HRESULT CTcpListenSocketImpl::BindEvloop(ioevloop_t* loop) +{ + m_evloop = loop; + return S_OK; +} HRESULT CTcpListenSocketImpl::CloseIo(UINT rw) { m_accept.dispose(); return S_OK; } +HRESULT CTcpListenSocketImpl::BindIo() +{ + rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + return S_OK; +} HRESULT CTcpListenSocketImpl::OpenIo() { return S_OK; } -HRESULT CTcpListenSocketImpl::BindIo() +HRESULT CTcpListenSocketImpl::BindEvent(IBase* pSocketEvent) +{ + return S_OK; +} +HRESULT CTcpListenSocketImpl::UnBindEvent() { - rc_assert(m_sock != INVALID_SOCKET, E_FAIL); return S_OK; } HRESULT CTcpListenSocketImpl::CreateSock() { HRESULT hr = S_OK; m_sock = INVALID_SOCKET; - m_sock = _createsock(PF_INET, SOCK_STREAM, IPPROTO_TCP); - rc_assert(m_sock != INVALID_SOCKET, E_FAIL) return hr; + m_sock = _createsock(AF_INET, SOCK_STREAM, IPPROTO_TCP); + rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + + set_blocking(m_sock, 1); + set_keepalive(m_sock, 1); + set_reuseableport(m_sock, 1); + set_reuseable(m_sock, 1); + set_deferaccpet(m_sock, 1); + + ioevtcp_init(m_tcp, m_evloop, m_sock); + ioevtcp_setctx(m_tcp, this); + ioevtcp_seteventcb(m_tcp, tcplisten_eventcb); + ioevtcp_setacceptcb(m_tcp, tcplisten_acceptcb); + + return hr; } HRESULT CTcpListenSocketImpl::CloseSock() { HRESULT hr = S_OK; - rc_assert(m_sock != INVALID_SOCKET, E_FAIL) _closesock(m_sock); + rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + ioevtcp_uninit(m_tcp); + _closesock(m_sock); m_sock = INVALID_SOCKET; return hr; @@ -51,47 +94,14 @@ HRESULT CTcpListenSocketImpl::AttachSock(_sock_t sock) } _sock_t CTcpListenSocketImpl::DetachSock() { - return m_sock; -} -HRESULT CTcpListenSocketImpl::SetOption(LPCSTR opt, int val) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::GetOption(LPCSTR opt, int* val) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::ReadOperationSize(int size) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::WriteOperationSize(int size) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::ReadStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::WriteStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::GetReadPtr(BUF_PTR* ptr) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::GetWritePtr(BUF_PTR* ptr) -{ - return E_NOTIMPL; -} -HRESULT CTcpListenSocketImpl::GetReadPtrSize(BUF_SIZE* size) -{ - return E_NOTIMPL; + _sock_t sock; + sock = m_sock; + m_sock = INVALID_SOCKET; + return sock; } -HRESULT CTcpListenSocketImpl::GetWritePtrSize(BUF_SIZE* size) +_sock_t CTcpListenSocketImpl::GetSock() { - return E_NOTIMPL; + return m_sock; } HRESULT CTcpListenSocketImpl::GetReadOperation(IID id, IBase** pBase) { @@ -105,15 +115,23 @@ HRESULT CTcpListenSocketImpl::Listen(NET_ADDR addr, NET_PORT port) { rc_assert(addr != NULL, E_FAIL); rc_assert(port != INVALID_NET_PORT, E_FAIL); + ioevtcp_bind(m_tcp, addr, port); return S_OK; } -HRESULT CTcpListenSocketImpl::Accept(IBase* pBase) +HRESULT CTcpListenSocketImpl::Listen6(NET_ADDR addr, NET_PORT port) { - HRESULT hr = S_OK; - - TcpSocketPtr pAsynTcpScoket; - hr = pBase->QueryInterface(IID_ITcpSocket, (void**)&pAsynTcpScoket); - rc_assert(hr == S_OK, E_FAIL); + rc_assert(addr != NULL, E_FAIL); + rc_assert(port != INVALID_NET_PORT, E_FAIL); + ioevtcp_bind6(m_tcp, addr, port); + return S_OK; +} +HRESULT CTcpListenSocketImpl::Accept(int on) +{ + if (on == LISTEN_OPEN) { + ioevtcp_enable(m_tcp); + } else if (on == LISTEN_CLOSE) { + ioevtcp_disable(m_tcp); + } return S_OK; } @@ -127,9 +145,9 @@ HRESULT CTcpListenSocketImpl::UnBindAccpet() m_accept.dispose(); return S_OK; } -void CTcpListenSocketImpl::AcceptCB(IBase* pBase, evid error_code, _sock_t s) +HRESULT CTcpListenSocketImpl::Acceptcb(_sock_t s, SOCKADDR_PTR sa, socklen_t sl, evid error_code) { - c_assert(pBase != NULL); - c_assert(m_accept.m_p != NULL); - m_accept->Accept(pBase, s, error_code); + rc_assert(m_accept.m_p != NULL, E_FAIL); + m_accept->Accept(s, sa, sl, error_code); + return S_OK; } diff --git a/asynio/tcplistensocketimpl.h b/asynio/tcplistensocketimpl.h index 91e0f85cb83a47f1da77585d49817079dd3065c2..61df4ee62a8389646caf778a0982e382cd7344c6 100644 --- a/asynio/tcplistensocketimpl.h +++ b/asynio/tcplistensocketimpl.h @@ -2,6 +2,8 @@ #define _ASYNCTCPLISTENSOCKIMPL_H_ #include "stdafx.h" +#include "ioevdef.h" + class CTcpListenSocketImpl : public ITcpListen, public CUnknownImp { @@ -13,45 +15,45 @@ public: STDCOM_INTERFACE_ENTRY(ITcpListen) STDCOM_INTERFACE_ENTRY_UNKNOWN_(ITcpListen) END_STDCOM_MAP + +public: + HRESULT BindEvloop(ioevloop_t* loop); +public: // IIoDevice std_method(CloseIo)(UINT rw); std_method(BindIo)(); std_method(OpenIo)(); // ISocket + std_method(BindEvent)(IBase* pSocketEvent); + std_method(UnBindEvent)(); std_method(CreateSock)(); std_method(CloseSock)(); std_method(IsOpen)(); std_method(AttachSock)(_sock_t sock); std_method_(_sock_t, DetachSock)(); - std_method(SetOption)(LPCSTR opt, int val); - std_method(GetOption)(LPCSTR opt, int* val); - std_method(ReadOperationSize)(int size); - std_method(WriteOperationSize)(int size); - std_method(ReadStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(WriteStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(GetReadPtr)(BUF_PTR* ptr); - std_method(GetWritePtr)(BUF_PTR* ptr); - std_method(GetReadPtrSize)(BUF_SIZE* size); - std_method(GetWritePtrSize)(BUF_SIZE* size); + std_method_(_sock_t, GetSock)(); std_method(GetReadOperation)(IID id, IBase** pBase); std_method(GetWriteOperation)(IID id, IBase** pBase); // IListen std_method(Listen)(NET_ADDR addr, NET_PORT port); - std_method(Accept)(IBase* pBase); + std_method(Listen6)(NET_ADDR addr, NET_PORT port); + std_method(Accept)(int on); // ITcpListen std_method(BindAccept)(IBase* pAccept); std_method(UnBindAccpet)(); public: - void AcceptCB(IBase* pBase, evid error_code, _sock_t s); + std_method(Acceptcb)(_sock_t s, SOCKADDR_PTR sa, socklen_t sl, evid error_code); private: _sock_t m_sock; - AcceptListenPtr m_accept; + _lComPtr m_accept; + SafePtr m_tcp; + ioevloop_t* m_evloop; }; #endif diff --git a/asynio/tcpsocketimpl.cpp b/asynio/tcpsocketimpl.cpp index 4e1a7eb19d3db2e7485c39257a0ead179895ba96..5e4da385816e15e3d7dc7ed10270d78efdc67dbf 100644 --- a/asynio/tcpsocketimpl.cpp +++ b/asynio/tcpsocketimpl.cpp @@ -1,30 +1,63 @@ #include "tcpsocketimpl.h" +int tcpsocket_eventcb(ioevstream_t* stream, short err, short what, _sock_t fd) +{ + rc_assert(stream != NULL, S_ERROR); + CTcpSocketImpl* tcpsock = (CTcpSocketImpl*)ioevstream_getctx(stream); + + return S_SUCCESS; +} +int tcpsocket_opencb(ioevstream_t* stream, short err, _sock_t fd) +{ + rc_assert(stream != NULL, S_ERROR); + CTcpSocketImpl* tcpsock = (CTcpSocketImpl*)ioevstream_getctx(stream); + + return S_SUCCESS; +} +int tcpsocket_readcb(ioevstream_t* stream, short err, BUF_PTR ptr, BUF_SIZE len) +{ + rc_assert(stream != NULL, S_ERROR); + CTcpSocketImpl* tcpsock = (CTcpSocketImpl*)ioevstream_getctx(stream); + + return S_SUCCESS; +} +int tcpsocket_writecb(ioevstream_t* stream, short err, BUF_PTR ptr, BUF_SIZE len) +{ + rc_assert(stream != NULL, S_ERROR); + CTcpSocketImpl* tcpsock = (CTcpSocketImpl*)ioevstream_getctx(stream); + + return S_SUCCESS; +} CTcpSocketImpl::CTcpSocketImpl() { m_sock = INVALID_SOCKET; + m_stream = (ioevstream_t*)heap_malloc(sizeof(ioevstream_t)); } CTcpSocketImpl::~CTcpSocketImpl() { logi("CTcpSocketImpl::~CTcpSocketImpl"); } -HRESULT CTcpSocketImpl::init_class(IBase* pAsynFrame) +HRESULT CTcpSocketImpl::CreateIoOperation(IAsynFrame* pIAsynFrame) { HRESULT hr = S_OK; - _lComPtr pIAsynFrame; - hr = pAsynFrame->QueryInterface(IID_IAsynFrame, (void**)&pIAsynFrame); + hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pReadOper); rc_assert(hr == S_OK, E_FAIL); - hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pReadOperation); + hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pWriteOper); rc_assert(hr == S_OK, E_FAIL); - hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pWriteOperation); + hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pConnectOper); rc_assert(hr == S_OK, E_FAIL); return S_OK; } +HRESULT CTcpSocketImpl::BindEvloop(ioevloop_t* loop) +{ + ioevstream_init(m_stream, loop, INVALID_SOCKET); + return S_OK; +} HRESULT CTcpSocketImpl::CloseIo(UINT rw) { return S_OK; @@ -38,12 +71,28 @@ HRESULT CTcpSocketImpl::OpenIo() { return S_OK; } +HRESULT CTcpSocketImpl::BindEvent(IBase* pSocketEvent) +{ + return S_OK; +} +HRESULT CTcpSocketImpl::UnBindEvent() +{ + return S_OK; +} HRESULT CTcpSocketImpl::CreateSock() { HRESULT hr = S_OK; m_sock = INVALID_SOCKET; m_sock = _createsock(PF_INET, SOCK_STREAM, IPPROTO_TCP); rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + + set_blocking(m_sock, 1); + ioevstream_assign(m_stream, m_sock); + ioevstream_setctx(m_stream, this); + ioevstream_seteventcb(m_stream, tcpsocket_eventcb); + ioevstream_setreadcb(m_stream, tcpsocket_readcb); + ioevstream_setwritecb(m_stream, tcpsocket_writecb); + return hr; } HRESULT CTcpSocketImpl::CloseSock() @@ -52,8 +101,9 @@ HRESULT CTcpSocketImpl::CloseSock() rc_assert(IsOpen() == S_OK, S_OK); rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + ioevstream_uninit(m_stream); // TODO: this is error - int rc = _closesock(m_sock); + _closesock(m_sock); m_sock = INVALID_SOCKET; return hr; @@ -66,149 +116,45 @@ HRESULT CTcpSocketImpl::AttachSock(_sock_t sock) { rc_assert(sock != INVALID_SOCKET, E_FAIL); m_sock = sock; + + set_blocking(m_sock, 1); + ioevstream_assign(m_stream, m_sock); + ioevstream_setctx(m_stream, this); + ioevstream_seteventcb(m_stream, tcpsocket_eventcb); + ioevstream_setreadcb(m_stream, tcpsocket_readcb); + ioevstream_setwritecb(m_stream, tcpsocket_writecb); + return S_OK; } - _sock_t CTcpSocketImpl::DetachSock() { - return m_sock; -} -HRESULT CTcpSocketImpl::SetOption(LPCSTR opt, int val) -{ - HRESULT hr = S_OK; - - if (s_strcmp(opt, SOL_REUSEDDR) == 0) { - SetReuseAddr(&m_sock, val); - } else if (s_strcmp(opt, SOL_NODELAY) == 0) { - SetNoDelay(&m_sock, val); - } else if (s_strcmp(opt, SOL_LINGER) == 0) { - SetLinger(&m_sock, val); - } else if (s_strcmp(opt, SOL_KEEPLIVE) == 0) { - SetKeepalive(&m_sock, val); - } else if (s_strcmp(opt, SOL_CORK) == 0) { - SetCork(&m_sock, val); - } else if (s_strcmp(opt, SOL_NOSIGPIPE) == 0) { - SetNoSigPipe(&m_sock, val); - } else if (s_strcmp(opt, SOL_RECVLEN) == 0) { - SetRecvBufLen(&m_sock, val); - } else if (s_strcmp(opt, SOL_SENDLEN) == 0) { - SetSendBufLen(&m_sock, val); - } else if (s_strcmp(opt, SOL_SENDTM) == 0) { - SetSendTimeOut(&m_sock, val); - } else if (s_strcmp(opt, SOL_RECVTM) == 0) { - SetRecvTimeOut(&m_sock, val); - } else if (s_strcmp(opt, SOL_CONTM) == 0) { - SetConTimeOut(&m_sock, val); - } else if (s_strcmp(opt, SOL_SENDLOWAT) == 0) { - SetSendLoWat(&m_sock, val); - } else if (s_strcmp(opt, SOL_RECVLOWAT) == 0) { - SetRecvLoWat(&m_sock, val); - } else if (s_strcmp(opt, SOL_ONLY_READ) == 0) { - _shutdown_sock(m_sock, SHUT_SOCK_RD); - } else if (s_strcmp(opt, SOL_ONLY_WRITE) == 0) { - _shutdown_sock(m_sock, SHUT_SOCK_RW); - } else { - return E_FAIL; - } - - m_sockoption[opt] = val; - - return hr; -} -HRESULT CTcpSocketImpl::GetOption(LPCSTR opt, int* val) -{ - HRESULT hr = S_OK; - SockOption option = m_sockoption.find(opt); - rc_assert(option != m_sockoption.end(), E_FAIL); - *val = option->second; - return hr; -} -HRESULT CTcpSocketImpl::ReadOperationSize(int size) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL) - - HRESULT hr = S_OK; - - hr = this->SetOption(SOL_RECVLEN, size); - rc_assert(hr == S_OK, E_FAIL); - - return m_pReadOperation->Alloc(size * 1024); -} -HRESULT CTcpSocketImpl::WriteOperationSize(int size) -{ - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - - HRESULT hr = S_OK; - - hr = this->SetOption(SOL_SENDLEN, size); - rc_assert(hr == S_OK, E_FAIL); - - return m_pWriteOperation->Alloc(size * 1024); -} -HRESULT CTcpSocketImpl::ReadStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->Attach(ptr, pos, size); -} -HRESULT CTcpSocketImpl::WriteStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->Attach(ptr, pos, size); -} -HRESULT CTcpSocketImpl::GetReadPtr(BUF_PTR* ptr) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->GetPtr(ptr); -} -HRESULT CTcpSocketImpl::GetWritePtr(BUF_PTR* ptr) -{ - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->GetPtr(ptr); -} -HRESULT CTcpSocketImpl::GetReadPtrSize(BUF_SIZE* size) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->GetLen(size); + _sock_t sock; + sock = m_sock; + m_sock = INVALID_SOCKET; + return sock; } -HRESULT CTcpSocketImpl::GetWritePtrSize(BUF_SIZE* size) +_sock_t CTcpSocketImpl::GetSock() { - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->GetLen(size); + return m_sock; } HRESULT CTcpSocketImpl::GetReadOperation(IID id, IBase** pBase) { - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->QueryInterface(id, (void**)pBase); + rc_assert(m_pReadOper.m_p != NULL, E_FAIL); + return this->m_pReadOper->QueryInterface(id, (void**)pBase); } HRESULT CTcpSocketImpl::GetWriteOperation(IID id, IBase** pBase) { - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->QueryInterface(id, (void**)pBase); -} -BUF_SIZE CTcpSocketImpl::SyncSend(BUF_PTR buf, BUF_SIZE size) -{ - return 0; -} -BUF_SIZE CTcpSocketImpl::SyncRecv(BUF_PTR buf, BUF_SIZE size) -{ - return 0; -} -HRESULT CTcpSocketImpl::SyncConnect(NET_ADDR addr, NET_PORT port) -{ - rc_assert(addr != NULL, E_FAIL); - rc_assert(port != INVALID_NET_PORT, E_FAIL); - return S_OK; + rc_assert(m_pWriteOper.m_p != NULL, E_FAIL); + return this->m_pWriteOper->QueryInterface(id, (void**)pBase); } -HRESULT CTcpSocketImpl::ReadIo(ULONG pos, ULONG size, evid event) +HRESULT CTcpSocketImpl::ReadIo(ULONG pos, ULONG size, evid event, int tm) { - HRESULT hr = S_OK; int rc = S_SUCCESS; return (S_SUCCESS == rc) ? S_OK : E_FAIL; } -HRESULT CTcpSocketImpl::WriteIo(ULONG pos, ULONG size, evid event) +HRESULT CTcpSocketImpl::WriteIo(ULONG pos, ULONG size, evid event, int tm) { - HRESULT hr = S_OK; int rc = S_SUCCESS; // hr = pBase->QueryInterface(IID_IOperation, (void**)&m_pOperation); @@ -228,20 +174,16 @@ HRESULT CTcpSocketImpl::WriteIo(ULONG pos, ULONG size, evid event) return (S_SUCCESS == rc) ? S_OK : E_FAIL; } -HRESULT CTcpSocketImpl::ConnectIo(NET_ADDR addr, NET_PORT port, evid event) +HRESULT CTcpSocketImpl::ConnectIo(NET_ADDR addr, NET_PORT port, evid event, int tm) { + rc_assert(m_sock != INVALID_SOCKET, E_FAIL); rc_assert(addr != NULL, E_FAIL); rc_assert(port != INVALID_NET_PORT, E_FAIL); + rc_assert(m_stream.m_p != INVALID_NET_PORT, E_FAIL); - HRESULT hr = S_OK; int rc = S_SUCCESS; - // hr = pBase->QueryInterface(IID_IOperation, (void**)&m_pOperation); - // rc_assert(hr == S_OK, E_FAIL) - - // this->ctx.data = pBase; - // this->ctx.event = event; - // rc = tcp_async_connect(m_pOperation, addr, port, contimeout, this); + rc = ioevstream_connectsock(m_stream, addr, port, tm); return (rc == S_SUCCESS) ? S_OK : E_FAIL; } diff --git a/asynio/tcpsocketimpl.h b/asynio/tcpsocketimpl.h index b89c274d4093662a7067bc06e18b0d2258a4985d..0a92e56c6635d7071550cc80737832d435a0f0ca 100644 --- a/asynio/tcpsocketimpl.h +++ b/asynio/tcpsocketimpl.h @@ -2,6 +2,8 @@ #define _ASYNCTCPSOCKIMPL_H_ #include "stdafx.h" +#include "ioevdef.h" + class CTcpSocketImpl : public ITcpSocket, public CUnknownImp { @@ -12,12 +14,13 @@ public: BEGIN_STDCOM_MAP STDCOM_INTERFACE_ENTRY(ITcpSocket) STDCOM_INTERFACE_ENTRY_UNKNOWN_(ITcpSocket) - STDCOM_INTERFACE_MEMBER_ENTRY_(m_pReadOperation, IOperation, IID_IReadOperation) - STDCOM_INTERFACE_MEMBER_ENTRY_(m_pWriteOperation, IOperation, IID_IWriteOperation) + STDCOM_INTERFACE_MEMBER_ENTRY_(m_pReadOper, IOperation, IID_IReadOperation) + STDCOM_INTERFACE_MEMBER_ENTRY_(m_pWriteOper, IOperation, IID_IWriteOperation) END_STDCOM_MAP public: - HRESULT init_class(IBase* pAsynFrame); + HRESULT CreateIoOperation(IAsynFrame* pIAsynFrame); + HRESULT BindEvloop(ioevloop_t* loop); public: // IIoDevice @@ -26,37 +29,28 @@ public: std_method(OpenIo)(); // ISocket + std_method(BindEvent)(IBase* pSocketEvent); + std_method(UnBindEvent)(); std_method(CreateSock)(); std_method(CloseSock)(); std_method(IsOpen)(); std_method(AttachSock)(_sock_t sock); std_method_(_sock_t, DetachSock)(); - std_method(SetOption)(LPCSTR opt, int val); - std_method(GetOption)(LPCSTR opt, int* val); - std_method(ReadOperationSize)(int size); - std_method(WriteOperationSize)(int size); - std_method(ReadStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(WriteStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(GetReadPtr)(BUF_PTR* ptr); - std_method(GetWritePtr)(BUF_PTR* ptr); - std_method(GetReadPtrSize)(BUF_SIZE* size); - std_method(GetWritePtrSize)(BUF_SIZE* size); + std_method_(_sock_t, GetSock)(); std_method(GetReadOperation)(IID id, IBase** pBase); std_method(GetWriteOperation)(IID id, IBase** pBase); // ITcpSocket - std_method_(BUF_SIZE, SyncSend)(BUF_PTR buf, BUF_SIZE size); - std_method_(BUF_SIZE, SyncRecv)(BUF_PTR buf, BUF_SIZE size); - std_method(SyncConnect)(NET_ADDR addr, NET_PORT port); - std_method(ReadIo)(ULONG pos, ULONG size, evid event); - std_method(WriteIo)(ULONG pos, ULONG size, evid event); - std_method(ConnectIo)(NET_ADDR addr, NET_PORT port, evid event); + std_method(ReadIo)(ULONG pos, ULONG size, evid event, int tm); + std_method(WriteIo)(ULONG pos, ULONG size, evid event, int tm); + std_method(ConnectIo)(NET_ADDR addr, NET_PORT port, evid event, int tm); private: _sock_t m_sock; - SockOptionTable m_sockoption; - OperationPtr m_pReadOperation; - OperationPtr m_pWriteOperation; + _lComPtr m_pReadOper; + _lComPtr m_pWriteOper; + _lComPtr m_pConnectOper; + SafePtr m_stream; }; #endif diff --git a/asynio/tcpsocketsslimpl.cpp b/asynio/tcpsocketsslimpl.cpp index fe9252e2b234668fef0e60e325d9aa43f5989151..29fe70e88498f263d877a73fbb17c4dafb49e0ec 100644 --- a/asynio/tcpsocketsslimpl.cpp +++ b/asynio/tcpsocketsslimpl.cpp @@ -1,29 +1,60 @@ #include "tcpsocketsslimpl.h" + +#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n" + +int tcpsocketssl_eventcb(ioevstream_t* stream, short err, short what, _sock_t fd) +{ + rc_assert(stream != NULL, S_ERROR); + CTcpSocketSSLImpl* tcpsockssl = (CTcpSocketSSLImpl*)ioevstream_getctx(stream); + rc_assert(tcpsockssl != NULL, S_ERROR); + tcpsockssl->OnEventcb(err, what, fd); + return S_SUCCESS; +} +int tcpsocketssl_readcb(ioevstream_t* stream, short err, BUF_PTR ptr, BUF_SIZE len) +{ + rc_assert(stream != NULL, S_ERROR); + CTcpSocketSSLImpl* tcpsockssl = (CTcpSocketSSLImpl*)ioevstream_getctx(stream); + tcpsockssl->OnReadcb(err, ptr, len); + return S_SUCCESS; +} +int tcpsocketssl_writecb(ioevstream_t* stream, short err, BUF_PTR ptr, BUF_SIZE len) +{ + rc_assert(stream != NULL, S_ERROR); + CTcpSocketSSLImpl* tcpsockssl = (CTcpSocketSSLImpl*)ioevstream_getctx(stream); + tcpsockssl->OnWritecb(err, ptr, len); + return S_SUCCESS; +} CTcpSocketSSLImpl::CTcpSocketSSLImpl() { - m_sock = INVALID_SOCKET; + m_sock = INVALID_SOCKET; + m_rstate = SSL_READ_HEAD; + m_stream = (ioevstream_t*)heap_malloc(sizeof(ioevstream_t)); } CTcpSocketSSLImpl::~CTcpSocketSSLImpl() { logi("CTcpSocketSSLImpl::~CTcpSocketSSLImpl"); } -HRESULT CTcpSocketSSLImpl::init_class(IBase* pAsynFrame) +HRESULT CTcpSocketSSLImpl::CreateIoOperation(IAsynFrame* pIAsynFrame) { HRESULT hr = S_OK; - _lComPtr pIAsynFrame; - hr = pAsynFrame->QueryInterface(IID_IAsynFrame, (void**)&pIAsynFrame); - rc_assert(hr == S_OK, E_FAIL); + hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pReadOper); + rc_assert(hr == S_OK, E_FAIL); - hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pReadOperation); - rc_assert(hr == S_OK, E_FAIL); + hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pWriteOper); + rc_assert(hr == S_OK, E_FAIL); - hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pWriteOperation); - rc_assert(hr == S_OK, E_FAIL); + hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pConnectOper); + rc_assert(hr == S_OK, E_FAIL); return S_OK; } - +HRESULT CTcpSocketSSLImpl::BindEvloop(ioevloop_t* loop) +{ + m_evloop = loop; + ioevstream_init(m_stream, loop, INVALID_SOCKET); + return S_OK; +} HRESULT CTcpSocketSSLImpl::CloseIo(UINT rw) { return S_OK; @@ -37,12 +68,37 @@ HRESULT CTcpSocketSSLImpl::OpenIo() { return S_OK; } +HRESULT CTcpSocketSSLImpl::BindEvent(IBase* pSocketEvent) +{ + HRESULT hr = S_OK; + + hr = pSocketEvent->QueryInterface(IID_ISockProc, (void**)&m_pISockProc); + rc_assert(hr == S_OK, E_FAIL); + + return S_OK; +} +HRESULT CTcpSocketSSLImpl::UnBindEvent() +{ + m_pISockProc.dispose(); + return S_OK; +} HRESULT CTcpSocketSSLImpl::CreateSock() { - HRESULT hr = S_OK; - m_sock = INVALID_SOCKET; - m_sock = _createsock(PF_INET, SOCK_STREAM, IPPROTO_TCP); - rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + HRESULT hr = S_OK; + m_sock = INVALID_SOCKET; + m_sock = _createsock(PF_INET, SOCK_STREAM, IPPROTO_TCP); + rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + + set_blocking(m_sock, 1); + ioevstream_assign(m_stream, m_sock); + ioevstream_setctx(m_stream, this); + ioevstream_seteventcb(m_stream, tcpsocketssl_eventcb); + ioevstream_setreadcb(m_stream, tcpsocketssl_readcb); + ioevstream_setwritecb(m_stream, tcpsocketssl_writecb); + + char *pers = "hello world"; + tls_init_bio(&m_session, pers, s_strlen(pers)); + return hr; } HRESULT CTcpSocketSSLImpl::CloseSock() @@ -52,7 +108,8 @@ HRESULT CTcpSocketSSLImpl::CloseSock() rc_assert(IsOpen() == S_OK, S_OK); rc_assert(m_sock != INVALID_SOCKET, E_FAIL); // TODO: this is error - int rc = _closesock(m_sock); + _closesock(m_sock); + m_sock = INVALID_SOCKET; return hr; @@ -65,105 +122,57 @@ HRESULT CTcpSocketSSLImpl::AttachSock(_sock_t sock) { rc_assert(sock != INVALID_SOCKET, E_FAIL); m_sock = sock; + + set_blocking(m_sock, 1); + ioevstream_assign(m_stream, m_sock); + ioevstream_setctx(m_stream, this); + ioevstream_seteventcb(m_stream, tcpsocketssl_eventcb); + ioevstream_setreadcb(m_stream, tcpsocketssl_readcb); + ioevstream_setwritecb(m_stream, tcpsocketssl_writecb); + return S_OK; } - _sock_t CTcpSocketSSLImpl::DetachSock() { - return m_sock; -} -HRESULT CTcpSocketSSLImpl::SetOption(LPCSTR opt, int val) -{ - HRESULT hr = S_OK; - - return hr; -} -HRESULT CTcpSocketSSLImpl::GetOption(LPCSTR opt, int* val) -{ - HRESULT hr = S_OK; - SockOption option = m_sockoption.find(opt); - rc_assert(option != m_sockoption.end(), E_FAIL); - *val = option->second; - return hr; -} -HRESULT CTcpSocketSSLImpl::ReadOperationSize(int size) -{ - HRESULT hr = S_OK; - return hr; -} -HRESULT CTcpSocketSSLImpl::WriteOperationSize(int size) -{ - HRESULT hr = S_OK; - return hr; -} -HRESULT CTcpSocketSSLImpl::ReadStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->Attach(ptr, pos, size); -} -HRESULT CTcpSocketSSLImpl::WriteStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->Attach(ptr, pos, size); -} -HRESULT CTcpSocketSSLImpl::GetReadPtr(BUF_PTR* ptr) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->GetPtr(ptr); -} -HRESULT CTcpSocketSSLImpl::GetWritePtr(BUF_PTR* ptr) -{ - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->GetPtr(ptr); -} -HRESULT CTcpSocketSSLImpl::GetReadPtrSize(BUF_SIZE* size) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->GetLen(size); + _sock_t sock; + sock = m_sock; + m_sock = INVALID_SOCKET; + return sock; } -HRESULT CTcpSocketSSLImpl::GetWritePtrSize(BUF_SIZE* size) +_sock_t CTcpSocketSSLImpl::GetSock() { - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->GetLen(size); + return m_sock; } HRESULT CTcpSocketSSLImpl::GetReadOperation(IID id, IBase** pBase) { - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->QueryInterface(id, (void**)pBase); + rc_assert(m_pReadOper.m_p != NULL, E_FAIL); + return this->m_pReadOper->QueryInterface(id, (void**)pBase); } HRESULT CTcpSocketSSLImpl::GetWriteOperation(IID id, IBase** pBase) { - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->QueryInterface(id, (void**)pBase); + rc_assert(m_pWriteOper.m_p != NULL, E_FAIL); + return this->m_pWriteOper->QueryInterface(id, (void**)pBase); } -BUF_SIZE CTcpSocketSSLImpl::SyncSend(BUF_PTR buf, BUF_SIZE size) +HRESULT CTcpSocketSSLImpl::ReadIo(ULONG pos, ULONG size, evid event, int tm) { - return 0; -} -BUF_SIZE CTcpSocketSSLImpl::SyncRecv(BUF_PTR buf, BUF_SIZE size) -{ - return 0; -} -HRESULT CTcpSocketSSLImpl::SyncConnect(NET_ADDR addr, NET_PORT port) -{ - rc_assert(addr != NULL, E_FAIL); - rc_assert(port != INVALID_NET_PORT, E_FAIL); return S_OK; } -HRESULT CTcpSocketSSLImpl::ReadIo(ULONG pos, ULONG size, evid event) +HRESULT CTcpSocketSSLImpl::WriteIo(ULONG pos, ULONG size, evid event, int tm) { return S_OK; } -HRESULT CTcpSocketSSLImpl::WriteIo(ULONG pos, ULONG size, evid event) +HRESULT CTcpSocketSSLImpl::ConnectIo(NET_ADDR addr, NET_PORT port, evid event, int tm) { - return S_OK; -} -HRESULT CTcpSocketSSLImpl::ConnectIo(NET_ADDR addr, NET_PORT port, evid event) -{ - rc_assert(addr != NULL, E_FAIL); - rc_assert(port != INVALID_NET_PORT, E_FAIL); + rc_assert(m_sock != INVALID_SOCKET, E_FAIL); + rc_assert(addr != NULL, E_FAIL); + rc_assert(port != INVALID_NET_PORT, E_FAIL); + rc_assert(m_stream.m_p != INVALID_NET_PORT, E_FAIL); - return S_OK; + int rc = S_SUCCESS; + + rc = ioevstream_connectsock(m_stream, addr, port, tm); + + return (rc == S_SUCCESS) ? S_OK : E_FAIL; } HRESULT CTcpSocketSSLImpl::LoadCertificate(UCHAR* buf, size_t size) { @@ -175,3 +184,87 @@ HRESULT CTcpSocketSSLImpl::SetSSLCtxAddress(LPCSTR hostname) return S_OK; } +HRESULT CTcpSocketSSLImpl::OnEventcb(short err, short what, _sock_t fd) +{ + rc_assert(m_pISockProc.m_p != NULL, E_FAIL); + + if (what == IOEVSTREAM_OPEN) { + + m_session.mbedNetCtx.fd = m_sock; + + int rc = 0; + while ((rc = mbedtls_ssl_handshake(&m_session.mbedSslCtx)) != 0) + { + if (rc != MBEDTLS_ERR_SSL_WANT_READ && rc != MBEDTLS_ERR_SSL_WANT_WRITE) + break; + } + + set_blocking(m_sock, 1); + + int len; + uint32_t flags; + + if ((flags = mbedtls_ssl_get_verify_result(&m_session.mbedSslCtx)) != 0) + { + char vrfy_buf[512]; + mbedtls_x509_crt_verify_info(vrfy_buf, sizeof(vrfy_buf), "!", flags); + } + + len = sprintf((char *)m_buffer, GET_REQUEST); + + tls_encrypt_buf(&m_session, m_buffer, len); + + + memset(m_sendbuffer, 0, sizeof(m_sendbuffer)); + + mbedtls_ssl_context* ssl = &m_session.mbedSslCtx; + + if (ssl->out_left > 0) { + memcpy(m_sendbuffer, ssl->out_hdr - ssl->out_left, ssl->out_left); + ioevstream_write(m_stream, m_sendbuffer, ssl->out_left, 30); + } + } + return S_OK; +} +HRESULT CTcpSocketSSLImpl::OnReadcb(short err, BUF_PTR ptr, BUF_SIZE len) +{ + rc_assert(m_pISockProc.m_p != NULL, E_FAIL); + + mbedtls_ssl_context* ssl = &m_session.mbedSslCtx; + + if (m_rstate == SSL_READ_HEAD) { + memcpy(ssl->in_hdr + ssl->in_left, ptr, len); + ssl_parse_record_header(ssl); + m_rstate = SSL_READ_BODY; + ssl->in_left = ssl->in_msglen; + ioevstream_read(m_stream, m_recvbuffer, ssl->in_msglen, 30); + return S_OK; + } + + if (m_rstate == SSL_READ_BODY) { + ssl->in_left = 5; + memcpy(ssl->in_hdr + ssl->in_left, ptr, len); + ssl_prepare_record_content(ssl); + } + + + return S_OK; +} +HRESULT CTcpSocketSSLImpl::OnWritecb(short err, BUF_PTR ptr, BUF_SIZE len) +{ + rc_assert(m_pISockProc.m_p != NULL, E_FAIL); + + ioevstream_read(m_stream, m_recvbuffer, 5, 30); + +/* + int ret = 0; + unsigned char buf[1024]; + int size = sizeof(buf) - 1; + memset(buf, 0, sizeof(buf)); + ret = mbedtls_ssl_read(&m_session.mbedSslCtx, buf, size); +*/ + + + + return S_OK; +} diff --git a/asynio/tcpsocketsslimpl.h b/asynio/tcpsocketsslimpl.h index 96a95f2c1ca8bcfa62e553b463e599fe7636674f..d005f9985027011cb5d056c2b2dcd8be76d87380 100644 --- a/asynio/tcpsocketsslimpl.h +++ b/asynio/tcpsocketsslimpl.h @@ -2,8 +2,16 @@ #define _ASYNCTCPSOCKSSLIMPL_H_ #include "stdafx.h" +#include "ioevdef.h" #include "tlswrap.h" +//openssl genrsa -des3 -out server.key 1024 +//openssl req -new -key server.key -out server.csr +//openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt + +#define SSL_READ_HEAD 0 +#define SSL_READ_BODY 1 + class CTcpSocketSSLImpl : public ITcpSocketSSL, public CUnknownImp { @@ -15,10 +23,13 @@ public: STDCOM_INTERFACE_ENTRY(ITcpSocketSSL) STDCOM_INTERFACE_ENTRY(ITcpSocket) STDCOM_INTERFACE_ENTRY_UNKNOWN_(ITcpSocketSSL) + STDCOM_INTERFACE_MEMBER_ENTRY_(m_pReadOper, IOperation, IID_IReadOperation) + STDCOM_INTERFACE_MEMBER_ENTRY_(m_pWriteOper, IOperation, IID_IWriteOperation) END_STDCOM_MAP public: - HRESULT init_class(IBase* pAsynFrame); + HRESULT CreateIoOperation(IAsynFrame* pIAsynFrame); + HRESULT BindEvloop(ioevloop_t* loop); public: // IIoDevice @@ -27,41 +38,45 @@ public: std_method(OpenIo)(); // ISocket + std_method(BindEvent)(IBase* pSocketEvent); + std_method(UnBindEvent)(); std_method(CreateSock)(); std_method(CloseSock)(); std_method(IsOpen)(); std_method(AttachSock)(_sock_t sock); std_method_(_sock_t, DetachSock)(); - std_method(SetOption)(LPCSTR opt, int val); - std_method(GetOption)(LPCSTR opt, int* val); - std_method(ReadOperationSize)(int size); - std_method(WriteOperationSize)(int size); - std_method(ReadStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(WriteStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(GetReadPtr)(BUF_PTR* ptr); - std_method(GetWritePtr)(BUF_PTR* ptr); - std_method(GetReadPtrSize)(BUF_SIZE* size); - std_method(GetWritePtrSize)(BUF_SIZE* size); + std_method_(_sock_t, GetSock)(); std_method(GetReadOperation)(IID id, IBase** pBase); std_method(GetWriteOperation)(IID id, IBase** pBase); // ITcpSocket - std_method_(BUF_SIZE, SyncSend)(BUF_PTR buf, BUF_SIZE size); - std_method_(BUF_SIZE, SyncRecv)(BUF_PTR buf, BUF_SIZE size); - std_method(SyncConnect)(NET_ADDR addr, NET_PORT port); - std_method(ReadIo)(ULONG pos, ULONG size, evid event); - std_method(WriteIo)(ULONG pos, ULONG size, evid event); - std_method(ConnectIo)(NET_ADDR addr, NET_PORT port, evid event); + std_method(ReadIo)(ULONG pos, ULONG size, evid event, int tm); + std_method(WriteIo)(ULONG pos, ULONG size, evid event, int tm); + std_method(ConnectIo)(NET_ADDR addr, NET_PORT port, evid event, int tm); // ITcpSocketSSL std_method(LoadCertificate)(UCHAR* buf, size_t size); std_method(SetSSLCtxAddress)(LPCSTR hostname); - + +public: + std_method(OnEventcb)(short err, short what, _sock_t fd); + std_method(OnReadcb)(short err, BUF_PTR ptr, BUF_SIZE len); + std_method(OnWritecb)(short err, BUF_PTR ptr, BUF_SIZE len); + private: - _sock_t m_sock; - SockOptionTable m_sockoption; - OperationPtr m_pReadOperation; - OperationPtr m_pWriteOperation; + _sock_t m_sock; + _lComPtr m_pReadOper; + _lComPtr m_pWriteOper; + _lComPtr m_pConnectOper; + _lComPtr m_pISockProc; + SafePtr m_stream; + mbedtls_session_t m_session; + ioevloop_t* m_evloop; + + unsigned char m_buffer[1024]; + unsigned char m_sendbuffer[1024]; + unsigned char m_recvbuffer[1024]; + unsigned int m_rstate; }; #endif diff --git a/asynio/timerimpl.cpp b/asynio/timerimpl.cpp index 3fface641fea2dcd5ba2003e515ad2098dd236b5..53a122ec806939ebd3df3e139ad7b48783e22052 100644 --- a/asynio/timerimpl.cpp +++ b/asynio/timerimpl.cpp @@ -7,6 +7,10 @@ CTimerImpl::~CTimerImpl(void) { logi("CTimerImpl::~CTimerImpl"); } +HRESULT CTimerImpl::BindEvloop(ioevloop_t* loop) +{ + return S_OK; +} HRESULT CTimerImpl::Start() { return S_OK; @@ -19,23 +23,23 @@ HRESULT CTimerImpl::SetSec(int isec) { return S_OK; } -HRESULT CTimerImpl::UnBind() +HRESULT CTimerImpl::Bind(IBase* pBase) { - rc_assert(m_Event != NULL, E_FAIL); - m_Event.dispose(); - return S_OK; + rc_assert(pBase != NULL, E_FAIL); + return pBase->QueryInterface(IID_ITimerProc, (void**)&m_pTimerProc); } -HRESULT CTimerImpl::Bind(IBase* pBase) +HRESULT CTimerImpl::UnBind() { - rc_assert(pBase != NULL, E_FAIL); - return pBase->QueryInterface(IID_ITimerEvent, (void**)&m_Event); + rc_assert(m_pTimerProc.m_p != NULL, E_FAIL); + m_pTimerProc.dispose(); + return S_OK; } UINT CTimerImpl::GetId() { - return m_uId; + return m_id; } -HRESULT CTimerImpl::SetId(UINT uId) +HRESULT CTimerImpl::SetId(UINT id) { - m_uId = uId; + m_id = id; return S_OK; } diff --git a/asynio/timerimpl.h b/asynio/timerimpl.h index 120915c0899f21108b24b13cf5f149b2603f61fc..ea28dd766a602135eb685373c42c83c4d0371c9e 100644 --- a/asynio/timerimpl.h +++ b/asynio/timerimpl.h @@ -2,6 +2,8 @@ #define _TIMEIMPL_H_ #include "stdafx.h" +#include "ioevdef.h" + class CTimerImpl : public ITimer, public CUnknownImp { @@ -13,18 +15,21 @@ public: STDCOM_INTERFACE_ENTRY(ITimer) STDCOM_INTERFACE_ENTRY_UNKNOWN_(ITimer) END_STDCOM_MAP - +public: + HRESULT BindEvloop(ioevloop_t* loop); + +public: // ITimer std_method(Start)(); std_method(Stop)(); std_method(SetSec)(int isec); + std_method(Bind)(IBase* pBase); std_method(UnBind)(); - std_method(Bind)(IBase* pBase); std_method_(UINT, GetId)(); - std_method(SetId)(UINT uId); + std_method(SetId)(UINT id); private: - UINT m_uId; - TimerEventPtr m_Event; + UINT m_id; + _lComPtr m_pTimerProc; }; #endif diff --git a/asynio/tlswrap.cpp b/asynio/tlswrap.cpp index 9f53931bdc8f3c35b53a4d382aba9ab8c1dbdcf2..862639a0af787b91987f518e5558626f568c9732 100644 --- a/asynio/tlswrap.cpp +++ b/asynio/tlswrap.cpp @@ -1,25 +1,168 @@ #include "tlswrap.h" -int tls_send(void* ctx, const unsigned char* buf, size_t len) + +static void my_debug(void *ctx, int level, + const char *file, int line, + const char *str) +{ + ((void)level); + + //printf("%s\n", str); +} + + + +int tls_init_bio(mbedtls_session_t* session, void *entropy, size_t len) { - return 0; + mbedtls_net_init(&session->mbedNetCtx); + mbedtls_ssl_init(&session->mbedSslCtx); + mbedtls_ssl_config_init(&session->mbedSslConf); + mbedtls_ctr_drbg_init(&session->mbedDrbgCtx); + mbedtls_x509_crt_init(&session->mbedX509Crt); + mbedtls_entropy_init(&(session->mbedEtpyCtx)); + //mbedtls_ssl_conf_dbg(&session->mbedSslConf, my_debug, stdout); + mbedtls_ctr_drbg_seed(&session->mbedDrbgCtx, + mbedtls_entropy_func, + &session->mbedEtpyCtx, + (unsigned char *)entropy, + len); + + mbedtls_ssl_config_defaults(&session->mbedSslConf, + MBEDTLS_SSL_IS_CLIENT, + MBEDTLS_SSL_TRANSPORT_STREAM, + MBEDTLS_SSL_PRESET_DEFAULT); + + mbedtls_ssl_conf_authmode(&session->mbedSslConf, MBEDTLS_SSL_VERIFY_OPTIONAL); + mbedtls_ssl_conf_ca_chain(&session->mbedSslConf, &session->mbedX509Crt, NULL); + mbedtls_ssl_conf_rng(&session->mbedSslConf, mbedtls_ctr_drbg_random, &session->mbedDrbgCtx); + mbedtls_ssl_conf_dbg(&session->mbedSslConf, my_debug, stdout); + mbedtls_ssl_setup(&session->mbedSslCtx, &session->mbedSslConf); + + mbedtls_ssl_set_bio(&session->mbedSslCtx, + &session->mbedNetCtx, mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout); + + mbedtls_debug_set_threshold(4); + + return 0; } -int tls_recv(void* ctx, unsigned char* buf, size_t len) +/* Length of the "epoch" field in the record header */ +static inline size_t iossl_ep_len(const mbedtls_ssl_context* ssl) { - return 0; +#if defined(MBEDTLS_SSL_PROTO_DTLS) + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) + return (2); +#else + ((void)ssl); +#endif + return (0); } -int tls_recv_timeout(void* ctx, unsigned char* buf, size_t len, uint32_t timeout) +static void iossl_update_out_pointers(mbedtls_ssl_context* ssl, mbedtls_ssl_transform* transform) { - return 0; +#if defined(MBEDTLS_SSL_PROTO_DTLS) + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { + ssl->out_ctr = ssl->out_hdr + 3; + ssl->out_len = ssl->out_hdr + 11; + ssl->out_iv = ssl->out_hdr + 13; + } else +#endif + { + ssl->out_ctr = ssl->out_hdr - 8; + ssl->out_len = ssl->out_hdr + 3; + ssl->out_iv = ssl->out_hdr + 5; + } + + /* Adjust out_msg to make space for explicit IV, if used. */ + if (transform != NULL && ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_2) { + ssl->out_msg = ssl->out_iv + transform->ivlen - transform->fixed_ivlen; + } else + ssl->out_msg = ssl->out_iv; } -int tls_handshake_client_step(mbedtls_ssl_context* ssl) +#define SSL_DONT_FORCE_FLUSH 0 +#define SSL_FORCE_FLUSH 1 + +int tls_encrypt_buf(mbedtls_session_t* session, unsigned char* ptr, size_t size) { - return 0; + unsigned i; + int ret, done = 0; + uint8_t flush = SSL_FORCE_FLUSH; + + size_t protected_record_size; + mbedtls_ssl_context* ssl = &session->mbedSslCtx; + + ssl->out_msglen = size; + ssl->out_msgtype = MBEDTLS_SSL_MSG_APPLICATION_DATA; + memcpy(ssl->out_msg, ptr, size); + + + size_t len = ssl->out_msglen; + ssl->out_hdr[0] = (unsigned char)ssl->out_msgtype; + mbedtls_ssl_write_version(ssl->major_ver, ssl->minor_ver,ssl->conf->transport, ssl->out_hdr + 1); + memcpy(ssl->out_ctr, ssl->cur_out_ctr, 8); + ssl->out_len[0] = (unsigned char)(len >> 8); + ssl->out_len[1] = (unsigned char)(len); + + if (ssl->transform_out != NULL) { + if ((ret = ssl_encrypt_buf(ssl)) != 0) { + return (ret); + } + + len = ssl->out_msglen; + ssl->out_len[0] = (unsigned char)(len >> 8); + ssl->out_len[1] = (unsigned char)(len); + } + protected_record_size = len + mbedtls_ssl_hdr_len(ssl); + + +#if defined(MBEDTLS_SSL_PROTO_DTLS) + /* In case of DTLS, double-check that we don't exceed + * the remaining space in the datagram. */ + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) { + ret = ssl_get_remaining_space_in_datagram(ssl); + if (ret < 0) + return (ret); + + if (protected_record_size > (size_t)ret) { + /* Should never happen */ + return (MBEDTLS_ERR_SSL_INTERNAL_ERROR); + } + } +#endif /* MBEDTLS_SSL_PROTO_DTLS */ + + + ssl->out_left += protected_record_size; + ssl->out_hdr += protected_record_size; + iossl_update_out_pointers(ssl, ssl->transform_out); + + for (i = 8; i > iossl_ep_len(ssl); i--) + if (++ssl->cur_out_ctr[i - 1] != 0) + break; + +#if defined(MBEDTLS_SSL_PROTO_DTLS) + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && flush == SSL_DONT_FORCE_FLUSH) { + + size_t remaining; + ret = ssl_get_remaining_payload_in_datagram(ssl); + if (ret < 0) { + MBEDTLS_SSL_DEBUG_RET(1, "ssl_get_remaining_payload_in_datagram", ret); + return (ret); + } + + remaining = (size_t)ret; + if (remaining == 0) { + flush = SSL_FORCE_FLUSH; + } else { + MBEDTLS_SSL_DEBUG_MSG(2, ("Still %u bytes available in current datagram", (unsigned)remaining)); + } + + } +#endif /* MBEDTLS_SSL_PROTO_DTLS */ + + return 0; } -int tls_handshake_server_step(mbedtls_ssl_context* ssl) +int tls_decryption_buf(mbedtls_session_t* session, unsigned char* ptr, size_t size) { - return 0; + return 0; } diff --git a/asynio/tlswrap.h b/asynio/tlswrap.h index 6a682ec040255f83099ab6156c494e5c4b75580f..68300359df936d590e753408eaa9740db4a7ed13 100644 --- a/asynio/tlswrap.h +++ b/asynio/tlswrap.h @@ -21,9 +21,9 @@ #define mbedtls_printf printf #endif -#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_SSL_TLS_C) \ - || !defined(MBEDTLS_SSL_CLI_C) || !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_CERTS_C) \ - || !defined(MBEDTLS_PEM_PARSE_C) || !defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) +#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) \ + || !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_CERTS_C) || !defined(MBEDTLS_PEM_PARSE_C) \ + || !defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) #else @@ -34,18 +34,26 @@ #include #include #include - +#include +#include #include #endif -int tls_send(void* ctx, const unsigned char* buf, size_t len); - -int tls_recv(void* ctx, unsigned char* buf, size_t len); - -int tls_recv_timeout(void* ctx, unsigned char* buf, size_t len, uint32_t timeout); - -int tls_handshake_client_step(mbedtls_ssl_context* ssl); -int tls_handshake_server_step(mbedtls_ssl_context* ssl); +typedef struct mbedtls_session_s mbedtls_session_t; + +struct mbedtls_session_s { + mbedtls_entropy_context mbedEntropy; + mbedtls_net_context mbedNetCtx; + mbedtls_ssl_context mbedSslCtx; + mbedtls_ssl_config mbedSslConf; + mbedtls_ctr_drbg_context mbedDrbgCtx; + mbedtls_entropy_context mbedEtpyCtx; + mbedtls_x509_crt mbedX509Crt; +}; + +int tls_init_bio(mbedtls_session_t* session, void *entropy, size_t len); +int tls_encrypt_buf(mbedtls_session_t* session, unsigned char* ptr, size_t size); +int tls_decryption_buf(mbedtls_session_t* session, unsigned char* ptr, size_t size); #endif diff --git a/asynio/udpsocketimpl.cpp b/asynio/udpsocketimpl.cpp index db8d5e39a25ea211010ab198c9ba72524c0be010..ff28c7787a6c703d0f84e582775a4ac67abb1ba1 100644 --- a/asynio/udpsocketimpl.cpp +++ b/asynio/udpsocketimpl.cpp @@ -8,14 +8,10 @@ CUdpSocketImpl::~CUdpSocketImpl() { logi("CUdpSocketImpl::~CUdpSocketImpl"); } -HRESULT CUdpSocketImpl::init_class(IBase* pAsynFrame) +HRESULT CUdpSocketImpl::CreateIoOperation(IAsynFrame* pIAsynFrame) { HRESULT hr = S_OK; - _lComPtr pIAsynFrame; - hr = pAsynFrame->QueryInterface(IID_IAsynFrame, (void**)&pIAsynFrame); - rc_assert(hr == S_OK, E_FAIL); - hr = pIAsynFrame->CreateIo(io_operation, (IBase**)&m_pReadOperation); rc_assert(hr == S_OK, E_FAIL); @@ -24,12 +20,16 @@ HRESULT CUdpSocketImpl::init_class(IBase* pAsynFrame) return S_OK; } +HRESULT CUdpSocketImpl::BindEvloop(ioevloop_t* loop) +{ + return S_OK; +} -HRESULT CUdpSocketImpl::CUdpSocketImpl::CloseIo(UINT rw) +HRESULT CUdpSocketImpl::CloseIo(UINT rw) { return S_OK; } -HRESULT CUdpSocketImpl::CUdpSocketImpl::BindIo() +HRESULT CUdpSocketImpl::BindIo() { rc_assert(m_sock != INVALID_SOCKET, S_ERROR); return S_OK; @@ -38,10 +38,18 @@ HRESULT CUdpSocketImpl::CUdpSocketImpl::OpenIo() { return S_OK; } +HRESULT CUdpSocketImpl::BindEvent(IBase* pSocketEvent) +{ + return S_OK; +} +HRESULT CUdpSocketImpl::UnBindEvent() +{ + return S_OK; +} HRESULT CUdpSocketImpl::CreateSock() { m_sock = INVALID_SOCKET; - m_sock = _createsock(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + m_sock = _createsock(AF_INET, SOCK_DGRAM, IPPROTO_UDP); rc_assert(m_sock != INVALID_SOCKET, E_FAIL); return S_OK; } @@ -62,86 +70,16 @@ HRESULT CUdpSocketImpl::AttachSock(_sock_t sock) m_sock = sock; return S_OK; } - _sock_t CUdpSocketImpl::DetachSock() { - return m_sock; -} -HRESULT CUdpSocketImpl::SetOption(LPCSTR opt, int val) -{ - HRESULT hr = S_OK; - - if (s_strcmp(opt, SOL_REUSEDDR) == 0) { - SetReuseAddr(&m_sock, val); - } else if (s_strcmp(opt, SOL_NODELAY) == 0) { - SetNoDelay(&m_sock, val); - } else if (s_strcmp(opt, SOL_LINGER) == 0) { - SetLinger(&m_sock, val); - } else if (s_strcmp(opt, SOL_KEEPLIVE) == 0) { - SetKeepalive(&m_sock, val); - } else if (s_strcmp(opt, SOL_CORK) == 0) { - SetCork(&m_sock, val); - } else if (s_strcmp(opt, SOL_NOSIGPIPE) == 0) { - SetNoSigPipe(&m_sock, val); - } else if (s_strcmp(opt, SOL_RECVLEN) == 0) { - SetRecvBufLen(&m_sock, val); - } else if (s_strcmp(opt, SOL_SENDLEN) == 0) { - SetSendBufLen(&m_sock, val); - } else if (s_strcmp(opt, SOL_SENDTM) == 0) { - SetSendTimeOut(&m_sock, val); - } else if (s_strcmp(opt, SOL_RECVTM) == 0) { - SetRecvTimeOut(&m_sock, val); - } else if (s_strcmp(opt, SOL_CONTM) == 0) { - SetConTimeOut(&m_sock, val); - } else if (s_strcmp(opt, SOL_SENDLOWAT) == 0) { - SetSendLoWat(&m_sock, val); - } else if (s_strcmp(opt, SOL_RECVLOWAT) == 0) { - SetRecvLoWat(&m_sock, val); - } else { - return E_FAIL; - } - - m_sockoption[opt] = val; - - return hr; -} -HRESULT CUdpSocketImpl::GetOption(LPCSTR opt, int* val) -{ - HRESULT hr = S_OK; - SockOption option = m_sockoption.find(opt); - rc_assert(option != m_sockoption.end(), E_FAIL); - *val = option->second; - return hr; -} -HRESULT CUdpSocketImpl::ReadStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->Attach(ptr, pos, size); -} -HRESULT CUdpSocketImpl::WriteStream(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) -{ - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->Attach(ptr, pos, size); -} -HRESULT CUdpSocketImpl::GetReadPtr(BUF_PTR* ptr) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->GetPtr(ptr); -} -HRESULT CUdpSocketImpl::GetWritePtr(BUF_PTR* ptr) -{ - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->GetPtr(ptr); -} -HRESULT CUdpSocketImpl::GetReadPtrSize(BUF_SIZE* size) -{ - rc_assert(m_pReadOperation.m_p != NULL, E_FAIL); - return this->m_pReadOperation->GetLen(size); + _sock_t sock; + sock = m_sock; + m_sock = INVALID_SOCKET; + return sock; } -HRESULT CUdpSocketImpl::GetWritePtrSize(BUF_SIZE* size) +_sock_t CUdpSocketImpl::GetSock() { - rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); - return this->m_pWriteOperation->GetLen(size); + return m_sock; } HRESULT CUdpSocketImpl::GetReadOperation(IID id, IBase** pBase) { @@ -153,34 +91,12 @@ HRESULT CUdpSocketImpl::GetWriteOperation(IID id, IBase** pBase) rc_assert(m_pWriteOperation.m_p != NULL, E_FAIL); return this->m_pWriteOperation->QueryInterface(id, (void**)pBase); } -HRESULT CUdpSocketImpl::ReadOperationSize(int size) -{ - HRESULT hr = S_OK; - return hr; -} -HRESULT CUdpSocketImpl::WriteOperationSize(int size) -{ - HRESULT hr = S_OK; - return hr; -} -BUF_SIZE CUdpSocketImpl::SyncSend(NET_ADDR addr, NET_PORT port, BUF_PTR buf, BUF_SIZE size) -{ - rc_assert(addr != NULL, E_FAIL); - rc_assert(port != INVALID_NET_PORT, E_FAIL); - return 0; -} -BUF_SIZE CUdpSocketImpl::SyncRecv(NET_ADDR addr, NET_PORT port, BUF_PTR buf, BUF_SIZE size) -{ - rc_assert(addr != NULL, E_FAIL); - rc_assert(port != INVALID_NET_PORT, E_FAIL); - return 0; -} HRESULT CUdpSocketImpl::ReadIo(NET_ADDR addr, NET_PORT port, IBase* pBase, evid event) { HRESULT hr = S_OK; rc_assert(pBase != NULL, E_FAIL); - OperationPtr pOperation; + _lComPtr pOperation; hr = pBase->QueryInterface(IID_IOperation, (void**)&pOperation); rc_assert(hr == S_OK, E_FAIL); @@ -189,9 +105,9 @@ HRESULT CUdpSocketImpl::ReadIo(NET_ADDR addr, NET_PORT port, IBase* pBase, evid HRESULT CUdpSocketImpl::WriteIo(NET_ADDR addr, NET_PORT port, IBase* pBase, evid event) { HRESULT hr = S_OK; - rc_assert(pBase != NULL, E_FAIL) + rc_assert(pBase != NULL, E_FAIL); - OperationPtr pOperation; + _lComPtr pOperation; hr = pBase->QueryInterface(IID_IOperation, (void**)&pOperation); rc_assert(hr == S_OK, E_FAIL); diff --git a/asynio/udpsocketimpl.h b/asynio/udpsocketimpl.h index 3c8469ac64ca28d9f50e1272aacbdf87e97a28ee..1cb3971a3d1399f0944b88c166bc821336b7f02e 100644 --- a/asynio/udpsocketimpl.h +++ b/asynio/udpsocketimpl.h @@ -2,6 +2,8 @@ #define _ASYNCUDPSOCKIMPL_H_ #include "stdafx.h" +#include "ioevdef.h" + class CUdpSocketImpl : public IUdpSocket, public CUnknownImp { @@ -15,7 +17,8 @@ public: END_STDCOM_MAP public: - HRESULT init_class(IBase* pAsynFrame); + HRESULT CreateIoOperation(IAsynFrame* pIAsynFrame); + HRESULT BindEvloop(ioevloop_t* loop); public: // IIoDevice @@ -24,37 +27,27 @@ public: std_method(OpenIo)(); // ISocket + std_method(BindEvent)(IBase* pSocketEvent); + std_method(UnBindEvent)(); std_method(CreateSock)(); std_method(CloseSock)(); std_method(IsOpen)(); std_method(AttachSock)(_sock_t sock); std_method_(_sock_t, DetachSock)(); - std_method(SetOption)(LPCSTR opt, int val); - std_method(GetOption)(LPCSTR opt, int* val); - std_method(ReadOperationSize)(int size); - std_method(WriteOperationSize)(int size); - std_method(ReadStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(WriteStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size); - std_method(GetReadPtr)(BUF_PTR* ptr); - std_method(GetWritePtr)(BUF_PTR* ptr); - std_method(GetReadPtrSize)(BUF_SIZE* size); - std_method(GetWritePtrSize)(BUF_SIZE* size); + std_method_(_sock_t, GetSock)(); std_method(GetReadOperation)(IID id, IBase** pBase); std_method(GetWriteOperation)(IID id, IBase** pBase); // IUdpSocket - std_method_(BUF_SIZE, SyncSend)(NET_ADDR addr, NET_PORT port, BUF_PTR buf, BUF_SIZE size); - std_method_(BUF_SIZE, SyncRecv)(NET_ADDR addr, NET_PORT port, BUF_PTR buf, BUF_SIZE size); std_method(ReadIo)(NET_ADDR addr, NET_PORT port, IBase* pBase, evid event); std_method(WriteIo)(NET_ADDR addr, NET_PORT port, IBase* pBase, evid event); private: _sock_t m_sock; - SockOptionTable m_sockoption; CharArrayPtr m_pAddr; NET_PORT m_uPort; - OperationPtr m_pReadOperation; - OperationPtr m_pWriteOperation; + _lComPtr m_pReadOperation; + _lComPtr m_pWriteOperation; }; #endif diff --git a/container/mainrun.h b/container/mainrun.h index a7d6f7e1b2a34b4d14571ba5cf41a9790f66cbc4..0cc25f5952f17b6e8a2fd52ebb1cff5253355171 100644 --- a/container/mainrun.h +++ b/container/mainrun.h @@ -31,7 +31,7 @@ public: private: typedef struct ObjectRunItem { ObjectRunPtr m_ptr; - } * pObjectRunItemPtr; + }* pObjectRunItemPtr; typedef std::map ObjectStruct; typedef ObjectStruct::iterator ObjectStructIterator; diff --git a/container/objectloader.cpp b/container/objectloader.cpp index 18ff55087a4ddaa282992a5e35c48289fcefecdc..9af8698064eef98459469f0978d22bfbf419a626 100644 --- a/container/objectloader.cpp +++ b/container/objectloader.cpp @@ -13,7 +13,7 @@ CObjectLoader::~CObjectLoader(void) HRESULT CObjectLoader::Load(LPSTRING path, LPCSTR name) { rc_assert(path != NULL, E_FAIL); - rc_assert(FileIsExist(path) == S_SUCCESS, E_FAIL); + rc_assert(fileisexist(path) == S_SUCCESS, E_FAIL); HRESULT hr = S_OK; diff --git a/container/objectrun.cpp b/container/objectrun.cpp index 91cead506ac67dabd5186cc9281feebddc1515fe..dfa3c729b4f477de97201f18be6069c05dd0cf8e 100644 --- a/container/objectrun.cpp +++ b/container/objectrun.cpp @@ -90,11 +90,9 @@ HRESULT CObjectRunImpl::SetPath(const SafePStringPtr* path) m_strRunPath.clear(); m_strRunPath.append(path->ptr); - logi("s_strcpy_func %p", s_strcpy); - m_strContainer.clear(); TCHAR szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00}; - GetDynamicName(_T("container"), szPluginName, DYNAMIC_NAME_LEN); + get_dynamicname(_T("container"), szPluginName, DYNAMIC_NAME_LEN); m_strContainer = m_strRunPath; m_strContainer.append(path_slash); m_strContainer.append(szPluginName); @@ -260,7 +258,7 @@ UINT CObjectRunImpl::GetStartType() { return m_type; } -_pid_t CObjectRunImpl::GetInstance() +_pid_t CObjectRunImpl::get_instance() { return m_pid; } @@ -661,8 +659,7 @@ HRESULT CObjectRunImpl::RunMsgPlugin_Stop(BaseConstPtr pBase) rc_assert(pMsgPlugin.m_p != NULL, E_FAIL); return pMsgPlugin->OnMsgStop(); } -HRESULT CObjectRunImpl::RunMsgPlugin_Recv( - BaseConstPtr pBase, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg, IBase** outmsg) +HRESULT CObjectRunImpl::RunMsgPlugin_Recv(BaseConstPtr pBase, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg, IBase** outmsg) { HRESULT hr = S_OK; MsgPluginPtr pMsgPlugin; @@ -702,17 +699,17 @@ basic_tstring CObjectRunImpl::ContainerPath(LPCSTR ComponentName) SafePtr pBuf; pBuf = char_to_wchar(ComponentName, s_strlen(ComponentName)); basic_tchar szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00}; - GetDynamicName(pBuf, szPluginName, DYNAMIC_NAME_LEN); + get_dynamicname(pBuf, szPluginName, DYNAMIC_NAME_LEN); #elif (TARGET_OS == OS_POSIX) basic_tchar szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00}; - GetDynamicName(ComponentName, szPluginName, DYNAMIC_NAME_LEN); + get_dynamicname(ComponentName, szPluginName, DYNAMIC_NAME_LEN); #elif (TARGET_OS == OS_MACH) basic_tchar szPluginName[DYNAMIC_NAME_LEN + 1] = {0x00}; - GetDynamicName(ComponentName, szPluginName, DYNAMIC_NAME_LEN); + get_dynamicname(ComponentName, szPluginName, DYNAMIC_NAME_LEN); #endif diff --git a/container/objectrun.h b/container/objectrun.h index 879b9d7a4b0a5ffc8dbaced78e75e31de4605ce7..e65d666cf3641d6b4fbedf263db7fe28c87117ce 100644 --- a/container/objectrun.h +++ b/container/objectrun.h @@ -51,7 +51,7 @@ public: std_method_(UINT, GetArgc)(); std_method_(LPSTRING, GetIndexArgc)(UINT index); std_method_(UINT, GetStartType)(); - std_method_(_pid_t, GetInstance)(); + std_method_(_pid_t, get_instance)(); // IMsgPlugin std_method(OnMsgStart)(); diff --git a/crt/crt_assert.hpp b/crt/crt_assert.hpp index 58df94581a1aa037df58b921dcd71aed293a0b63..16d4b23e947c3772a8b989b9d4329202b0ffe5a4 100644 --- a/crt/crt_assert.hpp +++ b/crt/crt_assert.hpp @@ -4,6 +4,10 @@ #include #include +// this linux kernel if +// #define likely(x) __builtin_expect(!!(x), 1) +// #define unlikely(x) __builtin_expect(!!(x), 0) + #define rs_assert(p, v) \ do { \ if ((int)(p)) \ diff --git a/crt/crt_cjson.h b/crt/crt_cjson.h index a472514ca9f6baa7b7bb792a862a9ed1c80d72cf..a34fcf7e70ee9427fd6ae02559325d027014ef43 100644 --- a/crt/crt_cjson.h +++ b/crt/crt_cjson.h @@ -138,11 +138,9 @@ void cJSON_Minify(char* json); #define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) double cJSON_SetNumberHelper(cJSON* object, double number); -#define cJSON_SetNumberValue(object, number) \ - ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) -#define cJSON_ArrayForEach(element, array) \ - for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) +#define cJSON_ArrayForEach(element, array) for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) void* cJSON_malloc(size_t size); void cJSON_free(void* object); diff --git a/crt/crt_common.hpp b/crt/crt_common.hpp index d941f8320b789b9edc302e0671e19fcb3a9a434c..542c37a5b8a4debe33262083263b5c55fefd62e6 100644 --- a/crt/crt_common.hpp +++ b/crt/crt_common.hpp @@ -89,9 +89,9 @@ typedef long _off_t; #define CONST_VTBL #endif -#define bool _Bool +#define bool _Bool #define false 0 -#define true 1 +#define true 1 #endif /* __cplusplus */ diff --git a/crt/crt_def.h b/crt/crt_def.h index 436b9438a2468a3b3e94c8e4f2244e9d19060623..04b54c3020f6f2ff0905f90d780621b5e3b103ec 100644 --- a/crt/crt_def.h +++ b/crt/crt_def.h @@ -81,6 +81,22 @@ typedef struct MemoryPtr_s { typedef const SafeMemoryPtr* SafeMemoryConstPtr; #endif +#ifndef BUF_PTR +typedef unsigned char* BUF_PTR; +#endif + +#ifndef BUF_SIZE +typedef unsigned long BUF_SIZE; +#endif + +#ifndef BUF_T +typedef struct _buffer_s _buffer_t; +struct _buffer_s { + BUF_PTR ptr; + BUF_SIZE len; +}; +#endif + #pragma pack(pop) #define _crt_iswalpha(c) (('A' <= (c) && (c) <= 'Z') || ('a' <= (c) && (c) <= 'z')) diff --git a/crt/crt_event.h b/crt/crt_event.h index 2dc00a3db055ce66a5ba351adfba34b22fc781b8..b33204cbfbf1db985c08686e8bd3de230fc5d5cf 100644 --- a/crt/crt_event.h +++ b/crt/crt_event.h @@ -320,35 +320,24 @@ struct evloop_s { #pragma pack(pop) void* evloop_evbase(evloop_t* loop); - void* evoper_evbase(evoper_t* oper); - void* evoper_private(evoper_t* oper); int evoper_bindevloop(evloop_t* loop, evoper_t* oper); int evloop_add(evoper_t* oper, ev_time_t tv, short event); - int evloop_del(evoper_t* oper, short event); int evloop_addtimer(evoper_t* oper, ev_time_t tv); - int evloop_open(evoper_t* oper, const addressptr_t* addr, short event, ev_time_t tv); - int evloop_poll(evoper_t* oper, short event); - int evloop_update_time(evloop_t* loop); - int evloop_alloc_evoper(evloop_t* loop, evoper_t* oper); - int evloop_dealloc_evoper(evloop_t* loop, evoper_t* oper); - int evloop_init(evloop_t* loop, int size, int flag); - int evloop_uninit(evloop_t* loop); int evloop_run(evloop_t* loop, long msec); - int evloop_stop(evloop_t* loop); #ifdef __cplusplus diff --git a/crt/crt_event_iocp.h b/crt/crt_event_iocp.h index 1ade04cd239271499fa0e6bce43bca8a9127e41a..061a343ef676db55d4f5668800b47251511157ac 100644 --- a/crt/crt_event_iocp.h +++ b/crt/crt_event_iocp.h @@ -17,28 +17,40 @@ typedef struct iocp_fns_ex iocp_fns; #ifndef WSAID_ACCEPTEX #define WSAID_ACCEPTEX \ { \ - 0xb5367df1, 0xcbac, 0x11cf, { 0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 } \ + 0xb5367df1, 0xcbac, 0x11cf, \ + { \ + 0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \ + } \ } #endif #ifndef WSAID_CONNECTEX #define WSAID_CONNECTEX \ { \ - 0x25a207b9, 0xddf3, 0x4660, { 0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e } \ + 0x25a207b9, 0xddf3, 0x4660, \ + { \ + 0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e \ + } \ } #endif #ifndef WSAID_GETACCEPTEXSOCKADDRS #define WSAID_GETACCEPTEXSOCKADDRS \ { \ - 0xb5367df2, 0xcbac, 0x11cf, { 0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 } \ + 0xb5367df2, 0xcbac, 0x11cf, \ + { \ + 0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \ + } \ } #endif #ifndef WSAID_DISCONNECTEX #define WSAID_DISCONNECTEX \ { \ - 0x7fda2e11, 0x8630, 0x436f, { 0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57 } \ + 0x7fda2e11, 0x8630, 0x436f, \ + { \ + 0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57 \ + } \ } #endif diff --git a/crt/crt_guid.hpp b/crt/crt_guid.hpp index 1c241e13e231a84d4689e4c8b15f520125a9b1d2..4b488e538eabc922c3cee387af7ad4b94706b245 100644 --- a/crt/crt_guid.hpp +++ b/crt/crt_guid.hpp @@ -96,10 +96,8 @@ typedef FMTID* LPFMTID; __inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) { return ( - ((unsigned long*)&rguid1)[0] == ((unsigned long*)&rguid2)[0] - && ((unsigned long*)&rguid1)[1] == ((unsigned long*)&rguid2)[1] - && ((unsigned long*)&rguid1)[2] == ((unsigned long*)&rguid2)[2] - && ((unsigned long*)&rguid1)[3] == ((unsigned long*)&rguid2)[3]); + ((unsigned long*)&rguid1)[0] == ((unsigned long*)&rguid2)[0] && ((unsigned long*)&rguid1)[1] == ((unsigned long*)&rguid2)[1] + && ((unsigned long*)&rguid1)[2] == ((unsigned long*)&rguid2)[2] && ((unsigned long*)&rguid1)[3] == ((unsigned long*)&rguid2)[3]); } __inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) @@ -110,10 +108,8 @@ __inline int IsEqualGUID(REFGUID rguid1, REFGUID rguid2) #else // ! __cplusplus #define InlineIsEqualGUID(rguid1, rguid2) \ - (((unsigned long*)rguid1)[0] == ((unsigned long*)rguid2)[0] \ - && ((unsigned long*)rguid1)[1] == ((unsigned long*)rguid2)[1] \ - && ((unsigned long*)rguid1)[2] == ((unsigned long*)rguid2)[2] \ - && ((unsigned long*)rguid1)[3] == ((unsigned long*)rguid2)[3]) + (((unsigned long*)rguid1)[0] == ((unsigned long*)rguid2)[0] && ((unsigned long*)rguid1)[1] == ((unsigned long*)rguid2)[1] \ + && ((unsigned long*)rguid1)[2] == ((unsigned long*)rguid2)[2] && ((unsigned long*)rguid1)[3] == ((unsigned long*)rguid2)[3]) #define IsEqualGUID(rguid1, rguid2) (!s_memicmp(rguid1, rguid2, sizeof(GUID))) diff --git a/crt/crt_iterator.h b/crt/crt_iterator.h index 3bf76c8833c8aedbb7d1d4ae0c01d76adcc7cf1c..045e1152a51b203c9ccdad4ed14b33be6b087795 100644 --- a/crt/crt_iterator.h +++ b/crt/crt_iterator.h @@ -19,8 +19,7 @@ struct ITER { int size; }; -#define foreach_t(iter, container) \ - for ((container)->iter_head(&(iter), (container)); (iter).ptr; (container)->iter_next(&(iter), (container))) +#define foreach_t(iter, container) for ((container)->iter_head(&(iter), (container)); (iter).ptr; (container)->iter_next(&(iter), (container))) #define foreach_reverse_t(iter, container) \ for ((container)->iter_tail(&(iter), (container)); (iter).ptr; (container)->iter_prev(&(iter), (container))) diff --git a/crt/crt_log.h b/crt/crt_log.h index 0d6151495caaff2ccc0861fe92df2df563a91dff..fd35154bd0dc02007f865744bfd89b0b100c631a 100644 --- a/crt/crt_log.h +++ b/crt/crt_log.h @@ -27,16 +27,8 @@ typedef enum sys_LogPriority { } sys_LogPriority; -_VISIBILITY_HIDDEN int log_print( - int proi, - const char* tag, - const char* data, - const char* time, - const char* file, - long line, - const char* func, - const char* fmt, - ...); +_VISIBILITY_HIDDEN int + log_print(int proi, const char* tag, const char* data, const char* time, const char* file, long line, const char* func, const char* fmt, ...); #if (TARGET_OS == OS_WIN) @@ -52,17 +44,13 @@ _VISIBILITY_HIDDEN int log_print( #endif -#define loge(...) \ - log_print(SYS_LOG_ERROR, log_error_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) +#define loge(...) log_print(SYS_LOG_ERROR, log_error_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) -#define logw(...) \ - log_print(SYS_LOG_WARN, log_warning_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) +#define logw(...) log_print(SYS_LOG_WARN, log_warning_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) -#define logi(...) \ - log_print(SYS_LOG_INFO, log_info_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) +#define logi(...) log_print(SYS_LOG_INFO, log_info_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) -#define logd(...) \ - log_print(SYS_LOG_DEBUG, log_debug_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) +#define logd(...) log_print(SYS_LOG_DEBUG, log_debug_tag, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) #define logv(...) log_print(SYS_LOG_VERBOSE, __DATE__, __TIME__, __FILE__, __LINE__, _LOG_FUNCTION_, __VA_ARGS__) diff --git a/crt/crt_path.h b/crt/crt_path.h index 7809516c40962be5f2ca44947cb847a031240e31..debffa8da212a21abfab915bb80abe934836b1b6 100644 --- a/crt/crt_path.h +++ b/crt/crt_path.h @@ -7,13 +7,21 @@ extern "C" { #endif -int FileIsExist(const basic_tchar* file); -int FileIsDirectory(const basic_tchar* dir); -int GetDynamicPath(void* name, basic_tchar* path, size_t len); -int GetExecutePath(_pid_t pid, basic_tchar* path, size_t len); -int GetDynamicName(const basic_tchar* name, basic_tchar* pluginame, size_t len); +#if (TARGET_OS == OS_WIN) +typedef size_t pathlen; +#elif (TARGET_OS == OS_POSIX) +typedef size_t pathlen; +#elif (TARGET_OS == OS_MACH) +typedef uint32_t pathlen; +#endif + +int fileisexist(const basic_tchar* file); +int fileisdirectory(const basic_tchar* dir); +int get_dynamicpath(void* name, basic_tchar* path, size_t len); +int get_executepath(_pid_t pid, basic_tchar* path, pathlen len); +int get_dynamicname(const basic_tchar* name, basic_tchar* pluginame, size_t len); typedef void (*get_file_cb)(const basic_tchar* path, void* ctx); -int GetFiles(basic_tchar* path, get_file_cb entry, void* ctx); +int get_files(basic_tchar* path, get_file_cb entry, void* ctx); #ifdef __cplusplus } diff --git a/crt/crt_proctl.h b/crt/crt_proctl.h index 8a362d9c9586787fa48781fb2a8f988f12d7c13c..e06a833f503a462e05aa98b7489edf43d7a1d7e1 100644 --- a/crt/crt_proctl.h +++ b/crt/crt_proctl.h @@ -30,8 +30,8 @@ typedef pid_t _pid_instance; #endif -_pid_t GetProcessid(void); -_pid_instance GetInstance(void); +_pid_t get_processid(void); +_pid_instance get_instance(void); #ifdef __cplusplus } diff --git a/crt/crt_rbtree.h b/crt/crt_rbtree.h index 8c5184ae095df52182899d26bcf262de4721cca8..04b6ef876c3365ff9e214ecb2bbf0f1383363fee 100644 --- a/crt/crt_rbtree.h +++ b/crt/crt_rbtree.h @@ -65,7 +65,10 @@ struct _rbtree_root { #define rb_parent(r) ((struct _rbtree_node*)((r)->__rb_parent_color & ~3)) #define RB_ROOT \ - (struct _rbtree_root) { NULL, } + (struct _rbtree_root) \ + { \ + NULL, \ + } #define rb_entry(ptr, type, member) _container_of(ptr, type, member) #define rb_entry_safe(ptr, type, member) _container_of(ptr, type, member) diff --git a/crt/crt_sock.h b/crt/crt_sock.h index a7f4e195047aa9c8a18b83fd52d490c8a1ff4af0..314ac5ad27a7e164fae21ac7f5f58e7f4e272d37 100644 --- a/crt/crt_sock.h +++ b/crt/crt_sock.h @@ -32,12 +32,8 @@ typedef const char* NET_ADDR; typedef unsigned int NET_ADDR_INT; #endif -#ifndef BUF_PTR -typedef unsigned char* BUF_PTR; -#endif - -#ifndef BUF_SIZE -typedef unsigned long BUF_SIZE; +#ifndef NET_ADDR_PORT +typedef unsigned short NET_ADDR_PORT; #endif /* @@ -56,6 +52,10 @@ struct crt_sockaddr_storage { } ss_union; }; +#ifndef SOCKADDR_PTR +typedef const struct sockaddr* SOCKADDR_PTR; +#endif + #if (TARGET_OS == OS_WIN) typedef SOCKET _sock_t; @@ -92,11 +92,14 @@ struct sockaddr_un { }; #endif // !_AFUNIX_ -#define _ERR_CONNECT_RETRIABLE(e) \ - ((e) == SC_EWOULDBLOCK || (e) == SC_EINTR || (e) == SC_EINPROGRESS || (e) == SC_EINVAL) +#define _ERR_CONNECT_RETRIABLE(e) ((e) == SC_EWOULDBLOCK || (e) == SC_EINTR || (e) == SC_EINPROGRESS || (e) == SC_EINVAL) #define _ERR_CONNECT_REFUSED(e) ((e) == WSAECONNREFUSED) +#define _ERR_CONNECT_ERRORRESET(e) ((e) == SC_ECONNRESET) +#define _ERR_CONNECT_ERROR_ENET(e) ((e) == SC_ENETDOWN || (e) == SC_ENETUNREACH) +#define _ERR_CONNECT_ERROR_EHOST(e) ((e) == SC_EHOSTDOWN || (e) == SC_EHOSTUNREACH) + int _socket_geterror(_sock_t sock); #elif (TARGET_OS == OS_POSIX) @@ -126,7 +129,11 @@ typedef int _sock_t; #define SC_EINPROGRESS EINPROGRESS #define _ERR_CONNECT_RETRIABLE(e) ((e) == SC_EINTR || (e) == SC_EINPROGRESS) -#define _ERR_CONNECT_REFUSED(e) ((e) == SC_ECONNREFUSED) +#define _ERR_CONNECT_REFUSED(e) ((e) == SC_ECONNREFUSED || (e) == SC_EAGAIN) + +#define _ERR_CONNECT_ERRORRESET(e) ((e) == SC_ECONNRESET) +#define _ERR_CONNECT_ERROR_ENET(e) ((e) == SC_ENETDOWN || (e) == SC_ENETUNREACH) +#define _ERR_CONNECT_ERROR_EHOST(e) ((e) == SC_EHOSTDOWN || (e) == SC_EHOSTUNREACH) #define _socket_geterror(sock) (errno) @@ -157,7 +164,11 @@ typedef int _sock_t; #define SC_EINPROGRESS EINPROGRESS #define _ERR_CONNECT_RETRIABLE(e) ((e) == SC_EINTR || (e) == SC_EINPROGRESS) -#define _ERR_CONNECT_REFUSED(e) ((e) == SC_ECONNREFUSED) +#define _ERR_CONNECT_REFUSED(e) ((e) == SC_ECONNREFUSED || (e) == SC_EAGAIN) + +#define _ERR_CONNECT_ERRORRESET(e) ((e) == SC_ECONNRESET) +#define _ERR_CONNECT_ERROR_ENET(e) ((e) == SC_ENETDOWN || (e) == SC_ENETUNREACH) +#define _ERR_CONNECT_ERROR_EHOST(e) ((e) == SC_EHOSTDOWN || (e) == SC_EHOSTUNREACH) #define _socket_geterror(sock) (errno) @@ -173,24 +184,19 @@ typedef union { struct sockaddr sa; } sock_addr; -_sock_t _bind_unixsock(const char* name, size_t len, int af, int type, int protocol); +int _bind_unixsock(_sock_t s, const char* name, size_t len, int af); +int _connect_unixsock(_sock_t s, const char* name, size_t len, int af); -_sock_t _connect_unixsock(const char* name, size_t len, int af, int type, int protocol); +int _bind_stcpsockv4(_sock_t s, const char* name, size_t len, int scount, unsigned short port); +int _bind_stcpsockv6(_sock_t s, const char* name, size_t len, int scount, unsigned short port); -_sock_t _bind_stcpsockv4(const char* name, size_t len, int slisten, unsigned short port); +int _connect_ctcpsockv4(_sock_t s, const char* name, size_t len, unsigned short port); +int _connect_ctcpsockv6(_sock_t s, const char* name, size_t len, unsigned short port); -_sock_t _bind_stcpsockv6(const char* name, size_t len, int slisten, unsigned short port); - -_sock_t _connect_ctcpsockv4(const char* name, size_t len, unsigned short port); - -_sock_t _connect_ctcpsockv6(const char* name, size_t len, unsigned short port); - -int _asynconnect_ctcpsockv4(_sock_t s, const struct sockaddr* sa, socklen_t socklen); - -int _asynconnect_ctcpsockv6(_sock_t s, const struct sockaddr* sa, socklen_t socklen); +int _asynconnect_sockv4(_sock_t s, const char* name, size_t len, unsigned short port); +int _asynconnect_sock(_sock_t s, SOCKADDR_PTR sa, socklen_t socklen); int _connectfinished_socket(_sock_t s); - int socket_closeonexec(_sock_t s); _sock_t _createsock(int af, int type, int protocol); @@ -199,26 +205,28 @@ int _closesock(_sock_t s); int _shutdown_sock(_sock_t s, int howrw); int is_listen_socket(_sock_t s); int getsocktype(_sock_t s); -int set_blocking(_sock_t s, int turn); -int SetError(_sock_t* s, int turn); -int SetReuseAddr(_sock_t* s, int turn); -int SetNoDelay(_sock_t* s, int turn); -int SetBroadCast(_sock_t* s, int turn); -int SetDontRoute(_sock_t* s, int turn); -int SetKeepalive(_sock_t* s, int turn); -int SetCork(_sock_t* s, int turn); -int SetNoSigPipe(_sock_t* s, int turn); -int SetNonblock(_sock_t* s, int turn); -int SetDoLinger(_sock_t* s, int turn); -int SetLinger(_sock_t* s, int sec); -int SetSendTimeOut(_sock_t* s, int sec); -int SetRecvTimeOut(_sock_t* s, int sec); -int SetConTimeOut(_sock_t* s, int sec); -int SetSendBufLen(_sock_t* s, int size); -int SetRecvBufLen(_sock_t* s, int size); -int SetSendLoWat(_sock_t* s, int size); -int SetRecvLoWat(_sock_t* s, int size); +int set_blocking(_sock_t s, int turn); +int set_sockerror(_sock_t s, int turn); +int set_reuseaddr(_sock_t s, int turn); +int set_nodelay(_sock_t s, int turn); +int set_deferaccpet(_sock_t s, int turn); +int set_broadcast(_sock_t s, int turn); +int set_dontroute(_sock_t s, int turn); +int set_keepalive(_sock_t s, int turn); +int set_cork(_sock_t s, int turn); +int set_nosigpipe(_sock_t s, int turn); +int set_dolinger(_sock_t s, int turn); +int set_reuseable(_sock_t s, int turn); +int set_reuseableport(_sock_t s, int turn); +int set_linger(_sock_t s, int sec); +int set_sendtime(_sock_t s, int sec); +int set_recvtime(_sock_t s, int sec); +int set_connectime(_sock_t s, int sec); +int set_sendbuflen(_sock_t s, int size); +int set_recvbuflen(_sock_t s, int size); +int set_sendlowat(_sock_t s, int size); +int set_recvlowat(_sock_t s, int size); #if (TARGET_OS == OS_WIN) int socketpair(int d, int type, int protocol, _sock_t sv[2]); diff --git a/crt/crt_sockinet.h b/crt/crt_sockinet.h index bd54f79e12307a58afd11b1e8c77a84eee521a58..fb679c91be3765d5713a1009543dfd08ead1696b 100644 --- a/crt/crt_sockinet.h +++ b/crt/crt_sockinet.h @@ -13,14 +13,14 @@ extern "C" { #define DONT_GRIPE 0 #define DO_GRIPE 1 -//#ifndef INET_ADDRSTRLEN -//#define INET_ADDRSTRLEN (sizeof("255.255.255.255") - 1) -//#endif +// #ifndef INET_ADDRSTRLEN +// #define INET_ADDRSTRLEN (sizeof("255.255.255.255") - 1) +// #endif // // -//#ifndef INET6_ADDRSTRLEN -//#define INET6_ADDRSTRLEN (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") - 1) -//#endif +// #ifndef INET6_ADDRSTRLEN +// #define INET6_ADDRSTRLEN (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") - 1) +// #endif int _valid_hostaddr(const char*, int); int _valid_ipv4_hostaddr(const char*, int); diff --git a/crt/crt_stdtime.h b/crt/crt_stdtime.h index b3cdb2405e2f57ab369ab20528047b4d5895bd6f..24531bcb7397f9fe26576dc7473360bc2bb92371 100644 --- a/crt/crt_stdtime.h +++ b/crt/crt_stdtime.h @@ -42,6 +42,10 @@ int timerval_sub(struct timeval* utv, struct timeval* ttv, struct timeval* vtv); #define tv_cmp_great 10 #define tv_cmp_less 11 +#ifndef TVL_PTR +typedef struct timeval* TVL_PTR; +#endif + int timerval_cmp(struct timeval* utv, struct timeval* ttv); #ifdef __cplusplus diff --git a/crt/crt_util.h b/crt/crt_util.h index 38a5add2f57f86b76272b79093be96e298bb9b12..be381102c898ac2c1e38fe4e291f89d493eccbf6 100644 --- a/crt/crt_util.h +++ b/crt/crt_util.h @@ -20,7 +20,7 @@ unsigned long long 8 8 %llu */ // Data Type ILP32 LP32 ILP64 LP64 LLP64 -//#define _ _ _ __LP64__ __LLP64__ +// #define _ _ _ __LP64__ __LLP64__ // target (Win32API,Linux,MacOSX) Win16 API _ Linux,MacOSX Win64 API // char 8 8 8 8 8 // short 16 16 16 16 16 diff --git a/crt/machosdef.h b/crt/machosdef.h index 803f08aa828fa3ac80658ac32ad3b772315859d3..dc682ee874c1716bb4022185b8bd71a10131d9df 100644 --- a/crt/machosdef.h +++ b/crt/machosdef.h @@ -30,7 +30,7 @@ // atomic #include -//#include +// #include #include diff --git a/crt/machossysdef.h b/crt/machossysdef.h index ed4f66fb2965a3fdaa007182a66b558b52c5fd97..446941f1abb7db2c9808c2acff0f9d212696906b 100644 --- a/crt/machossysdef.h +++ b/crt/machossysdef.h @@ -244,22 +244,22 @@ typedef LONG SCODE; #define DLL_THREAD_DETACH 3 #define DLL_PROCESS_DETACH 0 -//#ifndef _LINUX_LIMITS_H -//#define _LINUX_LIMITS_H -//#define NR_OPEN 1024 -//#define NGROUPS_MAX 65536 /* supplemental group IDs are available */ -//#define ARG_MAX 131072 /* bytes of args + environ for exec() */ -//#define LINK_MAX 127 /* # links a file may have */ -//#define MAX_CANON 255 /* size of the canonical input queue */ -//#define MAX_INPUT 255 /* size of the type-ahead buffer */ -//#define NAME_MAX 255 /* */ -//#define PATH_MAX 4096 /* */ -//#define PIPE_BUF 4096 /* bytes in atomic write to a pipe */ -//#define XATTR_NAME_MAX 255 /* chars in an extended attribute name */ -//#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */ -//#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ -//#define RTSIG_MAX 32 -//#endif +// #ifndef _LINUX_LIMITS_H +// #define _LINUX_LIMITS_H +// #define NR_OPEN 1024 +// #define NGROUPS_MAX 65536 /* supplemental group IDs are available */ +// #define ARG_MAX 131072 /* bytes of args + environ for exec() */ +// #define LINK_MAX 127 /* # links a file may have */ +// #define MAX_CANON 255 /* size of the canonical input queue */ +// #define MAX_INPUT 255 /* size of the type-ahead buffer */ +// #define NAME_MAX 255 /* */ +// #define PATH_MAX 4096 /* */ +// #define PIPE_BUF 4096 /* bytes in atomic write to a pipe */ +// #define XATTR_NAME_MAX 255 /* chars in an extended attribute name */ +// #define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */ +// #define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ +// #define RTSIG_MAX 32 +// #endif // look #include diff --git a/crt/posixosdef.h b/crt/posixosdef.h index 3937dea7063c290dd6a5fceb376481a09db7a594..172e17349d1f8b00122ef50371c47c7f19d2ec83 100644 --- a/crt/posixosdef.h +++ b/crt/posixosdef.h @@ -13,8 +13,8 @@ #include #include -//#define int64 long long int -//#define uint64 unsigned long long int +// #define int64 long long int +// #define uint64 unsigned long long int #define FMT_I64D "%lld" diff --git a/crt/posixossysdef.h b/crt/posixossysdef.h index 896f9e24abfc1367b8e85ca102aa013b5f7fb89b..7a04fe511e47991af253aeaa0f2238102c2e2be5 100644 --- a/crt/posixossysdef.h +++ b/crt/posixossysdef.h @@ -240,22 +240,22 @@ typedef LONG SCODE; #define DLL_THREAD_DETACH 3 #define DLL_PROCESS_DETACH 0 -//#ifndef _LINUX_LIMITS_H -//#define _LINUX_LIMITS_H -//#define NR_OPEN 1024 -//#define NGROUPS_MAX 65536 /* supplemental group IDs are available */ -//#define ARG_MAX 131072 /* bytes of args + environ for exec() */ -//#define LINK_MAX 127 /* # links a file may have */ -//#define MAX_CANON 255 /* size of the canonical input queue */ -//#define MAX_INPUT 255 /* size of the type-ahead buffer */ -//#define NAME_MAX 255 /* */ -//#define PATH_MAX 4096 /* */ -//#define PIPE_BUF 4096 /* bytes in atomic write to a pipe */ -//#define XATTR_NAME_MAX 255 /* chars in an extended attribute name */ -//#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */ -//#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ -//#define RTSIG_MAX 32 -//#endif +// #ifndef _LINUX_LIMITS_H +// #define _LINUX_LIMITS_H +// #define NR_OPEN 1024 +// #define NGROUPS_MAX 65536 /* supplemental group IDs are available */ +// #define ARG_MAX 131072 /* bytes of args + environ for exec() */ +// #define LINK_MAX 127 /* # links a file may have */ +// #define MAX_CANON 255 /* size of the canonical input queue */ +// #define MAX_INPUT 255 /* size of the type-ahead buffer */ +// #define NAME_MAX 255 /* */ +// #define PATH_MAX 4096 /* */ +// #define PIPE_BUF 4096 /* bytes in atomic write to a pipe */ +// #define XATTR_NAME_MAX 255 /* chars in an extended attribute name */ +// #define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */ +// #define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ +// #define RTSIG_MAX 32 +// #endif #ifndef MAX_PATH #define MAX_PATH 4096 diff --git a/dispatch/native-lib.cpp b/dispatch/native-lib.cpp index aec7bc86b998c72b9a0da5b34c129b1b470d3fd2..31845f7b107afd89db31ea9dcdd0e0daec1c1947 100644 --- a/dispatch/native-lib.cpp +++ b/dispatch/native-lib.cpp @@ -7,17 +7,17 @@ CLoadContainer* pConatainer; jstring str2jstring(JNIEnv* env, const char* pat) { - //瀹氫箟java String绫 strClass + // 瀹氫箟java String绫 strClass jclass strClass = (env)->FindClass("Ljava/lang/String;"); - //鑾峰彇String(byte[],String)鐨勬瀯閫犲櫒,鐢ㄤ簬灏嗘湰鍦癰yte[]鏁扮粍杞崲涓轰竴涓柊String + // 鑾峰彇String(byte[],String)鐨勬瀯閫犲櫒,鐢ㄤ簬灏嗘湰鍦癰yte[]鏁扮粍杞崲涓轰竴涓柊String jmethodID ctorID = (env)->GetMethodID(strClass, "", "([BLjava/lang/String;)V"); - //寤虹珛byte鏁扮粍 + // 寤虹珛byte鏁扮粍 jbyteArray bytes = (env)->NewByteArray(strlen(pat)); - //灏哻har* 杞崲涓篵yte鏁扮粍 + // 灏哻har* 杞崲涓篵yte鏁扮粍 (env)->SetByteArrayRegion(bytes, 0, strlen(pat), (jbyte*)pat); // 璁剧疆String, 淇濆瓨璇█绫诲瀷,鐢ㄤ簬byte鏁扮粍杞崲鑷砈tring鏃剁殑鍙傛暟 jstring encoding = (env)->NewStringUTF("GB2312"); - //灏哹yte鏁扮粍杞崲涓簀ava String,骞惰緭鍑 + // 灏哹yte鏁扮粍杞崲涓簀ava String,骞惰緭鍑 return (jstring)(env)->NewObject(strClass, ctorID, bytes, encoding); } @@ -93,8 +93,7 @@ JNIEXPORT jstring JNICALL Java_app_AppDispatch_RecvMessage(JNIEnv* env, jclass o * Method: InitEnv * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; */ -JNIEXPORT jstring JNICALL - Java_app_AppDispatch_InitEnv(JNIEnv* env, jclass obj, jstring key, jstring value, jint type, jint exit) +JNIEXPORT jstring JNICALL Java_app_AppDispatch_InitEnv(JNIEnv* env, jclass obj, jstring key, jstring value, jint type, jint exit) { std::string result = "ok"; diff --git a/extensions/include/comutiliy/asynio.h b/extensions/include/comutiliy/asynio.h deleted file mode 100644 index 0ab789e93456f68040744296b03b4a5d2dd17967..0000000000000000000000000000000000000000 --- a/extensions/include/comutiliy/asynio.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _COMUTILIY_ASYNIO_H_ -#define _COMUTILIY_ASYNIO_H_ - -#include -#include -#include -#include -#include -#include -#include -#include - -typedef _lComPtr AsynFramePtr; -typedef const _lComPtr& AsynFrameConstPtr; - -typedef _lComPtr TcpListenPtr; -typedef const _lComPtr& TcpListenConstPtr; - -typedef _lComPtr AcceptListenPtr; -typedef const _lComPtr& AcceptListenConstPtr; - -typedef _lComPtr TcpSocketPtr; -typedef const _lComPtr& TcpSocketConstPtr; - -typedef _lComPtr TcpSocketSSLPtr; -typedef const _lComPtr& TcpSocketSSLConstPtr; - -typedef _lComPtr UdpSocketPtr; -typedef const _lComPtr& UdpSocketConstPtr; - -typedef _lComPtr OperationPtr; -typedef const _lComPtr& OperationConstPtr; - -typedef _lComPtr OperationEventPtr; -typedef const _lComPtr OperationEventConstPtr; - -typedef _lComPtr TimerPtr; -typedef const _lComPtr& TimerConstPtr; - -typedef _lComPtr TimerEventPtr; -typedef const _lComPtr& TimerEventConstPtr; - -typedef _lComPtr FilePtr; -typedef const _lComPtr& FileConstPtr; - -typedef _lComPtr PipePtr; -typedef const _lComPtr& PipeConstPtr; - -typedef _lComPtr SPipePtr; -typedef const _lComPtr& SPipeConstPtr; - -#endif diff --git a/extensions/include/comutiliy/msg.h b/extensions/include/comutiliy/msg.h deleted file mode 100644 index 5d6ac9fc270603d59db04dc51a45575af20ee515..0000000000000000000000000000000000000000 --- a/extensions/include/comutiliy/msg.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _COMUTILIY_MSG_H_ -#define _COMUTILIY_MSG_H_ - -#include -#include - -typedef _lComPtr MsgBusPtr; -typedef const _lComPtr MsgBusConstPtr; - -typedef _lComPtr BrokerPtr; -typedef const _lComPtr BrokerConstPtr; - -typedef _lComPtr ConsumerPtr; -typedef const _lComPtr ConsumerConstPtr; - -typedef _lComPtr ProducerPtr; -typedef const _lComPtr ProducerConstPtr; - -typedef _lComPtr AgentPtr; -typedef const _lComPtr AgentConstPtr; - -#endif diff --git a/extensions/include/comutiliy/net.h b/extensions/include/comutiliy/net.h deleted file mode 100644 index f95f8451cb5a7c1262b1c7d1de9a4d93f5709ad7..0000000000000000000000000000000000000000 --- a/extensions/include/comutiliy/net.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _COMUTILIY_NET_H_ -#define _COMUTILIY_NET_H_ - -#include - -#include -#include -#include - -typedef _lComPtr NetPtr; -typedef const _lComPtr& NetConstPtr; - -typedef _lComPtr DnsPtr; -typedef const _lComPtr& DnsConstPtr; -typedef _lComPtr DnsHandlePtr; - -typedef _lComPtr HttpInstancePtr; -typedef const _lComPtr& HttpInstanceConstPtr; -typedef _lComPtr HttpInstanceHandlePtr; - -typedef _lComPtr HttpApplicationPtr; -typedef const _lComPtr& HttpApplicationConstPtr; -typedef _lComPtr HttpApplicationHandlePtr; - -#endif diff --git a/extensions/include/comutiliy/schannel.hpp b/extensions/include/comutiliy/schannel.hpp deleted file mode 100644 index 7536587ac6d8254ef7e825e75093759267b3d870..0000000000000000000000000000000000000000 --- a/extensions/include/comutiliy/schannel.hpp +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef _COMUTILIY_SCHANNEL_HPP_ -#define _COMUTILIY_SCHANNEL_HPP_ - -#include - -#define SCHANENEL_BIND_ADDR_MAXLEN 250 - -class SChannel -{ -public: - SChannel(void) { } - virtual ~SChannel(void) { } - - HRESULT CreateSChannel(IBase* pRot) - { - HRESULT hr = S_OK; - rc_assert(pRot != NULL, E_FAIL); - - hr = pRot->QueryInterface(IID_IRot, (void**)&m_pRot); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pRot->GetObject(CLSID_CAsynFrame, IID_IAsynFrame, (IBase**)&m_pIAsynFrame); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pIAsynFrame->CreateIo(io_tcplisten_socket, (IBase**)&m_pIListen); - rc_assert(hr == S_OK, E_FAIL); - - return S_OK; - } - HRESULT OpenCChannel() - { - HRESULT hr = S_OK; - - hr = m_pIListen->CreateSock(); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pIListen->OpenIo(); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pIListen->BindIo(); - rc_assert(hr == S_OK, E_FAIL); - - return hr; - } - HRESULT BindEvent(IBase* pBase) { return m_pIListen->BindAccept(pBase); } - HRESULT UnBindEvent() { return m_pIListen->UnBindAccpet(); } - HRESULT ListenChannel(LPCSTR addr, int len) - { - rc_assert(addr != NULL, E_FAIL); - rc_assert(len != 0, E_FAIL); - - HRESULT hr = S_OK; - - CharArrayPtr item; - item.dispose(); - item = ALLOC_NEW char[SCHANENEL_BIND_ADDR_MAXLEN + 1](); - rc_assert(item.m_p != NULL, E_FAIL); - s_strcpy(item, SCHANENEL_BIND_ADDR_MAXLEN, addr); - - char* port = NULL; - char* ip = NULL; - - ip = s_strtok(item, ":", &port); - rc_assert(ip != NULL, E_FAIL); - rc_assert(port != NULL, E_FAIL); - - hr = m_pIListen->Listen(ip, atoi(port)); - rc_assert(hr == S_OK, E_FAIL); - - return hr; - } - HRESULT AcceptCChannel() - { - HRESULT hr = S_OK; - _lComPtr pSocket; - - hr = m_pIAsynFrame->CreateIo(io_tcp_socket, (IBase**)&pSocket); - rc_assert(hr == S_OK, E_FAIL); - - hr = pSocket->OpenIo(); - rc_assert(hr == S_OK, E_FAIL); - - pSocket->AddRef(); // + 1 - - rc_assert(m_pIListen.m_p != NULL, E_FAIL); - - hr = m_pIListen->Accept(pSocket); - rc_assert(hr == S_OK, E_FAIL); - - return S_OK; - } - HRESULT CloseChannel() - { - HRESULT hr = S_OK; - - hr = m_pIListen->CloseIo(CLOSE_BOTH_IO); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pIListen->CloseSock(); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pIListen->UnBindAccpet(); - rc_assert(hr == S_OK, E_FAIL); - - m_pIListen.dispose(); - - m_pIAsynFrame.dispose(); - - m_pRot.dispose(); - - return S_OK; - } - HRESULT IsListenChannel() { return m_pIListen->IsOpen(); } - - HRESULT GetObject(IBase* pIBase, TcpSocketPtr& pSocket, OperationPtr& pOperation) - { - HRESULT hr = S_OK; - - hr = pIBase->QueryInterface(IID_IOperation, (void**)&pOperation); - rc_assert(hr == S_OK, E_FAIL); - - hr = pOperation->QueryIBaseIID(IID_ITcpSocket, (void**)&pSocket); - rc_assert(hr == S_OK, E_FAIL); - - return hr; - } - - HRESULT Send(const TcpSocketPtr& pSocket, const OperationPtr& pOperation, unsigned int len, evid eventid) - { - HRESULT hr = S_OK; - - hr = pOperation->SetExpect(len); - rc_assert(hr == S_OK, E_FAIL); - - return hr; - } - - HRESULT Recv(const TcpSocketPtr& pSocket, const OperationPtr& pOperation, unsigned int len, evid eventid) - { - HRESULT hr = S_OK; - - hr = pOperation->SetExpect(len); - rc_assert(hr == S_OK, E_FAIL); - - return hr; - } - -protected: - _lComPtr m_pRot; - AsynFramePtr m_pIAsynFrame; - TcpListenPtr m_pIListen; -}; - -#endif diff --git a/extensions/include/comutiliy/serialize.hpp b/extensions/include/comutiliy/serialize.hpp deleted file mode 100644 index 040477189f140e7bb46549f8b8a3421affbff41f..0000000000000000000000000000000000000000 --- a/extensions/include/comutiliy/serialize.hpp +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef _COMUTILIY_SERIALIZE_HPP_ -#define _COMUTILIY_SERIALIZE_HPP_ - -#include - -#define UCHAR_SIZE sizeof(unsigned char) -#define USHORT_SIZE sizeof(unsigned short) -#define UINT_SIZE sizeof(unsigned int) - -class Serialize -{ -public: - Serialize() - { - m_nBufSize = 0; - m_nDataSize = 0; - } - virtual ~Serialize(void) { m_pBuf.dispose(); } - -public: - std_method_type_impl(unsigned char*) Buffer(unsigned int bOffset) { return m_pBuf.m_p + bOffset; } - std_method_impl SetSize(unsigned int nSize) - { - HRESULT hr = S_OK; - rc_assert((m_nBufSize == 0 && m_pBuf == NULL), S_OK); - m_pBuf = ALLOC_NEW unsigned char[nSize + 1](); - rc_assert(m_pBuf.m_p != NULL, E_OUTOFMEMORY); - m_nBufSize = nSize; - return hr; - } - std_method_type_impl(unsigned int) GetSize() const { return m_nBufSize; } - std_method_type_impl(unsigned int) GetDataSize() const { return m_nDataSize; } - std_method_impl Attach(unsigned char* pBuf, unsigned int nSize) - { - rc_assert(pBuf, E_INVALIDARG); - - HRESULT hr = S_OK; - hr = Detach(); - rc_assert(hr == S_OK, E_FAIL); - - hr = SetSize(nSize); - rc_assert(hr == S_OK, E_FAIL); - - s_memcpy(m_pBuf, pBuf, nSize); - - return S_OK; - } - std_method_impl Detach() - { - m_pBuf.dispose(); - m_pBuf = NULL; - m_nBufSize = 0; - m_nDataSize = 0; - return S_OK; - } - -public: - std_method_impl PutUByte(unsigned char nVal) - { - rc_assert((UCHAR_SIZE + m_nDataSize) < m_nBufSize, E_FAIL); - Encode(m_pBuf + m_nDataSize, nVal); - m_nDataSize += UCHAR_SIZE; - return S_OK; - } - std_method_impl PutUShort(unsigned short nVal) - { - rc_assert((USHORT_SIZE + m_nDataSize) < m_nBufSize, E_FAIL); - Encode(m_pBuf + m_nDataSize, nVal); - m_nDataSize += USHORT_SIZE; - return S_OK; - } - std_method_impl PutUInt(unsigned int nVal) - { - rc_assert((UINT_SIZE + m_nDataSize) < m_nBufSize, E_FAIL); - Encode(m_pBuf + m_nDataSize, nVal); - m_nDataSize += UINT_SIZE; - return S_OK; - } - std_method_impl PutBytes(const unsigned char* pBytes, unsigned int nSize) - { - rc_assert(pBytes, E_INVALIDARG); - rc_assert((nSize + m_nDataSize) < m_nBufSize, E_FAIL); - s_memcpy(m_pBuf + m_nDataSize, pBytes, nSize); - m_nDataSize += nSize; - return S_OK; - } - std_method_impl GetUByte(unsigned char& nVal, unsigned int offset) - { - nVal = m_pBuf[offset++]; - return S_OK; - } - std_method_impl GetUShort(unsigned short& nVal, unsigned int offset) - { - unsigned short hi = (unsigned char)m_pBuf[offset++]; - hi = hi << 8; - hi |= (unsigned char)m_pBuf[offset++]; - nVal = hi; - return S_OK; - } - std_method_impl GetUInt(unsigned int& nVal, unsigned int offset) - { - unsigned int a = (unsigned char)m_pBuf[offset++]; - unsigned int b = (unsigned char)m_pBuf[offset++]; - unsigned int c = (unsigned char)m_pBuf[offset++]; - unsigned int d = (unsigned char)m_pBuf[offset++]; - a = a << 24; - a |= b << 16; - a |= c << 8; - a |= d; - nVal = a; - return S_OK; - } - std_method_impl GetBytes(unsigned char* pBytes, unsigned int nSize, unsigned int offset) - { - ::memcpy(pBytes, m_pBuf + offset, nSize); - return S_OK; - } - -private: - size_t Encode(unsigned char* data, unsigned char i) - { - *data = i; - return UCHAR_SIZE; - } - size_t Encode(unsigned char* data, unsigned short i) - { - unsigned short b = i; - size_t nOffset(0); - data[nOffset++] = (unsigned char)(0xFF & (b >> 8)); - data[nOffset++] = (unsigned char)(0xFF & (b)); - return USHORT_SIZE; - } - size_t Encode(unsigned char* data, unsigned int i) - { - unsigned int b = i; - size_t nOffset(0); - data[nOffset++] = (unsigned char)(0xFF & (b >> 24)); - data[nOffset++] = (unsigned char)(0xFF & (b >> 16)); - data[nOffset++] = (unsigned char)(0xFF & (b >> 8)); - data[nOffset++] = (unsigned char)(0xFF & (b)); - return UINT_SIZE; - } - -private: - UCharArrayPtr m_pBuf; - unsigned int m_nBufSize; - mutable unsigned int m_nDataSize; -}; - -#endif diff --git a/extensions/include/db/idatabase.h b/extensions/include/db/idatabase.h index 5f7a1c4d824dda8bebeb1108f687e2ddcdd632f5..57b2b65ee56abcb9a132937f34129cc2f6429ec8 100644 --- a/extensions/include/db/idatabase.h +++ b/extensions/include/db/idatabase.h @@ -52,8 +52,7 @@ typedef enum eFIELD_TYPE { static_inline int sqlite_string_to_type(const char* strTypeName) { - if (string_stricmp("INT", strTypeName) == 0 || string_stricmp("INT2", strTypeName) == 0 - || string_stricmp("INT8", strTypeName) == 0) { + if (string_stricmp("INT", strTypeName) == 0 || string_stricmp("INT2", strTypeName) == 0 || string_stricmp("INT8", strTypeName) == 0) { return FT_INT; } else if (string_stricmp("TINYINT", strTypeName) == 0) { return FT_TINYINT; @@ -65,9 +64,7 @@ static_inline int sqlite_string_to_type(const char* strTypeName) return FT_INTEGER; } else if (string_stricmp("BIGINT", strTypeName) == 0) { return FT_BIGINT; - } else if ( - strstr(strTypeName, "CHAR") != NULL || string_stricmp("TEXT", strTypeName) == 0 - || string_stricmp("CLOB", strTypeName) == 0) { + } else if (strstr(strTypeName, "CHAR") != NULL || string_stricmp("TEXT", strTypeName) == 0 || string_stricmp("CLOB", strTypeName) == 0) { return FT_TEXT; } else if (string_stricmp("BLOB", strTypeName) == 0) { return FT_BLOB; diff --git a/extensions/include/io/ifile.h b/extensions/include/io/ifile.h deleted file mode 100644 index bf21e05a2f0a5eab6aca727a74af58bf8ad84936..0000000000000000000000000000000000000000 --- a/extensions/include/io/ifile.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _IFILE_H_ -#define _IFILE_H_ - -interface IFile : public IBase -{ - std_method(LoadFile)( - const basic_tchar* pszLoadFile, - unsigned long ulwDesiredAccess, - unsigned long ulShareMode, - unsigned long ulCreationDisposition, - unsigned long ulFlagsAndAttributes) PURE; - std_method(CloseFile)() PURE; - std_method_(int64, GetFileSize)() PURE; - std_method(ReadBuffer)(char* szBuffer, int64 ulReadFileLen, int64* ulReadSize) PURE; - std_method(WriteBuffer)(char* szBuffer, int64 ulWriteSize) PURE; -}; - -// {978D055C-CF46-44C4-BE6C-E537C0E698C5} -_DEF_IID(IID_IFile, 0x978d055c, 0xcf46, 0x44c4, 0xbe, 0x6c, 0xe5, 0x37, 0xc0, 0xe6, 0x98, 0xc5); - -#endif diff --git a/extensions/include/io/ioperation.h b/extensions/include/io/ioperation.h index 6fd4aa7044e516a8ada0666004970885ea56f7e6..09614c96829b8615c477ff53f7b8f4ebd508e123 100644 --- a/extensions/include/io/ioperation.h +++ b/extensions/include/io/ioperation.h @@ -10,13 +10,13 @@ #define OP_EXCEPTION 0x100 #define OP_EOF 0x200 -interface IOperationEvent : public IBase +interface IOperationProc : public IBase { std_method(OnComplete)(IBase* pOperation, evid event, everr error_code) PURE; }; // {0470327E-5ACF-40EC-BAED-FE2AAE877B4B} -_DEF_IID(IID_IOperationEvent, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); +_DEF_IID(IID_IOperationProc, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); interface IOperation : public IBase { @@ -25,8 +25,8 @@ interface IOperation : public IBase std_method(QueryIBaseIID)(REFIID riid, void** ppv) PURE; std_method(BindEvent)(IBase* pEvents) PURE; std_method(UnBindEvent)() PURE; - std_method(SetId)(ULONG uId) PURE; - std_method_(ULONG, GetId)() PURE; + std_method(SetId)(evid uId) PURE; + std_method_(evid, GetId)() PURE; std_method(SetResult)(everr Error, BUF_SIZE uTransferedBytes) PURE; std_method(GetResult)(everr* Error, BUF_SIZE* pTransferedBytes) PURE; std_method(SetIoParam)(BUF_SIZE uStartPos, BUF_SIZE uExpectBytes) PURE; diff --git a/extensions/include/io/isocket.h b/extensions/include/io/isocket.h index 50ef5bec3004325b227cfcb464015796a912b9f7..05248206ec855f934b5782fc0b9700d584896ebe 100644 --- a/extensions/include/io/isocket.h +++ b/extensions/include/io/isocket.h @@ -1,49 +1,27 @@ #ifndef _ISOCKET_H_ #define _ISOCKET_H_ -interface ISocketEvent : public IBase +interface ISockProc : public IBase { - std_method(OnSend)(IBase* pSocket, evid event, everr error_code, BUF_PTR buf, BUF_SIZE size) PURE; - std_method(OnRecv)(IBase* pSocket, evid event, everr error_code, BUF_PTR buf, BUF_SIZE size) PURE; - std_method(OnConnect)(IBase* pSocket, evid event, everr error_code) PURE; + std_method(OnSockSend)(evid id, everr error_code, BUF_PTR buf, BUF_SIZE size) PURE; + std_method(OnSockRecv)(evid id, everr error_code, BUF_PTR buf, BUF_SIZE size) PURE; + std_method(OnSockConnect)(evid id, everr error_code, _sock_t fd) PURE; + std_method(OnSockEvent)(evid id, evid event, everr error_code, _sock_t fd) PURE; }; // {9C926805-64F5-4728-86A4-AB0208AA1487} -_DEF_IID(IID_ISocketEvent, 0x9c926805, 0x64f5, 0x4728, 0x86, 0xa4, 0xab, 0x2, 0x8, 0xaa, 0x14, 0x87); - -#define SOL_REUSEDDR "reuseddr" -#define SOL_NODELAY "nodelay" -#define SOL_LINGER "linger" -#define SOL_KEEPLIVE "keepalive" -#define SOL_CORK "cork" -#define SOL_NOSIGPIPE "nosigpipe" -#define SOL_SENDLEN "sendbuflen" -#define SOL_RECVLEN "recvbuflen" -#define SOL_SENDTM "sendtime" -#define SOL_RECVTM "recvtime" -#define SOL_CONTM "contimeout" -#define SOL_SENDLOWAT "sendlowat" -#define SOL_RECVLOWAT "recvlowat" -#define SOL_ONLY_READ "only_read" -#define SOL_ONLY_WRITE "only_write" +_DEF_IID(IID_ISockProc, 0x9c926805, 0x64f5, 0x4728, 0x86, 0xa4, 0xab, 0x2, 0x8, 0xaa, 0x14, 0x87); interface ISocket : public IIoDevice { + std_method(BindEvent)(IBase* pSocketEvent) PURE; + std_method(UnBindEvent)() PURE; std_method(CreateSock)() PURE; std_method(CloseSock)() PURE; std_method(IsOpen)() PURE; std_method(AttachSock)(_sock_t sock) PURE; std_method_(_sock_t, DetachSock)() PURE; - std_method(SetOption)(LPCSTR opt, int val) PURE; - std_method(GetOption)(LPCSTR opt, int* val) PURE; - std_method(ReadOperationSize)(int size) PURE; - std_method(WriteOperationSize)(int size) PURE; - std_method(ReadStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) PURE; - std_method(WriteStream)(BUF_PTR ptr, BUF_SIZE pos, BUF_SIZE size) PURE; - std_method(GetReadPtr)(BUF_PTR* ptr) PURE; - std_method(GetWritePtr)(BUF_PTR* ptr) PURE; - std_method(GetReadPtrSize)(BUF_SIZE* size) PURE; - std_method(GetWritePtrSize)(BUF_SIZE* size) PURE; + std_method_(_sock_t, GetSock)() PURE; std_method(GetReadOperation)(IID id, IBase** pBase) PURE; std_method(GetWriteOperation)(IID id, IBase** pBase) PURE; }; @@ -62,12 +40,9 @@ _DEF_IID(IID_IWriteOperation, 0x9e97f4a9, 0x2423, 0x4e14, 0xb9, 0x82, 0xff, 0x45 interface ITcpSocket : public ISocket { - std_method_(BUF_SIZE, SyncSend)(BUF_PTR buf, BUF_SIZE size) PURE; - std_method_(BUF_SIZE, SyncRecv)(BUF_PTR buf, BUF_SIZE size) PURE; - std_method(SyncConnect)(NET_ADDR addr, NET_PORT port) PURE; - std_method(ReadIo)(ULONG pos, ULONG size, evid event) PURE; - std_method(WriteIo)(ULONG pos, ULONG size, evid event) PURE; - std_method(ConnectIo)(NET_ADDR addr, NET_PORT port, evid event) PURE; + std_method(ReadIo)(ULONG pos, ULONG size, evid event, int tm) PURE; + std_method(WriteIo)(ULONG pos, ULONG size, evid event, int tm) PURE; + std_method(ConnectIo)(NET_ADDR addr, NET_PORT port, evid event, int tm) PURE; }; // {37ACA045-F4F5-4481-93F9-B260EA1A1305} @@ -112,8 +87,6 @@ _DEF_IID(IID_ITcpSocketSSL, 0x861bbc5d, 0xa0cc, 0x496f, 0x9e, 0x54, 0x3f, 0x97, interface IUdpSocket : public ISocket { - std_method_(BUF_SIZE, SyncSend)(NET_ADDR addr, NET_PORT port, BUF_PTR buf, BUF_SIZE size) PURE; - std_method_(BUF_SIZE, SyncRecv)(NET_ADDR addr, NET_PORT port, BUF_PTR buf, BUF_SIZE size) PURE; std_method(ReadIo)(NET_ADDR addr, NET_PORT port, IBase* pBase, evid event) PURE; std_method(WriteIo)(NET_ADDR addr, NET_PORT port, IBase* pBase, evid event) PURE; }; @@ -121,11 +94,14 @@ interface IUdpSocket : public ISocket // {7DB4FEA2-E7E2-4C1D-A5D6-751CA0CA07EA} _DEF_IID(IID_IUdpSocket, 0x7db4fea2, 0xe7e2, 0x4c1d, 0xa5, 0xd6, 0x75, 0x1c, 0xa0, 0xca, 0x7, 0xea); -////////////////////////////////////////////////////////////////////////// +#define LISTEN_OPEN 0 +#define LISTEN_CLOSE 1 + interface IListen : public ISocket { std_method(Listen)(NET_ADDR addr, NET_PORT port) PURE; - std_method(Accept)(IBase* pBase) PURE; + std_method(Listen6)(NET_ADDR addr, NET_PORT port) PURE; + std_method(Accept)(int on) PURE; }; // {BB9DA617-80BE-4E04-8EB4-13CF43F1EBD1} @@ -133,7 +109,7 @@ _DEF_IID(IID_IListen, 0xbb9da617, 0x80be, 0x4e04, 0x8e, 0xb4, 0x13, 0xcf, 0x43, interface IAcceptListen : public IBase { - std_method(Accept)(IBase* pBase, _sock_t s, evid error_code) PURE; + std_method(Accept)(_sock_t s, SOCKADDR_PTR sa, socklen_t sl, evid error_code) PURE; }; // {8221E95A-6E9F-4ADF-8F75-811BBC6DFBD0} diff --git a/extensions/include/io/itimer.h b/extensions/include/io/itimer.h index 5927995ee63db9654823c794c8947149dc96e3b6..98e0a1355389c8d1c2f20313a8cc9285de4e6023 100644 --- a/extensions/include/io/itimer.h +++ b/extensions/include/io/itimer.h @@ -1,23 +1,23 @@ #ifndef _ITIMER_H_ #define _ITIMER_H_ -interface ITimerEvent : public IBase +interface ITimerProc : public IBase { std_method(OnTimer)(UINT uId, UINT err) PURE; }; // {B5819C73-6EF7-4F25-B053-F6F6D4DCBE00} -_DEF_IID(IID_ITimerEvent, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); +_DEF_IID(IID_ITimerProc, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); interface ITimer : public IBase { std_method(Start)() PURE; std_method(Stop)() PURE; - std_method(SetSec)(int isec) PURE; + std_method(SetSec)(int sec) PURE; + std_method(Bind)(IBase* pBase) PURE; std_method(UnBind)() PURE; - std_method(Bind)(IBase* pBase) PURE; std_method_(UINT, GetId)() PURE; - std_method(SetId)(UINT uId) PURE; + std_method(SetId)(UINT id) PURE; }; // {F36A3734-C9CA-46C9-8F03-AD02AD24058F} diff --git a/extensions/include/net/idns.h b/extensions/include/net/idns.h index 8aff3fe36c91ca384b07608f056855bd7834780e..36df9c5226f604da8b82b5b21a559ded0fdd8119 100644 --- a/extensions/include/net/idns.h +++ b/extensions/include/net/idns.h @@ -14,7 +14,6 @@ _DEF_IID(IID_IDnsProc, 0x92ebbd6e, 0xbf4d, 0x41ec, 0x9d, 0xfb, 0x7, 0xc9, 0xaf, interface IDns : public IBase { - std_method(Send)(LPCSTR hostname, IBase* pProc) PURE; std_method(Post)(LPCSTR hostname, IBase* pProc) PURE; std_method(Close)() PURE; }; diff --git a/extensions/include/net/ihttp.h b/extensions/include/net/ihttp.h index ac51e284c76a6663d5038f28828a42a8751083aa..41ab388ba736e71e53bb0cc137ae4c4e643ddaf2 100644 --- a/extensions/include/net/ihttp.h +++ b/extensions/include/net/ihttp.h @@ -78,7 +78,7 @@ typedef const char* http_method_name; #define http_host_len 256 -interface IHttpInstanceProc : public IBase +interface IHttpProc : public IBase { std_method(OnHttpAuth)(ULONG event) PURE; std_method(OnHttpNotify)(evid event, everr error) PURE; @@ -91,9 +91,9 @@ interface IHttpInstanceProc : public IBase }; // {8C102441-E383-4B3C-8CC8-7C8E0B0162FE} -_DEF_IID(IID_IHttpInstanceProc, 0x8c102441, 0xe383, 0x4b3c, 0x8c, 0xc8, 0x7c, 0x8e, 0xb, 0x1, 0x62, 0xfe); +_DEF_IID(IID_IHttpProc, 0x8c102441, 0xe383, 0x4b3c, 0x8c, 0xc8, 0x7c, 0x8e, 0xb, 0x1, 0x62, 0xfe); -interface IHttpInstance : public IBase +interface IHttp : public IBase { std_method(BindEvent)(IBase* pBase) PURE; std_method(UnBindEvent)() PURE; @@ -105,21 +105,21 @@ interface IHttpInstance : public IBase }; // {6014F5E1-05A9-476F-898C-8606756A750F} -_DEF_IID(IID_IHttpInstance, 0x6014f5e1, 0x5a9, 0x476f, 0x89, 0x8c, 0x86, 0x6, 0x75, 0x6a, 0x75, 0xf); +_DEF_IID(IID_IHttp, 0x6014f5e1, 0x5a9, 0x476f, 0x89, 0x8c, 0x86, 0x6, 0x75, 0x6a, 0x75, 0xf); -interface IHttpApplicationProc : public IBase +interface IHttpWebProc : public IBase { std_method(OnAccept)(int error, LPCSTR hostname, LPCSTR host) PURE; }; // {23C86623-C039-416B-A489-C175C360E692} -_DEF_IID(IID_IHttpApplicationProc, 0x23c86623, 0xc039, 0x416b, 0xa4, 0x89, 0xc1, 0x75, 0xc3, 0x60, 0xe6, 0x92); +_DEF_IID(IID_IHttpWebProc, 0x23c86623, 0xc039, 0x416b, 0xa4, 0x89, 0xc1, 0x75, 0xc3, 0x60, 0xe6, 0x92); -interface IHttpApplication : public IBase +interface IHttpWeb : public IBase { }; // {75BD9CAF-2D0D-4408-B481-655F30F8613F} -_DEF_IID(IID_IHttpApplication, 0x75bd9caf, 0x2d0d, 0x4408, 0xb4, 0x81, 0x65, 0x5f, 0x30, 0xf8, 0x61, 0x3f); +_DEF_IID(IID_IHttpWeb, 0x75bd9caf, 0x2d0d, 0x4408, 0xb4, 0x81, 0x65, 0x5f, 0x30, 0xf8, 0x61, 0x3f); #endif diff --git a/extensions/include/runtime/ichannel.h b/extensions/include/runtime/ichannel.h index 955b7729c7e128c8b96ade2fc3e78f2e13405642..ce333bc77b74a025494e9bf937611af423ecaf20 100644 --- a/extensions/include/runtime/ichannel.h +++ b/extensions/include/runtime/ichannel.h @@ -1,8 +1,8 @@ #ifndef _ICHANNEL_H_ #define _ICHANNEL_H_ -#define channel_status_open 1000 -#define channel_status_close 2000 +#define channel_status_open 1000 +#define channel_status_close 2000 #define channel_send_complete 3000 #define channel_recv_complete 4000 @@ -38,7 +38,4 @@ _DEF_CLSID(IID_IChannelFrame, 0xD9E081AF, 0x6FA6, 0x4445, 0x9F, 0x44, 0x37, 0x11 //{46a65a7f-0e1c-4109-a319-a84be1def7f4} _DEF_CLSID(CLSID_CChannelFrame, 0x46A65A7F, 0x0E1C, 0x4109, 0xA3, 0x19, 0xA8, 0x4B, 0xE1, 0xDE, 0xF7, 0xF4); - - #endif - diff --git a/extensions/include/runtime/ipolicy.h b/extensions/include/runtime/ipolicy.h index 11922d52ea47f7823a855d869231c9401af6bf7b..a14d82074fccc27dab5b82824893779c2fa6eb27 100644 --- a/extensions/include/runtime/ipolicy.h +++ b/extensions/include/runtime/ipolicy.h @@ -1,7 +1,7 @@ #ifndef _IPOLICY_H_ #define _IPOLICY_H_ -#define policy_status 1000 +#define policy_status 1000 #define policy_status_start policy_status + 1 #define policy_status_stop policy_status + 2 @@ -29,5 +29,4 @@ _DEF_IID(IID_IPolicy, 0x736B6E66, 0x93BE, 0x478B, 0xBE, 0xD4, 0xE1, 0x1F, 0xCD, //{515b19ad-f72e-4baf-979f-d4f6310c15a6} _DEF_CLSID(CLSID_CPolicy, 0x515B19AD, 0xF72E, 0x4BAF, 0x97, 0x9F, 0xD4, 0xF6, 0x31, 0x0C, 0x15, 0xA6); - #endif diff --git a/extensions/include/ui/uidefine.h b/extensions/include/ui/uidefine.h index 90c32a26358987971eb009c8bf8c453198041c3a..14a34894bd337e3193412f25ef089287e4a833f6 100644 --- a/extensions/include/ui/uidefine.h +++ b/extensions/include/ui/uidefine.h @@ -3,68 +3,68 @@ #include -//#define DUI_MSGTYPE_MENU 0x40000000 -//#define DUI_MSGTYPE_LINK 0x40000001 -//#define DUI_MSGTYPE_TIMER 0x40000002 -//#define DUI_MSGTYPE_CLICK 0x40000003 -//#define DUI_MSGTYPE_RETURN 0x40000004 -//#define DUI_MSGTYPE_SCROLL 0x40000005 -//#define DUI_MSGTYPE_DROPDOWN 0x40000006 -//#define DUI_MSGTYPE_SETFOCUS 0x40000007 -//#define DUI_MSGTYPE_KILLFOCUS 0x40000008 -//#define DUI_MSGTYPE_ITEMCLICK 0x40000009 -//#define DUI_MSGTYPE_TABSELECT 0x4000000A -//#define DUI_MSGTYPE_ITEMSELECT 0x4000000B -//#define DUI_MSGTYPE_ITEMEXPAND 0x4000000C -//#define DUI_MSGTYPE_WINDOWINIT 0x4000000D -//#define DUI_MSGTYPE_BUTTONDOWN 0x4000000E -//#define DUI_MSGTYPE_MOUSEENTER 0x4000000F -//#define DUI_MSGTYPE_MOUSELEAVE 0x40000010 -//#define DUI_MSGTYPE_TEXTCHANGED 0x40000011 -//#define DUI_MSGTYPE_HEADERCLICK 0x40000012 -//#define DUI_MSGTYPE_ITEMDBCLICK 0x40000013 -//#define DUI_MSGTYPE_SHOWACTIVEX 0x40000014 -//#define DUI_MSGTYPE_ITEMCOLLAPSE 0x40000015 -//#define DUI_MSGTYPE_ITEMACTIVATE 0x40000016 -//#define DUI_MSGTYPE_VALUECHANGED 0x40000017 -//#define DUI_MSGTYPE_SELECTCHANGED 0x40000018 -//#define DUI_MSGTYPE_INVALID 0x4fffffff +// #define DUI_MSGTYPE_MENU 0x40000000 +// #define DUI_MSGTYPE_LINK 0x40000001 +// #define DUI_MSGTYPE_TIMER 0x40000002 +// #define DUI_MSGTYPE_CLICK 0x40000003 +// #define DUI_MSGTYPE_RETURN 0x40000004 +// #define DUI_MSGTYPE_SCROLL 0x40000005 +// #define DUI_MSGTYPE_DROPDOWN 0x40000006 +// #define DUI_MSGTYPE_SETFOCUS 0x40000007 +// #define DUI_MSGTYPE_KILLFOCUS 0x40000008 +// #define DUI_MSGTYPE_ITEMCLICK 0x40000009 +// #define DUI_MSGTYPE_TABSELECT 0x4000000A +// #define DUI_MSGTYPE_ITEMSELECT 0x4000000B +// #define DUI_MSGTYPE_ITEMEXPAND 0x4000000C +// #define DUI_MSGTYPE_WINDOWINIT 0x4000000D +// #define DUI_MSGTYPE_BUTTONDOWN 0x4000000E +// #define DUI_MSGTYPE_MOUSEENTER 0x4000000F +// #define DUI_MSGTYPE_MOUSELEAVE 0x40000010 +// #define DUI_MSGTYPE_TEXTCHANGED 0x40000011 +// #define DUI_MSGTYPE_HEADERCLICK 0x40000012 +// #define DUI_MSGTYPE_ITEMDBCLICK 0x40000013 +// #define DUI_MSGTYPE_SHOWACTIVEX 0x40000014 +// #define DUI_MSGTYPE_ITEMCOLLAPSE 0x40000015 +// #define DUI_MSGTYPE_ITEMACTIVATE 0x40000016 +// #define DUI_MSGTYPE_VALUECHANGED 0x40000017 +// #define DUI_MSGTYPE_SELECTCHANGED 0x40000018 +// #define DUI_MSGTYPE_INVALID 0x4fffffff // // -//#define DUI_CTR_GIF "Gif" -//#define DUI_CTR_EDIT "Edit" -//#define DUI_CTR_LIST "List" -//#define DUI_CTR_TEXT "Text" -//#define DUI_CTR_COMBO "Combo" -//#define DUI_CTR_LABEL "Label" -//#define DUI_CTR_FLASH "Flash" -//#define DUI_CTR_BUTTON "Button" -//#define DUI_CTR_OPTION "Option" -//#define DUI_CTR_SLIDER "Slider" -//#define DUI_CTR_CONTROL "Control" -//#define DUI_CTR_ACTIVEX "ActiveX" -//#define DUI_CTR_LISTITEM "ListItem" -//#define DUI_CTR_PROGRESS "Progress" -//#define DUI_CTR_RICHEDIT "RichEdit" -//#define DUI_CTR_CHECKBOX "CheckBox" -//#define DUI_CTR_COMBOBOX "ComboBox" -//#define DUI_CTR_DATETIME "DateTime" -//#define DUI_CTR_TREEVIEW "TreeView" -//#define DUI_CTR_TREENODE "TreeNode" -//#define DUI_CTR_CONTAINER "Container" -//#define DUI_CTR_TABLAYOUT "TabLayout" -//#define DUI_CTR_SCROLLBAR "ScrollBar" -//#define DUI_CTR_LISTHEADER "ListHeader" -//#define DUI_CTR_TILELAYOUT "TileLayout" -//#define DUI_CTR_WEBBROWSER "WebBrowser" -//#define DUI_CTR_CHILDLAYOUT "ChildLayout" -//#define DUI_CTR_LISTELEMENT "ListElement" -//#define DUI_CTR_DIALOGLAYOUT "DialogLayout" -//#define DUI_CTR_VERTICALLAYOUT "VerticalLayout" -//#define DUI_CTR_LISTHEADERITEM "ListHeaderItem" -//#define DUI_CTR_LISTTEXTELEMENT "ListTextElement" -//#define DUI_CTR_HORIZONTALLAYOUT "HorizontalLayout" -//#define DUI_CTR_LISTLABELELEMENT "ListLabelElement" -//#define DUI_CTR_LISTCONTAINERELEMENT "ListContainerElement" +// #define DUI_CTR_GIF "Gif" +// #define DUI_CTR_EDIT "Edit" +// #define DUI_CTR_LIST "List" +// #define DUI_CTR_TEXT "Text" +// #define DUI_CTR_COMBO "Combo" +// #define DUI_CTR_LABEL "Label" +// #define DUI_CTR_FLASH "Flash" +// #define DUI_CTR_BUTTON "Button" +// #define DUI_CTR_OPTION "Option" +// #define DUI_CTR_SLIDER "Slider" +// #define DUI_CTR_CONTROL "Control" +// #define DUI_CTR_ACTIVEX "ActiveX" +// #define DUI_CTR_LISTITEM "ListItem" +// #define DUI_CTR_PROGRESS "Progress" +// #define DUI_CTR_RICHEDIT "RichEdit" +// #define DUI_CTR_CHECKBOX "CheckBox" +// #define DUI_CTR_COMBOBOX "ComboBox" +// #define DUI_CTR_DATETIME "DateTime" +// #define DUI_CTR_TREEVIEW "TreeView" +// #define DUI_CTR_TREENODE "TreeNode" +// #define DUI_CTR_CONTAINER "Container" +// #define DUI_CTR_TABLAYOUT "TabLayout" +// #define DUI_CTR_SCROLLBAR "ScrollBar" +// #define DUI_CTR_LISTHEADER "ListHeader" +// #define DUI_CTR_TILELAYOUT "TileLayout" +// #define DUI_CTR_WEBBROWSER "WebBrowser" +// #define DUI_CTR_CHILDLAYOUT "ChildLayout" +// #define DUI_CTR_LISTELEMENT "ListElement" +// #define DUI_CTR_DIALOGLAYOUT "DialogLayout" +// #define DUI_CTR_VERTICALLAYOUT "VerticalLayout" +// #define DUI_CTR_LISTHEADERITEM "ListHeaderItem" +// #define DUI_CTR_LISTTEXTELEMENT "ListTextElement" +// #define DUI_CTR_HORIZONTALLAYOUT "HorizontalLayout" +// #define DUI_CTR_LISTLABELELEMENT "ListLabelElement" +// #define DUI_CTR_LISTCONTAINERELEMENT "ListContainerElement" #endif diff --git a/framwork.xcodeproj/project.pbxproj b/framwork.xcodeproj/project.pbxproj index 1b7160f3b4cdab0e4aef2cbfda28a2f51b6c29ea..eedc307f632f75fac88331f5fe0d9f56b3fe3147 100644 --- a/framwork.xcodeproj/project.pbxproj +++ b/framwork.xcodeproj/project.pbxproj @@ -16,10 +16,6 @@ A1021BA6286E02D6003DE34E /* test_sem.c in Sources */ = {isa = PBXBuildFile; fileRef = A1021B9E286E02D6003DE34E /* test_sem.c */; }; A1021BA7286E02D6003DE34E /* test_pipe.c in Sources */ = {isa = PBXBuildFile; fileRef = A1021B9F286E02D6003DE34E /* test_pipe.c */; }; A1021BA9286E03AC003DE34E /* compat_rbtree.c in Sources */ = {isa = PBXBuildFile; fileRef = A1021BA8286E03AC003DE34E /* compat_rbtree.c */; }; - A10773F0282195A20001A1EF /* compat_event.c in Sources */ = {isa = PBXBuildFile; fileRef = A10773EA282195A10001A1EF /* compat_event.c */; }; - A10773F1282195A20001A1EF /* compat_event_iocp.c in Sources */ = {isa = PBXBuildFile; fileRef = A10773EB282195A10001A1EF /* compat_event_iocp.c */; }; - A10773F2282195A20001A1EF /* compat_event_epoll.c in Sources */ = {isa = PBXBuildFile; fileRef = A10773EC282195A10001A1EF /* compat_event_epoll.c */; }; - A10773F5282195A20001A1EF /* compat_event_kqueue.c in Sources */ = {isa = PBXBuildFile; fileRef = A10773EF282195A10001A1EF /* compat_event_kqueue.c */; }; A107E8FC27172470006A8E8E /* net.h in Headers */ = {isa = PBXBuildFile; fileRef = A107E8FA27172470006A8E8E /* net.h */; settings = {ATTRIBUTES = (Public, ); }; }; A107E91B27172492006A8E8E /* netimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A107E90427172491006A8E8E /* netimpl.cpp */; }; A107E91C27172492006A8E8E /* websocketimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A107E90527172491006A8E8E /* websocketimpl.h */; }; @@ -125,8 +121,8 @@ A107EBEF27173DBA006A8E8E /* msgbus.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A107E93B27172BA8006A8E8E /* msgbus.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A107EBF227173DBA006A8E8E /* net.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A107E8F827172470006A8E8E /* net.framework */; }; A107EBF327173DBA006A8E8E /* net.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A107E8F827172470006A8E8E /* net.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + A108551429B7C10600A15324 /* msgbuschannel.hpp in Headers */ = {isa = PBXBuildFile; fileRef = A108551329B7C10600A15324 /* msgbuschannel.hpp */; }; A10B3F572715EBD50003990D /* asynio.h in Headers */ = {isa = PBXBuildFile; fileRef = A10B3F552715EBD50003990D /* asynio.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A10B3F6E2715EC0C0003990D /* fileimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F5B2715EC0B0003990D /* fileimpl.cpp */; }; A10B3F6F2715EC0C0003990D /* interface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F5C2715EC0B0003990D /* interface.cpp */; }; A10B3F702715EC0C0003990D /* stdafx.h in Headers */ = {isa = PBXBuildFile; fileRef = A10B3F5D2715EC0B0003990D /* stdafx.h */; }; A10B3F712715EC0C0003990D /* asynframeimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A10B3F5E2715EC0B0003990D /* asynframeimpl.h */; }; @@ -137,7 +133,6 @@ A10B3F762715EC0C0003990D /* asynio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F632715EC0C0003990D /* asynio.cpp */; }; A10B3F772715EC0C0003990D /* tcplistensocketimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F642715EC0C0003990D /* tcplistensocketimpl.cpp */; }; A10B3F782715EC0C0003990D /* udpsocketimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F652715EC0C0003990D /* udpsocketimpl.cpp */; }; - A10B3F792715EC0C0003990D /* fileimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A10B3F662715EC0C0003990D /* fileimpl.h */; }; A10B3F7A2715EC0C0003990D /* tcpsocketimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F672715EC0C0003990D /* tcpsocketimpl.cpp */; }; A10B3F7B2715EC0C0003990D /* timerimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F682715EC0C0003990D /* timerimpl.cpp */; }; A10B3F7C2715EC0C0003990D /* asynframeimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F692715EC0C0003990D /* asynframeimpl.cpp */; }; @@ -145,6 +140,9 @@ A10B3F7E2715EC0C0003990D /* timerimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A10B3F6B2715EC0C0003990D /* timerimpl.h */; }; A10B3F7F2715EC0C0003990D /* udpsocketimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A10B3F6C2715EC0C0003990D /* udpsocketimpl.h */; }; A10B3F802715EC0C0003990D /* dllmain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A10B3F6D2715EC0C0003990D /* dllmain.cpp */; }; + A110383F29B8D90A00DD9517 /* http.h in Headers */ = {isa = PBXBuildFile; fileRef = A110383D29B8D90A00DD9517 /* http.h */; }; + A110384029B8D90A00DD9517 /* http.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A110383E29B8D90A00DD9517 /* http.cpp */; }; + A1115E3129A3D885002FFA60 /* ioevdef.h in Headers */ = {isa = PBXBuildFile; fileRef = A1115E3029A3D885002FFA60 /* ioevdef.h */; }; A11694772713144500CBA348 /* container.h in Headers */ = {isa = PBXBuildFile; fileRef = A11694752713144500CBA348 /* container.h */; settings = {ATTRIBUTES = (Public, ); }; }; A116948F2713149700CBA348 /* plugins.h in Headers */ = {isa = PBXBuildFile; fileRef = A116947F2713149700CBA348 /* plugins.h */; }; A11694902713149700CBA348 /* msg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A11694802713149700CBA348 /* msg.cpp */; }; @@ -164,7 +162,6 @@ A116949E2713149700CBA348 /* targetver.h in Headers */ = {isa = PBXBuildFile; fileRef = A116948E2713149700CBA348 /* targetver.h */; }; A119CCE7271F0DAA00EF6077 /* appviewimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A119CCE5271F0DAA00EF6077 /* appviewimpl.cpp */; }; A122670927C158A4006D0ACA /* tcpsocketsslimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17A9FFF273AB7750044C30E /* tcpsocketsslimpl.cpp */; }; - A12411F3288065B300D73A63 /* compat_event_util.c in Sources */ = {isa = PBXBuildFile; fileRef = A12411F1288065B300D73A63 /* compat_event_util.c */; }; A126FDE428A015AF00D95D6C /* compat_vsnprintf.c in Sources */ = {isa = PBXBuildFile; fileRef = A126FDE228A015AF00D95D6C /* compat_vsnprintf.c */; }; A126FDE528A015AF00D95D6C /* compat_alloc.c in Sources */ = {isa = PBXBuildFile; fileRef = A126FDE328A015AF00D95D6C /* compat_alloc.c */; }; A126FDE728A015BF00D95D6C /* crt_vsnprintf.h in Headers */ = {isa = PBXBuildFile; fileRef = A126FDE628A015BF00D95D6C /* crt_vsnprintf.h */; }; @@ -186,7 +183,6 @@ A126FE4228A01AEA00D95D6C /* stdcrt.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A144AAFD272572A30019CA5F /* stdcrt.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A126FE4628A01B4D00D95D6C /* runtime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A126FE1F28A01A8100D95D6C /* runtime.framework */; }; A126FE4728A01B4D00D95D6C /* runtime.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A126FE1F28A01A8100D95D6C /* runtime.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - A12720692881D2B0001ECCC8 /* event_mach.c in Sources */ = {isa = PBXBuildFile; fileRef = A12720682881D2B0001ECCC8 /* event_mach.c */; }; A127206B2881D346001ECCC8 /* crt_event_mach.h in Headers */ = {isa = PBXBuildFile; fileRef = A127206A2881D346001ECCC8 /* crt_event_mach.h */; }; A127206D2881D384001ECCC8 /* crt_event_util.h in Headers */ = {isa = PBXBuildFile; fileRef = A127206C2881D384001ECCC8 /* crt_event_util.h */; }; A128C5FB2879C43C009F8396 /* compat_clock.c in Sources */ = {isa = PBXBuildFile; fileRef = A128C5F92879C43C009F8396 /* compat_clock.c */; }; @@ -202,8 +198,159 @@ A139C4E5285A363200416E98 /* spipeimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A139C4E2285A363200416E98 /* spipeimpl.cpp */; }; A139C4E6285A363200416E98 /* tlswrap.h in Headers */ = {isa = PBXBuildFile; fileRef = A139C4E3285A363200416E98 /* tlswrap.h */; }; A139C4E7285A363200416E98 /* spipeimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A139C4E4285A363200416E98 /* spipeimpl.h */; }; - A1447A2A2821A85D00D3DCA4 /* event_posix.c in Sources */ = {isa = PBXBuildFile; fileRef = A1447A272821A85D00D3DCA4 /* event_posix.c */; }; - A1447A2B2821A85D00D3DCA4 /* event_win32.c in Sources */ = {isa = PBXBuildFile; fileRef = A1447A282821A85D00D3DCA4 /* event_win32.c */; }; + A13D08B729A177C900AA7830 /* evconfig.h in Headers */ = {isa = PBXBuildFile; fileRef = A13D08B629A177C900AA7830 /* evconfig.h */; }; + A13D08B929A1783A00AA7830 /* evconfig-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A13D08B829A1783A00AA7830 /* evconfig-internal.h */; }; + A13D08BB29A1846000AA7830 /* thread-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A13D08BA29A1846000AA7830 /* thread-internal.h */; }; + A14337A529A9D2E7007A5959 /* nettls.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337A329A9D2E7007A5959 /* nettls.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A14337A829A9D2E7007A5959 /* nettls.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A14337A129A9D2E7007A5959 /* nettls.framework */; }; + A14337A929A9D2E7007A5959 /* nettls.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A14337A129A9D2E7007A5959 /* nettls.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + A143383D29A9D314007A5959 /* x509_create.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337AE29A9D314007A5959 /* x509_create.c */; }; + A143383E29A9D314007A5959 /* x509_crt.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337AF29A9D314007A5959 /* x509_crt.c */; }; + A143383F29A9D314007A5959 /* aes.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B029A9D314007A5959 /* aes.c */; }; + A143384029A9D314007A5959 /* ssl_srv.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B129A9D314007A5959 /* ssl_srv.c */; }; + A143384129A9D314007A5959 /* camellia.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B229A9D314007A5959 /* camellia.c */; }; + A143384229A9D314007A5959 /* pk_wrap.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B329A9D314007A5959 /* pk_wrap.c */; }; + A143384329A9D314007A5959 /* pk.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B429A9D314007A5959 /* pk.c */; }; + A143384429A9D314007A5959 /* ecdh.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B529A9D314007A5959 /* ecdh.c */; }; + A143384529A9D314007A5959 /* ssl_tls.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B629A9D314007A5959 /* ssl_tls.c */; }; + A143384629A9D314007A5959 /* x509_crl.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B729A9D314007A5959 /* x509_crl.c */; }; + A143384729A9D314007A5959 /* cipher_wrap.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B829A9D314007A5959 /* cipher_wrap.c */; }; + A143384829A9D314007A5959 /* chacha20.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337B929A9D314007A5959 /* chacha20.c */; }; + A143384929A9D314007A5959 /* des.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337BA29A9D314007A5959 /* des.c */; }; + A143384A29A9D314007A5959 /* ssl_cookie.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337BB29A9D314007A5959 /* ssl_cookie.c */; }; + A143384B29A9D314007A5959 /* ctr_drbg.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337BC29A9D314007A5959 /* ctr_drbg.c */; }; + A143384C29A9D314007A5959 /* dhm.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337BD29A9D314007A5959 /* dhm.c */; }; + A143384D29A9D314007A5959 /* ssl_cache.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337BE29A9D314007A5959 /* ssl_cache.c */; }; + A143384E29A9D314007A5959 /* ssl_ciphersuites.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337BF29A9D314007A5959 /* ssl_ciphersuites.c */; }; + A143384F29A9D314007A5959 /* hmac_drbg.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C029A9D314007A5959 /* hmac_drbg.c */; }; + A143385029A9D314007A5959 /* rsa.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C129A9D314007A5959 /* rsa.c */; }; + A143385129A9D314007A5959 /* ssl_ticket.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C229A9D314007A5959 /* ssl_ticket.c */; }; + A143385229A9D314007A5959 /* asn1parse.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C329A9D314007A5959 /* asn1parse.c */; }; + A143385329A9D314007A5959 /* certs.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C429A9D314007A5959 /* certs.c */; }; + A143385429A9D314007A5959 /* pkwrite.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C529A9D314007A5959 /* pkwrite.c */; }; + A143385529A9D314007A5959 /* gcm.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C629A9D314007A5959 /* gcm.c */; }; + A143385629A9D314007A5959 /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C729A9D314007A5959 /* sha1.c */; }; + A143385729A9D314007A5959 /* asn1write.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C829A9D314007A5959 /* asn1write.c */; }; + A143385829A9D314007A5959 /* ccm.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337C929A9D314007A5959 /* ccm.c */; }; + A143385929A9D314007A5959 /* version_features.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337CA29A9D314007A5959 /* version_features.c */; }; + A143385A29A9D314007A5959 /* entropy_poll.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337CB29A9D314007A5959 /* entropy_poll.c */; }; + A143385B29A9D314007A5959 /* x509write_csr.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337CC29A9D314007A5959 /* x509write_csr.c */; }; + A143385C29A9D314007A5959 /* platform.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337CD29A9D314007A5959 /* platform.c */; }; + A143385D29A9D314007A5959 /* cmac.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337CE29A9D314007A5959 /* cmac.c */; }; + A143385E29A9D314007A5959 /* bignum.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337CF29A9D314007A5959 /* bignum.c */; }; + A143385F29A9D314007A5959 /* pkparse.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D029A9D314007A5959 /* pkparse.c */; }; + A143386029A9D314007A5959 /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D129A9D314007A5959 /* debug.c */; }; + A143386129A9D314007A5959 /* ripemd160.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D229A9D314007A5959 /* ripemd160.c */; }; + A143386229A9D314007A5959 /* ssl_cli.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D329A9D314007A5959 /* ssl_cli.c */; }; + A143386329A9D314007A5959 /* blowfish.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D429A9D314007A5959 /* blowfish.c */; }; + A143386429A9D314007A5959 /* rsa_internal.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D529A9D314007A5959 /* rsa_internal.c */; }; + A143386529A9D314007A5959 /* pkcs5.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D629A9D314007A5959 /* pkcs5.c */; }; + A143386629A9D314007A5959 /* pem.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D729A9D314007A5959 /* pem.c */; }; + A143386729A9D314007A5959 /* oid.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D829A9D314007A5959 /* oid.c */; }; + A143386829A9D314007A5959 /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337D929A9D314007A5959 /* error.c */; }; + A143386929A9D314007A5959 /* md_wrap.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337DA29A9D314007A5959 /* md_wrap.c */; }; + A143386A29A9D314007A5959 /* x509_csr.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337DB29A9D314007A5959 /* x509_csr.c */; }; + A143386B29A9D314007A5959 /* platform_util.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337DC29A9D314007A5959 /* platform_util.c */; }; + A143386C29A9D314007A5959 /* pkcs11.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337DD29A9D314007A5959 /* pkcs11.c */; }; + A143386D29A9D314007A5959 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337DE29A9D314007A5959 /* base64.c */; }; + A143386E29A9D314007A5959 /* ecp.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337DF29A9D314007A5959 /* ecp.c */; }; + A143386F29A9D314007A5959 /* version.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E029A9D314007A5959 /* version.c */; }; + A143387029A9D314007A5959 /* x509.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E129A9D314007A5959 /* x509.c */; }; + A143387129A9D314007A5959 /* chachapoly.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E229A9D314007A5959 /* chachapoly.c */; }; + A143387229A9D314007A5959 /* sha256.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E329A9D314007A5959 /* sha256.c */; }; + A143387329A9D314007A5959 /* ecp_curves.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E429A9D314007A5959 /* ecp_curves.c */; }; + A143387429A9D314007A5959 /* md5.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E529A9D314007A5959 /* md5.c */; }; + A143387529A9D314007A5959 /* arc4.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E629A9D314007A5959 /* arc4.c */; }; + A143387629A9D314007A5959 /* poly1305.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E729A9D314007A5959 /* poly1305.c */; }; + A143387729A9D314007A5959 /* xtea.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E829A9D314007A5959 /* xtea.c */; }; + A143387829A9D314007A5959 /* x509write_crt.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337E929A9D314007A5959 /* x509write_crt.c */; }; + A143387929A9D314007A5959 /* hkdf.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337EA29A9D314007A5959 /* hkdf.c */; }; + A143387A29A9D314007A5959 /* pkcs12.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337EB29A9D314007A5959 /* pkcs12.c */; }; + A143387B29A9D314007A5959 /* entropy.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337EC29A9D314007A5959 /* entropy.c */; }; + A143387C29A9D314007A5959 /* net_sockets.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337ED29A9D314007A5959 /* net_sockets.c */; }; + A143387D29A9D314007A5959 /* sha512.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337EE29A9D314007A5959 /* sha512.c */; }; + A143387E29A9D314007A5959 /* md.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337EF29A9D314007A5959 /* md.c */; }; + A143387F29A9D314007A5959 /* ecjpake.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337F029A9D314007A5959 /* ecjpake.c */; }; + A143388029A9D314007A5959 /* cipher.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337F129A9D314007A5959 /* cipher.c */; }; + A143388129A9D314007A5959 /* ecdsa.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337F229A9D314007A5959 /* ecdsa.c */; }; + A143388229A9D314007A5959 /* nist_kw.c in Sources */ = {isa = PBXBuildFile; fileRef = A14337F329A9D314007A5959 /* nist_kw.c */; }; + A143388329A9D314007A5959 /* pem.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337F529A9D314007A5959 /* pem.h */; }; + A143388429A9D314007A5959 /* check_config.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337F629A9D314007A5959 /* check_config.h */; }; + A143388529A9D314007A5959 /* error.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337F729A9D314007A5959 /* error.h */; }; + A143388629A9D314007A5959 /* oid.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337F829A9D314007A5959 /* oid.h */; }; + A143388729A9D314007A5959 /* rsa_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337F929A9D314007A5959 /* rsa_internal.h */; }; + A143388829A9D314007A5959 /* pkcs5.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337FA29A9D314007A5959 /* pkcs5.h */; }; + A143388929A9D314007A5959 /* ripemd160.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337FB29A9D314007A5959 /* ripemd160.h */; }; + A143388A29A9D314007A5959 /* blowfish.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337FC29A9D314007A5959 /* blowfish.h */; }; + A143388B29A9D314007A5959 /* debug.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337FD29A9D314007A5959 /* debug.h */; }; + A143388C29A9D314007A5959 /* x509.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337FE29A9D314007A5959 /* x509.h */; }; + A143388D29A9D314007A5959 /* version.h in Headers */ = {isa = PBXBuildFile; fileRef = A14337FF29A9D314007A5959 /* version.h */; }; + A143388E29A9D314007A5959 /* ecp.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380029A9D314007A5959 /* ecp.h */; }; + A143388F29A9D314007A5959 /* net.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380129A9D314007A5959 /* net.h */; }; + A143389029A9D314007A5959 /* cipher_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380229A9D314007A5959 /* cipher_internal.h */; }; + A143389129A9D314007A5959 /* md_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380329A9D314007A5959 /* md_internal.h */; }; + A143389229A9D314007A5959 /* base64.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380429A9D314007A5959 /* base64.h */; }; + A143389329A9D314007A5959 /* pkcs11.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380529A9D314007A5959 /* pkcs11.h */; }; + A143389429A9D314007A5959 /* ssl_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380629A9D314007A5959 /* ssl_internal.h */; }; + A143389529A9D314007A5959 /* asn1.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380729A9D314007A5959 /* asn1.h */; }; + A143389629A9D314007A5959 /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380829A9D314007A5959 /* config.h */; }; + A143389729A9D314007A5959 /* x509_csr.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380929A9D314007A5959 /* x509_csr.h */; }; + A143389829A9D314007A5959 /* platform_util.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380A29A9D314007A5959 /* platform_util.h */; }; + A143389929A9D314007A5959 /* xtea.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380B29A9D314007A5959 /* xtea.h */; }; + A143389A29A9D314007A5959 /* poly1305.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380C29A9D314007A5959 /* poly1305.h */; }; + A143389B29A9D314007A5959 /* threading.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380D29A9D314007A5959 /* threading.h */; }; + A143389C29A9D314007A5959 /* hkdf.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380E29A9D314007A5959 /* hkdf.h */; }; + A143389D29A9D314007A5959 /* compat-1.3.h in Headers */ = {isa = PBXBuildFile; fileRef = A143380F29A9D314007A5959 /* compat-1.3.h */; }; + A143389E29A9D314007A5959 /* md5.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381029A9D314007A5959 /* md5.h */; }; + A143389F29A9D314007A5959 /* timing.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381129A9D314007A5959 /* timing.h */; }; + A14338A029A9D314007A5959 /* arc4.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381229A9D314007A5959 /* arc4.h */; }; + A14338A129A9D314007A5959 /* chachapoly.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381329A9D314007A5959 /* chachapoly.h */; }; + A14338A229A9D314007A5959 /* sha256.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381429A9D314007A5959 /* sha256.h */; }; + A14338A329A9D314007A5959 /* ecdsa.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381529A9D314007A5959 /* ecdsa.h */; }; + A14338A429A9D314007A5959 /* nist_kw.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381629A9D314007A5959 /* nist_kw.h */; }; + A14338A529A9D314007A5959 /* md.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381729A9D314007A5959 /* md.h */; }; + A14338A629A9D314007A5959 /* cipher.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381829A9D314007A5959 /* cipher.h */; }; + A14338A729A9D314007A5959 /* ecjpake.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381929A9D314007A5959 /* ecjpake.h */; }; + A14338A829A9D314007A5959 /* net_sockets.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381A29A9D314007A5959 /* net_sockets.h */; }; + A14338A929A9D314007A5959 /* entropy.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381B29A9D314007A5959 /* entropy.h */; }; + A14338AA29A9D314007A5959 /* pkcs12.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381C29A9D314007A5959 /* pkcs12.h */; }; + A14338AB29A9D314007A5959 /* sha512.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381D29A9D314007A5959 /* sha512.h */; }; + A14338AC29A9D314007A5959 /* bn_mul.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381E29A9D314007A5959 /* bn_mul.h */; }; + A14338AD29A9D314007A5959 /* pk.h in Headers */ = {isa = PBXBuildFile; fileRef = A143381F29A9D314007A5959 /* pk.h */; }; + A14338AE29A9D314007A5959 /* ecp_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382029A9D314007A5959 /* ecp_internal.h */; }; + A14338AF29A9D314007A5959 /* ssl.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382129A9D314007A5959 /* ssl.h */; }; + A14338B029A9D314007A5959 /* platform_time.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382229A9D314007A5959 /* platform_time.h */; }; + A14338B129A9D314007A5959 /* camellia.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382329A9D314007A5959 /* camellia.h */; }; + A14338B229A9D314007A5959 /* x509_crt.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382429A9D314007A5959 /* x509_crt.h */; }; + A14338B329A9D314007A5959 /* aes.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382529A9D314007A5959 /* aes.h */; }; + A14338B429A9D314007A5959 /* pk_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382629A9D314007A5959 /* pk_internal.h */; }; + A14338B529A9D314007A5959 /* ssl_cookie.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382729A9D314007A5959 /* ssl_cookie.h */; }; + A14338B629A9D314007A5959 /* dhm.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382829A9D314007A5959 /* dhm.h */; }; + A14338B729A9D314007A5959 /* ctr_drbg.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382929A9D314007A5959 /* ctr_drbg.h */; }; + A14338B829A9D314007A5959 /* chacha20.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382A29A9D314007A5959 /* chacha20.h */; }; + A14338B929A9D314007A5959 /* des.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382B29A9D314007A5959 /* des.h */; }; + A14338BA29A9D314007A5959 /* x509_crl.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382C29A9D314007A5959 /* x509_crl.h */; }; + A14338BB29A9D314007A5959 /* ecdh.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382D29A9D314007A5959 /* ecdh.h */; }; + A14338BC29A9D314007A5959 /* sha1.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382E29A9D314007A5959 /* sha1.h */; }; + A14338BD29A9D314007A5959 /* gcm.h in Headers */ = {isa = PBXBuildFile; fileRef = A143382F29A9D314007A5959 /* gcm.h */; }; + A14338BE29A9D314007A5959 /* certs.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383029A9D314007A5959 /* certs.h */; }; + A14338BF29A9D314007A5959 /* rsa.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383129A9D314007A5959 /* rsa.h */; }; + A14338C029A9D314007A5959 /* hmac_drbg.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383229A9D314007A5959 /* hmac_drbg.h */; }; + A14338C129A9D314007A5959 /* ssl_ticket.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383329A9D314007A5959 /* ssl_ticket.h */; }; + A14338C229A9D314007A5959 /* ssl_ciphersuites.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383429A9D314007A5959 /* ssl_ciphersuites.h */; }; + A14338C329A9D314007A5959 /* ssl_cache.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383529A9D314007A5959 /* ssl_cache.h */; }; + A14338C429A9D314007A5959 /* cmac.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383629A9D314007A5959 /* cmac.h */; }; + A14338C529A9D314007A5959 /* platform.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383729A9D314007A5959 /* platform.h */; }; + A14338C629A9D314007A5959 /* bignum.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383829A9D314007A5959 /* bignum.h */; }; + A14338C729A9D314007A5959 /* aria.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383929A9D314007A5959 /* aria.h */; }; + A14338C829A9D314007A5959 /* entropy_poll.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383A29A9D314007A5959 /* entropy_poll.h */; }; + A14338C929A9D314007A5959 /* asn1write.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383B29A9D314007A5959 /* asn1write.h */; }; + A14338CA29A9D314007A5959 /* ccm.h in Headers */ = {isa = PBXBuildFile; fileRef = A143383C29A9D314007A5959 /* ccm.h */; }; + A14338CB29A9D40A007A5959 /* license.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1BB5B7C2916B3DD00953939 /* license.framework */; }; + A14338CC29A9D40A007A5959 /* license.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A1BB5B7C2916B3DD00953939 /* license.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + A14338CF29A9D413007A5959 /* license.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A1BB5B7C2916B3DD00953939 /* license.framework */; }; + A14338D229A9D435007A5959 /* nettls.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A14337A129A9D2E7007A5959 /* nettls.framework */; }; + A14338D329A9D435007A5959 /* nettls.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A14337A129A9D2E7007A5959 /* nettls.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A1447A3E2821A91400D3DCA4 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = A1447A3D2821A91400D3DCA4 /* main.c */; }; A1447A422821A95C00D3DCA4 /* stdcrt.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A144AAFD272572A30019CA5F /* stdcrt.framework */; }; A1447A432821A95C00D3DCA4 /* stdcrt.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A144AAFD272572A30019CA5F /* stdcrt.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -214,7 +361,7 @@ A144AB73272572FD0019CA5F /* compat_base64.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB49272572FD0019CA5F /* compat_base64.c */; }; A144AB74272572FD0019CA5F /* compat_sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB4A272572FD0019CA5F /* compat_sha1.c */; }; A144AB75272572FD0019CA5F /* compat_md5.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB4B272572FD0019CA5F /* compat_md5.c */; }; - A144AB76272572FD0019CA5F /* compat_proctol.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB4D272572FD0019CA5F /* compat_proctol.c */; }; + A144AB76272572FD0019CA5F /* compat_proctl.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB4D272572FD0019CA5F /* compat_proctl.c */; }; A144AB77272572FD0019CA5F /* compat_stdtime.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB4E272572FD0019CA5F /* compat_stdtime.c */; }; A144AB78272572FD0019CA5F /* compat_argv.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB4F272572FD0019CA5F /* compat_argv.c */; }; A144AB79272572FD0019CA5F /* compat_guid.c in Sources */ = {isa = PBXBuildFile; fileRef = A144AB50272572FD0019CA5F /* compat_guid.c */; }; @@ -262,8 +409,6 @@ A144ABC6272574290019CA5F /* stdcrt.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A144AAFD272572A30019CA5F /* stdcrt.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A14E061B285A30B800DE3EDA /* objectrun.h in Headers */ = {isa = PBXBuildFile; fileRef = A14E0619285A30B700DE3EDA /* objectrun.h */; }; A14E061C285A30B800DE3EDA /* objectrun.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A14E061A285A30B700DE3EDA /* objectrun.cpp */; }; - A1681ABA273982CC004CC415 /* httpinstanceimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A1681AB8273982CC004CC415 /* httpinstanceimpl.h */; }; - A1681ABB273982CC004CC415 /* httpinstanceimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1681AB9273982CC004CC415 /* httpinstanceimpl.cpp */; }; A17163F2271DCD190062A998 /* tableinfo.h in Headers */ = {isa = PBXBuildFile; fileRef = A17163E0271DCD180062A998 /* tableinfo.h */; }; A17163F3271DCD190062A998 /* dbimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17163E1271DCD180062A998 /* dbimpl.cpp */; }; A17163F4271DCD190062A998 /* stringutil.h in Headers */ = {isa = PBXBuildFile; fileRef = A17163E2271DCD180062A998 /* stringutil.h */; }; @@ -294,6 +439,62 @@ A1BB5B912916B47200953939 /* stdafx.h in Headers */ = {isa = PBXBuildFile; fileRef = A1BB5B8C2916B47200953939 /* stdafx.h */; }; A1BB5B922916B49500953939 /* stdcrt.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A144AAFD272572A30019CA5F /* stdcrt.framework */; }; A1BB5B932916B49500953939 /* stdcrt.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A144AAFD272572A30019CA5F /* stdcrt.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + A1E50FBD29A0134500FF65B0 /* evthread_pthread.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F7529A0134400FF65B0 /* evthread_pthread.c */; }; + A1E50FBE29A0134500FF65B0 /* log.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F7629A0134400FF65B0 /* log.c */; }; + A1E50FBF29A0134500FF65B0 /* buffer_compat.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F7729A0134400FF65B0 /* buffer_compat.h */; }; + A1E50FC029A0134500FF65B0 /* changelist-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F7829A0134400FF65B0 /* changelist-internal.h */; }; + A1E50FC129A0134500FF65B0 /* evmap.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F7929A0134400FF65B0 /* evmap.c */; }; + A1E50FC229A0134500FF65B0 /* buffer.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F7A29A0134400FF65B0 /* buffer.c */; }; + A1E50FC329A0134500FF65B0 /* evsignal-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F7B29A0134400FF65B0 /* evsignal-internal.h */; }; + A1E50FC429A0134500FF65B0 /* event-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F7C29A0134400FF65B0 /* event-internal.h */; }; + A1E50FC529A0134500FF65B0 /* event-config.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F7D29A0134400FF65B0 /* event-config.h */; }; + A1E50FC629A0134500FF65B0 /* listener.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F7E29A0134400FF65B0 /* listener.h */; }; + A1E50FC729A0134500FF65B0 /* defer-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F7F29A0134400FF65B0 /* defer-internal.h */; }; + A1E50FC829A0134500FF65B0 /* strlcpy.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F8029A0134400FF65B0 /* strlcpy.c */; }; + A1E50FC929A0134500FF65B0 /* event_compat.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F8129A0134400FF65B0 /* event_compat.h */; }; + A1E50FCB29A0134500FF65B0 /* ratelim-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F8329A0134400FF65B0 /* ratelim-internal.h */; }; + A1E50FCC29A0134500FF65B0 /* bufferevent_struct.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F8429A0134400FF65B0 /* bufferevent_struct.h */; }; + A1E50FCD29A0134500FF65B0 /* bufferevent_filter.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F8529A0134400FF65B0 /* bufferevent_filter.c */; }; + A1E50FCE29A0134500FF65B0 /* event.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F8629A0134400FF65B0 /* event.h */; }; + A1E50FCF29A0134500FF65B0 /* evutil_rand.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F8729A0134400FF65B0 /* evutil_rand.c */; }; + A1E50FD029A0134500FF65B0 /* evmap-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F8829A0134400FF65B0 /* evmap-internal.h */; }; + A1E50FD229A0134500FF65B0 /* evutil.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F8A29A0134400FF65B0 /* evutil.h */; }; + A1E50FD329A0134500FF65B0 /* bufferevent_pair.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F8B29A0134400FF65B0 /* bufferevent_pair.c */; }; + A1E50FD429A0134500FF65B0 /* poll.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F8C29A0134400FF65B0 /* poll.c */; }; + A1E50FD529A0134500FF65B0 /* evport.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F8D29A0134400FF65B0 /* evport.c */; }; + A1E50FD629A0134500FF65B0 /* bufferevent.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F8E29A0134400FF65B0 /* bufferevent.h */; }; + A1E50FD829A0134500FF65B0 /* select.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F9029A0134400FF65B0 /* select.c */; }; + A1E50FD929A0134500FF65B0 /* minheap-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9129A0134400FF65B0 /* minheap-internal.h */; }; + A1E50FDA29A0134500FF65B0 /* evthread-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9229A0134400FF65B0 /* evthread-internal.h */; }; + A1E50FDB29A0134500FF65B0 /* time-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9329A0134400FF65B0 /* time-internal.h */; }; + A1E50FDC29A0134500FF65B0 /* evbuffer-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9429A0134500FF65B0 /* evbuffer-internal.h */; }; + A1E50FDD29A0134500FF65B0 /* bufferevent-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9529A0134500FF65B0 /* bufferevent-internal.h */; }; + A1E50FDE29A0134500FF65B0 /* buffer.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9629A0134500FF65B0 /* buffer.h */; }; + A1E50FDF29A0134500FF65B0 /* epolltable-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9729A0134500FF65B0 /* epolltable-internal.h */; }; + A1E50FE229A0134500FF65B0 /* util-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9A29A0134500FF65B0 /* util-internal.h */; }; + A1E50FE329A0134500FF65B0 /* ipv6-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9B29A0134500FF65B0 /* ipv6-internal.h */; }; + A1E50FE429A0134500FF65B0 /* log-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9C29A0134500FF65B0 /* log-internal.h */; }; + A1E50FE629A0134500FF65B0 /* keyvalq_struct.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50F9E29A0134500FF65B0 /* keyvalq_struct.h */; }; + A1E50FE729A0134500FF65B0 /* event.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50F9F29A0134500FF65B0 /* event.c */; }; + A1E50FE929A0134500FF65B0 /* strlcpy-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FA129A0134500FF65B0 /* strlcpy-internal.h */; }; + A1E50FEB29A0134500FF65B0 /* eventbase.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FA329A0134500FF65B0 /* eventbase.h */; }; + A1E50FEC29A0134500FF65B0 /* evconfig-private.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FA429A0134500FF65B0 /* evconfig-private.h */; }; + A1E50FEF29A0134500FF65B0 /* util.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FA729A0134500FF65B0 /* util.h */; }; + A1E50FF129A0134500FF65B0 /* listener.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FA929A0134500FF65B0 /* listener.c */; }; + A1E50FF229A0134500FF65B0 /* mm-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FAA29A0134500FF65B0 /* mm-internal.h */; }; + A1E50FF329A0134500FF65B0 /* bufferevent.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FAB29A0134500FF65B0 /* bufferevent.c */; }; + A1E50FF529A0134500FF65B0 /* evutil.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FAD29A0134500FF65B0 /* evutil.c */; }; + A1E50FF629A0134500FF65B0 /* bufferevent_ratelim.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FAE29A0134500FF65B0 /* bufferevent_ratelim.c */; }; + A1E50FF729A0134500FF65B0 /* evthread.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FAF29A0134500FF65B0 /* evthread.c */; }; + A1E50FFC29A0134500FF65B0 /* kqueue-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FB429A0134500FF65B0 /* kqueue-internal.h */; }; + A1E50FFD29A0134500FF65B0 /* bufferevent_sock.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FB529A0134500FF65B0 /* bufferevent_sock.c */; }; + A1E50FFE29A0134500FF65B0 /* bufferevent_compat.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FB629A0134500FF65B0 /* bufferevent_compat.h */; }; + A1E50FFF29A0134500FF65B0 /* queue-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FB729A0134500FF65B0 /* queue-internal.h */; }; + A1E5100029A0134500FF65B0 /* ht-internal.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FB829A0134500FF65B0 /* ht-internal.h */; }; + A1E5100129A0134500FF65B0 /* kqueue.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FB929A0134500FF65B0 /* kqueue.c */; }; + A1E5100229A0134500FF65B0 /* event_struct.h in Headers */ = {isa = PBXBuildFile; fileRef = A1E50FBA29A0134500FF65B0 /* event_struct.h */; }; + A1E5100329A0134500FF65B0 /* evutil_time.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E50FBB29A0134500FF65B0 /* evutil_time.c */; }; + A1E5100529A0271700FF65B0 /* signal.c in Sources */ = {isa = PBXBuildFile; fileRef = A1E5100429A0271700FF65B0 /* signal.c */; }; A1F110B1299CEA2A00C3891C /* licenseimpl.h in Headers */ = {isa = PBXBuildFile; fileRef = A1F110AF299CEA2A00C3891C /* licenseimpl.h */; }; A1F110B2299CEA2A00C3891C /* licenseimpl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1F110B0299CEA2A00C3891C /* licenseimpl.cpp */; }; A1F110B8299CEA5C00C3891C /* ichannel.h in Headers */ = {isa = PBXBuildFile; fileRef = A1F110B4299CEA5C00C3891C /* ichannel.h */; }; @@ -310,6 +511,20 @@ A1F6DB7327284749002BF005 /* http_content_type.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1F6DB6727284749002BF005 /* http_content_type.cpp */; }; A1F6DB7427284749002BF005 /* chttpparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1F6DB6827284749002BF005 /* chttpparser.cpp */; }; A1F6DB7527284749002BF005 /* http_header.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1F6DB6927284749002BF005 /* http_header.cpp */; }; + A1FAA5BD29BE54CE007FC149 /* bufferevent_ssl.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FAA5BC29BE54CE007FC149 /* bufferevent_ssl.c */; }; + A1FAA5BF29BE5551007FC149 /* ssl-compat.h in Headers */ = {isa = PBXBuildFile; fileRef = A1FAA5BE29BE5551007FC149 /* ssl-compat.h */; }; + A1FAA5C129BE55A8007FC149 /* bufferevent_ssl.h in Headers */ = {isa = PBXBuildFile; fileRef = A1FAA5C029BE55A8007FC149 /* bufferevent_ssl.h */; }; + A1FAA5C329BE5982007FC149 /* bufferevent_mbedtls.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FAA5C229BE5982007FC149 /* bufferevent_mbedtls.c */; }; + A1FAA5C529BE59D7007FC149 /* mbedtls-compat.h in Headers */ = {isa = PBXBuildFile; fileRef = A1FAA5C429BE59D7007FC149 /* mbedtls-compat.h */; }; + A1FC350E29A51010009FDCE9 /* ioev.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1FC350D29A51010009FDCE9 /* ioev.cpp */; }; + A1FD41FF29A5E57F003B81C5 /* event_posix.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41F729A5E57F003B81C5 /* event_posix.c */; }; + A1FD420029A5E57F003B81C5 /* compat_event.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41F829A5E57F003B81C5 /* compat_event.c */; }; + A1FD420129A5E57F003B81C5 /* event_mach.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41F929A5E57F003B81C5 /* event_mach.c */; }; + A1FD420229A5E57F003B81C5 /* compat_event_iocp.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41FA29A5E57F003B81C5 /* compat_event_iocp.c */; }; + A1FD420329A5E57F003B81C5 /* compat_event_kqueue.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41FB29A5E57F003B81C5 /* compat_event_kqueue.c */; }; + A1FD420429A5E57F003B81C5 /* compat_event_epoll.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41FC29A5E57F003B81C5 /* compat_event_epoll.c */; }; + A1FD420529A5E57F003B81C5 /* compat_event_util.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41FD29A5E57F003B81C5 /* compat_event_util.c */; }; + A1FD420629A5E57F003B81C5 /* event_win32.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FD41FE29A5E57F003B81C5 /* event_win32.c */; }; A1FEB717288097A200FC2CCD /* compat_evrbtree.c in Sources */ = {isa = PBXBuildFile; fileRef = A1FEB716288097A200FC2CCD /* compat_evrbtree.c */; }; A1FEB719288097C200FC2CCD /* crt_evrbtree.h in Headers */ = {isa = PBXBuildFile; fileRef = A1FEB718288097C200FC2CCD /* crt_evrbtree.h */; }; /* End PBXBuildFile section */ @@ -441,6 +656,34 @@ remoteGlobalIDString = A1351F76272054500080B9B4; remoteInfo = http; }; + A14337A629A9D2E7007A5959 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A10FFAA526F8417900A4D864 /* Project object */; + proxyType = 1; + remoteGlobalIDString = A14337A029A9D2E7007A5959; + remoteInfo = nettls; + }; + A14338CD29A9D40A007A5959 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A10FFAA526F8417900A4D864 /* Project object */; + proxyType = 1; + remoteGlobalIDString = A1BB5B7B2916B3DD00953939; + remoteInfo = license; + }; + A14338D029A9D413007A5959 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A10FFAA526F8417900A4D864 /* Project object */; + proxyType = 1; + remoteGlobalIDString = A1BB5B7B2916B3DD00953939; + remoteInfo = license; + }; + A14338D429A9D435007A5959 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A10FFAA526F8417900A4D864 /* Project object */; + proxyType = 1; + remoteGlobalIDString = A14337A029A9D2E7007A5959; + remoteInfo = nettls; + }; A1447A452821A95C00D3DCA4 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = A10FFAA526F8417900A4D864 /* Project object */; @@ -593,6 +836,7 @@ A126FE4728A01B4D00D95D6C /* runtime.framework in Embed Frameworks */, A107EB9227173C50006A8E8E /* container.framework in Embed Frameworks */, A107EB9E27173C50006A8E8E /* mainview.framework in Embed Frameworks */, + A14338CC29A9D40A007A5959 /* license.framework in Embed Frameworks */, A107EB8A27173C50006A8E8E /* asynio.framework in Embed Frameworks */, A144AB99272573EE0019CA5F /* stdcrt.framework in Embed Frameworks */, A107EB9A27173C50006A8E8E /* logs.framework in Embed Frameworks */, @@ -609,6 +853,7 @@ dstSubfolderSpec = 10; files = ( A107EBCF27173DBA006A8E8E /* access.framework in Embed Frameworks */, + A14337A929A9D2E7007A5959 /* nettls.framework in Embed Frameworks */, A126FE2728A01A8100D95D6C /* runtime.framework in Embed Frameworks */, A107EBDB27173DBA006A8E8E /* container.framework in Embed Frameworks */, A144AB05272572A30019CA5F /* stdcrt.framework in Embed Frameworks */, @@ -628,6 +873,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + A14338D329A9D435007A5959 /* nettls.framework in Embed Frameworks */, A144ABA2272573FE0019CA5F /* stdcrt.framework in Embed Frameworks */, ); name = "Embed Frameworks"; @@ -705,10 +951,6 @@ A10773DD282194210001A1EF /* crt_event_win32.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = crt_event_win32.h; sourceTree = ""; }; A10773DE282194210001A1EF /* crt_event_epoll.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = crt_event_epoll.h; sourceTree = ""; }; A10773DF282194210001A1EF /* crt_event_kqueue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = crt_event_kqueue.h; sourceTree = ""; }; - A10773EA282195A10001A1EF /* compat_event.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = compat_event.c; path = event/compat_event.c; sourceTree = ""; }; - A10773EB282195A10001A1EF /* compat_event_iocp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = compat_event_iocp.c; path = event/compat_event_iocp.c; sourceTree = ""; }; - A10773EC282195A10001A1EF /* compat_event_epoll.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = compat_event_epoll.c; path = event/compat_event_epoll.c; sourceTree = ""; }; - A10773EF282195A10001A1EF /* compat_event_kqueue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = compat_event_kqueue.c; path = event/compat_event_kqueue.c; sourceTree = ""; }; A107E8F827172470006A8E8E /* net.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = net.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A107E8FA27172470006A8E8E /* net.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = net.h; sourceTree = ""; }; A107E8FB27172470006A8E8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -806,10 +1048,10 @@ A107EBC727173D52006A8E8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A107EBC827173D52006A8E8E /* main.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = main.mm; sourceTree = ""; }; A107EBCA27173D52006A8E8E /* mainui.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = mainui.entitlements; sourceTree = ""; }; + A108551329B7C10600A15324 /* msgbuschannel.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = msgbuschannel.hpp; sourceTree = ""; }; A10B3F532715EBD50003990D /* asynio.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = asynio.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A10B3F552715EBD50003990D /* asynio.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = asynio.h; sourceTree = ""; }; A10B3F562715EBD50003990D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - A10B3F5B2715EC0B0003990D /* fileimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fileimpl.cpp; sourceTree = ""; }; A10B3F5C2715EC0B0003990D /* interface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = interface.cpp; sourceTree = ""; }; A10B3F5D2715EC0B0003990D /* stdafx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stdafx.h; sourceTree = ""; }; A10B3F5E2715EC0B0003990D /* asynframeimpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asynframeimpl.h; sourceTree = ""; }; @@ -820,7 +1062,6 @@ A10B3F632715EC0C0003990D /* asynio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = asynio.cpp; sourceTree = ""; }; A10B3F642715EC0C0003990D /* tcplistensocketimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tcplistensocketimpl.cpp; sourceTree = ""; }; A10B3F652715EC0C0003990D /* udpsocketimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = udpsocketimpl.cpp; sourceTree = ""; }; - A10B3F662715EC0C0003990D /* fileimpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fileimpl.h; sourceTree = ""; }; A10B3F672715EC0C0003990D /* tcpsocketimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tcpsocketimpl.cpp; sourceTree = ""; }; A10B3F682715EC0C0003990D /* timerimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = timerimpl.cpp; sourceTree = ""; }; A10B3F692715EC0C0003990D /* asynframeimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = asynframeimpl.cpp; sourceTree = ""; }; @@ -828,6 +1069,10 @@ A10B3F6B2715EC0C0003990D /* timerimpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = timerimpl.h; sourceTree = ""; }; A10B3F6C2715EC0C0003990D /* udpsocketimpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = udpsocketimpl.h; sourceTree = ""; }; A10B3F6D2715EC0C0003990D /* dllmain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dllmain.cpp; sourceTree = ""; }; + A110383C29B8D5D000DD9517 /* ipipe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ipipe.h; sourceTree = ""; }; + A110383D29B8D90A00DD9517 /* http.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = http.h; sourceTree = ""; }; + A110383E29B8D90A00DD9517 /* http.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http.cpp; sourceTree = ""; }; + A1115E3029A3D885002FFA60 /* ioevdef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ioevdef.h; sourceTree = ""; }; A11694732713144500CBA348 /* container.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = container.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A11694752713144500CBA348 /* container.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = container.h; sourceTree = ""; }; A11694762713144500CBA348 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -878,7 +1123,6 @@ A11694C82713154700CBA348 /* thread.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = thread.hpp; sourceTree = ""; }; A119CCE5271F0DAA00EF6077 /* appviewimpl.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = appviewimpl.cpp; sourceTree = ""; }; A119CCE6271F0DAA00EF6077 /* appviewimpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = appviewimpl.h; sourceTree = ""; }; - A12411F1288065B300D73A63 /* compat_event_util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = compat_event_util.c; path = event/compat_event_util.c; sourceTree = ""; }; A126FDE128A0158D00D95D6C /* crt_alloc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = crt_alloc.h; sourceTree = ""; }; A126FDE228A015AF00D95D6C /* compat_vsnprintf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_vsnprintf.c; sourceTree = ""; }; A126FDE328A015AF00D95D6C /* compat_alloc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_alloc.c; sourceTree = ""; }; @@ -897,7 +1141,6 @@ A126FE3328A01AB600D95D6C /* runtimeimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = runtimeimpl.cpp; sourceTree = ""; }; A126FE3428A01AB600D95D6C /* threadimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = threadimpl.cpp; sourceTree = ""; }; A126FE3528A01AB600D95D6C /* threadpoolimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = threadpoolimpl.cpp; sourceTree = ""; }; - A12720682881D2B0001ECCC8 /* event_mach.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = event_mach.c; path = event/event_mach.c; sourceTree = ""; }; A127206A2881D346001ECCC8 /* crt_event_mach.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crt_event_mach.h; sourceTree = ""; }; A127206C2881D384001ECCC8 /* crt_event_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crt_event_util.h; sourceTree = ""; }; A128C5F82879C41E009F8396 /* crt_clock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = crt_clock.h; sourceTree = ""; }; @@ -917,8 +1160,154 @@ A139C4E2285A363200416E98 /* spipeimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = spipeimpl.cpp; sourceTree = ""; }; A139C4E3285A363200416E98 /* tlswrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tlswrap.h; sourceTree = ""; }; A139C4E4285A363200416E98 /* spipeimpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = spipeimpl.h; sourceTree = ""; }; - A1447A272821A85D00D3DCA4 /* event_posix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = event_posix.c; path = event/event_posix.c; sourceTree = ""; }; - A1447A282821A85D00D3DCA4 /* event_win32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = event_win32.c; path = event/event_win32.c; sourceTree = ""; }; + A13D08B629A177C900AA7830 /* evconfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = evconfig.h; sourceTree = ""; }; + A13D08B829A1783A00AA7830 /* evconfig-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "evconfig-internal.h"; sourceTree = ""; }; + A13D08BA29A1846000AA7830 /* thread-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "thread-internal.h"; sourceTree = ""; }; + A14337A129A9D2E7007A5959 /* nettls.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = nettls.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + A14337A329A9D2E7007A5959 /* nettls.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = nettls.h; sourceTree = ""; }; + A14337A429A9D2E7007A5959 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + A14337AE29A9D314007A5959 /* x509_create.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x509_create.c; sourceTree = ""; }; + A14337AF29A9D314007A5959 /* x509_crt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x509_crt.c; sourceTree = ""; }; + A14337B029A9D314007A5959 /* aes.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aes.c; sourceTree = ""; }; + A14337B129A9D314007A5959 /* ssl_srv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ssl_srv.c; sourceTree = ""; }; + A14337B229A9D314007A5959 /* camellia.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = camellia.c; sourceTree = ""; }; + A14337B329A9D314007A5959 /* pk_wrap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pk_wrap.c; sourceTree = ""; }; + A14337B429A9D314007A5959 /* pk.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pk.c; sourceTree = ""; }; + A14337B529A9D314007A5959 /* ecdh.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ecdh.c; sourceTree = ""; }; + A14337B629A9D314007A5959 /* ssl_tls.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ssl_tls.c; sourceTree = ""; }; + A14337B729A9D314007A5959 /* x509_crl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x509_crl.c; sourceTree = ""; }; + A14337B829A9D314007A5959 /* cipher_wrap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cipher_wrap.c; sourceTree = ""; }; + A14337B929A9D314007A5959 /* chacha20.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = chacha20.c; sourceTree = ""; }; + A14337BA29A9D314007A5959 /* des.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = des.c; sourceTree = ""; }; + A14337BB29A9D314007A5959 /* ssl_cookie.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ssl_cookie.c; sourceTree = ""; }; + A14337BC29A9D314007A5959 /* ctr_drbg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ctr_drbg.c; sourceTree = ""; }; + A14337BD29A9D314007A5959 /* dhm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dhm.c; sourceTree = ""; }; + A14337BE29A9D314007A5959 /* ssl_cache.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ssl_cache.c; sourceTree = ""; }; + A14337BF29A9D314007A5959 /* ssl_ciphersuites.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ssl_ciphersuites.c; sourceTree = ""; }; + A14337C029A9D314007A5959 /* hmac_drbg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hmac_drbg.c; sourceTree = ""; }; + A14337C129A9D314007A5959 /* rsa.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rsa.c; sourceTree = ""; }; + A14337C229A9D314007A5959 /* ssl_ticket.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ssl_ticket.c; sourceTree = ""; }; + A14337C329A9D314007A5959 /* asn1parse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = asn1parse.c; sourceTree = ""; }; + A14337C429A9D314007A5959 /* certs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = certs.c; sourceTree = ""; }; + A14337C529A9D314007A5959 /* pkwrite.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkwrite.c; sourceTree = ""; }; + A14337C629A9D314007A5959 /* gcm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = gcm.c; sourceTree = ""; }; + A14337C729A9D314007A5959 /* sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha1.c; sourceTree = ""; }; + A14337C829A9D314007A5959 /* asn1write.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = asn1write.c; sourceTree = ""; }; + A14337C929A9D314007A5959 /* ccm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ccm.c; sourceTree = ""; }; + A14337CA29A9D314007A5959 /* version_features.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = version_features.c; sourceTree = ""; }; + A14337CB29A9D314007A5959 /* entropy_poll.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = entropy_poll.c; sourceTree = ""; }; + A14337CC29A9D314007A5959 /* x509write_csr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x509write_csr.c; sourceTree = ""; }; + A14337CD29A9D314007A5959 /* platform.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = platform.c; sourceTree = ""; }; + A14337CE29A9D314007A5959 /* cmac.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cmac.c; sourceTree = ""; }; + A14337CF29A9D314007A5959 /* bignum.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bignum.c; sourceTree = ""; }; + A14337D029A9D314007A5959 /* pkparse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkparse.c; sourceTree = ""; }; + A14337D129A9D314007A5959 /* debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = debug.c; sourceTree = ""; }; + A14337D229A9D314007A5959 /* ripemd160.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ripemd160.c; sourceTree = ""; }; + A14337D329A9D314007A5959 /* ssl_cli.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ssl_cli.c; sourceTree = ""; }; + A14337D429A9D314007A5959 /* blowfish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = blowfish.c; sourceTree = ""; }; + A14337D529A9D314007A5959 /* rsa_internal.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rsa_internal.c; sourceTree = ""; }; + A14337D629A9D314007A5959 /* pkcs5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkcs5.c; sourceTree = ""; }; + A14337D729A9D314007A5959 /* pem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pem.c; sourceTree = ""; }; + A14337D829A9D314007A5959 /* oid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = oid.c; sourceTree = ""; }; + A14337D929A9D314007A5959 /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = error.c; sourceTree = ""; }; + A14337DA29A9D314007A5959 /* md_wrap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md_wrap.c; sourceTree = ""; }; + A14337DB29A9D314007A5959 /* x509_csr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x509_csr.c; sourceTree = ""; }; + A14337DC29A9D314007A5959 /* platform_util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = platform_util.c; sourceTree = ""; }; + A14337DD29A9D314007A5959 /* pkcs11.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkcs11.c; sourceTree = ""; }; + A14337DE29A9D314007A5959 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = base64.c; sourceTree = ""; }; + A14337DF29A9D314007A5959 /* ecp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ecp.c; sourceTree = ""; }; + A14337E029A9D314007A5959 /* version.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = version.c; sourceTree = ""; }; + A14337E129A9D314007A5959 /* x509.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x509.c; sourceTree = ""; }; + A14337E229A9D314007A5959 /* chachapoly.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = chachapoly.c; sourceTree = ""; }; + A14337E329A9D314007A5959 /* sha256.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha256.c; sourceTree = ""; }; + A14337E429A9D314007A5959 /* ecp_curves.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ecp_curves.c; sourceTree = ""; }; + A14337E529A9D314007A5959 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = ""; }; + A14337E629A9D314007A5959 /* arc4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = arc4.c; sourceTree = ""; }; + A14337E729A9D314007A5959 /* poly1305.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = poly1305.c; sourceTree = ""; }; + A14337E829A9D314007A5959 /* xtea.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = xtea.c; sourceTree = ""; }; + A14337E929A9D314007A5959 /* x509write_crt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x509write_crt.c; sourceTree = ""; }; + A14337EA29A9D314007A5959 /* hkdf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hkdf.c; sourceTree = ""; }; + A14337EB29A9D314007A5959 /* pkcs12.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pkcs12.c; sourceTree = ""; }; + A14337EC29A9D314007A5959 /* entropy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = entropy.c; sourceTree = ""; }; + A14337ED29A9D314007A5959 /* net_sockets.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = net_sockets.c; sourceTree = ""; }; + A14337EE29A9D314007A5959 /* sha512.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha512.c; sourceTree = ""; }; + A14337EF29A9D314007A5959 /* md.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md.c; sourceTree = ""; }; + A14337F029A9D314007A5959 /* ecjpake.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ecjpake.c; sourceTree = ""; }; + A14337F129A9D314007A5959 /* cipher.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cipher.c; sourceTree = ""; }; + A14337F229A9D314007A5959 /* ecdsa.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ecdsa.c; sourceTree = ""; }; + A14337F329A9D314007A5959 /* nist_kw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nist_kw.c; sourceTree = ""; }; + A14337F529A9D314007A5959 /* pem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pem.h; sourceTree = ""; }; + A14337F629A9D314007A5959 /* check_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = check_config.h; sourceTree = ""; }; + A14337F729A9D314007A5959 /* error.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = error.h; sourceTree = ""; }; + A14337F829A9D314007A5959 /* oid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = oid.h; sourceTree = ""; }; + A14337F929A9D314007A5959 /* rsa_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rsa_internal.h; sourceTree = ""; }; + A14337FA29A9D314007A5959 /* pkcs5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pkcs5.h; sourceTree = ""; }; + A14337FB29A9D314007A5959 /* ripemd160.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ripemd160.h; sourceTree = ""; }; + A14337FC29A9D314007A5959 /* blowfish.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = blowfish.h; sourceTree = ""; }; + A14337FD29A9D314007A5959 /* debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = debug.h; sourceTree = ""; }; + A14337FE29A9D314007A5959 /* x509.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509.h; sourceTree = ""; }; + A14337FF29A9D314007A5959 /* version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = version.h; sourceTree = ""; }; + A143380029A9D314007A5959 /* ecp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ecp.h; sourceTree = ""; }; + A143380129A9D314007A5959 /* net.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = net.h; sourceTree = ""; }; + A143380229A9D314007A5959 /* cipher_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cipher_internal.h; sourceTree = ""; }; + A143380329A9D314007A5959 /* md_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md_internal.h; sourceTree = ""; }; + A143380429A9D314007A5959 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = base64.h; sourceTree = ""; }; + A143380529A9D314007A5959 /* pkcs11.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pkcs11.h; sourceTree = ""; }; + A143380629A9D314007A5959 /* ssl_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ssl_internal.h; sourceTree = ""; }; + A143380729A9D314007A5959 /* asn1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asn1.h; sourceTree = ""; }; + A143380829A9D314007A5959 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = ""; }; + A143380929A9D314007A5959 /* x509_csr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509_csr.h; sourceTree = ""; }; + A143380A29A9D314007A5959 /* platform_util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform_util.h; sourceTree = ""; }; + A143380B29A9D314007A5959 /* xtea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xtea.h; sourceTree = ""; }; + A143380C29A9D314007A5959 /* poly1305.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = poly1305.h; sourceTree = ""; }; + A143380D29A9D314007A5959 /* threading.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = threading.h; sourceTree = ""; }; + A143380E29A9D314007A5959 /* hkdf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hkdf.h; sourceTree = ""; }; + A143380F29A9D314007A5959 /* compat-1.3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "compat-1.3.h"; sourceTree = ""; }; + A143381029A9D314007A5959 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; + A143381129A9D314007A5959 /* timing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = timing.h; sourceTree = ""; }; + A143381229A9D314007A5959 /* arc4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = arc4.h; sourceTree = ""; }; + A143381329A9D314007A5959 /* chachapoly.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chachapoly.h; sourceTree = ""; }; + A143381429A9D314007A5959 /* sha256.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha256.h; sourceTree = ""; }; + A143381529A9D314007A5959 /* ecdsa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ecdsa.h; sourceTree = ""; }; + A143381629A9D314007A5959 /* nist_kw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nist_kw.h; sourceTree = ""; }; + A143381729A9D314007A5959 /* md.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md.h; sourceTree = ""; }; + A143381829A9D314007A5959 /* cipher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cipher.h; sourceTree = ""; }; + A143381929A9D314007A5959 /* ecjpake.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ecjpake.h; sourceTree = ""; }; + A143381A29A9D314007A5959 /* net_sockets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = net_sockets.h; sourceTree = ""; }; + A143381B29A9D314007A5959 /* entropy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = entropy.h; sourceTree = ""; }; + A143381C29A9D314007A5959 /* pkcs12.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pkcs12.h; sourceTree = ""; }; + A143381D29A9D314007A5959 /* sha512.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha512.h; sourceTree = ""; }; + A143381E29A9D314007A5959 /* bn_mul.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bn_mul.h; sourceTree = ""; }; + A143381F29A9D314007A5959 /* pk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pk.h; sourceTree = ""; }; + A143382029A9D314007A5959 /* ecp_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ecp_internal.h; sourceTree = ""; }; + A143382129A9D314007A5959 /* ssl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ssl.h; sourceTree = ""; }; + A143382229A9D314007A5959 /* platform_time.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform_time.h; sourceTree = ""; }; + A143382329A9D314007A5959 /* camellia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = camellia.h; sourceTree = ""; }; + A143382429A9D314007A5959 /* x509_crt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509_crt.h; sourceTree = ""; }; + A143382529A9D314007A5959 /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = ""; }; + A143382629A9D314007A5959 /* pk_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pk_internal.h; sourceTree = ""; }; + A143382729A9D314007A5959 /* ssl_cookie.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ssl_cookie.h; sourceTree = ""; }; + A143382829A9D314007A5959 /* dhm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dhm.h; sourceTree = ""; }; + A143382929A9D314007A5959 /* ctr_drbg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ctr_drbg.h; sourceTree = ""; }; + A143382A29A9D314007A5959 /* chacha20.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chacha20.h; sourceTree = ""; }; + A143382B29A9D314007A5959 /* des.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = des.h; sourceTree = ""; }; + A143382C29A9D314007A5959 /* x509_crl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = x509_crl.h; sourceTree = ""; }; + A143382D29A9D314007A5959 /* ecdh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ecdh.h; sourceTree = ""; }; + A143382E29A9D314007A5959 /* sha1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha1.h; sourceTree = ""; }; + A143382F29A9D314007A5959 /* gcm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gcm.h; sourceTree = ""; }; + A143383029A9D314007A5959 /* certs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = certs.h; sourceTree = ""; }; + A143383129A9D314007A5959 /* rsa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rsa.h; sourceTree = ""; }; + A143383229A9D314007A5959 /* hmac_drbg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hmac_drbg.h; sourceTree = ""; }; + A143383329A9D314007A5959 /* ssl_ticket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ssl_ticket.h; sourceTree = ""; }; + A143383429A9D314007A5959 /* ssl_ciphersuites.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ssl_ciphersuites.h; sourceTree = ""; }; + A143383529A9D314007A5959 /* ssl_cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ssl_cache.h; sourceTree = ""; }; + A143383629A9D314007A5959 /* cmac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cmac.h; sourceTree = ""; }; + A143383729A9D314007A5959 /* platform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform.h; sourceTree = ""; }; + A143383829A9D314007A5959 /* bignum.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bignum.h; sourceTree = ""; }; + A143383929A9D314007A5959 /* aria.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aria.h; sourceTree = ""; }; + A143383A29A9D314007A5959 /* entropy_poll.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = entropy_poll.h; sourceTree = ""; }; + A143383B29A9D314007A5959 /* asn1write.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asn1write.h; sourceTree = ""; }; + A143383C29A9D314007A5959 /* ccm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ccm.h; sourceTree = ""; }; A1447A3D2821A91400D3DCA4 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; A144AAFD272572A30019CA5F /* stdcrt.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = stdcrt.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A144AAFF272572A30019CA5F /* stdcrt.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stdcrt.h; sourceTree = ""; }; @@ -982,7 +1371,7 @@ A144AB49272572FD0019CA5F /* compat_base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_base64.c; sourceTree = ""; }; A144AB4A272572FD0019CA5F /* compat_sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_sha1.c; sourceTree = ""; }; A144AB4B272572FD0019CA5F /* compat_md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_md5.c; sourceTree = ""; }; - A144AB4D272572FD0019CA5F /* compat_proctol.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_proctol.c; sourceTree = ""; }; + A144AB4D272572FD0019CA5F /* compat_proctl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_proctl.c; sourceTree = ""; }; A144AB4E272572FD0019CA5F /* compat_stdtime.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_stdtime.c; sourceTree = ""; }; A144AB4F272572FD0019CA5F /* compat_argv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_argv.c; sourceTree = ""; }; A144AB50272572FD0019CA5F /* compat_guid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_guid.c; sourceTree = ""; }; @@ -1014,8 +1403,6 @@ A144AB71272572FD0019CA5F /* compat_error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_error.c; sourceTree = ""; }; A14E0619285A30B700DE3EDA /* objectrun.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = objectrun.h; sourceTree = ""; }; A14E061A285A30B700DE3EDA /* objectrun.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = objectrun.cpp; sourceTree = ""; }; - A1681AB8273982CC004CC415 /* httpinstanceimpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = httpinstanceimpl.h; sourceTree = ""; }; - A1681AB9273982CC004CC415 /* httpinstanceimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = httpinstanceimpl.cpp; sourceTree = ""; }; A17163E0271DCD180062A998 /* tableinfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tableinfo.h; sourceTree = ""; }; A17163E1271DCD180062A998 /* dbimpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dbimpl.cpp; sourceTree = ""; }; A17163E2271DCD180062A998 /* stringutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stringutil.h; sourceTree = ""; }; @@ -1047,6 +1434,62 @@ A1BB5B8B2916B47200953939 /* dllmain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dllmain.cpp; sourceTree = ""; }; A1BB5B8C2916B47200953939 /* stdafx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stdafx.h; sourceTree = ""; }; A1BB5B972916B66300953939 /* dllmodule.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = dllmodule.hpp; sourceTree = ""; }; + A1E50F7529A0134400FF65B0 /* evthread_pthread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evthread_pthread.c; sourceTree = ""; }; + A1E50F7629A0134400FF65B0 /* log.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = log.c; sourceTree = ""; }; + A1E50F7729A0134400FF65B0 /* buffer_compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = buffer_compat.h; sourceTree = ""; }; + A1E50F7829A0134400FF65B0 /* changelist-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "changelist-internal.h"; sourceTree = ""; }; + A1E50F7929A0134400FF65B0 /* evmap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evmap.c; sourceTree = ""; }; + A1E50F7A29A0134400FF65B0 /* buffer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = buffer.c; sourceTree = ""; }; + A1E50F7B29A0134400FF65B0 /* evsignal-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "evsignal-internal.h"; sourceTree = ""; }; + A1E50F7C29A0134400FF65B0 /* event-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "event-internal.h"; sourceTree = ""; }; + A1E50F7D29A0134400FF65B0 /* event-config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "event-config.h"; sourceTree = ""; }; + A1E50F7E29A0134400FF65B0 /* listener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = listener.h; sourceTree = ""; }; + A1E50F7F29A0134400FF65B0 /* defer-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "defer-internal.h"; sourceTree = ""; }; + A1E50F8029A0134400FF65B0 /* strlcpy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = strlcpy.c; sourceTree = ""; }; + A1E50F8129A0134400FF65B0 /* event_compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = event_compat.h; sourceTree = ""; }; + A1E50F8329A0134400FF65B0 /* ratelim-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ratelim-internal.h"; sourceTree = ""; }; + A1E50F8429A0134400FF65B0 /* bufferevent_struct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bufferevent_struct.h; sourceTree = ""; }; + A1E50F8529A0134400FF65B0 /* bufferevent_filter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bufferevent_filter.c; sourceTree = ""; }; + A1E50F8629A0134400FF65B0 /* event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = event.h; sourceTree = ""; }; + A1E50F8729A0134400FF65B0 /* evutil_rand.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evutil_rand.c; sourceTree = ""; }; + A1E50F8829A0134400FF65B0 /* evmap-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "evmap-internal.h"; sourceTree = ""; }; + A1E50F8A29A0134400FF65B0 /* evutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = evutil.h; sourceTree = ""; }; + A1E50F8B29A0134400FF65B0 /* bufferevent_pair.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bufferevent_pair.c; sourceTree = ""; }; + A1E50F8C29A0134400FF65B0 /* poll.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = poll.c; sourceTree = ""; }; + A1E50F8D29A0134400FF65B0 /* evport.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evport.c; sourceTree = ""; }; + A1E50F8E29A0134400FF65B0 /* bufferevent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bufferevent.h; sourceTree = ""; }; + A1E50F9029A0134400FF65B0 /* select.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = select.c; sourceTree = ""; }; + A1E50F9129A0134400FF65B0 /* minheap-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "minheap-internal.h"; sourceTree = ""; }; + A1E50F9229A0134400FF65B0 /* evthread-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "evthread-internal.h"; sourceTree = ""; }; + A1E50F9329A0134400FF65B0 /* time-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "time-internal.h"; sourceTree = ""; }; + A1E50F9429A0134500FF65B0 /* evbuffer-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "evbuffer-internal.h"; sourceTree = ""; }; + A1E50F9529A0134500FF65B0 /* bufferevent-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "bufferevent-internal.h"; sourceTree = ""; }; + A1E50F9629A0134500FF65B0 /* buffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = buffer.h; sourceTree = ""; }; + A1E50F9729A0134500FF65B0 /* epolltable-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "epolltable-internal.h"; sourceTree = ""; }; + A1E50F9A29A0134500FF65B0 /* util-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "util-internal.h"; sourceTree = ""; }; + A1E50F9B29A0134500FF65B0 /* ipv6-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ipv6-internal.h"; sourceTree = ""; }; + A1E50F9C29A0134500FF65B0 /* log-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "log-internal.h"; sourceTree = ""; }; + A1E50F9E29A0134500FF65B0 /* keyvalq_struct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = keyvalq_struct.h; sourceTree = ""; }; + A1E50F9F29A0134500FF65B0 /* event.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = event.c; sourceTree = ""; }; + A1E50FA129A0134500FF65B0 /* strlcpy-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "strlcpy-internal.h"; sourceTree = ""; }; + A1E50FA329A0134500FF65B0 /* eventbase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = eventbase.h; sourceTree = ""; }; + A1E50FA429A0134500FF65B0 /* evconfig-private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "evconfig-private.h"; sourceTree = ""; }; + A1E50FA729A0134500FF65B0 /* util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = util.h; sourceTree = ""; }; + A1E50FA929A0134500FF65B0 /* listener.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = listener.c; sourceTree = ""; }; + A1E50FAA29A0134500FF65B0 /* mm-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mm-internal.h"; sourceTree = ""; }; + A1E50FAB29A0134500FF65B0 /* bufferevent.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bufferevent.c; sourceTree = ""; }; + A1E50FAD29A0134500FF65B0 /* evutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evutil.c; sourceTree = ""; }; + A1E50FAE29A0134500FF65B0 /* bufferevent_ratelim.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bufferevent_ratelim.c; sourceTree = ""; }; + A1E50FAF29A0134500FF65B0 /* evthread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evthread.c; sourceTree = ""; }; + A1E50FB429A0134500FF65B0 /* kqueue-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "kqueue-internal.h"; sourceTree = ""; }; + A1E50FB529A0134500FF65B0 /* bufferevent_sock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bufferevent_sock.c; sourceTree = ""; }; + A1E50FB629A0134500FF65B0 /* bufferevent_compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bufferevent_compat.h; sourceTree = ""; }; + A1E50FB729A0134500FF65B0 /* queue-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "queue-internal.h"; sourceTree = ""; }; + A1E50FB829A0134500FF65B0 /* ht-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ht-internal.h"; sourceTree = ""; }; + A1E50FB929A0134500FF65B0 /* kqueue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = kqueue.c; sourceTree = ""; }; + A1E50FBA29A0134500FF65B0 /* event_struct.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = event_struct.h; sourceTree = ""; }; + A1E50FBB29A0134500FF65B0 /* evutil_time.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = evutil_time.c; sourceTree = ""; }; + A1E5100429A0271700FF65B0 /* signal.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = signal.c; sourceTree = ""; }; A1EB047827285B0600214133 /* iuiwindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iuiwindow.h; sourceTree = ""; }; A1EB047A27285B0600214133 /* uidefine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = uidefine.h; sourceTree = ""; }; A1EB047B27285B0600214133 /* iuibase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iuibase.h; sourceTree = ""; }; @@ -1058,14 +1501,11 @@ A1EB048427285B0600214133 /* issh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = issh.h; sourceTree = ""; }; A1EB048B27285B0600214133 /* itimer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = itimer.h; sourceTree = ""; }; A1EB048C27285B0600214133 /* isocket.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = isocket.h; sourceTree = ""; }; - A1EB048D27285B0600214133 /* ifile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ifile.h; sourceTree = ""; }; A1EB048E27285B0600214133 /* iiodevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iiodevice.h; sourceTree = ""; }; A1EB048F27285B0600214133 /* ioperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ioperation.h; sourceTree = ""; }; A1EB049027285B0600214133 /* iframe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iframe.h; sourceTree = ""; }; A1EB049227285B0600214133 /* idatabase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = idatabase.h; sourceTree = ""; }; A1EB049427285B0600214133 /* ilogs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ilogs.h; sourceTree = ""; }; - A1EB049527285B0600214133 /* ilogfilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ilogfilter.h; sourceTree = ""; }; - A1EB049627285B0600214133 /* ilogdatabase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ilogdatabase.h; sourceTree = ""; }; A1EB049827285B0600214133 /* imsgbus.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = imsgbus.h; sourceTree = ""; }; A1EB049927285B0600214133 /* isession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = isession.h; sourceTree = ""; }; A1EB049A27285B0600214133 /* imsg.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = imsg.h; sourceTree = ""; }; @@ -1085,6 +1525,20 @@ A1F6DB6727284749002BF005 /* http_content_type.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_content_type.cpp; sourceTree = ""; }; A1F6DB6827284749002BF005 /* chttpparser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chttpparser.cpp; sourceTree = ""; }; A1F6DB6927284749002BF005 /* http_header.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_header.cpp; sourceTree = ""; }; + A1FAA5BC29BE54CE007FC149 /* bufferevent_ssl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bufferevent_ssl.c; sourceTree = ""; }; + A1FAA5BE29BE5551007FC149 /* ssl-compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ssl-compat.h"; sourceTree = ""; }; + A1FAA5C029BE55A8007FC149 /* bufferevent_ssl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bufferevent_ssl.h; sourceTree = ""; }; + A1FAA5C229BE5982007FC149 /* bufferevent_mbedtls.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bufferevent_mbedtls.c; sourceTree = ""; }; + A1FAA5C429BE59D7007FC149 /* mbedtls-compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mbedtls-compat.h"; sourceTree = ""; }; + A1FC350D29A51010009FDCE9 /* ioev.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ioev.cpp; sourceTree = ""; }; + A1FD41F729A5E57F003B81C5 /* event_posix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = event_posix.c; sourceTree = ""; }; + A1FD41F829A5E57F003B81C5 /* compat_event.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_event.c; sourceTree = ""; }; + A1FD41F929A5E57F003B81C5 /* event_mach.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = event_mach.c; sourceTree = ""; }; + A1FD41FA29A5E57F003B81C5 /* compat_event_iocp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_event_iocp.c; sourceTree = ""; }; + A1FD41FB29A5E57F003B81C5 /* compat_event_kqueue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_event_kqueue.c; sourceTree = ""; }; + A1FD41FC29A5E57F003B81C5 /* compat_event_epoll.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_event_epoll.c; sourceTree = ""; }; + A1FD41FD29A5E57F003B81C5 /* compat_event_util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_event_util.c; sourceTree = ""; }; + A1FD41FE29A5E57F003B81C5 /* event_win32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = event_win32.c; sourceTree = ""; }; A1FEB716288097A200FC2CCD /* compat_evrbtree.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat_evrbtree.c; sourceTree = ""; }; A1FEB718288097C200FC2CCD /* crt_evrbtree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crt_evrbtree.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -1138,6 +1592,7 @@ A126FE4628A01B4D00D95D6C /* runtime.framework in Frameworks */, A107EB9127173C50006A8E8E /* container.framework in Frameworks */, A107EB9D27173C50006A8E8E /* mainview.framework in Frameworks */, + A14338CB29A9D40A007A5959 /* license.framework in Frameworks */, A107EB8927173C50006A8E8E /* asynio.framework in Frameworks */, A144AB98272573EE0019CA5F /* stdcrt.framework in Frameworks */, A107EB9927173C50006A8E8E /* logs.framework in Frameworks */, @@ -1151,8 +1606,10 @@ buildActionMask = 2147483647; files = ( A107EBCE27173DBA006A8E8E /* access.framework in Frameworks */, + A14337A829A9D2E7007A5959 /* nettls.framework in Frameworks */, A126FE2628A01A8100D95D6C /* runtime.framework in Frameworks */, A107EBDA27173DBA006A8E8E /* container.framework in Frameworks */, + A14338CF29A9D413007A5959 /* license.framework in Frameworks */, A107EBE627173DBA006A8E8E /* mainview.framework in Frameworks */, A1BB5B832916B3DD00953939 /* license.framework in Frameworks */, A144AB04272572A30019CA5F /* stdcrt.framework in Frameworks */, @@ -1167,6 +1624,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + A14338D229A9D435007A5959 /* nettls.framework in Frameworks */, A144ABA1272573FE0019CA5F /* stdcrt.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1187,6 +1645,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A143379E29A9D2E7007A5959 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; A1447A382821A91400D3DCA4 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1213,31 +1678,18 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - A10773E9282195930001A1EF /* event */ = { - isa = PBXGroup; - children = ( - A10773EA282195A10001A1EF /* compat_event.c */, - A12411F1288065B300D73A63 /* compat_event_util.c */, - A10773EF282195A10001A1EF /* compat_event_kqueue.c */, - A10773EB282195A10001A1EF /* compat_event_iocp.c */, - A10773EC282195A10001A1EF /* compat_event_epoll.c */, - A12720682881D2B0001ECCC8 /* event_mach.c */, - A1447A272821A85D00D3DCA4 /* event_posix.c */, - A1447A282821A85D00D3DCA4 /* event_win32.c */, - ); - name = event; - sourceTree = ""; - }; A107E8F927172470006A8E8E /* net */ = { isa = PBXGroup; children = ( - A1F6DB5F27284749002BF005 /* http_protocol */, A107E90627172491006A8E8E /* dllmain.cpp */, - A1681AB8273982CC004CC415 /* httpinstanceimpl.h */, - A1681AB9273982CC004CC415 /* httpinstanceimpl.cpp */, A107E90B27172491006A8E8E /* dnsimpl.cpp */, A107E91A27172492006A8E8E /* dnsimpl.h */, + A1F6DB5F27284749002BF005 /* http_protocol */, + A110383E29B8D90A00DD9517 /* http.cpp */, + A110383D29B8D90A00DD9517 /* http.h */, + A107E8FB27172470006A8E8E /* Info.plist */, A107E90827172491006A8E8E /* interface.cpp */, + A107E8FA27172470006A8E8E /* net.h */, A107E90427172491006A8E8E /* netimpl.cpp */, A107E90D27172491006A8E8E /* netimpl.h */, A107E90E27172492006A8E8E /* protocol */, @@ -1246,8 +1698,6 @@ A107E90927172491006A8E8E /* targetver.h */, A107E90C27172491006A8E8E /* websocketimpl.cpp */, A107E90527172491006A8E8E /* websocketimpl.h */, - A107E8FA27172470006A8E8E /* net.h */, - A107E8FB27172470006A8E8E /* Info.plist */, ); path = net; sourceTree = ""; @@ -1273,6 +1723,7 @@ A107E93C27172BA8006A8E8E /* msgbus */ = { isa = PBXGroup; children = ( + A108551329B7C10600A15324 /* msgbuschannel.hpp */, A107E95927172C14006A8E8E /* agent.cpp */, A107E95A27172C14006A8E8E /* agent.h */, A107E94A27172C14006A8E8E /* auth.hpp */, @@ -1403,35 +1854,36 @@ A10B3F542715EBD50003990D /* asynio */ = { isa = PBXGroup; children = ( - A139C4E2285A363200416E98 /* spipeimpl.cpp */, - A139C4E4285A363200416E98 /* spipeimpl.h */, - A139C4E3285A363200416E98 /* tlswrap.h */, - A139C4DE285A350C00416E98 /* pipeimpl.cpp */, - A139C4DD285A350C00416E98 /* pipeimpl.h */, - A139C4DC285A350C00416E98 /* tlswrap.cpp */, - A17A9FFF273AB7750044C30E /* tcpsocketsslimpl.cpp */, - A17AA000273AB7750044C30E /* tcpsocketsslimpl.h */, A10B3F692715EC0C0003990D /* asynframeimpl.cpp */, A10B3F5E2715EC0B0003990D /* asynframeimpl.h */, A10B3F632715EC0C0003990D /* asynio.cpp */, + A10B3F552715EBD50003990D /* asynio.h */, A10B3F6D2715EC0C0003990D /* dllmain.cpp */, - A10B3F5B2715EC0B0003990D /* fileimpl.cpp */, - A10B3F662715EC0C0003990D /* fileimpl.h */, + A1E50F7329A0134400FF65B0 /* event */, + A10B3F562715EBD50003990D /* Info.plist */, A10B3F5C2715EC0B0003990D /* interface.cpp */, + A1FC350D29A51010009FDCE9 /* ioev.cpp */, + A1115E3029A3D885002FFA60 /* ioevdef.h */, A10B3F622715EC0C0003990D /* iooperationimpl.cpp */, A10B3F6A2715EC0C0003990D /* iooperationimpl.h */, + A139C4DE285A350C00416E98 /* pipeimpl.cpp */, + A139C4DD285A350C00416E98 /* pipeimpl.h */, A10B3F602715EC0B0003990D /* ReadMe.txt */, + A139C4E2285A363200416E98 /* spipeimpl.cpp */, + A139C4E4285A363200416E98 /* spipeimpl.h */, A10B3F5D2715EC0B0003990D /* stdafx.h */, A10B3F642715EC0C0003990D /* tcplistensocketimpl.cpp */, A10B3F5F2715EC0B0003990D /* tcplistensocketimpl.h */, A10B3F672715EC0C0003990D /* tcpsocketimpl.cpp */, A10B3F612715EC0B0003990D /* tcpsocketimpl.h */, + A17A9FFF273AB7750044C30E /* tcpsocketsslimpl.cpp */, + A17AA000273AB7750044C30E /* tcpsocketsslimpl.h */, A10B3F682715EC0C0003990D /* timerimpl.cpp */, A10B3F6B2715EC0C0003990D /* timerimpl.h */, + A139C4DC285A350C00416E98 /* tlswrap.cpp */, + A139C4E3285A363200416E98 /* tlswrap.h */, A10B3F652715EC0C0003990D /* udpsocketimpl.cpp */, A10B3F6C2715EC0C0003990D /* udpsocketimpl.h */, - A10B3F552715EBD50003990D /* asynio.h */, - A10B3F562715EBD50003990D /* Info.plist */, ); path = asynio; sourceTree = ""; @@ -1455,6 +1907,7 @@ A1447A3C2821A91400D3DCA4 /* stdcrt_test */, A126FE2028A01A8100D95D6C /* runtime */, A1BB5B7D2916B3DD00953939 /* license */, + A14337A229A9D2E7007A5959 /* nettls */, A1F1D55F27117AE800442CFE /* Frameworks */, ); sourceTree = ""; @@ -1559,6 +2012,173 @@ path = runtime; sourceTree = ""; }; + A14337A229A9D2E7007A5959 /* nettls */ = { + isa = PBXGroup; + children = ( + A14337F429A9D314007A5959 /* nettls */, + A14337AD29A9D314007A5959 /* ssl */, + A14337A329A9D2E7007A5959 /* nettls.h */, + A14337A429A9D2E7007A5959 /* Info.plist */, + ); + path = nettls; + sourceTree = ""; + }; + A14337AD29A9D314007A5959 /* ssl */ = { + isa = PBXGroup; + children = ( + A14337AE29A9D314007A5959 /* x509_create.c */, + A14337AF29A9D314007A5959 /* x509_crt.c */, + A14337B029A9D314007A5959 /* aes.c */, + A14337B129A9D314007A5959 /* ssl_srv.c */, + A14337B229A9D314007A5959 /* camellia.c */, + A14337B329A9D314007A5959 /* pk_wrap.c */, + A14337B429A9D314007A5959 /* pk.c */, + A14337B529A9D314007A5959 /* ecdh.c */, + A14337B629A9D314007A5959 /* ssl_tls.c */, + A14337B729A9D314007A5959 /* x509_crl.c */, + A14337B829A9D314007A5959 /* cipher_wrap.c */, + A14337B929A9D314007A5959 /* chacha20.c */, + A14337BA29A9D314007A5959 /* des.c */, + A14337BB29A9D314007A5959 /* ssl_cookie.c */, + A14337BC29A9D314007A5959 /* ctr_drbg.c */, + A14337BD29A9D314007A5959 /* dhm.c */, + A14337BE29A9D314007A5959 /* ssl_cache.c */, + A14337BF29A9D314007A5959 /* ssl_ciphersuites.c */, + A14337C029A9D314007A5959 /* hmac_drbg.c */, + A14337C129A9D314007A5959 /* rsa.c */, + A14337C229A9D314007A5959 /* ssl_ticket.c */, + A14337C329A9D314007A5959 /* asn1parse.c */, + A14337C429A9D314007A5959 /* certs.c */, + A14337C529A9D314007A5959 /* pkwrite.c */, + A14337C629A9D314007A5959 /* gcm.c */, + A14337C729A9D314007A5959 /* sha1.c */, + A14337C829A9D314007A5959 /* asn1write.c */, + A14337C929A9D314007A5959 /* ccm.c */, + A14337CA29A9D314007A5959 /* version_features.c */, + A14337CB29A9D314007A5959 /* entropy_poll.c */, + A14337CC29A9D314007A5959 /* x509write_csr.c */, + A14337CD29A9D314007A5959 /* platform.c */, + A14337CE29A9D314007A5959 /* cmac.c */, + A14337CF29A9D314007A5959 /* bignum.c */, + A14337D029A9D314007A5959 /* pkparse.c */, + A14337D129A9D314007A5959 /* debug.c */, + A14337D229A9D314007A5959 /* ripemd160.c */, + A14337D329A9D314007A5959 /* ssl_cli.c */, + A14337D429A9D314007A5959 /* blowfish.c */, + A14337D529A9D314007A5959 /* rsa_internal.c */, + A14337D629A9D314007A5959 /* pkcs5.c */, + A14337D729A9D314007A5959 /* pem.c */, + A14337D829A9D314007A5959 /* oid.c */, + A14337D929A9D314007A5959 /* error.c */, + A14337DA29A9D314007A5959 /* md_wrap.c */, + A14337DB29A9D314007A5959 /* x509_csr.c */, + A14337DC29A9D314007A5959 /* platform_util.c */, + A14337DD29A9D314007A5959 /* pkcs11.c */, + A14337DE29A9D314007A5959 /* base64.c */, + A14337DF29A9D314007A5959 /* ecp.c */, + A14337E029A9D314007A5959 /* version.c */, + A14337E129A9D314007A5959 /* x509.c */, + A14337E229A9D314007A5959 /* chachapoly.c */, + A14337E329A9D314007A5959 /* sha256.c */, + A14337E429A9D314007A5959 /* ecp_curves.c */, + A14337E529A9D314007A5959 /* md5.c */, + A14337E629A9D314007A5959 /* arc4.c */, + A14337E729A9D314007A5959 /* poly1305.c */, + A14337E829A9D314007A5959 /* xtea.c */, + A14337E929A9D314007A5959 /* x509write_crt.c */, + A14337EA29A9D314007A5959 /* hkdf.c */, + A14337EB29A9D314007A5959 /* pkcs12.c */, + A14337EC29A9D314007A5959 /* entropy.c */, + A14337ED29A9D314007A5959 /* net_sockets.c */, + A14337EE29A9D314007A5959 /* sha512.c */, + A14337EF29A9D314007A5959 /* md.c */, + A14337F029A9D314007A5959 /* ecjpake.c */, + A14337F129A9D314007A5959 /* cipher.c */, + A14337F229A9D314007A5959 /* ecdsa.c */, + A14337F329A9D314007A5959 /* nist_kw.c */, + ); + path = ssl; + sourceTree = ""; + }; + A14337F429A9D314007A5959 /* nettls */ = { + isa = PBXGroup; + children = ( + A14337F529A9D314007A5959 /* pem.h */, + A14337F629A9D314007A5959 /* check_config.h */, + A14337F729A9D314007A5959 /* error.h */, + A14337F829A9D314007A5959 /* oid.h */, + A14337F929A9D314007A5959 /* rsa_internal.h */, + A14337FA29A9D314007A5959 /* pkcs5.h */, + A14337FB29A9D314007A5959 /* ripemd160.h */, + A14337FC29A9D314007A5959 /* blowfish.h */, + A14337FD29A9D314007A5959 /* debug.h */, + A14337FE29A9D314007A5959 /* x509.h */, + A14337FF29A9D314007A5959 /* version.h */, + A143380029A9D314007A5959 /* ecp.h */, + A143380129A9D314007A5959 /* net.h */, + A143380229A9D314007A5959 /* cipher_internal.h */, + A143380329A9D314007A5959 /* md_internal.h */, + A143380429A9D314007A5959 /* base64.h */, + A143380529A9D314007A5959 /* pkcs11.h */, + A143380629A9D314007A5959 /* ssl_internal.h */, + A143380729A9D314007A5959 /* asn1.h */, + A143380829A9D314007A5959 /* config.h */, + A143380929A9D314007A5959 /* x509_csr.h */, + A143380A29A9D314007A5959 /* platform_util.h */, + A143380B29A9D314007A5959 /* xtea.h */, + A143380C29A9D314007A5959 /* poly1305.h */, + A143380D29A9D314007A5959 /* threading.h */, + A143380E29A9D314007A5959 /* hkdf.h */, + A143380F29A9D314007A5959 /* compat-1.3.h */, + A143381029A9D314007A5959 /* md5.h */, + A143381129A9D314007A5959 /* timing.h */, + A143381229A9D314007A5959 /* arc4.h */, + A143381329A9D314007A5959 /* chachapoly.h */, + A143381429A9D314007A5959 /* sha256.h */, + A143381529A9D314007A5959 /* ecdsa.h */, + A143381629A9D314007A5959 /* nist_kw.h */, + A143381729A9D314007A5959 /* md.h */, + A143381829A9D314007A5959 /* cipher.h */, + A143381929A9D314007A5959 /* ecjpake.h */, + A143381A29A9D314007A5959 /* net_sockets.h */, + A143381B29A9D314007A5959 /* entropy.h */, + A143381C29A9D314007A5959 /* pkcs12.h */, + A143381D29A9D314007A5959 /* sha512.h */, + A143381E29A9D314007A5959 /* bn_mul.h */, + A143381F29A9D314007A5959 /* pk.h */, + A143382029A9D314007A5959 /* ecp_internal.h */, + A143382129A9D314007A5959 /* ssl.h */, + A143382229A9D314007A5959 /* platform_time.h */, + A143382329A9D314007A5959 /* camellia.h */, + A143382429A9D314007A5959 /* x509_crt.h */, + A143382529A9D314007A5959 /* aes.h */, + A143382629A9D314007A5959 /* pk_internal.h */, + A143382729A9D314007A5959 /* ssl_cookie.h */, + A143382829A9D314007A5959 /* dhm.h */, + A143382929A9D314007A5959 /* ctr_drbg.h */, + A143382A29A9D314007A5959 /* chacha20.h */, + A143382B29A9D314007A5959 /* des.h */, + A143382C29A9D314007A5959 /* x509_crl.h */, + A143382D29A9D314007A5959 /* ecdh.h */, + A143382E29A9D314007A5959 /* sha1.h */, + A143382F29A9D314007A5959 /* gcm.h */, + A143383029A9D314007A5959 /* certs.h */, + A143383129A9D314007A5959 /* rsa.h */, + A143383229A9D314007A5959 /* hmac_drbg.h */, + A143383329A9D314007A5959 /* ssl_ticket.h */, + A143383429A9D314007A5959 /* ssl_ciphersuites.h */, + A143383529A9D314007A5959 /* ssl_cache.h */, + A143383629A9D314007A5959 /* cmac.h */, + A143383729A9D314007A5959 /* platform.h */, + A143383829A9D314007A5959 /* bignum.h */, + A143383929A9D314007A5959 /* aria.h */, + A143383A29A9D314007A5959 /* entropy_poll.h */, + A143383B29A9D314007A5959 /* asn1write.h */, + A143383C29A9D314007A5959 /* ccm.h */, + ); + path = nettls; + sourceTree = ""; + }; A1447A3C2821A91400D3DCA4 /* stdcrt_test */ = { isa = PBXGroup; children = ( @@ -1579,7 +2199,7 @@ A144AAFE272572A30019CA5F /* stdcrt */ = { isa = PBXGroup; children = ( - A10773E9282195930001A1EF /* event */, + A1FD41F629A5E57F003B81C5 /* event */, A144AB48272572FD0019CA5F /* algorithm */, A144AB6E272572FD0019CA5F /* code */, A144AB71272572FD0019CA5F /* compat_error.c */, @@ -1697,7 +2317,7 @@ A128C5FA2879C43C009F8396 /* compat_avl.c */, A128C5F92879C43C009F8396 /* compat_clock.c */, A1021BA8286E03AC003DE34E /* compat_rbtree.c */, - A144AB4D272572FD0019CA5F /* compat_proctol.c */, + A144AB4D272572FD0019CA5F /* compat_proctl.c */, A144AB4E272572FD0019CA5F /* compat_stdtime.c */, A144AB4F272572FD0019CA5F /* compat_argv.c */, A144AB50272572FD0019CA5F /* compat_guid.c */, @@ -1795,6 +2415,77 @@ path = license; sourceTree = ""; }; + A1E50F7329A0134400FF65B0 /* event */ = { + isa = PBXGroup; + children = ( + A1FAA5C429BE59D7007FC149 /* mbedtls-compat.h */, + A1FAA5C229BE5982007FC149 /* bufferevent_mbedtls.c */, + A1E50F7729A0134400FF65B0 /* buffer_compat.h */, + A1E50F7A29A0134400FF65B0 /* buffer.c */, + A1E50F9629A0134500FF65B0 /* buffer.h */, + A1E50FB629A0134500FF65B0 /* bufferevent_compat.h */, + A1E50F8529A0134400FF65B0 /* bufferevent_filter.c */, + A1E50F8B29A0134400FF65B0 /* bufferevent_pair.c */, + A1E50FAE29A0134500FF65B0 /* bufferevent_ratelim.c */, + A1E50FB529A0134500FF65B0 /* bufferevent_sock.c */, + A1FAA5BC29BE54CE007FC149 /* bufferevent_ssl.c */, + A1FAA5C029BE55A8007FC149 /* bufferevent_ssl.h */, + A1E50F8429A0134400FF65B0 /* bufferevent_struct.h */, + A1E50F9529A0134500FF65B0 /* bufferevent-internal.h */, + A1E50FAB29A0134500FF65B0 /* bufferevent.c */, + A1E50F8E29A0134400FF65B0 /* bufferevent.h */, + A1E50F7829A0134400FF65B0 /* changelist-internal.h */, + A1E50F7F29A0134400FF65B0 /* defer-internal.h */, + A1E50F9729A0134500FF65B0 /* epolltable-internal.h */, + A1E50F9429A0134500FF65B0 /* evbuffer-internal.h */, + A13D08B829A1783A00AA7830 /* evconfig-internal.h */, + A1E50FA429A0134500FF65B0 /* evconfig-private.h */, + A13D08B629A177C900AA7830 /* evconfig.h */, + A1E50F8129A0134400FF65B0 /* event_compat.h */, + A1E50FBA29A0134500FF65B0 /* event_struct.h */, + A1E50F7D29A0134400FF65B0 /* event-config.h */, + A1E50F7C29A0134400FF65B0 /* event-internal.h */, + A1E50F9F29A0134500FF65B0 /* event.c */, + A1E50F8629A0134400FF65B0 /* event.h */, + A1E50FA329A0134500FF65B0 /* eventbase.h */, + A1E50F8829A0134400FF65B0 /* evmap-internal.h */, + A1E50F7929A0134400FF65B0 /* evmap.c */, + A1E50F8D29A0134400FF65B0 /* evport.c */, + A1E50F7B29A0134400FF65B0 /* evsignal-internal.h */, + A1E50F7529A0134400FF65B0 /* evthread_pthread.c */, + A1E50F9229A0134400FF65B0 /* evthread-internal.h */, + A1E50FAF29A0134500FF65B0 /* evthread.c */, + A1E50F8729A0134400FF65B0 /* evutil_rand.c */, + A1E50FBB29A0134500FF65B0 /* evutil_time.c */, + A1E50FAD29A0134500FF65B0 /* evutil.c */, + A1E50F8A29A0134400FF65B0 /* evutil.h */, + A1E50FB829A0134500FF65B0 /* ht-internal.h */, + A1E50F9B29A0134500FF65B0 /* ipv6-internal.h */, + A1E50F9E29A0134500FF65B0 /* keyvalq_struct.h */, + A1E50FB429A0134500FF65B0 /* kqueue-internal.h */, + A1E50FB929A0134500FF65B0 /* kqueue.c */, + A1E50FA929A0134500FF65B0 /* listener.c */, + A1E50F7E29A0134400FF65B0 /* listener.h */, + A1E50F9C29A0134500FF65B0 /* log-internal.h */, + A1E50F7629A0134400FF65B0 /* log.c */, + A1E50F9129A0134400FF65B0 /* minheap-internal.h */, + A1E50FAA29A0134500FF65B0 /* mm-internal.h */, + A1E50F8C29A0134400FF65B0 /* poll.c */, + A1E50FB729A0134500FF65B0 /* queue-internal.h */, + A1E50F8329A0134400FF65B0 /* ratelim-internal.h */, + A1E50F9029A0134400FF65B0 /* select.c */, + A1E5100429A0271700FF65B0 /* signal.c */, + A1FAA5BE29BE5551007FC149 /* ssl-compat.h */, + A1E50FA129A0134500FF65B0 /* strlcpy-internal.h */, + A1E50F8029A0134400FF65B0 /* strlcpy.c */, + A13D08BA29A1846000AA7830 /* thread-internal.h */, + A1E50F9329A0134400FF65B0 /* time-internal.h */, + A1E50F9A29A0134500FF65B0 /* util-internal.h */, + A1E50FA729A0134500FF65B0 /* util.h */, + ); + path = event; + sourceTree = ""; + }; A1EB047527285B0600214133 /* extensions */ = { isa = PBXGroup; children = ( @@ -1843,9 +2534,9 @@ A1EB048A27285B0600214133 /* io */ = { isa = PBXGroup; children = ( + A110383C29B8D5D000DD9517 /* ipipe.h */, A1EB048B27285B0600214133 /* itimer.h */, A1EB048C27285B0600214133 /* isocket.h */, - A1EB048D27285B0600214133 /* ifile.h */, A1EB048E27285B0600214133 /* iiodevice.h */, A1EB048F27285B0600214133 /* ioperation.h */, A1EB049027285B0600214133 /* iframe.h */, @@ -1865,8 +2556,6 @@ isa = PBXGroup; children = ( A1EB049427285B0600214133 /* ilogs.h */, - A1EB049527285B0600214133 /* ilogfilter.h */, - A1EB049627285B0600214133 /* ilogdatabase.h */, ); path = log; sourceTree = ""; @@ -1905,6 +2594,7 @@ A107EA3F271733E5006A8E8E /* mainview.framework */, A107E93B27172BA8006A8E8E /* msgbus.framework */, A107E8F827172470006A8E8E /* net.framework */, + A14337A129A9D2E7007A5959 /* nettls.framework */, A126FE1F28A01A8100D95D6C /* runtime.framework */, A183964228FB38E20064C7C2 /* stdcrt_test */, A144AAFD272572A30019CA5F /* stdcrt.framework */, @@ -1929,6 +2619,21 @@ path = http_protocol; sourceTree = ""; }; + A1FD41F629A5E57F003B81C5 /* event */ = { + isa = PBXGroup; + children = ( + A1FD41FC29A5E57F003B81C5 /* compat_event_epoll.c */, + A1FD41FA29A5E57F003B81C5 /* compat_event_iocp.c */, + A1FD41FB29A5E57F003B81C5 /* compat_event_kqueue.c */, + A1FD41FD29A5E57F003B81C5 /* compat_event_util.c */, + A1FD41F829A5E57F003B81C5 /* compat_event.c */, + A1FD41F929A5E57F003B81C5 /* event_mach.c */, + A1FD41F729A5E57F003B81C5 /* event_posix.c */, + A1FD41FE29A5E57F003B81C5 /* event_win32.c */, + ); + path = event; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -1951,8 +2656,8 @@ A107E92C27172492006A8E8E /* dns.h in Headers */, A107E92D27172492006A8E8E /* ip.h in Headers */, A1F6DB7127284749002BF005 /* http_content_type.hpp in Headers */, + A110383F29B8D90A00DD9517 /* http.h in Headers */, A1F6DB6D27284749002BF005 /* httputil.h in Headers */, - A1681ABA273982CC004CC415 /* httpinstanceimpl.h in Headers */, A107E92027172492006A8E8E /* targetver.h in Headers */, A1F6DB6E27284749002BF005 /* http_parser.h in Headers */, ); @@ -1967,6 +2672,7 @@ A107E96A27172C14006A8E8E /* targetver.h in Headers */, A107E96B27172C14006A8E8E /* broker.h in Headers */, A107E96227172C14006A8E8E /* producer.h in Headers */, + A108551429B7C10600A15324 /* msgbuschannel.hpp in Headers */, A107E96827172C14006A8E8E /* msgqueue.h in Headers */, A107E96927172C14006A8E8E /* consumer.h in Headers */, A107E95B27172C14006A8E8E /* node.h in Headers */, @@ -2021,18 +2727,59 @@ buildActionMask = 2147483647; files = ( A17AA002273AB7750044C30E /* tcpsocketsslimpl.h in Headers */, - A10B3F792715EC0C0003990D /* fileimpl.h in Headers */, + A1E50FFF29A0134500FF65B0 /* queue-internal.h in Headers */, + A1E50FDF29A0134500FF65B0 /* epolltable-internal.h in Headers */, A139C4E0285A350C00416E98 /* pipeimpl.h in Headers */, A10B3F722715EC0C0003990D /* tcplistensocketimpl.h in Headers */, A10B3F7D2715EC0C0003990D /* iooperationimpl.h in Headers */, + A1E50FE629A0134500FF65B0 /* keyvalq_struct.h in Headers */, + A1E50FC729A0134500FF65B0 /* defer-internal.h in Headers */, A10B3F742715EC0C0003990D /* tcpsocketimpl.h in Headers */, + A1E50FC429A0134500FF65B0 /* event-internal.h in Headers */, + A1E50FCC29A0134500FF65B0 /* bufferevent_struct.h in Headers */, A10B3F7E2715EC0C0003990D /* timerimpl.h in Headers */, + A1E50FEB29A0134500FF65B0 /* eventbase.h in Headers */, + A1E50FE929A0134500FF65B0 /* strlcpy-internal.h in Headers */, + A1E50FC029A0134500FF65B0 /* changelist-internal.h in Headers */, + A1E50FDD29A0134500FF65B0 /* bufferevent-internal.h in Headers */, + A1E50FE429A0134500FF65B0 /* log-internal.h in Headers */, + A1115E3129A3D885002FFA60 /* ioevdef.h in Headers */, + A1E50FD229A0134500FF65B0 /* evutil.h in Headers */, + A13D08B729A177C900AA7830 /* evconfig.h in Headers */, + A1E50FC929A0134500FF65B0 /* event_compat.h in Headers */, + A1E50FD929A0134500FF65B0 /* minheap-internal.h in Headers */, + A1E50FEF29A0134500FF65B0 /* util.h in Headers */, A10B3F7F2715EC0C0003990D /* udpsocketimpl.h in Headers */, + A1E50FC329A0134500FF65B0 /* evsignal-internal.h in Headers */, + A1FAA5BF29BE5551007FC149 /* ssl-compat.h in Headers */, + A1E5100229A0134500FF65B0 /* event_struct.h in Headers */, A139C4E6285A363200416E98 /* tlswrap.h in Headers */, A10B3F712715EC0C0003990D /* asynframeimpl.h in Headers */, + A1E50FDC29A0134500FF65B0 /* evbuffer-internal.h in Headers */, + A1E50FFC29A0134500FF65B0 /* kqueue-internal.h in Headers */, + A1E50FD629A0134500FF65B0 /* bufferevent.h in Headers */, + A1E50FDA29A0134500FF65B0 /* evthread-internal.h in Headers */, + A1E50FD029A0134500FF65B0 /* evmap-internal.h in Headers */, + A1E50FCB29A0134500FF65B0 /* ratelim-internal.h in Headers */, + A13D08B929A1783A00AA7830 /* evconfig-internal.h in Headers */, + A1E50FE329A0134500FF65B0 /* ipv6-internal.h in Headers */, + A13D08BB29A1846000AA7830 /* thread-internal.h in Headers */, + A1FAA5C529BE59D7007FC149 /* mbedtls-compat.h in Headers */, + A1E50FBF29A0134500FF65B0 /* buffer_compat.h in Headers */, + A1E50FDE29A0134500FF65B0 /* buffer.h in Headers */, A10B3F702715EC0C0003990D /* stdafx.h in Headers */, + A1E50FC629A0134500FF65B0 /* listener.h in Headers */, + A1E50FCE29A0134500FF65B0 /* event.h in Headers */, A10B3F572715EBD50003990D /* asynio.h in Headers */, + A1E50FDB29A0134500FF65B0 /* time-internal.h in Headers */, + A1E50FE229A0134500FF65B0 /* util-internal.h in Headers */, + A1E50FEC29A0134500FF65B0 /* evconfig-private.h in Headers */, + A1E5100029A0134500FF65B0 /* ht-internal.h in Headers */, + A1FAA5C129BE55A8007FC149 /* bufferevent_ssl.h in Headers */, A139C4E7285A363200416E98 /* spipeimpl.h in Headers */, + A1E50FFE29A0134500FF65B0 /* bufferevent_compat.h in Headers */, + A1E50FC529A0134500FF65B0 /* event-config.h in Headers */, + A1E50FF229A0134500FF65B0 /* mm-internal.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2066,6 +2813,86 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A143379C29A9D2E7007A5959 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + A14338BB29A9D314007A5959 /* ecdh.h in Headers */, + A14338B829A9D314007A5959 /* chacha20.h in Headers */, + A143389129A9D314007A5959 /* md_internal.h in Headers */, + A143388C29A9D314007A5959 /* x509.h in Headers */, + A14338A629A9D314007A5959 /* cipher.h in Headers */, + A14338CA29A9D314007A5959 /* ccm.h in Headers */, + A143388D29A9D314007A5959 /* version.h in Headers */, + A14338BD29A9D314007A5959 /* gcm.h in Headers */, + A14338A729A9D314007A5959 /* ecjpake.h in Headers */, + A14338C329A9D314007A5959 /* ssl_cache.h in Headers */, + A143389329A9D314007A5959 /* pkcs11.h in Headers */, + A143389F29A9D314007A5959 /* timing.h in Headers */, + A14338AC29A9D314007A5959 /* bn_mul.h in Headers */, + A14338B329A9D314007A5959 /* aes.h in Headers */, + A14338B629A9D314007A5959 /* dhm.h in Headers */, + A14338B129A9D314007A5959 /* camellia.h in Headers */, + A14338BA29A9D314007A5959 /* x509_crl.h in Headers */, + A143388F29A9D314007A5959 /* net.h in Headers */, + A14338AB29A9D314007A5959 /* sha512.h in Headers */, + A14338A929A9D314007A5959 /* entropy.h in Headers */, + A14338B929A9D314007A5959 /* des.h in Headers */, + A143388429A9D314007A5959 /* check_config.h in Headers */, + A143389429A9D314007A5959 /* ssl_internal.h in Headers */, + A143388929A9D314007A5959 /* ripemd160.h in Headers */, + A143389229A9D314007A5959 /* base64.h in Headers */, + A14338C129A9D314007A5959 /* ssl_ticket.h in Headers */, + A14338B029A9D314007A5959 /* platform_time.h in Headers */, + A143389D29A9D314007A5959 /* compat-1.3.h in Headers */, + A14338A529A9D314007A5959 /* md.h in Headers */, + A14338AD29A9D314007A5959 /* pk.h in Headers */, + A14338C529A9D314007A5959 /* platform.h in Headers */, + A143389C29A9D314007A5959 /* hkdf.h in Headers */, + A143389029A9D314007A5959 /* cipher_internal.h in Headers */, + A14338B429A9D314007A5959 /* pk_internal.h in Headers */, + A143388829A9D314007A5959 /* pkcs5.h in Headers */, + A143388629A9D314007A5959 /* oid.h in Headers */, + A14338A329A9D314007A5959 /* ecdsa.h in Headers */, + A14338B229A9D314007A5959 /* x509_crt.h in Headers */, + A14338AA29A9D314007A5959 /* pkcs12.h in Headers */, + A143388A29A9D314007A5959 /* blowfish.h in Headers */, + A143388729A9D314007A5959 /* rsa_internal.h in Headers */, + A14338BC29A9D314007A5959 /* sha1.h in Headers */, + A143388B29A9D314007A5959 /* debug.h in Headers */, + A143389529A9D314007A5959 /* asn1.h in Headers */, + A143389829A9D314007A5959 /* platform_util.h in Headers */, + A14338C229A9D314007A5959 /* ssl_ciphersuites.h in Headers */, + A14338AF29A9D314007A5959 /* ssl.h in Headers */, + A14337A529A9D2E7007A5959 /* nettls.h in Headers */, + A14338A829A9D314007A5959 /* net_sockets.h in Headers */, + A143388E29A9D314007A5959 /* ecp.h in Headers */, + A143389B29A9D314007A5959 /* threading.h in Headers */, + A14338C629A9D314007A5959 /* bignum.h in Headers */, + A14338C829A9D314007A5959 /* entropy_poll.h in Headers */, + A143388329A9D314007A5959 /* pem.h in Headers */, + A14338B729A9D314007A5959 /* ctr_drbg.h in Headers */, + A143389729A9D314007A5959 /* x509_csr.h in Headers */, + A14338BF29A9D314007A5959 /* rsa.h in Headers */, + A14338C729A9D314007A5959 /* aria.h in Headers */, + A143389A29A9D314007A5959 /* poly1305.h in Headers */, + A143388529A9D314007A5959 /* error.h in Headers */, + A14338A029A9D314007A5959 /* arc4.h in Headers */, + A14338AE29A9D314007A5959 /* ecp_internal.h in Headers */, + A14338B529A9D314007A5959 /* ssl_cookie.h in Headers */, + A143389929A9D314007A5959 /* xtea.h in Headers */, + A14338A229A9D314007A5959 /* sha256.h in Headers */, + A14338C429A9D314007A5959 /* cmac.h in Headers */, + A143389E29A9D314007A5959 /* md5.h in Headers */, + A14338BE29A9D314007A5959 /* certs.h in Headers */, + A14338C029A9D314007A5959 /* hmac_drbg.h in Headers */, + A14338A429A9D314007A5959 /* nist_kw.h in Headers */, + A14338A129A9D314007A5959 /* chachapoly.h in Headers */, + A143389629A9D314007A5959 /* config.h in Headers */, + A14338C929A9D314007A5959 /* asn1write.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; A144AAF8272572A30019CA5F /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -2221,6 +3048,7 @@ A107EBAC27173C50006A8E8E /* PBXTargetDependency */, A144AB9B272573EE0019CA5F /* PBXTargetDependency */, A126FE4928A01B4D00D95D6C /* PBXTargetDependency */, + A14338CE29A9D40A007A5959 /* PBXTargetDependency */, ); name = mainuiapp; productName = mainuiapp; @@ -2250,6 +3078,8 @@ A144AB03272572A30019CA5F /* PBXTargetDependency */, A126FE2528A01A8100D95D6C /* PBXTargetDependency */, A1BB5B822916B3DD00953939 /* PBXTargetDependency */, + A14337A729A9D2E7007A5959 /* PBXTargetDependency */, + A14338D129A9D413007A5959 /* PBXTargetDependency */, ); name = mainui; productName = mainui; @@ -2270,6 +3100,7 @@ ); dependencies = ( A144ABA4272573FE0019CA5F /* PBXTargetDependency */, + A14338D529A9D435007A5959 /* PBXTargetDependency */, ); name = asynio; productName = asynio; @@ -2316,6 +3147,24 @@ productReference = A126FE1F28A01A8100D95D6C /* runtime.framework */; productType = "com.apple.product-type.framework"; }; + A14337A029A9D2E7007A5959 /* nettls */ = { + isa = PBXNativeTarget; + buildConfigurationList = A14337AC29A9D2E7007A5959 /* Build configuration list for PBXNativeTarget "nettls" */; + buildPhases = ( + A143379C29A9D2E7007A5959 /* Headers */, + A143379D29A9D2E7007A5959 /* Sources */, + A143379E29A9D2E7007A5959 /* Frameworks */, + A143379F29A9D2E7007A5959 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = nettls; + productName = nettls; + productReference = A14337A129A9D2E7007A5959 /* nettls.framework */; + productType = "com.apple.product-type.framework"; + }; A1447A3A2821A91400D3DCA4 /* stdcrt_test */ = { isa = PBXNativeTarget; buildConfigurationList = A1447A3F2821A91400D3DCA4 /* Build configuration list for PBXNativeTarget "stdcrt_test" */; @@ -2411,6 +3260,9 @@ A126FE1E28A01A8100D95D6C = { CreatedOnToolsVersion = 12.5.1; }; + A14337A029A9D2E7007A5959 = { + CreatedOnToolsVersion = 12.5.1; + }; A1447A3A2821A91400D3DCA4 = { CreatedOnToolsVersion = 12.5.1; }; @@ -2446,6 +3298,7 @@ A107E9E827173276006A8E8E /* access */, A107EA3E271733E5006A8E8E /* mainview */, A1BB5B7B2916B3DD00953939 /* license */, + A14337A029A9D2E7007A5959 /* nettls */, A144AAFC272572A30019CA5F /* stdcrt */, A1447A3A2821A91400D3DCA4 /* stdcrt_test */, ); @@ -2529,6 +3382,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A143379F29A9D2E7007A5959 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; A144AAFB272572A30019CA5F /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -2559,10 +3419,10 @@ A107E92227172492006A8E8E /* dnsimpl.cpp in Sources */, A1F6DB7527284749002BF005 /* http_header.cpp in Sources */, A107E92E27172492006A8E8E /* dns.c in Sources */, + A110384029B8D90A00DD9517 /* http.cpp in Sources */, A107E91B27172492006A8E8E /* netimpl.cpp in Sources */, A107E92B27172492006A8E8E /* ftp.c in Sources */, A1F6DB7327284749002BF005 /* http_content_type.cpp in Sources */, - A1681ABB273982CC004CC415 /* httpinstanceimpl.cpp in Sources */, A107E91D27172492006A8E8E /* dllmain.cpp in Sources */, A107E91F27172492006A8E8E /* interface.cpp in Sources */, A1F6DB7427284749002BF005 /* chttpparser.cpp in Sources */, @@ -2656,18 +3516,41 @@ files = ( A122670927C158A4006D0ACA /* tcpsocketsslimpl.cpp in Sources */, A139C4E5285A363200416E98 /* spipeimpl.cpp in Sources */, + A1FAA5C329BE5982007FC149 /* bufferevent_mbedtls.c in Sources */, + A1E50FCD29A0134500FF65B0 /* bufferevent_filter.c in Sources */, + A1E50FBD29A0134500FF65B0 /* evthread_pthread.c in Sources */, + A1E50FE729A0134500FF65B0 /* event.c in Sources */, A139C4DF285A350C00416E98 /* tlswrap.cpp in Sources */, - A10B3F6E2715EC0C0003990D /* fileimpl.cpp in Sources */, A10B3F7B2715EC0C0003990D /* timerimpl.cpp in Sources */, A139C4E1285A350C00416E98 /* pipeimpl.cpp in Sources */, + A1E50FC829A0134500FF65B0 /* strlcpy.c in Sources */, A10B3F6F2715EC0C0003990D /* interface.cpp in Sources */, + A1E5100329A0134500FF65B0 /* evutil_time.c in Sources */, + A1E50FC129A0134500FF65B0 /* evmap.c in Sources */, + A1E5100529A0271700FF65B0 /* signal.c in Sources */, + A1E50FF629A0134500FF65B0 /* bufferevent_ratelim.c in Sources */, + A1E50FF329A0134500FF65B0 /* bufferevent.c in Sources */, + A1E50FD829A0134500FF65B0 /* select.c in Sources */, A10B3F782715EC0C0003990D /* udpsocketimpl.cpp in Sources */, A10B3F7A2715EC0C0003990D /* tcpsocketimpl.cpp in Sources */, + A1E50FF529A0134500FF65B0 /* evutil.c in Sources */, + A1E50FD329A0134500FF65B0 /* bufferevent_pair.c in Sources */, + A1E50FFD29A0134500FF65B0 /* bufferevent_sock.c in Sources */, + A1E50FF729A0134500FF65B0 /* evthread.c in Sources */, + A1E50FF129A0134500FF65B0 /* listener.c in Sources */, A10B3F762715EC0C0003990D /* asynio.cpp in Sources */, A10B3F7C2715EC0C0003990D /* asynframeimpl.cpp in Sources */, + A1E5100129A0134500FF65B0 /* kqueue.c in Sources */, A10B3F802715EC0C0003990D /* dllmain.cpp in Sources */, + A1E50FD429A0134500FF65B0 /* poll.c in Sources */, + A1FC350E29A51010009FDCE9 /* ioev.cpp in Sources */, + A1E50FD529A0134500FF65B0 /* evport.c in Sources */, A10B3F752715EC0C0003990D /* iooperationimpl.cpp in Sources */, + A1E50FBE29A0134500FF65B0 /* log.c in Sources */, A10B3F772715EC0C0003990D /* tcplistensocketimpl.cpp in Sources */, + A1E50FC229A0134500FF65B0 /* buffer.c in Sources */, + A1E50FCF29A0134500FF65B0 /* evutil_rand.c in Sources */, + A1FAA5BD29BE54CE007FC149 /* bufferevent_ssl.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2700,6 +3583,83 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A143379D29A9D2E7007A5959 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A143387C29A9D314007A5959 /* net_sockets.c in Sources */, + A143385C29A9D314007A5959 /* platform.c in Sources */, + A143385629A9D314007A5959 /* sha1.c in Sources */, + A143384A29A9D314007A5959 /* ssl_cookie.c in Sources */, + A143386329A9D314007A5959 /* blowfish.c in Sources */, + A143386029A9D314007A5959 /* debug.c in Sources */, + A143385529A9D314007A5959 /* gcm.c in Sources */, + A143386829A9D314007A5959 /* error.c in Sources */, + A143388029A9D314007A5959 /* cipher.c in Sources */, + A143388129A9D314007A5959 /* ecdsa.c in Sources */, + A143386B29A9D314007A5959 /* platform_util.c in Sources */, + A143385F29A9D314007A5959 /* pkparse.c in Sources */, + A143384329A9D314007A5959 /* pk.c in Sources */, + A143386929A9D314007A5959 /* md_wrap.c in Sources */, + A143387129A9D314007A5959 /* chachapoly.c in Sources */, + A143386129A9D314007A5959 /* ripemd160.c in Sources */, + A143386429A9D314007A5959 /* rsa_internal.c in Sources */, + A143387729A9D314007A5959 /* xtea.c in Sources */, + A143387029A9D314007A5959 /* x509.c in Sources */, + A143384529A9D314007A5959 /* ssl_tls.c in Sources */, + A143387229A9D314007A5959 /* sha256.c in Sources */, + A143383F29A9D314007A5959 /* aes.c in Sources */, + A143387629A9D314007A5959 /* poly1305.c in Sources */, + A143386529A9D314007A5959 /* pkcs5.c in Sources */, + A143387E29A9D314007A5959 /* md.c in Sources */, + A143387A29A9D314007A5959 /* pkcs12.c in Sources */, + A143385029A9D314007A5959 /* rsa.c in Sources */, + A143383D29A9D314007A5959 /* x509_create.c in Sources */, + A143385A29A9D314007A5959 /* entropy_poll.c in Sources */, + A143385D29A9D314007A5959 /* cmac.c in Sources */, + A143384729A9D314007A5959 /* cipher_wrap.c in Sources */, + A143386629A9D314007A5959 /* pem.c in Sources */, + A143384829A9D314007A5959 /* chacha20.c in Sources */, + A143386D29A9D314007A5959 /* base64.c in Sources */, + A143385429A9D314007A5959 /* pkwrite.c in Sources */, + A143387429A9D314007A5959 /* md5.c in Sources */, + A143384D29A9D314007A5959 /* ssl_cache.c in Sources */, + A143385E29A9D314007A5959 /* bignum.c in Sources */, + A143385329A9D314007A5959 /* certs.c in Sources */, + A143384B29A9D314007A5959 /* ctr_drbg.c in Sources */, + A143386729A9D314007A5959 /* oid.c in Sources */, + A143384429A9D314007A5959 /* ecdh.c in Sources */, + A143385B29A9D314007A5959 /* x509write_csr.c in Sources */, + A143387F29A9D314007A5959 /* ecjpake.c in Sources */, + A143386A29A9D314007A5959 /* x509_csr.c in Sources */, + A143385129A9D314007A5959 /* ssl_ticket.c in Sources */, + A143387B29A9D314007A5959 /* entropy.c in Sources */, + A143384F29A9D314007A5959 /* hmac_drbg.c in Sources */, + A143386229A9D314007A5959 /* ssl_cli.c in Sources */, + A143386E29A9D314007A5959 /* ecp.c in Sources */, + A143385829A9D314007A5959 /* ccm.c in Sources */, + A143387929A9D314007A5959 /* hkdf.c in Sources */, + A143384E29A9D314007A5959 /* ssl_ciphersuites.c in Sources */, + A143387D29A9D314007A5959 /* sha512.c in Sources */, + A143387829A9D314007A5959 /* x509write_crt.c in Sources */, + A143384229A9D314007A5959 /* pk_wrap.c in Sources */, + A143386F29A9D314007A5959 /* version.c in Sources */, + A143388229A9D314007A5959 /* nist_kw.c in Sources */, + A143384029A9D314007A5959 /* ssl_srv.c in Sources */, + A143385929A9D314007A5959 /* version_features.c in Sources */, + A143385229A9D314007A5959 /* asn1parse.c in Sources */, + A143384629A9D314007A5959 /* x509_crl.c in Sources */, + A143387529A9D314007A5959 /* arc4.c in Sources */, + A143383E29A9D314007A5959 /* x509_crt.c in Sources */, + A143385729A9D314007A5959 /* asn1write.c in Sources */, + A143386C29A9D314007A5959 /* pkcs11.c in Sources */, + A143387329A9D314007A5959 /* ecp_curves.c in Sources */, + A143384129A9D314007A5959 /* camellia.c in Sources */, + A143384929A9D314007A5959 /* des.c in Sources */, + A143384C29A9D314007A5959 /* dhm.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; A1447A372821A91400D3DCA4 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2721,19 +3681,19 @@ buildActionMask = 2147483647; files = ( A144AB80272572FD0019CA5F /* compat_wstr.c in Sources */, - A1447A2B2821A85D00D3DCA4 /* event_win32.c in Sources */, A144AB8C272572FD0019CA5F /* compat_thread.c in Sources */, - A10773F0282195A20001A1EF /* compat_event.c in Sources */, - A10773F1282195A20001A1EF /* compat_event_iocp.c in Sources */, A144AB90272572FD0019CA5F /* compat_mutex.c in Sources */, A144AB87272572FD0019CA5F /* compat_sockinet.c in Sources */, - A12720692881D2B0001ECCC8 /* event_mach.c in Sources */, A144AB77272572FD0019CA5F /* compat_stdtime.c in Sources */, A144AB84272572FD0019CA5F /* compat_path.c in Sources */, + A1FD420529A5E57F003B81C5 /* compat_event_util.c in Sources */, + A1FD41FF29A5E57F003B81C5 /* event_posix.c in Sources */, A128C5FB2879C43C009F8396 /* compat_clock.c in Sources */, A144AB86272572FD0019CA5F /* compat_utf8.c in Sources */, A128C5FC2879C43C009F8396 /* compat_avl.c in Sources */, A126FDE528A015AF00D95D6C /* compat_alloc.c in Sources */, + A1FD420129A5E57F003B81C5 /* event_mach.c in Sources */, + A1FD420329A5E57F003B81C5 /* compat_event_kqueue.c in Sources */, A183964428FB3B4C0064C7C2 /* compat_aes.c in Sources */, A144AB7C272572FD0019CA5F /* compat_list.c in Sources */, A1021BA9286E03AC003DE34E /* compat_rbtree.c in Sources */, @@ -2744,30 +3704,30 @@ A144AB82272572FD0019CA5F /* compat_atomic.c in Sources */, A144AB7A272572FD0019CA5F /* compat_str.c in Sources */, A144AB7F272572FD0019CA5F /* compat_queue.c in Sources */, + A1FD420629A5E57F003B81C5 /* event_win32.c in Sources */, A144AB8D272572FD0019CA5F /* compat_sem.c in Sources */, A144AB78272572FD0019CA5F /* compat_argv.c in Sources */, - A12411F3288065B300D73A63 /* compat_event_util.c in Sources */, A144AB8B272572FD0019CA5F /* compat_rwlock.c in Sources */, A144AB73272572FD0019CA5F /* compat_base64.c in Sources */, A144AB83272572FD0019CA5F /* compat_msghdr.c in Sources */, A144AB81272572FD0019CA5F /* compat_var.c in Sources */, A144AB8E272572FD0019CA5F /* compat_barrier.c in Sources */, - A10773F5282195A20001A1EF /* compat_event_kqueue.c in Sources */, - A1447A2A2821A85D00D3DCA4 /* event_posix.c in Sources */, A144AB75272572FD0019CA5F /* compat_md5.c in Sources */, + A1FD420229A5E57F003B81C5 /* compat_event_iocp.c in Sources */, A144AB8F272572FD0019CA5F /* compat_cond.c in Sources */, A1FEB717288097A200FC2CCD /* compat_evrbtree.c in Sources */, A144AB7D272572FD0019CA5F /* compat_memory.c in Sources */, A144AB7B272572FD0019CA5F /* compat_array.c in Sources */, A126FDE428A015AF00D95D6C /* compat_vsnprintf.c in Sources */, + A1FD420029A5E57F003B81C5 /* compat_event.c in Sources */, A144AB72272572FD0019CA5F /* compat_log.c in Sources */, - A10773F2282195A20001A1EF /* compat_event_epoll.c in Sources */, A144AB88272572FD0019CA5F /* compat_sock.c in Sources */, + A1FD420429A5E57F003B81C5 /* compat_event_epoll.c in Sources */, A144AB85272572FD0019CA5F /* compat_file.c in Sources */, A144AB89272572FD0019CA5F /* compat_init.c in Sources */, A144AB93272572FD0019CA5F /* compat_error.c in Sources */, A144AB7E272572FD0019CA5F /* compat_dll.c in Sources */, - A144AB76272572FD0019CA5F /* compat_proctol.c in Sources */, + A144AB76272572FD0019CA5F /* compat_proctl.c in Sources */, A144AB91272572FD0019CA5F /* compat_cjson.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2875,6 +3835,26 @@ isa = PBXTargetDependency; targetProxy = A1351FAF2720548D0080B9B4 /* PBXContainerItemProxy */; }; + A14337A729A9D2E7007A5959 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = A14337A029A9D2E7007A5959 /* nettls */; + targetProxy = A14337A629A9D2E7007A5959 /* PBXContainerItemProxy */; + }; + A14338CE29A9D40A007A5959 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = A1BB5B7B2916B3DD00953939 /* license */; + targetProxy = A14338CD29A9D40A007A5959 /* PBXContainerItemProxy */; + }; + A14338D129A9D413007A5959 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = A1BB5B7B2916B3DD00953939 /* license */; + targetProxy = A14338D029A9D413007A5959 /* PBXContainerItemProxy */; + }; + A14338D529A9D435007A5959 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = A14337A029A9D2E7007A5959 /* nettls */; + targetProxy = A14338D429A9D435007A5959 /* PBXContainerItemProxy */; + }; A1447A462821A95C00D3DCA4 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = A144AAFC272572A30019CA5F /* stdcrt */; @@ -3417,6 +4397,7 @@ include, 3rd/include, nettls, + event, ); INFOPLIST_FILE = asynio/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -3451,6 +4432,7 @@ include, 3rd/include, nettls, + event, ); INFOPLIST_FILE = asynio/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -3741,6 +4723,76 @@ }; name = Release; }; + A14337AA29A9D2E7007A5959 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = HQK3787VUQ; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = nettls/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = "std-com.nettls"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + A14337AB29A9D2E7007A5959 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = HQK3787VUQ; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = nettls/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 10.10; + PRODUCT_BUNDLE_IDENTIFIER = "std-com.nettls"; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SKIP_INSTALL = YES; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; A1447A402821A91400D3DCA4 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -4017,6 +5069,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + A14337AC29A9D2E7007A5959 /* Build configuration list for PBXNativeTarget "nettls" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A14337AA29A9D2E7007A5959 /* Debug */, + A14337AB29A9D2E7007A5959 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; A1447A3F2821A91400D3DCA4 /* Build configuration list for PBXNativeTarget "stdcrt_test" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/framwork.xcodeproj/project.xcworkspace/xcuserdata/com.app.xcuserdatad/UserInterfaceState.xcuserstate b/framwork.xcodeproj/project.xcworkspace/xcuserdata/com.app.xcuserdatad/UserInterfaceState.xcuserstate index 35031fefbbfc1a78c7d516c383c64d119d6bf801..050f4d2dfa65c87f3895435e9cf8317aeb4b93fa 100644 Binary files a/framwork.xcodeproj/project.xcworkspace/xcuserdata/com.app.xcuserdatad/UserInterfaceState.xcuserstate and b/framwork.xcodeproj/project.xcworkspace/xcuserdata/com.app.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 3ed5c25a4b0fe7d4693f2aaab3844d49aaa65f37..9b7e8d2703cfff69ace93650be37e4c69cb04a79 100644 --- a/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -7,18 +7,34 @@ + + + + diff --git a/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcschemes/xcschememanagement.plist b/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcschemes/xcschememanagement.plist index ec0ebe92e8d002064061b3c24fc73b66b102e648..3fb16395b32e5b24c69538425cb861977564c145 100644 --- a/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/framwork.xcodeproj/xcuserdata/com.app.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ access.xcscheme_^#shared#^_ orderHint - 11 + 9 asynio.xcscheme_^#shared#^_ @@ -27,7 +27,7 @@ logs.xcscheme_^#shared#^_ orderHint - 9 + 8 mainui.xcscheme_^#shared#^_ @@ -50,6 +50,11 @@ 2 net.xcscheme_^#shared#^_ + + orderHint + 13 + + nettls.xcscheme_^#shared#^_ orderHint 10 @@ -57,7 +62,7 @@ runtime.xcscheme_^#shared#^_ orderHint - 8 + 11 std_com.xcscheme_^#shared#^_ diff --git a/include/dlcom/comfactory.hpp b/include/dlcom/comfactory.hpp index 736e9fd0670536172c49f0c942e51e6d22a6e681..7f82ce52f8452ceb9688949c8b6343943724e8d7 100644 --- a/include/dlcom/comfactory.hpp +++ b/include/dlcom/comfactory.hpp @@ -64,10 +64,7 @@ public: } public: - std_method_(HRESULT, CreateInstance)(IBase* pUnkOuter, REFIID riid, void** ppvObject) - { - return CoCreateInstance(pUnkOuter, riid, ppvObject); - } + std_method_(HRESULT, CreateInstance)(IBase* pUnkOuter, REFIID riid, void** ppvObject) { return CoCreateInstance(pUnkOuter, riid, ppvObject); } std_method_(HRESULT, LockServer)(int fLock) { return S_OK; } public: @@ -87,10 +84,7 @@ public: return hr; } - static HRESULT GetClass(const IID& riid, void** ppv) - { - return ClassFactory::CoCreateInstance(0, riid, ppv); - } + static HRESULT GetClass(const IID& riid, void** ppv) { return ClassFactory::CoCreateInstance(0, riid, ppv); } }; } // namespace StdCom diff --git a/include/dlcom/icombase.h b/include/dlcom/icombase.h index 1cc0a276ea40d3ee14ba3e67c9d89ac754b09981..7340c96f169e30616f0631ad710b63dc9a3f5e7f 100644 --- a/include/dlcom/icombase.h +++ b/include/dlcom/icombase.h @@ -122,7 +122,7 @@ interface IObjectRun : public IBase std_method_(UINT, GetArgc)() PURE; std_method_(LPSTRING, GetIndexArgc)(UINT index) PURE; std_method_(UINT, GetStartType)() PURE; - std_method_(_pid_t, GetInstance)() PURE; + std_method_(_pid_t, get_instance)() PURE; }; // {321B84B2-ACE3-4EC4-9E0C-A63870839F07} @@ -139,8 +139,7 @@ interface IMainRun : public IBase std_method(GetObject)(REFCLSID rid, REFCLSID clsid, REFCLSID iid, IBase** ppunk) PURE; std_method(FreeObject)(REFCLSID id, UINT exit) PURE; std_method(Free)(UINT exit) PURE; - std_method(SendMsg)( - REFCLSID rid, REFCLSID gn, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg, IBase** outmsg) PURE; + std_method(SendMsg)(REFCLSID rid, REFCLSID gn, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg, IBase** outmsg) PURE; std_method(SendBroadcastMsg)(REFCLSID gn, REFCLSID sn, REFCLSID tn, UINT msg, IBase* inmsg) PURE; }; diff --git a/include/dlcom/id.hpp b/include/dlcom/id.hpp index 51a661acf797aa0f28b0e22de88170526a220d0c..bc551484f5d73d9cf52465d898e0705452a2a825 100644 --- a/include/dlcom/id.hpp +++ b/include/dlcom/id.hpp @@ -8,9 +8,9 @@ #define _uuidof(iface) (IID_##iface) #define _DEF_IID_IMPL(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ - const IID name = {l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; + const IID name = { l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; #define _DEF_CLSID_IMPL(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ - const GUID name = {l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; + const GUID name = { l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; #endif diff --git a/include/dlcom/loadcom.hpp b/include/dlcom/loadcom.hpp index a1c4e6852f83139d13745b3613f2c43b3f5b016a..5e620c468da74090ab0082c39289a130b3403b7b 100644 --- a/include/dlcom/loadcom.hpp +++ b/include/dlcom/loadcom.hpp @@ -4,7 +4,7 @@ #include #include -class CComLoader : protected dllmodule +class CComLoader : protected CDllmodule { public: DefineDllGetClassObject DllGetClassObject; @@ -121,7 +121,7 @@ public: CLSID GetAt(LONG nIndex) { return this->DllGetAt(nIndex); } LPCSTR ProgIDFromCLSID(REFCLSID clsid) { return this->DllProgIDFromCLSID(clsid); } HRESULT Setup(UINT type, UINT version) { return this->DllSetup(type, version); } - int IsLoaded() { return dllmodule::IsLoaded(); } + int IsLoaded() { return CDllmodule::IsLoaded(); } }; #endif diff --git a/include/dlcom/objectrun.hpp b/include/dlcom/objectrun.hpp index e95e1ca62ee930a32a852d189a495cfebd4a9789..bf84aabd2bd65bc6573f70580bece87b971cba4f 100644 --- a/include/dlcom/objectrun.hpp +++ b/include/dlcom/objectrun.hpp @@ -28,7 +28,7 @@ public: m_pIMainRun.dispose(); basic_tchar szContainerName[DYNAMIC_NAME_LEN + 1] = {0x00}; - GetDynamicName(_T("container"), szContainerName, DYNAMIC_NAME_LEN); + get_dynamicname(_T("container"), szContainerName, DYNAMIC_NAME_LEN); m_strContainer.clear(); m_strContainer.append(path->ptr); @@ -115,8 +115,7 @@ public: return pIObjectRun->Stop(type, exit); } - HRESULT RegisterComponent( - REFCLSID rid, REFCLSID clsid, LPCSTR progid, IBase* pBase, ULONG id, LPCSTR plugin, UINT type) + HRESULT RegisterComponent(REFCLSID rid, REFCLSID clsid, LPCSTR progid, IBase* pBase, ULONG id, LPCSTR plugin, UINT type) { HRESULT hr = S_OK; rc_assert(progid != NULL, E_FAIL); diff --git a/include/utilex/dllmodule.hpp b/include/utilex/dllmodule.hpp index d30328e211cdac3241b4b40473ef3e5eb6f92a5f..2f75b3b9061600ac5e0ce2278c4ae6d8edbb5f3d 100644 --- a/include/utilex/dllmodule.hpp +++ b/include/utilex/dllmodule.hpp @@ -5,7 +5,7 @@ #ifdef __cplusplus -class CPP_NO_VTABLE dllmodule +class CDllmodule { public: struct STFunDesc { @@ -14,13 +14,14 @@ public: }; public: - dllmodule() { m_hMod.dispose(); } - virtual ~dllmodule() { UnLoad(); } + CDllmodule() { m_hMod.dispose(); } + virtual ~CDllmodule() { UnLoad(); } public: virtual void InitIAT() { STFunDesc* pFunDesc = GetFunDefs(); + while (pFunDesc->pFunName) { pFunDesc++; } @@ -29,8 +30,9 @@ public: virtual int Load() { STFunDesc* pFunDesc = GetFunDefs(); - // m_hMod = loadlib(m_szModuleName, RTLD_NOW); + m_hMod = dllopen(m_szModuleName, RTLD_LAZY); + rc_assert(NULL != m_hMod, -1); while (string_stricmp(pFunDesc->pFunName, "null") != 0) { @@ -49,7 +51,8 @@ public: virtual int IsLoaded() { return NULL != m_hMod; } virtual bool Exception(HMODULE hModule, const char* lpProcName) { - debug_view("IImpModuleBase->Exception") return true; + debug_view("IImpModuleBase->Exception"); + return true; } virtual STFunDesc* GetFunDefs() = 0; virtual bool SetFuncAddress(size_t i, void* p) = 0; diff --git a/include/utilex/file.hpp b/include/utilex/file.hpp index d5a8eb99c77c506661adaaa4d24745c81af3778f..fe342f873e9f938d6ae24d857c5309f17fb87dc2 100644 --- a/include/utilex/file.hpp +++ b/include/utilex/file.hpp @@ -8,7 +8,7 @@ static_inline basic_tstring GetExePathString() { basic_tchar szPath[MAX_PATH + 1] = {0x00}; - GetExecutePath(pid_null, szPath, MAX_PATH); + get_executepath(pid_null, szPath, MAX_PATH); basic_tstring strPath(szPath); return strPath; } diff --git a/include/utilex/threadpool.hpp b/include/utilex/threadpool.hpp index 670a400dbd48b05d97b6158ffae80e0e068dc38f..0cd58cd8265828958b55dfa584aeab38f911032f 100644 --- a/include/utilex/threadpool.hpp +++ b/include/utilex/threadpool.hpp @@ -14,16 +14,38 @@ public: { _threadpool_t* parent_context = static_cast<_threadpool_t*>(data); rc_assert(parent_context != NULL, S_ERROR); + CThreadPool* pool = static_cast(parent_context->ctx); rc_assert(pool != NULL, S_ERROR); + pool->ThreadPool_Run(data, ctx); return S_SUCCESS; } - static int startfunccb(void* data, void* ctx) { return S_SUCCESS; } + static int startfunccb(void* data, void* ctx) + { + _threadpool_t* parent_context = static_cast<_threadpool_t*>(data); + rc_assert(parent_context != NULL, S_ERROR); + + CThreadPool* pool = static_cast(parent_context->ctx); + rc_assert(pool != NULL, S_ERROR); + + pool->ThreadPool_Start(); - static int stopfunccb(void* data, void* ctx) { return S_SUCCESS; } + return S_SUCCESS; + } + static int stopfunccb(void* data, void* ctx) + { + _threadpool_t* parent_context = static_cast<_threadpool_t*>(data); + rc_assert(parent_context != NULL, S_ERROR); + + CThreadPool* pool = static_cast(parent_context->ctx); + rc_assert(pool != NULL, S_ERROR); + + pool->ThreadPool_Stop(); + return S_SUCCESS; + } static int errorfunccb(void* data, void* ctx) { return S_SUCCESS; } @@ -40,24 +62,22 @@ public: return CThread::Start_Thread(); } - int StopThreadPool() { return CThread::Stop_Thread(); } + int StopThreadPool() + { + stop_threadpool(&pool); + return CThread::Stop_Thread(); + } std_method(Thread_Init)() { return S_OK; } std_method(Thread_Run)() { - this->ThreadPool_Start(); start_threadpool(&pool); return S_OK; } - std_method(Thread_UnInit)() - { - stop_threadpool(&pool); - this->ThreadPool_Stop(); - return S_OK; - } + std_method(Thread_UnInit)() { return S_OK; } protected: - std_method(ThreadPool_Run)(void* data, void* ctx) PURE; + std_method(ThreadPool_Run)(void* user, void* ctx) PURE; std_method(ThreadPool_Start)() PURE; std_method(ThreadPool_Stop)() PURE; std_method(ThreadPool_Error)() PURE; diff --git a/license/licenseimpl.cpp b/license/licenseimpl.cpp index 6580c985ff21494602e10ad536c940dd88ecb1d0..44e7a0ace7b8bc909ca7f20d81427b2079f5e072 100644 --- a/license/licenseimpl.cpp +++ b/license/licenseimpl.cpp @@ -40,6 +40,3 @@ int CLicenseImpl::GetAppVersion(int index) { return 0; } - - - diff --git a/logs/logdatabase.cpp b/logs/logdatabase.cpp index 16158df6a1dba55874b35541ddf244fbce91c580..78e42fa46943f3a3212e891a3aa9057d6ebabb38 100644 --- a/logs/logdatabase.cpp +++ b/logs/logdatabase.cpp @@ -19,11 +19,11 @@ HRESULT CLogDataBaseImpl::Init(IBase* pRot, IBase* pBase) basic_tstring strDBPath = GetExePathString(); strDBPath += DB_NAME; - //logi("db_name %s", strDBPath.c_str()); + // logi("db_name %s", strDBPath.c_str()); - int rc = FileIsExist(strDBPath.c_str()); + int rc = fileisexist(strDBPath.c_str()); - rc_assert_log(rc == S_SUCCESS, S_OK, "FileIsExist faild"); + rc_assert_log(rc == S_SUCCESS, S_OK, "db NoExist"); return S_OK; } @@ -33,8 +33,6 @@ HRESULT CLogDataBaseImpl::Uninit() } HRESULT CLogDataBaseImpl::Start(_pid_t pid, unsigned int type) { - HRESULT hr = S_OK; - return S_OK; } HRESULT CLogDataBaseImpl::Stop(unsigned int exit) @@ -58,8 +56,6 @@ HRESULT CLogDataBaseImpl::SyncTable(LPCSTR name, IBase* pBase) hr = pBase->QueryInterface(IID_ITableStruct, (void**)&pITableStruct); rc_assert(hr == S_OK, E_FAIL); - UINT Exist = S_ERROR; - m_pMapTableStruct[name] = pITableStruct; return S_OK; @@ -166,8 +162,6 @@ HRESULT CLogDataBaseImpl::CreateTable(LPCSTR name, ITableStruct* pITableStruct) HRESULT CLogDataBaseImpl::Insert(LPCSTR name, cJSON* pRoot, ITableStruct* pITableStruct) { - HRESULT hr = S_OK; - return S_OK; } diff --git a/logs/logsimpl.cpp b/logs/logsimpl.cpp index d89c6d17a2ceb74a59967ec269703513e2b35b34..311e9af7d57f08835d572a78e7c903e492da21f9 100644 --- a/logs/logsimpl.cpp +++ b/logs/logsimpl.cpp @@ -56,8 +56,6 @@ HRESULT CLogsImpl::Stop(unsigned int exit) HRESULT CLogsImpl::PostLog(UCHAR* pBuf, ULONG Size) { - HRESULT hr = S_OK; - rc_assert(pBuf != NULL, E_FAIL); rc_assert(Size != 0, E_FAIL); @@ -120,7 +118,7 @@ void get_file_cb_func(const basic_tchar* szPath, void* context) HRESULT CLogsImpl::GetRuleFiles() { basic_tstring strPath = GetExePathString(); - GetFiles((basic_tchar*)strPath.c_str(), get_file_cb_func, this); + get_files((basic_tchar*)strPath.c_str(), get_file_cb_func, this); return S_OK; } diff --git a/main/main.cpp b/main/main.cpp index b42df9040a4690c5ee46ce0aaa38b3df7431dec0..54f362d1df9de72f3e3abdf2d732ab171295d646 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -17,7 +17,7 @@ void __attribute__((used)) so_section_fini(void) #endif -//#pragma comment(lib, "wsock32.lib") +// #pragma comment(lib, "wsock32.lib") int main_t(_pid_t pid, int argc, basic_tchar* argv[]) { int iRes = 0; diff --git a/mainui/appviewimpl.cpp b/mainui/appviewimpl.cpp index aa7e4484d4502488cdcf51e71c554e1bb1c46c45..7aac29d12ce1cd726faf55fef65f08b1a9f2e809 100644 --- a/mainui/appviewimpl.cpp +++ b/mainui/appviewimpl.cpp @@ -1,5 +1,11 @@ #include "appviewimpl.h" +//{a7957a54-37cb-42a4-9ee8-599168c2a3d1} +_DEF_CLSID_IMPL(CLSID_AppView, 0xA7957A54, 0x37CB, 0x42A4, 0x9E, 0xE8, 0x59, 0x91, 0x68, 0xC2, 0xA3, 0xD1); + +// {9C926805-64F5-4728-86A4-AB0208AA1487} +_DEF_IID_IMPL(IID_ISockProc, 0x9c926805, 0x64f5, 0x4728, 0x86, 0xa4, 0xab, 0x2, 0x8, 0xaa, 0x14, 0x87); + CAppViewImpl::CAppViewImpl(void) { } @@ -25,7 +31,7 @@ HRESULT CAppViewImpl::Start(_pid_t pid, unsigned int type) HRESULT hr = S_OK; /* - NetPtr pINet; + _lComPtr pINet; m_pRot->GetObject(CLSID_INet, IID_INet, (IBase**)&pINet.m_p); rc_assert(pINet.m_p != INULL, E_FAIL) @@ -65,13 +71,32 @@ HRESULT CAppViewImpl::Stop(unsigned int exit) return hr; } +HRESULT CAppViewImpl::OnSockSend(evid id, everr error_code, BUF_PTR buf, BUF_SIZE size) +{ + return S_OK; +} +HRESULT CAppViewImpl::OnSockRecv(evid id, everr error_code, BUF_PTR buf, BUF_SIZE size) +{ + return S_OK; +} +HRESULT CAppViewImpl::OnSockConnect(evid id, everr error_code, _sock_t fd) +{ + return S_OK; +} +HRESULT CAppViewImpl::OnSockEvent(evid id, evid event, everr error_code, _sock_t fd) +{ + return S_OK; +} HRESULT CAppViewImpl::InitBus() { HRESULT hr = S_OK; hr = m_pRot->GetObject(CLSID_CMsgBus, IID_IMsgBus, (IBase**)&m_pIMsgBus); rc_assert(hr == S_OK, E_FAIL); - + + hr = m_pRot->GetObject(CLSID_CAsynFrame, IID_IAsynFrame, (IBase**)&m_pIAsynFrame); + rc_assert(hr == S_OK, E_FAIL); + hr = m_pIMsgBus->CreateNode(NDC_BROKER, (IBase**)&m_pIBroker); rc_assert(hr == S_OK, E_FAIL); @@ -80,24 +105,46 @@ HRESULT CAppViewImpl::InitBus() hr = m_pIMsgBus->CreateNode(NDC_CONSUMER, (IBase**)&m_pIConsumer); rc_assert(hr == S_OK, E_FAIL); - // m_pIConsumer->SetId(_inet_addr_v4("255.254.253.252")); - // m_pIConsumer->Bind("127.0.0.1:8080", s_strlen("127.0.0.1:8080")); + _lComPtr m_pITcpSocketSSL; + hr = m_pIAsynFrame->CreateIo(io_tcp_ssl_socket, (IBase**)&m_pITcpSocketSSL); + rc_assert(hr == S_OK, E_FAIL); + + m_pITcpSocketSSL->CreateSock(); + + _lComPtr pBase; + hr = this->QueryInterface(IID_IBase, (void**)&pBase); + rc_assert(hr == S_OK, E_FAIL); + + m_pITcpSocketSSL->BindEvent(pBase); + + //10.242.68.4 + //172.16.123.131 + m_pITcpSocketSSL->ConnectIo("172.16.123.131", 8443, 5, 5); + + sleep_time(300); + + //m_pIConsumer->SetId(_inet_addr_v4("255.254.253.252")); + //m_pIConsumer->Bind("127.0.0.1:8080", s_strlen("127.0.0.1:8080")); hr = m_pIMsgBus->CreateNode(NDC_PRODUCER, (IBase**)&m_pIProducer); rc_assert(hr == S_OK, E_FAIL); m_pIProducer->SetId(_inet_addr_v4("255.254.253.251")); - m_pIProducer->Bind("127.0.0.1:8080", s_strlen("127.0.0.1:8080")); + //m_pIProducer->Bind("127.0.0.1:8080", s_strlen("127.0.0.1:8080")); hr = m_pIMsgBus->CreateNode(NDC_AGENT, (IBase**)&m_pIAgent); rc_assert(hr == S_OK, E_FAIL); m_pIAgent->SetId(_inet_addr_v4("255.254.253.250")); - m_pIAgent->Bind("127.0.0.1:8080", s_strlen("127.0.0.1:8080")); + //m_pIAgent->Bind("127.0.0.1:8080", s_strlen("127.0.0.1:8080")); int sec = 0; - sec = 10; + sec = 30; + + m_pIBroker->Dispatch(sec); + + sleep_time(30); - return m_pIBroker->Dispatch(sec); + return S_OK; } HRESULT CAppViewImpl::UnInitBus() { diff --git a/mainui/appviewimpl.h b/mainui/appviewimpl.h index a23baa647b501452a3035853270615c4f6134b10..1769f5092e1d513265026e34e5b0a933b91b3c75 100644 --- a/mainui/appviewimpl.h +++ b/mainui/appviewimpl.h @@ -2,16 +2,26 @@ #define _APPVIEWIMPL_H_ #include -#include -#include -#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include //{a7957a54-37cb-42a4-9ee8-599168c2a3d1} -_DEF_CLSID_IMPL(CLSID_AppView, 0xA7957A54, 0x37CB, 0x42A4, 0x9E, 0xE8, 0x59, 0x91, 0x68, 0xC2, 0xA3, 0xD1); +_DEF_CLSID(CLSID_AppView, 0xA7957A54, 0x37CB, 0x42A4, 0x9E, 0xE8, 0x59, 0x91, 0x68, 0xC2, 0xA3, 0xD1); -class CAppViewImpl : public IPlugin, - public IPluginRun, - public CUnknownImp +class CAppViewImpl : public IPlugin, + public IPluginRun, + public ISockProc, + public CUnknownImp { public: CAppViewImpl(void); @@ -22,6 +32,7 @@ public: STDCOM_INTERFACE_ENTRY_UNKNOWN_(IPlugin) STDCOM_INTERFACE_ENTRY(IPlugin) STDCOM_INTERFACE_ENTRY(IPluginRun) + STDCOM_INTERFACE_ENTRY(ISockProc) END_STDCOM_MAP // IPlugin @@ -31,18 +42,24 @@ public: // IPluginRun std_method(Start)(_pid_t pid, unsigned int type); std_method(Stop)(unsigned int exit); - + + // ISockProc + std_method(OnSockSend)(evid id, everr error_code, BUF_PTR buf, BUF_SIZE size); + std_method(OnSockRecv)(evid id, everr error_code, BUF_PTR buf, BUF_SIZE size); + std_method(OnSockConnect)(evid id, everr error_code, _sock_t fd); + std_method(OnSockEvent)(evid id, evid event, everr error_code, _sock_t fd); + HRESULT InitBus(); HRESULT UnInitBus(); private: _lComPtr m_pRot; - HttpInstancePtr m_pIHttp; - MsgBusPtr m_pIMsgBus; - BrokerPtr m_pIBroker; - ConsumerPtr m_pIConsumer; - ProducerPtr m_pIProducer; - AgentPtr m_pIAgent; - AsynFramePtr m_pIAsynFrame; + _lComPtr m_pIAsynFrame; + _lComPtr m_pIHttp; + _lComPtr m_pIMsgBus; + _lComPtr m_pIBroker; + _lComPtr m_pIConsumer; + _lComPtr m_pIProducer; + _lComPtr m_pIAgent; }; #endif diff --git a/mainuiapp/appviewimpl.cpp b/mainuiapp/appviewimpl.cpp index 25557396bb21372da6337ec259808e5b987d2ef1..64bf437c9791d8dfebb2f0c1aa418fa5ccf91da1 100644 --- a/mainuiapp/appviewimpl.cpp +++ b/mainuiapp/appviewimpl.cpp @@ -1,5 +1,4 @@ #include "appviewimpl.h" -#include CAppViewImpl::CAppViewImpl(void) { @@ -25,15 +24,14 @@ HRESULT CAppViewImpl::Start(_pid_t pid, unsigned int type) { HRESULT hr = S_OK; - _lComPtr pINet; + //_lComPtr pINet; + // m_pRot->GetObject(CLSID_INet, IID_INet, (IBase**)&pINet.m_p); + // rc_assert(pINet.m_p != INULL, E_FAIL); - m_pRot->GetObject(CLSID_INet, IID_INet, (IBase**)&pINet.m_p); - rc_assert(pINet.m_p != INULL, E_FAIL); - - pINet->CreateProtocol(protocol_https, (IBase**)&m_pIHttp); - // m_pIHttp->Open("110.242.68.3", "/", 443); - CSemHandle handle; - handle.Wait(); + // pINet->CreateProtocol(protocol_https, (IBase**)&m_pIHttp); + // m_pIHttp->Open("110.242.68.3", "/", 443); + // CSemHandle handle; + // handle.Wait(); return hr; } diff --git a/mainuiapp/appviewimpl.h b/mainuiapp/appviewimpl.h index 740da9a14e76bb51280f770ee45a0464b939cbe1..0c4276ade445ae53fd738d82819664eedf25157f 100644 --- a/mainuiapp/appviewimpl.h +++ b/mainuiapp/appviewimpl.h @@ -2,7 +2,10 @@ #define _APPVIEWIMPL_H_ #include -#include + +#include +#include +#include //{a7957a54-37cb-42a4-9ee8-599168c2a3d1} _DEF_CLSID_IMPL(CLSID_AppView, 0xA7957A54, 0x37CB, 0x42A4, 0x9E, 0xE8, 0x59, 0x91, 0x68, 0xC2, 0xA3, 0xD1) @@ -32,6 +35,6 @@ public: private: _lComPtr m_pRot; - HttpInstancePtr m_pIHttp; + _lComPtr m_pIHttp; }; #endif diff --git a/mainview/mainviewimpl.cpp b/mainview/mainviewimpl.cpp index ffa995fcf5e8c406c5bea6242983195397d8cc60..7f53f1972003d7c2a065d32c485a194d4ab3d6f4 100644 --- a/mainview/mainviewimpl.cpp +++ b/mainview/mainviewimpl.cpp @@ -44,7 +44,7 @@ HRESULT CMainViewImpl::Start(_pid_t pid, unsigned int type) rc_assert(hr == S_OK, E_FAIL); basic_tchar szPath[MAX_PATH + 1] = {0x00}; - GetExecutePath(pid_null, szPath, MAX_PATH); + get_executepath(pid_null, szPath, MAX_PATH); basic_tstring strResFile(szPath); diff --git a/msgbus/agent.cpp b/msgbus/agent.cpp index 6678a06e7b24eabe2366be508b1a6cc83d400e61..221a4456e1ee532f42e5dd23ae8c30a5bc8eb53e 100644 --- a/msgbus/agent.cpp +++ b/msgbus/agent.cpp @@ -74,7 +74,7 @@ HRESULT CAgentImpl::OnConnected(IBase* pIBase) HRESULT hr = S_OK; BUF_PTR ptr = NULL; - hr = this->GetWritePtr(&ptr); + // hr = this->GetWritePtr(&ptr); rc_assert(hr == S_OK, E_FAIL); hr = BusProtocol_Init_Head(ptr, m_id, 0, NDC_PRODUCER, BUS_CONSUMER_VERSION); @@ -83,7 +83,7 @@ HRESULT CAgentImpl::OnConnected(IBase* pIBase) hr = BusProtocol_1st(ptr, BUS_SEQ_VALUE, BUS_NULL_VALUE); rc_assert(hr == S_OK, E_FAIL); - hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ); + // hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -93,7 +93,7 @@ HRESULT CAgentImpl::OnSendSeqed(IBase* pIBase) { HRESULT hr = S_OK; - hr = this->OnReadChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_SEQ_ACK); + // hr = this->OnReadChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_SEQ_ACK); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -103,19 +103,9 @@ HRESULT CAgentImpl::OnRecvSeqAcked(IBase* pIBase) { HRESULT hr = S_OK; - OperationPtr pIOperation; BUF_SIZE TransferedBytes = 0; BUF_PTR ptr = NULL; - hr = GetObject(pIBase, pIOperation); - rc_assert(hr == S_OK, E_FAIL); - - pIOperation->GetTransfered(&TransferedBytes); - rc_assert(TransferedBytes != 0, E_FAIL); - - hr = pIOperation->GetPtr(&ptr); - rc_assert(hr == S_OK, E_FAIL); - unsigned int s = 0; unsigned int a = 0; @@ -127,10 +117,10 @@ HRESULT CAgentImpl::OnRecvSeqAcked(IBase* pIBase) hr = BusProtocol_3rd(ptr, s, a); rc_assert(hr == S_OK, E_FAIL); - hr = this->WriteStream(ptr, 0, BUS_PROTOCOL_HEAD_LEN); + // hr = this->WriteStream(ptr, 0, BUS_PROTOCOL_HEAD_LEN); rc_assert(hr == S_OK, E_FAIL); - hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_ACK); + // hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_ACK); rc_assert(hr == S_OK, E_FAIL); return hr; diff --git a/msgbus/agent.h b/msgbus/agent.h index abfb552b81b056e30841f34155462d9ffc33c5ff..c9ef24d0f70f375c92f1bd302e03e18365bd13b2 100644 --- a/msgbus/agent.h +++ b/msgbus/agent.h @@ -3,10 +3,11 @@ #include "stdafx.h" #include "auth.hpp" +#include "msgbuschannel.hpp" class CAgentImpl : public IAgent, - public IOperationEvent, - public CChannel, + public IOperationProc, + public CMsgbusChannel, public CUnknownImp { @@ -16,7 +17,7 @@ public: BEGIN_STDCOM_MAP STDCOM_INTERFACE_ENTRY_UNKNOWN_(IAgent) - STDCOM_INTERFACE_ENTRY(IOperationEvent) + STDCOM_INTERFACE_ENTRY(IOperationProc) STDCOM_INTERFACE_ENTRY(IAgent) END_STDCOM_MAP @@ -28,7 +29,7 @@ public: std_method(Recv)(IBase* pBase); std_method(Send)(IBase* pBase); - // IOperationEvent + // IOperationProc std_method(OnComplete)(IBase* pOperation, evid event, everr error_code); private: diff --git a/msgbus/auth.hpp b/msgbus/auth.hpp index 05bcbd9deed9e0ed0e864a800edd3d0e79de4374..131d0b80224c204f280209a415ed45d876064d5f 100644 --- a/msgbus/auth.hpp +++ b/msgbus/auth.hpp @@ -179,8 +179,7 @@ static_inline HRESULT BusProtocol_GetValue(unsigned char* data, int offset, unsi return S_OK; } -static_inline HRESULT BusProtocol_Init_Head( - unsigned char* data, unsigned int uid, unsigned int netmask, unsigned int ver, unsigned int type) +static_inline HRESULT BusProtocol_Init_Head(unsigned char* data, unsigned int uid, unsigned int netmask, unsigned int ver, unsigned int type) { rc_assert(data != NULL, E_FAIL); s_memset(data, 0, BUS_PROTOCOL_HEAD_LEN); diff --git a/msgbus/broker.cpp b/msgbus/broker.cpp index b155126a2304ac96b5a54702ae5df9cbabadafc3..40a78872496246eae45921a5f3997486827054e8 100644 --- a/msgbus/broker.cpp +++ b/msgbus/broker.cpp @@ -1,9 +1,10 @@ #include "broker.h" #include "auth.hpp" -#define TIMER_ID 10000 -#define TIMER_ID_CON TIMER_ID + 1 -#define TIMER_ID_HEART TIMER_ID + 2 +#define TIMER_ID 10000 +#define TIMER_ID_CON TIMER_ID + 1 +#define TIMER_ID_HEART TIMER_ID + 2 +#define SCHANENEL_BIND_ADDR_MAXLEN 250 CBrokerImpl::CBrokerImpl(void) { @@ -21,7 +22,26 @@ HRESULT CBrokerImpl::Listen(LPCSTR addr, int len, int maxconn) hr = Init(); rc_assert(hr == S_OK, E_FAIL); - hr = ListenChannel(addr, len); + rc_assert(addr != NULL, E_FAIL); + rc_assert(len != 0, E_FAIL); + + CharArrayPtr item; + item.dispose(); + item = ALLOC_NEW char[SCHANENEL_BIND_ADDR_MAXLEN + 1](); + rc_assert(item.m_p != NULL, E_FAIL); + s_strcpy(item, SCHANENEL_BIND_ADDR_MAXLEN, addr); + + char* port = NULL; + char* ip = NULL; + + ip = s_strtok(item, ":", &port); + rc_assert(ip != NULL, E_FAIL); + rc_assert(port != NULL, E_FAIL); + + hr = m_pIListen->Listen(ip, atoi(port)); + rc_assert(hr == S_OK, E_FAIL); + + hr = m_pIListen->Accept(1); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -30,10 +50,7 @@ HRESULT CBrokerImpl::Dispatch(unsigned int sec) { HRESULT hr = S_OK; - hr = AcceptCChannel(); - rc_assert(hr == S_OK, E_FAIL); - - loge("CBrokerImpl::Dispatch\n"); + loge("CBrokerImpl::Dispatch"); m_sem.WaitTime(sec); @@ -47,7 +64,7 @@ HRESULT CBrokerImpl::Close() hr = UnInit(); rc_assert(hr == S_OK, E_FAIL); - hr = this->SChannel::CloseChannel(); + hr = this->CloseChannel(); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -56,22 +73,10 @@ HRESULT CBrokerImpl::IsListen() { return IsListenChannel(); } -HRESULT CBrokerImpl::Accept(IBase* pBase, _sock_t s, everr error_code) +HRESULT CBrokerImpl::Accept(_sock_t s, SOCKADDR_PTR sa, socklen_t sl, evid error_code) { HRESULT hr = S_OK; - rc_assert(pBase != NULL, E_FAIL); - - if (S_SUCCESS == error_code) { - hr = OnAccepted(pBase, s); - if (S_FAILED(hr)) - goto end; - hr = AcceptCChannel(); - if (S_FAILED(hr)) - goto end; - } -end: - pBase->Release(); return hr; } @@ -106,135 +111,105 @@ HRESULT CBrokerImpl::OnTimer(UINT uId, UINT err) // logi("id==>%u", uId); return S_OK; } -HRESULT CBrokerImpl::OnAccepted(IBase* pBase, _sock_t s) +HRESULT CBrokerImpl::CreateSChannel(IBase* pRot) { HRESULT hr = S_OK; + rc_assert(pRot != NULL, E_FAIL); - TcpSocketPtr pSocket; - - hr = pBase->QueryInterface(IID_ITcpSocket, (void**)&pSocket); + hr = pRot->QueryInterface(IID_IRot, (void**)&m_pRot); rc_assert(hr == S_OK, E_FAIL); - hr = pSocket->AttachSock(s); + hr = m_pRot->GetObject(CLSID_CAsynFrame, IID_IAsynFrame, (IBase**)&m_pIAsynFrame); rc_assert(hr == S_OK, E_FAIL); - OperationPtr WriteOperation; - hr = m_pIAsynFrame->CreateIo(io_operation, (IBase**)&WriteOperation); + hr = m_pIAsynFrame->CreateIo(io_tcplisten_socket, (IBase**)&m_pIListen); rc_assert(hr == S_OK, E_FAIL); - _lComPtr pEventBase; - hr = this->QueryInterface(IID_IBase, (void**)&pEventBase); - rc_assert(hr == S_OK, E_FAIL); + return S_OK; +} +HRESULT CBrokerImpl::OpenCChannel() +{ + HRESULT hr = S_OK; - hr = WriteOperation->BindEvent(pEventBase); + hr = m_pIListen->CreateSock(); rc_assert(hr == S_OK, E_FAIL); - hr = WriteOperation->BindIBase(pBase); + hr = m_pIListen->OpenIo(); rc_assert(hr == S_OK, E_FAIL); - hr = WriteOperation->SetExpect(BUS_PROTOCOL_HEAD_LEN); + hr = m_pIListen->BindIo(); rc_assert(hr == S_OK, E_FAIL); - WriteOperation->AddRef(); - - return S_OK; + return hr; } -HRESULT CBrokerImpl::OnRecvSeqed(IBase* pIBase) +HRESULT CBrokerImpl::CloseChannel() { HRESULT hr = S_OK; - TcpSocketPtr pIScoket; - OperationPtr pIOperation; - hr = GetObject(pIBase, pIScoket, pIOperation); + hr = m_pIListen->CloseIo(CLOSE_BOTH_IO); rc_assert(hr == S_OK, E_FAIL); - BUF_SIZE TransferedBytes = 0; - BUF_PTR ptr = NULL; - - hr = pIOperation->GetTransfered(&TransferedBytes); - rc_assert(TransferedBytes != 0, E_FAIL); - - hr = pIOperation->GetPtr(&ptr); + hr = m_pIListen->CloseSock(); rc_assert(hr == S_OK, E_FAIL); - unsigned int s = 0; - unsigned int a = 0; + hr = m_pIListen->UnBindAccpet(); + rc_assert(hr == S_OK, E_FAIL); - BusProtocol_Get_Seq_Ack(ptr, &s, &a); - // logi("s_recv==>seq:%u,ack:%u", s, a); + m_pIListen.dispose(); - BusProtocol_2nd(ptr, BUS_ACK_VALUE, s); + m_pIAsynFrame.dispose(); - Send(pIScoket, pIOperation, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ_ACK); + m_pRot.dispose(); - return hr; + return S_OK; } -HRESULT CBrokerImpl::OnSendSeqAcked(IBase* pIBase) + +HRESULT CBrokerImpl::OnAccepted(IBase* pBase, _sock_t s) { HRESULT hr = S_OK; - TcpSocketPtr pIScoket; - OperationPtr pIOperation; - - hr = GetObject(pIBase, pIScoket, pIOperation); - rc_assert(hr == S_OK, E_FAIL); - - hr = Recv(pIScoket, pIOperation, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_ACK); - rc_assert(hr == S_OK, E_FAIL); - - return hr; + return S_OK; } -HRESULT CBrokerImpl::OnRecvAcked(IBase* pIBase) +HRESULT CBrokerImpl::OnRecvSeqed(IBase* pIBase) { HRESULT hr = S_OK; - TcpSocketPtr pIScoket; - OperationPtr pIOperation; - BUF_SIZE TransferedBytes = 0; - BUF_PTR ptr = NULL; unsigned int s = 0; unsigned int a = 0; - hr = GetObject(pIBase, pIScoket, pIOperation); - rc_assert(hr == S_OK, E_FAIL); - - hr = pIOperation->GetTransfered(&TransferedBytes); - rc_assert(TransferedBytes != 0, E_FAIL); + // BusProtocol_Get_Seq_Ack(ptr, &s, &a); + // logi("s_recv==>seq:%u,ack:%u", s, a); - hr = pIOperation->GetPtr(&ptr); - rc_assert(hr == S_OK, E_FAIL); + // BusProtocol_2nd(ptr, BUS_ACK_VALUE, s); - hr = BusProtocol_Get_Seq_Ack(ptr, &s, &a); - rc_assert(hr == S_OK, E_FAIL); - - // logi("s_recv==>seq:%u,ack:%u", s, a); - // logi("s_recv==>accept_bus_client"); + // Send(pIScoket, pIOperation, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ_ACK); return hr; } - -HRESULT CBrokerImpl::OnSended(IBase* pIBase) +HRESULT CBrokerImpl::OnSendSeqAcked(IBase* pIBase) { HRESULT hr = S_OK; - TcpSocketPtr pIScoket; - OperationPtr pIOperation; - - hr = GetObject(pIBase, pIScoket, pIOperation); - rc_assert(hr == S_OK, E_FAIL); + // hr = Recv(pIScoket, pIOperation, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_ACK); + // rc_assert(hr == S_OK, E_FAIL); return hr; } -HRESULT CBrokerImpl::OnRecved(IBase* pIBase) +HRESULT CBrokerImpl::OnRecvAcked(IBase* pIBase) { HRESULT hr = S_OK; - TcpSocketPtr pIScoket; - OperationPtr pIOperation; + BUF_SIZE TransferedBytes = 0; + BUF_PTR ptr = NULL; + unsigned int s = 0; + unsigned int a = 0; - hr = GetObject(pIBase, pIScoket, pIOperation); + hr = BusProtocol_Get_Seq_Ack(ptr, &s, &a); rc_assert(hr == S_OK, E_FAIL); + // logi("s_recv==>seq:%u,ack:%u", s, a); + // logi("s_recv==>accept_bus_client"); + return hr; } diff --git a/msgbus/broker.h b/msgbus/broker.h index aacf06aa3883a0143963d6ca745cedbb4e3d7b84..d2b013eeaff90174f4485cf2d9e876f1cbfa1014 100644 --- a/msgbus/broker.h +++ b/msgbus/broker.h @@ -5,10 +5,9 @@ #include "node.h" class CBrokerImpl : public IBroker, - public IOperationEvent, + public IOperationProc, public IAcceptListen, - public ITimerEvent, - public SChannel, + public ITimerProc, public CUnknownImp { @@ -18,9 +17,9 @@ public: BEGIN_STDCOM_MAP STDCOM_INTERFACE_ENTRY_UNKNOWN_(IBroker) - STDCOM_INTERFACE_ENTRY(IOperationEvent) + STDCOM_INTERFACE_ENTRY(IOperationProc) STDCOM_INTERFACE_ENTRY(IAcceptListen) - STDCOM_INTERFACE_ENTRY(ITimerEvent) + STDCOM_INTERFACE_ENTRY(ITimerProc) STDCOM_INTERFACE_ENTRY(IBroker) END_STDCOM_MAP @@ -32,27 +31,38 @@ public: std_method(IsListen)(); // IAcceptListen - std_method(Accept)(IBase* pBase, _sock_t s, evid error_code); + std_method(Accept)(_sock_t s, SOCKADDR_PTR sa, socklen_t sl, evid error_code); - // IOperationEvent + // IOperationProc std_method(OnComplete)(IBase* pOperation, evid event, everr error_code); - // ITimerEvents + // ITimerProcs std_method(OnTimer)(UINT uId, UINT err); +public: + HRESULT CreateSChannel(IBase* pRot); + HRESULT OpenCChannel(); + HRESULT CloseChannel(); + HRESULT BindEvent(IBase* pBase) { return m_pIListen->BindAccept(pBase); } + HRESULT UnBindEvent() { return m_pIListen->UnBindAccpet(); } + HRESULT IsListenChannel() { return m_pIListen->IsOpen(); } + private: std_method(OnAccepted)(IBase* pBase, _sock_t s); std_method(OnRecvSeqed)(IBase* pIBase); std_method(OnSendSeqAcked)(IBase* pIBase); std_method(OnRecvAcked)(IBase* pIBase); - std_method(OnSended)(IBase* pIBase); - std_method(OnRecved)(IBase* pIBase); private: std_method(Init)(); std_method(UnInit)(); std_method(PushQueue)(IBase* pBase); +protected: + _lComPtr m_pRot; + _lComPtr m_pIAsynFrame; + _lComPtr m_pIListen; + private: CLockQueue m_AcceptQueue; CLockQueue m_ConnectQueue; diff --git a/msgbus/consumer.cpp b/msgbus/consumer.cpp index 9606ae8f9098dbf9ee68b7f79c1909c56d526418..35d15b1e1aa1ccb7f5ffc80279feadabcb522ecc 100644 --- a/msgbus/consumer.cpp +++ b/msgbus/consumer.cpp @@ -70,7 +70,7 @@ HRESULT CConsumerImpl::OnConnected(IBase* pIBase) HRESULT hr = S_OK; BUF_PTR ptr = NULL; - hr = this->GetWritePtr(&ptr); + // hr = this->GetWritePtr(&ptr); rc_assert(hr == S_OK, E_FAIL); hr = BusProtocol_Init_Head(ptr, m_id, 0, NDC_PRODUCER, BUS_CONSUMER_VERSION); @@ -79,7 +79,7 @@ HRESULT CConsumerImpl::OnConnected(IBase* pIBase) hr = BusProtocol_1st(ptr, BUS_SEQ_VALUE, BUS_NULL_VALUE); rc_assert(hr == S_OK, E_FAIL); - hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ); + // hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -89,7 +89,7 @@ HRESULT CConsumerImpl::OnSendSeqed(IBase* pIBase) { HRESULT hr = S_OK; - hr = this->OnReadChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_SEQ_ACK); + // hr = this->OnReadChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_SEQ_ACK); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -99,19 +99,9 @@ HRESULT CConsumerImpl::OnRecvSeqAcked(IBase* pIBase) { HRESULT hr = S_OK; - OperationPtr pIOperation; BUF_SIZE TransferedBytes = 0; BUF_PTR ptr = NULL; - hr = GetObject(pIBase, pIOperation); - rc_assert(hr == S_OK, E_FAIL); - - pIOperation->GetTransfered(&TransferedBytes); - rc_assert(TransferedBytes != 0, E_FAIL); - - hr = pIOperation->GetPtr(&ptr); - rc_assert(hr == S_OK, E_FAIL); - unsigned int s = 0; unsigned int a = 0; @@ -123,10 +113,10 @@ HRESULT CConsumerImpl::OnRecvSeqAcked(IBase* pIBase) hr = BusProtocol_3rd(ptr, s, a); rc_assert(hr == S_OK, E_FAIL); - hr = this->WriteStream(ptr, 0, BUS_PROTOCOL_HEAD_LEN); + // hr = this->WriteStream(ptr, 0, BUS_PROTOCOL_HEAD_LEN); rc_assert(hr == S_OK, E_FAIL); - hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_ACK); + // hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_ACK); rc_assert(hr == S_OK, E_FAIL); return hr; diff --git a/msgbus/consumer.h b/msgbus/consumer.h index 9852180699d51f292435f5f75ce345bfa9d9c389..aee74d1bfd7959632d4f37f519d6b23a751af819 100644 --- a/msgbus/consumer.h +++ b/msgbus/consumer.h @@ -3,10 +3,11 @@ #include "stdafx.h" #include "auth.hpp" +#include "msgbuschannel.hpp" class CConsumerImpl : public IConsumer, - public IOperationEvent, - public CChannel, + public IOperationProc, + public CMsgbusChannel, public CUnknownImp { @@ -16,7 +17,7 @@ public: BEGIN_STDCOM_MAP STDCOM_INTERFACE_ENTRY_UNKNOWN_(IConsumer) - STDCOM_INTERFACE_ENTRY(IOperationEvent) + STDCOM_INTERFACE_ENTRY(IOperationProc) STDCOM_INTERFACE_ENTRY(IConsumer) END_STDCOM_MAP @@ -27,7 +28,7 @@ public: std_method(Close)(); std_method(Recv)(IBase* pBase); - // IOperationEvent + // IOperationProc std_method(OnComplete)(IBase* pOperation, evid event, everr error_code); private: diff --git a/msgbus/interface.cpp b/msgbus/interface.cpp index 22b2f0f33a42520420042a62c956a91be40b6ec0..181ac9cc90bf0f904f9b0929cb39bf31ed996932 100644 --- a/msgbus/interface.cpp +++ b/msgbus/interface.cpp @@ -50,12 +50,7 @@ _DEF_CLSID_IMPL(StdCom::IID_IMsgPlugin, 0x5f8488ed, 0x8dba, 0x4c96, 0x92, 0x84, // {FEB12B33-7344-45CD-A375-2495C7BEBD88} _DEF_IID_IMPL(IID_IOperation, 0xfeb12b33, 0x7344, 0x45cd, 0xa3, 0x75, 0x24, 0x95, 0xc7, 0xbe, 0xbd, 0x88); // {0470327E-5ACF-40EC-BAED-FE2AAE877B4B} -_DEF_IID_IMPL(IID_IOperationEvent, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); - -// ifile.h - -// {978D055C-CF46-44C4-BE6C-E537C0E698C5} -_DEF_IID_IMPL(IID_IFile, 0x978d055c, 0xcf46, 0x44c4, 0xbe, 0x6c, 0xe5, 0x37, 0xc0, 0xe6, 0x98, 0xc5); +_DEF_IID_IMPL(IID_IOperationProc, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); // isocket.h // {BB9DA617-80BE-4E04-8EB4-13CF43F1EBD1} @@ -85,7 +80,7 @@ _DEF_CLSID_IMPL(CLSID_CAsynFrame, 0xf170a724, 0xaaca, 0x4603, 0xbb, 0x1c, 0xa, 0 // itimer.h // {B5819C73-6EF7-4F25-B053-F6F6D4DCBE00} -_DEF_IID_IMPL(IID_ITimerEvent, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); +_DEF_IID_IMPL(IID_ITimerProc, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); // {F36A3734-C9CA-46C9-8F03-AD02AD24058F} _DEF_IID_IMPL(IID_ITimer, 0xf36a3734, 0xc9ca, 0x46c9, 0x8f, 0x3, 0xad, 0x2, 0xad, 0x24, 0x5, 0x8f); diff --git a/extensions/include/comutiliy/cchannel.hpp b/msgbus/msgbuschannel.hpp similarity index 34% rename from extensions/include/comutiliy/cchannel.hpp rename to msgbus/msgbuschannel.hpp index 3615fe246b99c179ab2a3354e02fe25110e397e6..3beeaeaf467bc703041b443610370ea75452f820 100644 --- a/extensions/include/comutiliy/cchannel.hpp +++ b/msgbus/msgbuschannel.hpp @@ -1,15 +1,14 @@ -#ifndef _COMUTILIY_CCHANNEL_HPP_ -#define _COMUTILIY_CCHANNEL_HPP_ - -#include +#ifndef channel_h +#define channel_h #define CCHANENEL_CONNECT_ADDR_MAXLEN 250 +#include "stdafx.h" -class CChannel +class CMsgbusChannel { public: - CChannel(void) { } - virtual ~CChannel(void) { } + CMsgbusChannel(void) { } + virtual ~CMsgbusChannel(void) { } HRESULT CreateCChannel(IBase* pSocket) { @@ -22,12 +21,6 @@ public: hr = m_pISocket->CreateSock(); rc_assert(hr == S_OK, E_FAIL); - hr = m_pISocket->OpenIo(); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pISocket->BindIo(); - rc_assert(hr == S_OK, E_FAIL); - return hr; } @@ -36,8 +29,6 @@ public: rc_assert(addr != NULL, E_FAIL); rc_assert(len != 0, E_FAIL); - HRESULT hr = S_OK; - CharArrayPtr item; item.dispose(); item = ALLOC_NEW char[CCHANENEL_CONNECT_ADDR_MAXLEN + 1](); @@ -52,25 +43,15 @@ public: rc_assert(port != 0, E_FAIL); rc_assert(m_pISocket != NULL, E_FAIL); - return ConnectAddrChannel(ip, atoi(port), event); + return m_pISocket->ConnectIo(ip, atoi(port), event, 5); } - HRESULT ConnectAddrChannel(LPCSTR addr, NET_PORT port, evid event) - { - rc_assert(addr != NULL, E_FAIL); - rc_assert(port != 0, E_FAIL); - - return m_pISocket->ConnectIo(addr, port, event); - } HRESULT CloseChannel() { rc_assert(m_pISocket != NULL, E_FAIL); HRESULT hr = S_OK; - hr = m_pISocket->CloseIo(CLOSE_BOTH_IO); - rc_assert(hr == S_OK, E_FAIL); - hr = m_pISocket->CloseSock(); rc_assert(hr == S_OK, E_FAIL); @@ -79,68 +60,8 @@ public: return S_OK; } - HRESULT IsOpen() - { - rc_assert(m_pISocket.m_p != NULL, E_FAIL); - return m_pISocket->IsOpen(); - } - - HRESULT WriteOperationSize(BUF_SIZE Size) { return S_OK; } - HRESULT ReadOperationSize(BUF_SIZE Size) { return S_OK; } - - HRESULT SetSockOption(LPCSTR opt, int val) - { - rc_assert(m_pISocket.m_p != NULL, E_FAIL); - rc_assert(IsOpen() == S_OK, S_OK); - rc_assert(opt != NULL, S_OK); - return m_pISocket->SetOption(opt, val); - } - - HRESULT OnReadChannel(ULONG pos, ULONG size, evid event) - { - rc_assert(m_pISocket != NULL, E_FAIL); - rc_assert(size != 0, E_FAIL); - - return this->m_pISocket->ReadIo(pos, size, event); - } - HRESULT OnWriteChannel(ULONG pos, ULONG size, evid event) - { - rc_assert(m_pISocket != NULL, E_FAIL); - rc_assert(size != 0, E_FAIL); - - return this->m_pISocket->WriteIo(pos, size, event); - } - HRESULT WriteStream(BUF_PTR Ptr, BUF_SIZE Pos, BUF_SIZE Size) - { - rc_assert(m_pISocket != NULL, E_FAIL); - return this->m_pISocket->WriteStream(Ptr, Pos, Size); - } - - HRESULT GetObject(IBase* pIBase, OperationPtr& pOperation) - { - HRESULT hr = S_OK; - - hr = pIBase->QueryInterface(IID_IOperation, (void**)&pOperation); - rc_assert(hr == S_OK, E_FAIL); - - return hr; - } - - HRESULT GetWritePtr(BUF_PTR* Ptr) - { - rc_assert(m_pISocket != NULL, E_FAIL); - - return this->m_pISocket->GetWritePtr(Ptr); - } - HRESULT GetReadPtr(BUF_PTR* Ptr) - { - rc_assert(m_pISocket != NULL, E_FAIL); - - return this->m_pISocket->GetReadPtr(Ptr); - } - private: - TcpSocketPtr m_pISocket; + _lComPtr m_pISocket; }; #endif diff --git a/msgbus/msgbusimpl.cpp b/msgbus/msgbusimpl.cpp index 5ce708c34364cdb93261b262f6bfd6db37526375..7b14ca2a56e8a2b64153a5ff54da953d766e2677 100644 --- a/msgbus/msgbusimpl.cpp +++ b/msgbus/msgbusimpl.cpp @@ -63,14 +63,6 @@ HRESULT CMsgBusImpl::CreateNode(NODE_CLASS cls, IBase** pBase) hr = m_pIAsynFrame->CreateIo(io_tcp_socket, (IBase**)&pISocket); rc_assert(hr == S_OK, E_FAIL); - OperationPtr m_pIROperation; - pISocket->QueryInterface(IID_IReadOperation, (void**)&m_pIROperation); - m_pIROperation.dispose(); - - OperationPtr m_pIWOperation; - pISocket->QueryInterface(IID_IWriteOperation, (void**)&m_pIWOperation); - m_pIWOperation.dispose(); - hr = p->CreateCChannel(pISocket); rc_assert(hr == S_OK, E_FAIL); diff --git a/msgbus/msgbusimpl.h b/msgbus/msgbusimpl.h index ed8fce45c7cea5dcaad7d50b22523eb982d6b419..e9e912f8270c1924aea8f8e6cfa86034fb247444 100644 --- a/msgbus/msgbusimpl.h +++ b/msgbus/msgbusimpl.h @@ -32,6 +32,6 @@ public: protected: _lComPtr m_pRot; - AsynFramePtr m_pIAsynFrame; + _lComPtr m_pIAsynFrame; }; #endif diff --git a/msgbus/node.h b/msgbus/node.h index 861aca7e51e1315997a508f383c279a3a1849d15..2a8552f76481f5603e551df02bbd52d866f48322 100644 --- a/msgbus/node.h +++ b/msgbus/node.h @@ -2,6 +2,7 @@ #define _NODE_H_ #include "stdafx.h" +#include "msgbuschannel.hpp" class Node { @@ -9,7 +10,7 @@ public: Node() { } virtual ~Node() { channel.CloseChannel(); } - CChannel channel; + CMsgbusChannel channel; ULONG tm; }; diff --git a/msgbus/producer.cpp b/msgbus/producer.cpp index 998d2953e9f0376a6f0d979269d03d7bd4a87bcc..b47bdbe72f098fcfbd5262ba4310e180bf0fd10e 100644 --- a/msgbus/producer.cpp +++ b/msgbus/producer.cpp @@ -70,7 +70,7 @@ HRESULT CProducerImpl::OnConnected(IBase* pIBase) HRESULT hr = S_OK; BUF_PTR ptr = NULL; - hr = this->GetWritePtr(&ptr); + // hr = this->GetWritePtr(&ptr); rc_assert(hr == S_OK, E_FAIL); hr = BusProtocol_Init_Head(ptr, m_id, 0, NDC_PRODUCER, BUS_CONSUMER_VERSION); @@ -79,7 +79,7 @@ HRESULT CProducerImpl::OnConnected(IBase* pIBase) hr = BusProtocol_1st(ptr, BUS_SEQ_VALUE, BUS_NULL_VALUE); rc_assert(hr == S_OK, E_FAIL); - hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ); + // hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_SEQ); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -89,7 +89,7 @@ HRESULT CProducerImpl::OnSendSeqed(IBase* pIBase) { HRESULT hr = S_OK; - hr = this->OnReadChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_SEQ_ACK); + // hr = this->OnReadChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_RECV_SEQ_ACK); rc_assert(hr == S_OK, E_FAIL); return hr; @@ -99,19 +99,9 @@ HRESULT CProducerImpl::OnRecvSeqAcked(IBase* pIBase) { HRESULT hr = S_OK; - OperationPtr pIOperation; BUF_SIZE TransferedBytes = 0; BUF_PTR ptr = NULL; - hr = GetObject(pIBase, pIOperation); - rc_assert(hr == S_OK, E_FAIL); - - pIOperation->GetTransfered(&TransferedBytes); - rc_assert(TransferedBytes != 0, E_FAIL); - - hr = pIOperation->GetPtr(&ptr); - rc_assert(hr == S_OK, E_FAIL); - unsigned int s = 0; unsigned int a = 0; @@ -123,10 +113,10 @@ HRESULT CProducerImpl::OnRecvSeqAcked(IBase* pIBase) hr = BusProtocol_3rd(ptr, s, a); rc_assert(hr == S_OK, E_FAIL); - hr = this->WriteStream(ptr, 0, BUS_PROTOCOL_HEAD_LEN); + // hr = this->WriteStream(ptr, 0, BUS_PROTOCOL_HEAD_LEN); rc_assert(hr == S_OK, E_FAIL); - hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_ACK); + // hr = this->OnWriteChannel(0, BUS_PROTOCOL_HEAD_LEN, BUS_OP_SEND_ACK); rc_assert(hr == S_OK, E_FAIL); return hr; diff --git a/msgbus/producer.h b/msgbus/producer.h index 2371fca648b36cdeea7ce8311b0482f5d4fa7fea..c1a1c8fce6aa4d919898263d2e8ffcfd506a2c31 100644 --- a/msgbus/producer.h +++ b/msgbus/producer.h @@ -2,12 +2,14 @@ #define _PRODUCERIMPL_H_ #include "stdafx.h" +#include "auth.hpp" +#include "msgbuschannel.hpp" #define TCP_CONSUMER_CONNECT 100 class CProducerImpl : public IProducer, - public IOperationEvent, - public CChannel, + public IOperationProc, + public CMsgbusChannel, public CUnknownImp { @@ -17,7 +19,7 @@ public: BEGIN_STDCOM_MAP STDCOM_INTERFACE_ENTRY_UNKNOWN_(IProducer) - STDCOM_INTERFACE_ENTRY(IOperationEvent) + STDCOM_INTERFACE_ENTRY(IOperationProc) STDCOM_INTERFACE_ENTRY(IProducer) END_STDCOM_MAP @@ -28,7 +30,7 @@ public: std_method(Close)(); std_method(Send)(IBase* pBase); - // IOperationEvent + // IOperationProc std_method(OnComplete)(IBase* pOperation, evid event, everr error_code); private: diff --git a/msgbus/stdafx.h b/msgbus/stdafx.h index 648218e29cb11192179f8a58b9aa7c883e48663a..f16b626f9b6700d183c1da4bc37b7d877d7d25c2 100644 --- a/msgbus/stdafx.h +++ b/msgbus/stdafx.h @@ -9,8 +9,11 @@ #include #include +#include +#include +#include +#include + #include -#include -#include #endif diff --git a/net/dnsimpl.cpp b/net/dnsimpl.cpp index 9019527d4e3c62f65ecf8b8e0a9c93288b2a981e..b62b47f0e96aee520dd86e9a112b65352c571f5d 100644 --- a/net/dnsimpl.cpp +++ b/net/dnsimpl.cpp @@ -8,19 +8,16 @@ CDnsImpl::~CDnsImpl(void) { logi("CDnsImpl::~CDnsImpl"); } -HRESULT CDnsImpl::init_class(AsynFrameConstPtr AsynFrame, NetConstPtr Net) +HRESULT CDnsImpl::init_class(const _lComPtr& AsynFrame) { HRESULT hr = S_OK; hr = AsynFrame->CreateIo(io_udp_socket, (IBase**)&m_pISocket); rc_assert(hr == S_OK, E_FAIL); - hr = AsynFrame->CreateIo(io_operation, (IBase**)&m_pIOperation); - rc_assert(hr == S_OK, E_FAIL); - return S_OK; } -HRESULT CDnsImpl::Send(LPCSTR hostname, IBase* pProc) +HRESULT CDnsImpl::Post(LPCSTR hostname, IBase* pProc) { HRESULT hr = S_OK; logi("SendUrl ==>%s", hostname); @@ -60,15 +57,9 @@ HRESULT CDnsImpl::Send(LPCSTR hostname, IBase* pProc) hr = m_pISocket->CreateSock(); rc_assert(hr == S_OK, E_FAIL); - hr = m_pISocket->OpenIo(); - rc_assert(hr == S_OK, E_FAIL); - - hr = m_pISocket->BindIo(); - rc_assert(hr == S_OK, E_FAIL); - BUF_SIZE len = 0; - len = m_pISocket->SyncSend("114.114.114.114", 53, (BUF_PTR)buf, buflen); - rc_assert(len != 0, E_FAIL); + // len = m_pISocket->SyncSend("114.114.114.114", 53, (BUF_PTR)buf, buflen); + // rc_assert(len != 0, E_FAIL); hr = m_pIOperation->ClearPtr(); rc_assert(hr == S_OK, E_FAIL); @@ -86,18 +77,10 @@ HRESULT CDnsImpl::Send(LPCSTR hostname, IBase* pProc) return S_OK; } - -HRESULT CDnsImpl::Post(LPCSTR hostname, IBase* pProc) -{ - return S_OK; -} HRESULT CDnsImpl::Close() { HRESULT hr = S_OK; - hr = m_pISocket->CloseIo(CLOSE_BOTH_IO); - rc_assert(hr == S_OK, E_FAIL); - hr = m_pISocket->CloseSock(); rc_assert(hr == S_OK, E_FAIL); @@ -120,7 +103,7 @@ HRESULT CDnsImpl::OnComplete(IBase* pOperation, evid event, everr error_code) dns_t resp; memset(&resp, 0, sizeof(resp)); - OperationPtr pOper; + _lComPtr pOper; pOperation->QueryInterface(IID_IOperation, (void**)&pOper); everr error = 0; diff --git a/net/dnsimpl.h b/net/dnsimpl.h index 37d861c6b1f484cc2db79bc7def3e319046c11d2..93fb8f57f492644925bea9f1178673c6048d7950 100644 --- a/net/dnsimpl.h +++ b/net/dnsimpl.h @@ -4,7 +4,7 @@ #include "stdafx.h" class CDnsImpl : public IDns, - public IOperationEvent, + public IOperationProc, public CUnknownImp { public: @@ -15,13 +15,12 @@ public: BEGIN_STDCOM_MAP STDCOM_INTERFACE_ENTRY_UNKNOWN_(IDns); STDCOM_INTERFACE_ENTRY(IDns); - STDCOM_INTERFACE_ENTRY(IOperationEvent); + STDCOM_INTERFACE_ENTRY(IOperationProc); END_STDCOM_MAP - HRESULT init_class(AsynFrameConstPtr AsynFrame, NetConstPtr Net); + HRESULT init_class(const _lComPtr& AsynFrame); // IDns - std_method(Send)(LPCSTR hostname, IBase* pProc); std_method(Post)(LPCSTR hostname, IBase* pProc); std_method(Close)(); @@ -29,8 +28,8 @@ public: std_method(OnComplete)(IBase* pOperation, evid event, everr error_code); private: - UdpSocketPtr m_pISocket; - OperationPtr m_pIOperation; + _lComPtr m_pISocket; + _lComPtr m_pIOperation; CSemHandle m_sem; }; diff --git a/net/httpinstanceimpl.cpp b/net/http.cpp similarity index 64% rename from net/httpinstanceimpl.cpp rename to net/http.cpp index d5c2bc0bfa954e46ac74e7486f3d86ae734284cc..b633ff390f83036d5c4a8abd14c230cd030a1c4b 100644 --- a/net/httpinstanceimpl.cpp +++ b/net/http.cpp @@ -1,17 +1,17 @@ -#include "httpinstanceimpl.h" +#include "http.h" -CHttpInstanceImpl::CHttpInstanceImpl() +CHttpIImpl::CHttpIImpl() { m_httpcontent_length = 0; m_hstid = HTTP_IMPL_UNKNOWN; } -CHttpInstanceImpl::~CHttpInstanceImpl(void) +CHttpIImpl::~CHttpIImpl(void) { logi("CHttptImpl::~CHttptImpl"); } -HRESULT CHttpInstanceImpl::init_class(AsynFrameConstPtr AsynFrame, NetConstPtr Net) +HRESULT CHttpIImpl::init_class(const _lComPtr& AsynFrame, const _lComPtr& Net) { HRESULT hr = S_OK; @@ -26,9 +26,7 @@ HRESULT CHttpInstanceImpl::init_class(AsynFrameConstPtr AsynFrame, NetConstPtr N hr = Net->CreateProtocol(protocol_dns, (IBase**)&m_pIDns); rc_assert(hr == S_OK, E_FAIL); - hr = this->CreateCChannel(pISocket); - rc_assert(hr == S_OK, E_FAIL); - + /* hr = this->SetSockOption(SOL_SENDTM, 5); rc_assert(hr == S_OK, E_FAIL); @@ -43,6 +41,7 @@ HRESULT CHttpInstanceImpl::init_class(AsynFrameConstPtr AsynFrame, NetConstPtr N hr = this->WriteOperationSize(16); rc_assert(hr == S_OK, E_FAIL); + */ http_init_analyze(http_response); @@ -52,21 +51,21 @@ HRESULT CHttpInstanceImpl::init_class(AsynFrameConstPtr AsynFrame, NetConstPtr N return S_OK; } -HRESULT CHttpInstanceImpl::BindEvent(IBase* pBase) +HRESULT CHttpIImpl::BindEvent(IBase* pBase) { m_pHandle.dispose(); - return pBase->QueryInterface(IID_IHttpInstanceProc, (void**)&m_pHandle); + return pBase->QueryInterface(IID_IHttpProc, (void**)&m_pHandle); } -HRESULT CHttpInstanceImpl::UnBindEvent() +HRESULT CHttpIImpl::UnBindEvent() { m_pHandle.dispose(); return S_OK; } -HRESULT CHttpInstanceImpl::SetCookies(http_header* data) +HRESULT CHttpIImpl::SetCookies(http_header* data) { return S_OK; } -HRESULT CHttpInstanceImpl::Open(SafeStringPtr addr, SafeStringPtr scheme, unsigned short port) +HRESULT CHttpIImpl::Open(SafeStringPtr addr, SafeStringPtr scheme, unsigned short port) { varaint_t_free_string(&m_varurl); varaint_t_free_string(&m_varschema); @@ -75,25 +74,21 @@ HRESULT CHttpInstanceImpl::Open(SafeStringPtr addr, SafeStringPtr scheme, unsign return OnConnect(addr.ptr, addr.len); } -http_header CHttpInstanceImpl::GetHttpHead() +http_header CHttpIImpl::GetHttpHead() { return m_szhttpHead; } -HRESULT CHttpInstanceImpl::ReSet() +HRESULT CHttpIImpl::ReSet() { Cancel(); return S_OK; } -HRESULT CHttpInstanceImpl::Cancel() +HRESULT CHttpIImpl::Cancel() { m_hstid = HTTP_IMPL_UNKNOWN; http_init_analyze(http_response); - HRESULT hr = S_OK; - - this->CloseChannel(); - m_pIDns.dispose(); varaint_t_free_string(&m_varurl); @@ -102,11 +97,11 @@ HRESULT CHttpInstanceImpl::Cancel() return S_OK; } -int CHttpInstanceImpl::IsComplete() +int CHttpIImpl::IsComplete() { return m_parser->content_length == 0; } -HRESULT CHttpInstanceImpl::OnComplete(IBase* pOperation, evid event, everr error_code) +HRESULT CHttpIImpl::OnComplete(IBase* pOperation, evid event, everr error_code) { HRESULT hr = S_OK; @@ -118,7 +113,7 @@ HRESULT CHttpInstanceImpl::OnComplete(IBase* pOperation, evid event, everr error return S_OK; } -HRESULT CHttpInstanceImpl::OnGetHost(int error, LPCSTR hostname, LPCSTR host) +HRESULT CHttpIImpl::OnGetHost(int error, LPCSTR hostname, LPCSTR host) { if (m_hstid < HTTP_IMPL_CONNECTING && DNS_PROC_RES_NOERROR == error) { // httpConnect(m_pIOper.m_p, host, m_uport); @@ -134,21 +129,21 @@ HRESULT CHttpInstanceImpl::OnGetHost(int error, LPCSTR hostname, LPCSTR host) } return S_OK; } -ULONG CHttpInstanceImpl::OnNotify(evid event, everr error_code) +ULONG CHttpIImpl::OnNotify(evid event, everr error_code) { rc_assert(m_pHandle.m_p != NULL, HTTP_IMPL_UNKNOWN); return m_pHandle->OnHttpNotify(event, error_code); } -ULONG CHttpInstanceImpl::Id_Suc(ULONG ulid) +ULONG CHttpIImpl::Id_Suc(ULONG ulid) { return ulid; } -ULONG CHttpInstanceImpl::Id_Faild(ULONG ulid) +ULONG CHttpIImpl::Id_Faild(ULONG ulid) { return ulid; } -HRESULT CHttpInstanceImpl::httpEventProc(evid event, IBase* pOperation) +HRESULT CHttpIImpl::httpEventProc(evid event, IBase* pOperation) { HRESULT hr = S_OK; @@ -174,52 +169,30 @@ HRESULT CHttpInstanceImpl::httpEventProc(evid event, IBase* pOperation) return hr; } -HRESULT CHttpInstanceImpl::httpConnected(IBase* pBase) +HRESULT CHttpIImpl::httpConnected(IBase* pBase) { HRESULT hr = S_OK; - OperationPtr pOperation; - hr = pBase->QueryInterface(IID_IOperation, (void**)&pOperation); - this->OnNotify(HTTP_IMPL_CONNECTED, S_SUCCESS); return hr; } -HRESULT CHttpInstanceImpl::httpSendHeaded(IBase* pBase) +HRESULT CHttpIImpl::httpSendHeaded(IBase* pBase) { HRESULT hr = S_OK; - OperationPtr pOperation; - hr = pBase->QueryInterface(IID_IOperation, (void**)&pOperation); - pOperation->SetId(HTTP_IMPL_SEND_HEADED); - return hr; } -HRESULT CHttpInstanceImpl::httpSendBodyed(IBase* pBase) +HRESULT CHttpIImpl::httpSendBodyed(IBase* pBase) { HRESULT hr = S_OK; - OperationPtr pOperation; - hr = pBase->QueryInterface(IID_IOperation, (void**)&pOperation); - pOperation->SetId(HTTP_IMPL_SEND_BODYED); - return hr; } -HRESULT CHttpInstanceImpl::httpRecvHeaded(IBase* pBase) +HRESULT CHttpIImpl::httpRecvHeaded(IBase* pBase) { HRESULT hr = S_OK; - OperationPtr pOperation; - hr = pBase->QueryInterface(IID_IOperation, (void**)&pOperation); - pOperation->SetId(HTTP_IMPL_RECV_HEADED); - - everr error = 0; - BUF_SIZE size = 0; - pOperation->GetResult(&error, &size); - - BUF_PTR ptr; - pOperation->GetPtr(&ptr); - // ERROR_CODE errcode = 0; // ULONG pTransferedBytes = 0; @@ -238,18 +211,9 @@ HRESULT CHttpInstanceImpl::httpRecvHeaded(IBase* pBase) return hr; } -HRESULT CHttpInstanceImpl::httpRecvBodyed(IBase* pBase) +HRESULT CHttpIImpl::httpRecvBodyed(IBase* pBase) { HRESULT hr = S_OK; - - OperationPtr pOperation; - hr = pBase->QueryInterface(IID_IOperation, (void**)&pOperation); - pOperation->SetId(HTTP_IMPL_RECV_BODYED); - - BUF_SIZE pIoStartPos = 0; - BUF_SIZE pIoExpectBytes = 0; - pOperation->GetIoParam(&pIoStartPos, &pIoExpectBytes); - // BUFFER_PTR ptr = NULL; // pOperation->GetIo(&ptr, &pIoStartPos); // rc_assert(ptr != NULL, E_FAIL) @@ -260,7 +224,7 @@ HRESULT CHttpInstanceImpl::httpRecvBodyed(IBase* pBase) return hr; } -HRESULT CHttpInstanceImpl::httpEvent(evid event, IBase* pSocket, IBase* pOperation) +HRESULT CHttpIImpl::httpEvent(evid event, IBase* pSocket, IBase* pOperation) { HRESULT hr = E_FAIL; @@ -286,68 +250,68 @@ HRESULT CHttpInstanceImpl::httpEvent(evid event, IBase* pSocket, IBase* pOperati return hr; } -HRESULT CHttpInstanceImpl::httpConnect(IOperation* pOperation, NET_ADDR addr, NET_PORT uport) +HRESULT CHttpIImpl::httpConnect(IOperation* pOperation, NET_ADDR addr, NET_PORT uport) { logi("CHttpClientImpl::httpConnect %s", addr); return S_OK; // m_pISocket->ConnectIo(addr, uport, pOperation, HTTP_IMPL_CONNECTING); } -HRESULT CHttpInstanceImpl::httpSendHead(IBase* pSocket, IBase* pOperation) +HRESULT CHttpIImpl::httpSendHead(IBase* pSocket, IBase* pOperation) { const char* p = m_http_resheader.build_res(); size_t ulen = m_http_resheader.build_res_len(); return httpSend(HTTP_IMPL_SEND_HEAD, pSocket, pOperation); } -HRESULT CHttpInstanceImpl::httpSendBody(IBase* pSocket, IBase* pOperation) +HRESULT CHttpIImpl::httpSendBody(IBase* pSocket, IBase* pOperation) { return httpSend(HTTP_IMPL_SEND_BODY, pSocket, pOperation); } -HRESULT CHttpInstanceImpl::httpRecvHead(IBase* pSocket, IBase* pOperation) +HRESULT CHttpIImpl::httpRecvHead(IBase* pSocket, IBase* pOperation) { return httpRecv(HTTP_IMPL_RECV_HEAD, pSocket, pOperation); } -HRESULT CHttpInstanceImpl::httpRecvBody(IBase* pSocket, IBase* pOperation) +HRESULT CHttpIImpl::httpRecvBody(IBase* pSocket, IBase* pOperation) { return httpRecv(HTTP_IMPL_RECV_BODY, pSocket, pOperation); } -HRESULT CHttpInstanceImpl::httpSend(evid event, IBase* pSocket, IBase* pOperation) +HRESULT CHttpIImpl::httpSend(evid event, IBase* pSocket, IBase* pOperation) { // pOperation->SetId(event); // return pSocket->WriteIo(pOperation, event); return S_OK; } -HRESULT CHttpInstanceImpl::httpRecv(evid event, IBase* pSocket, IBase* pOperation) +HRESULT CHttpIImpl::httpRecv(evid event, IBase* pSocket, IBase* pOperation) { // pOperation->SetId(event); // return pSocket->ReadIo(pOperation, event); return S_OK; } -void CHttpInstanceImpl::on_http_message_begin() +void CHttpIImpl::on_http_message_begin() { c_assert(m_parser != NULL) } -void CHttpInstanceImpl::on_http_header_complete() +void CHttpIImpl::on_http_header_complete() { c_assert(m_parser != NULL) m_httpcontent_length = m_parser->content_length; m_szhttpHead = new char[m_parser->nread + 1](); memcpy(m_szhttpHead, m_parser->p, m_parser->nread); } -void CHttpInstanceImpl::on_http_body(const char* at, size_t length) +void CHttpIImpl::on_http_body(const char* at, size_t length) { c_assert(m_parser != NULL) // m_Notify->RecvBody((void*)at, length, 1); } -void CHttpInstanceImpl::on_http_message_complete(){c_assert(m_parser != NULL)} +void CHttpIImpl::on_http_message_complete(){c_assert(m_parser != NULL)} -HRESULT CHttpInstanceImpl::OnConnect(NET_ADDR addr, ULONG addrlen) +HRESULT CHttpIImpl::OnConnect(NET_ADDR addr, ULONG addrlen) { HRESULT hr = S_OK; CharArrayPtr item; item.dispose(); - item = ALLOC_NEW char[CCHANENEL_CONNECT_ADDR_MAXLEN + 1](); + item = ALLOC_NEW char[1023 + 1](); rc_assert(item.m_p != NULL, E_FAIL); - s_strcpy(item, CCHANENEL_CONNECT_ADDR_MAXLEN, addr); + s_strcpy(item, 1023, addr); char* port = NULL; char* host = NULL; @@ -359,14 +323,13 @@ HRESULT CHttpInstanceImpl::OnConnect(NET_ADDR addr, ULONG addrlen) m_uport = atoi(port); if (_is_ip(host)) { - hr = this->ConnectAddrChannel(host, m_uport, HTTP_IMPL_CONNECTING); } else { // hr = m_pIDns->GetURLtoHost(url, "", "http", this, NULL, NULL, 1); } return hr; } -HRESULT CHttpInstanceImpl::OnBuildHttp(http_addr_s url, http_addr_s scheme, NET_PORT uport) +HRESULT CHttpIImpl::OnBuildHttp(http_addr_s url, http_addr_s scheme, NET_PORT uport) { m_http_resheader.set_method(scheme); diff --git a/net/httpinstanceimpl.h b/net/http.h similarity index 79% rename from net/httpinstanceimpl.h rename to net/http.h index 12666be7621da35aa50b20fb6fbaf2ae1e1656ba..d2ea6890c87bcd69681efbb9d918838b079ca422 100644 --- a/net/httpinstanceimpl.h +++ b/net/http.h @@ -4,27 +4,26 @@ #include "stdafx.h" #include "http_protocol/chttpparser.h" -class CHttpInstanceImpl : public IHttpInstance, - public IOperationEvent, - public IDnsProc, - public CChannel, - public CUnknownImp, - public CHttpParser +class CHttpIImpl : public IHttp, + public IOperationProc, + public IDnsProc, + public CUnknownImp, + public CHttpParser { public: - CHttpInstanceImpl(); - virtual ~CHttpInstanceImpl(void); + CHttpIImpl(); + virtual ~CHttpIImpl(void); public: BEGIN_STDCOM_MAP - STDCOM_INTERFACE_ENTRY_UNKNOWN_(IHttpInstance) - STDCOM_INTERFACE_ENTRY(IHttpInstance) + STDCOM_INTERFACE_ENTRY_UNKNOWN_(IHttp) + STDCOM_INTERFACE_ENTRY(IHttp) STDCOM_INTERFACE_ENTRY(IDnsProc) - STDCOM_INTERFACE_ENTRY(IOperationEvent); + STDCOM_INTERFACE_ENTRY(IOperationProc); END_STDCOM_MAP public: - HRESULT init_class(AsynFrameConstPtr AsynFrame, NetConstPtr Net); + HRESULT init_class(const _lComPtr& AsynFrame, const _lComPtr& Net); public: // IHttp @@ -77,14 +76,14 @@ private: HRESULT OnBuildHttp(http_addr_s url, http_addr_s scheme, NET_PORT uport); private: - DnsPtr m_pIDns; + _lComPtr m_pIDns; int64 m_httpcontent_length; CharArrayPtr m_szhttpHead; CharArrayPtr m_szhttpSendHead; CharArrayPtr m_szhttpurl; NET_PORT m_uport; - HttpInstanceHandlePtr m_pHandle; + _lComPtr m_pHandle; http_header_t m_http_resheader; long m_hstid; diff --git a/net/http_protocol/http_parser.cpp b/net/http_protocol/http_parser.cpp index 9e41968ee450e804b75ac5ff4a4113e54da85536..e5748e8b9edb76dda196d9ffb9e7788554daf5eb 100644 --- a/net/http_protocol/http_parser.cpp +++ b/net/http_protocol/http_parser.cpp @@ -204,12 +204,11 @@ static const char tokens[256] = { /* 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 del */ 'x', 'y', 'z', 0, '|', 0, '~', 0}; -static const int8_t unhex[256] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, - 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; +static const int8_t unhex[256] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; #if HTTP_PARSER_STRICT #define T(v) 0 @@ -405,12 +404,9 @@ enum http_host_state { #define IS_NUM(c) ((c) >= '0' && (c) <= '9') #define IS_ALPHANUM(c) (IS_ALPHA(c) || IS_NUM(c)) #define IS_HEX(c) (IS_NUM(c) || (LOWER(c) >= 'a' && LOWER(c) <= 'f')) -#define IS_MARK(c) \ - ((c) == '-' || (c) == '_' || (c) == '.' || (c) == '!' || (c) == '~' || (c) == '*' || (c) == '\'' || (c) == '(' \ - || (c) == ')') +#define IS_MARK(c) ((c) == '-' || (c) == '_' || (c) == '.' || (c) == '!' || (c) == '~' || (c) == '*' || (c) == '\'' || (c) == '(' || (c) == ')') #define IS_USERINFO_CHAR(c) \ - (IS_ALPHANUM(c) || IS_MARK(c) || (c) == '%' || (c) == ';' || (c) == ':' || (c) == '&' || (c) == '=' || (c) == '+' \ - || (c) == '$' || (c) == ',') + (IS_ALPHANUM(c) || IS_MARK(c) || (c) == '%' || (c) == ';' || (c) == ':' || (c) == '&' || (c) == '=' || (c) == '+' || (c) == '$' || (c) == ',') #define STRICT_TOKEN(c) (tokens[(unsigned char)c]) @@ -1986,10 +1982,7 @@ size_t http_parser_execute(http_parser* parser, const http_parser_settings* sett * value that's in-bounds). */ - assert( - ((header_field_mark ? 1 : 0) + (header_value_mark ? 1 : 0) + (url_mark ? 1 : 0) + (body_mark ? 1 : 0) - + (status_mark ? 1 : 0)) - <= 1); + assert(((header_field_mark ? 1 : 0) + (header_value_mark ? 1 : 0) + (url_mark ? 1 : 0) + (body_mark ? 1 : 0) + (status_mark ? 1 : 0)) <= 1); CALLBACK_DATA_NOADVANCE(header_field); CALLBACK_DATA_NOADVANCE(header_value); @@ -2382,6 +2375,5 @@ int http_body_is_final(const struct http_parser* parser) unsigned long http_parser_version(void) { - return HTTP_PARSER_VERSION_MAJOR * 0x10000 | HTTP_PARSER_VERSION_MINOR * 0x00100 - | HTTP_PARSER_VERSION_PATCH * 0x00001; + return HTTP_PARSER_VERSION_MAJOR * 0x10000 | HTTP_PARSER_VERSION_MINOR * 0x00100 | HTTP_PARSER_VERSION_PATCH * 0x00001; } diff --git a/net/http_protocol/http_parser.h b/net/http_protocol/http_parser.h index 2b13610c9365676730a54a71aaf25c635c6e1034..14dee23bff9fbce244f7119bfd7c6743315d559c 100644 --- a/net/http_protocol/http_parser.h +++ b/net/http_protocol/http_parser.h @@ -318,16 +318,7 @@ struct http_parser_settings { http_cb on_chunk_complete; }; -enum http_parser_url_fields { - UF_SCHEMA = 0, - UF_HOST = 1, - UF_PORT = 2, - UF_PATH = 3, - UF_QUERY = 4, - UF_FRAGMENT = 5, - UF_USERINFO = 6, - UF_MAX = 7 -}; +enum http_parser_url_fields { UF_SCHEMA = 0, UF_HOST = 1, UF_PORT = 2, UF_PATH = 3, UF_QUERY = 4, UF_FRAGMENT = 5, UF_USERINFO = 6, UF_MAX = 7 }; /* Result structure for http_parser_parse_url(). * diff --git a/net/http_protocol/httputil.cpp b/net/http_protocol/httputil.cpp index 6f4943d5a6d90160e65feef2b125e82d5e4c6855..c3d3f9a3e056bd3b8a7bfc60ed5e84b06c712d6f 100644 --- a/net/http_protocol/httputil.cpp +++ b/net/http_protocol/httputil.cpp @@ -44,14 +44,12 @@ char* http_gb2312_url_encode(const char* str) } static unsigned char dec_tab[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, - 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; char* http_gb2312_url_decode(const char* str) { diff --git a/net/interface.cpp b/net/interface.cpp index 2ac5a0c1f2b81c6f72b61379212964dc10544165..7b286742d3ef8e5a605e422d718b5795023b6a29 100644 --- a/net/interface.cpp +++ b/net/interface.cpp @@ -48,11 +48,7 @@ _DEF_CLSID_IMPL(StdCom::IID_IMsgPlugin, 0x5f8488ed, 0x8dba, 0x4c96, 0x92, 0x84, // {FEB12B33-7344-45CD-A375-2495C7BEBD88} _DEF_IID_IMPL(IID_IOperation, 0xfeb12b33, 0x7344, 0x45cd, 0xa3, 0x75, 0x24, 0x95, 0xc7, 0xbe, 0xbd, 0x88); // {0470327E-5ACF-40EC-BAED-FE2AAE877B4B} -_DEF_IID_IMPL(IID_IOperationEvent, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); - -// ifile.h -// {978D055C-CF46-44C4-BE6C-E537C0E698C5} -_DEF_IID_IMPL(IID_IFile, 0x978d055c, 0xcf46, 0x44c4, 0xbe, 0x6c, 0xe5, 0x37, 0xc0, 0xe6, 0x98, 0xc5); +_DEF_IID_IMPL(IID_IOperationProc, 0x470327e, 0x5acf, 0x40ec, 0xba, 0xed, 0xfe, 0x2a, 0xae, 0x87, 0x7b, 0x4b); // isocket.h // {BB9DA617-80BE-4E04-8EB4-13CF43F1EBD1} @@ -78,7 +74,7 @@ _DEF_CLSID_IMPL(CLSID_CAsynFrame, 0xf170a724, 0xaaca, 0x4603, 0xbb, 0x1c, 0xa, 0 // itimer.h // {B5819C73-6EF7-4F25-B053-F6F6D4DCBE00} -_DEF_IID_IMPL(IID_ITimerEvent, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); +_DEF_IID_IMPL(IID_ITimerProc, 0xb5819c73, 0x6ef7, 0x4f25, 0xb0, 0x53, 0xf6, 0xf6, 0xd4, 0xdc, 0xbe, 0x0); // {F36A3734-C9CA-46C9-8F03-AD02AD24058F} _DEF_IID_IMPL(IID_ITimer, 0xf36a3734, 0xc9ca, 0x46c9, 0x8f, 0x3, 0xad, 0x2, 0xad, 0x24, 0x5, 0x8f); @@ -100,11 +96,11 @@ _DEF_CLSID_IMPL(CLSID_INet, 0xc54c9cc0, 0xf448, 0x4a49, 0xa6, 0x22, 0x4, 0x67, 0 // ihttp.h // {8C102441-E383-4B3C-8CC8-7C8E0B0162FE} -_DEF_IID_IMPL(IID_IHttpInstanceProc, 0x8c102441, 0xe383, 0x4b3c, 0x8c, 0xc8, 0x7c, 0x8e, 0xb, 0x1, 0x62, 0xfe); +_DEF_IID_IMPL(IID_IHttpProc, 0x8c102441, 0xe383, 0x4b3c, 0x8c, 0xc8, 0x7c, 0x8e, 0xb, 0x1, 0x62, 0xfe); // {6014F5E1-05A9-476F-898C-8606756A750F} -_DEF_IID_IMPL(IID_IHttpInstance, 0x6014f5e1, 0x5a9, 0x476f, 0x89, 0x8c, 0x86, 0x6, 0x75, 0x6a, 0x75, 0xf); +_DEF_IID_IMPL(IID_IHttp, 0x6014f5e1, 0x5a9, 0x476f, 0x89, 0x8c, 0x86, 0x6, 0x75, 0x6a, 0x75, 0xf); // {23C86623-C039-416B-A489-C175C360E692} -_DEF_IID_IMPL(IID_IHttpApplicationProc, 0x23c86623, 0xc039, 0x416b, 0xa4, 0x89, 0xc1, 0x75, 0xc3, 0x60, 0xe6, 0x92); +_DEF_IID_IMPL(IID_IHttpWebProc, 0x23c86623, 0xc039, 0x416b, 0xa4, 0x89, 0xc1, 0x75, 0xc3, 0x60, 0xe6, 0x92); // {75BD9CAF-2D0D-4408-B481-655F30F8613F} -_DEF_IID_IMPL(IID_IHttpApplication, 0x75bd9caf, 0x2d0d, 0x4408, 0xb4, 0x81, 0x65, 0x5f, 0x30, 0xf8, 0x61, 0x3f); +_DEF_IID_IMPL(IID_IHttpWeb, 0x75bd9caf, 0x2d0d, 0x4408, 0xb4, 0x81, 0x65, 0x5f, 0x30, 0xf8, 0x61, 0x3f); diff --git a/net/netimpl.cpp b/net/netimpl.cpp index 27cf74487a41c9eb7128efe6bc7dbb2a6372203c..85322eb4385e2afab2eee737f8f64f8e54e4bb7f 100644 --- a/net/netimpl.cpp +++ b/net/netimpl.cpp @@ -1,7 +1,7 @@ #include "netimpl.h" #include "dnsimpl.h" #include "websocketimpl.h" -#include "httpinstanceimpl.h" +#include "http.h" CNetImpl::CNetImpl(void) { @@ -57,7 +57,7 @@ HRESULT CNetImpl::CreateProtocol(Net_Protocol netp, IBase** pBase) CDnsImpl* pDns = ALLOC_NEW CDnsImpl(); rc_assert(pDns != NULL, E_FAIL); - hr = pDns->init_class(m_pIAsynFrame, m_pINet); + hr = pDns->init_class(m_pIAsynFrame); rc_assert(hr == S_OK, E_FAIL); return pDns->QueryInterface(IID_IDns, (void**)pBase); @@ -66,13 +66,13 @@ HRESULT CNetImpl::CreateProtocol(Net_Protocol netp, IBase** pBase) CWebSocketImpl* pWebSocket = ALLOC_NEW CWebSocketImpl(); rc_assert(pWebSocket != NULL, E_FAIL); } else if (protocol_http == netp || protocol_https == netp) { - CHttpInstanceImpl* pObject = ALLOC_NEW CHttpInstanceImpl(); + CHttpIImpl* pObject = ALLOC_NEW CHttpIImpl(); rc_assert(pObject != NULL, E_FAIL); hr = pObject->init_class(m_pIAsynFrame, m_pINet); rc_assert(hr == S_OK, E_FAIL); - return pObject->QueryInterface(IID_IHttpInstance, (void**)pBase); + return pObject->QueryInterface(IID_IHttp, (void**)pBase); } else { } return S_OK; diff --git a/net/netimpl.h b/net/netimpl.h index eb3297298d43628251817e4e7397f2779b29c762..6d495e681661fed66f39c45dafcd81723fb79bc5 100644 --- a/net/netimpl.h +++ b/net/netimpl.h @@ -32,8 +32,8 @@ public: private: _lComPtr m_pRot; - AsynFramePtr m_pIAsynFrame; - NetPtr m_pINet; + _lComPtr m_pIAsynFrame; + _lComPtr m_pINet; }; #endif diff --git a/net/protocol/dns.c b/net/protocol/dns.c index 974da9283e1fd9f736bdd297856235e9e820a896..624b31d3c9fde81ee4e0f84c1a0fc3fb66f5f9d5 100644 --- a/net/protocol/dns.c +++ b/net/protocol/dns.c @@ -37,7 +37,7 @@ #define SAFE_DELETE_ARRAY(p) \ do { \ if (p) { \ - delete[](p); \ + delete[] (p); \ (p) = NULL; \ } \ } while (0) diff --git a/net/protocol/dns.h b/net/protocol/dns.h index def09c600250c55f6dd40c80555dbb2e43d3abdb..fdce621fdbefa35bfbe212db49195debfbdf4ecd 100644 --- a/net/protocol/dns.h +++ b/net/protocol/dns.h @@ -9,8 +9,7 @@ extern "C" { #define BigtoLittle16(A) ((((uint16)(A)&0xff00) >> 8) | (((uint16)(A)&0x00ff) << 8)) #define BigtoLittle32(A) \ - ((((uint32)(A)&0xff000000) >> 24) | (((uint32)(A)&0x00ff0000) >> 8) | (((uint32)(A)&0x0000ff00) << 8) \ - | (((uint32)(A)&0x000000ff) << 24)) + ((((uint32)(A)&0xff000000) >> 24) | (((uint32)(A)&0x00ff0000) >> 8) | (((uint32)(A)&0x0000ff00) << 8) | (((uint32)(A)&0x000000ff) << 24)) #define DNS_PORT 53 diff --git a/net/protocol/icmp.h b/net/protocol/icmp.h index a5fcdc737d8a5c7f76bfe3dda1cdb69f041c72a1..f507f165785218452dccdcf1c19a527f812c7878 100644 --- a/net/protocol/icmp.h +++ b/net/protocol/icmp.h @@ -99,7 +99,7 @@ typedef struct icmp_s { #define icmp_mask icmp_dun.id_mask #define icmp_data icmp_dun.id_data } icmp_t; -//#endif +// #endif int ping(const char* host, int cnt /* DEFAULT(4)*/); diff --git a/net/stdafx.h b/net/stdafx.h index 9668998e25e38ad28a7518afd8813aeccd412929..5a46d2fad918c110ad099ec6cd41f4f437be0952 100644 --- a/net/stdafx.h +++ b/net/stdafx.h @@ -7,8 +7,15 @@ #define _STDAFX_H_ #include -#include -#include -#include + +#include +#include +#include +#include +#include + +#include +#include +#include #endif diff --git a/nettls/Info.plist b/nettls/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..9bcb244429ec1db0606ce6b3d95962276a7c2377 --- /dev/null +++ b/nettls/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + + diff --git a/nettls/nettls.h b/nettls/nettls.h new file mode 100644 index 0000000000000000000000000000000000000000..1923d6524a8f349ca4615265c46c22416fa7c4cf --- /dev/null +++ b/nettls/nettls.h @@ -0,0 +1,16 @@ +// +// nettls.h +// nettls +// +// Created by com on 2023/2/25. +// + +#import + +//! Project version number for nettls. +FOUNDATION_EXPORT double nettlsVersionNumber; + +//! Project version string for nettls. +FOUNDATION_EXPORT const unsigned char nettlsVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import diff --git a/nettls/nettls/aes.h b/nettls/nettls/aes.h index 71fc778fc585f73705379797ec36bdf4ec6b4a02..1fc851c5c4e1ee7cfab451b7ecbbcddcb6149333 100644 --- a/nettls/nettls/aes.h +++ b/nettls/nettls/aes.h @@ -88,8 +88,7 @@ #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */ /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */ -#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE \ - -0x0023 /**< Feature not available. For example, an unsupported AES key size. */ +#define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */ /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */ @@ -317,13 +316,7 @@ int mbedtls_aes_crypt_ecb(mbedtls_aes_context* ctx, int mode, const unsigned cha * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH * on failure. */ -int mbedtls_aes_crypt_cbc( - mbedtls_aes_context* ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char* input, - unsigned char* output); +int mbedtls_aes_crypt_cbc(mbedtls_aes_context* ctx, int mode, size_t length, unsigned char iv[16], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_XTS) @@ -363,12 +356,7 @@ int mbedtls_aes_crypt_cbc( * length is larger than 2^20 blocks (16 MiB). */ int mbedtls_aes_crypt_xts( - mbedtls_aes_xts_context* ctx, - int mode, - size_t length, - const unsigned char data_unit[16], - const unsigned char* input, - unsigned char* output); + mbedtls_aes_xts_context* ctx, int mode, size_t length, const unsigned char data_unit[16], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_XTS */ #if defined(MBEDTLS_CIPHER_MODE_CFB) @@ -412,13 +400,7 @@ int mbedtls_aes_crypt_xts( * \return \c 0 on success. */ int mbedtls_aes_crypt_cfb128( - mbedtls_aes_context* ctx, - int mode, - size_t length, - size_t* iv_off, - unsigned char iv[16], - const unsigned char* input, - unsigned char* output); + mbedtls_aes_context* ctx, int mode, size_t length, size_t* iv_off, unsigned char iv[16], const unsigned char* input, unsigned char* output); /** * \brief This function performs an AES-CFB8 encryption or decryption @@ -457,12 +439,7 @@ int mbedtls_aes_crypt_cfb128( * \return \c 0 on success. */ int mbedtls_aes_crypt_cfb8( - mbedtls_aes_context* ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char* input, - unsigned char* output); + mbedtls_aes_context* ctx, int mode, size_t length, unsigned char iv[16], const unsigned char* input, unsigned char* output); #endif /*MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) @@ -512,12 +489,7 @@ int mbedtls_aes_crypt_cfb8( * \return \c 0 on success. */ int mbedtls_aes_crypt_ofb( - mbedtls_aes_context* ctx, - size_t length, - size_t* iv_off, - unsigned char iv[16], - const unsigned char* input, - unsigned char* output); + mbedtls_aes_context* ctx, size_t length, size_t* iv_off, unsigned char iv[16], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_OFB */ @@ -650,8 +622,7 @@ int mbedtls_internal_aes_decrypt(mbedtls_aes_context* ctx, const unsigned char i * \param input Plaintext block. * \param output Output (ciphertext) block. */ -MBEDTLS_DEPRECATED void - mbedtls_aes_encrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]); +MBEDTLS_DEPRECATED void mbedtls_aes_encrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]); /** * \brief Deprecated internal AES block decryption function @@ -663,8 +634,7 @@ MBEDTLS_DEPRECATED void * \param input Ciphertext block. * \param output Output (plaintext) block. */ -MBEDTLS_DEPRECATED void - mbedtls_aes_decrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]); +MBEDTLS_DEPRECATED void mbedtls_aes_decrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]); #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ diff --git a/nettls/nettls/aria.h b/nettls/nettls/aria.h index ab25a9f1ccdcaa0751ecf013b8303b4e638c0e51..50703dfcc5606be4895eae7f038a6562202e446d 100644 --- a/nettls/nettls/aria.h +++ b/nettls/nettls/aria.h @@ -83,8 +83,7 @@ /* MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE is deprecated and should not be used. */ -#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE \ - -0x005A /**< Feature not available. For example, an unsupported ARIA key size. */ +#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A /**< Feature not available. For example, an unsupported ARIA key size. */ /* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED \ @@ -186,9 +185,7 @@ int mbedtls_aria_setkey_dec(mbedtls_aria_context* ctx, const unsigned char* key, * \return A negative error code on failure. */ int mbedtls_aria_crypt_ecb( - mbedtls_aria_context* ctx, - const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE], - unsigned char output[MBEDTLS_ARIA_BLOCKSIZE]); + mbedtls_aria_context* ctx, const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE], unsigned char output[MBEDTLS_ARIA_BLOCKSIZE]); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** @@ -233,12 +230,7 @@ int mbedtls_aria_crypt_ecb( * \return A negative error code on failure. */ int mbedtls_aria_crypt_cbc( - mbedtls_aria_context* ctx, - int mode, - size_t length, - unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], - const unsigned char* input, - unsigned char* output); + mbedtls_aria_context* ctx, int mode, size_t length, unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) diff --git a/nettls/nettls/asn1.h b/nettls/nettls/asn1.h index c6ed689c053b91eee4e641ee2b36338f5ec47c1e..88c65754a79e5d19d2fd2dff3c7f9b0c2b0ca8fa 100644 --- a/nettls/nettls/asn1.h +++ b/nettls/nettls/asn1.h @@ -142,8 +142,7 @@ * Only works for 'defined' oid_str values (MBEDTLS_OID_HMAC_SHA1), you cannot use a * 'unsigned char *oid' here! */ -#define MBEDTLS_OID_CMP(oid_str, oid_buf) \ - ((MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len) || memcmp((oid_str), (oid_buf)->p, (oid_buf)->len) != 0) +#define MBEDTLS_OID_CMP(oid_str, oid_buf) ((MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len) || memcmp((oid_str), (oid_buf)->p, (oid_buf)->len) != 0) #ifdef __cplusplus extern "C" { diff --git a/nettls/nettls/asn1write.h b/nettls/nettls/asn1write.h index 5f0653fd1c82a0a5cfe5f9d10a15d18915b92ab8..8670e9460debd0d2debacf0571da7b1bf7556feb 100644 --- a/nettls/nettls/asn1write.h +++ b/nettls/nettls/asn1write.h @@ -173,8 +173,7 @@ int mbedtls_asn1_write_oid(unsigned char** p, unsigned char* start, const char* * \return The number of bytes written to \p p on success. * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ -int mbedtls_asn1_write_algorithm_identifier( - unsigned char** p, unsigned char* start, const char* oid, size_t oid_len, size_t par_len); +int mbedtls_asn1_write_algorithm_identifier(unsigned char** p, unsigned char* start, const char* oid, size_t oid_len, size_t par_len); /** * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value @@ -223,8 +222,7 @@ int mbedtls_asn1_write_int(unsigned char** p, unsigned char* start, int val); * \return The number of bytes written to \p p on success. * \return A negative error code on failure. */ -int mbedtls_asn1_write_tagged_string( - unsigned char** p, unsigned char* start, int tag, const char* text, size_t text_len); +int mbedtls_asn1_write_tagged_string(unsigned char** p, unsigned char* start, int tag, const char* text, size_t text_len); /** * \brief Write a string in ASN.1 format using the PrintableString @@ -326,8 +324,8 @@ int mbedtls_asn1_write_octet_string(unsigned char** p, unsigned char* start, con * \return A pointer to the new / existing entry on success. * \return \c NULL if if there was a memory allocation error. */ -mbedtls_asn1_named_data* mbedtls_asn1_store_named_data( - mbedtls_asn1_named_data** list, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len); +mbedtls_asn1_named_data* + mbedtls_asn1_store_named_data(mbedtls_asn1_named_data** list, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len); #ifdef __cplusplus } diff --git a/nettls/nettls/bignum.h b/nettls/nettls/bignum.h index 3101f54c1fb06efd82be121372eb9e93dc08cb1e..3b3d1016e4ae2b529bca38337b639db2ea2262ee 100644 --- a/nettls/nettls/bignum.h +++ b/nettls/nettls/bignum.h @@ -152,9 +152,8 @@ typedef int64_t mbedtls_mpi_sint; typedef uint64_t mbedtls_mpi_uint; #elif defined(__GNUC__) \ - && (defined(__amd64__) || defined(__x86_64__) || defined(__ppc64__) || defined(__powerpc64__) || defined(__ia64__) \ - || defined(__alpha__) || (defined(__sparc__) && defined(__arch64__)) || defined(__s390x__) \ - || defined(__mips64)) + && (defined(__amd64__) || defined(__x86_64__) || defined(__ppc64__) || defined(__powerpc64__) || defined(__ia64__) || defined(__alpha__) \ + || (defined(__sparc__) && defined(__arch64__)) || defined(__s390x__) || defined(__mips64)) #if !defined(MBEDTLS_HAVE_INT64) #define MBEDTLS_HAVE_INT64 #endif /* MBEDTLS_HAVE_INT64 */ @@ -819,8 +818,7 @@ int mbedtls_mpi_mod_int(mbedtls_mpi_uint* r, const mbedtls_mpi* A, mbedtls_mpi_s * \return Another negative error code on different kinds of failures. * */ -int mbedtls_mpi_exp_mod( - mbedtls_mpi* X, const mbedtls_mpi* A, const mbedtls_mpi* E, const mbedtls_mpi* N, mbedtls_mpi* _RR); +int mbedtls_mpi_exp_mod(mbedtls_mpi* X, const mbedtls_mpi* A, const mbedtls_mpi* E, const mbedtls_mpi* N, mbedtls_mpi* _RR); /** * \brief Fill an MPI with a number of random bytes. @@ -897,8 +895,7 @@ int mbedtls_mpi_inv_mod(mbedtls_mpi* X, const mbedtls_mpi* A, const mbedtls_mpi* * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime. * \return Another negative error code on other kinds of failure. */ -MBEDTLS_DEPRECATED int - mbedtls_mpi_is_prime(const mbedtls_mpi* X, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +MBEDTLS_DEPRECATED int mbedtls_mpi_is_prime(const mbedtls_mpi* X, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ @@ -929,8 +926,7 @@ MBEDTLS_DEPRECATED int * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime. * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_is_prime_ext( - const mbedtls_mpi* X, int rounds, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +int mbedtls_mpi_is_prime_ext(const mbedtls_mpi* X, int rounds, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief Flags for mbedtls_mpi_gen_prime() * @@ -961,8 +957,7 @@ typedef enum { * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `nbits` is not between * \c 3 and #MBEDTLS_MPI_MAX_BITS. */ -int mbedtls_mpi_gen_prime( - mbedtls_mpi* X, size_t nbits, int flags, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +int mbedtls_mpi_gen_prime(mbedtls_mpi* X, size_t nbits, int flags, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #if defined(MBEDTLS_SELF_TEST) diff --git a/nettls/nettls/blowfish.h b/nettls/nettls/blowfish.h index 766d28970e584e33a415d5fd646751d430121e1b..e2b71edf64b7d4c08be4b8129eea0b2a6e665b95 100644 --- a/nettls/nettls/blowfish.h +++ b/nettls/nettls/blowfish.h @@ -149,10 +149,7 @@ int mbedtls_blowfish_setkey(mbedtls_blowfish_context* ctx, const unsigned char* * \return A negative error code on failure. */ int mbedtls_blowfish_crypt_ecb( - mbedtls_blowfish_context* ctx, - int mode, - const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], - unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE]); + mbedtls_blowfish_context* ctx, int mode, const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE]); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** diff --git a/nettls/nettls/camellia.h b/nettls/nettls/camellia.h index 76a9065ff935db539ca6eeb3199fe1ebb1847dbd..e5e88f71b85b14fac54950236093d44f4b9245db 100644 --- a/nettls/nettls/camellia.h +++ b/nettls/nettls/camellia.h @@ -154,8 +154,7 @@ int mbedtls_camellia_setkey_dec(mbedtls_camellia_context* ctx, const unsigned ch * \return \c 0 if successful. * \return A negative error code on failure. */ -int mbedtls_camellia_crypt_ecb( - mbedtls_camellia_context* ctx, int mode, const unsigned char input[16], unsigned char output[16]); +int mbedtls_camellia_crypt_ecb(mbedtls_camellia_context* ctx, int mode, const unsigned char input[16], unsigned char output[16]); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** @@ -187,12 +186,7 @@ int mbedtls_camellia_crypt_ecb( * \return A negative error code on failure. */ int mbedtls_camellia_crypt_cbc( - mbedtls_camellia_context* ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char* input, - unsigned char* output); + mbedtls_camellia_context* ctx, int mode, size_t length, unsigned char iv[16], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) @@ -234,13 +228,7 @@ int mbedtls_camellia_crypt_cbc( * \return A negative error code on failure. */ int mbedtls_camellia_crypt_cfb128( - mbedtls_camellia_context* ctx, - int mode, - size_t length, - size_t* iv_off, - unsigned char iv[16], - const unsigned char* input, - unsigned char* output); + mbedtls_camellia_context* ctx, int mode, size_t length, size_t* iv_off, unsigned char iv[16], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) diff --git a/nettls/nettls/ccm.h b/nettls/nettls/ccm.h index 62d4d6d292608ebdc3a455fdd1d09c3eee07d639..c7a1b063b4618fd6df3fcc772d8036a26f1468fc 100644 --- a/nettls/nettls/ccm.h +++ b/nettls/nettls/ccm.h @@ -130,8 +130,7 @@ void mbedtls_ccm_init(mbedtls_ccm_context* ctx); * \return \c 0 on success. * \return A CCM or cipher-specific error code on failure. */ -int mbedtls_ccm_setkey( - mbedtls_ccm_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits); +int mbedtls_ccm_setkey(mbedtls_ccm_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits); /** * \brief This function releases and clears the specified CCM context diff --git a/nettls/nettls/chacha20.h b/nettls/nettls/chacha20.h index 30add6ae13e54622a6c53f18a55bcf1da6cc3deb..7b4f585a865c28ae7ed4412ff463147e837df893 100644 --- a/nettls/nettls/chacha20.h +++ b/nettls/nettls/chacha20.h @@ -192,8 +192,7 @@ int mbedtls_chacha20_starts(mbedtls_chacha20_context* ctx, const unsigned char n * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_chacha20_update( - mbedtls_chacha20_context* ctx, size_t size, const unsigned char* input, unsigned char* output); +int mbedtls_chacha20_update(mbedtls_chacha20_context* ctx, size_t size, const unsigned char* input, unsigned char* output); /** * \brief This function encrypts or decrypts data with ChaCha20 and @@ -224,12 +223,7 @@ int mbedtls_chacha20_update( * \return A negative error code on failure. */ int mbedtls_chacha20_crypt( - const unsigned char key[32], - const unsigned char nonce[12], - uint32_t counter, - size_t size, - const unsigned char* input, - unsigned char* output); + const unsigned char key[32], const unsigned char nonce[12], uint32_t counter, size_t size, const unsigned char* input, unsigned char* output); #if defined(MBEDTLS_SELF_TEST) /** diff --git a/nettls/nettls/chachapoly.h b/nettls/nettls/chachapoly.h index 93a74efac4733644ff1f9bd4881a7c9559e0975b..42c19215d550e83d7125ab7f3b7f9e004f7cee59 100644 --- a/nettls/nettls/chachapoly.h +++ b/nettls/nettls/chachapoly.h @@ -190,8 +190,7 @@ int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context* ctx, const unsigned ch * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_chachapoly_starts( - mbedtls_chachapoly_context* ctx, const unsigned char nonce[12], mbedtls_chachapoly_mode_t mode); +int mbedtls_chachapoly_starts(mbedtls_chachapoly_context* ctx, const unsigned char nonce[12], mbedtls_chachapoly_mode_t mode); /** * \brief This function feeds additional data to be authenticated @@ -265,8 +264,7 @@ int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context* ctx, const unsigne * finished. * \return Another negative error code on other kinds of failure. */ -int mbedtls_chachapoly_update( - mbedtls_chachapoly_context* ctx, size_t len, const unsigned char* input, unsigned char* output); +int mbedtls_chachapoly_update(mbedtls_chachapoly_context* ctx, size_t len, const unsigned char* input, unsigned char* output); /** * \brief This function finished the ChaCha20-Poly1305 operation and diff --git a/nettls/nettls/check_config.h b/nettls/nettls/check_config.h index 69717cc383e530f1b4bd822e2a7242af2361d520..2e9efcd33155321c708016639fabc797a6837cd2 100644 --- a/nettls/nettls/check_config.h +++ b/nettls/nettls/check_config.h @@ -77,8 +77,7 @@ #endif /* _WIN32 */ #if defined(TARGET_LIKE_MBED) && (defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C)) -#error \ - "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS" +#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS" #endif #if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(__GNUC__) && !defined(__clang__) @@ -117,8 +116,7 @@ #error "MBEDTLS_ECDH_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_ECDSA_C) \ - && (!defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_ASN1_PARSE_C) || !defined(MBEDTLS_ASN1_WRITE_C)) +#if defined(MBEDTLS_ECDSA_C) && (!defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_ASN1_PARSE_C) || !defined(MBEDTLS_ASN1_WRITE_C)) #error "MBEDTLS_ECDSA_C defined, but not all prerequisites" #endif @@ -127,9 +125,8 @@ #endif #if defined(MBEDTLS_ECP_RESTARTABLE) \ - && (defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) \ - || defined(MBEDTLS_ECDSA_SIGN_ALT) || defined(MBEDTLS_ECDSA_VERIFY_ALT) || defined(MBEDTLS_ECDSA_GENKEY_ALT) \ - || defined(MBEDTLS_ECP_INTERNAL_ALT) || defined(MBEDTLS_ECP_ALT)) + && (defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) || defined(MBEDTLS_ECDSA_SIGN_ALT) \ + || defined(MBEDTLS_ECDSA_VERIFY_ALT) || defined(MBEDTLS_ECDSA_GENKEY_ALT) || defined(MBEDTLS_ECP_INTERNAL_ALT) || defined(MBEDTLS_ECP_ALT)) #error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative ECP implementation" #endif @@ -139,22 +136,19 @@ #if defined(MBEDTLS_ECP_C) \ && (!defined(MBEDTLS_BIGNUM_C) \ - || (!defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) \ - && !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) \ - && !defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) && !defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) \ - && !defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) && !defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) \ - && !defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) \ - && !defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) && !defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) \ - && !defined(MBEDTLS_ECP_DP_CURVE448_ENABLED))) + || (!defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) \ + && !defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) && !defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) \ + && !defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) && !defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) \ + && !defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) && !defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) \ + && !defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) && !defined(MBEDTLS_ECP_DP_CURVE448_ENABLED))) #error "MBEDTLS_ECP_C defined, but not all prerequisites" #endif #if defined(MBEDTLS_ECP_C) \ && !( \ - defined(MBEDTLS_ECP_ALT) || defined(MBEDTLS_CTR_DRBG_C) || defined(MBEDTLS_HMAC_DRBG_C) \ - || defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_ECP_NO_INTERNAL_RNG)) -#error \ - "MBEDTLS_ECP_C requires a DRBG or SHA-2 module unless MBEDTLS_ECP_NO_INTERNAL_RNG is defined or an alternative implementation is used" + defined(MBEDTLS_ECP_ALT) || defined(MBEDTLS_CTR_DRBG_C) || defined(MBEDTLS_HMAC_DRBG_C) || defined(MBEDTLS_SHA512_C) \ + || defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_ECP_NO_INTERNAL_RNG)) +#error "MBEDTLS_ECP_C requires a DRBG or SHA-2 module unless MBEDTLS_ECP_NO_INTERNAL_RNG is defined or an alternative implementation is used" #endif #if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_ASN1_PARSE_C) @@ -164,12 +158,11 @@ #if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_SHA256_C)) #error "MBEDTLS_ENTROPY_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) \ - && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64) +#if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64) #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high" #endif -#if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256)) \ - && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32) +#if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256)) && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) \ + && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32) #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high" #endif #if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_SHA256_C) @@ -189,8 +182,7 @@ #if defined(MBEDTLS_TEST_NULL_ENTROPY) && (!defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES)) #error "MBEDTLS_TEST_NULL_ENTROPY defined, but not all prerequisites" #endif -#if defined(MBEDTLS_TEST_NULL_ENTROPY) \ - && (defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || defined(MBEDTLS_HAVEGE_C)) +#if defined(MBEDTLS_TEST_NULL_ENTROPY) && (defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || defined(MBEDTLS_HAVEGE_C)) #error "MBEDTLS_TEST_NULL_ENTROPY defined, but entropy sources too" #endif @@ -259,29 +251,24 @@ #endif #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ - && (!defined(MBEDTLS_DHM_C) || !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) \ - || !defined(MBEDTLS_PKCS1_V15)) + && (!defined(MBEDTLS_DHM_C) || !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15)) #error "MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED defined, but not all prerequisites" #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ - && (!defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) \ - || !defined(MBEDTLS_PKCS1_V15)) + && (!defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15)) #error "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED defined, but not all prerequisites" #endif -#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) \ - && (!defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)) +#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && (!defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)) #error "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED defined, but not all prerequisites" #endif -#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) \ - && (!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15)) +#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) && (!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15)) #error "MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED defined, but not all prerequisites" #endif -#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) \ - && (!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15)) +#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && (!defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15)) #error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites" #endif @@ -339,8 +326,7 @@ #endif #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) && (defined(MBEDTLS_PLATFORM_STD_EXIT) || defined(MBEDTLS_PLATFORM_EXIT_ALT)) -#error \ - "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously" +#error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously" #endif #if defined(MBEDTLS_PLATFORM_TIME_ALT) && (!defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_HAVE_TIME)) @@ -356,14 +342,11 @@ #endif #if defined(MBEDTLS_PLATFORM_TIME_MACRO) && (defined(MBEDTLS_PLATFORM_STD_TIME) || defined(MBEDTLS_PLATFORM_TIME_ALT)) -#error \ - "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously" +#error "MBEDTLS_PLATFORM_TIME_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously" #endif -#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) \ - && (defined(MBEDTLS_PLATFORM_STD_TIME) || defined(MBEDTLS_PLATFORM_TIME_ALT)) -#error \ - "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously" +#if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) && (defined(MBEDTLS_PLATFORM_STD_TIME) || defined(MBEDTLS_PLATFORM_TIME_ALT)) +#error "MBEDTLS_PLATFORM_TIME_TYPE_MACRO and MBEDTLS_PLATFORM_STD_TIME/MBEDTLS_PLATFORM_TIME_ALT cannot be defined simultaneously" #endif #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C) @@ -374,10 +357,8 @@ #error "MBEDTLS_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) \ - && (defined(MBEDTLS_PLATFORM_STD_FPRINTF) || defined(MBEDTLS_PLATFORM_FPRINTF_ALT)) -#error \ - "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously" +#if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) && (defined(MBEDTLS_PLATFORM_STD_FPRINTF) || defined(MBEDTLS_PLATFORM_FPRINTF_ALT)) +#error "MBEDTLS_PLATFORM_FPRINTF_MACRO and MBEDTLS_PLATFORM_STD_FPRINTF/MBEDTLS_PLATFORM_FPRINTF_ALT cannot be defined simultaneously" #endif #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && (!defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY)) @@ -416,10 +397,8 @@ #error "MBEDTLS_PLATFORM_PRINTF_MACRO defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) \ - && (defined(MBEDTLS_PLATFORM_STD_PRINTF) || defined(MBEDTLS_PLATFORM_PRINTF_ALT)) -#error \ - "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously" +#if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) && (defined(MBEDTLS_PLATFORM_STD_PRINTF) || defined(MBEDTLS_PLATFORM_PRINTF_ALT)) +#error "MBEDTLS_PLATFORM_PRINTF_MACRO and MBEDTLS_PLATFORM_STD_PRINTF/MBEDTLS_PLATFORM_PRINTF_ALT cannot be defined simultaneously" #endif #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C) @@ -430,10 +409,8 @@ #error "MBEDTLS_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) \ - && (defined(MBEDTLS_PLATFORM_STD_SNPRINTF) || defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)) -#error \ - "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously" +#if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) && (defined(MBEDTLS_PLATFORM_STD_SNPRINTF) || defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)) +#error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously" #endif #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) && !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) @@ -488,13 +465,11 @@ #error "MBEDTLS_PLATFORM_STD_NV_SEED_WRITE defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) \ - && (defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) || defined(MBEDTLS_PLATFORM_NV_SEED_ALT)) +#if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && (defined(MBEDTLS_PLATFORM_STD_NV_SEED_READ) || defined(MBEDTLS_PLATFORM_NV_SEED_ALT)) #error "MBEDTLS_PLATFORM_NV_SEED_READ_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_READ cannot be defined simultaneously" #endif -#if defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) \ - && (defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) || defined(MBEDTLS_PLATFORM_NV_SEED_ALT)) +#if defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) && (defined(MBEDTLS_PLATFORM_STD_NV_SEED_WRITE) || defined(MBEDTLS_PLATFORM_NV_SEED_ALT)) #error "MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO and MBEDTLS_PLATFORM_STD_NV_SEED_WRITE cannot be defined simultaneously" #endif @@ -522,14 +497,11 @@ #error "MBEDTLS_SSL_PROTO_TLS1_1 defined, but not all prerequisites" #endif -#if defined(MBEDTLS_SSL_PROTO_TLS1_2) \ - && (!defined(MBEDTLS_SHA1_C) && !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C)) +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && (!defined(MBEDTLS_SHA1_C) && !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C)) #error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites" #endif -#if ( \ - defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) \ - || defined(MBEDTLS_SSL_PROTO_TLS1_2)) \ +#if (defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2)) \ && !( \ defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) \ @@ -563,13 +535,11 @@ #error "MBEDTLS_SSL_TLS_C defined, but no protocols are active" #endif -#if defined(MBEDTLS_SSL_TLS_C) \ - && (defined(MBEDTLS_SSL_PROTO_SSL3) && defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1)) +#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1)) #error "Illegal protocol selection" #endif -#if defined(MBEDTLS_SSL_TLS_C) \ - && (defined(MBEDTLS_SSL_PROTO_TLS1) && defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1)) +#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_TLS1) && defined(MBEDTLS_SSL_PROTO_TLS1_2) && !defined(MBEDTLS_SSL_PROTO_TLS1_1)) #error "Illegal protocol selection" #endif @@ -600,8 +570,8 @@ #error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites" #endif -#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && !defined(MBEDTLS_SSL_PROTO_TLS1) \ - && !defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1_2) +#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && !defined(MBEDTLS_SSL_PROTO_TLS1) && !defined(MBEDTLS_SSL_PROTO_TLS1_1) \ + && !defined(MBEDTLS_SSL_PROTO_TLS1_2) #error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites" #endif @@ -641,14 +611,12 @@ #endif #if defined(MBEDTLS_X509_USE_C) \ - && (!defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) \ - || !defined(MBEDTLS_PK_PARSE_C)) + && (!defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || !defined(MBEDTLS_PK_PARSE_C)) #error "MBEDTLS_X509_USE_C defined, but not all prerequisites" #endif #if defined(MBEDTLS_X509_CREATE_C) \ - && (!defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) \ - || !defined(MBEDTLS_PK_WRITE_C)) + && (!defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || !defined(MBEDTLS_PK_WRITE_C)) #error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites" #endif diff --git a/nettls/nettls/cipher.h b/nettls/nettls/cipher.h index eb8286da8f97a78066eb9e608564768cc5069626..8b11c526c23a7df75996321cdbd70f0d055ca159 100644 --- a/nettls/nettls/cipher.h +++ b/nettls/nettls/cipher.h @@ -395,8 +395,7 @@ const mbedtls_cipher_info_t* mbedtls_cipher_info_from_type(const mbedtls_cipher_ * given \p cipher_id. * \return \c NULL if the associated cipher information is not found. */ -const mbedtls_cipher_info_t* mbedtls_cipher_info_from_values( - const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode); +const mbedtls_cipher_info_t* mbedtls_cipher_info_from_values(const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode); /** * \brief This function initializes a \p cipher_context as NONE. @@ -579,8 +578,7 @@ static inline mbedtls_operation_t mbedtls_cipher_get_operation(const mbedtls_cip * parameter-verification failure. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_setkey( - mbedtls_cipher_context_t* ctx, const unsigned char* key, int key_bitlen, const mbedtls_operation_t operation); +int mbedtls_cipher_setkey(mbedtls_cipher_context_t* ctx, const unsigned char* key, int key_bitlen, const mbedtls_operation_t operation); #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) /** @@ -685,8 +683,7 @@ int mbedtls_cipher_update_ad(mbedtls_cipher_context_t* ctx, const unsigned char* * unsupported mode for a cipher. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_update( - mbedtls_cipher_context_t* ctx, const unsigned char* input, size_t ilen, unsigned char* output, size_t* olen); +int mbedtls_cipher_update(mbedtls_cipher_context_t* ctx, const unsigned char* input, size_t ilen, unsigned char* output, size_t* olen); /** * \brief The generic cipher finalization function. If data still diff --git a/nettls/nettls/cipher_internal.h b/nettls/nettls/cipher_internal.h index 107fcd8f05f37c35db2958ed9d17545cc791c7b9..9c0a824ff2d50c466949563bfac0dd9fab7b0ca9 100644 --- a/nettls/nettls/cipher_internal.h +++ b/nettls/nettls/cipher_internal.h @@ -75,31 +75,18 @@ struct mbedtls_cipher_base_t { #if defined(MBEDTLS_CIPHER_MODE_CBC) /** Encrypt using CBC */ - int (*cbc_func)( - void* ctx, - mbedtls_operation_t mode, - size_t length, - unsigned char* iv, - const unsigned char* input, - unsigned char* output); + int (*cbc_func)(void* ctx, mbedtls_operation_t mode, size_t length, unsigned char* iv, const unsigned char* input, unsigned char* output); #endif #if defined(MBEDTLS_CIPHER_MODE_CFB) /** Encrypt using CFB (Full length) */ int (*cfb_func)( - void* ctx, - mbedtls_operation_t mode, - size_t length, - size_t* iv_off, - unsigned char* iv, - const unsigned char* input, - unsigned char* output); + void* ctx, mbedtls_operation_t mode, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output); #endif #if defined(MBEDTLS_CIPHER_MODE_OFB) /** Encrypt using OFB (Full length) */ - int (*ofb_func)( - void* ctx, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output); + int (*ofb_func)(void* ctx, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output); #endif #if defined(MBEDTLS_CIPHER_MODE_CTR) @@ -117,12 +104,7 @@ struct mbedtls_cipher_base_t { #if defined(MBEDTLS_CIPHER_MODE_XTS) /** Encrypt or decrypt using XTS. */ int (*xts_func)( - void* ctx, - mbedtls_operation_t mode, - size_t length, - const unsigned char data_unit[16], - const unsigned char* input, - unsigned char* output); + void* ctx, mbedtls_operation_t mode, size_t length, const unsigned char data_unit[16], const unsigned char* input, unsigned char* output); #endif #if defined(MBEDTLS_CIPHER_MODE_STREAM) diff --git a/nettls/nettls/cmac.h b/nettls/nettls/cmac.h index 19ac6f53f52f6be723095b07974392865effa54f..e6c3e755d55e5bb98674fffe17c2b00162ef2e7a 100644 --- a/nettls/nettls/cmac.h +++ b/nettls/nettls/cmac.h @@ -217,8 +217,7 @@ int mbedtls_cipher_cmac( * * \return \c 0 on success. */ -int mbedtls_aes_cmac_prf_128( - const unsigned char* key, size_t key_len, const unsigned char* input, size_t in_len, unsigned char output[16]); +int mbedtls_aes_cmac_prf_128(const unsigned char* key, size_t key_len, const unsigned char* input, size_t in_len, unsigned char output[16]); #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_SELF_TEST) && (defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C)) diff --git a/nettls/nettls/compat-1.3.h b/nettls/nettls/compat-1.3.h index 3f4366da863352253176b9156ec9c29f03cd36fb..9b8f58802d7cd4b73b9a7078f3811953985770f1 100644 --- a/nettls/nettls/compat-1.3.h +++ b/nettls/nettls/compat-1.3.h @@ -1409,1149 +1409,1147 @@ #define SSL_ANTI_REPLAY_ENABLED MBEDTLS_SSL_ANTI_REPLAY_ENABLED #define SSL_ARC4_DISABLED MBEDTLS_SSL_ARC4_DISABLED #define SSL_ARC4_ENABLED MBEDTLS_SSL_ARC4_ENABLED -#define SSL_BUFFER_LEN \ - (((MBEDTLS_SSL_IN_BUFFER_LEN) < (MBEDTLS_SSL_OUT_BUFFER_LEN)) ? (MBEDTLS_SSL_IN_BUFFER_LEN) \ - : (MBEDTLS_SSL_OUT_BUFFER_LEN)) -#define SSL_CACHE_DEFAULT_MAX_ENTRIES MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES -#define SSL_CACHE_DEFAULT_TIMEOUT MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT -#define SSL_CBC_RECORD_SPLITTING_DISABLED MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED -#define SSL_CBC_RECORD_SPLITTING_ENABLED MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED -#define SSL_CERTIFICATE_REQUEST MBEDTLS_SSL_CERTIFICATE_REQUEST -#define SSL_CERTIFICATE_VERIFY MBEDTLS_SSL_CERTIFICATE_VERIFY -#define SSL_CERT_TYPE_ECDSA_SIGN MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN -#define SSL_CERT_TYPE_RSA_SIGN MBEDTLS_SSL_CERT_TYPE_RSA_SIGN -#define SSL_CHANNEL_INBOUND MBEDTLS_SSL_CHANNEL_INBOUND -#define SSL_CHANNEL_OUTBOUND MBEDTLS_SSL_CHANNEL_OUTBOUND -#define SSL_CIPHERSUITES MBEDTLS_SSL_CIPHERSUITES -#define SSL_CLIENT_CERTIFICATE MBEDTLS_SSL_CLIENT_CERTIFICATE -#define SSL_CLIENT_CHANGE_CIPHER_SPEC MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC -#define SSL_CLIENT_FINISHED MBEDTLS_SSL_CLIENT_FINISHED -#define SSL_CLIENT_HELLO MBEDTLS_SSL_CLIENT_HELLO -#define SSL_CLIENT_KEY_EXCHANGE MBEDTLS_SSL_CLIENT_KEY_EXCHANGE -#define SSL_COMPRESSION_ADD MBEDTLS_SSL_COMPRESSION_ADD -#define SSL_COMPRESS_DEFLATE MBEDTLS_SSL_COMPRESS_DEFLATE -#define SSL_COMPRESS_NULL MBEDTLS_SSL_COMPRESS_NULL -#define SSL_DEBUG_BUF MBEDTLS_SSL_DEBUG_BUF -#define SSL_DEBUG_CRT MBEDTLS_SSL_DEBUG_CRT -#define SSL_DEBUG_ECP MBEDTLS_SSL_DEBUG_ECP -#define SSL_DEBUG_MPI MBEDTLS_SSL_DEBUG_MPI -#define SSL_DEBUG_MSG MBEDTLS_SSL_DEBUG_MSG -#define SSL_DEBUG_RET MBEDTLS_SSL_DEBUG_RET -#define SSL_DEFAULT_TICKET_LIFETIME MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME -#define SSL_DTLS_TIMEOUT_DFL_MAX MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX -#define SSL_DTLS_TIMEOUT_DFL_MIN MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN -#define SSL_EMPTY_RENEGOTIATION_INFO MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO -#define SSL_ETM_DISABLED MBEDTLS_SSL_ETM_DISABLED -#define SSL_ETM_ENABLED MBEDTLS_SSL_ETM_ENABLED -#define SSL_EXTENDED_MS_DISABLED MBEDTLS_SSL_EXTENDED_MS_DISABLED -#define SSL_EXTENDED_MS_ENABLED MBEDTLS_SSL_EXTENDED_MS_ENABLED -#define SSL_FALLBACK_SCSV MBEDTLS_SSL_FALLBACK_SCSV -#define SSL_FLUSH_BUFFERS MBEDTLS_SSL_FLUSH_BUFFERS -#define SSL_HANDSHAKE_OVER MBEDTLS_SSL_HANDSHAKE_OVER -#define SSL_HANDSHAKE_WRAPUP MBEDTLS_SSL_HANDSHAKE_WRAPUP -#define SSL_HASH_MD5 MBEDTLS_SSL_HASH_MD5 -#define SSL_HASH_NONE MBEDTLS_SSL_HASH_NONE -#define SSL_HASH_SHA1 MBEDTLS_SSL_HASH_SHA1 -#define SSL_HASH_SHA224 MBEDTLS_SSL_HASH_SHA224 -#define SSL_HASH_SHA256 MBEDTLS_SSL_HASH_SHA256 -#define SSL_HASH_SHA384 MBEDTLS_SSL_HASH_SHA384 -#define SSL_HASH_SHA512 MBEDTLS_SSL_HASH_SHA512 -#define SSL_HELLO_REQUEST MBEDTLS_SSL_HELLO_REQUEST -#define SSL_HS_CERTIFICATE MBEDTLS_SSL_HS_CERTIFICATE -#define SSL_HS_CERTIFICATE_REQUEST MBEDTLS_SSL_HS_CERTIFICATE_REQUEST -#define SSL_HS_CERTIFICATE_VERIFY MBEDTLS_SSL_HS_CERTIFICATE_VERIFY -#define SSL_HS_CLIENT_HELLO MBEDTLS_SSL_HS_CLIENT_HELLO -#define SSL_HS_CLIENT_KEY_EXCHANGE MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE -#define SSL_HS_FINISHED MBEDTLS_SSL_HS_FINISHED -#define SSL_HS_HELLO_REQUEST MBEDTLS_SSL_HS_HELLO_REQUEST -#define SSL_HS_HELLO_VERIFY_REQUEST MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST -#define SSL_HS_NEW_SESSION_TICKET MBEDTLS_SSL_HS_NEW_SESSION_TICKET -#define SSL_HS_SERVER_HELLO MBEDTLS_SSL_HS_SERVER_HELLO -#define SSL_HS_SERVER_HELLO_DONE MBEDTLS_SSL_HS_SERVER_HELLO_DONE -#define SSL_HS_SERVER_KEY_EXCHANGE MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE -#define SSL_INITIAL_HANDSHAKE MBEDTLS_SSL_INITIAL_HANDSHAKE -#define SSL_IS_CLIENT MBEDTLS_SSL_IS_CLIENT -#define SSL_IS_FALLBACK MBEDTLS_SSL_IS_FALLBACK -#define SSL_IS_NOT_FALLBACK MBEDTLS_SSL_IS_NOT_FALLBACK -#define SSL_IS_SERVER MBEDTLS_SSL_IS_SERVER -#define SSL_LEGACY_ALLOW_RENEGOTIATION MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION -#define SSL_LEGACY_BREAK_HANDSHAKE MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE -#define SSL_LEGACY_NO_RENEGOTIATION MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION -#define SSL_LEGACY_RENEGOTIATION MBEDTLS_SSL_LEGACY_RENEGOTIATION -#define SSL_MAC_ADD MBEDTLS_SSL_MAC_ADD -#define SSL_MAJOR_VERSION_3 MBEDTLS_SSL_MAJOR_VERSION_3 -#define SSL_MAX_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN -#define SSL_MAX_FRAG_LEN_1024 MBEDTLS_SSL_MAX_FRAG_LEN_1024 -#define SSL_MAX_FRAG_LEN_2048 MBEDTLS_SSL_MAX_FRAG_LEN_2048 -#define SSL_MAX_FRAG_LEN_4096 MBEDTLS_SSL_MAX_FRAG_LEN_4096 -#define SSL_MAX_FRAG_LEN_512 MBEDTLS_SSL_MAX_FRAG_LEN_512 -#define SSL_MAX_FRAG_LEN_INVALID MBEDTLS_SSL_MAX_FRAG_LEN_INVALID -#define SSL_MAX_FRAG_LEN_NONE MBEDTLS_SSL_MAX_FRAG_LEN_NONE -#define SSL_MAX_MAJOR_VERSION MBEDTLS_SSL_MAX_MAJOR_VERSION -#define SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MAX_MINOR_VERSION -#define SSL_MINOR_VERSION_0 MBEDTLS_SSL_MINOR_VERSION_0 -#define SSL_MINOR_VERSION_1 MBEDTLS_SSL_MINOR_VERSION_1 -#define SSL_MINOR_VERSION_2 MBEDTLS_SSL_MINOR_VERSION_2 -#define SSL_MINOR_VERSION_3 MBEDTLS_SSL_MINOR_VERSION_3 -#define SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MIN_MAJOR_VERSION -#define SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MIN_MINOR_VERSION -#define SSL_MSG_ALERT MBEDTLS_SSL_MSG_ALERT -#define SSL_MSG_APPLICATION_DATA MBEDTLS_SSL_MSG_APPLICATION_DATA -#define SSL_MSG_CHANGE_CIPHER_SPEC MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC -#define SSL_MSG_HANDSHAKE MBEDTLS_SSL_MSG_HANDSHAKE -#define SSL_PADDING_ADD MBEDTLS_SSL_PADDING_ADD -#define SSL_RENEGOTIATION MBEDTLS_SSL_RENEGOTIATION -#define SSL_RENEGOTIATION_DISABLED MBEDTLS_SSL_RENEGOTIATION_DISABLED -#define SSL_RENEGOTIATION_DONE MBEDTLS_SSL_RENEGOTIATION_DONE -#define SSL_RENEGOTIATION_ENABLED MBEDTLS_SSL_RENEGOTIATION_ENABLED -#define SSL_RENEGOTIATION_NOT_ENFORCED MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -#define SSL_RENEGOTIATION_PENDING MBEDTLS_SSL_RENEGOTIATION_PENDING -#define SSL_RENEGO_MAX_RECORDS_DEFAULT MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT -#define SSL_RETRANS_FINISHED MBEDTLS_SSL_RETRANS_FINISHED -#define SSL_RETRANS_PREPARING MBEDTLS_SSL_RETRANS_PREPARING -#define SSL_RETRANS_SENDING MBEDTLS_SSL_RETRANS_SENDING -#define SSL_RETRANS_WAITING MBEDTLS_SSL_RETRANS_WAITING -#define SSL_SECURE_RENEGOTIATION MBEDTLS_SSL_SECURE_RENEGOTIATION -#define SSL_SERVER_CERTIFICATE MBEDTLS_SSL_SERVER_CERTIFICATE -#define SSL_SERVER_CHANGE_CIPHER_SPEC MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC -#define SSL_SERVER_FINISHED MBEDTLS_SSL_SERVER_FINISHED -#define SSL_SERVER_HELLO MBEDTLS_SSL_SERVER_HELLO -#define SSL_SERVER_HELLO_DONE MBEDTLS_SSL_SERVER_HELLO_DONE -#define SSL_SERVER_HELLO_VERIFY_REQUEST_SENT MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT -#define SSL_SERVER_KEY_EXCHANGE MBEDTLS_SSL_SERVER_KEY_EXCHANGE -#define SSL_SERVER_NEW_SESSION_TICKET MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET -#define SSL_SESSION_TICKETS_DISABLED MBEDTLS_SSL_SESSION_TICKETS_DISABLED -#define SSL_SESSION_TICKETS_ENABLED MBEDTLS_SSL_SESSION_TICKETS_ENABLED -#define SSL_SIG_ANON MBEDTLS_SSL_SIG_ANON -#define SSL_SIG_ECDSA MBEDTLS_SSL_SIG_ECDSA -#define SSL_SIG_RSA MBEDTLS_SSL_SIG_RSA -#define SSL_TRANSPORT_DATAGRAM MBEDTLS_SSL_TRANSPORT_DATAGRAM -#define SSL_TRANSPORT_STREAM MBEDTLS_SSL_TRANSPORT_STREAM -#define SSL_TRUNCATED_HMAC_LEN MBEDTLS_SSL_TRUNCATED_HMAC_LEN -#define SSL_TRUNC_HMAC_DISABLED MBEDTLS_SSL_TRUNC_HMAC_DISABLED -#define SSL_TRUNC_HMAC_ENABLED MBEDTLS_SSL_TRUNC_HMAC_ENABLED -#define SSL_VERIFY_DATA_MAX_LEN MBEDTLS_SSL_VERIFY_DATA_MAX_LEN -#define SSL_VERIFY_NONE MBEDTLS_SSL_VERIFY_NONE -#define SSL_VERIFY_OPTIONAL MBEDTLS_SSL_VERIFY_OPTIONAL -#define SSL_VERIFY_REQUIRED MBEDTLS_SSL_VERIFY_REQUIRED -#define TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA -#define TLS_DHE_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA -#define TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 -#define TLS_DHE_PSK_WITH_AES_128_CCM MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM -#define TLS_DHE_PSK_WITH_AES_128_CCM_8 MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8 -#define TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 -#define TLS_DHE_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA -#define TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 -#define TLS_DHE_PSK_WITH_AES_256_CCM MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM -#define TLS_DHE_PSK_WITH_AES_256_CCM_8 MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8 -#define TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 -#define TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_DHE_PSK_WITH_NULL_SHA MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA -#define TLS_DHE_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 -#define TLS_DHE_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 -#define TLS_DHE_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA -#define TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA -#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA -#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 -#define TLS_DHE_RSA_WITH_AES_128_CCM MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM -#define TLS_DHE_RSA_WITH_AES_128_CCM_8 MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8 -#define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 -#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA -#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 -#define TLS_DHE_RSA_WITH_AES_256_CCM MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM -#define TLS_DHE_RSA_WITH_AES_256_CCM_8 MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8 -#define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 -#define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA -#define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA -#define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 -#define TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_DHE_RSA_WITH_DES_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA -#define TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA -#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA -#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 -#define TLS_ECDHE_ECDSA_WITH_AES_128_CCM MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM -#define TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 -#define TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 -#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA -#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 -#define TLS_ECDHE_ECDSA_WITH_AES_256_CCM MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM -#define TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 -#define TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 -#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_ECDHE_ECDSA_WITH_NULL_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA -#define TLS_ECDHE_ECDSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA -#define TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA -#define TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA -#define TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 -#define TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA -#define TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 -#define TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_ECDHE_PSK_WITH_NULL_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA -#define TLS_ECDHE_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 -#define TLS_ECDHE_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 -#define TLS_ECDHE_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA -#define TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA -#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA -#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 -#define TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 -#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA -#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 -#define TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 -#define TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_ECDHE_RSA_WITH_NULL_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA -#define TLS_ECDHE_RSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA -#define TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA -#define TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA -#define TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 -#define TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 -#define TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA -#define TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 -#define TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 -#define TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_ECDH_ECDSA_WITH_NULL_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA -#define TLS_ECDH_ECDSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA -#define TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA -#define TLS_ECDH_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA -#define TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 -#define TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 -#define TLS_ECDH_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA -#define TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 -#define TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 -#define TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_ECDH_RSA_WITH_NULL_SHA MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA -#define TLS_ECDH_RSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA -#define TLS_EXT_ALPN MBEDTLS_TLS_EXT_ALPN -#define TLS_EXT_ENCRYPT_THEN_MAC MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC -#define TLS_EXT_EXTENDED_MASTER_SECRET MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET -#define TLS_EXT_MAX_FRAGMENT_LENGTH MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH -#define TLS_EXT_RENEGOTIATION_INFO MBEDTLS_TLS_EXT_RENEGOTIATION_INFO -#define TLS_EXT_SERVERNAME MBEDTLS_TLS_EXT_SERVERNAME -#define TLS_EXT_SERVERNAME_HOSTNAME MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME -#define TLS_EXT_SESSION_TICKET MBEDTLS_TLS_EXT_SESSION_TICKET -#define TLS_EXT_SIG_ALG MBEDTLS_TLS_EXT_SIG_ALG -#define TLS_EXT_SUPPORTED_ELLIPTIC_CURVES MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES -#define TLS_EXT_SUPPORTED_POINT_FORMATS MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS -#define TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT -#define TLS_EXT_TRUNCATED_HMAC MBEDTLS_TLS_EXT_TRUNCATED_HMAC -#define TLS_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA -#define TLS_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA -#define TLS_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 -#define TLS_PSK_WITH_AES_128_CCM MBEDTLS_TLS_PSK_WITH_AES_128_CCM -#define TLS_PSK_WITH_AES_128_CCM_8 MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8 -#define TLS_PSK_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 -#define TLS_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA -#define TLS_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 -#define TLS_PSK_WITH_AES_256_CCM MBEDTLS_TLS_PSK_WITH_AES_256_CCM -#define TLS_PSK_WITH_AES_256_CCM_8 MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8 -#define TLS_PSK_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 -#define TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_PSK_WITH_NULL_SHA MBEDTLS_TLS_PSK_WITH_NULL_SHA -#define TLS_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_PSK_WITH_NULL_SHA256 -#define TLS_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_PSK_WITH_NULL_SHA384 -#define TLS_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_PSK_WITH_RC4_128_SHA -#define TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA -#define TLS_RSA_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA -#define TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 -#define TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 -#define TLS_RSA_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA -#define TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 -#define TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 -#define TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 -#define TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_RSA_PSK_WITH_NULL_SHA MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA -#define TLS_RSA_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 -#define TLS_RSA_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 -#define TLS_RSA_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA -#define TLS_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA -#define TLS_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA -#define TLS_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 -#define TLS_RSA_WITH_AES_128_CCM MBEDTLS_TLS_RSA_WITH_AES_128_CCM -#define TLS_RSA_WITH_AES_128_CCM_8 MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8 -#define TLS_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 -#define TLS_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA -#define TLS_RSA_WITH_AES_256_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 -#define TLS_RSA_WITH_AES_256_CCM MBEDTLS_TLS_RSA_WITH_AES_256_CCM -#define TLS_RSA_WITH_AES_256_CCM_8 MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8 -#define TLS_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 -#define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA -#define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 -#define TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 -#define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA -#define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 -#define TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 -#define TLS_RSA_WITH_DES_CBC_SHA MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA -#define TLS_RSA_WITH_NULL_MD5 MBEDTLS_TLS_RSA_WITH_NULL_MD5 -#define TLS_RSA_WITH_NULL_SHA MBEDTLS_TLS_RSA_WITH_NULL_SHA -#define TLS_RSA_WITH_NULL_SHA256 MBEDTLS_TLS_RSA_WITH_NULL_SHA256 -#define TLS_RSA_WITH_RC4_128_MD5 MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 -#define TLS_RSA_WITH_RC4_128_SHA MBEDTLS_TLS_RSA_WITH_RC4_128_SHA -#define X509_CRT_VERSION_1 MBEDTLS_X509_CRT_VERSION_1 -#define X509_CRT_VERSION_2 MBEDTLS_X509_CRT_VERSION_2 -#define X509_CRT_VERSION_3 MBEDTLS_X509_CRT_VERSION_3 -#define X509_FORMAT_DER MBEDTLS_X509_FORMAT_DER -#define X509_FORMAT_PEM MBEDTLS_X509_FORMAT_PEM -#define X509_MAX_DN_NAME_SIZE MBEDTLS_X509_MAX_DN_NAME_SIZE -#define X509_RFC5280_MAX_SERIAL_LEN MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN -#define X509_RFC5280_UTC_TIME_LEN MBEDTLS_X509_RFC5280_UTC_TIME_LEN -#define XTEA_DECRYPT MBEDTLS_XTEA_DECRYPT -#define XTEA_ENCRYPT MBEDTLS_XTEA_ENCRYPT -#define _asn1_bitstring mbedtls_asn1_bitstring -#define _asn1_buf mbedtls_asn1_buf -#define _asn1_named_data mbedtls_asn1_named_data -#define _asn1_sequence mbedtls_asn1_sequence -#define _ssl_cache_context mbedtls_ssl_cache_context -#define _ssl_cache_entry mbedtls_ssl_cache_entry -#define _ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t -#define _ssl_context mbedtls_ssl_context -#define _ssl_flight_item mbedtls_ssl_flight_item -#define _ssl_handshake_params mbedtls_ssl_handshake_params -#define _ssl_key_cert mbedtls_ssl_key_cert -#define _ssl_premaster_secret mbedtls_ssl_premaster_secret -#define _ssl_session mbedtls_ssl_session -#define _ssl_transform mbedtls_ssl_transform -#define _x509_crl mbedtls_x509_crl -#define _x509_crl_entry mbedtls_x509_crl_entry -#define _x509_crt mbedtls_x509_crt -#define _x509_csr mbedtls_x509_csr -#define _x509_time mbedtls_x509_time -#define _x509write_cert mbedtls_x509write_cert -#define _x509write_csr mbedtls_x509write_csr -#define aes_context mbedtls_aes_context -#define aes_crypt_cbc mbedtls_aes_crypt_cbc -#define aes_crypt_cfb128 mbedtls_aes_crypt_cfb128 -#define aes_crypt_cfb8 mbedtls_aes_crypt_cfb8 -#define aes_crypt_ctr mbedtls_aes_crypt_ctr -#define aes_crypt_ecb mbedtls_aes_crypt_ecb -#define aes_free mbedtls_aes_free -#define aes_init mbedtls_aes_init -#define aes_self_test mbedtls_aes_self_test -#define aes_setkey_dec mbedtls_aes_setkey_dec -#define aes_setkey_enc mbedtls_aes_setkey_enc -#define aesni_crypt_ecb mbedtls_aesni_crypt_ecb -#define aesni_gcm_mult mbedtls_aesni_gcm_mult -#define aesni_inverse_key mbedtls_aesni_inverse_key -#define aesni_setkey_enc mbedtls_aesni_setkey_enc -#define aesni_supports mbedtls_aesni_has_support -#define alarmed mbedtls_timing_alarmed -#define arc4_context mbedtls_arc4_context -#define arc4_crypt mbedtls_arc4_crypt -#define arc4_free mbedtls_arc4_free -#define arc4_init mbedtls_arc4_init -#define arc4_self_test mbedtls_arc4_self_test -#define arc4_setup mbedtls_arc4_setup -#define asn1_bitstring mbedtls_asn1_bitstring -#define asn1_buf mbedtls_asn1_buf -#define asn1_find_named_data mbedtls_asn1_find_named_data -#define asn1_free_named_data mbedtls_asn1_free_named_data -#define asn1_free_named_data_list mbedtls_asn1_free_named_data_list -#define asn1_get_alg mbedtls_asn1_get_alg -#define asn1_get_alg_null mbedtls_asn1_get_alg_null -#define asn1_get_bitstring mbedtls_asn1_get_bitstring -#define asn1_get_bitstring_null mbedtls_asn1_get_bitstring_null -#define asn1_get_bool mbedtls_asn1_get_bool -#define asn1_get_int mbedtls_asn1_get_int -#define asn1_get_len mbedtls_asn1_get_len -#define asn1_get_mpi mbedtls_asn1_get_mpi -#define asn1_get_sequence_of mbedtls_asn1_get_sequence_of -#define asn1_get_tag mbedtls_asn1_get_tag -#define asn1_named_data mbedtls_asn1_named_data -#define asn1_sequence mbedtls_asn1_sequence -#define asn1_store_named_data mbedtls_asn1_store_named_data -#define asn1_write_algorithm_identifier mbedtls_asn1_write_algorithm_identifier -#define asn1_write_bitstring mbedtls_asn1_write_bitstring -#define asn1_write_bool mbedtls_asn1_write_bool -#define asn1_write_ia5_string mbedtls_asn1_write_ia5_string -#define asn1_write_int mbedtls_asn1_write_int -#define asn1_write_len mbedtls_asn1_write_len -#define asn1_write_mpi mbedtls_asn1_write_mpi -#define asn1_write_null mbedtls_asn1_write_null -#define asn1_write_octet_string mbedtls_asn1_write_octet_string -#define asn1_write_oid mbedtls_asn1_write_oid -#define asn1_write_printable_string mbedtls_asn1_write_printable_string -#define asn1_write_raw_buffer mbedtls_asn1_write_raw_buffer -#define asn1_write_tag mbedtls_asn1_write_tag -#define base64_decode mbedtls_base64_decode -#define base64_encode mbedtls_base64_encode -#define base64_self_test mbedtls_base64_self_test -#define blowfish_context mbedtls_blowfish_context -#define blowfish_crypt_cbc mbedtls_blowfish_crypt_cbc -#define blowfish_crypt_cfb64 mbedtls_blowfish_crypt_cfb64 -#define blowfish_crypt_ctr mbedtls_blowfish_crypt_ctr -#define blowfish_crypt_ecb mbedtls_blowfish_crypt_ecb -#define blowfish_free mbedtls_blowfish_free -#define blowfish_init mbedtls_blowfish_init -#define blowfish_setkey mbedtls_blowfish_setkey -#define camellia_context mbedtls_camellia_context -#define camellia_crypt_cbc mbedtls_camellia_crypt_cbc -#define camellia_crypt_cfb128 mbedtls_camellia_crypt_cfb128 -#define camellia_crypt_ctr mbedtls_camellia_crypt_ctr -#define camellia_crypt_ecb mbedtls_camellia_crypt_ecb -#define camellia_free mbedtls_camellia_free -#define camellia_init mbedtls_camellia_init -#define camellia_self_test mbedtls_camellia_self_test -#define camellia_setkey_dec mbedtls_camellia_setkey_dec -#define camellia_setkey_enc mbedtls_camellia_setkey_enc -#define ccm_auth_decrypt mbedtls_ccm_auth_decrypt -#define ccm_context mbedtls_ccm_context -#define ccm_encrypt_and_tag mbedtls_ccm_encrypt_and_tag -#define ccm_free mbedtls_ccm_free -#define ccm_init mbedtls_ccm_init -#define ccm_self_test mbedtls_ccm_self_test -#define cipher_auth_decrypt mbedtls_cipher_auth_decrypt -#define cipher_auth_encrypt mbedtls_cipher_auth_encrypt -#define cipher_base_t mbedtls_cipher_base_t -#define cipher_check_tag mbedtls_cipher_check_tag -#define cipher_context_t mbedtls_cipher_context_t -#define cipher_crypt mbedtls_cipher_crypt -#define cipher_definition_t mbedtls_cipher_definition_t -#define cipher_definitions mbedtls_cipher_definitions -#define cipher_finish mbedtls_cipher_finish -#define cipher_free mbedtls_cipher_free -#define cipher_get_block_size mbedtls_cipher_get_block_size -#define cipher_get_cipher_mode mbedtls_cipher_get_cipher_mode -#define cipher_get_iv_size mbedtls_cipher_get_iv_size -#define cipher_get_key_size mbedtls_cipher_get_key_bitlen -#define cipher_get_name mbedtls_cipher_get_name -#define cipher_get_operation mbedtls_cipher_get_operation -#define cipher_get_type mbedtls_cipher_get_type -#define cipher_id_t mbedtls_cipher_id_t -#define cipher_info_from_string mbedtls_cipher_info_from_string -#define cipher_info_from_type mbedtls_cipher_info_from_type -#define cipher_info_from_values mbedtls_cipher_info_from_values -#define cipher_info_t mbedtls_cipher_info_t -#define cipher_init mbedtls_cipher_init -#define cipher_init_ctx mbedtls_cipher_setup -#define cipher_list mbedtls_cipher_list -#define cipher_mode_t mbedtls_cipher_mode_t -#define cipher_padding_t mbedtls_cipher_padding_t -#define cipher_reset mbedtls_cipher_reset -#define cipher_set_iv mbedtls_cipher_set_iv -#define cipher_set_padding_mode mbedtls_cipher_set_padding_mode -#define cipher_setkey mbedtls_cipher_setkey -#define cipher_type_t mbedtls_cipher_type_t -#define cipher_update mbedtls_cipher_update -#define cipher_update_ad mbedtls_cipher_update_ad -#define cipher_write_tag mbedtls_cipher_write_tag -#define ctr_drbg_context mbedtls_ctr_drbg_context -#define ctr_drbg_free mbedtls_ctr_drbg_free -#define ctr_drbg_init mbedtls_ctr_drbg_init -#define ctr_drbg_random mbedtls_ctr_drbg_random -#define ctr_drbg_random_with_add mbedtls_ctr_drbg_random_with_add -#define ctr_drbg_reseed mbedtls_ctr_drbg_reseed -#define ctr_drbg_self_test mbedtls_ctr_drbg_self_test -#define ctr_drbg_set_entropy_len mbedtls_ctr_drbg_set_entropy_len -#define ctr_drbg_set_prediction_resistance mbedtls_ctr_drbg_set_prediction_resistance -#define ctr_drbg_set_reseed_interval mbedtls_ctr_drbg_set_reseed_interval -#define ctr_drbg_update mbedtls_ctr_drbg_update -#define ctr_drbg_update_seed_file mbedtls_ctr_drbg_update_seed_file -#define ctr_drbg_write_seed_file mbedtls_ctr_drbg_write_seed_file -#define debug_print_buf mbedtls_debug_print_buf -#define debug_print_crt mbedtls_debug_print_crt -#define debug_print_ecp mbedtls_debug_print_ecp -#define debug_print_mpi mbedtls_debug_print_mpi -#define debug_print_msg mbedtls_debug_print_msg -#define debug_print_ret mbedtls_debug_print_ret -#define debug_set_threshold mbedtls_debug_set_threshold -#define des3_context mbedtls_des3_context -#define des3_crypt_cbc mbedtls_des3_crypt_cbc -#define des3_crypt_ecb mbedtls_des3_crypt_ecb -#define des3_free mbedtls_des3_free -#define des3_init mbedtls_des3_init -#define des3_set2key_dec mbedtls_des3_set2key_dec -#define des3_set2key_enc mbedtls_des3_set2key_enc -#define des3_set3key_dec mbedtls_des3_set3key_dec -#define des3_set3key_enc mbedtls_des3_set3key_enc -#define des_context mbedtls_des_context -#define des_crypt_cbc mbedtls_des_crypt_cbc -#define des_crypt_ecb mbedtls_des_crypt_ecb -#define des_free mbedtls_des_free -#define des_init mbedtls_des_init -#define des_key_check_key_parity mbedtls_des_key_check_key_parity -#define des_key_check_weak mbedtls_des_key_check_weak -#define des_key_set_parity mbedtls_des_key_set_parity -#define des_self_test mbedtls_des_self_test -#define des_setkey_dec mbedtls_des_setkey_dec -#define des_setkey_enc mbedtls_des_setkey_enc -#define dhm_calc_secret mbedtls_dhm_calc_secret -#define dhm_context mbedtls_dhm_context -#define dhm_free mbedtls_dhm_free -#define dhm_init mbedtls_dhm_init -#define dhm_make_params mbedtls_dhm_make_params -#define dhm_make_public mbedtls_dhm_make_public -#define dhm_parse_dhm mbedtls_dhm_parse_dhm -#define dhm_parse_dhmfile mbedtls_dhm_parse_dhmfile -#define dhm_read_params mbedtls_dhm_read_params -#define dhm_read_public mbedtls_dhm_read_public -#define dhm_self_test mbedtls_dhm_self_test -#define ecdh_calc_secret mbedtls_ecdh_calc_secret -#define ecdh_compute_shared mbedtls_ecdh_compute_shared -#define ecdh_context mbedtls_ecdh_context -#define ecdh_free mbedtls_ecdh_free -#define ecdh_gen_public mbedtls_ecdh_gen_public -#define ecdh_get_params mbedtls_ecdh_get_params -#define ecdh_init mbedtls_ecdh_init -#define ecdh_make_params mbedtls_ecdh_make_params -#define ecdh_make_public mbedtls_ecdh_make_public -#define ecdh_read_params mbedtls_ecdh_read_params -#define ecdh_read_public mbedtls_ecdh_read_public -#define ecdh_side mbedtls_ecdh_side -#define ecdsa_context mbedtls_ecdsa_context -#define ecdsa_free mbedtls_ecdsa_free -#define ecdsa_from_keypair mbedtls_ecdsa_from_keypair -#define ecdsa_genkey mbedtls_ecdsa_genkey -#define ecdsa_info mbedtls_ecdsa_info -#define ecdsa_init mbedtls_ecdsa_init -#define ecdsa_read_signature mbedtls_ecdsa_read_signature -#define ecdsa_sign mbedtls_ecdsa_sign -#define ecdsa_sign_det mbedtls_ecdsa_sign_det -#define ecdsa_verify mbedtls_ecdsa_verify -#define ecdsa_write_signature mbedtls_ecdsa_write_signature -#define ecdsa_write_signature_det mbedtls_ecdsa_write_signature_det -#define eckey_info mbedtls_eckey_info -#define eckeydh_info mbedtls_eckeydh_info -#define ecp_check_privkey mbedtls_ecp_check_privkey -#define ecp_check_pub_priv mbedtls_ecp_check_pub_priv -#define ecp_check_pubkey mbedtls_ecp_check_pubkey -#define ecp_copy mbedtls_ecp_copy -#define ecp_curve_info mbedtls_ecp_curve_info -#define ecp_curve_info_from_grp_id mbedtls_ecp_curve_info_from_grp_id -#define ecp_curve_info_from_name mbedtls_ecp_curve_info_from_name -#define ecp_curve_info_from_tls_id mbedtls_ecp_curve_info_from_tls_id -#define ecp_curve_list mbedtls_ecp_curve_list -#define ecp_gen_key mbedtls_ecp_gen_key -#define ecp_gen_keypair mbedtls_ecp_gen_keypair -#define ecp_group mbedtls_ecp_group -#define ecp_group_copy mbedtls_ecp_group_copy -#define ecp_group_free mbedtls_ecp_group_free -#define ecp_group_id mbedtls_ecp_group_id -#define ecp_group_init mbedtls_ecp_group_init -#define ecp_grp_id_list mbedtls_ecp_grp_id_list -#define ecp_is_zero mbedtls_ecp_is_zero -#define ecp_keypair mbedtls_ecp_keypair -#define ecp_keypair_free mbedtls_ecp_keypair_free -#define ecp_keypair_init mbedtls_ecp_keypair_init -#define ecp_mul mbedtls_ecp_mul -#define ecp_point mbedtls_ecp_point -#define ecp_point_free mbedtls_ecp_point_free -#define ecp_point_init mbedtls_ecp_point_init -#define ecp_point_read_binary mbedtls_ecp_point_read_binary -#define ecp_point_read_string mbedtls_ecp_point_read_string -#define ecp_point_write_binary mbedtls_ecp_point_write_binary -#define ecp_self_test mbedtls_ecp_self_test -#define ecp_set_zero mbedtls_ecp_set_zero -#define ecp_tls_read_group mbedtls_ecp_tls_read_group -#define ecp_tls_read_point mbedtls_ecp_tls_read_point -#define ecp_tls_write_group mbedtls_ecp_tls_write_group -#define ecp_tls_write_point mbedtls_ecp_tls_write_point -#define ecp_use_known_dp mbedtls_ecp_group_load -#define entropy_add_source mbedtls_entropy_add_source -#define entropy_context mbedtls_entropy_context -#define entropy_free mbedtls_entropy_free -#define entropy_func mbedtls_entropy_func -#define entropy_gather mbedtls_entropy_gather -#define entropy_init mbedtls_entropy_init -#define entropy_self_test mbedtls_entropy_self_test -#define entropy_update_manual mbedtls_entropy_update_manual -#define entropy_update_seed_file mbedtls_entropy_update_seed_file -#define entropy_write_seed_file mbedtls_entropy_write_seed_file -#define error_strerror mbedtls_strerror -#define f_source_ptr mbedtls_entropy_f_source_ptr -#define gcm_auth_decrypt mbedtls_gcm_auth_decrypt -#define gcm_context mbedtls_gcm_context -#define gcm_crypt_and_tag mbedtls_gcm_crypt_and_tag -#define gcm_finish mbedtls_gcm_finish -#define gcm_free mbedtls_gcm_free -#define gcm_init mbedtls_gcm_init -#define gcm_self_test mbedtls_gcm_self_test -#define gcm_starts mbedtls_gcm_starts -#define gcm_update mbedtls_gcm_update -#define get_timer mbedtls_timing_get_timer -#define hardclock mbedtls_timing_hardclock -#define hardclock_poll mbedtls_hardclock_poll -#define havege_free mbedtls_havege_free -#define havege_init mbedtls_havege_init -#define havege_poll mbedtls_havege_poll -#define havege_random mbedtls_havege_random -#define havege_state mbedtls_havege_state -#define hmac_drbg_context mbedtls_hmac_drbg_context -#define hmac_drbg_free mbedtls_hmac_drbg_free -#define hmac_drbg_init mbedtls_hmac_drbg_init -#define hmac_drbg_random mbedtls_hmac_drbg_random -#define hmac_drbg_random_with_add mbedtls_hmac_drbg_random_with_add -#define hmac_drbg_reseed mbedtls_hmac_drbg_reseed -#define hmac_drbg_self_test mbedtls_hmac_drbg_self_test -#define hmac_drbg_set_entropy_len mbedtls_hmac_drbg_set_entropy_len -#define hmac_drbg_set_prediction_resistance mbedtls_hmac_drbg_set_prediction_resistance -#define hmac_drbg_set_reseed_interval mbedtls_hmac_drbg_set_reseed_interval -#define hmac_drbg_update mbedtls_hmac_drbg_update -#define hmac_drbg_update_seed_file mbedtls_hmac_drbg_update_seed_file -#define hmac_drbg_write_seed_file mbedtls_hmac_drbg_write_seed_file -#define hr_time mbedtls_timing_hr_time -#define key_exchange_type_t mbedtls_key_exchange_type_t -#define md mbedtls_md -#define md2 mbedtls_md2 -#define md2_context mbedtls_md2_context -#define md2_finish mbedtls_md2_finish -#define md2_free mbedtls_md2_free -#define md2_info mbedtls_md2_info -#define md2_init mbedtls_md2_init -#define md2_process mbedtls_md2_process -#define md2_self_test mbedtls_md2_self_test -#define md2_starts mbedtls_md2_starts -#define md2_update mbedtls_md2_update -#define md4 mbedtls_md4 -#define md4_context mbedtls_md4_context -#define md4_finish mbedtls_md4_finish -#define md4_free mbedtls_md4_free -#define md4_info mbedtls_md4_info -#define md4_init mbedtls_md4_init -#define md4_process mbedtls_md4_process -#define md4_self_test mbedtls_md4_self_test -#define md4_starts mbedtls_md4_starts -#define md4_update mbedtls_md4_update -#define md5 mbedtls_md5 -#define md5_context mbedtls_md5_context -#define md5_finish mbedtls_md5_finish -#define md5_free mbedtls_md5_free -#define md5_info mbedtls_md5_info -#define md5_init mbedtls_md5_init -#define md5_process mbedtls_md5_process -#define md5_self_test mbedtls_md5_self_test -#define md5_starts mbedtls_md5_starts -#define md5_update mbedtls_md5_update -#define md_context_t mbedtls_md_context_t -#define md_file mbedtls_md_file -#define md_finish mbedtls_md_finish -#define md_free mbedtls_md_free -#define md_get_name mbedtls_md_get_name -#define md_get_size mbedtls_md_get_size -#define md_get_type mbedtls_md_get_type -#define md_hmac mbedtls_md_hmac -#define md_hmac_finish mbedtls_md_hmac_finish -#define md_hmac_reset mbedtls_md_hmac_reset -#define md_hmac_starts mbedtls_md_hmac_starts -#define md_hmac_update mbedtls_md_hmac_update -#define md_info_from_string mbedtls_md_info_from_string -#define md_info_from_type mbedtls_md_info_from_type -#define md_info_t mbedtls_md_info_t -#define md_init mbedtls_md_init -#define md_init_ctx mbedtls_md_init_ctx -#define md_list mbedtls_md_list -#define md_process mbedtls_md_process -#define md_starts mbedtls_md_starts -#define md_type_t mbedtls_md_type_t -#define md_update mbedtls_md_update -#define memory_buffer_alloc_cur_get mbedtls_memory_buffer_alloc_cur_get -#define memory_buffer_alloc_free mbedtls_memory_buffer_alloc_free -#define memory_buffer_alloc_init mbedtls_memory_buffer_alloc_init -#define memory_buffer_alloc_max_get mbedtls_memory_buffer_alloc_max_get -#define memory_buffer_alloc_max_reset mbedtls_memory_buffer_alloc_max_reset -#define memory_buffer_alloc_self_test mbedtls_memory_buffer_alloc_self_test -#define memory_buffer_alloc_status mbedtls_memory_buffer_alloc_status -#define memory_buffer_alloc_verify mbedtls_memory_buffer_alloc_verify -#define memory_buffer_set_verify mbedtls_memory_buffer_set_verify -#define mpi mbedtls_mpi -#define mpi_add_abs mbedtls_mpi_add_abs -#define mpi_add_int mbedtls_mpi_add_int -#define mpi_add_mpi mbedtls_mpi_add_mpi -#define mpi_cmp_abs mbedtls_mpi_cmp_abs -#define mpi_cmp_int mbedtls_mpi_cmp_int -#define mpi_cmp_mpi mbedtls_mpi_cmp_mpi -#define mpi_copy mbedtls_mpi_copy -#define mpi_div_int mbedtls_mpi_div_int -#define mpi_div_mpi mbedtls_mpi_div_mpi -#define mpi_exp_mod mbedtls_mpi_exp_mod -#define mpi_fill_random mbedtls_mpi_fill_random -#define mpi_free mbedtls_mpi_free -#define mpi_gcd mbedtls_mpi_gcd -#define mpi_gen_prime mbedtls_mpi_gen_prime -#define mpi_get_bit mbedtls_mpi_get_bit -#define mpi_grow mbedtls_mpi_grow -#define mpi_init mbedtls_mpi_init -#define mpi_inv_mod mbedtls_mpi_inv_mod -#define mpi_is_prime mbedtls_mpi_is_prime -#define mpi_lsb mbedtls_mpi_lsb -#define mpi_lset mbedtls_mpi_lset -#define mpi_mod_int mbedtls_mpi_mod_int -#define mpi_mod_mpi mbedtls_mpi_mod_mpi -#define mpi_msb mbedtls_mpi_bitlen -#define mpi_mul_int mbedtls_mpi_mul_int -#define mpi_mul_mpi mbedtls_mpi_mul_mpi -#define mpi_read_binary mbedtls_mpi_read_binary -#define mpi_read_file mbedtls_mpi_read_file -#define mpi_read_string mbedtls_mpi_read_string -#define mpi_safe_cond_assign mbedtls_mpi_safe_cond_assign -#define mpi_safe_cond_swap mbedtls_mpi_safe_cond_swap -#define mpi_self_test mbedtls_mpi_self_test -#define mpi_set_bit mbedtls_mpi_set_bit -#define mpi_shift_l mbedtls_mpi_shift_l -#define mpi_shift_r mbedtls_mpi_shift_r -#define mpi_shrink mbedtls_mpi_shrink -#define mpi_size mbedtls_mpi_size -#define mpi_sub_abs mbedtls_mpi_sub_abs -#define mpi_sub_int mbedtls_mpi_sub_int -#define mpi_sub_mpi mbedtls_mpi_sub_mpi -#define mpi_swap mbedtls_mpi_swap -#define mpi_write_binary mbedtls_mpi_write_binary -#define mpi_write_file mbedtls_mpi_write_file -#define mpi_write_string mbedtls_mpi_write_string -#define net_accept mbedtls_net_accept -#define net_bind mbedtls_net_bind -#define net_close mbedtls_net_free -#define net_connect mbedtls_net_connect -#define net_recv mbedtls_net_recv -#define net_recv_timeout mbedtls_net_recv_timeout -#define net_send mbedtls_net_send -#define net_set_block mbedtls_net_set_block -#define net_set_nonblock mbedtls_net_set_nonblock -#define net_usleep mbedtls_net_usleep -#define oid_descriptor_t mbedtls_oid_descriptor_t -#define oid_get_attr_short_name mbedtls_oid_get_attr_short_name -#define oid_get_cipher_alg mbedtls_oid_get_cipher_alg -#define oid_get_ec_grp mbedtls_oid_get_ec_grp -#define oid_get_extended_key_usage mbedtls_oid_get_extended_key_usage -#define oid_get_md_alg mbedtls_oid_get_md_alg -#define oid_get_numeric_string mbedtls_oid_get_numeric_string -#define oid_get_oid_by_ec_grp mbedtls_oid_get_oid_by_ec_grp -#define oid_get_oid_by_md mbedtls_oid_get_oid_by_md -#define oid_get_oid_by_pk_alg mbedtls_oid_get_oid_by_pk_alg -#define oid_get_oid_by_sig_alg mbedtls_oid_get_oid_by_sig_alg -#define oid_get_pk_alg mbedtls_oid_get_pk_alg -#define oid_get_pkcs12_pbe_alg mbedtls_oid_get_pkcs12_pbe_alg -#define oid_get_sig_alg mbedtls_oid_get_sig_alg -#define oid_get_sig_alg_desc mbedtls_oid_get_sig_alg_desc -#define oid_get_x509_ext_type mbedtls_oid_get_x509_ext_type -#define operation_t mbedtls_operation_t -#define padlock_supports mbedtls_padlock_has_support -#define padlock_xcryptcbc mbedtls_padlock_xcryptcbc -#define padlock_xcryptecb mbedtls_padlock_xcryptecb -#define pem_context mbedtls_pem_context -#define pem_free mbedtls_pem_free -#define pem_init mbedtls_pem_init -#define pem_read_buffer mbedtls_pem_read_buffer -#define pem_write_buffer mbedtls_pem_write_buffer -#define pk_can_do mbedtls_pk_can_do -#define pk_check_pair mbedtls_pk_check_pair -#define pk_context mbedtls_pk_context -#define pk_debug mbedtls_pk_debug -#define pk_debug_item mbedtls_pk_debug_item -#define pk_debug_type mbedtls_pk_debug_type -#define pk_decrypt mbedtls_pk_decrypt -#define pk_ec mbedtls_pk_ec -#define pk_encrypt mbedtls_pk_encrypt -#define pk_free mbedtls_pk_free -#define pk_get_len mbedtls_pk_get_len -#define pk_get_name mbedtls_pk_get_name -#define pk_get_size mbedtls_pk_get_bitlen -#define pk_get_type mbedtls_pk_get_type -#define pk_info_from_type mbedtls_pk_info_from_type -#define pk_info_t mbedtls_pk_info_t -#define pk_init mbedtls_pk_init -#define pk_init_ctx mbedtls_pk_setup -#define pk_init_ctx_rsa_alt mbedtls_pk_setup_rsa_alt -#define pk_load_file mbedtls_pk_load_file -#define pk_parse_key mbedtls_pk_parse_key -#define pk_parse_keyfile mbedtls_pk_parse_keyfile -#define pk_parse_public_key mbedtls_pk_parse_public_key -#define pk_parse_public_keyfile mbedtls_pk_parse_public_keyfile -#define pk_parse_subpubkey mbedtls_pk_parse_subpubkey -#define pk_rsa mbedtls_pk_rsa -#define pk_rsa_alt_decrypt_func mbedtls_pk_rsa_alt_decrypt_func -#define pk_rsa_alt_key_len_func mbedtls_pk_rsa_alt_key_len_func -#define pk_rsa_alt_sign_func mbedtls_pk_rsa_alt_sign_func -#define pk_rsassa_pss_options mbedtls_pk_rsassa_pss_options -#define pk_sign mbedtls_pk_sign -#define pk_type_t mbedtls_pk_type_t -#define pk_verify mbedtls_pk_verify -#define pk_verify_ext mbedtls_pk_verify_ext -#define pk_write_key_der mbedtls_pk_write_key_der -#define pk_write_key_pem mbedtls_pk_write_key_pem -#define pk_write_pubkey mbedtls_pk_write_pubkey -#define pk_write_pubkey_der mbedtls_pk_write_pubkey_der -#define pk_write_pubkey_pem mbedtls_pk_write_pubkey_pem -#define pkcs11_context mbedtls_pkcs11_context -#define pkcs11_decrypt mbedtls_pkcs11_decrypt -#define pkcs11_priv_key_free mbedtls_pkcs11_priv_key_free -#define pkcs11_priv_key_init mbedtls_pkcs11_priv_key_bind -#define pkcs11_sign mbedtls_pkcs11_sign -#define pkcs11_x509_cert_init mbedtls_pkcs11_x509_cert_bind -#define pkcs12_derivation mbedtls_pkcs12_derivation -#define pkcs12_pbe mbedtls_pkcs12_pbe -#define pkcs12_pbe_sha1_rc4_128 mbedtls_pkcs12_pbe_sha1_rc4_128 -#define pkcs5_pbes2 mbedtls_pkcs5_pbes2 -#define pkcs5_pbkdf2_hmac mbedtls_pkcs5_pbkdf2_hmac -#define pkcs5_self_test mbedtls_pkcs5_self_test -#define platform_entropy_poll mbedtls_platform_entropy_poll -#define platform_set_exit mbedtls_platform_set_exit -#define platform_set_fprintf mbedtls_platform_set_fprintf -#define platform_set_printf mbedtls_platform_set_printf -#define platform_set_snprintf mbedtls_platform_set_snprintf -#define polarssl_exit mbedtls_exit -#define polarssl_fprintf mbedtls_fprintf -#define polarssl_free mbedtls_free -#define polarssl_mutex_free mbedtls_mutex_free -#define polarssl_mutex_init mbedtls_mutex_init -#define polarssl_mutex_lock mbedtls_mutex_lock -#define polarssl_mutex_unlock mbedtls_mutex_unlock -#define polarssl_printf mbedtls_printf -#define polarssl_snprintf mbedtls_snprintf -#define polarssl_strerror mbedtls_strerror -#define ripemd160 mbedtls_ripemd160 -#define ripemd160_context mbedtls_ripemd160_context -#define ripemd160_finish mbedtls_ripemd160_finish -#define ripemd160_free mbedtls_ripemd160_free -#define ripemd160_info mbedtls_ripemd160_info -#define ripemd160_init mbedtls_ripemd160_init -#define ripemd160_process mbedtls_ripemd160_process -#define ripemd160_self_test mbedtls_ripemd160_self_test -#define ripemd160_starts mbedtls_ripemd160_starts -#define ripemd160_update mbedtls_ripemd160_update -#define rsa_alt_context mbedtls_rsa_alt_context -#define rsa_alt_info mbedtls_rsa_alt_info -#define rsa_check_privkey mbedtls_rsa_check_privkey -#define rsa_check_pub_priv mbedtls_rsa_check_pub_priv -#define rsa_check_pubkey mbedtls_rsa_check_pubkey -#define rsa_context mbedtls_rsa_context -#define rsa_copy mbedtls_rsa_copy -#define rsa_free mbedtls_rsa_free -#define rsa_gen_key mbedtls_rsa_gen_key -#define rsa_info mbedtls_rsa_info -#define rsa_init mbedtls_rsa_init -#define rsa_pkcs1_decrypt mbedtls_rsa_pkcs1_decrypt -#define rsa_pkcs1_encrypt mbedtls_rsa_pkcs1_encrypt -#define rsa_pkcs1_sign mbedtls_rsa_pkcs1_sign -#define rsa_pkcs1_verify mbedtls_rsa_pkcs1_verify -#define rsa_private mbedtls_rsa_private -#define rsa_public mbedtls_rsa_public -#define rsa_rsaes_oaep_decrypt mbedtls_rsa_rsaes_oaep_decrypt -#define rsa_rsaes_oaep_encrypt mbedtls_rsa_rsaes_oaep_encrypt -#define rsa_rsaes_pkcs1_v15_decrypt mbedtls_rsa_rsaes_pkcs1_v15_decrypt -#define rsa_rsaes_pkcs1_v15_encrypt mbedtls_rsa_rsaes_pkcs1_v15_encrypt -#define rsa_rsassa_pkcs1_v15_sign mbedtls_rsa_rsassa_pkcs1_v15_sign -#define rsa_rsassa_pkcs1_v15_verify mbedtls_rsa_rsassa_pkcs1_v15_verify -#define rsa_rsassa_pss_sign mbedtls_rsa_rsassa_pss_sign -#define rsa_rsassa_pss_verify mbedtls_rsa_rsassa_pss_verify -#define rsa_rsassa_pss_verify_ext mbedtls_rsa_rsassa_pss_verify_ext -#define rsa_self_test mbedtls_rsa_self_test -#define rsa_set_padding mbedtls_rsa_set_padding -#define safer_memcmp mbedtls_ssl_safer_memcmp -#define set_alarm mbedtls_set_alarm -#define sha1 mbedtls_sha1 -#define sha1_context mbedtls_sha1_context -#define sha1_finish mbedtls_sha1_finish -#define sha1_free mbedtls_sha1_free -#define sha1_info mbedtls_sha1_info -#define sha1_init mbedtls_sha1_init -#define sha1_process mbedtls_sha1_process -#define sha1_self_test mbedtls_sha1_self_test -#define sha1_starts mbedtls_sha1_starts -#define sha1_update mbedtls_sha1_update -#define sha224_info mbedtls_sha224_info -#define sha256 mbedtls_sha256 -#define sha256_context mbedtls_sha256_context -#define sha256_finish mbedtls_sha256_finish -#define sha256_free mbedtls_sha256_free -#define sha256_info mbedtls_sha256_info -#define sha256_init mbedtls_sha256_init -#define sha256_process mbedtls_sha256_process -#define sha256_self_test mbedtls_sha256_self_test -#define sha256_starts mbedtls_sha256_starts -#define sha256_update mbedtls_sha256_update -#define sha384_info mbedtls_sha384_info -#define sha512 mbedtls_sha512 -#define sha512_context mbedtls_sha512_context -#define sha512_finish mbedtls_sha512_finish -#define sha512_free mbedtls_sha512_free -#define sha512_info mbedtls_sha512_info -#define sha512_init mbedtls_sha512_init -#define sha512_process mbedtls_sha512_process -#define sha512_self_test mbedtls_sha512_self_test -#define sha512_starts mbedtls_sha512_starts -#define sha512_update mbedtls_sha512_update -#define source_state mbedtls_entropy_source_state -#define ssl_cache_context mbedtls_ssl_cache_context -#define ssl_cache_entry mbedtls_ssl_cache_entry -#define ssl_cache_free mbedtls_ssl_cache_free -#define ssl_cache_get mbedtls_ssl_cache_get -#define ssl_cache_init mbedtls_ssl_cache_init -#define ssl_cache_set mbedtls_ssl_cache_set -#define ssl_cache_set_max_entries mbedtls_ssl_cache_set_max_entries -#define ssl_cache_set_timeout mbedtls_ssl_cache_set_timeout -#define ssl_check_cert_usage mbedtls_ssl_check_cert_usage -#define ssl_ciphersuite_from_id mbedtls_ssl_ciphersuite_from_id -#define ssl_ciphersuite_from_string mbedtls_ssl_ciphersuite_from_string -#define ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t -#define ssl_ciphersuite_uses_ec mbedtls_ssl_ciphersuite_uses_ec -#define ssl_ciphersuite_uses_psk mbedtls_ssl_ciphersuite_uses_psk -#define ssl_close_notify mbedtls_ssl_close_notify -#define ssl_context mbedtls_ssl_context -#define ssl_cookie_check mbedtls_ssl_cookie_check -#define ssl_cookie_check_t mbedtls_ssl_cookie_check_t -#define ssl_cookie_ctx mbedtls_ssl_cookie_ctx -#define ssl_cookie_free mbedtls_ssl_cookie_free -#define ssl_cookie_init mbedtls_ssl_cookie_init -#define ssl_cookie_set_timeout mbedtls_ssl_cookie_set_timeout -#define ssl_cookie_setup mbedtls_ssl_cookie_setup -#define ssl_cookie_write mbedtls_ssl_cookie_write -#define ssl_cookie_write_t mbedtls_ssl_cookie_write_t -#define ssl_derive_keys mbedtls_ssl_derive_keys -#define ssl_dtls_replay_check mbedtls_ssl_dtls_replay_check -#define ssl_dtls_replay_update mbedtls_ssl_dtls_replay_update -#define ssl_fetch_input mbedtls_ssl_fetch_input -#define ssl_flight_item mbedtls_ssl_flight_item -#define ssl_flush_output mbedtls_ssl_flush_output -#define ssl_free mbedtls_ssl_free -#define ssl_get_alpn_protocol mbedtls_ssl_get_alpn_protocol -#define ssl_get_bytes_avail mbedtls_ssl_get_bytes_avail -#define ssl_get_ciphersuite mbedtls_ssl_get_ciphersuite -#define ssl_get_ciphersuite_id mbedtls_ssl_get_ciphersuite_id -#define ssl_get_ciphersuite_name mbedtls_ssl_get_ciphersuite_name -#define ssl_get_ciphersuite_sig_pk_alg mbedtls_ssl_get_ciphersuite_sig_pk_alg -#define ssl_get_peer_cert mbedtls_ssl_get_peer_cert -#define ssl_get_record_expansion mbedtls_ssl_get_record_expansion -#define ssl_get_session mbedtls_ssl_get_session -#define ssl_get_verify_result mbedtls_ssl_get_verify_result -#define ssl_get_version mbedtls_ssl_get_version -#define ssl_handshake mbedtls_ssl_handshake -#define ssl_handshake_client_step mbedtls_ssl_handshake_client_step -#define ssl_handshake_free mbedtls_ssl_handshake_free -#define ssl_handshake_params mbedtls_ssl_handshake_params -#define ssl_handshake_server_step mbedtls_ssl_handshake_server_step -#define ssl_handshake_step mbedtls_ssl_handshake_step -#define ssl_handshake_wrapup mbedtls_ssl_handshake_wrapup -#define ssl_hdr_len mbedtls_ssl_hdr_len -#define ssl_hs_hdr_len mbedtls_ssl_hs_hdr_len -#define ssl_hw_record_activate mbedtls_ssl_hw_record_activate -#define ssl_hw_record_finish mbedtls_ssl_hw_record_finish -#define ssl_hw_record_init mbedtls_ssl_hw_record_init -#define ssl_hw_record_read mbedtls_ssl_hw_record_read -#define ssl_hw_record_reset mbedtls_ssl_hw_record_reset -#define ssl_hw_record_write mbedtls_ssl_hw_record_write -#define ssl_init mbedtls_ssl_init -#define ssl_key_cert mbedtls_ssl_key_cert -#define ssl_legacy_renegotiation mbedtls_ssl_conf_legacy_renegotiation -#define ssl_list_ciphersuites mbedtls_ssl_list_ciphersuites -#define ssl_md_alg_from_hash mbedtls_ssl_md_alg_from_hash -#define ssl_optimize_checksum mbedtls_ssl_optimize_checksum -#define ssl_own_cert mbedtls_ssl_own_cert -#define ssl_own_key mbedtls_ssl_own_key -#define ssl_parse_certificate mbedtls_ssl_parse_certificate -#define ssl_parse_change_cipher_spec mbedtls_ssl_parse_change_cipher_spec -#define ssl_parse_finished mbedtls_ssl_parse_finished -#define ssl_pk_alg_from_sig mbedtls_ssl_pk_alg_from_sig -#define ssl_pkcs11_decrypt mbedtls_ssl_pkcs11_decrypt -#define ssl_pkcs11_key_len mbedtls_ssl_pkcs11_key_len -#define ssl_pkcs11_sign mbedtls_ssl_pkcs11_sign -#define ssl_psk_derive_premaster mbedtls_ssl_psk_derive_premaster -#define ssl_read mbedtls_ssl_read -#define ssl_read_record mbedtls_ssl_read_record -#define ssl_read_version mbedtls_ssl_read_version -#define ssl_recv_flight_completed mbedtls_ssl_recv_flight_completed -#define ssl_renegotiate mbedtls_ssl_renegotiate -#define ssl_resend mbedtls_ssl_resend -#define ssl_reset_checksum mbedtls_ssl_reset_checksum -#define ssl_send_alert_message mbedtls_ssl_send_alert_message -#define ssl_send_fatal_handshake_failure mbedtls_ssl_send_fatal_handshake_failure -#define ssl_send_flight_completed mbedtls_ssl_send_flight_completed -#define ssl_session mbedtls_ssl_session -#define ssl_session_free mbedtls_ssl_session_free -#define ssl_session_init mbedtls_ssl_session_init -#define ssl_session_reset mbedtls_ssl_session_reset -#define ssl_set_alpn_protocols mbedtls_ssl_conf_alpn_protocols -#define ssl_set_arc4_support mbedtls_ssl_conf_arc4_support -#define ssl_set_authmode mbedtls_ssl_conf_authmode -#define ssl_set_bio mbedtls_ssl_set_bio -#define ssl_set_ca_chain mbedtls_ssl_conf_ca_chain -#define ssl_set_cbc_record_splitting mbedtls_ssl_conf_cbc_record_splitting -#define ssl_set_ciphersuites mbedtls_ssl_conf_ciphersuites -#define ssl_set_ciphersuites_for_version mbedtls_ssl_conf_ciphersuites_for_version -#define ssl_set_client_transport_id mbedtls_ssl_set_client_transport_id -#define ssl_set_curves mbedtls_ssl_conf_curves -#define ssl_set_dbg mbedtls_ssl_conf_dbg -#define ssl_set_dh_param mbedtls_ssl_conf_dh_param -#define ssl_set_dh_param_ctx mbedtls_ssl_conf_dh_param_ctx -#define ssl_set_dtls_anti_replay mbedtls_ssl_conf_dtls_anti_replay -#define ssl_set_dtls_badmac_limit mbedtls_ssl_conf_dtls_badmac_limit -#define ssl_set_dtls_cookies mbedtls_ssl_conf_dtls_cookies -#define ssl_set_encrypt_then_mac mbedtls_ssl_conf_encrypt_then_mac -#define ssl_set_endpoint mbedtls_ssl_conf_endpoint -#define ssl_set_extended_master_secret mbedtls_ssl_conf_extended_master_secret -#define ssl_set_fallback mbedtls_ssl_conf_fallback -#define ssl_set_handshake_timeout mbedtls_ssl_conf_handshake_timeout -#define ssl_set_hostname mbedtls_ssl_set_hostname -#define ssl_set_max_frag_len mbedtls_ssl_conf_max_frag_len -#define ssl_set_max_version mbedtls_ssl_conf_max_version -#define ssl_set_min_version mbedtls_ssl_conf_min_version -#define ssl_set_own_cert mbedtls_ssl_conf_own_cert -#define ssl_set_psk mbedtls_ssl_conf_psk -#define ssl_set_psk_cb mbedtls_ssl_conf_psk_cb -#define ssl_set_renegotiation mbedtls_ssl_conf_renegotiation -#define ssl_set_renegotiation_enforced mbedtls_ssl_conf_renegotiation_enforced -#define ssl_set_renegotiation_period mbedtls_ssl_conf_renegotiation_period -#define ssl_set_rng mbedtls_ssl_conf_rng -#define ssl_set_session mbedtls_ssl_set_session -#define ssl_set_session_cache mbedtls_ssl_conf_session_cache -#define ssl_set_session_tickets mbedtls_ssl_conf_session_tickets -#define ssl_set_sni mbedtls_ssl_conf_sni -#define ssl_set_transport mbedtls_ssl_conf_transport -#define ssl_set_truncated_hmac mbedtls_ssl_conf_truncated_hmac -#define ssl_set_verify mbedtls_ssl_conf_verify -#define ssl_sig_from_pk mbedtls_ssl_sig_from_pk -#define ssl_states mbedtls_ssl_states -#define ssl_transform mbedtls_ssl_transform -#define ssl_transform_free mbedtls_ssl_transform_free -#define ssl_write mbedtls_ssl_write -#define ssl_write_certificate mbedtls_ssl_write_certificate -#define ssl_write_change_cipher_spec mbedtls_ssl_write_change_cipher_spec -#define ssl_write_finished mbedtls_ssl_write_finished -#define ssl_write_record mbedtls_ssl_write_record -#define ssl_write_version mbedtls_ssl_write_version -#define supported_ciphers mbedtls_cipher_supported -#define t_sint mbedtls_mpi_sint -#define t_udbl mbedtls_t_udbl -#define t_uint mbedtls_mpi_uint -#define test_ca_crt mbedtls_test_ca_crt -#define test_ca_crt_ec mbedtls_test_ca_crt_ec -#define test_ca_crt_rsa mbedtls_test_ca_crt_rsa -#define test_ca_key mbedtls_test_ca_key -#define test_ca_key_ec mbedtls_test_ca_key_ec -#define test_ca_key_rsa mbedtls_test_ca_key_rsa -#define test_ca_list mbedtls_test_cas_pem -#define test_ca_pwd mbedtls_test_ca_pwd -#define test_ca_pwd_ec mbedtls_test_ca_pwd_ec -#define test_ca_pwd_rsa mbedtls_test_ca_pwd_rsa -#define test_cli_crt mbedtls_test_cli_crt -#define test_cli_crt_ec mbedtls_test_cli_crt_ec -#define test_cli_crt_rsa mbedtls_test_cli_crt_rsa -#define test_cli_key mbedtls_test_cli_key -#define test_cli_key_ec mbedtls_test_cli_key_ec -#define test_cli_key_rsa mbedtls_test_cli_key_rsa -#define test_srv_crt mbedtls_test_srv_crt -#define test_srv_crt_ec mbedtls_test_srv_crt_ec -#define test_srv_crt_rsa mbedtls_test_srv_crt_rsa -#define test_srv_key mbedtls_test_srv_key -#define test_srv_key_ec mbedtls_test_srv_key_ec -#define test_srv_key_rsa mbedtls_test_srv_key_rsa -#define threading_mutex_t mbedtls_threading_mutex_t -#define threading_set_alt mbedtls_threading_set_alt -#define timing_self_test mbedtls_timing_self_test -#define version_check_feature mbedtls_version_check_feature -#define version_get_number mbedtls_version_get_number -#define version_get_string mbedtls_version_get_string -#define version_get_string_full mbedtls_version_get_string_full -#define x509_bitstring mbedtls_x509_bitstring -#define x509_buf mbedtls_x509_buf -#define x509_crl mbedtls_x509_crl -#define x509_crl_entry mbedtls_x509_crl_entry -#define x509_crl_free mbedtls_x509_crl_free -#define x509_crl_info mbedtls_x509_crl_info -#define x509_crl_init mbedtls_x509_crl_init -#define x509_crl_parse mbedtls_x509_crl_parse -#define x509_crl_parse_der mbedtls_x509_crl_parse_der -#define x509_crl_parse_file mbedtls_x509_crl_parse_file -#define x509_crt mbedtls_x509_crt -#define x509_crt_check_extended_key_usage mbedtls_x509_crt_check_extended_key_usage -#define x509_crt_check_key_usage mbedtls_x509_crt_check_key_usage -#define x509_crt_free mbedtls_x509_crt_free -#define x509_crt_info mbedtls_x509_crt_info -#define x509_crt_init mbedtls_x509_crt_init -#define x509_crt_parse mbedtls_x509_crt_parse -#define x509_crt_parse_der mbedtls_x509_crt_parse_der -#define x509_crt_parse_file mbedtls_x509_crt_parse_file -#define x509_crt_parse_path mbedtls_x509_crt_parse_path -#define x509_crt_revoked mbedtls_x509_crt_is_revoked -#define x509_crt_verify mbedtls_x509_crt_verify -#define x509_csr mbedtls_x509_csr -#define x509_csr_free mbedtls_x509_csr_free -#define x509_csr_info mbedtls_x509_csr_info -#define x509_csr_init mbedtls_x509_csr_init -#define x509_csr_parse mbedtls_x509_csr_parse -#define x509_csr_parse_der mbedtls_x509_csr_parse_der -#define x509_csr_parse_file mbedtls_x509_csr_parse_file -#define x509_dn_gets mbedtls_x509_dn_gets -#define x509_get_alg mbedtls_x509_get_alg -#define x509_get_alg_null mbedtls_x509_get_alg_null -#define x509_get_ext mbedtls_x509_get_ext -#define x509_get_name mbedtls_x509_get_name -#define x509_get_rsassa_pss_params mbedtls_x509_get_rsassa_pss_params -#define x509_get_serial mbedtls_x509_get_serial -#define x509_get_sig mbedtls_x509_get_sig -#define x509_get_sig_alg mbedtls_x509_get_sig_alg -#define x509_get_time mbedtls_x509_get_time -#define x509_key_size_helper mbedtls_x509_key_size_helper -#define x509_name mbedtls_x509_name -#define x509_self_test mbedtls_x509_self_test -#define x509_sequence mbedtls_x509_sequence -#define x509_serial_gets mbedtls_x509_serial_gets -#define x509_set_extension mbedtls_x509_set_extension -#define x509_sig_alg_gets mbedtls_x509_sig_alg_gets -#define x509_string_to_names mbedtls_x509_string_to_names -#define x509_time mbedtls_x509_time -#define x509_time_expired mbedtls_x509_time_is_past -#define x509_time_future mbedtls_x509_time_is_future -#define x509_write_extensions mbedtls_x509_write_extensions -#define x509_write_names mbedtls_x509_write_names -#define x509_write_sig mbedtls_x509_write_sig -#define x509write_cert mbedtls_x509write_cert -#define x509write_crt_der mbedtls_x509write_crt_der -#define x509write_crt_free mbedtls_x509write_crt_free -#define x509write_crt_init mbedtls_x509write_crt_init -#define x509write_crt_pem mbedtls_x509write_crt_pem -#define x509write_crt_set_authority_key_identifier mbedtls_x509write_crt_set_authority_key_identifier -#define x509write_crt_set_basic_constraints mbedtls_x509write_crt_set_basic_constraints -#define x509write_crt_set_extension mbedtls_x509write_crt_set_extension -#define x509write_crt_set_issuer_key mbedtls_x509write_crt_set_issuer_key -#define x509write_crt_set_issuer_name mbedtls_x509write_crt_set_issuer_name -#define x509write_crt_set_key_usage mbedtls_x509write_crt_set_key_usage -#define x509write_crt_set_md_alg mbedtls_x509write_crt_set_md_alg -#define x509write_crt_set_ns_cert_type mbedtls_x509write_crt_set_ns_cert_type -#define x509write_crt_set_serial mbedtls_x509write_crt_set_serial -#define x509write_crt_set_subject_key mbedtls_x509write_crt_set_subject_key -#define x509write_crt_set_subject_key_identifier mbedtls_x509write_crt_set_subject_key_identifier -#define x509write_crt_set_subject_name mbedtls_x509write_crt_set_subject_name -#define x509write_crt_set_validity mbedtls_x509write_crt_set_validity -#define x509write_crt_set_version mbedtls_x509write_crt_set_version -#define x509write_csr mbedtls_x509write_csr -#define x509write_csr_der mbedtls_x509write_csr_der -#define x509write_csr_free mbedtls_x509write_csr_free -#define x509write_csr_init mbedtls_x509write_csr_init -#define x509write_csr_pem mbedtls_x509write_csr_pem -#define x509write_csr_set_extension mbedtls_x509write_csr_set_extension -#define x509write_csr_set_key mbedtls_x509write_csr_set_key -#define x509write_csr_set_key_usage mbedtls_x509write_csr_set_key_usage -#define x509write_csr_set_md_alg mbedtls_x509write_csr_set_md_alg -#define x509write_csr_set_ns_cert_type mbedtls_x509write_csr_set_ns_cert_type -#define x509write_csr_set_subject_name mbedtls_x509write_csr_set_subject_name -#define xtea_context mbedtls_xtea_context -#define xtea_crypt_cbc mbedtls_xtea_crypt_cbc -#define xtea_crypt_ecb mbedtls_xtea_crypt_ecb -#define xtea_free mbedtls_xtea_free -#define xtea_init mbedtls_xtea_init -#define xtea_self_test mbedtls_xtea_self_test -#define xtea_setup mbedtls_xtea_setup +#define SSL_BUFFER_LEN (((MBEDTLS_SSL_IN_BUFFER_LEN) < (MBEDTLS_SSL_OUT_BUFFER_LEN)) ? (MBEDTLS_SSL_IN_BUFFER_LEN) : (MBEDTLS_SSL_OUT_BUFFER_LEN)) +#define SSL_CACHE_DEFAULT_MAX_ENTRIES MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES +#define SSL_CACHE_DEFAULT_TIMEOUT MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT +#define SSL_CBC_RECORD_SPLITTING_DISABLED MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED +#define SSL_CBC_RECORD_SPLITTING_ENABLED MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED +#define SSL_CERTIFICATE_REQUEST MBEDTLS_SSL_CERTIFICATE_REQUEST +#define SSL_CERTIFICATE_VERIFY MBEDTLS_SSL_CERTIFICATE_VERIFY +#define SSL_CERT_TYPE_ECDSA_SIGN MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN +#define SSL_CERT_TYPE_RSA_SIGN MBEDTLS_SSL_CERT_TYPE_RSA_SIGN +#define SSL_CHANNEL_INBOUND MBEDTLS_SSL_CHANNEL_INBOUND +#define SSL_CHANNEL_OUTBOUND MBEDTLS_SSL_CHANNEL_OUTBOUND +#define SSL_CIPHERSUITES MBEDTLS_SSL_CIPHERSUITES +#define SSL_CLIENT_CERTIFICATE MBEDTLS_SSL_CLIENT_CERTIFICATE +#define SSL_CLIENT_CHANGE_CIPHER_SPEC MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC +#define SSL_CLIENT_FINISHED MBEDTLS_SSL_CLIENT_FINISHED +#define SSL_CLIENT_HELLO MBEDTLS_SSL_CLIENT_HELLO +#define SSL_CLIENT_KEY_EXCHANGE MBEDTLS_SSL_CLIENT_KEY_EXCHANGE +#define SSL_COMPRESSION_ADD MBEDTLS_SSL_COMPRESSION_ADD +#define SSL_COMPRESS_DEFLATE MBEDTLS_SSL_COMPRESS_DEFLATE +#define SSL_COMPRESS_NULL MBEDTLS_SSL_COMPRESS_NULL +#define SSL_DEBUG_BUF MBEDTLS_SSL_DEBUG_BUF +#define SSL_DEBUG_CRT MBEDTLS_SSL_DEBUG_CRT +#define SSL_DEBUG_ECP MBEDTLS_SSL_DEBUG_ECP +#define SSL_DEBUG_MPI MBEDTLS_SSL_DEBUG_MPI +#define SSL_DEBUG_MSG MBEDTLS_SSL_DEBUG_MSG +#define SSL_DEBUG_RET MBEDTLS_SSL_DEBUG_RET +#define SSL_DEFAULT_TICKET_LIFETIME MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME +#define SSL_DTLS_TIMEOUT_DFL_MAX MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX +#define SSL_DTLS_TIMEOUT_DFL_MIN MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN +#define SSL_EMPTY_RENEGOTIATION_INFO MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO +#define SSL_ETM_DISABLED MBEDTLS_SSL_ETM_DISABLED +#define SSL_ETM_ENABLED MBEDTLS_SSL_ETM_ENABLED +#define SSL_EXTENDED_MS_DISABLED MBEDTLS_SSL_EXTENDED_MS_DISABLED +#define SSL_EXTENDED_MS_ENABLED MBEDTLS_SSL_EXTENDED_MS_ENABLED +#define SSL_FALLBACK_SCSV MBEDTLS_SSL_FALLBACK_SCSV +#define SSL_FLUSH_BUFFERS MBEDTLS_SSL_FLUSH_BUFFERS +#define SSL_HANDSHAKE_OVER MBEDTLS_SSL_HANDSHAKE_OVER +#define SSL_HANDSHAKE_WRAPUP MBEDTLS_SSL_HANDSHAKE_WRAPUP +#define SSL_HASH_MD5 MBEDTLS_SSL_HASH_MD5 +#define SSL_HASH_NONE MBEDTLS_SSL_HASH_NONE +#define SSL_HASH_SHA1 MBEDTLS_SSL_HASH_SHA1 +#define SSL_HASH_SHA224 MBEDTLS_SSL_HASH_SHA224 +#define SSL_HASH_SHA256 MBEDTLS_SSL_HASH_SHA256 +#define SSL_HASH_SHA384 MBEDTLS_SSL_HASH_SHA384 +#define SSL_HASH_SHA512 MBEDTLS_SSL_HASH_SHA512 +#define SSL_HELLO_REQUEST MBEDTLS_SSL_HELLO_REQUEST +#define SSL_HS_CERTIFICATE MBEDTLS_SSL_HS_CERTIFICATE +#define SSL_HS_CERTIFICATE_REQUEST MBEDTLS_SSL_HS_CERTIFICATE_REQUEST +#define SSL_HS_CERTIFICATE_VERIFY MBEDTLS_SSL_HS_CERTIFICATE_VERIFY +#define SSL_HS_CLIENT_HELLO MBEDTLS_SSL_HS_CLIENT_HELLO +#define SSL_HS_CLIENT_KEY_EXCHANGE MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE +#define SSL_HS_FINISHED MBEDTLS_SSL_HS_FINISHED +#define SSL_HS_HELLO_REQUEST MBEDTLS_SSL_HS_HELLO_REQUEST +#define SSL_HS_HELLO_VERIFY_REQUEST MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST +#define SSL_HS_NEW_SESSION_TICKET MBEDTLS_SSL_HS_NEW_SESSION_TICKET +#define SSL_HS_SERVER_HELLO MBEDTLS_SSL_HS_SERVER_HELLO +#define SSL_HS_SERVER_HELLO_DONE MBEDTLS_SSL_HS_SERVER_HELLO_DONE +#define SSL_HS_SERVER_KEY_EXCHANGE MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE +#define SSL_INITIAL_HANDSHAKE MBEDTLS_SSL_INITIAL_HANDSHAKE +#define SSL_IS_CLIENT MBEDTLS_SSL_IS_CLIENT +#define SSL_IS_FALLBACK MBEDTLS_SSL_IS_FALLBACK +#define SSL_IS_NOT_FALLBACK MBEDTLS_SSL_IS_NOT_FALLBACK +#define SSL_IS_SERVER MBEDTLS_SSL_IS_SERVER +#define SSL_LEGACY_ALLOW_RENEGOTIATION MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION +#define SSL_LEGACY_BREAK_HANDSHAKE MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE +#define SSL_LEGACY_NO_RENEGOTIATION MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION +#define SSL_LEGACY_RENEGOTIATION MBEDTLS_SSL_LEGACY_RENEGOTIATION +#define SSL_MAC_ADD MBEDTLS_SSL_MAC_ADD +#define SSL_MAJOR_VERSION_3 MBEDTLS_SSL_MAJOR_VERSION_3 +#define SSL_MAX_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN +#define SSL_MAX_FRAG_LEN_1024 MBEDTLS_SSL_MAX_FRAG_LEN_1024 +#define SSL_MAX_FRAG_LEN_2048 MBEDTLS_SSL_MAX_FRAG_LEN_2048 +#define SSL_MAX_FRAG_LEN_4096 MBEDTLS_SSL_MAX_FRAG_LEN_4096 +#define SSL_MAX_FRAG_LEN_512 MBEDTLS_SSL_MAX_FRAG_LEN_512 +#define SSL_MAX_FRAG_LEN_INVALID MBEDTLS_SSL_MAX_FRAG_LEN_INVALID +#define SSL_MAX_FRAG_LEN_NONE MBEDTLS_SSL_MAX_FRAG_LEN_NONE +#define SSL_MAX_MAJOR_VERSION MBEDTLS_SSL_MAX_MAJOR_VERSION +#define SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MAX_MINOR_VERSION +#define SSL_MINOR_VERSION_0 MBEDTLS_SSL_MINOR_VERSION_0 +#define SSL_MINOR_VERSION_1 MBEDTLS_SSL_MINOR_VERSION_1 +#define SSL_MINOR_VERSION_2 MBEDTLS_SSL_MINOR_VERSION_2 +#define SSL_MINOR_VERSION_3 MBEDTLS_SSL_MINOR_VERSION_3 +#define SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MIN_MAJOR_VERSION +#define SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MIN_MINOR_VERSION +#define SSL_MSG_ALERT MBEDTLS_SSL_MSG_ALERT +#define SSL_MSG_APPLICATION_DATA MBEDTLS_SSL_MSG_APPLICATION_DATA +#define SSL_MSG_CHANGE_CIPHER_SPEC MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC +#define SSL_MSG_HANDSHAKE MBEDTLS_SSL_MSG_HANDSHAKE +#define SSL_PADDING_ADD MBEDTLS_SSL_PADDING_ADD +#define SSL_RENEGOTIATION MBEDTLS_SSL_RENEGOTIATION +#define SSL_RENEGOTIATION_DISABLED MBEDTLS_SSL_RENEGOTIATION_DISABLED +#define SSL_RENEGOTIATION_DONE MBEDTLS_SSL_RENEGOTIATION_DONE +#define SSL_RENEGOTIATION_ENABLED MBEDTLS_SSL_RENEGOTIATION_ENABLED +#define SSL_RENEGOTIATION_NOT_ENFORCED MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED +#define SSL_RENEGOTIATION_PENDING MBEDTLS_SSL_RENEGOTIATION_PENDING +#define SSL_RENEGO_MAX_RECORDS_DEFAULT MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT +#define SSL_RETRANS_FINISHED MBEDTLS_SSL_RETRANS_FINISHED +#define SSL_RETRANS_PREPARING MBEDTLS_SSL_RETRANS_PREPARING +#define SSL_RETRANS_SENDING MBEDTLS_SSL_RETRANS_SENDING +#define SSL_RETRANS_WAITING MBEDTLS_SSL_RETRANS_WAITING +#define SSL_SECURE_RENEGOTIATION MBEDTLS_SSL_SECURE_RENEGOTIATION +#define SSL_SERVER_CERTIFICATE MBEDTLS_SSL_SERVER_CERTIFICATE +#define SSL_SERVER_CHANGE_CIPHER_SPEC MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC +#define SSL_SERVER_FINISHED MBEDTLS_SSL_SERVER_FINISHED +#define SSL_SERVER_HELLO MBEDTLS_SSL_SERVER_HELLO +#define SSL_SERVER_HELLO_DONE MBEDTLS_SSL_SERVER_HELLO_DONE +#define SSL_SERVER_HELLO_VERIFY_REQUEST_SENT MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT +#define SSL_SERVER_KEY_EXCHANGE MBEDTLS_SSL_SERVER_KEY_EXCHANGE +#define SSL_SERVER_NEW_SESSION_TICKET MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET +#define SSL_SESSION_TICKETS_DISABLED MBEDTLS_SSL_SESSION_TICKETS_DISABLED +#define SSL_SESSION_TICKETS_ENABLED MBEDTLS_SSL_SESSION_TICKETS_ENABLED +#define SSL_SIG_ANON MBEDTLS_SSL_SIG_ANON +#define SSL_SIG_ECDSA MBEDTLS_SSL_SIG_ECDSA +#define SSL_SIG_RSA MBEDTLS_SSL_SIG_RSA +#define SSL_TRANSPORT_DATAGRAM MBEDTLS_SSL_TRANSPORT_DATAGRAM +#define SSL_TRANSPORT_STREAM MBEDTLS_SSL_TRANSPORT_STREAM +#define SSL_TRUNCATED_HMAC_LEN MBEDTLS_SSL_TRUNCATED_HMAC_LEN +#define SSL_TRUNC_HMAC_DISABLED MBEDTLS_SSL_TRUNC_HMAC_DISABLED +#define SSL_TRUNC_HMAC_ENABLED MBEDTLS_SSL_TRUNC_HMAC_ENABLED +#define SSL_VERIFY_DATA_MAX_LEN MBEDTLS_SSL_VERIFY_DATA_MAX_LEN +#define SSL_VERIFY_NONE MBEDTLS_SSL_VERIFY_NONE +#define SSL_VERIFY_OPTIONAL MBEDTLS_SSL_VERIFY_OPTIONAL +#define SSL_VERIFY_REQUIRED MBEDTLS_SSL_VERIFY_REQUIRED +#define TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA +#define TLS_DHE_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA +#define TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 +#define TLS_DHE_PSK_WITH_AES_128_CCM MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM +#define TLS_DHE_PSK_WITH_AES_128_CCM_8 MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8 +#define TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 +#define TLS_DHE_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA +#define TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 +#define TLS_DHE_PSK_WITH_AES_256_CCM MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM +#define TLS_DHE_PSK_WITH_AES_256_CCM_8 MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8 +#define TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 +#define TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_DHE_PSK_WITH_NULL_SHA MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA +#define TLS_DHE_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256 +#define TLS_DHE_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384 +#define TLS_DHE_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA +#define TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA +#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA +#define TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 +#define TLS_DHE_RSA_WITH_AES_128_CCM MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM +#define TLS_DHE_RSA_WITH_AES_128_CCM_8 MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8 +#define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 +#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA +#define TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 +#define TLS_DHE_RSA_WITH_AES_256_CCM MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM +#define TLS_DHE_RSA_WITH_AES_256_CCM_8 MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8 +#define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 +#define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA +#define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA +#define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 +#define TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_DHE_RSA_WITH_DES_CBC_SHA MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA +#define TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA +#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA +#define TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 +#define TLS_ECDHE_ECDSA_WITH_AES_128_CCM MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM +#define TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 +#define TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 +#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA +#define TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 +#define TLS_ECDHE_ECDSA_WITH_AES_256_CCM MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM +#define TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 +#define TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 +#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_ECDHE_ECDSA_WITH_NULL_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA +#define TLS_ECDHE_ECDSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA +#define TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA +#define TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA +#define TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 +#define TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA +#define TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 +#define TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_ECDHE_PSK_WITH_NULL_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA +#define TLS_ECDHE_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256 +#define TLS_ECDHE_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384 +#define TLS_ECDHE_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA +#define TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA +#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA +#define TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 +#define TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 +#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA +#define TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 +#define TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 +#define TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_ECDHE_RSA_WITH_NULL_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA +#define TLS_ECDHE_RSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA +#define TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA +#define TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA +#define TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 +#define TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 +#define TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA +#define TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 +#define TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 +#define TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_ECDH_ECDSA_WITH_NULL_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA +#define TLS_ECDH_ECDSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA +#define TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA +#define TLS_ECDH_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA +#define TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 +#define TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 +#define TLS_ECDH_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA +#define TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 +#define TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 +#define TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_ECDH_RSA_WITH_NULL_SHA MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA +#define TLS_ECDH_RSA_WITH_RC4_128_SHA MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA +#define TLS_EXT_ALPN MBEDTLS_TLS_EXT_ALPN +#define TLS_EXT_ENCRYPT_THEN_MAC MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC +#define TLS_EXT_EXTENDED_MASTER_SECRET MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET +#define TLS_EXT_MAX_FRAGMENT_LENGTH MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH +#define TLS_EXT_RENEGOTIATION_INFO MBEDTLS_TLS_EXT_RENEGOTIATION_INFO +#define TLS_EXT_SERVERNAME MBEDTLS_TLS_EXT_SERVERNAME +#define TLS_EXT_SERVERNAME_HOSTNAME MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME +#define TLS_EXT_SESSION_TICKET MBEDTLS_TLS_EXT_SESSION_TICKET +#define TLS_EXT_SIG_ALG MBEDTLS_TLS_EXT_SIG_ALG +#define TLS_EXT_SUPPORTED_ELLIPTIC_CURVES MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES +#define TLS_EXT_SUPPORTED_POINT_FORMATS MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS +#define TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT +#define TLS_EXT_TRUNCATED_HMAC MBEDTLS_TLS_EXT_TRUNCATED_HMAC +#define TLS_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA +#define TLS_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA +#define TLS_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256 +#define TLS_PSK_WITH_AES_128_CCM MBEDTLS_TLS_PSK_WITH_AES_128_CCM +#define TLS_PSK_WITH_AES_128_CCM_8 MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8 +#define TLS_PSK_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256 +#define TLS_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA +#define TLS_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384 +#define TLS_PSK_WITH_AES_256_CCM MBEDTLS_TLS_PSK_WITH_AES_256_CCM +#define TLS_PSK_WITH_AES_256_CCM_8 MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8 +#define TLS_PSK_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384 +#define TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_PSK_WITH_NULL_SHA MBEDTLS_TLS_PSK_WITH_NULL_SHA +#define TLS_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_PSK_WITH_NULL_SHA256 +#define TLS_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_PSK_WITH_NULL_SHA384 +#define TLS_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_PSK_WITH_RC4_128_SHA +#define TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA +#define TLS_RSA_PSK_WITH_AES_128_CBC_SHA MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA +#define TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 +#define TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 +#define TLS_RSA_PSK_WITH_AES_256_CBC_SHA MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA +#define TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 +#define TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 +#define TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 +#define TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_RSA_PSK_WITH_NULL_SHA MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA +#define TLS_RSA_PSK_WITH_NULL_SHA256 MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256 +#define TLS_RSA_PSK_WITH_NULL_SHA384 MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384 +#define TLS_RSA_PSK_WITH_RC4_128_SHA MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA +#define TLS_RSA_WITH_3DES_EDE_CBC_SHA MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA +#define TLS_RSA_WITH_AES_128_CBC_SHA MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA +#define TLS_RSA_WITH_AES_128_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256 +#define TLS_RSA_WITH_AES_128_CCM MBEDTLS_TLS_RSA_WITH_AES_128_CCM +#define TLS_RSA_WITH_AES_128_CCM_8 MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8 +#define TLS_RSA_WITH_AES_128_GCM_SHA256 MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256 +#define TLS_RSA_WITH_AES_256_CBC_SHA MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA +#define TLS_RSA_WITH_AES_256_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256 +#define TLS_RSA_WITH_AES_256_CCM MBEDTLS_TLS_RSA_WITH_AES_256_CCM +#define TLS_RSA_WITH_AES_256_CCM_8 MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8 +#define TLS_RSA_WITH_AES_256_GCM_SHA384 MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384 +#define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA +#define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 +#define TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 +#define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA +#define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 +#define TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 +#define TLS_RSA_WITH_DES_CBC_SHA MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA +#define TLS_RSA_WITH_NULL_MD5 MBEDTLS_TLS_RSA_WITH_NULL_MD5 +#define TLS_RSA_WITH_NULL_SHA MBEDTLS_TLS_RSA_WITH_NULL_SHA +#define TLS_RSA_WITH_NULL_SHA256 MBEDTLS_TLS_RSA_WITH_NULL_SHA256 +#define TLS_RSA_WITH_RC4_128_MD5 MBEDTLS_TLS_RSA_WITH_RC4_128_MD5 +#define TLS_RSA_WITH_RC4_128_SHA MBEDTLS_TLS_RSA_WITH_RC4_128_SHA +#define X509_CRT_VERSION_1 MBEDTLS_X509_CRT_VERSION_1 +#define X509_CRT_VERSION_2 MBEDTLS_X509_CRT_VERSION_2 +#define X509_CRT_VERSION_3 MBEDTLS_X509_CRT_VERSION_3 +#define X509_FORMAT_DER MBEDTLS_X509_FORMAT_DER +#define X509_FORMAT_PEM MBEDTLS_X509_FORMAT_PEM +#define X509_MAX_DN_NAME_SIZE MBEDTLS_X509_MAX_DN_NAME_SIZE +#define X509_RFC5280_MAX_SERIAL_LEN MBEDTLS_X509_RFC5280_MAX_SERIAL_LEN +#define X509_RFC5280_UTC_TIME_LEN MBEDTLS_X509_RFC5280_UTC_TIME_LEN +#define XTEA_DECRYPT MBEDTLS_XTEA_DECRYPT +#define XTEA_ENCRYPT MBEDTLS_XTEA_ENCRYPT +#define _asn1_bitstring mbedtls_asn1_bitstring +#define _asn1_buf mbedtls_asn1_buf +#define _asn1_named_data mbedtls_asn1_named_data +#define _asn1_sequence mbedtls_asn1_sequence +#define _ssl_cache_context mbedtls_ssl_cache_context +#define _ssl_cache_entry mbedtls_ssl_cache_entry +#define _ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t +#define _ssl_context mbedtls_ssl_context +#define _ssl_flight_item mbedtls_ssl_flight_item +#define _ssl_handshake_params mbedtls_ssl_handshake_params +#define _ssl_key_cert mbedtls_ssl_key_cert +#define _ssl_premaster_secret mbedtls_ssl_premaster_secret +#define _ssl_session mbedtls_ssl_session +#define _ssl_transform mbedtls_ssl_transform +#define _x509_crl mbedtls_x509_crl +#define _x509_crl_entry mbedtls_x509_crl_entry +#define _x509_crt mbedtls_x509_crt +#define _x509_csr mbedtls_x509_csr +#define _x509_time mbedtls_x509_time +#define _x509write_cert mbedtls_x509write_cert +#define _x509write_csr mbedtls_x509write_csr +#define aes_context mbedtls_aes_context +#define aes_crypt_cbc mbedtls_aes_crypt_cbc +#define aes_crypt_cfb128 mbedtls_aes_crypt_cfb128 +#define aes_crypt_cfb8 mbedtls_aes_crypt_cfb8 +#define aes_crypt_ctr mbedtls_aes_crypt_ctr +#define aes_crypt_ecb mbedtls_aes_crypt_ecb +#define aes_free mbedtls_aes_free +#define aes_init mbedtls_aes_init +#define aes_self_test mbedtls_aes_self_test +#define aes_setkey_dec mbedtls_aes_setkey_dec +#define aes_setkey_enc mbedtls_aes_setkey_enc +#define aesni_crypt_ecb mbedtls_aesni_crypt_ecb +#define aesni_gcm_mult mbedtls_aesni_gcm_mult +#define aesni_inverse_key mbedtls_aesni_inverse_key +#define aesni_setkey_enc mbedtls_aesni_setkey_enc +#define aesni_supports mbedtls_aesni_has_support +#define alarmed mbedtls_timing_alarmed +#define arc4_context mbedtls_arc4_context +#define arc4_crypt mbedtls_arc4_crypt +#define arc4_free mbedtls_arc4_free +#define arc4_init mbedtls_arc4_init +#define arc4_self_test mbedtls_arc4_self_test +#define arc4_setup mbedtls_arc4_setup +#define asn1_bitstring mbedtls_asn1_bitstring +#define asn1_buf mbedtls_asn1_buf +#define asn1_find_named_data mbedtls_asn1_find_named_data +#define asn1_free_named_data mbedtls_asn1_free_named_data +#define asn1_free_named_data_list mbedtls_asn1_free_named_data_list +#define asn1_get_alg mbedtls_asn1_get_alg +#define asn1_get_alg_null mbedtls_asn1_get_alg_null +#define asn1_get_bitstring mbedtls_asn1_get_bitstring +#define asn1_get_bitstring_null mbedtls_asn1_get_bitstring_null +#define asn1_get_bool mbedtls_asn1_get_bool +#define asn1_get_int mbedtls_asn1_get_int +#define asn1_get_len mbedtls_asn1_get_len +#define asn1_get_mpi mbedtls_asn1_get_mpi +#define asn1_get_sequence_of mbedtls_asn1_get_sequence_of +#define asn1_get_tag mbedtls_asn1_get_tag +#define asn1_named_data mbedtls_asn1_named_data +#define asn1_sequence mbedtls_asn1_sequence +#define asn1_store_named_data mbedtls_asn1_store_named_data +#define asn1_write_algorithm_identifier mbedtls_asn1_write_algorithm_identifier +#define asn1_write_bitstring mbedtls_asn1_write_bitstring +#define asn1_write_bool mbedtls_asn1_write_bool +#define asn1_write_ia5_string mbedtls_asn1_write_ia5_string +#define asn1_write_int mbedtls_asn1_write_int +#define asn1_write_len mbedtls_asn1_write_len +#define asn1_write_mpi mbedtls_asn1_write_mpi +#define asn1_write_null mbedtls_asn1_write_null +#define asn1_write_octet_string mbedtls_asn1_write_octet_string +#define asn1_write_oid mbedtls_asn1_write_oid +#define asn1_write_printable_string mbedtls_asn1_write_printable_string +#define asn1_write_raw_buffer mbedtls_asn1_write_raw_buffer +#define asn1_write_tag mbedtls_asn1_write_tag +#define base64_decode mbedtls_base64_decode +#define base64_encode mbedtls_base64_encode +#define base64_self_test mbedtls_base64_self_test +#define blowfish_context mbedtls_blowfish_context +#define blowfish_crypt_cbc mbedtls_blowfish_crypt_cbc +#define blowfish_crypt_cfb64 mbedtls_blowfish_crypt_cfb64 +#define blowfish_crypt_ctr mbedtls_blowfish_crypt_ctr +#define blowfish_crypt_ecb mbedtls_blowfish_crypt_ecb +#define blowfish_free mbedtls_blowfish_free +#define blowfish_init mbedtls_blowfish_init +#define blowfish_setkey mbedtls_blowfish_setkey +#define camellia_context mbedtls_camellia_context +#define camellia_crypt_cbc mbedtls_camellia_crypt_cbc +#define camellia_crypt_cfb128 mbedtls_camellia_crypt_cfb128 +#define camellia_crypt_ctr mbedtls_camellia_crypt_ctr +#define camellia_crypt_ecb mbedtls_camellia_crypt_ecb +#define camellia_free mbedtls_camellia_free +#define camellia_init mbedtls_camellia_init +#define camellia_self_test mbedtls_camellia_self_test +#define camellia_setkey_dec mbedtls_camellia_setkey_dec +#define camellia_setkey_enc mbedtls_camellia_setkey_enc +#define ccm_auth_decrypt mbedtls_ccm_auth_decrypt +#define ccm_context mbedtls_ccm_context +#define ccm_encrypt_and_tag mbedtls_ccm_encrypt_and_tag +#define ccm_free mbedtls_ccm_free +#define ccm_init mbedtls_ccm_init +#define ccm_self_test mbedtls_ccm_self_test +#define cipher_auth_decrypt mbedtls_cipher_auth_decrypt +#define cipher_auth_encrypt mbedtls_cipher_auth_encrypt +#define cipher_base_t mbedtls_cipher_base_t +#define cipher_check_tag mbedtls_cipher_check_tag +#define cipher_context_t mbedtls_cipher_context_t +#define cipher_crypt mbedtls_cipher_crypt +#define cipher_definition_t mbedtls_cipher_definition_t +#define cipher_definitions mbedtls_cipher_definitions +#define cipher_finish mbedtls_cipher_finish +#define cipher_free mbedtls_cipher_free +#define cipher_get_block_size mbedtls_cipher_get_block_size +#define cipher_get_cipher_mode mbedtls_cipher_get_cipher_mode +#define cipher_get_iv_size mbedtls_cipher_get_iv_size +#define cipher_get_key_size mbedtls_cipher_get_key_bitlen +#define cipher_get_name mbedtls_cipher_get_name +#define cipher_get_operation mbedtls_cipher_get_operation +#define cipher_get_type mbedtls_cipher_get_type +#define cipher_id_t mbedtls_cipher_id_t +#define cipher_info_from_string mbedtls_cipher_info_from_string +#define cipher_info_from_type mbedtls_cipher_info_from_type +#define cipher_info_from_values mbedtls_cipher_info_from_values +#define cipher_info_t mbedtls_cipher_info_t +#define cipher_init mbedtls_cipher_init +#define cipher_init_ctx mbedtls_cipher_setup +#define cipher_list mbedtls_cipher_list +#define cipher_mode_t mbedtls_cipher_mode_t +#define cipher_padding_t mbedtls_cipher_padding_t +#define cipher_reset mbedtls_cipher_reset +#define cipher_set_iv mbedtls_cipher_set_iv +#define cipher_set_padding_mode mbedtls_cipher_set_padding_mode +#define cipher_setkey mbedtls_cipher_setkey +#define cipher_type_t mbedtls_cipher_type_t +#define cipher_update mbedtls_cipher_update +#define cipher_update_ad mbedtls_cipher_update_ad +#define cipher_write_tag mbedtls_cipher_write_tag +#define ctr_drbg_context mbedtls_ctr_drbg_context +#define ctr_drbg_free mbedtls_ctr_drbg_free +#define ctr_drbg_init mbedtls_ctr_drbg_init +#define ctr_drbg_random mbedtls_ctr_drbg_random +#define ctr_drbg_random_with_add mbedtls_ctr_drbg_random_with_add +#define ctr_drbg_reseed mbedtls_ctr_drbg_reseed +#define ctr_drbg_self_test mbedtls_ctr_drbg_self_test +#define ctr_drbg_set_entropy_len mbedtls_ctr_drbg_set_entropy_len +#define ctr_drbg_set_prediction_resistance mbedtls_ctr_drbg_set_prediction_resistance +#define ctr_drbg_set_reseed_interval mbedtls_ctr_drbg_set_reseed_interval +#define ctr_drbg_update mbedtls_ctr_drbg_update +#define ctr_drbg_update_seed_file mbedtls_ctr_drbg_update_seed_file +#define ctr_drbg_write_seed_file mbedtls_ctr_drbg_write_seed_file +#define debug_print_buf mbedtls_debug_print_buf +#define debug_print_crt mbedtls_debug_print_crt +#define debug_print_ecp mbedtls_debug_print_ecp +#define debug_print_mpi mbedtls_debug_print_mpi +#define debug_print_msg mbedtls_debug_print_msg +#define debug_print_ret mbedtls_debug_print_ret +#define debug_set_threshold mbedtls_debug_set_threshold +#define des3_context mbedtls_des3_context +#define des3_crypt_cbc mbedtls_des3_crypt_cbc +#define des3_crypt_ecb mbedtls_des3_crypt_ecb +#define des3_free mbedtls_des3_free +#define des3_init mbedtls_des3_init +#define des3_set2key_dec mbedtls_des3_set2key_dec +#define des3_set2key_enc mbedtls_des3_set2key_enc +#define des3_set3key_dec mbedtls_des3_set3key_dec +#define des3_set3key_enc mbedtls_des3_set3key_enc +#define des_context mbedtls_des_context +#define des_crypt_cbc mbedtls_des_crypt_cbc +#define des_crypt_ecb mbedtls_des_crypt_ecb +#define des_free mbedtls_des_free +#define des_init mbedtls_des_init +#define des_key_check_key_parity mbedtls_des_key_check_key_parity +#define des_key_check_weak mbedtls_des_key_check_weak +#define des_key_set_parity mbedtls_des_key_set_parity +#define des_self_test mbedtls_des_self_test +#define des_setkey_dec mbedtls_des_setkey_dec +#define des_setkey_enc mbedtls_des_setkey_enc +#define dhm_calc_secret mbedtls_dhm_calc_secret +#define dhm_context mbedtls_dhm_context +#define dhm_free mbedtls_dhm_free +#define dhm_init mbedtls_dhm_init +#define dhm_make_params mbedtls_dhm_make_params +#define dhm_make_public mbedtls_dhm_make_public +#define dhm_parse_dhm mbedtls_dhm_parse_dhm +#define dhm_parse_dhmfile mbedtls_dhm_parse_dhmfile +#define dhm_read_params mbedtls_dhm_read_params +#define dhm_read_public mbedtls_dhm_read_public +#define dhm_self_test mbedtls_dhm_self_test +#define ecdh_calc_secret mbedtls_ecdh_calc_secret +#define ecdh_compute_shared mbedtls_ecdh_compute_shared +#define ecdh_context mbedtls_ecdh_context +#define ecdh_free mbedtls_ecdh_free +#define ecdh_gen_public mbedtls_ecdh_gen_public +#define ecdh_get_params mbedtls_ecdh_get_params +#define ecdh_init mbedtls_ecdh_init +#define ecdh_make_params mbedtls_ecdh_make_params +#define ecdh_make_public mbedtls_ecdh_make_public +#define ecdh_read_params mbedtls_ecdh_read_params +#define ecdh_read_public mbedtls_ecdh_read_public +#define ecdh_side mbedtls_ecdh_side +#define ecdsa_context mbedtls_ecdsa_context +#define ecdsa_free mbedtls_ecdsa_free +#define ecdsa_from_keypair mbedtls_ecdsa_from_keypair +#define ecdsa_genkey mbedtls_ecdsa_genkey +#define ecdsa_info mbedtls_ecdsa_info +#define ecdsa_init mbedtls_ecdsa_init +#define ecdsa_read_signature mbedtls_ecdsa_read_signature +#define ecdsa_sign mbedtls_ecdsa_sign +#define ecdsa_sign_det mbedtls_ecdsa_sign_det +#define ecdsa_verify mbedtls_ecdsa_verify +#define ecdsa_write_signature mbedtls_ecdsa_write_signature +#define ecdsa_write_signature_det mbedtls_ecdsa_write_signature_det +#define eckey_info mbedtls_eckey_info +#define eckeydh_info mbedtls_eckeydh_info +#define ecp_check_privkey mbedtls_ecp_check_privkey +#define ecp_check_pub_priv mbedtls_ecp_check_pub_priv +#define ecp_check_pubkey mbedtls_ecp_check_pubkey +#define ecp_copy mbedtls_ecp_copy +#define ecp_curve_info mbedtls_ecp_curve_info +#define ecp_curve_info_from_grp_id mbedtls_ecp_curve_info_from_grp_id +#define ecp_curve_info_from_name mbedtls_ecp_curve_info_from_name +#define ecp_curve_info_from_tls_id mbedtls_ecp_curve_info_from_tls_id +#define ecp_curve_list mbedtls_ecp_curve_list +#define ecp_gen_key mbedtls_ecp_gen_key +#define ecp_gen_keypair mbedtls_ecp_gen_keypair +#define ecp_group mbedtls_ecp_group +#define ecp_group_copy mbedtls_ecp_group_copy +#define ecp_group_free mbedtls_ecp_group_free +#define ecp_group_id mbedtls_ecp_group_id +#define ecp_group_init mbedtls_ecp_group_init +#define ecp_grp_id_list mbedtls_ecp_grp_id_list +#define ecp_is_zero mbedtls_ecp_is_zero +#define ecp_keypair mbedtls_ecp_keypair +#define ecp_keypair_free mbedtls_ecp_keypair_free +#define ecp_keypair_init mbedtls_ecp_keypair_init +#define ecp_mul mbedtls_ecp_mul +#define ecp_point mbedtls_ecp_point +#define ecp_point_free mbedtls_ecp_point_free +#define ecp_point_init mbedtls_ecp_point_init +#define ecp_point_read_binary mbedtls_ecp_point_read_binary +#define ecp_point_read_string mbedtls_ecp_point_read_string +#define ecp_point_write_binary mbedtls_ecp_point_write_binary +#define ecp_self_test mbedtls_ecp_self_test +#define ecp_set_zero mbedtls_ecp_set_zero +#define ecp_tls_read_group mbedtls_ecp_tls_read_group +#define ecp_tls_read_point mbedtls_ecp_tls_read_point +#define ecp_tls_write_group mbedtls_ecp_tls_write_group +#define ecp_tls_write_point mbedtls_ecp_tls_write_point +#define ecp_use_known_dp mbedtls_ecp_group_load +#define entropy_add_source mbedtls_entropy_add_source +#define entropy_context mbedtls_entropy_context +#define entropy_free mbedtls_entropy_free +#define entropy_func mbedtls_entropy_func +#define entropy_gather mbedtls_entropy_gather +#define entropy_init mbedtls_entropy_init +#define entropy_self_test mbedtls_entropy_self_test +#define entropy_update_manual mbedtls_entropy_update_manual +#define entropy_update_seed_file mbedtls_entropy_update_seed_file +#define entropy_write_seed_file mbedtls_entropy_write_seed_file +#define error_strerror mbedtls_strerror +#define f_source_ptr mbedtls_entropy_f_source_ptr +#define gcm_auth_decrypt mbedtls_gcm_auth_decrypt +#define gcm_context mbedtls_gcm_context +#define gcm_crypt_and_tag mbedtls_gcm_crypt_and_tag +#define gcm_finish mbedtls_gcm_finish +#define gcm_free mbedtls_gcm_free +#define gcm_init mbedtls_gcm_init +#define gcm_self_test mbedtls_gcm_self_test +#define gcm_starts mbedtls_gcm_starts +#define gcm_update mbedtls_gcm_update +#define get_timer mbedtls_timing_get_timer +#define hardclock mbedtls_timing_hardclock +#define hardclock_poll mbedtls_hardclock_poll +#define havege_free mbedtls_havege_free +#define havege_init mbedtls_havege_init +#define havege_poll mbedtls_havege_poll +#define havege_random mbedtls_havege_random +#define havege_state mbedtls_havege_state +#define hmac_drbg_context mbedtls_hmac_drbg_context +#define hmac_drbg_free mbedtls_hmac_drbg_free +#define hmac_drbg_init mbedtls_hmac_drbg_init +#define hmac_drbg_random mbedtls_hmac_drbg_random +#define hmac_drbg_random_with_add mbedtls_hmac_drbg_random_with_add +#define hmac_drbg_reseed mbedtls_hmac_drbg_reseed +#define hmac_drbg_self_test mbedtls_hmac_drbg_self_test +#define hmac_drbg_set_entropy_len mbedtls_hmac_drbg_set_entropy_len +#define hmac_drbg_set_prediction_resistance mbedtls_hmac_drbg_set_prediction_resistance +#define hmac_drbg_set_reseed_interval mbedtls_hmac_drbg_set_reseed_interval +#define hmac_drbg_update mbedtls_hmac_drbg_update +#define hmac_drbg_update_seed_file mbedtls_hmac_drbg_update_seed_file +#define hmac_drbg_write_seed_file mbedtls_hmac_drbg_write_seed_file +#define hr_time mbedtls_timing_hr_time +#define key_exchange_type_t mbedtls_key_exchange_type_t +#define md mbedtls_md +#define md2 mbedtls_md2 +#define md2_context mbedtls_md2_context +#define md2_finish mbedtls_md2_finish +#define md2_free mbedtls_md2_free +#define md2_info mbedtls_md2_info +#define md2_init mbedtls_md2_init +#define md2_process mbedtls_md2_process +#define md2_self_test mbedtls_md2_self_test +#define md2_starts mbedtls_md2_starts +#define md2_update mbedtls_md2_update +#define md4 mbedtls_md4 +#define md4_context mbedtls_md4_context +#define md4_finish mbedtls_md4_finish +#define md4_free mbedtls_md4_free +#define md4_info mbedtls_md4_info +#define md4_init mbedtls_md4_init +#define md4_process mbedtls_md4_process +#define md4_self_test mbedtls_md4_self_test +#define md4_starts mbedtls_md4_starts +#define md4_update mbedtls_md4_update +#define md5 mbedtls_md5 +#define md5_context mbedtls_md5_context +#define md5_finish mbedtls_md5_finish +#define md5_free mbedtls_md5_free +#define md5_info mbedtls_md5_info +#define md5_init mbedtls_md5_init +#define md5_process mbedtls_md5_process +#define md5_self_test mbedtls_md5_self_test +#define md5_starts mbedtls_md5_starts +#define md5_update mbedtls_md5_update +#define md_context_t mbedtls_md_context_t +#define md_file mbedtls_md_file +#define md_finish mbedtls_md_finish +#define md_free mbedtls_md_free +#define md_get_name mbedtls_md_get_name +#define md_get_size mbedtls_md_get_size +#define md_get_type mbedtls_md_get_type +#define md_hmac mbedtls_md_hmac +#define md_hmac_finish mbedtls_md_hmac_finish +#define md_hmac_reset mbedtls_md_hmac_reset +#define md_hmac_starts mbedtls_md_hmac_starts +#define md_hmac_update mbedtls_md_hmac_update +#define md_info_from_string mbedtls_md_info_from_string +#define md_info_from_type mbedtls_md_info_from_type +#define md_info_t mbedtls_md_info_t +#define md_init mbedtls_md_init +#define md_init_ctx mbedtls_md_init_ctx +#define md_list mbedtls_md_list +#define md_process mbedtls_md_process +#define md_starts mbedtls_md_starts +#define md_type_t mbedtls_md_type_t +#define md_update mbedtls_md_update +#define memory_buffer_alloc_cur_get mbedtls_memory_buffer_alloc_cur_get +#define memory_buffer_alloc_free mbedtls_memory_buffer_alloc_free +#define memory_buffer_alloc_init mbedtls_memory_buffer_alloc_init +#define memory_buffer_alloc_max_get mbedtls_memory_buffer_alloc_max_get +#define memory_buffer_alloc_max_reset mbedtls_memory_buffer_alloc_max_reset +#define memory_buffer_alloc_self_test mbedtls_memory_buffer_alloc_self_test +#define memory_buffer_alloc_status mbedtls_memory_buffer_alloc_status +#define memory_buffer_alloc_verify mbedtls_memory_buffer_alloc_verify +#define memory_buffer_set_verify mbedtls_memory_buffer_set_verify +#define mpi mbedtls_mpi +#define mpi_add_abs mbedtls_mpi_add_abs +#define mpi_add_int mbedtls_mpi_add_int +#define mpi_add_mpi mbedtls_mpi_add_mpi +#define mpi_cmp_abs mbedtls_mpi_cmp_abs +#define mpi_cmp_int mbedtls_mpi_cmp_int +#define mpi_cmp_mpi mbedtls_mpi_cmp_mpi +#define mpi_copy mbedtls_mpi_copy +#define mpi_div_int mbedtls_mpi_div_int +#define mpi_div_mpi mbedtls_mpi_div_mpi +#define mpi_exp_mod mbedtls_mpi_exp_mod +#define mpi_fill_random mbedtls_mpi_fill_random +#define mpi_free mbedtls_mpi_free +#define mpi_gcd mbedtls_mpi_gcd +#define mpi_gen_prime mbedtls_mpi_gen_prime +#define mpi_get_bit mbedtls_mpi_get_bit +#define mpi_grow mbedtls_mpi_grow +#define mpi_init mbedtls_mpi_init +#define mpi_inv_mod mbedtls_mpi_inv_mod +#define mpi_is_prime mbedtls_mpi_is_prime +#define mpi_lsb mbedtls_mpi_lsb +#define mpi_lset mbedtls_mpi_lset +#define mpi_mod_int mbedtls_mpi_mod_int +#define mpi_mod_mpi mbedtls_mpi_mod_mpi +#define mpi_msb mbedtls_mpi_bitlen +#define mpi_mul_int mbedtls_mpi_mul_int +#define mpi_mul_mpi mbedtls_mpi_mul_mpi +#define mpi_read_binary mbedtls_mpi_read_binary +#define mpi_read_file mbedtls_mpi_read_file +#define mpi_read_string mbedtls_mpi_read_string +#define mpi_safe_cond_assign mbedtls_mpi_safe_cond_assign +#define mpi_safe_cond_swap mbedtls_mpi_safe_cond_swap +#define mpi_self_test mbedtls_mpi_self_test +#define mpi_set_bit mbedtls_mpi_set_bit +#define mpi_shift_l mbedtls_mpi_shift_l +#define mpi_shift_r mbedtls_mpi_shift_r +#define mpi_shrink mbedtls_mpi_shrink +#define mpi_size mbedtls_mpi_size +#define mpi_sub_abs mbedtls_mpi_sub_abs +#define mpi_sub_int mbedtls_mpi_sub_int +#define mpi_sub_mpi mbedtls_mpi_sub_mpi +#define mpi_swap mbedtls_mpi_swap +#define mpi_write_binary mbedtls_mpi_write_binary +#define mpi_write_file mbedtls_mpi_write_file +#define mpi_write_string mbedtls_mpi_write_string +#define net_accept mbedtls_net_accept +#define net_bind mbedtls_net_bind +#define net_close mbedtls_net_free +#define net_connect mbedtls_net_connect +#define net_recv mbedtls_net_recv +#define net_recv_timeout mbedtls_net_recv_timeout +#define net_send mbedtls_net_send +#define net_set_block mbedtls_net_set_block +#define net_set_nonblock mbedtls_net_set_nonblock +#define net_usleep mbedtls_net_usleep +#define oid_descriptor_t mbedtls_oid_descriptor_t +#define oid_get_attr_short_name mbedtls_oid_get_attr_short_name +#define oid_get_cipher_alg mbedtls_oid_get_cipher_alg +#define oid_get_ec_grp mbedtls_oid_get_ec_grp +#define oid_get_extended_key_usage mbedtls_oid_get_extended_key_usage +#define oid_get_md_alg mbedtls_oid_get_md_alg +#define oid_get_numeric_string mbedtls_oid_get_numeric_string +#define oid_get_oid_by_ec_grp mbedtls_oid_get_oid_by_ec_grp +#define oid_get_oid_by_md mbedtls_oid_get_oid_by_md +#define oid_get_oid_by_pk_alg mbedtls_oid_get_oid_by_pk_alg +#define oid_get_oid_by_sig_alg mbedtls_oid_get_oid_by_sig_alg +#define oid_get_pk_alg mbedtls_oid_get_pk_alg +#define oid_get_pkcs12_pbe_alg mbedtls_oid_get_pkcs12_pbe_alg +#define oid_get_sig_alg mbedtls_oid_get_sig_alg +#define oid_get_sig_alg_desc mbedtls_oid_get_sig_alg_desc +#define oid_get_x509_ext_type mbedtls_oid_get_x509_ext_type +#define operation_t mbedtls_operation_t +#define padlock_supports mbedtls_padlock_has_support +#define padlock_xcryptcbc mbedtls_padlock_xcryptcbc +#define padlock_xcryptecb mbedtls_padlock_xcryptecb +#define pem_context mbedtls_pem_context +#define pem_free mbedtls_pem_free +#define pem_init mbedtls_pem_init +#define pem_read_buffer mbedtls_pem_read_buffer +#define pem_write_buffer mbedtls_pem_write_buffer +#define pk_can_do mbedtls_pk_can_do +#define pk_check_pair mbedtls_pk_check_pair +#define pk_context mbedtls_pk_context +#define pk_debug mbedtls_pk_debug +#define pk_debug_item mbedtls_pk_debug_item +#define pk_debug_type mbedtls_pk_debug_type +#define pk_decrypt mbedtls_pk_decrypt +#define pk_ec mbedtls_pk_ec +#define pk_encrypt mbedtls_pk_encrypt +#define pk_free mbedtls_pk_free +#define pk_get_len mbedtls_pk_get_len +#define pk_get_name mbedtls_pk_get_name +#define pk_get_size mbedtls_pk_get_bitlen +#define pk_get_type mbedtls_pk_get_type +#define pk_info_from_type mbedtls_pk_info_from_type +#define pk_info_t mbedtls_pk_info_t +#define pk_init mbedtls_pk_init +#define pk_init_ctx mbedtls_pk_setup +#define pk_init_ctx_rsa_alt mbedtls_pk_setup_rsa_alt +#define pk_load_file mbedtls_pk_load_file +#define pk_parse_key mbedtls_pk_parse_key +#define pk_parse_keyfile mbedtls_pk_parse_keyfile +#define pk_parse_public_key mbedtls_pk_parse_public_key +#define pk_parse_public_keyfile mbedtls_pk_parse_public_keyfile +#define pk_parse_subpubkey mbedtls_pk_parse_subpubkey +#define pk_rsa mbedtls_pk_rsa +#define pk_rsa_alt_decrypt_func mbedtls_pk_rsa_alt_decrypt_func +#define pk_rsa_alt_key_len_func mbedtls_pk_rsa_alt_key_len_func +#define pk_rsa_alt_sign_func mbedtls_pk_rsa_alt_sign_func +#define pk_rsassa_pss_options mbedtls_pk_rsassa_pss_options +#define pk_sign mbedtls_pk_sign +#define pk_type_t mbedtls_pk_type_t +#define pk_verify mbedtls_pk_verify +#define pk_verify_ext mbedtls_pk_verify_ext +#define pk_write_key_der mbedtls_pk_write_key_der +#define pk_write_key_pem mbedtls_pk_write_key_pem +#define pk_write_pubkey mbedtls_pk_write_pubkey +#define pk_write_pubkey_der mbedtls_pk_write_pubkey_der +#define pk_write_pubkey_pem mbedtls_pk_write_pubkey_pem +#define pkcs11_context mbedtls_pkcs11_context +#define pkcs11_decrypt mbedtls_pkcs11_decrypt +#define pkcs11_priv_key_free mbedtls_pkcs11_priv_key_free +#define pkcs11_priv_key_init mbedtls_pkcs11_priv_key_bind +#define pkcs11_sign mbedtls_pkcs11_sign +#define pkcs11_x509_cert_init mbedtls_pkcs11_x509_cert_bind +#define pkcs12_derivation mbedtls_pkcs12_derivation +#define pkcs12_pbe mbedtls_pkcs12_pbe +#define pkcs12_pbe_sha1_rc4_128 mbedtls_pkcs12_pbe_sha1_rc4_128 +#define pkcs5_pbes2 mbedtls_pkcs5_pbes2 +#define pkcs5_pbkdf2_hmac mbedtls_pkcs5_pbkdf2_hmac +#define pkcs5_self_test mbedtls_pkcs5_self_test +#define platform_entropy_poll mbedtls_platform_entropy_poll +#define platform_set_exit mbedtls_platform_set_exit +#define platform_set_fprintf mbedtls_platform_set_fprintf +#define platform_set_printf mbedtls_platform_set_printf +#define platform_set_snprintf mbedtls_platform_set_snprintf +#define polarssl_exit mbedtls_exit +#define polarssl_fprintf mbedtls_fprintf +#define polarssl_free mbedtls_free +#define polarssl_mutex_free mbedtls_mutex_free +#define polarssl_mutex_init mbedtls_mutex_init +#define polarssl_mutex_lock mbedtls_mutex_lock +#define polarssl_mutex_unlock mbedtls_mutex_unlock +#define polarssl_printf mbedtls_printf +#define polarssl_snprintf mbedtls_snprintf +#define polarssl_strerror mbedtls_strerror +#define ripemd160 mbedtls_ripemd160 +#define ripemd160_context mbedtls_ripemd160_context +#define ripemd160_finish mbedtls_ripemd160_finish +#define ripemd160_free mbedtls_ripemd160_free +#define ripemd160_info mbedtls_ripemd160_info +#define ripemd160_init mbedtls_ripemd160_init +#define ripemd160_process mbedtls_ripemd160_process +#define ripemd160_self_test mbedtls_ripemd160_self_test +#define ripemd160_starts mbedtls_ripemd160_starts +#define ripemd160_update mbedtls_ripemd160_update +#define rsa_alt_context mbedtls_rsa_alt_context +#define rsa_alt_info mbedtls_rsa_alt_info +#define rsa_check_privkey mbedtls_rsa_check_privkey +#define rsa_check_pub_priv mbedtls_rsa_check_pub_priv +#define rsa_check_pubkey mbedtls_rsa_check_pubkey +#define rsa_context mbedtls_rsa_context +#define rsa_copy mbedtls_rsa_copy +#define rsa_free mbedtls_rsa_free +#define rsa_gen_key mbedtls_rsa_gen_key +#define rsa_info mbedtls_rsa_info +#define rsa_init mbedtls_rsa_init +#define rsa_pkcs1_decrypt mbedtls_rsa_pkcs1_decrypt +#define rsa_pkcs1_encrypt mbedtls_rsa_pkcs1_encrypt +#define rsa_pkcs1_sign mbedtls_rsa_pkcs1_sign +#define rsa_pkcs1_verify mbedtls_rsa_pkcs1_verify +#define rsa_private mbedtls_rsa_private +#define rsa_public mbedtls_rsa_public +#define rsa_rsaes_oaep_decrypt mbedtls_rsa_rsaes_oaep_decrypt +#define rsa_rsaes_oaep_encrypt mbedtls_rsa_rsaes_oaep_encrypt +#define rsa_rsaes_pkcs1_v15_decrypt mbedtls_rsa_rsaes_pkcs1_v15_decrypt +#define rsa_rsaes_pkcs1_v15_encrypt mbedtls_rsa_rsaes_pkcs1_v15_encrypt +#define rsa_rsassa_pkcs1_v15_sign mbedtls_rsa_rsassa_pkcs1_v15_sign +#define rsa_rsassa_pkcs1_v15_verify mbedtls_rsa_rsassa_pkcs1_v15_verify +#define rsa_rsassa_pss_sign mbedtls_rsa_rsassa_pss_sign +#define rsa_rsassa_pss_verify mbedtls_rsa_rsassa_pss_verify +#define rsa_rsassa_pss_verify_ext mbedtls_rsa_rsassa_pss_verify_ext +#define rsa_self_test mbedtls_rsa_self_test +#define rsa_set_padding mbedtls_rsa_set_padding +#define safer_memcmp mbedtls_ssl_safer_memcmp +#define set_alarm mbedtls_set_alarm +#define sha1 mbedtls_sha1 +#define sha1_context mbedtls_sha1_context +#define sha1_finish mbedtls_sha1_finish +#define sha1_free mbedtls_sha1_free +#define sha1_info mbedtls_sha1_info +#define sha1_init mbedtls_sha1_init +#define sha1_process mbedtls_sha1_process +#define sha1_self_test mbedtls_sha1_self_test +#define sha1_starts mbedtls_sha1_starts +#define sha1_update mbedtls_sha1_update +#define sha224_info mbedtls_sha224_info +#define sha256 mbedtls_sha256 +#define sha256_context mbedtls_sha256_context +#define sha256_finish mbedtls_sha256_finish +#define sha256_free mbedtls_sha256_free +#define sha256_info mbedtls_sha256_info +#define sha256_init mbedtls_sha256_init +#define sha256_process mbedtls_sha256_process +#define sha256_self_test mbedtls_sha256_self_test +#define sha256_starts mbedtls_sha256_starts +#define sha256_update mbedtls_sha256_update +#define sha384_info mbedtls_sha384_info +#define sha512 mbedtls_sha512 +#define sha512_context mbedtls_sha512_context +#define sha512_finish mbedtls_sha512_finish +#define sha512_free mbedtls_sha512_free +#define sha512_info mbedtls_sha512_info +#define sha512_init mbedtls_sha512_init +#define sha512_process mbedtls_sha512_process +#define sha512_self_test mbedtls_sha512_self_test +#define sha512_starts mbedtls_sha512_starts +#define sha512_update mbedtls_sha512_update +#define source_state mbedtls_entropy_source_state +#define ssl_cache_context mbedtls_ssl_cache_context +#define ssl_cache_entry mbedtls_ssl_cache_entry +#define ssl_cache_free mbedtls_ssl_cache_free +#define ssl_cache_get mbedtls_ssl_cache_get +#define ssl_cache_init mbedtls_ssl_cache_init +#define ssl_cache_set mbedtls_ssl_cache_set +#define ssl_cache_set_max_entries mbedtls_ssl_cache_set_max_entries +#define ssl_cache_set_timeout mbedtls_ssl_cache_set_timeout +#define ssl_check_cert_usage mbedtls_ssl_check_cert_usage +#define ssl_ciphersuite_from_id mbedtls_ssl_ciphersuite_from_id +#define ssl_ciphersuite_from_string mbedtls_ssl_ciphersuite_from_string +#define ssl_ciphersuite_t mbedtls_ssl_ciphersuite_t +#define ssl_ciphersuite_uses_ec mbedtls_ssl_ciphersuite_uses_ec +#define ssl_ciphersuite_uses_psk mbedtls_ssl_ciphersuite_uses_psk +#define ssl_close_notify mbedtls_ssl_close_notify +#define ssl_context mbedtls_ssl_context +#define ssl_cookie_check mbedtls_ssl_cookie_check +#define ssl_cookie_check_t mbedtls_ssl_cookie_check_t +#define ssl_cookie_ctx mbedtls_ssl_cookie_ctx +#define ssl_cookie_free mbedtls_ssl_cookie_free +#define ssl_cookie_init mbedtls_ssl_cookie_init +#define ssl_cookie_set_timeout mbedtls_ssl_cookie_set_timeout +#define ssl_cookie_setup mbedtls_ssl_cookie_setup +#define ssl_cookie_write mbedtls_ssl_cookie_write +#define ssl_cookie_write_t mbedtls_ssl_cookie_write_t +#define ssl_derive_keys mbedtls_ssl_derive_keys +#define ssl_dtls_replay_check mbedtls_ssl_dtls_replay_check +#define ssl_dtls_replay_update mbedtls_ssl_dtls_replay_update +#define ssl_fetch_input mbedtls_ssl_fetch_input +#define ssl_flight_item mbedtls_ssl_flight_item +#define ssl_flush_output mbedtls_ssl_flush_output +#define ssl_free mbedtls_ssl_free +#define ssl_get_alpn_protocol mbedtls_ssl_get_alpn_protocol +#define ssl_get_bytes_avail mbedtls_ssl_get_bytes_avail +#define ssl_get_ciphersuite mbedtls_ssl_get_ciphersuite +#define ssl_get_ciphersuite_id mbedtls_ssl_get_ciphersuite_id +#define ssl_get_ciphersuite_name mbedtls_ssl_get_ciphersuite_name +#define ssl_get_ciphersuite_sig_pk_alg mbedtls_ssl_get_ciphersuite_sig_pk_alg +#define ssl_get_peer_cert mbedtls_ssl_get_peer_cert +#define ssl_get_record_expansion mbedtls_ssl_get_record_expansion +#define ssl_get_session mbedtls_ssl_get_session +#define ssl_get_verify_result mbedtls_ssl_get_verify_result +#define ssl_get_version mbedtls_ssl_get_version +#define ssl_handshake mbedtls_ssl_handshake +#define ssl_handshake_client_step mbedtls_ssl_handshake_client_step +#define ssl_handshake_free mbedtls_ssl_handshake_free +#define ssl_handshake_params mbedtls_ssl_handshake_params +#define ssl_handshake_server_step mbedtls_ssl_handshake_server_step +#define ssl_handshake_step mbedtls_ssl_handshake_step +#define ssl_handshake_wrapup mbedtls_ssl_handshake_wrapup +#define ssl_hdr_len mbedtls_ssl_hdr_len +#define ssl_hs_hdr_len mbedtls_ssl_hs_hdr_len +#define ssl_hw_record_activate mbedtls_ssl_hw_record_activate +#define ssl_hw_record_finish mbedtls_ssl_hw_record_finish +#define ssl_hw_record_init mbedtls_ssl_hw_record_init +#define ssl_hw_record_read mbedtls_ssl_hw_record_read +#define ssl_hw_record_reset mbedtls_ssl_hw_record_reset +#define ssl_hw_record_write mbedtls_ssl_hw_record_write +#define ssl_init mbedtls_ssl_init +#define ssl_key_cert mbedtls_ssl_key_cert +#define ssl_legacy_renegotiation mbedtls_ssl_conf_legacy_renegotiation +#define ssl_list_ciphersuites mbedtls_ssl_list_ciphersuites +#define ssl_md_alg_from_hash mbedtls_ssl_md_alg_from_hash +#define ssl_optimize_checksum mbedtls_ssl_optimize_checksum +#define ssl_own_cert mbedtls_ssl_own_cert +#define ssl_own_key mbedtls_ssl_own_key +#define ssl_parse_certificate mbedtls_ssl_parse_certificate +#define ssl_parse_change_cipher_spec mbedtls_ssl_parse_change_cipher_spec +#define ssl_parse_finished mbedtls_ssl_parse_finished +#define ssl_pk_alg_from_sig mbedtls_ssl_pk_alg_from_sig +#define ssl_pkcs11_decrypt mbedtls_ssl_pkcs11_decrypt +#define ssl_pkcs11_key_len mbedtls_ssl_pkcs11_key_len +#define ssl_pkcs11_sign mbedtls_ssl_pkcs11_sign +#define ssl_psk_derive_premaster mbedtls_ssl_psk_derive_premaster +#define ssl_read mbedtls_ssl_read +#define ssl_read_record mbedtls_ssl_read_record +#define ssl_read_version mbedtls_ssl_read_version +#define ssl_recv_flight_completed mbedtls_ssl_recv_flight_completed +#define ssl_renegotiate mbedtls_ssl_renegotiate +#define ssl_resend mbedtls_ssl_resend +#define ssl_reset_checksum mbedtls_ssl_reset_checksum +#define ssl_send_alert_message mbedtls_ssl_send_alert_message +#define ssl_send_fatal_handshake_failure mbedtls_ssl_send_fatal_handshake_failure +#define ssl_send_flight_completed mbedtls_ssl_send_flight_completed +#define ssl_session mbedtls_ssl_session +#define ssl_session_free mbedtls_ssl_session_free +#define ssl_session_init mbedtls_ssl_session_init +#define ssl_session_reset mbedtls_ssl_session_reset +#define ssl_set_alpn_protocols mbedtls_ssl_conf_alpn_protocols +#define ssl_set_arc4_support mbedtls_ssl_conf_arc4_support +#define ssl_set_authmode mbedtls_ssl_conf_authmode +#define ssl_set_bio mbedtls_ssl_set_bio +#define ssl_set_ca_chain mbedtls_ssl_conf_ca_chain +#define ssl_set_cbc_record_splitting mbedtls_ssl_conf_cbc_record_splitting +#define ssl_set_ciphersuites mbedtls_ssl_conf_ciphersuites +#define ssl_set_ciphersuites_for_version mbedtls_ssl_conf_ciphersuites_for_version +#define ssl_set_client_transport_id mbedtls_ssl_set_client_transport_id +#define ssl_set_curves mbedtls_ssl_conf_curves +#define ssl_set_dbg mbedtls_ssl_conf_dbg +#define ssl_set_dh_param mbedtls_ssl_conf_dh_param +#define ssl_set_dh_param_ctx mbedtls_ssl_conf_dh_param_ctx +#define ssl_set_dtls_anti_replay mbedtls_ssl_conf_dtls_anti_replay +#define ssl_set_dtls_badmac_limit mbedtls_ssl_conf_dtls_badmac_limit +#define ssl_set_dtls_cookies mbedtls_ssl_conf_dtls_cookies +#define ssl_set_encrypt_then_mac mbedtls_ssl_conf_encrypt_then_mac +#define ssl_set_endpoint mbedtls_ssl_conf_endpoint +#define ssl_set_extended_master_secret mbedtls_ssl_conf_extended_master_secret +#define ssl_set_fallback mbedtls_ssl_conf_fallback +#define ssl_set_handshake_timeout mbedtls_ssl_conf_handshake_timeout +#define ssl_set_hostname mbedtls_ssl_set_hostname +#define ssl_set_max_frag_len mbedtls_ssl_conf_max_frag_len +#define ssl_set_max_version mbedtls_ssl_conf_max_version +#define ssl_set_min_version mbedtls_ssl_conf_min_version +#define ssl_set_own_cert mbedtls_ssl_conf_own_cert +#define ssl_set_psk mbedtls_ssl_conf_psk +#define ssl_set_psk_cb mbedtls_ssl_conf_psk_cb +#define ssl_set_renegotiation mbedtls_ssl_conf_renegotiation +#define ssl_set_renegotiation_enforced mbedtls_ssl_conf_renegotiation_enforced +#define ssl_set_renegotiation_period mbedtls_ssl_conf_renegotiation_period +#define ssl_set_rng mbedtls_ssl_conf_rng +#define ssl_set_session mbedtls_ssl_set_session +#define ssl_set_session_cache mbedtls_ssl_conf_session_cache +#define ssl_set_session_tickets mbedtls_ssl_conf_session_tickets +#define ssl_set_sni mbedtls_ssl_conf_sni +#define ssl_set_transport mbedtls_ssl_conf_transport +#define ssl_set_truncated_hmac mbedtls_ssl_conf_truncated_hmac +#define ssl_set_verify mbedtls_ssl_conf_verify +#define ssl_sig_from_pk mbedtls_ssl_sig_from_pk +#define ssl_states mbedtls_ssl_states +#define ssl_transform mbedtls_ssl_transform +#define ssl_transform_free mbedtls_ssl_transform_free +#define ssl_write mbedtls_ssl_write +#define ssl_write_certificate mbedtls_ssl_write_certificate +#define ssl_write_change_cipher_spec mbedtls_ssl_write_change_cipher_spec +#define ssl_write_finished mbedtls_ssl_write_finished +#define ssl_write_record mbedtls_ssl_write_record +#define ssl_write_version mbedtls_ssl_write_version +#define supported_ciphers mbedtls_cipher_supported +#define t_sint mbedtls_mpi_sint +#define t_udbl mbedtls_t_udbl +#define t_uint mbedtls_mpi_uint +#define test_ca_crt mbedtls_test_ca_crt +#define test_ca_crt_ec mbedtls_test_ca_crt_ec +#define test_ca_crt_rsa mbedtls_test_ca_crt_rsa +#define test_ca_key mbedtls_test_ca_key +#define test_ca_key_ec mbedtls_test_ca_key_ec +#define test_ca_key_rsa mbedtls_test_ca_key_rsa +#define test_ca_list mbedtls_test_cas_pem +#define test_ca_pwd mbedtls_test_ca_pwd +#define test_ca_pwd_ec mbedtls_test_ca_pwd_ec +#define test_ca_pwd_rsa mbedtls_test_ca_pwd_rsa +#define test_cli_crt mbedtls_test_cli_crt +#define test_cli_crt_ec mbedtls_test_cli_crt_ec +#define test_cli_crt_rsa mbedtls_test_cli_crt_rsa +#define test_cli_key mbedtls_test_cli_key +#define test_cli_key_ec mbedtls_test_cli_key_ec +#define test_cli_key_rsa mbedtls_test_cli_key_rsa +#define test_srv_crt mbedtls_test_srv_crt +#define test_srv_crt_ec mbedtls_test_srv_crt_ec +#define test_srv_crt_rsa mbedtls_test_srv_crt_rsa +#define test_srv_key mbedtls_test_srv_key +#define test_srv_key_ec mbedtls_test_srv_key_ec +#define test_srv_key_rsa mbedtls_test_srv_key_rsa +#define threading_mutex_t mbedtls_threading_mutex_t +#define threading_set_alt mbedtls_threading_set_alt +#define timing_self_test mbedtls_timing_self_test +#define version_check_feature mbedtls_version_check_feature +#define version_get_number mbedtls_version_get_number +#define version_get_string mbedtls_version_get_string +#define version_get_string_full mbedtls_version_get_string_full +#define x509_bitstring mbedtls_x509_bitstring +#define x509_buf mbedtls_x509_buf +#define x509_crl mbedtls_x509_crl +#define x509_crl_entry mbedtls_x509_crl_entry +#define x509_crl_free mbedtls_x509_crl_free +#define x509_crl_info mbedtls_x509_crl_info +#define x509_crl_init mbedtls_x509_crl_init +#define x509_crl_parse mbedtls_x509_crl_parse +#define x509_crl_parse_der mbedtls_x509_crl_parse_der +#define x509_crl_parse_file mbedtls_x509_crl_parse_file +#define x509_crt mbedtls_x509_crt +#define x509_crt_check_extended_key_usage mbedtls_x509_crt_check_extended_key_usage +#define x509_crt_check_key_usage mbedtls_x509_crt_check_key_usage +#define x509_crt_free mbedtls_x509_crt_free +#define x509_crt_info mbedtls_x509_crt_info +#define x509_crt_init mbedtls_x509_crt_init +#define x509_crt_parse mbedtls_x509_crt_parse +#define x509_crt_parse_der mbedtls_x509_crt_parse_der +#define x509_crt_parse_file mbedtls_x509_crt_parse_file +#define x509_crt_parse_path mbedtls_x509_crt_parse_path +#define x509_crt_revoked mbedtls_x509_crt_is_revoked +#define x509_crt_verify mbedtls_x509_crt_verify +#define x509_csr mbedtls_x509_csr +#define x509_csr_free mbedtls_x509_csr_free +#define x509_csr_info mbedtls_x509_csr_info +#define x509_csr_init mbedtls_x509_csr_init +#define x509_csr_parse mbedtls_x509_csr_parse +#define x509_csr_parse_der mbedtls_x509_csr_parse_der +#define x509_csr_parse_file mbedtls_x509_csr_parse_file +#define x509_dn_gets mbedtls_x509_dn_gets +#define x509_get_alg mbedtls_x509_get_alg +#define x509_get_alg_null mbedtls_x509_get_alg_null +#define x509_get_ext mbedtls_x509_get_ext +#define x509_get_name mbedtls_x509_get_name +#define x509_get_rsassa_pss_params mbedtls_x509_get_rsassa_pss_params +#define x509_get_serial mbedtls_x509_get_serial +#define x509_get_sig mbedtls_x509_get_sig +#define x509_get_sig_alg mbedtls_x509_get_sig_alg +#define x509_get_time mbedtls_x509_get_time +#define x509_key_size_helper mbedtls_x509_key_size_helper +#define x509_name mbedtls_x509_name +#define x509_self_test mbedtls_x509_self_test +#define x509_sequence mbedtls_x509_sequence +#define x509_serial_gets mbedtls_x509_serial_gets +#define x509_set_extension mbedtls_x509_set_extension +#define x509_sig_alg_gets mbedtls_x509_sig_alg_gets +#define x509_string_to_names mbedtls_x509_string_to_names +#define x509_time mbedtls_x509_time +#define x509_time_expired mbedtls_x509_time_is_past +#define x509_time_future mbedtls_x509_time_is_future +#define x509_write_extensions mbedtls_x509_write_extensions +#define x509_write_names mbedtls_x509_write_names +#define x509_write_sig mbedtls_x509_write_sig +#define x509write_cert mbedtls_x509write_cert +#define x509write_crt_der mbedtls_x509write_crt_der +#define x509write_crt_free mbedtls_x509write_crt_free +#define x509write_crt_init mbedtls_x509write_crt_init +#define x509write_crt_pem mbedtls_x509write_crt_pem +#define x509write_crt_set_authority_key_identifier mbedtls_x509write_crt_set_authority_key_identifier +#define x509write_crt_set_basic_constraints mbedtls_x509write_crt_set_basic_constraints +#define x509write_crt_set_extension mbedtls_x509write_crt_set_extension +#define x509write_crt_set_issuer_key mbedtls_x509write_crt_set_issuer_key +#define x509write_crt_set_issuer_name mbedtls_x509write_crt_set_issuer_name +#define x509write_crt_set_key_usage mbedtls_x509write_crt_set_key_usage +#define x509write_crt_set_md_alg mbedtls_x509write_crt_set_md_alg +#define x509write_crt_set_ns_cert_type mbedtls_x509write_crt_set_ns_cert_type +#define x509write_crt_set_serial mbedtls_x509write_crt_set_serial +#define x509write_crt_set_subject_key mbedtls_x509write_crt_set_subject_key +#define x509write_crt_set_subject_key_identifier mbedtls_x509write_crt_set_subject_key_identifier +#define x509write_crt_set_subject_name mbedtls_x509write_crt_set_subject_name +#define x509write_crt_set_validity mbedtls_x509write_crt_set_validity +#define x509write_crt_set_version mbedtls_x509write_crt_set_version +#define x509write_csr mbedtls_x509write_csr +#define x509write_csr_der mbedtls_x509write_csr_der +#define x509write_csr_free mbedtls_x509write_csr_free +#define x509write_csr_init mbedtls_x509write_csr_init +#define x509write_csr_pem mbedtls_x509write_csr_pem +#define x509write_csr_set_extension mbedtls_x509write_csr_set_extension +#define x509write_csr_set_key mbedtls_x509write_csr_set_key +#define x509write_csr_set_key_usage mbedtls_x509write_csr_set_key_usage +#define x509write_csr_set_md_alg mbedtls_x509write_csr_set_md_alg +#define x509write_csr_set_ns_cert_type mbedtls_x509write_csr_set_ns_cert_type +#define x509write_csr_set_subject_name mbedtls_x509write_csr_set_subject_name +#define xtea_context mbedtls_xtea_context +#define xtea_crypt_cbc mbedtls_xtea_crypt_cbc +#define xtea_crypt_ecb mbedtls_xtea_crypt_ecb +#define xtea_free mbedtls_xtea_free +#define xtea_init mbedtls_xtea_init +#define xtea_self_test mbedtls_xtea_self_test +#define xtea_setup mbedtls_xtea_setup #endif /* compat-1.3.h */ #endif /* MBEDTLS_DEPRECATED_REMOVED */ diff --git a/nettls/nettls/config.h b/nettls/nettls/config.h index 9326f27346dce1ccbbe229787953c7867e2b5198..0fc9a17f5e47e71adec9567dab642734f540375b 100644 --- a/nettls/nettls/config.h +++ b/nettls/nettls/config.h @@ -83,7 +83,7 @@ * * Comment to disable the use of assembly code. */ -//#define MBEDTLS_HAVE_ASM +// #define MBEDTLS_HAVE_ASM /** * \def MBEDTLS_NO_UDBL_DIVISION @@ -111,7 +111,7 @@ * example, if double-width division is implemented in software, disabling * it can reduce code size in some embedded targets. */ -//#define MBEDTLS_NO_UDBL_DIVISION +// #define MBEDTLS_NO_UDBL_DIVISION /** * \def MBEDTLS_NO_64BIT_MULTIPLICATION @@ -133,7 +133,7 @@ * Note that depending on the compiler, this may decrease performance compared * to using the library function provided by the toolchain. */ -//#define MBEDTLS_NO_64BIT_MULTIPLICATION +// #define MBEDTLS_NO_64BIT_MULTIPLICATION /** * \def MBEDTLS_HAVE_SSE2 @@ -142,7 +142,7 @@ * * Uncomment if the CPU supports SSE2 (IA-32 specific). */ -//#define MBEDTLS_HAVE_SSE2 +// #define MBEDTLS_HAVE_SSE2 /** * \def MBEDTLS_HAVE_TIME @@ -202,7 +202,7 @@ * * Enable this layer to allow use of alternative memory allocators. */ -//#define MBEDTLS_PLATFORM_MEMORY +// #define MBEDTLS_PLATFORM_MEMORY /** * \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS @@ -221,7 +221,7 @@ * Uncomment to prevent default assignment of standard functions in the * platform layer. */ -//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +// #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS /** * \def MBEDTLS_PLATFORM_EXIT_ALT @@ -246,13 +246,13 @@ * Uncomment a macro to enable alternate implementation of specific base * platform function */ -//#define MBEDTLS_PLATFORM_EXIT_ALT -//#define MBEDTLS_PLATFORM_TIME_ALT -//#define MBEDTLS_PLATFORM_FPRINTF_ALT -//#define MBEDTLS_PLATFORM_PRINTF_ALT -//#define MBEDTLS_PLATFORM_SNPRINTF_ALT -//#define MBEDTLS_PLATFORM_NV_SEED_ALT -//#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT +// #define MBEDTLS_PLATFORM_EXIT_ALT +// #define MBEDTLS_PLATFORM_TIME_ALT +// #define MBEDTLS_PLATFORM_FPRINTF_ALT +// #define MBEDTLS_PLATFORM_PRINTF_ALT +// #define MBEDTLS_PLATFORM_SNPRINTF_ALT +// #define MBEDTLS_PLATFORM_NV_SEED_ALT +// #define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT /** * \def MBEDTLS_DEPRECATED_WARNING @@ -267,7 +267,7 @@ * * Uncomment to get warnings on using deprecated functions. */ -//#define MBEDTLS_DEPRECATED_WARNING +// #define MBEDTLS_DEPRECATED_WARNING /** * \def MBEDTLS_DEPRECATED_REMOVED @@ -279,7 +279,7 @@ * * Uncomment to get errors on using deprecated functions. */ -//#define MBEDTLS_DEPRECATED_REMOVED +// #define MBEDTLS_DEPRECATED_REMOVED /** * \def MBEDTLS_CHECK_PARAMS @@ -331,7 +331,7 @@ * * Uncomment to enable validation of application-controlled parameters. */ -//#define MBEDTLS_CHECK_PARAMS +// #define MBEDTLS_CHECK_PARAMS /** * \def MBEDTLS_CHECK_PARAMS_ASSERT @@ -345,7 +345,7 @@ * * Uncomment to allow MBEDTLS_PARAM_FAILED() to call `assert`. */ -//#define MBEDTLS_CHECK_PARAMS_ASSERT +// #define MBEDTLS_CHECK_PARAMS_ASSERT /* \} name SECTION: System support */ @@ -368,7 +368,7 @@ * You will need to provide a header "timing_alt.h" and an implementation at * compile time. */ -//#define MBEDTLS_TIMING_ALT +// #define MBEDTLS_TIMING_ALT /** * \def MBEDTLS_AES_ALT @@ -395,30 +395,30 @@ * digests and ciphers instead. * */ -//#define MBEDTLS_AES_ALT -//#define MBEDTLS_ARC4_ALT -//#define MBEDTLS_ARIA_ALT -//#define MBEDTLS_BLOWFISH_ALT -//#define MBEDTLS_CAMELLIA_ALT -//#define MBEDTLS_CCM_ALT -//#define MBEDTLS_CHACHA20_ALT -//#define MBEDTLS_CHACHAPOLY_ALT -//#define MBEDTLS_CMAC_ALT -//#define MBEDTLS_DES_ALT -//#define MBEDTLS_DHM_ALT -//#define MBEDTLS_ECJPAKE_ALT -//#define MBEDTLS_GCM_ALT -//#define MBEDTLS_NIST_KW_ALT -//#define MBEDTLS_MD2_ALT -//#define MBEDTLS_MD4_ALT -//#define MBEDTLS_MD5_ALT -//#define MBEDTLS_POLY1305_ALT -//#define MBEDTLS_RIPEMD160_ALT -//#define MBEDTLS_RSA_ALT -//#define MBEDTLS_SHA1_ALT -//#define MBEDTLS_SHA256_ALT -//#define MBEDTLS_SHA512_ALT -//#define MBEDTLS_XTEA_ALT +// #define MBEDTLS_AES_ALT +// #define MBEDTLS_ARC4_ALT +// #define MBEDTLS_ARIA_ALT +// #define MBEDTLS_BLOWFISH_ALT +// #define MBEDTLS_CAMELLIA_ALT +// #define MBEDTLS_CCM_ALT +// #define MBEDTLS_CHACHA20_ALT +// #define MBEDTLS_CHACHAPOLY_ALT +// #define MBEDTLS_CMAC_ALT +// #define MBEDTLS_DES_ALT +// #define MBEDTLS_DHM_ALT +// #define MBEDTLS_ECJPAKE_ALT +// #define MBEDTLS_GCM_ALT +// #define MBEDTLS_NIST_KW_ALT +// #define MBEDTLS_MD2_ALT +// #define MBEDTLS_MD4_ALT +// #define MBEDTLS_MD5_ALT +// #define MBEDTLS_POLY1305_ALT +// #define MBEDTLS_RIPEMD160_ALT +// #define MBEDTLS_RSA_ALT +// #define MBEDTLS_SHA1_ALT +// #define MBEDTLS_SHA256_ALT +// #define MBEDTLS_SHA512_ALT +// #define MBEDTLS_XTEA_ALT /* * When replacing the elliptic curve module, pleace consider, that it is @@ -429,7 +429,7 @@ * macros as described above. The only difference is that you have to make sure * that you provide functionality for both .c files. */ -//#define MBEDTLS_ECP_ALT +// #define MBEDTLS_ECP_ALT /** * \def MBEDTLS_MD2_PROCESS_ALT @@ -476,25 +476,25 @@ * desirable). * */ -//#define MBEDTLS_MD2_PROCESS_ALT -//#define MBEDTLS_MD4_PROCESS_ALT -//#define MBEDTLS_MD5_PROCESS_ALT -//#define MBEDTLS_RIPEMD160_PROCESS_ALT -//#define MBEDTLS_SHA1_PROCESS_ALT -//#define MBEDTLS_SHA256_PROCESS_ALT -//#define MBEDTLS_SHA512_PROCESS_ALT -//#define MBEDTLS_DES_SETKEY_ALT -//#define MBEDTLS_DES_CRYPT_ECB_ALT -//#define MBEDTLS_DES3_CRYPT_ECB_ALT -//#define MBEDTLS_AES_SETKEY_ENC_ALT -//#define MBEDTLS_AES_SETKEY_DEC_ALT -//#define MBEDTLS_AES_ENCRYPT_ALT -//#define MBEDTLS_AES_DECRYPT_ALT -//#define MBEDTLS_ECDH_GEN_PUBLIC_ALT -//#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT -//#define MBEDTLS_ECDSA_VERIFY_ALT -//#define MBEDTLS_ECDSA_SIGN_ALT -//#define MBEDTLS_ECDSA_GENKEY_ALT +// #define MBEDTLS_MD2_PROCESS_ALT +// #define MBEDTLS_MD4_PROCESS_ALT +// #define MBEDTLS_MD5_PROCESS_ALT +// #define MBEDTLS_RIPEMD160_PROCESS_ALT +// #define MBEDTLS_SHA1_PROCESS_ALT +// #define MBEDTLS_SHA256_PROCESS_ALT +// #define MBEDTLS_SHA512_PROCESS_ALT +// #define MBEDTLS_DES_SETKEY_ALT +// #define MBEDTLS_DES_CRYPT_ECB_ALT +// #define MBEDTLS_DES3_CRYPT_ECB_ALT +// #define MBEDTLS_AES_SETKEY_ENC_ALT +// #define MBEDTLS_AES_SETKEY_DEC_ALT +// #define MBEDTLS_AES_ENCRYPT_ALT +// #define MBEDTLS_AES_DECRYPT_ALT +// #define MBEDTLS_ECDH_GEN_PUBLIC_ALT +// #define MBEDTLS_ECDH_COMPUTE_SHARED_ALT +// #define MBEDTLS_ECDSA_VERIFY_ALT +// #define MBEDTLS_ECDSA_SIGN_ALT +// #define MBEDTLS_ECDSA_GENKEY_ALT /** * \def MBEDTLS_ECP_INTERNAL_ALT @@ -537,17 +537,17 @@ * function. */ /* Required for all the functions in this section */ -//#define MBEDTLS_ECP_INTERNAL_ALT +// #define MBEDTLS_ECP_INTERNAL_ALT /* Support for Weierstrass curves with Jacobi representation */ -//#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT -//#define MBEDTLS_ECP_ADD_MIXED_ALT -//#define MBEDTLS_ECP_DOUBLE_JAC_ALT -//#define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT -//#define MBEDTLS_ECP_NORMALIZE_JAC_ALT +// #define MBEDTLS_ECP_RANDOMIZE_JAC_ALT +// #define MBEDTLS_ECP_ADD_MIXED_ALT +// #define MBEDTLS_ECP_DOUBLE_JAC_ALT +// #define MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT +// #define MBEDTLS_ECP_NORMALIZE_JAC_ALT /* Support for curves with Montgomery arithmetic */ -//#define MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT -//#define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT -//#define MBEDTLS_ECP_NORMALIZE_MXZ_ALT +// #define MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT +// #define MBEDTLS_ECP_RANDOMIZE_MXZ_ALT +// #define MBEDTLS_ECP_NORMALIZE_MXZ_ALT /** * \def MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN @@ -564,7 +564,7 @@ * * Uncomment to enable testing of the constant-flow nature of selected code. */ -//#define MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN +// #define MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN /** * \def MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND @@ -583,7 +583,7 @@ * * Uncomment to enable testing of the constant-flow nature of selected code. */ -//#define MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND +// #define MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND /** * \def MBEDTLS_TEST_NULL_ENTROPY @@ -600,7 +600,7 @@ * Requires MBEDTLS_ENTROPY_C, MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES * */ -//#define MBEDTLS_TEST_NULL_ENTROPY +// #define MBEDTLS_TEST_NULL_ENTROPY /** * \def MBEDTLS_ENTROPY_HARDWARE_ALT @@ -613,7 +613,7 @@ * * Uncomment to use your own hardware entropy collector. */ -//#define MBEDTLS_ENTROPY_HARDWARE_ALT +// #define MBEDTLS_ENTROPY_HARDWARE_ALT /** * \def MBEDTLS_AES_ROM_TABLES @@ -633,7 +633,7 @@ * This option is independent of \c MBEDTLS_AES_FEWER_TABLES. * */ -//#define MBEDTLS_AES_ROM_TABLES +// #define MBEDTLS_AES_ROM_TABLES /** * \def MBEDTLS_AES_FEWER_TABLES @@ -655,7 +655,7 @@ * This option is independent of \c MBEDTLS_AES_ROM_TABLES. * */ -//#define MBEDTLS_AES_FEWER_TABLES +// #define MBEDTLS_AES_FEWER_TABLES /** * \def MBEDTLS_CAMELLIA_SMALL_MEMORY @@ -664,7 +664,7 @@ * * Uncomment this macro to use less memory for Camellia. */ -//#define MBEDTLS_CAMELLIA_SMALL_MEMORY +// #define MBEDTLS_CAMELLIA_SMALL_MEMORY /** * \def MBEDTLS_CIPHER_MODE_CBC @@ -732,7 +732,7 @@ * * Uncomment this macro to enable the NULL cipher and ciphersuites */ -//#define MBEDTLS_CIPHER_NULL_CIPHER +// #define MBEDTLS_CIPHER_NULL_CIPHER /** * \def MBEDTLS_CIPHER_PADDING_PKCS7 @@ -755,7 +755,7 @@ * Uncomment this macro to use a 128-bit key in the CTR_DRBG module. * By default, CTR_DRBG uses a 256-bit key. */ -//#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY +// #define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY /** * \def MBEDTLS_ENABLE_WEAK_CIPHERSUITES @@ -773,7 +773,7 @@ * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers instead. */ -//#define MBEDTLS_ENABLE_WEAK_CIPHERSUITES +// #define MBEDTLS_ENABLE_WEAK_CIPHERSUITES /** * \def MBEDTLS_REMOVE_ARC4_CIPHERSUITES @@ -861,7 +861,7 @@ * * Uncomment this macro to disable some counter-measures in ECP. */ -//#define MBEDTLS_ECP_NO_INTERNAL_RNG +// #define MBEDTLS_ECP_NO_INTERNAL_RNG /** * \def MBEDTLS_ECP_RESTARTABLE @@ -885,7 +885,7 @@ * elliptic curve functionality. It is incompatible with * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT and MBEDTLS_ECDSA_XXX_ALT. */ -//#define MBEDTLS_ECP_RESTARTABLE +// #define MBEDTLS_ECP_RESTARTABLE /** * \def MBEDTLS_ECDSA_DETERMINISTIC @@ -1174,7 +1174,7 @@ * enabled as well): * MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 */ -//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED +// #define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED /** * \def MBEDTLS_PK_PARSE_EC_EXTENDED @@ -1232,7 +1232,7 @@ * * Uncomment this macro to prevent loading of default entropy functions. */ -//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES +// #define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES /** * \def MBEDTLS_NO_PLATFORM_ENTROPY @@ -1243,7 +1243,7 @@ * * Uncomment this macro to disable the built-in platform entropy functions. */ -//#define MBEDTLS_NO_PLATFORM_ENTROPY +// #define MBEDTLS_NO_PLATFORM_ENTROPY /** * \def MBEDTLS_ENTROPY_FORCE_SHA256 @@ -1259,7 +1259,7 @@ * This option is only useful if both MBEDTLS_SHA256_C and * MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used. */ -//#define MBEDTLS_ENTROPY_FORCE_SHA256 +// #define MBEDTLS_ENTROPY_FORCE_SHA256 /** * \def MBEDTLS_ENTROPY_NV_SEED @@ -1287,7 +1287,7 @@ * \note The entropy collector will write to the seed file before entropy is * given to an external source, to update it. */ -//#define MBEDTLS_ENTROPY_NV_SEED +// #define MBEDTLS_ENTROPY_NV_SEED /** * \def MBEDTLS_MEMORY_DEBUG @@ -1300,7 +1300,7 @@ * * Uncomment this macro to let the buffer allocator print out error messages. */ -//#define MBEDTLS_MEMORY_DEBUG +// #define MBEDTLS_MEMORY_DEBUG /** * \def MBEDTLS_MEMORY_BACKTRACE @@ -1312,7 +1312,7 @@ * * Uncomment this macro to include backtrace information */ -//#define MBEDTLS_MEMORY_BACKTRACE +// #define MBEDTLS_MEMORY_BACKTRACE /** * \def MBEDTLS_PK_RSA_ALT_SUPPORT @@ -1354,7 +1354,7 @@ * Uncomment this macro to disable the use of CRT in RSA. * */ -//#define MBEDTLS_RSA_NO_CRT +// #define MBEDTLS_RSA_NO_CRT /** * \def MBEDTLS_SELF_TEST @@ -1377,7 +1377,7 @@ * * Uncomment to enable the smaller implementation of SHA256. */ -//#define MBEDTLS_SHA256_SMALLER +// #define MBEDTLS_SHA256_SMALLER /** * \def MBEDTLS_SSL_ALL_ALERT_MESSAGES @@ -1418,7 +1418,7 @@ * a timing side-channel. * */ -//#define MBEDTLS_SSL_DEBUG_ALL +// #define MBEDTLS_SSL_DEBUG_ALL /** \def MBEDTLS_SSL_ENCRYPT_THEN_MAC * @@ -1481,7 +1481,7 @@ * * Uncomment this macro to enable hooking functions. */ -//#define MBEDTLS_SSL_HW_RECORD_ACCEL +// #define MBEDTLS_SSL_HW_RECORD_ACCEL /** * \def MBEDTLS_SSL_CBC_RECORD_SPLITTING @@ -1525,7 +1525,7 @@ * * Uncomment this macro to enable support for SSLv2 Client Hello messages. */ -//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO +// #define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO /** * \def MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE @@ -1535,7 +1535,7 @@ * * Uncomment this macro to respect client's ciphersuite order */ -//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE +// #define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE /** * \def MBEDTLS_SSL_MAX_FRAGMENT_LENGTH @@ -1744,7 +1744,7 @@ * * Requires: MBEDTLS_SSL_TRUNCATED_HMAC */ -//#define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT +// #define MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT /** * \def MBEDTLS_TEST_HOOKS @@ -1761,7 +1761,7 @@ * * Uncomment to enable invasive tests. */ -//#define MBEDTLS_TEST_HOOKS +// #define MBEDTLS_TEST_HOOKS /** * \def MBEDTLS_THREADING_ALT @@ -1772,7 +1772,7 @@ * * Uncomment this to allow your own alternate threading implementation. */ -//#define MBEDTLS_THREADING_ALT +// #define MBEDTLS_THREADING_ALT /** * \def MBEDTLS_THREADING_PTHREAD @@ -1783,7 +1783,7 @@ * * Uncomment this to enable pthread mutexes. */ -//#define MBEDTLS_THREADING_PTHREAD +// #define MBEDTLS_THREADING_PTHREAD /** * \def MBEDTLS_VERSION_FEATURES @@ -1806,7 +1806,7 @@ * * Uncomment to prevent an error. */ -//#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 +// #define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 /** * \def MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION @@ -1818,7 +1818,7 @@ * * Uncomment to prevent an error. */ -//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION +// #define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION /** * \def MBEDTLS_X509_CHECK_KEY_USAGE @@ -1880,7 +1880,7 @@ * * Uncomment to enable use of ZLIB */ -//#define MBEDTLS_ZLIB_SUPPORT +// #define MBEDTLS_ZLIB_SUPPORT /* \} name SECTION: mbed TLS feature support */ /** @@ -1902,7 +1902,7 @@ * * This modules adds support for the AES-NI instructions on x86-64 */ -//#define MBEDTLS_AESNI_C +// #define MBEDTLS_AESNI_C /** * \def MBEDTLS_AES_C @@ -2178,7 +2178,7 @@ * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 */ -//#define MBEDTLS_ARIA_C +// #define MBEDTLS_ARIA_C /** * \def MBEDTLS_CCM_C @@ -2249,7 +2249,7 @@ * Requires: MBEDTLS_AES_C or MBEDTLS_DES_C * */ -//#define MBEDTLS_CMAC_C +// #define MBEDTLS_CMAC_C /** * \def MBEDTLS_CTR_DRBG_C @@ -2383,7 +2383,7 @@ * * Requires: MBEDTLS_ECP_C, MBEDTLS_MD_C */ -//#define MBEDTLS_ECJPAKE_C +// #define MBEDTLS_ECJPAKE_C /** * \def MBEDTLS_ECP_C @@ -2460,7 +2460,7 @@ * * Uncomment to enable the HAVEGE random generator. */ -//#define MBEDTLS_HAVEGE_C +// #define MBEDTLS_HAVEGE_C /** * \def MBEDTLS_HKDF_C @@ -2502,7 +2502,7 @@ * * Requires: MBEDTLS_AES_C and MBEDTLS_CIPHER_C */ -//#define MBEDTLS_NIST_KW_C +// #define MBEDTLS_NIST_KW_C /** * \def MBEDTLS_MD_C @@ -2531,7 +2531,7 @@ * it, and considering stronger message digests instead. * */ -//#define MBEDTLS_MD2_C +// #define MBEDTLS_MD2_C /** * \def MBEDTLS_MD4_C @@ -2548,7 +2548,7 @@ * it, and considering stronger message digests instead. * */ -//#define MBEDTLS_MD4_C +// #define MBEDTLS_MD4_C /** * \def MBEDTLS_MD5_C @@ -2586,7 +2586,7 @@ * * Enable this module to enable the buffer memory allocator. */ -//#define MBEDTLS_MEMORY_BUFFER_ALLOC_C +// #define MBEDTLS_MEMORY_BUFFER_ALLOC_C /** * \def MBEDTLS_NET_C @@ -2642,7 +2642,7 @@ * * This modules adds support for the VIA PadLock on x86. */ -//#define MBEDTLS_PADLOCK_C +// #define MBEDTLS_PADLOCK_C /** * \def MBEDTLS_PEM_PARSE_C @@ -2749,7 +2749,7 @@ * This module enables SSL/TLS PKCS #11 smartcard support. * Requires the presence of the PKCS#11 helper library (libpkcs11-helper) */ -//#define MBEDTLS_PKCS11_C +// #define MBEDTLS_PKCS11_C /** * \def MBEDTLS_PKCS12_C @@ -2979,7 +2979,7 @@ * * Enable this layer to allow use of mutexes within mbed TLS */ -//#define MBEDTLS_THREADING_C +// #define MBEDTLS_THREADING_C /** * \def MBEDTLS_TIMING_C @@ -3002,7 +3002,7 @@ * * This module is used by the HAVEGE random number generator. */ -//#define MBEDTLS_TIMING_C +// #define MBEDTLS_TIMING_C /** * \def MBEDTLS_VERSION_C @@ -3143,82 +3143,82 @@ */ /* MPI / BIGNUM options */ -//#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum window size used. */ -//#define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable -// MPIs. */ +// #define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum window size used. */ +// #define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable +// MPIs. */ /* CTR_DRBG options */ -//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per -// seed by default (48 with SHA-512, 32 with SHA-256) */ #define -// MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed -// by default */ #define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number -// of additional input bytes */ #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< -// Maximum number of requested bytes per call */ #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT -// 384 /**< Maximum size of (re)seed buffer */ +// #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per +// seed by default (48 with SHA-512, 32 with SHA-256) */ #define +// MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed +// by default */ #define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number +// of additional input bytes */ #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< +// Maximum number of requested bytes per call */ #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT +// 384 /**< Maximum size of (re)seed buffer */ /* HMAC_DRBG options */ -//#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is -// performed by default */ #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum -// number of additional input bytes */ #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 +// #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is +// performed by default */ #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256 /**< Maximum +// number of additional input bytes */ #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024 ///**< Maximum number of requested bytes per call */ #define // MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ /* ECP options */ -//#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ -//#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */ -//#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */ +// #define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ +// #define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */ +// #define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */ /* Entropy options */ -//#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources -// supported */ #define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount -// requested from entropy sources */ #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 +// #define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources +// supported */ #define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount +// requested from entropy sources */ #define MBEDTLS_ENTROPY_MIN_HARDWARE 32 ///**< Default minimum number of bytes required for the hardware entropy source // mbedtls_hardware_poll() before entropy is released */ /* Memory buffer allocator options */ -//#define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ +// #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ /* Platform options */ -//#define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if -// MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */ -//#define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be -// undefined */ #define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, -// can be undefined */ #define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit -// to use, can be undefined */ #define MBEDTLS_PLATFORM_STD_TIME time /**< -// Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ #define -// MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined +// #define MBEDTLS_PLATFORM_STD_MEM_HDR /**< Header to include if +// MBEDTLS_PLATFORM_NO_STD_FUNCTIONS is defined. Don't define if no header is needed. */ +// #define MBEDTLS_PLATFORM_STD_CALLOC calloc /**< Default allocator to use, can be +// undefined */ #define MBEDTLS_PLATFORM_STD_FREE free /**< Default free to use, +// can be undefined */ #define MBEDTLS_PLATFORM_STD_EXIT exit /**< Default exit +// to use, can be undefined */ #define MBEDTLS_PLATFORM_STD_TIME time /**< +// Default time to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ #define +// MBEDTLS_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use, can be undefined //*/ #define MBEDTLS_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be -// undefined */ +// undefined */ /* Note: your snprintf must correctly zero-terminate the buffer! */ -//#define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be -// undefined */ #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value -// to use, can be undefined */ #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< -// Default exit value to use, can be undefined */ #define MBEDTLS_PLATFORM_STD_NV_SEED_READ -// mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be -// undefined */ #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE -// mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be -// undefined */ #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" /**< Seed file to -// read/write with default implementation */ +// #define MBEDTLS_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be +// undefined */ #define MBEDTLS_PLATFORM_STD_EXIT_SUCCESS 0 /**< Default exit value +// to use, can be undefined */ #define MBEDTLS_PLATFORM_STD_EXIT_FAILURE 1 /**< +// Default exit value to use, can be undefined */ #define MBEDTLS_PLATFORM_STD_NV_SEED_READ +// mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be +// undefined */ #define MBEDTLS_PLATFORM_STD_NV_SEED_WRITE +// mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be +// undefined */ #define MBEDTLS_PLATFORM_STD_NV_SEED_FILE "seedfile" /**< Seed file to +// read/write with default implementation */ /* To Use Function Macros MBEDTLS_PLATFORM_C must be enabled */ /* MBEDTLS_PLATFORM_XXX_MACRO and MBEDTLS_PLATFORM_XXX_ALT cannot both be defined */ -//#define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, -// can be undefined */ #define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default -// free macro to use, can be undefined */ #define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< -// Default exit macro to use, can be undefined */ #define MBEDTLS_PLATFORM_TIME_MACRO time +// #define MBEDTLS_PLATFORM_CALLOC_MACRO calloc /**< Default allocator macro to use, +// can be undefined */ #define MBEDTLS_PLATFORM_FREE_MACRO free /**< Default +// free macro to use, can be undefined */ #define MBEDTLS_PLATFORM_EXIT_MACRO exit /**< +// Default exit macro to use, can be undefined */ #define MBEDTLS_PLATFORM_TIME_MACRO time ///**< Default time macro to use, can be undefined. MBEDTLS_HAVE_TIME must be enabled */ -//#define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, -// can be undefined. MBEDTLS_HAVE_TIME must be enabled */ #define -// MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be -// undefined */ #define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf -// macro to use, can be undefined */ +// #define MBEDTLS_PLATFORM_TIME_TYPE_MACRO time_t /**< Default time macro to use, +// can be undefined. MBEDTLS_HAVE_TIME must be enabled */ #define +// MBEDTLS_PLATFORM_FPRINTF_MACRO fprintf /**< Default fprintf macro to use, can be +// undefined */ #define MBEDTLS_PLATFORM_PRINTF_MACRO printf /**< Default printf +// macro to use, can be undefined */ /* Note: your snprintf must correctly zero-terminate the buffer! */ -//#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, -// can be undefined */ #define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO -// mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be -// undefined */ #define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO -// mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be -// undefined */ +// #define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf /**< Default snprintf macro to use, +// can be undefined */ #define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO +// mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be +// undefined */ #define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO +// mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be +// undefined */ /** * \brief This macro is invoked by the library when an invalid parameter @@ -3254,11 +3254,11 @@ * * \param cond The expression that should evaluate to true, but doesn't. */ -//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond ) +// #define MBEDTLS_PARAM_FAILED( cond ) assert( cond ) /* SSL Cache options */ -//#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */ -//#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */ +// #define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */ +// #define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */ /* SSL options */ @@ -3286,7 +3286,7 @@ * Uncomment to set the maximum plaintext size of both * incoming and outgoing I/O buffers. */ -//#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 +// #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /** \def MBEDTLS_SSL_IN_CONTENT_LEN * @@ -3311,7 +3311,7 @@ * Uncomment to set the maximum plaintext size of the incoming I/O buffer * independently of the outgoing I/O buffer. */ -//#define MBEDTLS_SSL_IN_CONTENT_LEN 16384 +// #define MBEDTLS_SSL_IN_CONTENT_LEN 16384 /** \def MBEDTLS_SSL_OUT_CONTENT_LEN * @@ -3335,7 +3335,7 @@ * Uncomment to set the maximum plaintext size of the outgoing I/O buffer * independently of the incoming I/O buffer. */ -//#define MBEDTLS_SSL_OUT_CONTENT_LEN 16384 +// #define MBEDTLS_SSL_OUT_CONTENT_LEN 16384 /** \def MBEDTLS_SSL_DTLS_MAX_BUFFERING * @@ -3352,11 +3352,11 @@ * while buffering multiple smaller handshake messages. * */ -//#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768 +// #define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768 -//#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets +// #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets //(if enabled) */ #define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS -// pre-shared keys, in bytes (default 256 bits) */ #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 +// pre-shared keys, in bytes (default 256 bits) */ #define MBEDTLS_SSL_COOKIE_TIMEOUT 60 ///**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of // cookies issued */ @@ -3372,13 +3372,13 @@ * * The value below is only an example, not the default. */ -//#define MBEDTLS_SSL_CIPHERSUITES -// MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 +// #define MBEDTLS_SSL_CIPHERSUITES +// MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 /* X509 options */ -//#define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs -// in a verification chain. */ #define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum -// length of a path/filename string in bytes including the null terminator character +// #define MBEDTLS_X509_MAX_INTERMEDIATE_CA 8 /**< Maximum number of intermediate CAs +// in a verification chain. */ #define MBEDTLS_X509_MAX_FILE_PATH_LEN 512 /**< Maximum +// length of a path/filename string in bytes including the null terminator character //('\0'). */ /** @@ -3430,7 +3430,7 @@ * C standards (e.g using memset_s() in C11) or calling a secure memset() from * their system (e.g explicit_bzero() in BSD). */ -//#define MBEDTLS_PLATFORM_ZEROIZE_ALT +// #define MBEDTLS_PLATFORM_ZEROIZE_ALT /** * Uncomment the macro to let Mbed TLS use your alternate implementation of @@ -3449,7 +3449,7 @@ * unconditionally use the implementation for mbedtls_platform_gmtime_r() * supplied at compile time. */ -//#define MBEDTLS_PLATFORM_GMTIME_R_ALT +// #define MBEDTLS_PLATFORM_GMTIME_R_ALT /* \} name SECTION: Customisation configuration options */ diff --git a/nettls/nettls/ctr_drbg.h b/nettls/nettls/ctr_drbg.h index 6acdade252b22dba1e2c7df389036da02b7788d4..fad4856a5b813766fdb821aa69dc365531280b25 100644 --- a/nettls/nettls/ctr_drbg.h +++ b/nettls/nettls/ctr_drbg.h @@ -322,11 +322,7 @@ void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context* ctx); * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure. */ int mbedtls_ctr_drbg_seed( - mbedtls_ctr_drbg_context* ctx, - int (*f_entropy)(void*, unsigned char*, size_t), - void* p_entropy, - const unsigned char* custom, - size_t len); + mbedtls_ctr_drbg_context* ctx, int (*f_entropy)(void*, unsigned char*, size_t), void* p_entropy, const unsigned char* custom, size_t len); /** * \brief This function resets CTR_DRBG context to the state immediately @@ -464,8 +460,7 @@ int mbedtls_ctr_drbg_update_ret(mbedtls_ctr_drbg_context* ctx, const unsigned ch * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure. */ -int mbedtls_ctr_drbg_random_with_add( - void* p_rng, unsigned char* output, size_t output_len, const unsigned char* additional, size_t add_len); +int mbedtls_ctr_drbg_random_with_add(void* p_rng, unsigned char* output, size_t output_len, const unsigned char* additional, size_t add_len); /** * \brief This function uses CTR_DRBG to generate random data. @@ -514,8 +509,7 @@ int mbedtls_ctr_drbg_random(void* p_rng, unsigned char* output, size_t output_le * \param additional The data to update the state with. * \param add_len Length of \p additional data. */ -MBEDTLS_DEPRECATED void - mbedtls_ctr_drbg_update(mbedtls_ctr_drbg_context* ctx, const unsigned char* additional, size_t add_len); +MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update(mbedtls_ctr_drbg_context* ctx, const unsigned char* additional, size_t add_len); #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ @@ -563,8 +557,7 @@ int mbedtls_ctr_drbg_self_test(int verbose); #endif /* MBEDTLS_SELF_TEST */ /* Internal functions (do not call directly) */ -int mbedtls_ctr_drbg_seed_entropy_len( - mbedtls_ctr_drbg_context*, int (*)(void*, unsigned char*, size_t), void*, const unsigned char*, size_t, size_t); +int mbedtls_ctr_drbg_seed_entropy_len(mbedtls_ctr_drbg_context*, int (*)(void*, unsigned char*, size_t), void*, const unsigned char*, size_t, size_t); #ifdef __cplusplus } diff --git a/nettls/nettls/debug.h b/nettls/nettls/debug.h index 3a1b7e7e6f7ff4f533e43d6a9e90694037d75610..559e87282a63b955b98ab3511fff669d561ff2aa 100644 --- a/nettls/nettls/debug.h +++ b/nettls/nettls/debug.h @@ -65,13 +65,11 @@ #define MBEDTLS_DEBUG_STRIP_PARENS(...) __VA_ARGS__ -#define MBEDTLS_SSL_DEBUG_MSG(level, args) \ - mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__, MBEDTLS_DEBUG_STRIP_PARENS args) +#define MBEDTLS_SSL_DEBUG_MSG(level, args) mbedtls_debug_print_msg(ssl, level, __FILE__, __LINE__, MBEDTLS_DEBUG_STRIP_PARENS args) #define MBEDTLS_SSL_DEBUG_RET(level, text, ret) mbedtls_debug_print_ret(ssl, level, __FILE__, __LINE__, text, ret) -#define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) \ - mbedtls_debug_print_buf(ssl, level, __FILE__, __LINE__, text, buf, len) +#define MBEDTLS_SSL_DEBUG_BUF(level, text, buf, len) mbedtls_debug_print_buf(ssl, level, __FILE__, __LINE__, text, buf, len) #if defined(MBEDTLS_BIGNUM_C) #define MBEDTLS_SSL_DEBUG_MPI(level, text, X) mbedtls_debug_print_mpi(ssl, level, __FILE__, __LINE__, text, X) @@ -151,8 +149,7 @@ void mbedtls_debug_set_threshold(int threshold); * \attention This function is intended for INTERNAL usage within the * library only. */ -void mbedtls_debug_print_msg( - const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* format, ...); +void mbedtls_debug_print_msg(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* format, ...); /** * \brief Print the return value of a function to the debug output. This @@ -169,8 +166,7 @@ void mbedtls_debug_print_msg( * \attention This function is intended for INTERNAL usage within the * library only. */ -void mbedtls_debug_print_ret( - const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, int ret); +void mbedtls_debug_print_ret(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, int ret); /** * \brief Output a buffer of size len bytes to the debug output. This function @@ -190,13 +186,7 @@ void mbedtls_debug_print_ret( * library only. */ void mbedtls_debug_print_buf( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const char* text, - const unsigned char* buf, - size_t len); + const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const unsigned char* buf, size_t len); #if defined(MBEDTLS_BIGNUM_C) /** @@ -215,8 +205,7 @@ void mbedtls_debug_print_buf( * \attention This function is intended for INTERNAL usage within the * library only. */ -void mbedtls_debug_print_mpi( - const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_mpi* X); +void mbedtls_debug_print_mpi(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_mpi* X); #endif #if defined(MBEDTLS_ECP_C) @@ -236,13 +225,7 @@ void mbedtls_debug_print_mpi( * \attention This function is intended for INTERNAL usage within the * library only. */ -void mbedtls_debug_print_ecp( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const char* text, - const mbedtls_ecp_point* X); +void mbedtls_debug_print_ecp(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_ecp_point* X); #endif #if defined(MBEDTLS_X509_CRT_PARSE_C) @@ -261,13 +244,7 @@ void mbedtls_debug_print_ecp( * \attention This function is intended for INTERNAL usage within the * library only. */ -void mbedtls_debug_print_crt( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const char* text, - const mbedtls_x509_crt* crt); +void mbedtls_debug_print_crt(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_x509_crt* crt); #endif #if defined(MBEDTLS_ECDH_C) @@ -294,12 +271,7 @@ typedef enum { * library only. */ void mbedtls_debug_printf_ecdh( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const mbedtls_ecdh_context* ecdh, - mbedtls_debug_ecdh_attr attr); + const mbedtls_ssl_context* ssl, int level, const char* file, int line, const mbedtls_ecdh_context* ecdh, mbedtls_debug_ecdh_attr attr); #endif #ifdef __cplusplus diff --git a/nettls/nettls/des.h b/nettls/nettls/des.h index 55f089a740815149c2e124fc893b7d42d6ea7ef4..1de9460a0b38b2985ce97b4032d50a78351bed8b 100644 --- a/nettls/nettls/des.h +++ b/nettls/nettls/des.h @@ -288,13 +288,7 @@ int mbedtls_des_crypt_ecb(mbedtls_des_context* ctx, const unsigned char input[8] * security risk. We recommend considering stronger ciphers * instead. */ -int mbedtls_des_crypt_cbc( - mbedtls_des_context* ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char* input, - unsigned char* output); +int mbedtls_des_crypt_cbc(mbedtls_des_context* ctx, int mode, size_t length, unsigned char iv[8], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ /** @@ -330,12 +324,7 @@ int mbedtls_des3_crypt_ecb(mbedtls_des3_context* ctx, const unsigned char input[ * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH */ int mbedtls_des3_crypt_cbc( - mbedtls_des3_context* ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char* input, - unsigned char* output); + mbedtls_des3_context* ctx, int mode, size_t length, unsigned char iv[8], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ /** diff --git a/nettls/nettls/dhm.h b/nettls/nettls/dhm.h index 20d94823375a536250ee6590e94a4a84f9dc6779..ecd42e38f60f5bd2f7759f2e4d2d45f37a9ecd04 100644 --- a/nettls/nettls/dhm.h +++ b/nettls/nettls/dhm.h @@ -206,12 +206,7 @@ int mbedtls_dhm_read_params(mbedtls_dhm_context* ctx, unsigned char** p, const u * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_make_params( - mbedtls_dhm_context* ctx, - int x_size, - unsigned char* output, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_dhm_context* ctx, int x_size, unsigned char* output, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function sets the prime modulus and generator. @@ -273,12 +268,7 @@ int mbedtls_dhm_read_public(mbedtls_dhm_context* ctx, const unsigned char* input * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_make_public( - mbedtls_dhm_context* ctx, - int x_size, - unsigned char* output, - size_t olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_dhm_context* ctx, int x_size, unsigned char* output, size_t olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function derives and exports the shared secret @@ -307,12 +297,7 @@ int mbedtls_dhm_make_public( * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_calc_secret( - mbedtls_dhm_context* ctx, - unsigned char* output, - size_t output_size, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_dhm_context* ctx, unsigned char* output, size_t output_size, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function frees and clears the components @@ -569,21 +554,18 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC3526_MODP_2048_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, \ - 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, \ - 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, \ - 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, \ - 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, \ - 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, \ - 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \ - 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, \ - 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, \ - 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, \ - 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, \ - 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, \ - 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, \ - 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, \ - 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, \ + 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, \ + 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, \ + 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, \ + 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, \ + 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, \ + 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, \ + 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, \ + 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, \ + 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, \ + 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, \ + 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ } #define MBEDTLS_DHM_RFC3526_MODP_2048_G_BIN \ @@ -593,28 +575,23 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC3526_MODP_3072_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, \ - 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, \ - 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, \ - 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, \ - 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, \ - 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, \ - 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \ - 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, \ - 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, \ - 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, \ - 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, \ - 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, \ - 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, \ - 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, \ - 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \ - 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, \ - 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, 0xAB, 0xF5, \ - 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, \ - 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, \ - 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, \ - 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, \ - 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, \ + 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, \ + 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, \ + 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, \ + 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, \ + 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, \ + 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, \ + 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, \ + 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, \ + 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, \ + 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, \ + 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, \ + 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, \ + 0xC7, 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, \ + 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, \ + 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, \ + 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, \ 0xCA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ } @@ -625,36 +602,30 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC3526_MODP_4096_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, \ - 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, \ - 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, \ - 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, \ - 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, \ - 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, \ - 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, \ - 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, \ - 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, \ - 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, \ - 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, \ - 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, \ - 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, \ - 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, \ - 0x10, 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, \ - 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, \ - 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, 0xAB, 0xF5, \ - 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, \ - 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, \ - 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, \ - 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, \ - 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, \ - 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, \ - 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C, 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, 0x25, \ - 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, \ - 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, 0x96, \ - 0x4F, 0xA0, 0x90, 0xC3, 0xA2, 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, 0x1F, 0x61, 0x29, 0x70, \ - 0xCE, 0xE2, 0xD7, 0xAF, 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, \ - 0xB0, 0x5A, 0xA9, 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, \ - 0xC0, 0x8F, 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, \ + 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, \ + 0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, \ + 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, \ + 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, \ + 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, \ + 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, \ + 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, \ + 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, \ + 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, \ + 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E, \ + 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, \ + 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, \ + 0xC7, 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, \ + 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, \ + 0x18, 0x17, 0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2, 0x08, \ + 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, \ + 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18, 0x6A, \ + 0xF4, 0xE2, 0x3C, 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, 0xDB, 0xBB, 0xC2, \ + 0xDB, 0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, \ + 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2, 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, \ + 0xAF, 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, 0x93, 0xB4, 0xEA, 0x98, 0x8D, \ + 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F, 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ } #define MBEDTLS_DHM_RFC3526_MODP_4096_G_BIN \ @@ -664,21 +635,18 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC7919_FFDHE2048_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, \ - 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, \ - 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, \ - 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, \ - 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, \ - 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, \ - 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \ - 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, \ - 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, \ - 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, \ - 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, \ - 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, \ - 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, \ - 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, \ - 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x28, 0x5C, 0x97, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, \ + 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, \ + 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, \ + 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, \ + 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, \ + 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, \ + 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, \ + 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, \ + 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, \ + 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, \ + 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, \ + 0x38, 0x61, 0x28, 0x5C, 0x97, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ } #define MBEDTLS_DHM_RFC7919_FFDHE2048_G_BIN \ @@ -688,28 +656,23 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC7919_FFDHE3072_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, \ - 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, \ - 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, \ - 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, \ - 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, \ - 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, \ - 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \ - 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, \ - 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, \ - 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, \ - 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, \ - 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, \ - 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, \ - 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, \ - 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \ - 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, \ - 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, \ - 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, \ - 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, \ - 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, \ - 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, \ - 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, \ + 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, \ + 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, \ + 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, \ + 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, \ + 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, \ + 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, \ + 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, \ + 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, \ + 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, \ + 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, \ + 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, \ + 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, \ + 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, \ + 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, \ + 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, \ + 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0xC6, 0x2E, \ 0x37, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ } @@ -720,36 +683,30 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC7919_FFDHE4096_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, \ - 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, \ - 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, \ - 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, \ - 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, \ - 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, \ - 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \ - 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, \ - 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, \ - 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, \ - 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, \ - 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, \ - 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, \ - 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, \ - 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \ - 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, \ - 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, \ - 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, \ - 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, \ - 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, \ - 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, \ - 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, \ - 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \ - 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, \ - 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, \ - 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, \ - 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, \ - 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, \ - 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, \ - 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, \ + 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, \ + 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, \ + 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, \ + 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, \ + 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, \ + 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, \ + 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, \ + 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, \ + 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, \ + 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, \ + 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, \ + 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, \ + 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, \ + 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, \ + 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, \ + 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, \ + 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, \ + 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, \ + 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, \ + 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, \ + 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, \ + 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x65, 0x5F, 0x6A, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ } #define MBEDTLS_DHM_RFC7919_FFDHE4096_G_BIN \ @@ -759,52 +716,41 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC7919_FFDHE6144_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, \ - 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, \ - 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, \ - 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, \ - 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, \ - 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, \ - 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \ - 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, \ - 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, \ - 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, \ - 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, \ - 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, \ - 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, \ - 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, \ - 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \ - 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, \ - 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, \ - 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, \ - 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, \ - 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, \ - 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, \ - 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, \ - 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \ - 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, \ - 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, \ - 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, \ - 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, \ - 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, \ - 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, \ - 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, \ - 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \ - 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, \ - 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, \ - 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, \ - 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, 0x92, \ - 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, \ - 0x30, 0x23, 0xC3, 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, \ - 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, \ - 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \ - 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, \ - 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, \ - 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, \ - 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, \ - 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, \ - 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ - 0xFF, 0xFF \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, \ + 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, \ + 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, \ + 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, \ + 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, \ + 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, \ + 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, \ + 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, \ + 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, \ + 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, \ + 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, \ + 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, \ + 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, \ + 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, \ + 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, \ + 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, \ + 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, \ + 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, \ + 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, \ + 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, \ + 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, \ + 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, \ + 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, \ + 0xB6, 0x45, 0x03, 0x6C, 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, 0x3B, \ + 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, \ + 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, \ + 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, \ + 0x92, 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, 0x58, \ + 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, \ + 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, \ + 0xA6, 0x7C, 0xBE, 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, 0x29, 0x2C, \ + 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, \ + 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, \ + 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, \ + 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xD0, 0xE4, 0x0E, 0x65, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ } #define MBEDTLS_DHM_RFC7919_FFDHE6144_G_BIN \ @@ -814,67 +760,53 @@ int mbedtls_dhm_self_test(int verbose); #define MBEDTLS_DHM_RFC7919_FFDHE8192_P_BIN \ { \ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, \ - 0x56, 0x20, 0x27, 0x3D, 0x3C, 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, \ - 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, \ - 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, 0xD5, 0xD5, \ - 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, \ - 0x1A, 0xF3, 0xB5, 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, \ - 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, \ - 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, 0x24, 0xFB, 0x61, 0xD1, \ - 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, \ - 0x42, 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, \ - 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, \ - 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, \ - 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, 0xC2, \ - 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, \ - 0xFA, 0x88, 0x6B, 0x42, 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, \ - 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, \ - 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, 0x1C, 0xAE, 0xFE, \ - 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, \ - 0x52, 0xE2, 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, \ - 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, \ - 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, 0xBC, 0xD0, 0x6B, 0xFA, 0x53, \ - 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, \ - 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, \ - 0xAC, 0x7D, 0x5F, 0x42, 0xD6, 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, \ - 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, \ - 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, 0xC7, 0x78, \ - 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, \ - 0x71, 0x40, 0x00, 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, \ - 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, \ - 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, 0xB6, 0x45, 0x03, 0x6C, \ - 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, \ - 0x3B, 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, \ - 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, \ - 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, \ - 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, 0x92, \ - 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, \ - 0x30, 0x23, 0xC3, 0x58, 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, \ - 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, \ - 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, 0xA6, 0x7C, 0xBE, \ - 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, \ - 0x29, 0x2C, 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, \ - 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, \ - 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, \ - 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, \ - 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, \ - 0xC8, 0x38, 0x1E, 0x42, 0x5A, 0x31, 0xD9, 0x51, 0xAE, 0x64, 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, \ - 0x43, 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, 0x0B, 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, \ - 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, 0x65, 0xCB, \ - 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, 0x54, 0x50, \ - 0x4A, 0xC7, 0x8B, 0x75, 0x82, 0x82, 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, 0x59, 0x16, 0x0C, \ - 0xC0, 0x46, 0xFD, 0x82, 0x51, 0x54, 0x1F, 0xC6, 0x8C, 0x9C, 0x86, 0xB0, 0x22, 0xBB, 0x70, 0x99, 0x87, \ - 0x6A, 0x46, 0x0E, 0x74, 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, 0x1C, 0x21, 0x7E, 0x6C, 0x38, \ - 0x26, 0xE5, 0x2C, 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, \ - 0x21, 0x7B, 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, \ - 0xA0, 0xA1, 0xFE, 0x30, 0x75, 0xA5, 0x77, 0xE2, 0x31, 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, \ - 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, 0xB6, 0x85, 0x5D, 0xFE, 0x72, 0xB0, 0xA6, 0x6E, 0xDE, \ - 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, 0x2F, 0x74, \ - 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, 0x97, 0xD1, 0x1D, \ - 0x49, 0xF7, 0xA8, 0x44, 0x3D, 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, 0x01, 0x1E, 0x2A, 0x94, \ - 0x83, 0x8F, 0xF8, 0x8C, 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, 0xC6, 0x42, 0x4C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ - 0xFF, 0xFF, 0xFF \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xAD, 0xF8, 0x54, 0x58, 0xA2, 0xBB, 0x4A, 0x9A, 0xAF, 0xDC, 0x56, 0x20, 0x27, 0x3D, 0x3C, \ + 0xF1, 0xD8, 0xB9, 0xC5, 0x83, 0xCE, 0x2D, 0x36, 0x95, 0xA9, 0xE1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xFB, 0xCC, 0x93, 0x9D, 0xCE, 0x24, \ + 0x9B, 0x3E, 0xF9, 0x7D, 0x2F, 0xE3, 0x63, 0x63, 0x0C, 0x75, 0xD8, 0xF6, 0x81, 0xB2, 0x02, 0xAE, 0xC4, 0x61, 0x7A, 0xD3, 0xDF, 0x1E, \ + 0xD5, 0xD5, 0xFD, 0x65, 0x61, 0x24, 0x33, 0xF5, 0x1F, 0x5F, 0x06, 0x6E, 0xD0, 0x85, 0x63, 0x65, 0x55, 0x3D, 0xED, 0x1A, 0xF3, 0xB5, \ + 0x57, 0x13, 0x5E, 0x7F, 0x57, 0xC9, 0x35, 0x98, 0x4F, 0x0C, 0x70, 0xE0, 0xE6, 0x8B, 0x77, 0xE2, 0xA6, 0x89, 0xDA, 0xF3, 0xEF, 0xE8, \ + 0x72, 0x1D, 0xF1, 0x58, 0xA1, 0x36, 0xAD, 0xE7, 0x35, 0x30, 0xAC, 0xCA, 0x4F, 0x48, 0x3A, 0x79, 0x7A, 0xBC, 0x0A, 0xB1, 0x82, 0xB3, \ + 0x24, 0xFB, 0x61, 0xD1, 0x08, 0xA9, 0x4B, 0xB2, 0xC8, 0xE3, 0xFB, 0xB9, 0x6A, 0xDA, 0xB7, 0x60, 0xD7, 0xF4, 0x68, 0x1D, 0x4F, 0x42, \ + 0xA3, 0xDE, 0x39, 0x4D, 0xF4, 0xAE, 0x56, 0xED, 0xE7, 0x63, 0x72, 0xBB, 0x19, 0x0B, 0x07, 0xA7, 0xC8, 0xEE, 0x0A, 0x6D, 0x70, 0x9E, \ + 0x02, 0xFC, 0xE1, 0xCD, 0xF7, 0xE2, 0xEC, 0xC0, 0x34, 0x04, 0xCD, 0x28, 0x34, 0x2F, 0x61, 0x91, 0x72, 0xFE, 0x9C, 0xE9, 0x85, 0x83, \ + 0xFF, 0x8E, 0x4F, 0x12, 0x32, 0xEE, 0xF2, 0x81, 0x83, 0xC3, 0xFE, 0x3B, 0x1B, 0x4C, 0x6F, 0xAD, 0x73, 0x3B, 0xB5, 0xFC, 0xBC, 0x2E, \ + 0xC2, 0x20, 0x05, 0xC5, 0x8E, 0xF1, 0x83, 0x7D, 0x16, 0x83, 0xB2, 0xC6, 0xF3, 0x4A, 0x26, 0xC1, 0xB2, 0xEF, 0xFA, 0x88, 0x6B, 0x42, \ + 0x38, 0x61, 0x1F, 0xCF, 0xDC, 0xDE, 0x35, 0x5B, 0x3B, 0x65, 0x19, 0x03, 0x5B, 0xBC, 0x34, 0xF4, 0xDE, 0xF9, 0x9C, 0x02, 0x38, 0x61, \ + 0xB4, 0x6F, 0xC9, 0xD6, 0xE6, 0xC9, 0x07, 0x7A, 0xD9, 0x1D, 0x26, 0x91, 0xF7, 0xF7, 0xEE, 0x59, 0x8C, 0xB0, 0xFA, 0xC1, 0x86, 0xD9, \ + 0x1C, 0xAE, 0xFE, 0x13, 0x09, 0x85, 0x13, 0x92, 0x70, 0xB4, 0x13, 0x0C, 0x93, 0xBC, 0x43, 0x79, 0x44, 0xF4, 0xFD, 0x44, 0x52, 0xE2, \ + 0xD7, 0x4D, 0xD3, 0x64, 0xF2, 0xE2, 0x1E, 0x71, 0xF5, 0x4B, 0xFF, 0x5C, 0xAE, 0x82, 0xAB, 0x9C, 0x9D, 0xF6, 0x9E, 0xE8, 0x6D, 0x2B, \ + 0xC5, 0x22, 0x36, 0x3A, 0x0D, 0xAB, 0xC5, 0x21, 0x97, 0x9B, 0x0D, 0xEA, 0xDA, 0x1D, 0xBF, 0x9A, 0x42, 0xD5, 0xC4, 0x48, 0x4E, 0x0A, \ + 0xBC, 0xD0, 0x6B, 0xFA, 0x53, 0xDD, 0xEF, 0x3C, 0x1B, 0x20, 0xEE, 0x3F, 0xD5, 0x9D, 0x7C, 0x25, 0xE4, 0x1D, 0x2B, 0x66, 0x9E, 0x1E, \ + 0xF1, 0x6E, 0x6F, 0x52, 0xC3, 0x16, 0x4D, 0xF4, 0xFB, 0x79, 0x30, 0xE9, 0xE4, 0xE5, 0x88, 0x57, 0xB6, 0xAC, 0x7D, 0x5F, 0x42, 0xD6, \ + 0x9F, 0x6D, 0x18, 0x77, 0x63, 0xCF, 0x1D, 0x55, 0x03, 0x40, 0x04, 0x87, 0xF5, 0x5B, 0xA5, 0x7E, 0x31, 0xCC, 0x7A, 0x71, 0x35, 0xC8, \ + 0x86, 0xEF, 0xB4, 0x31, 0x8A, 0xED, 0x6A, 0x1E, 0x01, 0x2D, 0x9E, 0x68, 0x32, 0xA9, 0x07, 0x60, 0x0A, 0x91, 0x81, 0x30, 0xC4, 0x6D, \ + 0xC7, 0x78, 0xF9, 0x71, 0xAD, 0x00, 0x38, 0x09, 0x29, 0x99, 0xA3, 0x33, 0xCB, 0x8B, 0x7A, 0x1A, 0x1D, 0xB9, 0x3D, 0x71, 0x40, 0x00, \ + 0x3C, 0x2A, 0x4E, 0xCE, 0xA9, 0xF9, 0x8D, 0x0A, 0xCC, 0x0A, 0x82, 0x91, 0xCD, 0xCE, 0xC9, 0x7D, 0xCF, 0x8E, 0xC9, 0xB5, 0x5A, 0x7F, \ + 0x88, 0xA4, 0x6B, 0x4D, 0xB5, 0xA8, 0x51, 0xF4, 0x41, 0x82, 0xE1, 0xC6, 0x8A, 0x00, 0x7E, 0x5E, 0x0D, 0xD9, 0x02, 0x0B, 0xFD, 0x64, \ + 0xB6, 0x45, 0x03, 0x6C, 0x7A, 0x4E, 0x67, 0x7D, 0x2C, 0x38, 0x53, 0x2A, 0x3A, 0x23, 0xBA, 0x44, 0x42, 0xCA, 0xF5, 0x3E, 0xA6, 0x3B, \ + 0xB4, 0x54, 0x32, 0x9B, 0x76, 0x24, 0xC8, 0x91, 0x7B, 0xDD, 0x64, 0xB1, 0xC0, 0xFD, 0x4C, 0xB3, 0x8E, 0x8C, 0x33, 0x4C, 0x70, 0x1C, \ + 0x3A, 0xCD, 0xAD, 0x06, 0x57, 0xFC, 0xCF, 0xEC, 0x71, 0x9B, 0x1F, 0x5C, 0x3E, 0x4E, 0x46, 0x04, 0x1F, 0x38, 0x81, 0x47, 0xFB, 0x4C, \ + 0xFD, 0xB4, 0x77, 0xA5, 0x24, 0x71, 0xF7, 0xA9, 0xA9, 0x69, 0x10, 0xB8, 0x55, 0x32, 0x2E, 0xDB, 0x63, 0x40, 0xD8, 0xA0, 0x0E, 0xF0, \ + 0x92, 0x35, 0x05, 0x11, 0xE3, 0x0A, 0xBE, 0xC1, 0xFF, 0xF9, 0xE3, 0xA2, 0x6E, 0x7F, 0xB2, 0x9F, 0x8C, 0x18, 0x30, 0x23, 0xC3, 0x58, \ + 0x7E, 0x38, 0xDA, 0x00, 0x77, 0xD9, 0xB4, 0x76, 0x3E, 0x4E, 0x4B, 0x94, 0xB2, 0xBB, 0xC1, 0x94, 0xC6, 0x65, 0x1E, 0x77, 0xCA, 0xF9, \ + 0x92, 0xEE, 0xAA, 0xC0, 0x23, 0x2A, 0x28, 0x1B, 0xF6, 0xB3, 0xA7, 0x39, 0xC1, 0x22, 0x61, 0x16, 0x82, 0x0A, 0xE8, 0xDB, 0x58, 0x47, \ + 0xA6, 0x7C, 0xBE, 0xF9, 0xC9, 0x09, 0x1B, 0x46, 0x2D, 0x53, 0x8C, 0xD7, 0x2B, 0x03, 0x74, 0x6A, 0xE7, 0x7F, 0x5E, 0x62, 0x29, 0x2C, \ + 0x31, 0x15, 0x62, 0xA8, 0x46, 0x50, 0x5D, 0xC8, 0x2D, 0xB8, 0x54, 0x33, 0x8A, 0xE4, 0x9F, 0x52, 0x35, 0xC9, 0x5B, 0x91, 0x17, 0x8C, \ + 0xCF, 0x2D, 0xD5, 0xCA, 0xCE, 0xF4, 0x03, 0xEC, 0x9D, 0x18, 0x10, 0xC6, 0x27, 0x2B, 0x04, 0x5B, 0x3B, 0x71, 0xF9, 0xDC, 0x6B, 0x80, \ + 0xD6, 0x3F, 0xDD, 0x4A, 0x8E, 0x9A, 0xDB, 0x1E, 0x69, 0x62, 0xA6, 0x95, 0x26, 0xD4, 0x31, 0x61, 0xC1, 0xA4, 0x1D, 0x57, 0x0D, 0x79, \ + 0x38, 0xDA, 0xD4, 0xA4, 0x0E, 0x32, 0x9C, 0xCF, 0xF4, 0x6A, 0xAA, 0x36, 0xAD, 0x00, 0x4C, 0xF6, 0x00, 0xC8, 0x38, 0x1E, 0x42, 0x5A, \ + 0x31, 0xD9, 0x51, 0xAE, 0x64, 0xFD, 0xB2, 0x3F, 0xCE, 0xC9, 0x50, 0x9D, 0x43, 0x68, 0x7F, 0xEB, 0x69, 0xED, 0xD1, 0xCC, 0x5E, 0x0B, \ + 0x8C, 0xC3, 0xBD, 0xF6, 0x4B, 0x10, 0xEF, 0x86, 0xB6, 0x31, 0x42, 0xA3, 0xAB, 0x88, 0x29, 0x55, 0x5B, 0x2F, 0x74, 0x7C, 0x93, 0x26, \ + 0x65, 0xCB, 0x2C, 0x0F, 0x1C, 0xC0, 0x1B, 0xD7, 0x02, 0x29, 0x38, 0x88, 0x39, 0xD2, 0xAF, 0x05, 0xE4, 0x54, 0x50, 0x4A, 0xC7, 0x8B, \ + 0x75, 0x82, 0x82, 0x28, 0x46, 0xC0, 0xBA, 0x35, 0xC3, 0x5F, 0x5C, 0x59, 0x16, 0x0C, 0xC0, 0x46, 0xFD, 0x82, 0x51, 0x54, 0x1F, 0xC6, \ + 0x8C, 0x9C, 0x86, 0xB0, 0x22, 0xBB, 0x70, 0x99, 0x87, 0x6A, 0x46, 0x0E, 0x74, 0x51, 0xA8, 0xA9, 0x31, 0x09, 0x70, 0x3F, 0xEE, 0x1C, \ + 0x21, 0x7E, 0x6C, 0x38, 0x26, 0xE5, 0x2C, 0x51, 0xAA, 0x69, 0x1E, 0x0E, 0x42, 0x3C, 0xFC, 0x99, 0xE9, 0xE3, 0x16, 0x50, 0xC1, 0x21, \ + 0x7B, 0x62, 0x48, 0x16, 0xCD, 0xAD, 0x9A, 0x95, 0xF9, 0xD5, 0xB8, 0x01, 0x94, 0x88, 0xD9, 0xC0, 0xA0, 0xA1, 0xFE, 0x30, 0x75, 0xA5, \ + 0x77, 0xE2, 0x31, 0x83, 0xF8, 0x1D, 0x4A, 0x3F, 0x2F, 0xA4, 0x57, 0x1E, 0xFC, 0x8C, 0xE0, 0xBA, 0x8A, 0x4F, 0xE8, 0xB6, 0x85, 0x5D, \ + 0xFE, 0x72, 0xB0, 0xA6, 0x6E, 0xDE, 0xD2, 0xFB, 0xAB, 0xFB, 0xE5, 0x8A, 0x30, 0xFA, 0xFA, 0xBE, 0x1C, 0x5D, 0x71, 0xA8, 0x7E, 0x2F, \ + 0x74, 0x1E, 0xF8, 0xC1, 0xFE, 0x86, 0xFE, 0xA6, 0xBB, 0xFD, 0xE5, 0x30, 0x67, 0x7F, 0x0D, 0x97, 0xD1, 0x1D, 0x49, 0xF7, 0xA8, 0x44, \ + 0x3D, 0x08, 0x22, 0xE5, 0x06, 0xA9, 0xF4, 0x61, 0x4E, 0x01, 0x1E, 0x2A, 0x94, 0x83, 0x8F, 0xF8, 0x8C, 0xD6, 0x8C, 0x8B, 0xB7, 0xC5, \ + 0xC6, 0x42, 0x4C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \ } #define MBEDTLS_DHM_RFC7919_FFDHE8192_G_BIN \ diff --git a/nettls/nettls/ecdh.h b/nettls/nettls/ecdh.h index 0c398dfaba6e047bcc9598a33ffad537d7310356..a947de7aa07b13611a2894f251357dc5470c58cc 100644 --- a/nettls/nettls/ecdh.h +++ b/nettls/nettls/ecdh.h @@ -189,12 +189,7 @@ typedef struct mbedtls_ecdh_context { * \return Another \c MBEDTLS_ERR_ECP_XXX or * \c MBEDTLS_MPI_XXX error code on failure. */ -int mbedtls_ecdh_gen_public( - mbedtls_ecp_group* grp, - mbedtls_mpi* d, - mbedtls_ecp_point* Q, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); +int mbedtls_ecdh_gen_public(mbedtls_ecp_group* grp, mbedtls_mpi* d, mbedtls_ecp_point* Q, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function computes the shared secret. @@ -298,12 +293,7 @@ void mbedtls_ecdh_free(mbedtls_ecdh_context* ctx); * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. */ int mbedtls_ecdh_make_params( - mbedtls_ecdh_context* ctx, - size_t* olen, - unsigned char* buf, - size_t blen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_ecdh_context* ctx, size_t* olen, unsigned char* buf, size_t blen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function parses the ECDHE parameters in a @@ -379,12 +369,7 @@ int mbedtls_ecdh_get_params(mbedtls_ecdh_context* ctx, const mbedtls_ecp_keypair * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. */ int mbedtls_ecdh_make_public( - mbedtls_ecdh_context* ctx, - size_t* olen, - unsigned char* buf, - size_t blen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_ecdh_context* ctx, size_t* olen, unsigned char* buf, size_t blen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function parses and processes the ECDHE payload of a @@ -438,12 +423,7 @@ int mbedtls_ecdh_read_public(mbedtls_ecdh_context* ctx, const unsigned char* buf * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. */ int mbedtls_ecdh_calc_secret( - mbedtls_ecdh_context* ctx, - size_t* olen, - unsigned char* buf, - size_t blen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_ecdh_context* ctx, size_t* olen, unsigned char* buf, size_t blen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #if defined(MBEDTLS_ECP_RESTARTABLE) /** diff --git a/nettls/nettls/ecdsa.h b/nettls/nettls/ecdsa.h index 67bb019f3319fc066f86af96a0f44e8f62ae3802..dcc77765faa0bcec5bc43a6fb030569791f9ee97 100644 --- a/nettls/nettls/ecdsa.h +++ b/nettls/nettls/ecdsa.h @@ -240,13 +240,7 @@ int mbedtls_ecdsa_sign( * error code on failure. */ int mbedtls_ecdsa_sign_det( - mbedtls_ecp_group* grp, - mbedtls_mpi* r, - mbedtls_mpi* s, - const mbedtls_mpi* d, - const unsigned char* buf, - size_t blen, - mbedtls_md_type_t md_alg); + mbedtls_ecp_group* grp, mbedtls_mpi* r, mbedtls_mpi* s, const mbedtls_mpi* d, const unsigned char* buf, size_t blen, mbedtls_md_type_t md_alg); /** * \brief This function computes the ECDSA signature of a * previously-hashed message, deterministic version. @@ -331,12 +325,7 @@ int mbedtls_ecdsa_sign_det_ext( * error code on failure for any other reason. */ int mbedtls_ecdsa_verify( - mbedtls_ecp_group* grp, - const unsigned char* buf, - size_t blen, - const mbedtls_ecp_point* Q, - const mbedtls_mpi* r, - const mbedtls_mpi* s); + mbedtls_ecp_group* grp, const unsigned char* buf, size_t blen, const mbedtls_ecp_point* Q, const mbedtls_mpi* r, const mbedtls_mpi* s); /** * \brief This function computes the ECDSA signature and writes it @@ -496,12 +485,8 @@ int mbedtls_ecdsa_write_signature_restartable( * \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_ecdsa_write_signature_det( - mbedtls_ecdsa_context* ctx, - const unsigned char* hash, - size_t hlen, - unsigned char* sig, - size_t* slen, - mbedtls_md_type_t md_alg) MBEDTLS_DEPRECATED; + mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, unsigned char* sig, size_t* slen, mbedtls_md_type_t md_alg) + MBEDTLS_DEPRECATED; #undef MBEDTLS_DEPRECATED #endif /* MBEDTLS_DEPRECATED_REMOVED */ #endif /* MBEDTLS_ECDSA_DETERMINISTIC */ @@ -533,8 +518,7 @@ int mbedtls_ecdsa_write_signature_det( * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX * error code on failure for any other reason. */ -int mbedtls_ecdsa_read_signature( - mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, const unsigned char* sig, size_t slen); +int mbedtls_ecdsa_read_signature(mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, const unsigned char* sig, size_t slen); /** * \brief This function reads and verifies an ECDSA signature, @@ -568,12 +552,7 @@ int mbedtls_ecdsa_read_signature( * error code on failure for any other reason. */ int mbedtls_ecdsa_read_signature_restartable( - mbedtls_ecdsa_context* ctx, - const unsigned char* hash, - size_t hlen, - const unsigned char* sig, - size_t slen, - mbedtls_ecdsa_restart_ctx* rs_ctx); + mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, const unsigned char* sig, size_t slen, mbedtls_ecdsa_restart_ctx* rs_ctx); /** * \brief This function generates an ECDSA keypair on the given curve. @@ -591,8 +570,7 @@ int mbedtls_ecdsa_read_signature_restartable( * \return \c 0 on success. * \return An \c MBEDTLS_ERR_ECP_XXX code on failure. */ -int mbedtls_ecdsa_genkey( - mbedtls_ecdsa_context* ctx, mbedtls_ecp_group_id gid, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +int mbedtls_ecdsa_genkey(mbedtls_ecdsa_context* ctx, mbedtls_ecp_group_id gid, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function sets up an ECDSA context from an EC key pair. diff --git a/nettls/nettls/ecjpake.h b/nettls/nettls/ecjpake.h index 68655311440d52e35e6da693364704e16818c645..4f059c76ab5782a2d0f377ff879e3cd4aefa307a 100644 --- a/nettls/nettls/ecjpake.h +++ b/nettls/nettls/ecjpake.h @@ -188,12 +188,7 @@ int mbedtls_ecjpake_check(const mbedtls_ecjpake_context* ctx); * \return A negative error code on failure. */ int mbedtls_ecjpake_write_round_one( - mbedtls_ecjpake_context* ctx, - unsigned char* buf, - size_t len, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_ecjpake_context* ctx, unsigned char* buf, size_t len, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief Read and process the first round message @@ -230,12 +225,7 @@ int mbedtls_ecjpake_read_round_one(mbedtls_ecjpake_context* ctx, const unsigned * \return A negative error code on failure. */ int mbedtls_ecjpake_write_round_two( - mbedtls_ecjpake_context* ctx, - unsigned char* buf, - size_t len, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_ecjpake_context* ctx, unsigned char* buf, size_t len, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief Read and process the second round message @@ -271,12 +261,7 @@ int mbedtls_ecjpake_read_round_two(mbedtls_ecjpake_context* ctx, const unsigned * \return A negative error code on failure. */ int mbedtls_ecjpake_derive_secret( - mbedtls_ecjpake_context* ctx, - unsigned char* buf, - size_t len, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); + mbedtls_ecjpake_context* ctx, unsigned char* buf, size_t len, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This clears an ECJPAKE context and frees any diff --git a/nettls/nettls/ecp.h b/nettls/nettls/ecp.h index 0b54f884cecbcbc8f210123ead5fc90a29804ae9..f784e5dfdfbda722a0dd6272f75d1138c3897b82 100644 --- a/nettls/nettls/ecp.h +++ b/nettls/nettls/ecp.h @@ -75,8 +75,8 @@ #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */ #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */ #define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE \ - -0x4E80 /**< The requested feature is not available, for example, the requested \ - curve is not supported. */ + -0x4E80 /**< The requested feature is not available, for example, the requested \ + curve is not supported. */ #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */ #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */ #define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as ephemeral key, failed. */ @@ -656,12 +656,7 @@ int mbedtls_ecp_point_read_string(mbedtls_ecp_point* P, int radix, const char* x * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_point_write_binary( - const mbedtls_ecp_group* grp, - const mbedtls_ecp_point* P, - int format, - size_t* olen, - unsigned char* buf, - size_t buflen); + const mbedtls_ecp_group* grp, const mbedtls_ecp_point* P, int format, size_t* olen, unsigned char* buf, size_t buflen); /** * \brief This function imports a point from unsigned binary data. @@ -685,8 +680,7 @@ int mbedtls_ecp_point_write_binary( * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format * is not implemented. */ -int mbedtls_ecp_point_read_binary( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* P, const unsigned char* buf, size_t ilen); +int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group* grp, mbedtls_ecp_point* P, const unsigned char* buf, size_t ilen); /** * \brief This function imports a point from a TLS ECPoint record. @@ -706,8 +700,7 @@ int mbedtls_ecp_point_read_binary( * failure. * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid. */ -int mbedtls_ecp_tls_read_point( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, const unsigned char** buf, size_t len); +int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, const unsigned char** buf, size_t len); /** * \brief This function exports a point as a TLS ECPoint record @@ -731,13 +724,7 @@ int mbedtls_ecp_tls_read_point( * is too small to hold the exported point. * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_tls_write_point( - const mbedtls_ecp_group* grp, - const mbedtls_ecp_point* pt, - int format, - size_t* olen, - unsigned char* buf, - size_t blen); +int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group* grp, const mbedtls_ecp_point* pt, int format, size_t* olen, unsigned char* buf, size_t blen); /** * \brief This function sets up an ECP group context @@ -929,12 +916,7 @@ int mbedtls_ecp_mul_restartable( * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_muladd( - mbedtls_ecp_group* grp, - mbedtls_ecp_point* R, - const mbedtls_mpi* m, - const mbedtls_ecp_point* P, - const mbedtls_mpi* n, - const mbedtls_ecp_point* Q); + mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_mpi* m, const mbedtls_ecp_point* P, const mbedtls_mpi* n, const mbedtls_ecp_point* Q); /** * \brief This function performs multiplication and addition of two @@ -1044,8 +1026,7 @@ int mbedtls_ecp_check_privkey(const mbedtls_ecp_group* grp, const mbedtls_mpi* d * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code * on failure. */ -int mbedtls_ecp_gen_privkey( - const mbedtls_ecp_group* grp, mbedtls_mpi* d, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group* grp, mbedtls_mpi* d, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function generates a keypair with a configurable base @@ -1105,12 +1086,7 @@ int mbedtls_ecp_gen_keypair_base( * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code * on failure. */ -int mbedtls_ecp_gen_keypair( - mbedtls_ecp_group* grp, - mbedtls_mpi* d, - mbedtls_ecp_point* Q, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); +int mbedtls_ecp_gen_keypair(mbedtls_ecp_group* grp, mbedtls_mpi* d, mbedtls_ecp_point* Q, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function generates an ECP key. @@ -1125,8 +1101,7 @@ int mbedtls_ecp_gen_keypair( * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code * on failure. */ -int mbedtls_ecp_gen_key( - mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair* key, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair* key, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); /** * \brief This function checks that the keypair objects diff --git a/nettls/nettls/ecp_internal.h b/nettls/nettls/ecp_internal.h index 43bac6845bef5e2b3c06880fa63803909e700330..37bdade423bd8955a9d5560a02d2542078d54d69 100644 --- a/nettls/nettls/ecp_internal.h +++ b/nettls/nettls/ecp_internal.h @@ -148,8 +148,7 @@ void mbedtls_internal_ecp_free(const mbedtls_ecp_group* grp); * * \return 0 if successful. */ -int mbedtls_internal_ecp_randomize_jac( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +int mbedtls_internal_ecp_randomize_jac(const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #endif #if defined(MBEDTLS_ECP_ADD_MIXED_ALT) @@ -192,8 +191,7 @@ int mbedtls_internal_ecp_randomize_jac( * * \return 0 if successful. */ -int mbedtls_internal_ecp_add_mixed( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_ecp_point* P, const mbedtls_ecp_point* Q); +int mbedtls_internal_ecp_add_mixed(const mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_ecp_point* P, const mbedtls_ecp_point* Q); #endif /** @@ -295,8 +293,7 @@ int mbedtls_internal_ecp_double_add_mxz( * \return 0 if successful */ #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) -int mbedtls_internal_ecp_randomize_mxz( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* P, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); +int mbedtls_internal_ecp_randomize_mxz(const mbedtls_ecp_group* grp, mbedtls_ecp_point* P, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #endif /** diff --git a/nettls/nettls/entropy.h b/nettls/nettls/entropy.h index 1280d619866dfe6e5005aadc0a20f6e1a9b93746..02c53ff15741bf230483bb85348437052303ea59 100644 --- a/nettls/nettls/entropy.h +++ b/nettls/nettls/entropy.h @@ -201,8 +201,7 @@ void mbedtls_entropy_free(mbedtls_entropy_context* ctx); * * \return 0 if successful or MBEDTLS_ERR_ENTROPY_MAX_SOURCES */ -int mbedtls_entropy_add_source( - mbedtls_entropy_context* ctx, mbedtls_entropy_f_source_ptr f_source, void* p_source, size_t threshold, int strong); +int mbedtls_entropy_add_source(mbedtls_entropy_context* ctx, mbedtls_entropy_f_source_ptr f_source, void* p_source, size_t threshold, int strong); /** * \brief Trigger an extra gather poll for the accumulator diff --git a/nettls/nettls/gcm.h b/nettls/nettls/gcm.h index 4a951881eeaf6e97a7f74b92dc6a26f50babeeee..d11ae6f83001005e4c78e15acda53f170befa09a 100644 --- a/nettls/nettls/gcm.h +++ b/nettls/nettls/gcm.h @@ -134,8 +134,7 @@ void mbedtls_gcm_init(mbedtls_gcm_context* ctx); * \return \c 0 on success. * \return A cipher-specific error code on failure. */ -int mbedtls_gcm_setkey( - mbedtls_gcm_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits); +int mbedtls_gcm_setkey(mbedtls_gcm_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits); /** * \brief This function performs GCM encryption or decryption of a buffer. @@ -263,13 +262,7 @@ int mbedtls_gcm_auth_decrypt( * * \return \c 0 on success. */ -int mbedtls_gcm_starts( - mbedtls_gcm_context* ctx, - int mode, - const unsigned char* iv, - size_t iv_len, - const unsigned char* add, - size_t add_len); +int mbedtls_gcm_starts(mbedtls_gcm_context* ctx, int mode, const unsigned char* iv, size_t iv_len, const unsigned char* add, size_t add_len); /** * \brief This function feeds an input buffer into an ongoing GCM diff --git a/nettls/nettls/hkdf.h b/nettls/nettls/hkdf.h index 0e5c24178c3646c11fa3a952b921a1360c197893..4b446acf29bb52ee5ecd86f6176cea560201cf45 100644 --- a/nettls/nettls/hkdf.h +++ b/nettls/nettls/hkdf.h @@ -133,12 +133,7 @@ int mbedtls_hkdf( * MD layer. */ int mbedtls_hkdf_extract( - const mbedtls_md_info_t* md, - const unsigned char* salt, - size_t salt_len, - const unsigned char* ikm, - size_t ikm_len, - unsigned char* prk); + const mbedtls_md_info_t* md, const unsigned char* salt, size_t salt_len, const unsigned char* ikm, size_t ikm_len, unsigned char* prk); /** * \brief Expand the supplied \p prk into several additional pseudorandom diff --git a/nettls/nettls/hmac_drbg.h b/nettls/nettls/hmac_drbg.h index 0370587ed17a6b8e1de567e4c94d480506b0b310..612cd5c304de87395eeba65c5a9ace859b8521fa 100644 --- a/nettls/nettls/hmac_drbg.h +++ b/nettls/nettls/hmac_drbg.h @@ -259,8 +259,7 @@ int mbedtls_hmac_drbg_seed( * \return #MBEDTLS_ERR_MD_ALLOC_FAILED if there was not enough * memory to allocate context data. */ -int mbedtls_hmac_drbg_seed_buf( - mbedtls_hmac_drbg_context* ctx, const mbedtls_md_info_t* md_info, const unsigned char* data, size_t data_len); +int mbedtls_hmac_drbg_seed_buf(mbedtls_hmac_drbg_context* ctx, const mbedtls_md_info_t* md_info, const unsigned char* data, size_t data_len); /** * \brief This function turns prediction resistance on or off. @@ -378,8 +377,7 @@ int mbedtls_hmac_drbg_reseed(mbedtls_hmac_drbg_context* ctx, const unsigned char * \return #MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG if * \p add_len > #MBEDTLS_HMAC_DRBG_MAX_INPUT. */ -int mbedtls_hmac_drbg_random_with_add( - void* p_rng, unsigned char* output, size_t output_len, const unsigned char* additional, size_t add_len); +int mbedtls_hmac_drbg_random_with_add(void* p_rng, unsigned char* output, size_t output_len, const unsigned char* additional, size_t add_len); /** * \brief This function uses HMAC_DRBG to generate random data. @@ -436,8 +434,7 @@ void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context* ctx); * \param add_len Length of \p additional in bytes. * Unused if \p additional is \c NULL. */ -MBEDTLS_DEPRECATED void - mbedtls_hmac_drbg_update(mbedtls_hmac_drbg_context* ctx, const unsigned char* additional, size_t add_len); +MBEDTLS_DEPRECATED void mbedtls_hmac_drbg_update(mbedtls_hmac_drbg_context* ctx, const unsigned char* additional, size_t add_len); #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ diff --git a/nettls/nettls/md.h b/nettls/nettls/md.h index a8286e1e371fa4a0b5918942a260e2d4f6386e60..3802c0c267f5624ad0dba2368c9ee031fe0e00b8 100644 --- a/nettls/nettls/md.h +++ b/nettls/nettls/md.h @@ -476,12 +476,7 @@ int mbedtls_md_hmac_reset(mbedtls_md_context_t* ctx); * failure. */ int mbedtls_md_hmac( - const mbedtls_md_info_t* md_info, - const unsigned char* key, - size_t keylen, - const unsigned char* input, - size_t ilen, - unsigned char* output); + const mbedtls_md_info_t* md_info, const unsigned char* key, size_t keylen, const unsigned char* input, size_t ilen, unsigned char* output); /* Internal use */ int mbedtls_md_process(mbedtls_md_context_t* ctx, const unsigned char* data); diff --git a/nettls/nettls/net_sockets.h b/nettls/nettls/net_sockets.h index 6b07c643b0f2af6c1cb059f38ef336982a7c0a6a..60ee266d552a4e55e20bd958f216a193f0a8726f 100644 --- a/nettls/nettls/net_sockets.h +++ b/nettls/nettls/net_sockets.h @@ -176,8 +176,7 @@ int mbedtls_net_bind(mbedtls_net_context* ctx, const char* bind_ip, const char* * MBEDTLS_ERR_SSL_WANT_READ if bind_fd was set to * non-blocking and accept() would block. */ -int mbedtls_net_accept( - mbedtls_net_context* bind_ctx, mbedtls_net_context* client_ctx, void* client_ip, size_t buf_size, size_t* ip_len); +int mbedtls_net_accept(mbedtls_net_context* bind_ctx, mbedtls_net_context* client_ctx, void* client_ip, size_t buf_size, size_t* ip_len); /** * \brief Check and wait for the context to be ready for read/write diff --git a/nettls/nettls/nist_kw.h b/nettls/nettls/nist_kw.h index 785ff2bfba003f7ae234df4ee48676fa495037e9..bbe7f98437e267de47bb312dd669f2731ce4021e 100644 --- a/nettls/nettls/nist_kw.h +++ b/nettls/nettls/nist_kw.h @@ -123,11 +123,7 @@ void mbedtls_nist_kw_init(mbedtls_nist_kw_context* ctx); * \return cipher-specific error code on failure of the underlying cipher. */ int mbedtls_nist_kw_setkey( - mbedtls_nist_kw_context* ctx, - mbedtls_cipher_id_t cipher, - const unsigned char* key, - unsigned int keybits, - const int is_wrap); + mbedtls_nist_kw_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits, const int is_wrap); /** * \brief This function releases and clears the specified key wrapping context diff --git a/nettls/nettls/oid.h b/nettls/nettls/oid.h index 7c5e7b250f094c2168175677cf7182c15c9cf146..7f5d8640d91b182a89e3799e5829dd0c8875c082 100644 --- a/nettls/nettls/oid.h +++ b/nettls/nettls/oid.h @@ -89,10 +89,9 @@ #define MBEDTLS_OID_COUNTRY_US "\x86\x48" /* {us(840)} */ #define MBEDTLS_OID_ORG_RSA_DATA_SECURITY "\x86\xf7\x0d" /* {rsadsi(113549)} */ #define MBEDTLS_OID_RSA_COMPANY \ - MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \ - MBEDTLS_OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) \ - rsadsi(113549)} */ -#define MBEDTLS_OID_ORG_ANSI_X9_62 "\xce\x3d" /* ansi-X9-62(10045) */ + MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) \ + rsadsi(113549)} */ +#define MBEDTLS_OID_ORG_ANSI_X9_62 "\xce\x3d" /* ansi-X9-62(10045) */ #define MBEDTLS_OID_ANSI_X9_62 MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORG_ANSI_X9_62 /* @@ -149,7 +148,7 @@ */ #define MBEDTLS_OID_AT \ MBEDTLS_OID_ISO_CCITT_DS \ - "\x04" /**< id-at OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 4} */ + "\x04" /**< id-at OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 4} */ #define MBEDTLS_OID_AT_CN MBEDTLS_OID_AT "\x03" /**< id-at-commonName AttributeType:= {id-at 3} */ #define MBEDTLS_OID_AT_SUR_NAME MBEDTLS_OID_AT "\x04" /**< id-at-surName AttributeType:= {id-at 4} */ #define MBEDTLS_OID_AT_SERIAL_NUMBER MBEDTLS_OID_AT "\x05" /**< id-at-serialNumber AttributeType:= {id-at 5} */ @@ -158,15 +157,14 @@ #define MBEDTLS_OID_AT_STATE MBEDTLS_OID_AT "\x08" /**< id-at-state AttributeType:= {id-at 8} */ #define MBEDTLS_OID_AT_ORGANIZATION MBEDTLS_OID_AT "\x0A" /**< id-at-organizationName AttributeType:= {id-at 10} */ #define MBEDTLS_OID_AT_ORG_UNIT \ - MBEDTLS_OID_AT "\x0B" /**< id-at-organizationalUnitName AttributeType:= {id-at 11} \ - */ -#define MBEDTLS_OID_AT_TITLE MBEDTLS_OID_AT "\x0C" /**< id-at-title AttributeType:= {id-at 12} */ -#define MBEDTLS_OID_AT_POSTAL_ADDRESS MBEDTLS_OID_AT "\x10" /**< id-at-postalAddress AttributeType:= {id-at 16} */ -#define MBEDTLS_OID_AT_POSTAL_CODE MBEDTLS_OID_AT "\x11" /**< id-at-postalCode AttributeType:= {id-at 17} */ -#define MBEDTLS_OID_AT_GIVEN_NAME MBEDTLS_OID_AT "\x2A" /**< id-at-givenName AttributeType:= {id-at 42} */ -#define MBEDTLS_OID_AT_INITIALS MBEDTLS_OID_AT "\x2B" /**< id-at-initials AttributeType:= {id-at 43} */ -#define MBEDTLS_OID_AT_GENERATION_QUALIFIER \ - MBEDTLS_OID_AT "\x2C" /**< id-at-generationQualifier AttributeType:= {id-at 44} */ + MBEDTLS_OID_AT "\x0B" /**< id-at-organizationalUnitName AttributeType:= {id-at 11} \ + */ +#define MBEDTLS_OID_AT_TITLE MBEDTLS_OID_AT "\x0C" /**< id-at-title AttributeType:= {id-at 12} */ +#define MBEDTLS_OID_AT_POSTAL_ADDRESS MBEDTLS_OID_AT "\x10" /**< id-at-postalAddress AttributeType:= {id-at 16} */ +#define MBEDTLS_OID_AT_POSTAL_CODE MBEDTLS_OID_AT "\x11" /**< id-at-postalCode AttributeType:= {id-at 17} */ +#define MBEDTLS_OID_AT_GIVEN_NAME MBEDTLS_OID_AT "\x2A" /**< id-at-givenName AttributeType:= {id-at 42} */ +#define MBEDTLS_OID_AT_INITIALS MBEDTLS_OID_AT "\x2B" /**< id-at-initials AttributeType:= {id-at 43} */ +#define MBEDTLS_OID_AT_GENERATION_QUALIFIER MBEDTLS_OID_AT "\x2C" /**< id-at-generationQualifier AttributeType:= {id-at 44} */ #define MBEDTLS_OID_AT_UNIQUE_IDENTIFIER \ MBEDTLS_OID_AT "\x2D" /**< id-at-uniqueIdentifier AttributType:= {id-at 45} \ */ @@ -188,7 +186,7 @@ "\x23" /**< id-ce-authorityKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 35 } */ #define MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER \ MBEDTLS_OID_ID_CE \ - "\x0E" /**< id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } */ + "\x0E" /**< id-ce-subjectKeyIdentifier OBJECT IDENTIFIER ::= { id-ce 14 } */ #define MBEDTLS_OID_KEY_USAGE MBEDTLS_OID_ID_CE "\x0F" /**< id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 } */ #define MBEDTLS_OID_CERTIFICATE_POLICIES \ MBEDTLS_OID_ID_CE \ @@ -384,9 +382,8 @@ * Encryption algorithms */ #define MBEDTLS_OID_DES_CBC \ - MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG \ - "\x07" /**< desCBC OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) \ - oiw(14) secsig(3) algorithms(2) 7 } */ + MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG "\x07" /**< desCBC OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) \ + oiw(14) secsig(3) algorithms(2) 7 } */ #define MBEDTLS_OID_DES_EDE3_CBC \ MBEDTLS_OID_RSA_COMPANY \ "\x03\x07" /**< des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) -- \ @@ -440,8 +437,7 @@ /* * PKCS#8 OIDs */ -#define MBEDTLS_OID_PKCS9_CSR_EXT_REQ \ - MBEDTLS_OID_PKCS9 "\x0e" /**< extensionRequest OBJECT IDENTIFIER ::= {pkcs-9 14} */ +#define MBEDTLS_OID_PKCS9_CSR_EXT_REQ MBEDTLS_OID_PKCS9 "\x0e" /**< extensionRequest OBJECT IDENTIFIER ::= {pkcs-9 14} */ /* * PKCS#12 PBE OIDs @@ -765,8 +761,7 @@ int mbedtls_oid_get_cipher_alg(const mbedtls_asn1_buf* oid, mbedtls_cipher_type_ * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_pkcs12_pbe_alg( - const mbedtls_asn1_buf* oid, mbedtls_md_type_t* md_alg, mbedtls_cipher_type_t* cipher_alg); +int mbedtls_oid_get_pkcs12_pbe_alg(const mbedtls_asn1_buf* oid, mbedtls_md_type_t* md_alg, mbedtls_cipher_type_t* cipher_alg); #endif /* MBEDTLS_PKCS12_C */ #ifdef __cplusplus diff --git a/nettls/nettls/pem.h b/nettls/nettls/pem.h index 293eee588fb0c983706aca73b0747fac977ce4df..1f503d0b5c8407bc30dd38b7375cdb84471f3c69 100644 --- a/nettls/nettls/pem.h +++ b/nettls/nettls/pem.h @@ -69,10 +69,9 @@ #define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */ #define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */ #define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */ -#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH \ - -0x1380 /**< Given private key password does not allow for correct decryption. */ -#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */ -#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */ +#define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */ +#define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */ /* \} name */ #ifdef __cplusplus @@ -163,13 +162,7 @@ void mbedtls_pem_free(mbedtls_pem_context* ctx); * \return Another PEM or BASE64 error code on other kinds of failure. */ int mbedtls_pem_write_buffer( - const char* header, - const char* footer, - const unsigned char* der_data, - size_t der_len, - unsigned char* buf, - size_t buf_len, - size_t* olen); + const char* header, const char* footer, const unsigned char* der_data, size_t der_len, unsigned char* buf, size_t buf_len, size_t* olen); #endif /* MBEDTLS_PEM_WRITE_C */ #ifdef __cplusplus diff --git a/nettls/nettls/pk.h b/nettls/nettls/pk.h index e394e5603b27f73f94b613c7ebbeeabcfd7b7508..d152bc4ca36d2344aa14ec38384868217d17487a 100644 --- a/nettls/nettls/pk.h +++ b/nettls/nettls/pk.h @@ -82,15 +82,12 @@ #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00 /**< Invalid key tag or value. */ #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80 /**< Key algorithm is unsupported (only RSA and EC are supported). */ #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00 /**< Private key password can't be empty. */ -#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH \ - -0x3B80 /**< Given private key password does not allow for correct decryption. */ -#define MBEDTLS_ERR_PK_INVALID_PUBKEY \ - -0x3B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */ +#define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80 /**< Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00 /**< The pubkey tag or value is invalid (only RSA and EC are supported). */ #define MBEDTLS_ERR_PK_INVALID_ALG \ - -0x3A80 /**< The algorithm tag or value is invalid. \ - */ -#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE \ - -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */ + -0x3A80 /**< The algorithm tag or value is invalid. \ + */ +#define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */ #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */ #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /**< The buffer contains a valid signature followed by more data. */ @@ -359,12 +356,7 @@ int mbedtls_pk_can_do(const mbedtls_pk_context* ctx, mbedtls_pk_type_t type); * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0 */ int mbedtls_pk_verify( - mbedtls_pk_context* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len); + mbedtls_pk_context* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len); /** * \brief Restartable version of \c mbedtls_pk_verify() @@ -633,8 +625,7 @@ mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context* ctx); * * \return 0 if successful, or a specific PK or PEM error code */ -int mbedtls_pk_parse_key( - mbedtls_pk_context* ctx, const unsigned char* key, size_t keylen, const unsigned char* pwd, size_t pwdlen); +int mbedtls_pk_parse_key(mbedtls_pk_context* ctx, const unsigned char* key, size_t keylen, const unsigned char* pwd, size_t pwdlen); /** \ingroup pk_module */ /** diff --git a/nettls/nettls/pk_internal.h b/nettls/nettls/pk_internal.h index 89b95226f67959dbe7e798f4b1373166b4b4cab9..a39eac4473b607924bf8d5ea8a0113f0fd804c4a 100644 --- a/nettls/nettls/pk_internal.h +++ b/nettls/nettls/pk_internal.h @@ -72,13 +72,7 @@ struct mbedtls_pk_info_t { int (*can_do)(mbedtls_pk_type_t type); /** Verify signature */ - int (*verify_func)( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len); + int (*verify_func)(void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len); /** Make signature */ int (*sign_func)( @@ -94,13 +88,7 @@ struct mbedtls_pk_info_t { #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /** Verify signature (restartable) */ int (*verify_rs_func)( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len, - void* rs_ctx); + void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len, void* rs_ctx); /** Make signature (restartable) */ int (*sign_rs_func)( diff --git a/nettls/nettls/pkcs11.h b/nettls/nettls/pkcs11.h index 3330bf96d2dba63f7d945072b0337a59fbdaea29..dc149dcf081ba356b9ddc6944d52577978dbeb8e 100644 --- a/nettls/nettls/pkcs11.h +++ b/nettls/nettls/pkcs11.h @@ -133,12 +133,7 @@ void mbedtls_pkcs11_priv_key_free(mbedtls_pkcs11_context* priv_key); * an error is thrown. */ int mbedtls_pkcs11_decrypt( - mbedtls_pkcs11_context* ctx, - int mode, - size_t* olen, - const unsigned char* input, - unsigned char* output, - size_t output_max_len); + mbedtls_pkcs11_context* ctx, int mode, size_t* olen, const unsigned char* input, unsigned char* output, size_t output_max_len); /** * \brief Do a private RSA to sign a message digest @@ -157,18 +152,13 @@ int mbedtls_pkcs11_decrypt( * of ctx->N (eg. 128 bytes if RSA-1024 is used). */ int mbedtls_pkcs11_sign( - mbedtls_pkcs11_context* ctx, - int mode, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char* hash, - unsigned char* sig); + mbedtls_pkcs11_context* ctx, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char* hash, unsigned char* sig); /** * SSL/TLS wrappers for PKCS#11 functions */ -static inline int mbedtls_ssl_pkcs11_decrypt( - void* ctx, int mode, size_t* olen, const unsigned char* input, unsigned char* output, size_t output_max_len) +static inline int + mbedtls_ssl_pkcs11_decrypt(void* ctx, int mode, size_t* olen, const unsigned char* input, unsigned char* output, size_t output_max_len) { return mbedtls_pkcs11_decrypt((mbedtls_pkcs11_context*)ctx, mode, olen, input, output, output_max_len); } diff --git a/nettls/nettls/pkcs12.h b/nettls/nettls/pkcs12.h index bf23637aea5353f22a27e9003c060fe46c9a0e62..e7434825bc0e8bf09c9050b2f47cd02a9b295118 100644 --- a/nettls/nettls/pkcs12.h +++ b/nettls/nettls/pkcs12.h @@ -61,12 +61,10 @@ #include -#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */ -#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE \ - -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */ -#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */ -#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH \ - -0x1E00 /**< Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA -0x1F80 /**< Bad input parameters to function. */ +#define MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE -0x1F00 /**< Feature not available, e.g. unsupported encryption scheme. */ +#define MBEDTLS_ERR_PKCS12_PBE_INVALID_FORMAT -0x1E80 /**< PBE ASN.1 data not as expected. */ +#define MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH -0x1E00 /**< Given private key password does not allow for correct decryption. */ #define MBEDTLS_PKCS12_DERIVE_KEY 1 /**< encryption/decryption key */ #define MBEDTLS_PKCS12_DERIVE_IV 2 /**< initialization vector */ @@ -96,13 +94,7 @@ extern "C" { * \return 0 if successful, or a MBEDTLS_ERR_XXX code */ int mbedtls_pkcs12_pbe_sha1_rc4_128( - mbedtls_asn1_buf* pbe_params, - int mode, - const unsigned char* pwd, - size_t pwdlen, - const unsigned char* input, - size_t len, - unsigned char* output); + mbedtls_asn1_buf* pbe_params, int mode, const unsigned char* pwd, size_t pwdlen, const unsigned char* input, size_t len, unsigned char* output); /** * \brief PKCS12 Password Based function (encryption / decryption) diff --git a/nettls/nettls/pkcs5.h b/nettls/nettls/pkcs5.h index f1f01e6fb46d4b1ee605b6dcf70a1f09838e0f7e..eb1d484f47577939618b4288e709a36b3a978807 100644 --- a/nettls/nettls/pkcs5.h +++ b/nettls/nettls/pkcs5.h @@ -68,8 +68,7 @@ */ #define MBEDTLS_ERR_PKCS5_INVALID_FORMAT -0x2f00 /**< Unexpected ASN.1 data. */ #define MBEDTLS_ERR_PKCS5_FEATURE_UNAVAILABLE -0x2e80 /**< Requested encryption or digest alg not available. */ -#define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH \ - -0x2e00 /**< Given private key password does not allow for correct decryption. */ +#define MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH -0x2e00 /**< Given private key password does not allow for correct decryption. */ #define MBEDTLS_PKCS5_DECRYPT 0 #define MBEDTLS_PKCS5_ENCRYPT 1 diff --git a/nettls/nettls/platform.h b/nettls/nettls/platform.h index 130c4343aec9b973d531283bcffb91912e0c89b0..46a586a5499829957f0a41b552d250658d82143c 100644 --- a/nettls/nettls/platform.h +++ b/nettls/nettls/platform.h @@ -321,8 +321,7 @@ extern int (*mbedtls_nv_seed_write)(unsigned char* buf, size_t buf_len); * \return \c 0 on success. */ int mbedtls_platform_set_nv_seed( - int (*nv_seed_read_func)(unsigned char* buf, size_t buf_len), - int (*nv_seed_write_func)(unsigned char* buf, size_t buf_len)); + int (*nv_seed_read_func)(unsigned char* buf, size_t buf_len), int (*nv_seed_write_func)(unsigned char* buf, size_t buf_len)); #else #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) #define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO diff --git a/nettls/nettls/ripemd160.h b/nettls/nettls/ripemd160.h index f3cfda087aa71fdeb73fecbb84810554b705ec86..8ff4f1d75679e54b6c6a5f2d8d67ca5a8333ad56 100644 --- a/nettls/nettls/ripemd160.h +++ b/nettls/nettls/ripemd160.h @@ -171,8 +171,7 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160_starts(mbedtls_ripemd160_context* ctx) * \param input buffer holding the data * \param ilen length of the input data */ -MBEDTLS_DEPRECATED void - mbedtls_ripemd160_update(mbedtls_ripemd160_context* ctx, const unsigned char* input, size_t ilen); +MBEDTLS_DEPRECATED void mbedtls_ripemd160_update(mbedtls_ripemd160_context* ctx, const unsigned char* input, size_t ilen); /** * \brief RIPEMD-160 final digest diff --git a/nettls/nettls/rsa.h b/nettls/nettls/rsa.h index b5bd83887bf7a23e7333c1337dc17c264f3e2161..dc9a0b511b25ef63ad271fa47c58ff59007ec327 100644 --- a/nettls/nettls/rsa.h +++ b/nettls/nettls/rsa.h @@ -228,12 +228,7 @@ void mbedtls_rsa_init(mbedtls_rsa_context* ctx, int padding, int hash_id); * \return A non-zero error code on failure. */ int mbedtls_rsa_import( - mbedtls_rsa_context* ctx, - const mbedtls_mpi* N, - const mbedtls_mpi* P, - const mbedtls_mpi* Q, - const mbedtls_mpi* D, - const mbedtls_mpi* E); + mbedtls_rsa_context* ctx, const mbedtls_mpi* N, const mbedtls_mpi* P, const mbedtls_mpi* Q, const mbedtls_mpi* D, const mbedtls_mpi* E); /** * \brief This function imports core RSA parameters, in raw big-endian @@ -356,8 +351,7 @@ int mbedtls_rsa_complete(mbedtls_rsa_context* ctx); * \return A non-zero return code on any other failure. * */ -int mbedtls_rsa_export( - const mbedtls_rsa_context* ctx, mbedtls_mpi* N, mbedtls_mpi* P, mbedtls_mpi* Q, mbedtls_mpi* D, mbedtls_mpi* E); +int mbedtls_rsa_export(const mbedtls_rsa_context* ctx, mbedtls_mpi* N, mbedtls_mpi* P, mbedtls_mpi* Q, mbedtls_mpi* D, mbedtls_mpi* E); /** * \brief This function exports core parameters of an RSA key @@ -479,12 +473,7 @@ size_t mbedtls_rsa_get_len(const mbedtls_rsa_context* ctx); * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_gen_key( - mbedtls_rsa_context* ctx, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng, - unsigned int nbits, - int exponent); +int mbedtls_rsa_gen_key(mbedtls_rsa_context* ctx, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng, unsigned int nbits, int exponent); /** * \brief This function checks if a context contains at least an RSA @@ -606,11 +595,7 @@ int mbedtls_rsa_public(mbedtls_rsa_context* ctx, const unsigned char* input, uns * */ int mbedtls_rsa_private( - mbedtls_rsa_context* ctx, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng, - const unsigned char* input, - unsigned char* output); + mbedtls_rsa_context* ctx, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng, const unsigned char* input, unsigned char* output); /** * \brief This function adds the message padding, then performs an RSA diff --git a/nettls/nettls/rsa_internal.h b/nettls/nettls/rsa_internal.h index a723a43a2be0206a7c8edf6b045555359beac695..e55b4232b06eedc3f29d66a79c024f328a52b634 100644 --- a/nettls/nettls/rsa_internal.h +++ b/nettls/nettls/rsa_internal.h @@ -118,8 +118,7 @@ extern "C" { * use the helper function \c mbedtls_rsa_validate_params. * */ -int mbedtls_rsa_deduce_primes( - mbedtls_mpi const* N, mbedtls_mpi const* E, mbedtls_mpi const* D, mbedtls_mpi* P, mbedtls_mpi* Q); +int mbedtls_rsa_deduce_primes(mbedtls_mpi const* N, mbedtls_mpi const* E, mbedtls_mpi const* D, mbedtls_mpi* P, mbedtls_mpi* Q); /** * \brief Compute RSA private exponent from @@ -142,8 +141,7 @@ int mbedtls_rsa_deduce_primes( * \note This function does not check whether P and Q are primes. * */ -int mbedtls_rsa_deduce_private_exponent( - mbedtls_mpi const* P, mbedtls_mpi const* Q, mbedtls_mpi const* E, mbedtls_mpi* D); +int mbedtls_rsa_deduce_private_exponent(mbedtls_mpi const* P, mbedtls_mpi const* Q, mbedtls_mpi const* E, mbedtls_mpi* D); /** * \brief Generate RSA-CRT parameters @@ -165,13 +163,7 @@ int mbedtls_rsa_deduce_private_exponent( * prime and whether D is a valid private exponent. * */ -int mbedtls_rsa_deduce_crt( - const mbedtls_mpi* P, - const mbedtls_mpi* Q, - const mbedtls_mpi* D, - mbedtls_mpi* DP, - mbedtls_mpi* DQ, - mbedtls_mpi* QP); +int mbedtls_rsa_deduce_crt(const mbedtls_mpi* P, const mbedtls_mpi* Q, const mbedtls_mpi* D, mbedtls_mpi* DP, mbedtls_mpi* DQ, mbedtls_mpi* QP); /** * \brief Check validity of core RSA parameters @@ -242,12 +234,7 @@ int mbedtls_rsa_validate_params( * parameters (P, -, D, DP, -, -) will check DP = D mod P-1. */ int mbedtls_rsa_validate_crt( - const mbedtls_mpi* P, - const mbedtls_mpi* Q, - const mbedtls_mpi* D, - const mbedtls_mpi* DP, - const mbedtls_mpi* DQ, - const mbedtls_mpi* QP); + const mbedtls_mpi* P, const mbedtls_mpi* Q, const mbedtls_mpi* D, const mbedtls_mpi* DP, const mbedtls_mpi* DQ, const mbedtls_mpi* QP); #ifdef __cplusplus } diff --git a/nettls/nettls/ssl.h b/nettls/nettls/ssl.h index 56770e7cc162eab90d4aa43794272233e7a43cf1..778fe362b08367ee9e0235a5793cf5ef7d5cd251 100644 --- a/nettls/nettls/ssl.h +++ b/nettls/nettls/ssl.h @@ -76,13 +76,11 @@ #if defined(MBEDTLS_ZLIB_SUPPORT) #if defined(MBEDTLS_DEPRECATED_WARNING) -#warning \ - "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library" +#warning "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library" #endif #if defined(MBEDTLS_DEPRECATED_REMOVED) -#error \ - "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set" +#error "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set" #endif #include "zlib.h" @@ -108,54 +106,44 @@ #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */ #define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */ #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE \ - -0x7480 /**< No client certification received from the client, but required by the \ - authentication mode. */ -#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE \ - -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */ -#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */ -#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED \ - -0x7600 /**< The own private key or pre-shared key is not set, but needed. */ -#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */ -#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */ -#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */ -#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */ -#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY \ - -0x7880 /**< The peer notified us that the connection is going to be closed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST \ - -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE \ - -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE \ - -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE \ - -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */ + -0x7480 /**< No client certification received from the client, but required by the \ + authentication mode. */ +#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */ +#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */ +#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */ +#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */ +#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */ +#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */ +#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */ +#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */ #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP \ -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / \ ECDH Read Public. */ #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS \ - -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / \ - ECDH Calculate Secret. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY \ - -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC \ - -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */ -#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */ -#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */ -#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */ -#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */ -#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */ -#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */ -#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET \ - -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */ + -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / \ + ECDH Calculate Secret. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */ +#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */ +#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */ +#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */ +#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */ +#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */ +#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */ +#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */ #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED \ -0x6D80 /**< Session ticket has expired. \ */ #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH \ - -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented \ - EC key) */ + -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented \ + EC key) */ #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */ #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */ #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */ @@ -168,8 +156,8 @@ -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, \ see debug messages). */ #define MBEDTLS_ERR_SSL_WANT_READ \ - -0x6900 /**< No data of requested type currently available on underlying transport. \ - */ + -0x6900 /**< No data of requested type currently available on underlying transport. \ + */ #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */ #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */ #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */ @@ -177,8 +165,8 @@ #define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */ #define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */ #define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING \ - -0x6580 /**< Internal-only message signaling that further message-processing should \ - be done */ + -0x6580 /**< Internal-only message signaling that further message-processing should \ + be done */ #define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500 /**< The asynchronous operation is not completed yet. */ #define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480 /**< Internal-only message signaling that a message arrived early. */ #define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000 /**< A cryptographic operation is in progress. Try again later. */ @@ -692,12 +680,8 @@ typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item; * use \c MBEDTLS_ERR_SSL_xxx error codes except as * directed in the documentation of this callback. */ -typedef int mbedtls_ssl_async_sign_t( - mbedtls_ssl_context* ssl, - mbedtls_x509_crt* cert, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len); +typedef int + mbedtls_ssl_async_sign_t(mbedtls_ssl_context* ssl, mbedtls_x509_crt* cert, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len); /** * \brief Callback type: start external decryption operation. @@ -759,8 +743,7 @@ typedef int mbedtls_ssl_async_sign_t( * use \c MBEDTLS_ERR_SSL_xxx error codes except as * directed in the documentation of this callback. */ -typedef int mbedtls_ssl_async_decrypt_t( - mbedtls_ssl_context* ssl, mbedtls_x509_crt* cert, const unsigned char* input, size_t input_len); +typedef int mbedtls_ssl_async_decrypt_t(mbedtls_ssl_context* ssl, mbedtls_x509_crt* cert, const unsigned char* input, size_t input_len); #endif /* MBEDTLS_X509_CRT_PARSE_C */ /** @@ -805,8 +788,7 @@ typedef int mbedtls_ssl_async_decrypt_t( * use \c MBEDTLS_ERR_SSL_xxx error codes except as * directed in the documentation of this callback. */ -typedef int - mbedtls_ssl_async_resume_t(mbedtls_ssl_context* ssl, unsigned char* output, size_t* output_len, size_t output_size); +typedef int mbedtls_ssl_async_resume_t(mbedtls_ssl_context* ssl, unsigned char* output, size_t* output_len, size_t output_size); /** * \brief Callback type: cancel external operation. @@ -1368,8 +1350,7 @@ void mbedtls_ssl_conf_authmode(mbedtls_ssl_config* conf, int authmode); * \param f_vrfy verification function * \param p_vrfy verification parameter */ -void mbedtls_ssl_conf_verify( - mbedtls_ssl_config* conf, int (*f_vrfy)(void*, mbedtls_x509_crt*, int, uint32_t*), void* p_vrfy); +void mbedtls_ssl_conf_verify(mbedtls_ssl_config* conf, int (*f_vrfy)(void*, mbedtls_x509_crt*, int, uint32_t*), void* p_vrfy); #endif /* MBEDTLS_X509_CRT_PARSE_C */ /** @@ -1395,8 +1376,7 @@ void mbedtls_ssl_conf_rng(mbedtls_ssl_config* conf, int (*f_rng)(void*, unsigned * \param f_dbg debug function * \param p_dbg debug parameter */ -void mbedtls_ssl_conf_dbg( - mbedtls_ssl_config* conf, void (*f_dbg)(void*, int, const char*, int, const char*), void* p_dbg); +void mbedtls_ssl_conf_dbg(mbedtls_ssl_config* conf, void (*f_dbg)(void*, int, const char*, int, const char*), void* p_dbg); /** * \brief Set the underlying BIO callbacks for write, read and @@ -1429,11 +1409,7 @@ void mbedtls_ssl_conf_dbg( * here. */ void mbedtls_ssl_set_bio( - mbedtls_ssl_context* ssl, - void* p_bio, - mbedtls_ssl_send_t* f_send, - mbedtls_ssl_recv_t* f_recv, - mbedtls_ssl_recv_timeout_t* f_recv_timeout); + mbedtls_ssl_context* ssl, void* p_bio, mbedtls_ssl_send_t* f_send, mbedtls_ssl_recv_t* f_recv, mbedtls_ssl_recv_timeout_t* f_recv_timeout); #if defined(MBEDTLS_SSL_PROTO_DTLS) /** @@ -1519,11 +1495,7 @@ void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config* conf, uint32_t timeout); * \note See also the "DTLS tutorial" article in our knowledge base. * https://tls.mbed.org/kb/how-to/dtls-tutorial */ -void mbedtls_ssl_set_timer_cb( - mbedtls_ssl_context* ssl, - void* p_timer, - mbedtls_ssl_set_timer_t* f_set_timer, - mbedtls_ssl_get_timer_t* f_get_timer); +void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context* ssl, void* p_timer, mbedtls_ssl_set_timer_t* f_set_timer, mbedtls_ssl_get_timer_t* f_get_timer); /** * \brief Callback type: generate and write session ticket @@ -1545,12 +1517,7 @@ void mbedtls_ssl_set_timer_cb( * a specific MBEDTLS_ERR_XXX code. */ typedef int mbedtls_ssl_ticket_write_t( - void* p_ticket, - const mbedtls_ssl_session* session, - unsigned char* start, - const unsigned char* end, - size_t* tlen, - uint32_t* lifetime); + void* p_ticket, const mbedtls_ssl_session* session, unsigned char* start, const unsigned char* end, size_t* tlen, uint32_t* lifetime); #if defined(MBEDTLS_SSL_EXPORT_KEYS) /** @@ -1573,8 +1540,7 @@ typedef int mbedtls_ssl_ticket_write_t( * \return 0 if successful, or * a specific MBEDTLS_ERR_XXX code. */ -typedef int mbedtls_ssl_export_keys_t( - void* p_expkey, const unsigned char* ms, const unsigned char* kb, size_t maclen, size_t keylen, size_t ivlen); +typedef int mbedtls_ssl_export_keys_t(void* p_expkey, const unsigned char* ms, const unsigned char* kb, size_t maclen, size_t keylen, size_t ivlen); #endif /* MBEDTLS_SSL_EXPORT_KEYS */ /** @@ -1618,10 +1584,7 @@ typedef int mbedtls_ssl_ticket_parse_t(void* p_ticket, mbedtls_ssl_session* sess * \param p_ticket Context shared by the two callbacks */ void mbedtls_ssl_conf_session_tickets_cb( - mbedtls_ssl_config* conf, - mbedtls_ssl_ticket_write_t* f_ticket_write, - mbedtls_ssl_ticket_parse_t* f_ticket_parse, - void* p_ticket); + mbedtls_ssl_config* conf, mbedtls_ssl_ticket_write_t* f_ticket_write, mbedtls_ssl_ticket_parse_t* f_ticket_parse, void* p_ticket); #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */ #if defined(MBEDTLS_SSL_EXPORT_KEYS) @@ -1635,8 +1598,7 @@ void mbedtls_ssl_conf_session_tickets_cb( * \param f_export_keys Callback for exporting keys * \param p_export_keys Context for the callback */ -void mbedtls_ssl_conf_export_keys_cb( - mbedtls_ssl_config* conf, mbedtls_ssl_export_keys_t* f_export_keys, void* p_export_keys); +void mbedtls_ssl_conf_export_keys_cb(mbedtls_ssl_config* conf, mbedtls_ssl_export_keys_t* f_export_keys, void* p_export_keys); #endif /* MBEDTLS_SSL_EXPORT_KEYS */ #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) @@ -1732,8 +1694,7 @@ void mbedtls_ssl_set_async_operation_data(mbedtls_ssl_context* ssl, void* ctx); * \return The callback must return 0 on success, * or a negative error code. */ -typedef int mbedtls_ssl_cookie_write_t( - void* ctx, unsigned char** p, unsigned char* end, const unsigned char* info, size_t ilen); +typedef int mbedtls_ssl_cookie_write_t(void* ctx, unsigned char** p, unsigned char* end, const unsigned char* info, size_t ilen); /** * \brief Callback type: verify a cookie @@ -1748,8 +1709,7 @@ typedef int mbedtls_ssl_cookie_write_t( * \return The callback must return 0 if cookie is valid, * or a negative error code. */ -typedef int mbedtls_ssl_cookie_check_t( - void* ctx, const unsigned char* cookie, size_t clen, const unsigned char* info, size_t ilen); +typedef int mbedtls_ssl_cookie_check_t(void* ctx, const unsigned char* cookie, size_t clen, const unsigned char* info, size_t ilen); #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C) /** @@ -1781,10 +1741,7 @@ typedef int mbedtls_ssl_cookie_check_t( * \param p_cookie Context for both callbacks */ void mbedtls_ssl_conf_dtls_cookies( - mbedtls_ssl_config* conf, - mbedtls_ssl_cookie_write_t* f_cookie_write, - mbedtls_ssl_cookie_check_t* f_cookie_check, - void* p_cookie); + mbedtls_ssl_config* conf, mbedtls_ssl_cookie_write_t* f_cookie_write, mbedtls_ssl_cookie_check_t* f_cookie_check, void* p_cookie); /** * \brief Set client's transport-level identification info. @@ -1960,10 +1917,7 @@ void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config* conf, uint32_t min, * \param f_set_cache session set callback */ void mbedtls_ssl_conf_session_cache( - mbedtls_ssl_config* conf, - void* p_cache, - int (*f_get_cache)(void*, mbedtls_ssl_session*), - int (*f_set_cache)(void*, const mbedtls_ssl_session*)); + mbedtls_ssl_config* conf, void* p_cache, int (*f_get_cache)(void*, mbedtls_ssl_session*), int (*f_set_cache)(void*, const mbedtls_ssl_session*)); #endif /* MBEDTLS_SSL_SRV_C */ #if defined(MBEDTLS_SSL_CLI_C) @@ -2109,11 +2063,7 @@ int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config* conf, mbedtls_x509_crt* own_ce * \return 0 if successful or MBEDTLS_ERR_SSL_ALLOC_FAILED */ int mbedtls_ssl_conf_psk( - mbedtls_ssl_config* conf, - const unsigned char* psk, - size_t psk_len, - const unsigned char* psk_identity, - size_t psk_identity_len); + mbedtls_ssl_config* conf, const unsigned char* psk, size_t psk_len, const unsigned char* psk_identity, size_t psk_identity_len); /** * \brief Set the Pre Shared Key (PSK) for the current handshake @@ -2153,8 +2103,7 @@ int mbedtls_ssl_set_hs_psk(mbedtls_ssl_context* ssl, const unsigned char* psk, s * \param f_psk PSK identity function * \param p_psk PSK identity parameter */ -void mbedtls_ssl_conf_psk_cb( - mbedtls_ssl_config* conf, int (*f_psk)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_psk); +void mbedtls_ssl_conf_psk_cb(mbedtls_ssl_config* conf, int (*f_psk)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_psk); #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */ #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C) @@ -2197,8 +2146,7 @@ MBEDTLS_DEPRECATED int mbedtls_ssl_conf_dh_param(mbedtls_ssl_config* conf, const * * \return 0 if successful */ -int mbedtls_ssl_conf_dh_param_bin( - mbedtls_ssl_config* conf, const unsigned char* dhm_P, size_t P_len, const unsigned char* dhm_G, size_t G_len); +int mbedtls_ssl_conf_dh_param_bin(mbedtls_ssl_config* conf, const unsigned char* dhm_P, size_t P_len, const unsigned char* dhm_G, size_t G_len); /** * \brief Set the Diffie-Hellman public P and G values, @@ -2362,8 +2310,7 @@ void mbedtls_ssl_set_hs_authmode(mbedtls_ssl_context* ssl, int authmode); * \param f_sni verification function * \param p_sni verification parameter */ -void mbedtls_ssl_conf_sni( - mbedtls_ssl_config* conf, int (*f_sni)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_sni); +void mbedtls_ssl_conf_sni(mbedtls_ssl_config* conf, int (*f_sni)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_sni); #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */ #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) diff --git a/nettls/nettls/ssl_ciphersuites.h b/nettls/nettls/ssl_ciphersuites.h index bf49c1cdd16660f00c0983381c3d34020c4c3ac3..f7088785eb77d872b6235c5e8bd878f2f5178770 100644 --- a/nettls/nettls/ssl_ciphersuites.h +++ b/nettls/nettls/ssl_ciphersuites.h @@ -330,17 +330,16 @@ typedef enum { } mbedtls_key_exchange_type_t; /* Key exchanges using a certificate */ -#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ - || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) \ - || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) \ - || defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ + || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) \ + || defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) #define MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED #endif /* Key exchanges allowing client certificate requests */ -#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ - || defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ - || defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) \ + || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) \ + || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) #define MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED #endif @@ -356,8 +355,8 @@ typedef enum { #endif /* Key exchanges that don't involve ephemeral keys */ -#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) \ - || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) \ + || defined(MBEDTLS_KEY_EXCHANGE__SOME__ECDH_ENABLED) #define MBEDTLS_KEY_EXCHANGE__SOME_NON_PFS__ENABLED #endif @@ -369,8 +368,8 @@ typedef enum { #endif /* Key exchanges using a PSK */ -#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) \ - || defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) +#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) \ + || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) #define MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED #endif diff --git a/nettls/nettls/ssl_internal.h b/nettls/nettls/ssl_internal.h index 085258f026cddb50102b1bb3a88f78c742cfe39c..8b91d3b7c43c3b41b236cf0f9ce5826359689ddd 100644 --- a/nettls/nettls/ssl_internal.h +++ b/nettls/nettls/ssl_internal.h @@ -148,8 +148,7 @@ #define MBEDTLS_SSL_RETRANS_FINISHED 3 /* This macro determines whether CBC is supported. */ -#if defined(MBEDTLS_CIPHER_MODE_CBC) \ - && (defined(MBEDTLS_AES_C) || defined(MBEDTLS_CAMELLIA_C) || defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_DES_C)) +#if defined(MBEDTLS_CIPHER_MODE_CBC) && (defined(MBEDTLS_AES_C) || defined(MBEDTLS_CAMELLIA_C) || defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_DES_C)) #define MBEDTLS_SSL_SOME_SUITES_USE_CBC #endif @@ -192,8 +191,7 @@ #define MBEDTLS_SSL_PADDING_ADD 0 #endif -#define MBEDTLS_SSL_PAYLOAD_OVERHEAD \ - (MBEDTLS_SSL_COMPRESSION_ADD + MBEDTLS_MAX_IV_LENGTH + MBEDTLS_SSL_MAC_ADD + MBEDTLS_SSL_PADDING_ADD) +#define MBEDTLS_SSL_PAYLOAD_OVERHEAD (MBEDTLS_SSL_COMPRESSION_ADD + MBEDTLS_MAX_IV_LENGTH + MBEDTLS_SSL_MAC_ADD + MBEDTLS_SSL_PADDING_ADD) #define MBEDTLS_SSL_IN_PAYLOAD_LEN (MBEDTLS_SSL_PAYLOAD_OVERHEAD + (MBEDTLS_SSL_IN_CONTENT_LEN)) @@ -207,8 +205,7 @@ (the lesser of both sizes, if they are unequal.) */ #define MBEDTLS_TLS_EXT_ADV_CONTENT_LEN \ - ((MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN) ? (MBEDTLS_SSL_OUT_CONTENT_LEN) \ - : (MBEDTLS_SSL_IN_CONTENT_LEN)) + ((MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN) ? (MBEDTLS_SSL_OUT_CONTENT_LEN) : (MBEDTLS_SSL_IN_CONTENT_LEN)) /* Maximum size in bytes of list in sig-hash algorithm ext., RFC 5246 */ #define MBEDTLS_SSL_MAX_SIG_HASH_ALG_LIST_LEN 65534 @@ -657,6 +654,15 @@ int mbedtls_ssl_write_handshake_msg(mbedtls_ssl_context* ssl); int mbedtls_ssl_write_record(mbedtls_ssl_context* ssl, uint8_t force_flush); int mbedtls_ssl_flush_output(mbedtls_ssl_context* ssl); + +int ssl_parse_record_header(mbedtls_ssl_context* ssl); +int ssl_encrypt_buf(mbedtls_ssl_context* ssl); +int ssl_prepare_record_content(mbedtls_ssl_context* ssl); +int ssl_decrypt_buf(mbedtls_ssl_context* ssl); +int ssl_get_remaining_space_in_datagram(mbedtls_ssl_context const* ssl); +int ssl_get_remaining_payload_in_datagram(mbedtls_ssl_context const* ssl); + + int mbedtls_ssl_parse_certificate(mbedtls_ssl_context* ssl); int mbedtls_ssl_write_certificate(mbedtls_ssl_context* ssl); @@ -724,8 +730,7 @@ static inline mbedtls_x509_crt* mbedtls_ssl_own_cert(mbedtls_ssl_context* ssl) * * Return 0 if everything is OK, -1 if not. */ -int mbedtls_ssl_check_cert_usage( - const mbedtls_x509_crt* cert, const mbedtls_ssl_ciphersuite_t* ciphersuite, int cert_endpoint, uint32_t* flags); +int mbedtls_ssl_check_cert_usage(const mbedtls_x509_crt* cert, const mbedtls_ssl_ciphersuite_t* ciphersuite, int cert_endpoint, uint32_t* flags); #endif /* MBEDTLS_X509_CRT_PARSE_C */ void mbedtls_ssl_write_version(int major, int minor, int transport, unsigned char ver[2]); @@ -786,19 +791,13 @@ static inline int mbedtls_ssl_safer_memcmp(const void* a, const void* b, size_t } #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) -int mbedtls_ssl_get_key_exchange_md_ssl_tls( - mbedtls_ssl_context* ssl, unsigned char* output, unsigned char* data, size_t data_len); +int mbedtls_ssl_get_key_exchange_md_ssl_tls(mbedtls_ssl_context* ssl, unsigned char* output, unsigned char* data, size_t data_len); #endif /* MBEDTLS_SSL_PROTO_SSL3 || MBEDTLS_SSL_PROTO_TLS1 || \ MBEDTLS_SSL_PROTO_TLS1_1 */ #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2) int mbedtls_ssl_get_key_exchange_md_tls1_2( - mbedtls_ssl_context* ssl, - unsigned char* hash, - size_t* hashlen, - unsigned char* data, - size_t data_len, - mbedtls_md_type_t md_alg); + mbedtls_ssl_context* ssl, unsigned char* hash, size_t* hashlen, unsigned char* data, size_t data_len, mbedtls_md_type_t md_alg); #endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \ MBEDTLS_SSL_PROTO_TLS1_2 */ @@ -866,12 +865,7 @@ int mbedtls_ssl_cf_hmac( * \param len The number of bytes to copy. */ void mbedtls_ssl_cf_memcpy_offset( - unsigned char* dst, - const unsigned char* src_base, - size_t offset_secret, - size_t offset_min, - size_t offset_max, - size_t len); + unsigned char* dst, const unsigned char* src_base, size_t offset_secret, size_t offset_min, size_t offset_max, size_t len); #endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ #ifdef __cplusplus diff --git a/nettls/nettls/ssl_ticket.h b/nettls/nettls/ssl_ticket.h index 190f44347eae40876acd09b339a493971f48e033..bd278387ec4e6807cc3411d29f1d5e14a561978f 100644 --- a/nettls/nettls/ssl_ticket.h +++ b/nettls/nettls/ssl_ticket.h @@ -131,11 +131,7 @@ void mbedtls_ssl_ticket_init(mbedtls_ssl_ticket_context* ctx); * or a specific MBEDTLS_ERR_XXX error code */ int mbedtls_ssl_ticket_setup( - mbedtls_ssl_ticket_context* ctx, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng, - mbedtls_cipher_type_t cipher, - uint32_t lifetime); + mbedtls_ssl_ticket_context* ctx, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng, mbedtls_cipher_type_t cipher, uint32_t lifetime); /** * \brief Implementation of the ticket write callback diff --git a/nettls/nettls/x509.h b/nettls/nettls/x509.h index a8caa8317ee872407da5320f7b234619fe25e63b..4ffc599830f88a85f273fe4dafa5f1c3c4692edc 100644 --- a/nettls/nettls/x509.h +++ b/nettls/nettls/x509.h @@ -83,9 +83,8 @@ * \name X509 Error codes * \{ */ -#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE \ - -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */ -#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 /**< Requested OID is unknown. */ +#define MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE -0x2080 /**< Unavailable feature, e.g. RSA hashing/encryption combination. */ +#define MBEDTLS_ERR_X509_UNKNOWN_OID -0x2100 /**< Requested OID is unknown. */ #define MBEDTLS_ERR_X509_INVALID_FORMAT \ -0x2180 /**< The CRT/CRL/CSR format is invalid, e.g. different type expected. \ */ @@ -104,8 +103,8 @@ -0x2680 /**< Signature algorithms do not match. (see \c ::mbedtls_x509_crt sig_oid) \ */ #define MBEDTLS_ERR_X509_CERT_VERIFY_FAILED \ - -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check \ - failed. */ + -0x2700 /**< Certificate verification failed, e.g. CRL, CA or signature check \ + failed. */ #define MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT -0x2780 /**< Format not recognized as DER or PEM. */ #define MBEDTLS_ERR_X509_BAD_INPUT_DATA -0x2800 /**< Input invalid. */ #define MBEDTLS_ERR_X509_ALLOC_FAILED -0x2880 /**< Allocation of memory failed. */ @@ -123,10 +122,9 @@ * \{ */ /* Reminder: update x509_crt_verify_strings[] in library/x509_crt.c */ -#define MBEDTLS_X509_BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */ -#define MBEDTLS_X509_BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */ -#define MBEDTLS_X509_BADCERT_CN_MISMATCH \ - 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */ +#define MBEDTLS_X509_BADCERT_EXPIRED 0x01 /**< The certificate validity has expired. */ +#define MBEDTLS_X509_BADCERT_REVOKED 0x02 /**< The certificate has been revoked (is on a CRL). */ +#define MBEDTLS_X509_BADCERT_CN_MISMATCH 0x04 /**< The certificate Common Name (CN) does not match with the expected CN. */ #define MBEDTLS_X509_BADCERT_NOT_TRUSTED 0x08 /**< The certificate is not correctly signed by the trusted CA. */ #define MBEDTLS_X509_BADCRL_NOT_TRUSTED 0x10 /**< The CRL is not correctly signed by the trusted CA. */ #define MBEDTLS_X509_BADCRL_EXPIRED 0x20 /**< The CRL is expired. */ @@ -331,39 +329,23 @@ int mbedtls_x509_get_name(unsigned char** p, const unsigned char* end, mbedtls_x int mbedtls_x509_get_alg_null(unsigned char** p, const unsigned char* end, mbedtls_x509_buf* alg); int mbedtls_x509_get_alg(unsigned char** p, const unsigned char* end, mbedtls_x509_buf* alg, mbedtls_x509_buf* params); #if defined(MBEDTLS_X509_RSASSA_PSS_SUPPORT) -int mbedtls_x509_get_rsassa_pss_params( - const mbedtls_x509_buf* params, mbedtls_md_type_t* md_alg, mbedtls_md_type_t* mgf_md, int* salt_len); +int mbedtls_x509_get_rsassa_pss_params(const mbedtls_x509_buf* params, mbedtls_md_type_t* md_alg, mbedtls_md_type_t* mgf_md, int* salt_len); #endif int mbedtls_x509_get_sig(unsigned char** p, const unsigned char* end, mbedtls_x509_buf* sig); int mbedtls_x509_get_sig_alg( - const mbedtls_x509_buf* sig_oid, - const mbedtls_x509_buf* sig_params, - mbedtls_md_type_t* md_alg, - mbedtls_pk_type_t* pk_alg, - void** sig_opts); + const mbedtls_x509_buf* sig_oid, const mbedtls_x509_buf* sig_params, mbedtls_md_type_t* md_alg, mbedtls_pk_type_t* pk_alg, void** sig_opts); int mbedtls_x509_get_time(unsigned char** p, const unsigned char* end, mbedtls_x509_time* t); int mbedtls_x509_get_serial(unsigned char** p, const unsigned char* end, mbedtls_x509_buf* serial); int mbedtls_x509_get_ext(unsigned char** p, const unsigned char* end, mbedtls_x509_buf* ext, int tag); int mbedtls_x509_sig_alg_gets( - char* buf, - size_t size, - const mbedtls_x509_buf* sig_oid, - mbedtls_pk_type_t pk_alg, - mbedtls_md_type_t md_alg, - const void* sig_opts); + char* buf, size_t size, const mbedtls_x509_buf* sig_oid, mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, const void* sig_opts); int mbedtls_x509_key_size_helper(char* buf, size_t buf_size, const char* name); int mbedtls_x509_string_to_names(mbedtls_asn1_named_data** head, const char* name); int mbedtls_x509_set_extension( - mbedtls_asn1_named_data** head, - const char* oid, - size_t oid_len, - int critical, - const unsigned char* val, - size_t val_len); + mbedtls_asn1_named_data** head, const char* oid, size_t oid_len, int critical, const unsigned char* val, size_t val_len); int mbedtls_x509_write_extensions(unsigned char** p, unsigned char* start, mbedtls_asn1_named_data* first); int mbedtls_x509_write_names(unsigned char** p, unsigned char* start, mbedtls_asn1_named_data* first); -int mbedtls_x509_write_sig( - unsigned char** p, unsigned char* start, const char* oid, size_t oid_len, unsigned char* sig, size_t size); +int mbedtls_x509_write_sig(unsigned char** p, unsigned char* start, const char* oid, size_t oid_len, unsigned char* sig, size_t size); #define MBEDTLS_X509_SAFE_SNPRINTF \ do { \ diff --git a/nettls/nettls/x509_crt.h b/nettls/nettls/x509_crt.h index e10652a6cfbd8286df6f2c0bb47b422db98c5094..8076fbff93d67dabca26127db9c51709e81a65c2 100644 --- a/nettls/nettls/x509_crt.h +++ b/nettls/nettls/x509_crt.h @@ -680,12 +680,7 @@ void mbedtls_x509write_crt_set_md_alg(mbedtls_x509write_cert* ctx, mbedtls_md_ty * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED */ int mbedtls_x509write_crt_set_extension( - mbedtls_x509write_cert* ctx, - const char* oid, - size_t oid_len, - int critical, - const unsigned char* val, - size_t val_len); + mbedtls_x509write_cert* ctx, const char* oid, size_t oid_len, int critical, const unsigned char* val, size_t val_len); /** * \brief Set the basicConstraints extension for a CRT @@ -775,12 +770,7 @@ void mbedtls_x509write_crt_free(mbedtls_x509write_cert* ctx); * for countermeasures against timing attacks). * ECDSA signatures always require a non-NULL f_rng. */ -int mbedtls_x509write_crt_der( - mbedtls_x509write_cert* ctx, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); +int mbedtls_x509write_crt_der(mbedtls_x509write_cert* ctx, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #if defined(MBEDTLS_PEM_WRITE_C) /** @@ -799,12 +789,7 @@ int mbedtls_x509write_crt_der( * for countermeasures against timing attacks). * ECDSA signatures always require a non-NULL f_rng. */ -int mbedtls_x509write_crt_pem( - mbedtls_x509write_cert* ctx, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); +int mbedtls_x509write_crt_pem(mbedtls_x509write_cert* ctx, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #endif /* MBEDTLS_PEM_WRITE_C */ #endif /* MBEDTLS_X509_CRT_WRITE_C */ diff --git a/nettls/nettls/x509_csr.h b/nettls/nettls/x509_csr.h index f28b35c1469bde2681bdf83bf307515073a50e03..52d66d597435810b0d66076aa14a4b3bed841734 100644 --- a/nettls/nettls/x509_csr.h +++ b/nettls/nettls/x509_csr.h @@ -262,8 +262,7 @@ int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr* ctx, unsigned * * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED */ -int mbedtls_x509write_csr_set_extension( - mbedtls_x509write_csr* ctx, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len); +int mbedtls_x509write_csr_set_extension(mbedtls_x509write_csr* ctx, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len); /** * \brief Free the contents of a CSR context @@ -293,12 +292,7 @@ void mbedtls_x509write_csr_free(mbedtls_x509write_csr* ctx); * for countermeasures against timing attacks). * ECDSA signatures always require a non-NULL f_rng. */ -int mbedtls_x509write_csr_der( - mbedtls_x509write_csr* ctx, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); +int mbedtls_x509write_csr_der(mbedtls_x509write_csr* ctx, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #if defined(MBEDTLS_PEM_WRITE_C) /** @@ -318,12 +312,7 @@ int mbedtls_x509write_csr_der( * for countermeasures against timing attacks). * ECDSA signatures always require a non-NULL f_rng. */ -int mbedtls_x509write_csr_pem( - mbedtls_x509write_csr* ctx, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng); +int mbedtls_x509write_csr_pem(mbedtls_x509write_csr* ctx, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); #endif /* MBEDTLS_PEM_WRITE_C */ #endif /* MBEDTLS_X509_CSR_WRITE_C */ diff --git a/nettls/nettls/xtea.h b/nettls/nettls/xtea.h index 709595c091fe90be97f4aeeacaa30b318ecee561..a752f02f3ffb7a9458a0a47da2d129beab2827d1 100644 --- a/nettls/nettls/xtea.h +++ b/nettls/nettls/xtea.h @@ -138,12 +138,7 @@ int mbedtls_xtea_crypt_ecb(mbedtls_xtea_context* ctx, int mode, const unsigned c * MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0 */ int mbedtls_xtea_crypt_cbc( - mbedtls_xtea_context* ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char* input, - unsigned char* output); + mbedtls_xtea_context* ctx, int mode, size_t length, unsigned char iv[8], const unsigned char* input, unsigned char* output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_SELF_TEST) diff --git a/nettls/ssl/aes.c b/nettls/ssl/aes.c index 589ce819bb2581524179f923f6026007378ea121..f4a038841b84675df7531f69b982a34157f6e869 100644 --- a/nettls/ssl/aes.c +++ b/nettls/ssl/aes.c @@ -64,7 +64,6 @@ #include "nettls/platform.h" #include "nettls/platform_util.h" - #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "nettls/platform.h" @@ -77,36 +76,30 @@ #if !defined(MBEDTLS_AES_ALT) /* Parameter validation macros based on platform_util.h */ -#define AES_VALIDATE_RET( cond ) \ - MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_AES_BAD_INPUT_DATA ) -#define AES_VALIDATE( cond ) \ - MBEDTLS_INTERNAL_VALIDATE( cond ) +#define AES_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_AES_BAD_INPUT_DATA) +#define AES_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) /* * 32-bit integer manipulation macros (little endian) */ #ifndef GET_UINT32_LE -#define GET_UINT32_LE(n,b,i) \ -{ \ - (n) = ( (uint32_t) (b)[(i) ] ) \ - | ( (uint32_t) (b)[(i) + 1] << 8 ) \ - | ( (uint32_t) (b)[(i) + 2] << 16 ) \ - | ( (uint32_t) (b)[(i) + 3] << 24 ); \ -} +#define GET_UINT32_LE(n, b, i) \ + { \ + (n) = ((uint32_t)(b)[(i)]) | ((uint32_t)(b)[(i) + 1] << 8) | ((uint32_t)(b)[(i) + 2] << 16) | ((uint32_t)(b)[(i) + 3] << 24); \ + } #endif #ifndef PUT_UINT32_LE -#define PUT_UINT32_LE(n,b,i) \ -{ \ - (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \ - (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \ - (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \ - (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \ -} +#define PUT_UINT32_LE(n, b, i) \ + { \ + (b)[(i)] = (unsigned char)(((n)) & 0xFF); \ + (b)[(i) + 1] = (unsigned char)(((n) >> 8) & 0xFF); \ + (b)[(i) + 2] = (unsigned char)(((n) >> 16) & 0xFF); \ + (b)[(i) + 3] = (unsigned char)(((n) >> 24) & 0xFF); \ + } #endif -#if defined(MBEDTLS_PADLOCK_C) && \ - ( defined(MBEDTLS_HAVE_X86) || defined(MBEDTLS_PADLOCK_ALIGN16) ) +#if defined(MBEDTLS_PADLOCK_C) && (defined(MBEDTLS_HAVE_X86) || defined(MBEDTLS_PADLOCK_ALIGN16)) static int aes_padlock_ace = -1; #endif @@ -114,128 +107,78 @@ static int aes_padlock_ace = -1; /* * Forward S-box */ -static const unsigned char FSb[256] = -{ - 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, - 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, - 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, - 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, - 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, - 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, - 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, - 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, - 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, - 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, - 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, - 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, - 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, - 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, - 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, - 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, - 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, - 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, - 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, - 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, - 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, - 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, - 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, - 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, - 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, - 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, - 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, - 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, - 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, - 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, - 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, - 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 -}; +static const unsigned char FSb[256] = { + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, + 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, + 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, + 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, + 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16}; /* * Forward tables */ #define FT \ \ - V(A5,63,63,C6), V(84,7C,7C,F8), V(99,77,77,EE), V(8D,7B,7B,F6), \ - V(0D,F2,F2,FF), V(BD,6B,6B,D6), V(B1,6F,6F,DE), V(54,C5,C5,91), \ - V(50,30,30,60), V(03,01,01,02), V(A9,67,67,CE), V(7D,2B,2B,56), \ - V(19,FE,FE,E7), V(62,D7,D7,B5), V(E6,AB,AB,4D), V(9A,76,76,EC), \ - V(45,CA,CA,8F), V(9D,82,82,1F), V(40,C9,C9,89), V(87,7D,7D,FA), \ - V(15,FA,FA,EF), V(EB,59,59,B2), V(C9,47,47,8E), V(0B,F0,F0,FB), \ - V(EC,AD,AD,41), V(67,D4,D4,B3), V(FD,A2,A2,5F), V(EA,AF,AF,45), \ - V(BF,9C,9C,23), V(F7,A4,A4,53), V(96,72,72,E4), V(5B,C0,C0,9B), \ - V(C2,B7,B7,75), V(1C,FD,FD,E1), V(AE,93,93,3D), V(6A,26,26,4C), \ - V(5A,36,36,6C), V(41,3F,3F,7E), V(02,F7,F7,F5), V(4F,CC,CC,83), \ - V(5C,34,34,68), V(F4,A5,A5,51), V(34,E5,E5,D1), V(08,F1,F1,F9), \ - V(93,71,71,E2), V(73,D8,D8,AB), V(53,31,31,62), V(3F,15,15,2A), \ - V(0C,04,04,08), V(52,C7,C7,95), V(65,23,23,46), V(5E,C3,C3,9D), \ - V(28,18,18,30), V(A1,96,96,37), V(0F,05,05,0A), V(B5,9A,9A,2F), \ - V(09,07,07,0E), V(36,12,12,24), V(9B,80,80,1B), V(3D,E2,E2,DF), \ - V(26,EB,EB,CD), V(69,27,27,4E), V(CD,B2,B2,7F), V(9F,75,75,EA), \ - V(1B,09,09,12), V(9E,83,83,1D), V(74,2C,2C,58), V(2E,1A,1A,34), \ - V(2D,1B,1B,36), V(B2,6E,6E,DC), V(EE,5A,5A,B4), V(FB,A0,A0,5B), \ - V(F6,52,52,A4), V(4D,3B,3B,76), V(61,D6,D6,B7), V(CE,B3,B3,7D), \ - V(7B,29,29,52), V(3E,E3,E3,DD), V(71,2F,2F,5E), V(97,84,84,13), \ - V(F5,53,53,A6), V(68,D1,D1,B9), V(00,00,00,00), V(2C,ED,ED,C1), \ - V(60,20,20,40), V(1F,FC,FC,E3), V(C8,B1,B1,79), V(ED,5B,5B,B6), \ - V(BE,6A,6A,D4), V(46,CB,CB,8D), V(D9,BE,BE,67), V(4B,39,39,72), \ - V(DE,4A,4A,94), V(D4,4C,4C,98), V(E8,58,58,B0), V(4A,CF,CF,85), \ - V(6B,D0,D0,BB), V(2A,EF,EF,C5), V(E5,AA,AA,4F), V(16,FB,FB,ED), \ - V(C5,43,43,86), V(D7,4D,4D,9A), V(55,33,33,66), V(94,85,85,11), \ - V(CF,45,45,8A), V(10,F9,F9,E9), V(06,02,02,04), V(81,7F,7F,FE), \ - V(F0,50,50,A0), V(44,3C,3C,78), V(BA,9F,9F,25), V(E3,A8,A8,4B), \ - V(F3,51,51,A2), V(FE,A3,A3,5D), V(C0,40,40,80), V(8A,8F,8F,05), \ - V(AD,92,92,3F), V(BC,9D,9D,21), V(48,38,38,70), V(04,F5,F5,F1), \ - V(DF,BC,BC,63), V(C1,B6,B6,77), V(75,DA,DA,AF), V(63,21,21,42), \ - V(30,10,10,20), V(1A,FF,FF,E5), V(0E,F3,F3,FD), V(6D,D2,D2,BF), \ - V(4C,CD,CD,81), V(14,0C,0C,18), V(35,13,13,26), V(2F,EC,EC,C3), \ - V(E1,5F,5F,BE), V(A2,97,97,35), V(CC,44,44,88), V(39,17,17,2E), \ - V(57,C4,C4,93), V(F2,A7,A7,55), V(82,7E,7E,FC), V(47,3D,3D,7A), \ - V(AC,64,64,C8), V(E7,5D,5D,BA), V(2B,19,19,32), V(95,73,73,E6), \ - V(A0,60,60,C0), V(98,81,81,19), V(D1,4F,4F,9E), V(7F,DC,DC,A3), \ - V(66,22,22,44), V(7E,2A,2A,54), V(AB,90,90,3B), V(83,88,88,0B), \ - V(CA,46,46,8C), V(29,EE,EE,C7), V(D3,B8,B8,6B), V(3C,14,14,28), \ - V(79,DE,DE,A7), V(E2,5E,5E,BC), V(1D,0B,0B,16), V(76,DB,DB,AD), \ - V(3B,E0,E0,DB), V(56,32,32,64), V(4E,3A,3A,74), V(1E,0A,0A,14), \ - V(DB,49,49,92), V(0A,06,06,0C), V(6C,24,24,48), V(E4,5C,5C,B8), \ - V(5D,C2,C2,9F), V(6E,D3,D3,BD), V(EF,AC,AC,43), V(A6,62,62,C4), \ - V(A8,91,91,39), V(A4,95,95,31), V(37,E4,E4,D3), V(8B,79,79,F2), \ - V(32,E7,E7,D5), V(43,C8,C8,8B), V(59,37,37,6E), V(B7,6D,6D,DA), \ - V(8C,8D,8D,01), V(64,D5,D5,B1), V(D2,4E,4E,9C), V(E0,A9,A9,49), \ - V(B4,6C,6C,D8), V(FA,56,56,AC), V(07,F4,F4,F3), V(25,EA,EA,CF), \ - V(AF,65,65,CA), V(8E,7A,7A,F4), V(E9,AE,AE,47), V(18,08,08,10), \ - V(D5,BA,BA,6F), V(88,78,78,F0), V(6F,25,25,4A), V(72,2E,2E,5C), \ - V(24,1C,1C,38), V(F1,A6,A6,57), V(C7,B4,B4,73), V(51,C6,C6,97), \ - V(23,E8,E8,CB), V(7C,DD,DD,A1), V(9C,74,74,E8), V(21,1F,1F,3E), \ - V(DD,4B,4B,96), V(DC,BD,BD,61), V(86,8B,8B,0D), V(85,8A,8A,0F), \ - V(90,70,70,E0), V(42,3E,3E,7C), V(C4,B5,B5,71), V(AA,66,66,CC), \ - V(D8,48,48,90), V(05,03,03,06), V(01,F6,F6,F7), V(12,0E,0E,1C), \ - V(A3,61,61,C2), V(5F,35,35,6A), V(F9,57,57,AE), V(D0,B9,B9,69), \ - V(91,86,86,17), V(58,C1,C1,99), V(27,1D,1D,3A), V(B9,9E,9E,27), \ - V(38,E1,E1,D9), V(13,F8,F8,EB), V(B3,98,98,2B), V(33,11,11,22), \ - V(BB,69,69,D2), V(70,D9,D9,A9), V(89,8E,8E,07), V(A7,94,94,33), \ - V(B6,9B,9B,2D), V(22,1E,1E,3C), V(92,87,87,15), V(20,E9,E9,C9), \ - V(49,CE,CE,87), V(FF,55,55,AA), V(78,28,28,50), V(7A,DF,DF,A5), \ - V(8F,8C,8C,03), V(F8,A1,A1,59), V(80,89,89,09), V(17,0D,0D,1A), \ - V(DA,BF,BF,65), V(31,E6,E6,D7), V(C6,42,42,84), V(B8,68,68,D0), \ - V(C3,41,41,82), V(B0,99,99,29), V(77,2D,2D,5A), V(11,0F,0F,1E), \ - V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C) - -#define V(a,b,c,d) 0x##a##b##c##d -static const uint32_t FT0[256] = { FT }; + V(A5, 63, 63, C6), V(84, 7C, 7C, F8), V(99, 77, 77, EE), V(8D, 7B, 7B, F6), V(0D, F2, F2, FF), V(BD, 6B, 6B, D6), V(B1, 6F, 6F, DE), \ + V(54, C5, C5, 91), V(50, 30, 30, 60), V(03, 01, 01, 02), V(A9, 67, 67, CE), V(7D, 2B, 2B, 56), V(19, FE, FE, E7), V(62, D7, D7, B5), \ + V(E6, AB, AB, 4D), V(9A, 76, 76, EC), V(45, CA, CA, 8F), V(9D, 82, 82, 1F), V(40, C9, C9, 89), V(87, 7D, 7D, FA), V(15, FA, FA, EF), \ + V(EB, 59, 59, B2), V(C9, 47, 47, 8E), V(0B, F0, F0, FB), V(EC, AD, AD, 41), V(67, D4, D4, B3), V(FD, A2, A2, 5F), V(EA, AF, AF, 45), \ + V(BF, 9C, 9C, 23), V(F7, A4, A4, 53), V(96, 72, 72, E4), V(5B, C0, C0, 9B), V(C2, B7, B7, 75), V(1C, FD, FD, E1), V(AE, 93, 93, 3D), \ + V(6A, 26, 26, 4C), V(5A, 36, 36, 6C), V(41, 3F, 3F, 7E), V(02, F7, F7, F5), V(4F, CC, CC, 83), V(5C, 34, 34, 68), V(F4, A5, A5, 51), \ + V(34, E5, E5, D1), V(08, F1, F1, F9), V(93, 71, 71, E2), V(73, D8, D8, AB), V(53, 31, 31, 62), V(3F, 15, 15, 2A), V(0C, 04, 04, 08), \ + V(52, C7, C7, 95), V(65, 23, 23, 46), V(5E, C3, C3, 9D), V(28, 18, 18, 30), V(A1, 96, 96, 37), V(0F, 05, 05, 0A), V(B5, 9A, 9A, 2F), \ + V(09, 07, 07, 0E), V(36, 12, 12, 24), V(9B, 80, 80, 1B), V(3D, E2, E2, DF), V(26, EB, EB, CD), V(69, 27, 27, 4E), V(CD, B2, B2, 7F), \ + V(9F, 75, 75, EA), V(1B, 09, 09, 12), V(9E, 83, 83, 1D), V(74, 2C, 2C, 58), V(2E, 1A, 1A, 34), V(2D, 1B, 1B, 36), V(B2, 6E, 6E, DC), \ + V(EE, 5A, 5A, B4), V(FB, A0, A0, 5B), V(F6, 52, 52, A4), V(4D, 3B, 3B, 76), V(61, D6, D6, B7), V(CE, B3, B3, 7D), V(7B, 29, 29, 52), \ + V(3E, E3, E3, DD), V(71, 2F, 2F, 5E), V(97, 84, 84, 13), V(F5, 53, 53, A6), V(68, D1, D1, B9), V(00, 00, 00, 00), V(2C, ED, ED, C1), \ + V(60, 20, 20, 40), V(1F, FC, FC, E3), V(C8, B1, B1, 79), V(ED, 5B, 5B, B6), V(BE, 6A, 6A, D4), V(46, CB, CB, 8D), V(D9, BE, BE, 67), \ + V(4B, 39, 39, 72), V(DE, 4A, 4A, 94), V(D4, 4C, 4C, 98), V(E8, 58, 58, B0), V(4A, CF, CF, 85), V(6B, D0, D0, BB), V(2A, EF, EF, C5), \ + V(E5, AA, AA, 4F), V(16, FB, FB, ED), V(C5, 43, 43, 86), V(D7, 4D, 4D, 9A), V(55, 33, 33, 66), V(94, 85, 85, 11), V(CF, 45, 45, 8A), \ + V(10, F9, F9, E9), V(06, 02, 02, 04), V(81, 7F, 7F, FE), V(F0, 50, 50, A0), V(44, 3C, 3C, 78), V(BA, 9F, 9F, 25), V(E3, A8, A8, 4B), \ + V(F3, 51, 51, A2), V(FE, A3, A3, 5D), V(C0, 40, 40, 80), V(8A, 8F, 8F, 05), V(AD, 92, 92, 3F), V(BC, 9D, 9D, 21), V(48, 38, 38, 70), \ + V(04, F5, F5, F1), V(DF, BC, BC, 63), V(C1, B6, B6, 77), V(75, DA, DA, AF), V(63, 21, 21, 42), V(30, 10, 10, 20), V(1A, FF, FF, E5), \ + V(0E, F3, F3, FD), V(6D, D2, D2, BF), V(4C, CD, CD, 81), V(14, 0C, 0C, 18), V(35, 13, 13, 26), V(2F, EC, EC, C3), V(E1, 5F, 5F, BE), \ + V(A2, 97, 97, 35), V(CC, 44, 44, 88), V(39, 17, 17, 2E), V(57, C4, C4, 93), V(F2, A7, A7, 55), V(82, 7E, 7E, FC), V(47, 3D, 3D, 7A), \ + V(AC, 64, 64, C8), V(E7, 5D, 5D, BA), V(2B, 19, 19, 32), V(95, 73, 73, E6), V(A0, 60, 60, C0), V(98, 81, 81, 19), V(D1, 4F, 4F, 9E), \ + V(7F, DC, DC, A3), V(66, 22, 22, 44), V(7E, 2A, 2A, 54), V(AB, 90, 90, 3B), V(83, 88, 88, 0B), V(CA, 46, 46, 8C), V(29, EE, EE, C7), \ + V(D3, B8, B8, 6B), V(3C, 14, 14, 28), V(79, DE, DE, A7), V(E2, 5E, 5E, BC), V(1D, 0B, 0B, 16), V(76, DB, DB, AD), V(3B, E0, E0, DB), \ + V(56, 32, 32, 64), V(4E, 3A, 3A, 74), V(1E, 0A, 0A, 14), V(DB, 49, 49, 92), V(0A, 06, 06, 0C), V(6C, 24, 24, 48), V(E4, 5C, 5C, B8), \ + V(5D, C2, C2, 9F), V(6E, D3, D3, BD), V(EF, AC, AC, 43), V(A6, 62, 62, C4), V(A8, 91, 91, 39), V(A4, 95, 95, 31), V(37, E4, E4, D3), \ + V(8B, 79, 79, F2), V(32, E7, E7, D5), V(43, C8, C8, 8B), V(59, 37, 37, 6E), V(B7, 6D, 6D, DA), V(8C, 8D, 8D, 01), V(64, D5, D5, B1), \ + V(D2, 4E, 4E, 9C), V(E0, A9, A9, 49), V(B4, 6C, 6C, D8), V(FA, 56, 56, AC), V(07, F4, F4, F3), V(25, EA, EA, CF), V(AF, 65, 65, CA), \ + V(8E, 7A, 7A, F4), V(E9, AE, AE, 47), V(18, 08, 08, 10), V(D5, BA, BA, 6F), V(88, 78, 78, F0), V(6F, 25, 25, 4A), V(72, 2E, 2E, 5C), \ + V(24, 1C, 1C, 38), V(F1, A6, A6, 57), V(C7, B4, B4, 73), V(51, C6, C6, 97), V(23, E8, E8, CB), V(7C, DD, DD, A1), V(9C, 74, 74, E8), \ + V(21, 1F, 1F, 3E), V(DD, 4B, 4B, 96), V(DC, BD, BD, 61), V(86, 8B, 8B, 0D), V(85, 8A, 8A, 0F), V(90, 70, 70, E0), V(42, 3E, 3E, 7C), \ + V(C4, B5, B5, 71), V(AA, 66, 66, CC), V(D8, 48, 48, 90), V(05, 03, 03, 06), V(01, F6, F6, F7), V(12, 0E, 0E, 1C), V(A3, 61, 61, C2), \ + V(5F, 35, 35, 6A), V(F9, 57, 57, AE), V(D0, B9, B9, 69), V(91, 86, 86, 17), V(58, C1, C1, 99), V(27, 1D, 1D, 3A), V(B9, 9E, 9E, 27), \ + V(38, E1, E1, D9), V(13, F8, F8, EB), V(B3, 98, 98, 2B), V(33, 11, 11, 22), V(BB, 69, 69, D2), V(70, D9, D9, A9), V(89, 8E, 8E, 07), \ + V(A7, 94, 94, 33), V(B6, 9B, 9B, 2D), V(22, 1E, 1E, 3C), V(92, 87, 87, 15), V(20, E9, E9, C9), V(49, CE, CE, 87), V(FF, 55, 55, AA), \ + V(78, 28, 28, 50), V(7A, DF, DF, A5), V(8F, 8C, 8C, 03), V(F8, A1, A1, 59), V(80, 89, 89, 09), V(17, 0D, 0D, 1A), V(DA, BF, BF, 65), \ + V(31, E6, E6, D7), V(C6, 42, 42, 84), V(B8, 68, 68, D0), V(C3, 41, 41, 82), V(B0, 99, 99, 29), V(77, 2D, 2D, 5A), V(11, 0F, 0F, 1E), \ + V(CB, B0, B0, 7B), V(FC, 54, 54, A8), V(D6, BB, BB, 6D), V(3A, 16, 16, 2C) + +#define V(a, b, c, d) 0x##a##b##c##d +static const uint32_t FT0[256] = {FT}; #undef V #if !defined(MBEDTLS_AES_FEWER_TABLES) -#define V(a,b,c,d) 0x##b##c##d##a -static const uint32_t FT1[256] = { FT }; +#define V(a, b, c, d) 0x##b##c##d##a +static const uint32_t FT1[256] = {FT}; #undef V -#define V(a,b,c,d) 0x##c##d##a##b -static const uint32_t FT2[256] = { FT }; +#define V(a, b, c, d) 0x##c##d##a##b +static const uint32_t FT2[256] = {FT}; #undef V -#define V(a,b,c,d) 0x##d##a##b##c -static const uint32_t FT3[256] = { FT }; +#define V(a, b, c, d) 0x##d##a##b##c +static const uint32_t FT3[256] = {FT}; #undef V #endif /* !MBEDTLS_AES_FEWER_TABLES */ @@ -245,128 +188,78 @@ static const uint32_t FT3[256] = { FT }; /* * Reverse S-box */ -static const unsigned char RSb[256] = -{ - 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, - 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, - 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, - 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, - 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, - 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, - 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, - 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, - 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, - 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, - 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, - 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, - 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, - 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, - 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, - 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, - 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, - 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, - 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, - 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, - 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, - 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, - 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, - 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, - 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, - 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, - 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, - 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, - 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, - 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, - 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, - 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D -}; +static const unsigned char RSb[256] = { + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, + 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, + 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, + 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D}; /* * Reverse tables */ #define RT \ \ - V(50,A7,F4,51), V(53,65,41,7E), V(C3,A4,17,1A), V(96,5E,27,3A), \ - V(CB,6B,AB,3B), V(F1,45,9D,1F), V(AB,58,FA,AC), V(93,03,E3,4B), \ - V(55,FA,30,20), V(F6,6D,76,AD), V(91,76,CC,88), V(25,4C,02,F5), \ - V(FC,D7,E5,4F), V(D7,CB,2A,C5), V(80,44,35,26), V(8F,A3,62,B5), \ - V(49,5A,B1,DE), V(67,1B,BA,25), V(98,0E,EA,45), V(E1,C0,FE,5D), \ - V(02,75,2F,C3), V(12,F0,4C,81), V(A3,97,46,8D), V(C6,F9,D3,6B), \ - V(E7,5F,8F,03), V(95,9C,92,15), V(EB,7A,6D,BF), V(DA,59,52,95), \ - V(2D,83,BE,D4), V(D3,21,74,58), V(29,69,E0,49), V(44,C8,C9,8E), \ - V(6A,89,C2,75), V(78,79,8E,F4), V(6B,3E,58,99), V(DD,71,B9,27), \ - V(B6,4F,E1,BE), V(17,AD,88,F0), V(66,AC,20,C9), V(B4,3A,CE,7D), \ - V(18,4A,DF,63), V(82,31,1A,E5), V(60,33,51,97), V(45,7F,53,62), \ - V(E0,77,64,B1), V(84,AE,6B,BB), V(1C,A0,81,FE), V(94,2B,08,F9), \ - V(58,68,48,70), V(19,FD,45,8F), V(87,6C,DE,94), V(B7,F8,7B,52), \ - V(23,D3,73,AB), V(E2,02,4B,72), V(57,8F,1F,E3), V(2A,AB,55,66), \ - V(07,28,EB,B2), V(03,C2,B5,2F), V(9A,7B,C5,86), V(A5,08,37,D3), \ - V(F2,87,28,30), V(B2,A5,BF,23), V(BA,6A,03,02), V(5C,82,16,ED), \ - V(2B,1C,CF,8A), V(92,B4,79,A7), V(F0,F2,07,F3), V(A1,E2,69,4E), \ - V(CD,F4,DA,65), V(D5,BE,05,06), V(1F,62,34,D1), V(8A,FE,A6,C4), \ - V(9D,53,2E,34), V(A0,55,F3,A2), V(32,E1,8A,05), V(75,EB,F6,A4), \ - V(39,EC,83,0B), V(AA,EF,60,40), V(06,9F,71,5E), V(51,10,6E,BD), \ - V(F9,8A,21,3E), V(3D,06,DD,96), V(AE,05,3E,DD), V(46,BD,E6,4D), \ - V(B5,8D,54,91), V(05,5D,C4,71), V(6F,D4,06,04), V(FF,15,50,60), \ - V(24,FB,98,19), V(97,E9,BD,D6), V(CC,43,40,89), V(77,9E,D9,67), \ - V(BD,42,E8,B0), V(88,8B,89,07), V(38,5B,19,E7), V(DB,EE,C8,79), \ - V(47,0A,7C,A1), V(E9,0F,42,7C), V(C9,1E,84,F8), V(00,00,00,00), \ - V(83,86,80,09), V(48,ED,2B,32), V(AC,70,11,1E), V(4E,72,5A,6C), \ - V(FB,FF,0E,FD), V(56,38,85,0F), V(1E,D5,AE,3D), V(27,39,2D,36), \ - V(64,D9,0F,0A), V(21,A6,5C,68), V(D1,54,5B,9B), V(3A,2E,36,24), \ - V(B1,67,0A,0C), V(0F,E7,57,93), V(D2,96,EE,B4), V(9E,91,9B,1B), \ - V(4F,C5,C0,80), V(A2,20,DC,61), V(69,4B,77,5A), V(16,1A,12,1C), \ - V(0A,BA,93,E2), V(E5,2A,A0,C0), V(43,E0,22,3C), V(1D,17,1B,12), \ - V(0B,0D,09,0E), V(AD,C7,8B,F2), V(B9,A8,B6,2D), V(C8,A9,1E,14), \ - V(85,19,F1,57), V(4C,07,75,AF), V(BB,DD,99,EE), V(FD,60,7F,A3), \ - V(9F,26,01,F7), V(BC,F5,72,5C), V(C5,3B,66,44), V(34,7E,FB,5B), \ - V(76,29,43,8B), V(DC,C6,23,CB), V(68,FC,ED,B6), V(63,F1,E4,B8), \ - V(CA,DC,31,D7), V(10,85,63,42), V(40,22,97,13), V(20,11,C6,84), \ - V(7D,24,4A,85), V(F8,3D,BB,D2), V(11,32,F9,AE), V(6D,A1,29,C7), \ - V(4B,2F,9E,1D), V(F3,30,B2,DC), V(EC,52,86,0D), V(D0,E3,C1,77), \ - V(6C,16,B3,2B), V(99,B9,70,A9), V(FA,48,94,11), V(22,64,E9,47), \ - V(C4,8C,FC,A8), V(1A,3F,F0,A0), V(D8,2C,7D,56), V(EF,90,33,22), \ - V(C7,4E,49,87), V(C1,D1,38,D9), V(FE,A2,CA,8C), V(36,0B,D4,98), \ - V(CF,81,F5,A6), V(28,DE,7A,A5), V(26,8E,B7,DA), V(A4,BF,AD,3F), \ - V(E4,9D,3A,2C), V(0D,92,78,50), V(9B,CC,5F,6A), V(62,46,7E,54), \ - V(C2,13,8D,F6), V(E8,B8,D8,90), V(5E,F7,39,2E), V(F5,AF,C3,82), \ - V(BE,80,5D,9F), V(7C,93,D0,69), V(A9,2D,D5,6F), V(B3,12,25,CF), \ - V(3B,99,AC,C8), V(A7,7D,18,10), V(6E,63,9C,E8), V(7B,BB,3B,DB), \ - V(09,78,26,CD), V(F4,18,59,6E), V(01,B7,9A,EC), V(A8,9A,4F,83), \ - V(65,6E,95,E6), V(7E,E6,FF,AA), V(08,CF,BC,21), V(E6,E8,15,EF), \ - V(D9,9B,E7,BA), V(CE,36,6F,4A), V(D4,09,9F,EA), V(D6,7C,B0,29), \ - V(AF,B2,A4,31), V(31,23,3F,2A), V(30,94,A5,C6), V(C0,66,A2,35), \ - V(37,BC,4E,74), V(A6,CA,82,FC), V(B0,D0,90,E0), V(15,D8,A7,33), \ - V(4A,98,04,F1), V(F7,DA,EC,41), V(0E,50,CD,7F), V(2F,F6,91,17), \ - V(8D,D6,4D,76), V(4D,B0,EF,43), V(54,4D,AA,CC), V(DF,04,96,E4), \ - V(E3,B5,D1,9E), V(1B,88,6A,4C), V(B8,1F,2C,C1), V(7F,51,65,46), \ - V(04,EA,5E,9D), V(5D,35,8C,01), V(73,74,87,FA), V(2E,41,0B,FB), \ - V(5A,1D,67,B3), V(52,D2,DB,92), V(33,56,10,E9), V(13,47,D6,6D), \ - V(8C,61,D7,9A), V(7A,0C,A1,37), V(8E,14,F8,59), V(89,3C,13,EB), \ - V(EE,27,A9,CE), V(35,C9,61,B7), V(ED,E5,1C,E1), V(3C,B1,47,7A), \ - V(59,DF,D2,9C), V(3F,73,F2,55), V(79,CE,14,18), V(BF,37,C7,73), \ - V(EA,CD,F7,53), V(5B,AA,FD,5F), V(14,6F,3D,DF), V(86,DB,44,78), \ - V(81,F3,AF,CA), V(3E,C4,68,B9), V(2C,34,24,38), V(5F,40,A3,C2), \ - V(72,C3,1D,16), V(0C,25,E2,BC), V(8B,49,3C,28), V(41,95,0D,FF), \ - V(71,01,A8,39), V(DE,B3,0C,08), V(9C,E4,B4,D8), V(90,C1,56,64), \ - V(61,84,CB,7B), V(70,B6,32,D5), V(74,5C,6C,48), V(42,57,B8,D0) - -#define V(a,b,c,d) 0x##a##b##c##d -static const uint32_t RT0[256] = { RT }; + V(50, A7, F4, 51), V(53, 65, 41, 7E), V(C3, A4, 17, 1A), V(96, 5E, 27, 3A), V(CB, 6B, AB, 3B), V(F1, 45, 9D, 1F), V(AB, 58, FA, AC), \ + V(93, 03, E3, 4B), V(55, FA, 30, 20), V(F6, 6D, 76, AD), V(91, 76, CC, 88), V(25, 4C, 02, F5), V(FC, D7, E5, 4F), V(D7, CB, 2A, C5), \ + V(80, 44, 35, 26), V(8F, A3, 62, B5), V(49, 5A, B1, DE), V(67, 1B, BA, 25), V(98, 0E, EA, 45), V(E1, C0, FE, 5D), V(02, 75, 2F, C3), \ + V(12, F0, 4C, 81), V(A3, 97, 46, 8D), V(C6, F9, D3, 6B), V(E7, 5F, 8F, 03), V(95, 9C, 92, 15), V(EB, 7A, 6D, BF), V(DA, 59, 52, 95), \ + V(2D, 83, BE, D4), V(D3, 21, 74, 58), V(29, 69, E0, 49), V(44, C8, C9, 8E), V(6A, 89, C2, 75), V(78, 79, 8E, F4), V(6B, 3E, 58, 99), \ + V(DD, 71, B9, 27), V(B6, 4F, E1, BE), V(17, AD, 88, F0), V(66, AC, 20, C9), V(B4, 3A, CE, 7D), V(18, 4A, DF, 63), V(82, 31, 1A, E5), \ + V(60, 33, 51, 97), V(45, 7F, 53, 62), V(E0, 77, 64, B1), V(84, AE, 6B, BB), V(1C, A0, 81, FE), V(94, 2B, 08, F9), V(58, 68, 48, 70), \ + V(19, FD, 45, 8F), V(87, 6C, DE, 94), V(B7, F8, 7B, 52), V(23, D3, 73, AB), V(E2, 02, 4B, 72), V(57, 8F, 1F, E3), V(2A, AB, 55, 66), \ + V(07, 28, EB, B2), V(03, C2, B5, 2F), V(9A, 7B, C5, 86), V(A5, 08, 37, D3), V(F2, 87, 28, 30), V(B2, A5, BF, 23), V(BA, 6A, 03, 02), \ + V(5C, 82, 16, ED), V(2B, 1C, CF, 8A), V(92, B4, 79, A7), V(F0, F2, 07, F3), V(A1, E2, 69, 4E), V(CD, F4, DA, 65), V(D5, BE, 05, 06), \ + V(1F, 62, 34, D1), V(8A, FE, A6, C4), V(9D, 53, 2E, 34), V(A0, 55, F3, A2), V(32, E1, 8A, 05), V(75, EB, F6, A4), V(39, EC, 83, 0B), \ + V(AA, EF, 60, 40), V(06, 9F, 71, 5E), V(51, 10, 6E, BD), V(F9, 8A, 21, 3E), V(3D, 06, DD, 96), V(AE, 05, 3E, DD), V(46, BD, E6, 4D), \ + V(B5, 8D, 54, 91), V(05, 5D, C4, 71), V(6F, D4, 06, 04), V(FF, 15, 50, 60), V(24, FB, 98, 19), V(97, E9, BD, D6), V(CC, 43, 40, 89), \ + V(77, 9E, D9, 67), V(BD, 42, E8, B0), V(88, 8B, 89, 07), V(38, 5B, 19, E7), V(DB, EE, C8, 79), V(47, 0A, 7C, A1), V(E9, 0F, 42, 7C), \ + V(C9, 1E, 84, F8), V(00, 00, 00, 00), V(83, 86, 80, 09), V(48, ED, 2B, 32), V(AC, 70, 11, 1E), V(4E, 72, 5A, 6C), V(FB, FF, 0E, FD), \ + V(56, 38, 85, 0F), V(1E, D5, AE, 3D), V(27, 39, 2D, 36), V(64, D9, 0F, 0A), V(21, A6, 5C, 68), V(D1, 54, 5B, 9B), V(3A, 2E, 36, 24), \ + V(B1, 67, 0A, 0C), V(0F, E7, 57, 93), V(D2, 96, EE, B4), V(9E, 91, 9B, 1B), V(4F, C5, C0, 80), V(A2, 20, DC, 61), V(69, 4B, 77, 5A), \ + V(16, 1A, 12, 1C), V(0A, BA, 93, E2), V(E5, 2A, A0, C0), V(43, E0, 22, 3C), V(1D, 17, 1B, 12), V(0B, 0D, 09, 0E), V(AD, C7, 8B, F2), \ + V(B9, A8, B6, 2D), V(C8, A9, 1E, 14), V(85, 19, F1, 57), V(4C, 07, 75, AF), V(BB, DD, 99, EE), V(FD, 60, 7F, A3), V(9F, 26, 01, F7), \ + V(BC, F5, 72, 5C), V(C5, 3B, 66, 44), V(34, 7E, FB, 5B), V(76, 29, 43, 8B), V(DC, C6, 23, CB), V(68, FC, ED, B6), V(63, F1, E4, B8), \ + V(CA, DC, 31, D7), V(10, 85, 63, 42), V(40, 22, 97, 13), V(20, 11, C6, 84), V(7D, 24, 4A, 85), V(F8, 3D, BB, D2), V(11, 32, F9, AE), \ + V(6D, A1, 29, C7), V(4B, 2F, 9E, 1D), V(F3, 30, B2, DC), V(EC, 52, 86, 0D), V(D0, E3, C1, 77), V(6C, 16, B3, 2B), V(99, B9, 70, A9), \ + V(FA, 48, 94, 11), V(22, 64, E9, 47), V(C4, 8C, FC, A8), V(1A, 3F, F0, A0), V(D8, 2C, 7D, 56), V(EF, 90, 33, 22), V(C7, 4E, 49, 87), \ + V(C1, D1, 38, D9), V(FE, A2, CA, 8C), V(36, 0B, D4, 98), V(CF, 81, F5, A6), V(28, DE, 7A, A5), V(26, 8E, B7, DA), V(A4, BF, AD, 3F), \ + V(E4, 9D, 3A, 2C), V(0D, 92, 78, 50), V(9B, CC, 5F, 6A), V(62, 46, 7E, 54), V(C2, 13, 8D, F6), V(E8, B8, D8, 90), V(5E, F7, 39, 2E), \ + V(F5, AF, C3, 82), V(BE, 80, 5D, 9F), V(7C, 93, D0, 69), V(A9, 2D, D5, 6F), V(B3, 12, 25, CF), V(3B, 99, AC, C8), V(A7, 7D, 18, 10), \ + V(6E, 63, 9C, E8), V(7B, BB, 3B, DB), V(09, 78, 26, CD), V(F4, 18, 59, 6E), V(01, B7, 9A, EC), V(A8, 9A, 4F, 83), V(65, 6E, 95, E6), \ + V(7E, E6, FF, AA), V(08, CF, BC, 21), V(E6, E8, 15, EF), V(D9, 9B, E7, BA), V(CE, 36, 6F, 4A), V(D4, 09, 9F, EA), V(D6, 7C, B0, 29), \ + V(AF, B2, A4, 31), V(31, 23, 3F, 2A), V(30, 94, A5, C6), V(C0, 66, A2, 35), V(37, BC, 4E, 74), V(A6, CA, 82, FC), V(B0, D0, 90, E0), \ + V(15, D8, A7, 33), V(4A, 98, 04, F1), V(F7, DA, EC, 41), V(0E, 50, CD, 7F), V(2F, F6, 91, 17), V(8D, D6, 4D, 76), V(4D, B0, EF, 43), \ + V(54, 4D, AA, CC), V(DF, 04, 96, E4), V(E3, B5, D1, 9E), V(1B, 88, 6A, 4C), V(B8, 1F, 2C, C1), V(7F, 51, 65, 46), V(04, EA, 5E, 9D), \ + V(5D, 35, 8C, 01), V(73, 74, 87, FA), V(2E, 41, 0B, FB), V(5A, 1D, 67, B3), V(52, D2, DB, 92), V(33, 56, 10, E9), V(13, 47, D6, 6D), \ + V(8C, 61, D7, 9A), V(7A, 0C, A1, 37), V(8E, 14, F8, 59), V(89, 3C, 13, EB), V(EE, 27, A9, CE), V(35, C9, 61, B7), V(ED, E5, 1C, E1), \ + V(3C, B1, 47, 7A), V(59, DF, D2, 9C), V(3F, 73, F2, 55), V(79, CE, 14, 18), V(BF, 37, C7, 73), V(EA, CD, F7, 53), V(5B, AA, FD, 5F), \ + V(14, 6F, 3D, DF), V(86, DB, 44, 78), V(81, F3, AF, CA), V(3E, C4, 68, B9), V(2C, 34, 24, 38), V(5F, 40, A3, C2), V(72, C3, 1D, 16), \ + V(0C, 25, E2, BC), V(8B, 49, 3C, 28), V(41, 95, 0D, FF), V(71, 01, A8, 39), V(DE, B3, 0C, 08), V(9C, E4, B4, D8), V(90, C1, 56, 64), \ + V(61, 84, CB, 7B), V(70, B6, 32, D5), V(74, 5C, 6C, 48), V(42, 57, B8, D0) + +#define V(a, b, c, d) 0x##a##b##c##d +static const uint32_t RT0[256] = {RT}; #undef V #if !defined(MBEDTLS_AES_FEWER_TABLES) -#define V(a,b,c,d) 0x##b##c##d##a -static const uint32_t RT1[256] = { RT }; +#define V(a, b, c, d) 0x##b##c##d##a +static const uint32_t RT1[256] = {RT}; #undef V -#define V(a,b,c,d) 0x##c##d##a##b -static const uint32_t RT2[256] = { RT }; +#define V(a, b, c, d) 0x##c##d##a##b +static const uint32_t RT2[256] = {RT}; #undef V -#define V(a,b,c,d) 0x##d##a##b##c -static const uint32_t RT3[256] = { RT }; +#define V(a, b, c, d) 0x##d##a##b##c +static const uint32_t RT3[256] = {RT}; #undef V #endif /* !MBEDTLS_AES_FEWER_TABLES */ @@ -376,12 +269,8 @@ static const uint32_t RT3[256] = { RT }; /* * Round constants */ -static const uint32_t RCON[10] = -{ - 0x00000001, 0x00000002, 0x00000004, 0x00000008, - 0x00000010, 0x00000020, 0x00000040, 0x00000080, - 0x0000001B, 0x00000036 -}; +static const uint32_t RCON[10] = {0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, + 0x00000020, 0x00000040, 0x00000080, 0x0000001B, 0x00000036}; #else /* MBEDTLS_AES_ROM_TABLES */ @@ -415,13 +304,13 @@ static uint32_t RCON[10]; /* * Tables generation code */ -#define ROTL8(x) ( ( (x) << 8 ) & 0xFFFFFFFF ) | ( (x) >> 24 ) -#define XTIME(x) ( ( (x) << 1 ) ^ ( ( (x) & 0x80 ) ? 0x1B : 0x00 ) ) -#define MUL(x,y) ( ( (x) && (y) ) ? pow[(log[(x)]+log[(y)]) % 255] : 0 ) +#define ROTL8(x) (((x) << 8) & 0xFFFFFFFF) | ((x) >> 24) +#define XTIME(x) (((x) << 1) ^ (((x)&0x80) ? 0x1B : 0x00)) +#define MUL(x, y) (((x) && (y)) ? pow[(log[(x)] + log[(y)]) % 255] : 0) static int aes_init_done = 0; -static void aes_gen_tables( void ) +static void aes_gen_tables(void) { int i, x, y, z; int pow[256]; @@ -430,20 +319,18 @@ static void aes_gen_tables( void ) /* * compute pow and log tables over GF(2^8) */ - for( i = 0, x = 1; i < 256; i++ ) - { + for (i = 0, x = 1; i < 256; i++) { pow[i] = x; log[x] = i; - x = ( x ^ XTIME( x ) ) & 0xFF; + x = (x ^ XTIME(x)) & 0xFF; } /* * calculate the round constants */ - for( i = 0, x = 1; i < 10; i++ ) - { - RCON[i] = (uint32_t) x; - x = XTIME( x ) & 0xFF; + for (i = 0, x = 1; i < 10; i++) { + RCON[i] = (uint32_t)x; + x = XTIME(x) & 0xFF; } /* @@ -452,51 +339,47 @@ static void aes_gen_tables( void ) FSb[0x00] = 0x63; RSb[0x63] = 0x00; - for( i = 1; i < 256; i++ ) - { + for (i = 1; i < 256; i++) { x = pow[255 - log[i]]; - y = x; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF; - x ^= y; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF; - x ^= y; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF; - x ^= y; y = ( ( y << 1 ) | ( y >> 7 ) ) & 0xFF; + y = x; + y = ((y << 1) | (y >> 7)) & 0xFF; + x ^= y; + y = ((y << 1) | (y >> 7)) & 0xFF; + x ^= y; + y = ((y << 1) | (y >> 7)) & 0xFF; + x ^= y; + y = ((y << 1) | (y >> 7)) & 0xFF; x ^= y ^ 0x63; - FSb[i] = (unsigned char) x; - RSb[x] = (unsigned char) i; + FSb[i] = (unsigned char)x; + RSb[x] = (unsigned char)i; } /* * generate the forward and reverse tables */ - for( i = 0; i < 256; i++ ) - { + for (i = 0; i < 256; i++) { x = FSb[i]; - y = XTIME( x ) & 0xFF; - z = ( y ^ x ) & 0xFF; + y = XTIME(x) & 0xFF; + z = (y ^ x) & 0xFF; - FT0[i] = ( (uint32_t) y ) ^ - ( (uint32_t) x << 8 ) ^ - ( (uint32_t) x << 16 ) ^ - ( (uint32_t) z << 24 ); + FT0[i] = ((uint32_t)y) ^ ((uint32_t)x << 8) ^ ((uint32_t)x << 16) ^ ((uint32_t)z << 24); #if !defined(MBEDTLS_AES_FEWER_TABLES) - FT1[i] = ROTL8( FT0[i] ); - FT2[i] = ROTL8( FT1[i] ); - FT3[i] = ROTL8( FT2[i] ); + FT1[i] = ROTL8(FT0[i]); + FT2[i] = ROTL8(FT1[i]); + FT3[i] = ROTL8(FT2[i]); #endif /* !MBEDTLS_AES_FEWER_TABLES */ x = RSb[i]; - RT0[i] = ( (uint32_t) MUL( 0x0E, x ) ) ^ - ( (uint32_t) MUL( 0x09, x ) << 8 ) ^ - ( (uint32_t) MUL( 0x0D, x ) << 16 ) ^ - ( (uint32_t) MUL( 0x0B, x ) << 24 ); + RT0[i] = ((uint32_t)MUL(0x0E, x)) ^ ((uint32_t)MUL(0x09, x) << 8) ^ ((uint32_t)MUL(0x0D, x) << 16) ^ ((uint32_t)MUL(0x0B, x) << 24); #if !defined(MBEDTLS_AES_FEWER_TABLES) - RT1[i] = ROTL8( RT0[i] ); - RT2[i] = ROTL8( RT1[i] ); - RT3[i] = ROTL8( RT2[i] ); + RT1[i] = ROTL8(RT0[i]); + RT2[i] = ROTL8(RT1[i]); + RT3[i] = ROTL8(RT2[i]); #endif /* !MBEDTLS_AES_FEWER_TABLES */ } } @@ -507,19 +390,19 @@ static void aes_gen_tables( void ) #if defined(MBEDTLS_AES_FEWER_TABLES) -#define ROTL8(x) ( (uint32_t)( ( x ) << 8 ) + (uint32_t)( ( x ) >> 24 ) ) -#define ROTL16(x) ( (uint32_t)( ( x ) << 16 ) + (uint32_t)( ( x ) >> 16 ) ) -#define ROTL24(x) ( (uint32_t)( ( x ) << 24 ) + (uint32_t)( ( x ) >> 8 ) ) +#define ROTL8(x) ((uint32_t)((x) << 8) + (uint32_t)((x) >> 24)) +#define ROTL16(x) ((uint32_t)((x) << 16) + (uint32_t)((x) >> 16)) +#define ROTL24(x) ((uint32_t)((x) << 24) + (uint32_t)((x) >> 8)) #define AES_RT0(idx) RT0[idx] -#define AES_RT1(idx) ROTL8( RT0[idx] ) -#define AES_RT2(idx) ROTL16( RT0[idx] ) -#define AES_RT3(idx) ROTL24( RT0[idx] ) +#define AES_RT1(idx) ROTL8(RT0[idx]) +#define AES_RT2(idx) ROTL16(RT0[idx]) +#define AES_RT3(idx) ROTL24(RT0[idx]) #define AES_FT0(idx) FT0[idx] -#define AES_FT1(idx) ROTL8( FT0[idx] ) -#define AES_FT2(idx) ROTL16( FT0[idx] ) -#define AES_FT3(idx) ROTL24( FT0[idx] ) +#define AES_FT1(idx) ROTL8(FT0[idx]) +#define AES_FT2(idx) ROTL16(FT0[idx]) +#define AES_FT3(idx) ROTL24(FT0[idx]) #else /* MBEDTLS_AES_FEWER_TABLES */ @@ -535,37 +418,37 @@ static void aes_gen_tables( void ) #endif /* MBEDTLS_AES_FEWER_TABLES */ -void mbedtls_aes_init( mbedtls_aes_context *ctx ) +void mbedtls_aes_init(mbedtls_aes_context* ctx) { - AES_VALIDATE( ctx != NULL ); + AES_VALIDATE(ctx != NULL); - memset( ctx, 0, sizeof( mbedtls_aes_context ) ); + memset(ctx, 0, sizeof(mbedtls_aes_context)); } -void mbedtls_aes_free( mbedtls_aes_context *ctx ) +void mbedtls_aes_free(mbedtls_aes_context* ctx) { - if( ctx == NULL ) + if (ctx == NULL) return; - mbedtls_platform_zeroize( ctx, sizeof( mbedtls_aes_context ) ); + mbedtls_platform_zeroize(ctx, sizeof(mbedtls_aes_context)); } #if defined(MBEDTLS_CIPHER_MODE_XTS) -void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ) +void mbedtls_aes_xts_init(mbedtls_aes_xts_context* ctx) { - AES_VALIDATE( ctx != NULL ); + AES_VALIDATE(ctx != NULL); - mbedtls_aes_init( &ctx->crypt ); - mbedtls_aes_init( &ctx->tweak ); + mbedtls_aes_init(&ctx->crypt); + mbedtls_aes_init(&ctx->tweak); } -void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ) +void mbedtls_aes_xts_free(mbedtls_aes_xts_context* ctx) { - if( ctx == NULL ) + if (ctx == NULL) return; - mbedtls_aes_free( &ctx->crypt ); - mbedtls_aes_free( &ctx->tweak ); + mbedtls_aes_free(&ctx->crypt); + mbedtls_aes_free(&ctx->tweak); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ @@ -573,104 +456,89 @@ void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ) * AES key schedule (encryption) */ #if !defined(MBEDTLS_AES_SETKEY_ENC_ALT) -int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits ) +int mbedtls_aes_setkey_enc(mbedtls_aes_context* ctx, const unsigned char* key, unsigned int keybits) { unsigned int i; - uint32_t *RK; - - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( key != NULL ); - - switch( keybits ) - { - case 128: ctx->nr = 10; break; - case 192: ctx->nr = 12; break; - case 256: ctx->nr = 14; break; - default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); + uint32_t* RK; + + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(key != NULL); + + switch (keybits) { + case 128: + ctx->nr = 10; + break; + case 192: + ctx->nr = 12; + break; + case 256: + ctx->nr = 14; + break; + default: + return (MBEDTLS_ERR_AES_INVALID_KEY_LENGTH); } #if !defined(MBEDTLS_AES_ROM_TABLES) - if( aes_init_done == 0 ) - { + if (aes_init_done == 0) { aes_gen_tables(); aes_init_done = 1; } #endif - ctx->rk = RK = ctx->buf; - - for( i = 0; i < ( keybits >> 5 ); i++ ) - { - GET_UINT32_LE( RK[i], key, i << 2 ); + for (i = 0; i < (keybits >> 5); i++) { + GET_UINT32_LE(RK[i], key, i << 2); } - switch( ctx->nr ) - { - case 10: - - for( i = 0; i < 10; i++, RK += 4 ) - { - RK[4] = RK[0] ^ RCON[i] ^ - ( (uint32_t) FSb[ ( RK[3] >> 8 ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( RK[3] >> 16 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( RK[3] >> 24 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( RK[3] ) & 0xFF ] << 24 ); - - RK[5] = RK[1] ^ RK[4]; - RK[6] = RK[2] ^ RK[5]; - RK[7] = RK[3] ^ RK[6]; - } - break; - - case 12: - - for( i = 0; i < 8; i++, RK += 6 ) - { - RK[6] = RK[0] ^ RCON[i] ^ - ( (uint32_t) FSb[ ( RK[5] >> 8 ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( RK[5] >> 16 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( RK[5] >> 24 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( RK[5] ) & 0xFF ] << 24 ); - - RK[7] = RK[1] ^ RK[6]; - RK[8] = RK[2] ^ RK[7]; - RK[9] = RK[3] ^ RK[8]; - RK[10] = RK[4] ^ RK[9]; - RK[11] = RK[5] ^ RK[10]; - } - break; - - case 14: - - for( i = 0; i < 7; i++, RK += 8 ) - { - RK[8] = RK[0] ^ RCON[i] ^ - ( (uint32_t) FSb[ ( RK[7] >> 8 ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( RK[7] >> 16 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( RK[7] >> 24 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( RK[7] ) & 0xFF ] << 24 ); - - RK[9] = RK[1] ^ RK[8]; - RK[10] = RK[2] ^ RK[9]; - RK[11] = RK[3] ^ RK[10]; - - RK[12] = RK[4] ^ - ( (uint32_t) FSb[ ( RK[11] ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( RK[11] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( RK[11] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( RK[11] >> 24 ) & 0xFF ] << 24 ); - - RK[13] = RK[5] ^ RK[12]; - RK[14] = RK[6] ^ RK[13]; - RK[15] = RK[7] ^ RK[14]; - } - break; + switch (ctx->nr) { + case 10: + + for (i = 0; i < 10; i++, RK += 4) { + RK[4] = RK[0] ^ RCON[i] ^ ((uint32_t)FSb[(RK[3] >> 8) & 0xFF]) ^ ((uint32_t)FSb[(RK[3] >> 16) & 0xFF] << 8) + ^ ((uint32_t)FSb[(RK[3] >> 24) & 0xFF] << 16) ^ ((uint32_t)FSb[(RK[3]) & 0xFF] << 24); + + RK[5] = RK[1] ^ RK[4]; + RK[6] = RK[2] ^ RK[5]; + RK[7] = RK[3] ^ RK[6]; + } + break; + + case 12: + + for (i = 0; i < 8; i++, RK += 6) { + RK[6] = RK[0] ^ RCON[i] ^ ((uint32_t)FSb[(RK[5] >> 8) & 0xFF]) ^ ((uint32_t)FSb[(RK[5] >> 16) & 0xFF] << 8) + ^ ((uint32_t)FSb[(RK[5] >> 24) & 0xFF] << 16) ^ ((uint32_t)FSb[(RK[5]) & 0xFF] << 24); + + RK[7] = RK[1] ^ RK[6]; + RK[8] = RK[2] ^ RK[7]; + RK[9] = RK[3] ^ RK[8]; + RK[10] = RK[4] ^ RK[9]; + RK[11] = RK[5] ^ RK[10]; + } + break; + + case 14: + + for (i = 0; i < 7; i++, RK += 8) { + RK[8] = RK[0] ^ RCON[i] ^ ((uint32_t)FSb[(RK[7] >> 8) & 0xFF]) ^ ((uint32_t)FSb[(RK[7] >> 16) & 0xFF] << 8) + ^ ((uint32_t)FSb[(RK[7] >> 24) & 0xFF] << 16) ^ ((uint32_t)FSb[(RK[7]) & 0xFF] << 24); + + RK[9] = RK[1] ^ RK[8]; + RK[10] = RK[2] ^ RK[9]; + RK[11] = RK[3] ^ RK[10]; + + RK[12] = RK[4] ^ ((uint32_t)FSb[(RK[11]) & 0xFF]) ^ ((uint32_t)FSb[(RK[11] >> 8) & 0xFF] << 8) + ^ ((uint32_t)FSb[(RK[11] >> 16) & 0xFF] << 16) ^ ((uint32_t)FSb[(RK[11] >> 24) & 0xFF] << 24); + + RK[13] = RK[5] ^ RK[12]; + RK[14] = RK[6] ^ RK[13]; + RK[15] = RK[7] ^ RK[14]; + } + break; } - return( 0 ); + return (0); } #endif /* !MBEDTLS_AES_SETKEY_ENC_ALT */ @@ -678,29 +546,26 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, * AES key schedule (decryption) */ #if !defined(MBEDTLS_AES_SETKEY_DEC_ALT) -int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits ) +int mbedtls_aes_setkey_dec(mbedtls_aes_context* ctx, const unsigned char* key, unsigned int keybits) { int i, j, ret; mbedtls_aes_context cty; - uint32_t *RK; - uint32_t *SK; + uint32_t* RK; + uint32_t* SK; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( key != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(key != NULL); - mbedtls_aes_init( &cty ); + mbedtls_aes_init(&cty); ctx->rk = RK = ctx->buf; /* Also checks keybits */ - if( ( ret = mbedtls_aes_setkey_enc( &cty, key, keybits ) ) != 0 ) + if ((ret = mbedtls_aes_setkey_enc(&cty, key, keybits)) != 0) goto exit; ctx->nr = cty.nr; - - SK = cty.rk + cty.nr * 4; *RK++ = *SK++; @@ -708,14 +573,10 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, *RK++ = *SK++; *RK++ = *SK++; - for( i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8 ) - { - for( j = 0; j < 4; j++, SK++ ) - { - *RK++ = AES_RT0( FSb[ ( *SK ) & 0xFF ] ) ^ - AES_RT1( FSb[ ( *SK >> 8 ) & 0xFF ] ) ^ - AES_RT2( FSb[ ( *SK >> 16 ) & 0xFF ] ) ^ - AES_RT3( FSb[ ( *SK >> 24 ) & 0xFF ] ); + for (i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8) { + for (j = 0; j < 4; j++, SK++) { + *RK++ = + AES_RT0(FSb[(*SK) & 0xFF]) ^ AES_RT1(FSb[(*SK >> 8) & 0xFF]) ^ AES_RT2(FSb[(*SK >> 16) & 0xFF]) ^ AES_RT3(FSb[(*SK >> 24) & 0xFF]); } } @@ -725,28 +586,31 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, *RK++ = *SK++; exit: - mbedtls_aes_free( &cty ); + mbedtls_aes_free(&cty); - return( ret ); + return (ret); } #endif /* !MBEDTLS_AES_SETKEY_DEC_ALT */ #if defined(MBEDTLS_CIPHER_MODE_XTS) -static int mbedtls_aes_xts_decode_keys( const unsigned char *key, - unsigned int keybits, - const unsigned char **key1, - unsigned int *key1bits, - const unsigned char **key2, - unsigned int *key2bits ) +static int mbedtls_aes_xts_decode_keys( + const unsigned char* key, + unsigned int keybits, + const unsigned char** key1, + unsigned int* key1bits, + const unsigned char** key2, + unsigned int* key2bits) { const unsigned int half_keybits = keybits / 2; const unsigned int half_keybytes = half_keybits / 8; - switch( keybits ) - { - case 256: break; - case 512: break; - default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); + switch (keybits) { + case 256: + break; + case 512: + break; + default: + return (MBEDTLS_ERR_AES_INVALID_KEY_LENGTH); } *key1bits = half_keybits; @@ -757,175 +621,129 @@ static int mbedtls_aes_xts_decode_keys( const unsigned char *key, return 0; } -int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, - const unsigned char *key, - unsigned int keybits) +int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context* ctx, const unsigned char* key, unsigned int keybits) { int ret; const unsigned char *key1, *key2; unsigned int key1bits, key2bits; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( key != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(key != NULL); - ret = mbedtls_aes_xts_decode_keys( key, keybits, &key1, &key1bits, - &key2, &key2bits ); - if( ret != 0 ) - return( ret ); + ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits, &key2, &key2bits); + if (ret != 0) + return (ret); /* Set the tweak key. Always set tweak key for the encryption mode. */ - ret = mbedtls_aes_setkey_enc( &ctx->tweak, key2, key2bits ); - if( ret != 0 ) - return( ret ); + ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits); + if (ret != 0) + return (ret); /* Set crypt key for encryption. */ - return mbedtls_aes_setkey_enc( &ctx->crypt, key1, key1bits ); + return mbedtls_aes_setkey_enc(&ctx->crypt, key1, key1bits); } -int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, - const unsigned char *key, - unsigned int keybits) +int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context* ctx, const unsigned char* key, unsigned int keybits) { int ret; const unsigned char *key1, *key2; unsigned int key1bits, key2bits; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( key != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(key != NULL); - ret = mbedtls_aes_xts_decode_keys( key, keybits, &key1, &key1bits, - &key2, &key2bits ); - if( ret != 0 ) - return( ret ); + ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits, &key2, &key2bits); + if (ret != 0) + return (ret); /* Set the tweak key. Always set tweak key for encryption. */ - ret = mbedtls_aes_setkey_enc( &ctx->tweak, key2, key2bits ); - if( ret != 0 ) - return( ret ); + ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits); + if (ret != 0) + return (ret); /* Set crypt key for decryption. */ - return mbedtls_aes_setkey_dec( &ctx->crypt, key1, key1bits ); + return mbedtls_aes_setkey_dec(&ctx->crypt, key1, key1bits); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ -#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ - do \ - { \ - (X0) = *RK++ ^ AES_FT0( ( (Y0) ) & 0xFF ) ^ \ - AES_FT1( ( (Y1) >> 8 ) & 0xFF ) ^ \ - AES_FT2( ( (Y2) >> 16 ) & 0xFF ) ^ \ - AES_FT3( ( (Y3) >> 24 ) & 0xFF ); \ - \ - (X1) = *RK++ ^ AES_FT0( ( (Y1) ) & 0xFF ) ^ \ - AES_FT1( ( (Y2) >> 8 ) & 0xFF ) ^ \ - AES_FT2( ( (Y3) >> 16 ) & 0xFF ) ^ \ - AES_FT3( ( (Y0) >> 24 ) & 0xFF ); \ - \ - (X2) = *RK++ ^ AES_FT0( ( (Y2) ) & 0xFF ) ^ \ - AES_FT1( ( (Y3) >> 8 ) & 0xFF ) ^ \ - AES_FT2( ( (Y0) >> 16 ) & 0xFF ) ^ \ - AES_FT3( ( (Y1) >> 24 ) & 0xFF ); \ - \ - (X3) = *RK++ ^ AES_FT0( ( (Y3) ) & 0xFF ) ^ \ - AES_FT1( ( (Y0) >> 8 ) & 0xFF ) ^ \ - AES_FT2( ( (Y1) >> 16 ) & 0xFF ) ^ \ - AES_FT3( ( (Y2) >> 24 ) & 0xFF ); \ - } while( 0 ) - -#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ - do \ - { \ - (X0) = *RK++ ^ AES_RT0( ( (Y0) ) & 0xFF ) ^ \ - AES_RT1( ( (Y3) >> 8 ) & 0xFF ) ^ \ - AES_RT2( ( (Y2) >> 16 ) & 0xFF ) ^ \ - AES_RT3( ( (Y1) >> 24 ) & 0xFF ); \ - \ - (X1) = *RK++ ^ AES_RT0( ( (Y1) ) & 0xFF ) ^ \ - AES_RT1( ( (Y0) >> 8 ) & 0xFF ) ^ \ - AES_RT2( ( (Y3) >> 16 ) & 0xFF ) ^ \ - AES_RT3( ( (Y2) >> 24 ) & 0xFF ); \ - \ - (X2) = *RK++ ^ AES_RT0( ( (Y2) ) & 0xFF ) ^ \ - AES_RT1( ( (Y1) >> 8 ) & 0xFF ) ^ \ - AES_RT2( ( (Y0) >> 16 ) & 0xFF ) ^ \ - AES_RT3( ( (Y3) >> 24 ) & 0xFF ); \ - \ - (X3) = *RK++ ^ AES_RT0( ( (Y3) ) & 0xFF ) ^ \ - AES_RT1( ( (Y2) >> 8 ) & 0xFF ) ^ \ - AES_RT2( ( (Y1) >> 16 ) & 0xFF ) ^ \ - AES_RT3( ( (Y0) >> 24 ) & 0xFF ); \ - } while( 0 ) +#define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \ + do { \ + (X0) = *RK++ ^ AES_FT0(((Y0)) & 0xFF) ^ AES_FT1(((Y1) >> 8) & 0xFF) ^ AES_FT2(((Y2) >> 16) & 0xFF) ^ AES_FT3(((Y3) >> 24) & 0xFF); \ +\ + (X1) = *RK++ ^ AES_FT0(((Y1)) & 0xFF) ^ AES_FT1(((Y2) >> 8) & 0xFF) ^ AES_FT2(((Y3) >> 16) & 0xFF) ^ AES_FT3(((Y0) >> 24) & 0xFF); \ +\ + (X2) = *RK++ ^ AES_FT0(((Y2)) & 0xFF) ^ AES_FT1(((Y3) >> 8) & 0xFF) ^ AES_FT2(((Y0) >> 16) & 0xFF) ^ AES_FT3(((Y1) >> 24) & 0xFF); \ +\ + (X3) = *RK++ ^ AES_FT0(((Y3)) & 0xFF) ^ AES_FT1(((Y0) >> 8) & 0xFF) ^ AES_FT2(((Y1) >> 16) & 0xFF) ^ AES_FT3(((Y2) >> 24) & 0xFF); \ + } while (0) + +#define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \ + do { \ + (X0) = *RK++ ^ AES_RT0(((Y0)) & 0xFF) ^ AES_RT1(((Y3) >> 8) & 0xFF) ^ AES_RT2(((Y2) >> 16) & 0xFF) ^ AES_RT3(((Y1) >> 24) & 0xFF); \ +\ + (X1) = *RK++ ^ AES_RT0(((Y1)) & 0xFF) ^ AES_RT1(((Y0) >> 8) & 0xFF) ^ AES_RT2(((Y3) >> 16) & 0xFF) ^ AES_RT3(((Y2) >> 24) & 0xFF); \ +\ + (X2) = *RK++ ^ AES_RT0(((Y2)) & 0xFF) ^ AES_RT1(((Y1) >> 8) & 0xFF) ^ AES_RT2(((Y0) >> 16) & 0xFF) ^ AES_RT3(((Y3) >> 24) & 0xFF); \ +\ + (X3) = *RK++ ^ AES_RT0(((Y3)) & 0xFF) ^ AES_RT1(((Y2) >> 8) & 0xFF) ^ AES_RT2(((Y1) >> 16) & 0xFF) ^ AES_RT3(((Y0) >> 24) & 0xFF); \ + } while (0) /* * AES-ECB block encryption */ #if !defined(MBEDTLS_AES_ENCRYPT_ALT) -int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16] ) +int mbedtls_internal_aes_encrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]) { int i; - uint32_t *RK = ctx->rk; - struct - { + uint32_t* RK = ctx->rk; + struct { uint32_t X[4]; uint32_t Y[4]; } t; - GET_UINT32_LE( t.X[0], input, 0 ); t.X[0] ^= *RK++; - GET_UINT32_LE( t.X[1], input, 4 ); t.X[1] ^= *RK++; - GET_UINT32_LE( t.X[2], input, 8 ); t.X[2] ^= *RK++; - GET_UINT32_LE( t.X[3], input, 12 ); t.X[3] ^= *RK++; - - for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- ) - { - AES_FROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); - AES_FROUND( t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3] ); + GET_UINT32_LE(t.X[0], input, 0); + t.X[0] ^= *RK++; + GET_UINT32_LE(t.X[1], input, 4); + t.X[1] ^= *RK++; + GET_UINT32_LE(t.X[2], input, 8); + t.X[2] ^= *RK++; + GET_UINT32_LE(t.X[3], input, 12); + t.X[3] ^= *RK++; + + for (i = (ctx->nr >> 1) - 1; i > 0; i--) { + AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); + AES_FROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]); } - AES_FROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); + AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); - t.X[0] = *RK++ ^ \ - ( (uint32_t) FSb[ ( t.Y[0] ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( t.Y[1] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( t.Y[2] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( t.Y[3] >> 24 ) & 0xFF ] << 24 ); + t.X[0] = *RK++ ^ ((uint32_t)FSb[(t.Y[0]) & 0xFF]) ^ ((uint32_t)FSb[(t.Y[1] >> 8) & 0xFF] << 8) ^ ((uint32_t)FSb[(t.Y[2] >> 16) & 0xFF] << 16) + ^ ((uint32_t)FSb[(t.Y[3] >> 24) & 0xFF] << 24); - t.X[1] = *RK++ ^ \ - ( (uint32_t) FSb[ ( t.Y[1] ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( t.Y[2] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( t.Y[3] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( t.Y[0] >> 24 ) & 0xFF ] << 24 ); + t.X[1] = *RK++ ^ ((uint32_t)FSb[(t.Y[1]) & 0xFF]) ^ ((uint32_t)FSb[(t.Y[2] >> 8) & 0xFF] << 8) ^ ((uint32_t)FSb[(t.Y[3] >> 16) & 0xFF] << 16) + ^ ((uint32_t)FSb[(t.Y[0] >> 24) & 0xFF] << 24); - t.X[2] = *RK++ ^ \ - ( (uint32_t) FSb[ ( t.Y[2] ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( t.Y[3] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( t.Y[0] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( t.Y[1] >> 24 ) & 0xFF ] << 24 ); + t.X[2] = *RK++ ^ ((uint32_t)FSb[(t.Y[2]) & 0xFF]) ^ ((uint32_t)FSb[(t.Y[3] >> 8) & 0xFF] << 8) ^ ((uint32_t)FSb[(t.Y[0] >> 16) & 0xFF] << 16) + ^ ((uint32_t)FSb[(t.Y[1] >> 24) & 0xFF] << 24); - t.X[3] = *RK++ ^ \ - ( (uint32_t) FSb[ ( t.Y[3] ) & 0xFF ] ) ^ - ( (uint32_t) FSb[ ( t.Y[0] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) FSb[ ( t.Y[1] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) FSb[ ( t.Y[2] >> 24 ) & 0xFF ] << 24 ); + t.X[3] = *RK++ ^ ((uint32_t)FSb[(t.Y[3]) & 0xFF]) ^ ((uint32_t)FSb[(t.Y[0] >> 8) & 0xFF] << 8) ^ ((uint32_t)FSb[(t.Y[1] >> 16) & 0xFF] << 16) + ^ ((uint32_t)FSb[(t.Y[2] >> 24) & 0xFF] << 24); - PUT_UINT32_LE( t.X[0], output, 0 ); - PUT_UINT32_LE( t.X[1], output, 4 ); - PUT_UINT32_LE( t.X[2], output, 8 ); - PUT_UINT32_LE( t.X[3], output, 12 ); + PUT_UINT32_LE(t.X[0], output, 0); + PUT_UINT32_LE(t.X[1], output, 4); + PUT_UINT32_LE(t.X[2], output, 8); + PUT_UINT32_LE(t.X[3], output, 12); - mbedtls_platform_zeroize( &t, sizeof( t ) ); + mbedtls_platform_zeroize(&t, sizeof(t)); - return( 0 ); + return (0); } #endif /* !MBEDTLS_AES_ENCRYPT_ALT */ #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_aes_encrypt( mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16] ) +void mbedtls_aes_encrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]) { - mbedtls_internal_aes_encrypt( ctx, input, output ); + mbedtls_internal_aes_encrypt(ctx, input, output); } #endif /* !MBEDTLS_DEPRECATED_REMOVED */ @@ -933,153 +751,124 @@ void mbedtls_aes_encrypt( mbedtls_aes_context *ctx, * AES-ECB block decryption */ #if !defined(MBEDTLS_AES_DECRYPT_ALT) -int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16] ) +int mbedtls_internal_aes_decrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]) { int i; - uint32_t *RK = ctx->rk; - struct - { + uint32_t* RK = ctx->rk; + struct { uint32_t X[4]; uint32_t Y[4]; } t; - GET_UINT32_LE( t.X[0], input, 0 ); t.X[0] ^= *RK++; - GET_UINT32_LE( t.X[1], input, 4 ); t.X[1] ^= *RK++; - GET_UINT32_LE( t.X[2], input, 8 ); t.X[2] ^= *RK++; - GET_UINT32_LE( t.X[3], input, 12 ); t.X[3] ^= *RK++; - - for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- ) - { - AES_RROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); - AES_RROUND( t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3] ); + GET_UINT32_LE(t.X[0], input, 0); + t.X[0] ^= *RK++; + GET_UINT32_LE(t.X[1], input, 4); + t.X[1] ^= *RK++; + GET_UINT32_LE(t.X[2], input, 8); + t.X[2] ^= *RK++; + GET_UINT32_LE(t.X[3], input, 12); + t.X[3] ^= *RK++; + + for (i = (ctx->nr >> 1) - 1; i > 0; i--) { + AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); + AES_RROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]); } - AES_RROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); + AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); - t.X[0] = *RK++ ^ \ - ( (uint32_t) RSb[ ( t.Y[0] ) & 0xFF ] ) ^ - ( (uint32_t) RSb[ ( t.Y[3] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) RSb[ ( t.Y[2] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) RSb[ ( t.Y[1] >> 24 ) & 0xFF ] << 24 ); + t.X[0] = *RK++ ^ ((uint32_t)RSb[(t.Y[0]) & 0xFF]) ^ ((uint32_t)RSb[(t.Y[3] >> 8) & 0xFF] << 8) ^ ((uint32_t)RSb[(t.Y[2] >> 16) & 0xFF] << 16) + ^ ((uint32_t)RSb[(t.Y[1] >> 24) & 0xFF] << 24); - t.X[1] = *RK++ ^ \ - ( (uint32_t) RSb[ ( t.Y[1] ) & 0xFF ] ) ^ - ( (uint32_t) RSb[ ( t.Y[0] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) RSb[ ( t.Y[3] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) RSb[ ( t.Y[2] >> 24 ) & 0xFF ] << 24 ); + t.X[1] = *RK++ ^ ((uint32_t)RSb[(t.Y[1]) & 0xFF]) ^ ((uint32_t)RSb[(t.Y[0] >> 8) & 0xFF] << 8) ^ ((uint32_t)RSb[(t.Y[3] >> 16) & 0xFF] << 16) + ^ ((uint32_t)RSb[(t.Y[2] >> 24) & 0xFF] << 24); - t.X[2] = *RK++ ^ \ - ( (uint32_t) RSb[ ( t.Y[2] ) & 0xFF ] ) ^ - ( (uint32_t) RSb[ ( t.Y[1] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) RSb[ ( t.Y[0] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) RSb[ ( t.Y[3] >> 24 ) & 0xFF ] << 24 ); + t.X[2] = *RK++ ^ ((uint32_t)RSb[(t.Y[2]) & 0xFF]) ^ ((uint32_t)RSb[(t.Y[1] >> 8) & 0xFF] << 8) ^ ((uint32_t)RSb[(t.Y[0] >> 16) & 0xFF] << 16) + ^ ((uint32_t)RSb[(t.Y[3] >> 24) & 0xFF] << 24); - t.X[3] = *RK++ ^ \ - ( (uint32_t) RSb[ ( t.Y[3] ) & 0xFF ] ) ^ - ( (uint32_t) RSb[ ( t.Y[2] >> 8 ) & 0xFF ] << 8 ) ^ - ( (uint32_t) RSb[ ( t.Y[1] >> 16 ) & 0xFF ] << 16 ) ^ - ( (uint32_t) RSb[ ( t.Y[0] >> 24 ) & 0xFF ] << 24 ); + t.X[3] = *RK++ ^ ((uint32_t)RSb[(t.Y[3]) & 0xFF]) ^ ((uint32_t)RSb[(t.Y[2] >> 8) & 0xFF] << 8) ^ ((uint32_t)RSb[(t.Y[1] >> 16) & 0xFF] << 16) + ^ ((uint32_t)RSb[(t.Y[0] >> 24) & 0xFF] << 24); - PUT_UINT32_LE( t.X[0], output, 0 ); - PUT_UINT32_LE( t.X[1], output, 4 ); - PUT_UINT32_LE( t.X[2], output, 8 ); - PUT_UINT32_LE( t.X[3], output, 12 ); + PUT_UINT32_LE(t.X[0], output, 0); + PUT_UINT32_LE(t.X[1], output, 4); + PUT_UINT32_LE(t.X[2], output, 8); + PUT_UINT32_LE(t.X[3], output, 12); - mbedtls_platform_zeroize( &t, sizeof( t ) ); + mbedtls_platform_zeroize(&t, sizeof(t)); - return( 0 ); + return (0); } #endif /* !MBEDTLS_AES_DECRYPT_ALT */ #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_aes_decrypt( mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16] ) +void mbedtls_aes_decrypt(mbedtls_aes_context* ctx, const unsigned char input[16], unsigned char output[16]) { - mbedtls_internal_aes_decrypt( ctx, input, output ); + mbedtls_internal_aes_decrypt(ctx, input, output); } #endif /* !MBEDTLS_DEPRECATED_REMOVED */ /* * AES-ECB block encryption/decryption */ -int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16] ) +int mbedtls_aes_crypt_ecb(mbedtls_aes_context* ctx, int mode, const unsigned char input[16], unsigned char output[16]) { - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( input != NULL ); - AES_VALIDATE_RET( output != NULL ); - AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || - mode == MBEDTLS_AES_DECRYPT ); - - if( mode == MBEDTLS_AES_ENCRYPT ) - return( mbedtls_internal_aes_encrypt( ctx, input, output ) ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(input != NULL); + AES_VALIDATE_RET(output != NULL); + AES_VALIDATE_RET(mode == MBEDTLS_AES_ENCRYPT || mode == MBEDTLS_AES_DECRYPT); + + if (mode == MBEDTLS_AES_ENCRYPT) + return (mbedtls_internal_aes_encrypt(ctx, input, output)); else - return( mbedtls_internal_aes_decrypt( ctx, input, output ) ); + return (mbedtls_internal_aes_decrypt(ctx, input, output)); } #if defined(MBEDTLS_CIPHER_MODE_CBC) /* * AES-CBC buffer encryption/decryption */ -int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_aes_crypt_cbc(mbedtls_aes_context* ctx, int mode, size_t length, unsigned char iv[16], const unsigned char* input, unsigned char* output) { int i; unsigned char temp[16]; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || - mode == MBEDTLS_AES_DECRYPT ); - AES_VALIDATE_RET( iv != NULL ); - AES_VALIDATE_RET( input != NULL ); - AES_VALIDATE_RET( output != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(mode == MBEDTLS_AES_ENCRYPT || mode == MBEDTLS_AES_DECRYPT); + AES_VALIDATE_RET(iv != NULL); + AES_VALIDATE_RET(input != NULL); + AES_VALIDATE_RET(output != NULL); - if( length % 16 ) - return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); + if (length % 16) + return (MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH); - if( mode == MBEDTLS_AES_DECRYPT ) - { - while( length > 0 ) - { - memcpy( temp, input, 16 ); - mbedtls_aes_crypt_ecb( ctx, mode, input, output ); + if (mode == MBEDTLS_AES_DECRYPT) { + while (length > 0) { + memcpy(temp, input, 16); + mbedtls_aes_crypt_ecb(ctx, mode, input, output); - for( i = 0; i < 16; i++ ) - output[i] = (unsigned char)( output[i] ^ iv[i] ); + for (i = 0; i < 16; i++) + output[i] = (unsigned char)(output[i] ^ iv[i]); - memcpy( iv, temp, 16 ); + memcpy(iv, temp, 16); - input += 16; + input += 16; output += 16; length -= 16; } - } - else - { - while( length > 0 ) - { - for( i = 0; i < 16; i++ ) - output[i] = (unsigned char)( input[i] ^ iv[i] ); + } else { + while (length > 0) { + for (i = 0; i < 16; i++) + output[i] = (unsigned char)(input[i] ^ iv[i]); - mbedtls_aes_crypt_ecb( ctx, mode, output, output ); - memcpy( iv, output, 16 ); + mbedtls_aes_crypt_ecb(ctx, mode, output, output); + memcpy(iv, output, 16); - input += 16; + input += 16; output += 16; length -= 16; } } - return( 0 ); + return (0); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -1087,31 +876,25 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, /* Endianess with 64 bits values */ #ifndef GET_UINT64_LE -#define GET_UINT64_LE(n,b,i) \ -{ \ - (n) = ( (uint64_t) (b)[(i) + 7] << 56 ) \ - | ( (uint64_t) (b)[(i) + 6] << 48 ) \ - | ( (uint64_t) (b)[(i) + 5] << 40 ) \ - | ( (uint64_t) (b)[(i) + 4] << 32 ) \ - | ( (uint64_t) (b)[(i) + 3] << 24 ) \ - | ( (uint64_t) (b)[(i) + 2] << 16 ) \ - | ( (uint64_t) (b)[(i) + 1] << 8 ) \ - | ( (uint64_t) (b)[(i) ] ); \ -} +#define GET_UINT64_LE(n, b, i) \ + { \ + (n) = ((uint64_t)(b)[(i) + 7] << 56) | ((uint64_t)(b)[(i) + 6] << 48) | ((uint64_t)(b)[(i) + 5] << 40) | ((uint64_t)(b)[(i) + 4] << 32) \ + | ((uint64_t)(b)[(i) + 3] << 24) | ((uint64_t)(b)[(i) + 2] << 16) | ((uint64_t)(b)[(i) + 1] << 8) | ((uint64_t)(b)[(i)]); \ + } #endif #ifndef PUT_UINT64_LE -#define PUT_UINT64_LE(n,b,i) \ -{ \ - (b)[(i) + 7] = (unsigned char) ( (n) >> 56 ); \ - (b)[(i) + 6] = (unsigned char) ( (n) >> 48 ); \ - (b)[(i) + 5] = (unsigned char) ( (n) >> 40 ); \ - (b)[(i) + 4] = (unsigned char) ( (n) >> 32 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) ] = (unsigned char) ( (n) ); \ -} +#define PUT_UINT64_LE(n, b, i) \ + { \ + (b)[(i) + 7] = (unsigned char)((n) >> 56); \ + (b)[(i) + 6] = (unsigned char)((n) >> 48); \ + (b)[(i) + 5] = (unsigned char)((n) >> 40); \ + (b)[(i) + 4] = (unsigned char)((n) >> 32); \ + (b)[(i) + 3] = (unsigned char)((n) >> 24); \ + (b)[(i) + 2] = (unsigned char)((n) >> 16); \ + (b)[(i) + 1] = (unsigned char)((n) >> 8); \ + (b)[(i)] = (unsigned char)((n)); \ + } #endif typedef unsigned char mbedtls_be128[16]; @@ -1124,30 +907,25 @@ typedef unsigned char mbedtls_be128[16]; * for machine endianess and hence works correctly on both big and little * endian machines. */ -static void mbedtls_gf128mul_x_ble( unsigned char r[16], - const unsigned char x[16] ) +static void mbedtls_gf128mul_x_ble(unsigned char r[16], const unsigned char x[16]) { uint64_t a, b, ra, rb; - GET_UINT64_LE( a, x, 0 ); - GET_UINT64_LE( b, x, 8 ); + GET_UINT64_LE(a, x, 0); + GET_UINT64_LE(b, x, 8); - ra = ( a << 1 ) ^ 0x0087 >> ( 8 - ( ( b >> 63 ) << 3 ) ); - rb = ( a >> 63 ) | ( b << 1 ); + ra = (a << 1) ^ 0x0087 >> (8 - ((b >> 63) << 3)); + rb = (a >> 63) | (b << 1); - PUT_UINT64_LE( ra, r, 0 ); - PUT_UINT64_LE( rb, r, 8 ); + PUT_UINT64_LE(ra, r, 0); + PUT_UINT64_LE(rb, r, 8); } /* * AES-XTS buffer encryption/decryption */ -int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, - int mode, - size_t length, - const unsigned char data_unit[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_aes_crypt_xts( + mbedtls_aes_xts_context* ctx, int mode, size_t length, const unsigned char data_unit[16], const unsigned char* input, unsigned char* output) { int ret; size_t blocks = length / 16; @@ -1156,96 +934,90 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, unsigned char prev_tweak[16]; unsigned char tmp[16]; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || - mode == MBEDTLS_AES_DECRYPT ); - AES_VALIDATE_RET( data_unit != NULL ); - AES_VALIDATE_RET( input != NULL ); - AES_VALIDATE_RET( output != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(mode == MBEDTLS_AES_ENCRYPT || mode == MBEDTLS_AES_DECRYPT); + AES_VALIDATE_RET(data_unit != NULL); + AES_VALIDATE_RET(input != NULL); + AES_VALIDATE_RET(output != NULL); /* Data units must be at least 16 bytes long. */ - if( length < 16 ) + if (length < 16) return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; /* NIST SP 800-38E disallows data units larger than 2**20 blocks. */ - if( length > ( 1 << 20 ) * 16 ) + if (length > (1 << 20) * 16) return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; /* Compute the tweak. */ - ret = mbedtls_aes_crypt_ecb( &ctx->tweak, MBEDTLS_AES_ENCRYPT, - data_unit, tweak ); - if( ret != 0 ) - return( ret ); + ret = mbedtls_aes_crypt_ecb(&ctx->tweak, MBEDTLS_AES_ENCRYPT, data_unit, tweak); + if (ret != 0) + return (ret); - while( blocks-- ) - { + while (blocks--) { size_t i; - if( leftover && ( mode == MBEDTLS_AES_DECRYPT ) && blocks == 0 ) - { + if (leftover && (mode == MBEDTLS_AES_DECRYPT) && blocks == 0) { /* We are on the last block in a decrypt operation that has * leftover bytes, so we need to use the next tweak for this block, * and this tweak for the lefover bytes. Save the current tweak for * the leftovers and then update the current tweak for use on this, * the last full block. */ - memcpy( prev_tweak, tweak, sizeof( tweak ) ); - mbedtls_gf128mul_x_ble( tweak, tweak ); + memcpy(prev_tweak, tweak, sizeof(tweak)); + mbedtls_gf128mul_x_ble(tweak, tweak); } - for( i = 0; i < 16; i++ ) + for (i = 0; i < 16; i++) tmp[i] = input[i] ^ tweak[i]; - ret = mbedtls_aes_crypt_ecb( &ctx->crypt, mode, tmp, tmp ); - if( ret != 0 ) - return( ret ); + ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp); + if (ret != 0) + return (ret); - for( i = 0; i < 16; i++ ) + for (i = 0; i < 16; i++) output[i] = tmp[i] ^ tweak[i]; /* Update the tweak for the next block. */ - mbedtls_gf128mul_x_ble( tweak, tweak ); + mbedtls_gf128mul_x_ble(tweak, tweak); output += 16; input += 16; } - if( leftover ) - { + if (leftover) { /* If we are on the leftover bytes in a decrypt operation, we need to * use the previous tweak for these bytes (as saved in prev_tweak). */ - unsigned char *t = mode == MBEDTLS_AES_DECRYPT ? prev_tweak : tweak; + unsigned char* t = mode == MBEDTLS_AES_DECRYPT ? prev_tweak : tweak; /* We are now on the final part of the data unit, which doesn't divide * evenly by 16. It's time for ciphertext stealing. */ size_t i; - unsigned char *prev_output = output - 16; + unsigned char* prev_output = output - 16; /* Copy ciphertext bytes from the previous block to our output for each * byte of cyphertext we won't steal. At the same time, copy the * remainder of the input for this final round (since the loop bounds * are the same). */ - for( i = 0; i < leftover; i++ ) - { + for (i = 0; i < leftover; i++) { output[i] = prev_output[i]; tmp[i] = input[i] ^ t[i]; } /* Copy ciphertext bytes from the previous block for input in this * round. */ - for( ; i < 16; i++ ) + for (; i < 16; i++) tmp[i] = prev_output[i] ^ t[i]; - ret = mbedtls_aes_crypt_ecb( &ctx->crypt, mode, tmp, tmp ); - if( ret != 0 ) + ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp); + if (ret != 0) return ret; /* Write the result back to the previous block, overriding the previous * output we copied. */ - for( i = 0; i < 16; i++ ) + for (i = 0; i < 16; i++) prev_output[i] = tmp[i] ^ t[i]; } - return( 0 ); + return (0); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ @@ -1253,98 +1025,80 @@ int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, /* * AES-CFB128 buffer encryption/decryption */ -int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, - int mode, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_aes_crypt_cfb128( + mbedtls_aes_context* ctx, int mode, size_t length, size_t* iv_off, unsigned char iv[16], const unsigned char* input, unsigned char* output) { int c; size_t n; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || - mode == MBEDTLS_AES_DECRYPT ); - AES_VALIDATE_RET( iv_off != NULL ); - AES_VALIDATE_RET( iv != NULL ); - AES_VALIDATE_RET( input != NULL ); - AES_VALIDATE_RET( output != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(mode == MBEDTLS_AES_ENCRYPT || mode == MBEDTLS_AES_DECRYPT); + AES_VALIDATE_RET(iv_off != NULL); + AES_VALIDATE_RET(iv != NULL); + AES_VALIDATE_RET(input != NULL); + AES_VALIDATE_RET(output != NULL); n = *iv_off; - if( n > 15 ) - return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + if (n > 15) + return (MBEDTLS_ERR_AES_BAD_INPUT_DATA); - if( mode == MBEDTLS_AES_DECRYPT ) - { - while( length-- ) - { - if( n == 0 ) - mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); + if (mode == MBEDTLS_AES_DECRYPT) { + while (length--) { + if (n == 0) + mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); c = *input++; - *output++ = (unsigned char)( c ^ iv[n] ); - iv[n] = (unsigned char) c; + *output++ = (unsigned char)(c ^ iv[n]); + iv[n] = (unsigned char)c; - n = ( n + 1 ) & 0x0F; + n = (n + 1) & 0x0F; } - } - else - { - while( length-- ) - { - if( n == 0 ) - mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); + } else { + while (length--) { + if (n == 0) + mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); - iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); + iv[n] = *output++ = (unsigned char)(iv[n] ^ *input++); - n = ( n + 1 ) & 0x0F; + n = (n + 1) & 0x0F; } } *iv_off = n; - return( 0 ); + return (0); } /* * AES-CFB8 buffer encryption/decryption */ -int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_aes_crypt_cfb8(mbedtls_aes_context* ctx, int mode, size_t length, unsigned char iv[16], const unsigned char* input, unsigned char* output) { unsigned char c; unsigned char ov[17]; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || - mode == MBEDTLS_AES_DECRYPT ); - AES_VALIDATE_RET( iv != NULL ); - AES_VALIDATE_RET( input != NULL ); - AES_VALIDATE_RET( output != NULL ); - while( length-- ) - { - memcpy( ov, iv, 16 ); - mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(mode == MBEDTLS_AES_ENCRYPT || mode == MBEDTLS_AES_DECRYPT); + AES_VALIDATE_RET(iv != NULL); + AES_VALIDATE_RET(input != NULL); + AES_VALIDATE_RET(output != NULL); + while (length--) { + memcpy(ov, iv, 16); + mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); - if( mode == MBEDTLS_AES_DECRYPT ) + if (mode == MBEDTLS_AES_DECRYPT) ov[16] = *input; - c = *output++ = (unsigned char)( iv[0] ^ *input++ ); + c = *output++ = (unsigned char)(iv[0] ^ *input++); - if( mode == MBEDTLS_AES_ENCRYPT ) + if (mode == MBEDTLS_AES_ENCRYPT) ov[16] = c; - memcpy( iv, ov + 1, 16 ); + memcpy(iv, ov + 1, 16); } - return( 0 ); + return (0); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ @@ -1352,44 +1106,38 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, /* * AES-OFB (Output Feedback Mode) buffer encryption/decryption */ -int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_aes_crypt_ofb( + mbedtls_aes_context* ctx, size_t length, size_t* iv_off, unsigned char iv[16], const unsigned char* input, unsigned char* output) { int ret = 0; size_t n; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( iv_off != NULL ); - AES_VALIDATE_RET( iv != NULL ); - AES_VALIDATE_RET( input != NULL ); - AES_VALIDATE_RET( output != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(iv_off != NULL); + AES_VALIDATE_RET(iv != NULL); + AES_VALIDATE_RET(input != NULL); + AES_VALIDATE_RET(output != NULL); n = *iv_off; - if( n > 15 ) - return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + if (n > 15) + return (MBEDTLS_ERR_AES_BAD_INPUT_DATA); - while( length-- ) - { - if( n == 0 ) - { - ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); - if( ret != 0 ) + while (length--) { + if (n == 0) { + ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); + if (ret != 0) goto exit; } - *output++ = *input++ ^ iv[n]; + *output++ = *input++ ^ iv[n]; - n = ( n + 1 ) & 0x0F; + n = (n + 1) & 0x0F; } *iv_off = n; exit: - return( ret ); + return (ret); } #endif /* MBEDTLS_CIPHER_MODE_OFB */ @@ -1397,47 +1145,47 @@ exit: /* * AES-CTR buffer encryption/decryption */ -int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, - size_t length, - size_t *nc_off, - unsigned char nonce_counter[16], - unsigned char stream_block[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_aes_crypt_ctr( + mbedtls_aes_context* ctx, + size_t length, + size_t* nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char* input, + unsigned char* output) { int c, i; size_t n; - AES_VALIDATE_RET( ctx != NULL ); - AES_VALIDATE_RET( nc_off != NULL ); - AES_VALIDATE_RET( nonce_counter != NULL ); - AES_VALIDATE_RET( stream_block != NULL ); - AES_VALIDATE_RET( input != NULL ); - AES_VALIDATE_RET( output != NULL ); + AES_VALIDATE_RET(ctx != NULL); + AES_VALIDATE_RET(nc_off != NULL); + AES_VALIDATE_RET(nonce_counter != NULL); + AES_VALIDATE_RET(stream_block != NULL); + AES_VALIDATE_RET(input != NULL); + AES_VALIDATE_RET(output != NULL); n = *nc_off; - if ( n > 0x0F ) - return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + if (n > 0x0F) + return (MBEDTLS_ERR_AES_BAD_INPUT_DATA); - while( length-- ) - { - if( n == 0 ) { - mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block ); + while (length--) { + if (n == 0) { + mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block); - for( i = 16; i > 0; i-- ) - if( ++nonce_counter[i - 1] != 0 ) + for (i = 16; i > 0; i--) + if (++nonce_counter[i - 1] != 0) break; } c = *input++; - *output++ = (unsigned char)( c ^ stream_block[n] ); + *output++ = (unsigned char)(c ^ stream_block[n]); - n = ( n + 1 ) & 0x0F; + n = (n + 1) & 0x0F; } *nc_off = n; - return( 0 ); + return (0); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ @@ -1449,45 +1197,29 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, * * http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip */ -static const unsigned char aes_test_ecb_dec[3][16] = -{ - { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, - 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 }, - { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, - 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 }, - { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, - 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE } +static const unsigned char aes_test_ecb_dec[3][16] = { + {0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0}, + {0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4}, + {0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE} }; -static const unsigned char aes_test_ecb_enc[3][16] = -{ - { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, - 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F }, - { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, - 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 }, - { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, - 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 } +static const unsigned char aes_test_ecb_enc[3][16] = { + {0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F}, + {0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14}, + {0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4} }; #if defined(MBEDTLS_CIPHER_MODE_CBC) -static const unsigned char aes_test_cbc_dec[3][16] = -{ - { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73, - 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 }, - { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75, - 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B }, - { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75, - 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 } +static const unsigned char aes_test_cbc_dec[3][16] = { + {0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73, 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86}, + {0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75, 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B}, + {0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75, 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13} }; -static const unsigned char aes_test_cbc_enc[3][16] = -{ - { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84, - 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D }, - { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB, - 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 }, - { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5, - 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 } +static const unsigned char aes_test_cbc_enc[3][16] = { + {0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84, 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D}, + {0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB, 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04}, + {0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5, 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0} }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -1497,63 +1229,30 @@ static const unsigned char aes_test_cbc_enc[3][16] = * * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf */ -static const unsigned char aes_test_cfb128_key[3][32] = -{ - { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, - 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, - { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, - 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, - 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }, - { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, - 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, - 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, - 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } -}; - -static const unsigned char aes_test_cfb128_iv[16] = -{ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F +static const unsigned char aes_test_cfb128_key[3][32] = { + {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C}, + {0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B}, + {0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, + 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4} }; -static const unsigned char aes_test_cfb128_pt[64] = -{ - 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, - 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, - 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, - 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, - 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, - 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, - 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, - 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 -}; - -static const unsigned char aes_test_cfb128_ct[3][64] = -{ - { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, - 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, - 0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F, - 0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B, - 0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40, - 0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF, - 0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E, - 0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 }, - { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, - 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, - 0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21, - 0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A, - 0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1, - 0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9, - 0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0, - 0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF }, - { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, - 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, - 0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8, - 0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B, - 0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92, - 0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9, - 0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8, - 0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 } +static const unsigned char aes_test_cfb128_iv[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; + +static const unsigned char aes_test_cfb128_pt[64] = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, + 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, + 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, + 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10}; + +static const unsigned char aes_test_cfb128_ct[3][64] = { + {0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, 0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, + 0xA9, 0x3F, 0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B, 0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40, 0xB1, 0x80, 0x8C, 0xF1, + 0x87, 0xA4, 0xF4, 0xDF, 0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E, 0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6}, + {0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, 0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, + 0x36, 0x21, 0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A, 0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1, 0xC8, 0xE6, 0x0F, 0xED, + 0x1E, 0xFA, 0xC4, 0xC9, 0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0, 0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF}, + {0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, 0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, + 0xB1, 0xC8, 0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B, 0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92, 0xA1, 0x3E, 0xD0, 0xA8, + 0x26, 0x7A, 0xE2, 0xF9, 0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8, 0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71} }; #endif /* MBEDTLS_CIPHER_MODE_CFB */ @@ -1563,63 +1262,30 @@ static const unsigned char aes_test_cfb128_ct[3][64] = * * https://csrc.nist.gov/publications/detail/sp/800-38a/final */ -static const unsigned char aes_test_ofb_key[3][32] = -{ - { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, - 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, - { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, - 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, - 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }, - { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, - 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, - 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, - 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } -}; - -static const unsigned char aes_test_ofb_iv[16] = -{ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F +static const unsigned char aes_test_ofb_key[3][32] = { + {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C}, + {0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B}, + {0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, + 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4} }; -static const unsigned char aes_test_ofb_pt[64] = -{ - 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, - 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, - 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, - 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, - 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, - 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, - 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, - 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 -}; - -static const unsigned char aes_test_ofb_ct[3][64] = -{ - { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, - 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, - 0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, 0x8f, 0x03, - 0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25, - 0x97, 0x40, 0x05, 0x1e, 0x9c, 0x5f, 0xec, 0xf6, - 0x43, 0x44, 0xf7, 0xa8, 0x22, 0x60, 0xed, 0xcc, - 0x30, 0x4c, 0x65, 0x28, 0xf6, 0x59, 0xc7, 0x78, - 0x66, 0xa5, 0x10, 0xd9, 0xc1, 0xd6, 0xae, 0x5e }, - { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, - 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, - 0xfc, 0xc2, 0x8b, 0x8d, 0x4c, 0x63, 0x83, 0x7c, - 0x09, 0xe8, 0x17, 0x00, 0xc1, 0x10, 0x04, 0x01, - 0x8d, 0x9a, 0x9a, 0xea, 0xc0, 0xf6, 0x59, 0x6f, - 0x55, 0x9c, 0x6d, 0x4d, 0xaf, 0x59, 0xa5, 0xf2, - 0x6d, 0x9f, 0x20, 0x08, 0x57, 0xca, 0x6c, 0x3e, - 0x9c, 0xac, 0x52, 0x4b, 0xd9, 0xac, 0xc9, 0x2a }, - { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, - 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, - 0x4f, 0xeb, 0xdc, 0x67, 0x40, 0xd2, 0x0b, 0x3a, - 0xc8, 0x8f, 0x6a, 0xd8, 0x2a, 0x4f, 0xb0, 0x8d, - 0x71, 0xab, 0x47, 0xa0, 0x86, 0xe8, 0x6e, 0xed, - 0xf3, 0x9d, 0x1c, 0x5b, 0xba, 0x97, 0xc4, 0x08, - 0x01, 0x26, 0x14, 0x1d, 0x67, 0xf3, 0x7b, 0xe8, - 0x53, 0x8f, 0x5a, 0x8b, 0xe7, 0x40, 0xe4, 0x84 } +static const unsigned char aes_test_ofb_iv[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; + +static const unsigned char aes_test_ofb_pt[64] = {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, + 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, + 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, + 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10}; + +static const unsigned char aes_test_ofb_ct[3][64] = { + {0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, 0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, + 0x8f, 0x03, 0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25, 0x97, 0x40, 0x05, 0x1e, 0x9c, 0x5f, 0xec, 0xf6, 0x43, 0x44, 0xf7, 0xa8, + 0x22, 0x60, 0xed, 0xcc, 0x30, 0x4c, 0x65, 0x28, 0xf6, 0x59, 0xc7, 0x78, 0x66, 0xa5, 0x10, 0xd9, 0xc1, 0xd6, 0xae, 0x5e}, + {0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, 0xfc, 0xc2, 0x8b, 0x8d, 0x4c, 0x63, + 0x83, 0x7c, 0x09, 0xe8, 0x17, 0x00, 0xc1, 0x10, 0x04, 0x01, 0x8d, 0x9a, 0x9a, 0xea, 0xc0, 0xf6, 0x59, 0x6f, 0x55, 0x9c, 0x6d, 0x4d, + 0xaf, 0x59, 0xa5, 0xf2, 0x6d, 0x9f, 0x20, 0x08, 0x57, 0xca, 0x6c, 0x3e, 0x9c, 0xac, 0x52, 0x4b, 0xd9, 0xac, 0xc9, 0x2a}, + {0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, 0x4f, 0xeb, 0xdc, 0x67, 0x40, 0xd2, + 0x0b, 0x3a, 0xc8, 0x8f, 0x6a, 0xd8, 0x2a, 0x4f, 0xb0, 0x8d, 0x71, 0xab, 0x47, 0xa0, 0x86, 0xe8, 0x6e, 0xed, 0xf3, 0x9d, 0x1c, 0x5b, + 0xba, 0x97, 0xc4, 0x08, 0x01, 0x26, 0x14, 0x1d, 0x67, 0xf3, 0x7b, 0xe8, 0x53, 0x8f, 0x5a, 0x8b, 0xe7, 0x40, 0xe4, 0x84} }; #endif /* MBEDTLS_CIPHER_MODE_OFB */ @@ -1630,60 +1296,37 @@ static const unsigned char aes_test_ofb_ct[3][64] = * http://www.faqs.org/rfcs/rfc3686.html */ -static const unsigned char aes_test_ctr_key[3][16] = -{ - { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC, - 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E }, - { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, - 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 }, - { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8, - 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC } +static const unsigned char aes_test_ctr_key[3][16] = { + {0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC, 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E}, + {0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63}, + {0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8, 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC} }; -static const unsigned char aes_test_ctr_nonce_counter[3][16] = -{ - { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, - { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, - 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 }, - { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, - 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 } +static const unsigned char aes_test_ctr_nonce_counter[3][16] = { + {0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01} }; -static const unsigned char aes_test_ctr_pt[3][48] = -{ - { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, - 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 }, - - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }, - - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23 } +static const unsigned char aes_test_ctr_pt[3][48] = { + {0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67}, + + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}, + + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23} }; -static const unsigned char aes_test_ctr_ct[3][48] = -{ - { 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79, - 0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 }, - { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9, - 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88, - 0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8, - 0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 }, - { 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9, - 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7, - 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36, - 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53, - 0x25, 0xB2, 0x07, 0x2F } +static const unsigned char aes_test_ctr_ct[3][48] = { + {0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79, 0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8}, + {0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9, 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88, + 0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8, 0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28}, + {0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9, 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7, 0x45, 0x40, + 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36, 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53, 0x25, 0xB2, 0x07, 0x2F} }; -static const int aes_test_ctr_len[3] = - { 16, 32, 36 }; +static const int aes_test_ctr_len[3] = {16, 32, 36}; #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) @@ -1694,62 +1337,37 @@ static const int aes_test_ctr_len[3] = * https://web.archive.org/web/20150629024421/http://grouper.ieee.org/groups/1619/email/pdf00086.pdf * (Archived from original at http://grouper.ieee.org/groups/1619/email/pdf00086.pdf) */ -static const unsigned char aes_test_xts_key[][32] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, - 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }, - { 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, - 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }, +static const unsigned char aes_test_xts_key[][32] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22}, + {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22}, }; -static const unsigned char aes_test_xts_pt32[][32] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }, - { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }, +static const unsigned char aes_test_xts_pt32[][32] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, + {0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44}, }; -static const unsigned char aes_test_xts_ct32[][32] = -{ - { 0x91, 0x7c, 0xf6, 0x9e, 0xbd, 0x68, 0xb2, 0xec, - 0x9b, 0x9f, 0xe9, 0xa3, 0xea, 0xdd, 0xa6, 0x92, - 0xcd, 0x43, 0xd2, 0xf5, 0x95, 0x98, 0xed, 0x85, - 0x8c, 0x02, 0xc2, 0x65, 0x2f, 0xbf, 0x92, 0x2e }, - { 0xc4, 0x54, 0x18, 0x5e, 0x6a, 0x16, 0x93, 0x6e, - 0x39, 0x33, 0x40, 0x38, 0xac, 0xef, 0x83, 0x8b, - 0xfb, 0x18, 0x6f, 0xff, 0x74, 0x80, 0xad, 0xc4, - 0x28, 0x93, 0x82, 0xec, 0xd6, 0xd3, 0x94, 0xf0 }, - { 0xaf, 0x85, 0x33, 0x6b, 0x59, 0x7a, 0xfc, 0x1a, - 0x90, 0x0b, 0x2e, 0xb2, 0x1e, 0xc9, 0x49, 0xd2, - 0x92, 0xdf, 0x4c, 0x04, 0x7e, 0x0b, 0x21, 0x53, - 0x21, 0x86, 0xa5, 0x97, 0x1a, 0x22, 0x7a, 0x89 }, +static const unsigned char aes_test_xts_ct32[][32] = { + {0x91, 0x7c, 0xf6, 0x9e, 0xbd, 0x68, 0xb2, 0xec, 0x9b, 0x9f, 0xe9, 0xa3, 0xea, 0xdd, 0xa6, 0x92, + 0xcd, 0x43, 0xd2, 0xf5, 0x95, 0x98, 0xed, 0x85, 0x8c, 0x02, 0xc2, 0x65, 0x2f, 0xbf, 0x92, 0x2e}, + {0xc4, 0x54, 0x18, 0x5e, 0x6a, 0x16, 0x93, 0x6e, 0x39, 0x33, 0x40, 0x38, 0xac, 0xef, 0x83, 0x8b, + 0xfb, 0x18, 0x6f, 0xff, 0x74, 0x80, 0xad, 0xc4, 0x28, 0x93, 0x82, 0xec, 0xd6, 0xd3, 0x94, 0xf0}, + {0xaf, 0x85, 0x33, 0x6b, 0x59, 0x7a, 0xfc, 0x1a, 0x90, 0x0b, 0x2e, 0xb2, 0x1e, 0xc9, 0x49, 0xd2, + 0x92, 0xdf, 0x4c, 0x04, 0x7e, 0x0b, 0x21, 0x53, 0x21, 0x86, 0xa5, 0x97, 0x1a, 0x22, 0x7a, 0x89}, }; -static const unsigned char aes_test_xts_data_unit[][16] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, +static const unsigned char aes_test_xts_data_unit[][16] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, }; #endif /* MBEDTLS_CIPHER_MODE_XTS */ @@ -1757,21 +1375,20 @@ static const unsigned char aes_test_xts_data_unit[][16] = /* * Checkup routine */ -int mbedtls_aes_self_test( int verbose ) +int mbedtls_aes_self_test(int verbose) { int ret = 0, i, j, u, mode; unsigned int keybits; unsigned char key[32]; unsigned char buf[64]; - const unsigned char *aes_tests; + const unsigned char* aes_tests; #if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB) unsigned char iv[16]; #endif #if defined(MBEDTLS_CIPHER_MODE_CBC) unsigned char prv[16]; #endif -#if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB) || \ - defined(MBEDTLS_CIPHER_MODE_OFB) +#if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB) || defined(MBEDTLS_CIPHER_MODE_OFB) size_t offset; #endif #if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_XTS) @@ -1783,32 +1400,27 @@ int mbedtls_aes_self_test( int verbose ) #endif mbedtls_aes_context ctx; - memset( key, 0, 32 ); - mbedtls_aes_init( &ctx ); + memset(key, 0, 32); + mbedtls_aes_init(&ctx); /* * ECB mode */ - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { u = i >> 1; keybits = 128 + u * 64; mode = i & 1; - if( verbose != 0 ) - mbedtls_printf( " AES-ECB-%3d (%s): ", keybits, - ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + if (verbose != 0) + mbedtls_printf(" AES-ECB-%3d (%s): ", keybits, (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - memset( buf, 0, 16 ); + memset(buf, 0, 16); - if( mode == MBEDTLS_AES_DECRYPT ) - { - ret = mbedtls_aes_setkey_dec( &ctx, key, keybits ); + if (mode == MBEDTLS_AES_DECRYPT) { + ret = mbedtls_aes_setkey_dec(&ctx, key, keybits); aes_tests = aes_test_ecb_dec[u]; - } - else - { - ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + } else { + ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); aes_tests = aes_test_ecb_enc[u]; } @@ -1817,62 +1429,52 @@ int mbedtls_aes_self_test( int verbose ) * there is an alternative underlying implementation i.e. when * MBEDTLS_AES_ALT is defined. */ - if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) - { - mbedtls_printf( "skipped\n" ); + if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { + mbedtls_printf("skipped\n"); continue; - } - else if( ret != 0 ) - { + } else if (ret != 0) { goto exit; } - for( j = 0; j < 10000; j++ ) - { - ret = mbedtls_aes_crypt_ecb( &ctx, mode, buf, buf ); - if( ret != 0 ) + for (j = 0; j < 10000; j++) { + ret = mbedtls_aes_crypt_ecb(&ctx, mode, buf, buf); + if (ret != 0) goto exit; } - if( memcmp( buf, aes_tests, 16 ) != 0 ) - { + if (memcmp(buf, aes_tests, 16) != 0) { ret = 1; goto exit; } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #if defined(MBEDTLS_CIPHER_MODE_CBC) /* * CBC mode */ - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { u = i >> 1; keybits = 128 + u * 64; mode = i & 1; - if( verbose != 0 ) - mbedtls_printf( " AES-CBC-%3d (%s): ", keybits, - ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + if (verbose != 0) + mbedtls_printf(" AES-CBC-%3d (%s): ", keybits, (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - memset( iv , 0, 16 ); - memset( prv, 0, 16 ); - memset( buf, 0, 16 ); + memset(iv, 0, 16); + memset(prv, 0, 16); + memset(buf, 0, 16); - if( mode == MBEDTLS_AES_DECRYPT ) - { - ret = mbedtls_aes_setkey_dec( &ctx, key, keybits ); + if (mode == MBEDTLS_AES_DECRYPT) { + ret = mbedtls_aes_setkey_dec(&ctx, key, keybits); aes_tests = aes_test_cbc_dec[u]; - } - else - { - ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + } else { + ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); aes_tests = aes_test_cbc_enc[u]; } @@ -1881,301 +1483,260 @@ int mbedtls_aes_self_test( int verbose ) * there is an alternative underlying implementation i.e. when * MBEDTLS_AES_ALT is defined. */ - if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) - { - mbedtls_printf( "skipped\n" ); + if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { + mbedtls_printf("skipped\n"); continue; - } - else if( ret != 0 ) - { + } else if (ret != 0) { goto exit; } - for( j = 0; j < 10000; j++ ) - { - if( mode == MBEDTLS_AES_ENCRYPT ) - { + for (j = 0; j < 10000; j++) { + if (mode == MBEDTLS_AES_ENCRYPT) { unsigned char tmp[16]; - memcpy( tmp, prv, 16 ); - memcpy( prv, buf, 16 ); - memcpy( buf, tmp, 16 ); + memcpy(tmp, prv, 16); + memcpy(prv, buf, 16); + memcpy(buf, tmp, 16); } - ret = mbedtls_aes_crypt_cbc( &ctx, mode, 16, iv, buf, buf ); - if( ret != 0 ) + ret = mbedtls_aes_crypt_cbc(&ctx, mode, 16, iv, buf, buf); + if (ret != 0) goto exit; - } - if( memcmp( buf, aes_tests, 16 ) != 0 ) - { + if (memcmp(buf, aes_tests, 16) != 0) { ret = 1; goto exit; } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) /* * CFB128 mode */ - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { u = i >> 1; keybits = 128 + u * 64; mode = i & 1; - if( verbose != 0 ) - mbedtls_printf( " AES-CFB128-%3d (%s): ", keybits, - ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + if (verbose != 0) + mbedtls_printf(" AES-CFB128-%3d (%s): ", keybits, (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - memcpy( iv, aes_test_cfb128_iv, 16 ); - memcpy( key, aes_test_cfb128_key[u], keybits / 8 ); + memcpy(iv, aes_test_cfb128_iv, 16); + memcpy(key, aes_test_cfb128_key[u], keybits / 8); offset = 0; - ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); /* * AES-192 is an optional feature that may be unavailable when * there is an alternative underlying implementation i.e. when * MBEDTLS_AES_ALT is defined. */ - if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) - { - mbedtls_printf( "skipped\n" ); + if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { + mbedtls_printf("skipped\n"); continue; - } - else if( ret != 0 ) - { + } else if (ret != 0) { goto exit; } - if( mode == MBEDTLS_AES_DECRYPT ) - { - memcpy( buf, aes_test_cfb128_ct[u], 64 ); + if (mode == MBEDTLS_AES_DECRYPT) { + memcpy(buf, aes_test_cfb128_ct[u], 64); aes_tests = aes_test_cfb128_pt; - } - else - { - memcpy( buf, aes_test_cfb128_pt, 64 ); + } else { + memcpy(buf, aes_test_cfb128_pt, 64); aes_tests = aes_test_cfb128_ct[u]; } - ret = mbedtls_aes_crypt_cfb128( &ctx, mode, 64, &offset, iv, buf, buf ); - if( ret != 0 ) + ret = mbedtls_aes_crypt_cfb128(&ctx, mode, 64, &offset, iv, buf, buf); + if (ret != 0) goto exit; - if( memcmp( buf, aes_tests, 64 ) != 0 ) - { + if (memcmp(buf, aes_tests, 64) != 0) { ret = 1; goto exit; } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) /* * OFB mode */ - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { u = i >> 1; keybits = 128 + u * 64; mode = i & 1; - if( verbose != 0 ) - mbedtls_printf( " AES-OFB-%3d (%s): ", keybits, - ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + if (verbose != 0) + mbedtls_printf(" AES-OFB-%3d (%s): ", keybits, (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - memcpy( iv, aes_test_ofb_iv, 16 ); - memcpy( key, aes_test_ofb_key[u], keybits / 8 ); + memcpy(iv, aes_test_ofb_iv, 16); + memcpy(key, aes_test_ofb_key[u], keybits / 8); offset = 0; - ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); /* * AES-192 is an optional feature that may be unavailable when * there is an alternative underlying implementation i.e. when * MBEDTLS_AES_ALT is defined. */ - if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) - { - mbedtls_printf( "skipped\n" ); + if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { + mbedtls_printf("skipped\n"); continue; - } - else if( ret != 0 ) - { + } else if (ret != 0) { goto exit; } - if( mode == MBEDTLS_AES_DECRYPT ) - { - memcpy( buf, aes_test_ofb_ct[u], 64 ); + if (mode == MBEDTLS_AES_DECRYPT) { + memcpy(buf, aes_test_ofb_ct[u], 64); aes_tests = aes_test_ofb_pt; - } - else - { - memcpy( buf, aes_test_ofb_pt, 64 ); + } else { + memcpy(buf, aes_test_ofb_pt, 64); aes_tests = aes_test_ofb_ct[u]; } - ret = mbedtls_aes_crypt_ofb( &ctx, 64, &offset, iv, buf, buf ); - if( ret != 0 ) + ret = mbedtls_aes_crypt_ofb(&ctx, 64, &offset, iv, buf, buf); + if (ret != 0) goto exit; - if( memcmp( buf, aes_tests, 64 ) != 0 ) - { + if (memcmp(buf, aes_tests, 64) != 0) { ret = 1; goto exit; } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) /* * CTR mode */ - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { u = i >> 1; mode = i & 1; - if( verbose != 0 ) - mbedtls_printf( " AES-CTR-128 (%s): ", - ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + if (verbose != 0) + mbedtls_printf(" AES-CTR-128 (%s): ", (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 ); - memcpy( key, aes_test_ctr_key[u], 16 ); + memcpy(nonce_counter, aes_test_ctr_nonce_counter[u], 16); + memcpy(key, aes_test_ctr_key[u], 16); offset = 0; - if( ( ret = mbedtls_aes_setkey_enc( &ctx, key, 128 ) ) != 0 ) + if ((ret = mbedtls_aes_setkey_enc(&ctx, key, 128)) != 0) goto exit; len = aes_test_ctr_len[u]; - if( mode == MBEDTLS_AES_DECRYPT ) - { - memcpy( buf, aes_test_ctr_ct[u], len ); + if (mode == MBEDTLS_AES_DECRYPT) { + memcpy(buf, aes_test_ctr_ct[u], len); aes_tests = aes_test_ctr_pt[u]; - } - else - { - memcpy( buf, aes_test_ctr_pt[u], len ); + } else { + memcpy(buf, aes_test_ctr_pt[u], len); aes_tests = aes_test_ctr_ct[u]; } - ret = mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, - stream_block, buf, buf ); - if( ret != 0 ) + ret = mbedtls_aes_crypt_ctr(&ctx, len, &offset, nonce_counter, stream_block, buf, buf); + if (ret != 0) goto exit; - if( memcmp( buf, aes_tests, len ) != 0 ) - { + if (memcmp(buf, aes_tests, len) != 0) { ret = 1; goto exit; } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) { - static const int num_tests = - sizeof(aes_test_xts_key) / sizeof(*aes_test_xts_key); - mbedtls_aes_xts_context ctx_xts; + static const int num_tests = sizeof(aes_test_xts_key) / sizeof(*aes_test_xts_key); + mbedtls_aes_xts_context ctx_xts; - /* - * XTS mode - */ - mbedtls_aes_xts_init( &ctx_xts ); - - for( i = 0; i < num_tests << 1; i++ ) - { - const unsigned char *data_unit; - u = i >> 1; - mode = i & 1; - - if( verbose != 0 ) - mbedtls_printf( " AES-XTS-128 (%s): ", - ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); - - memset( key, 0, sizeof( key ) ); - memcpy( key, aes_test_xts_key[u], 32 ); - data_unit = aes_test_xts_data_unit[u]; - - len = sizeof( *aes_test_xts_ct32 ); + /* + * XTS mode + */ + mbedtls_aes_xts_init(&ctx_xts); + + for (i = 0; i < num_tests << 1; i++) { + const unsigned char* data_unit; + u = i >> 1; + mode = i & 1; + + if (verbose != 0) + mbedtls_printf(" AES-XTS-128 (%s): ", (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); + + memset(key, 0, sizeof(key)); + memcpy(key, aes_test_xts_key[u], 32); + data_unit = aes_test_xts_data_unit[u]; + + len = sizeof(*aes_test_xts_ct32); + + if (mode == MBEDTLS_AES_DECRYPT) { + ret = mbedtls_aes_xts_setkey_dec(&ctx_xts, key, 256); + if (ret != 0) + goto exit; + memcpy(buf, aes_test_xts_ct32[u], len); + aes_tests = aes_test_xts_pt32[u]; + } else { + ret = mbedtls_aes_xts_setkey_enc(&ctx_xts, key, 256); + if (ret != 0) + goto exit; + memcpy(buf, aes_test_xts_pt32[u], len); + aes_tests = aes_test_xts_ct32[u]; + } - if( mode == MBEDTLS_AES_DECRYPT ) - { - ret = mbedtls_aes_xts_setkey_dec( &ctx_xts, key, 256 ); - if( ret != 0) - goto exit; - memcpy( buf, aes_test_xts_ct32[u], len ); - aes_tests = aes_test_xts_pt32[u]; - } - else - { - ret = mbedtls_aes_xts_setkey_enc( &ctx_xts, key, 256 ); - if( ret != 0) + ret = mbedtls_aes_crypt_xts(&ctx_xts, mode, len, data_unit, buf, buf); + if (ret != 0) goto exit; - memcpy( buf, aes_test_xts_pt32[u], len ); - aes_tests = aes_test_xts_ct32[u]; - } + if (memcmp(buf, aes_tests, len) != 0) { + ret = 1; + goto exit; + } - ret = mbedtls_aes_crypt_xts( &ctx_xts, mode, len, data_unit, - buf, buf ); - if( ret != 0 ) - goto exit; - - if( memcmp( buf, aes_tests, len ) != 0 ) - { - ret = 1; - goto exit; + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); - } - - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); - mbedtls_aes_xts_free( &ctx_xts ); + mbedtls_aes_xts_free(&ctx_xts); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ ret = 0; exit: - if( ret != 0 && verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (ret != 0 && verbose != 0) + mbedtls_printf("failed\n"); - mbedtls_aes_free( &ctx ); + mbedtls_aes_free(&ctx); - return( ret ); + return (ret); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/nettls/ssl/asn1write.c b/nettls/ssl/asn1write.c index 17f047434a40a95058ad4eb776f8901f1f7d1138..40db31317b1b8e1b92e247b92cca804de6ab5946 100644 --- a/nettls/ssl/asn1write.c +++ b/nettls/ssl/asn1write.c @@ -210,8 +210,7 @@ int mbedtls_asn1_write_oid(unsigned char** p, unsigned char* start, const char* return ((int)len); } -int mbedtls_asn1_write_algorithm_identifier( - unsigned char** p, unsigned char* start, const char* oid, size_t oid_len, size_t par_len) +int mbedtls_asn1_write_algorithm_identifier(unsigned char** p, unsigned char* start, const char* oid, size_t oid_len, size_t par_len) { int ret; size_t len = 0; @@ -271,8 +270,7 @@ int mbedtls_asn1_write_int(unsigned char** p, unsigned char* start, int val) return ((int)len); } -int mbedtls_asn1_write_tagged_string( - unsigned char** p, unsigned char* start, int tag, const char* text, size_t text_len) +int mbedtls_asn1_write_tagged_string(unsigned char** p, unsigned char* start, int tag, const char* text, size_t text_len) { int ret; size_t len = 0; @@ -359,8 +357,8 @@ static mbedtls_asn1_named_data* asn1_find_named_data(mbedtls_asn1_named_data* li return (list); } -mbedtls_asn1_named_data* mbedtls_asn1_store_named_data( - mbedtls_asn1_named_data** head, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len) +mbedtls_asn1_named_data* + mbedtls_asn1_store_named_data(mbedtls_asn1_named_data** head, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len) { mbedtls_asn1_named_data* cur; diff --git a/nettls/ssl/base64.c b/nettls/ssl/base64.c index 128f47004fb36de33abce04934dcc48989f7d4f5..6b94de33ba6c22cd2a0eb0943130b17db655dee7 100644 --- a/nettls/ssl/base64.c +++ b/nettls/ssl/base64.c @@ -66,26 +66,24 @@ #endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_SELF_TEST */ -static const unsigned char base64_enc_map[64] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', - 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', - 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; +static const unsigned char base64_enc_map[64] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; static const unsigned char base64_dec_map[128] = { - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 62, - 127, 127, 127, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 127, 127, 127, 64, 127, 127, 127, 0, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, 127, 127, 127, 127, 127, 127, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 127, 127, 127, 127, 127}; + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 62, 127, 127, 127, 63, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 127, 127, 127, 64, 127, 127, 127, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 127, 127, 127, 127, 127, 127, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 127, 127, 127, 127, 127}; #define BASE64_SIZE_T_MAX ((size_t)-1) /* SIZE_T_MAX is not standard */ /* * Constant flow conditional assignment to unsigned char */ -static void - mbedtls_base64_cond_assign_uchar(unsigned char* dest, const unsigned char* const src, unsigned char condition) +static void mbedtls_base64_cond_assign_uchar(unsigned char* dest, const unsigned char* const src, unsigned char condition) { /* MSVC has a warning about unary minus on unsigned integer types, * but this is well-defined and precisely what we want to do here. */ @@ -159,8 +157,7 @@ static unsigned char mbedtls_base64_eq(size_t in_a, size_t in_b) /* * Constant flow lookup into table. */ -static unsigned char - mbedtls_base64_table_lookup(const unsigned char* const table, const size_t table_size, const size_t table_index) +static unsigned char mbedtls_base64_table_lookup(const unsigned char* const table, const size_t table_size, const size_t table_index) { size_t i; unsigned char result = 0; @@ -209,11 +206,9 @@ int mbedtls_base64_encode(unsigned char* dst, size_t dlen, size_t* olen, const u *p++ = mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), ((C1 >> 2) & 0x3F)); - *p++ = - mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), ((((C1 & 3) << 4) + (C2 >> 4)) & 0x3F)); + *p++ = mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), ((((C1 & 3) << 4) + (C2 >> 4)) & 0x3F)); - *p++ = mbedtls_base64_table_lookup( - base64_enc_map, sizeof(base64_enc_map), ((((C2 & 15) << 2) + (C3 >> 6)) & 0x3F)); + *p++ = mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), ((((C2 & 15) << 2) + (C3 >> 6)) & 0x3F)); *p++ = mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), (C3 & 0x3F)); } @@ -224,8 +219,7 @@ int mbedtls_base64_encode(unsigned char* dst, size_t dlen, size_t* olen, const u *p++ = mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), ((C1 >> 2) & 0x3F)); - *p++ = - mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), ((((C1 & 3) << 4) + (C2 >> 4)) & 0x3F)); + *p++ = mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), ((((C1 & 3) << 4) + (C2 >> 4)) & 0x3F)); if ((i + 1) < slen) *p++ = mbedtls_base64_table_lookup(base64_enc_map, sizeof(base64_enc_map), (((C2 & 15) << 2) & 0x3F)); @@ -332,11 +326,10 @@ int mbedtls_base64_decode(unsigned char* dst, size_t dlen, size_t* olen, const u #if defined(MBEDTLS_SELF_TEST) -static const unsigned char base64_test_dec[64] = { - 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD, 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01, - 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09, 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13, - 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31, 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38, - 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B, 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97}; +static const unsigned char base64_test_dec[64] = {0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD, 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01, + 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09, 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13, + 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31, 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38, + 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B, 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97}; static const unsigned char base64_test_enc[] = "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK" "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw=="; diff --git a/nettls/ssl/bignum.c b/nettls/ssl/bignum.c index a4a3b4e0e4579868830037e652326572c64f1345..cebd1d963178cf279de26cbd2bb1630457ae84d9 100644 --- a/nettls/ssl/bignum.c +++ b/nettls/ssl/bignum.c @@ -821,8 +821,7 @@ static void mpi_bigendian_to_host(mbedtls_mpi_uint* const p, size_t limbs) * than the right index (it's not a problem if limbs is odd and the * indices coincide in the last iteration). */ - for (cur_limb_left = p, cur_limb_right = p + (limbs - 1); cur_limb_left <= cur_limb_right; - cur_limb_left++, cur_limb_right--) { + for (cur_limb_left = p, cur_limb_right = p + (limbs - 1); cur_limb_left <= cur_limb_right; cur_limb_left++, cur_limb_right--) { mbedtls_mpi_uint tmp; /* Note that if cur_limb_left == cur_limb_right, * this code effectively swaps the bytes only once. */ @@ -1467,8 +1466,7 @@ static MULADDC_INIT MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE - MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE - MULADDC_STOP + MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_CORE MULADDC_STOP } for (; i >= 8; i -= 8) { @@ -1564,8 +1562,7 @@ int mbedtls_mpi_mul_int(mbedtls_mpi* X, const mbedtls_mpi* A, mbedtls_mpi_uint b * Unsigned integer divide - double mbedtls_mpi_uint dividend, u1/u0, and * mbedtls_mpi_uint divisor, d */ -static mbedtls_mpi_uint - mbedtls_int_div_int(mbedtls_mpi_uint u1, mbedtls_mpi_uint u0, mbedtls_mpi_uint d, mbedtls_mpi_uint* r) +static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1, mbedtls_mpi_uint u0, mbedtls_mpi_uint d, mbedtls_mpi_uint* r) { #if defined(MBEDTLS_HAVE_UDBL) mbedtls_t_udbl dividend, quotient; @@ -1908,8 +1905,7 @@ static void mpi_montg_init(mbedtls_mpi_uint* mm, const mbedtls_mpi* N) * Note that unlike the usual convention in the library * for `const mbedtls_mpi*`, the content of T can change. */ -static void - mpi_montmul(mbedtls_mpi* A, const mbedtls_mpi* B, const mbedtls_mpi* N, mbedtls_mpi_uint mm, const mbedtls_mpi* T) +static void mpi_montmul(mbedtls_mpi* A, const mbedtls_mpi* B, const mbedtls_mpi* N, mbedtls_mpi_uint mm, const mbedtls_mpi* T) { size_t i, n, m; mbedtls_mpi_uint u0, u1, *d; @@ -1974,8 +1970,7 @@ static void mpi_montred(mbedtls_mpi* A, const mbedtls_mpi* N, mbedtls_mpi_uint m /* * Sliding-window exponentiation: X = A^E mod N (HAC 14.85) */ -int mbedtls_mpi_exp_mod( - mbedtls_mpi* X, const mbedtls_mpi* A, const mbedtls_mpi* E, const mbedtls_mpi* N, mbedtls_mpi* _RR) +int mbedtls_mpi_exp_mod(mbedtls_mpi* X, const mbedtls_mpi* A, const mbedtls_mpi* E, const mbedtls_mpi* N, mbedtls_mpi* _RR) { int ret; size_t wbits, wsize, one = 1; @@ -2374,14 +2369,12 @@ cleanup: #if defined(MBEDTLS_GENPRIME) static const int small_prime[] = { - 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, - 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, - 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, - 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, - 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, - 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, - 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, - 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, -103}; + 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, + 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, + 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, + 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, + 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, + 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, -103}; /* * Small divisors test (X must be positive) @@ -2418,8 +2411,7 @@ cleanup: /* * Miller-Rabin pseudo-primality test (HAC 4.24) */ -static int - mpi_miller_rabin(const mbedtls_mpi* X, size_t rounds, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +static int mpi_miller_rabin(const mbedtls_mpi* X, size_t rounds, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret, count; size_t i, j, k, s; @@ -2560,8 +2552,7 @@ int mbedtls_mpi_is_prime(const mbedtls_mpi* X, int (*f_rng)(void*, unsigned char * be either 1024 bits or 1536 bits long, and flags must contain * MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR. */ -int mbedtls_mpi_gen_prime( - mbedtls_mpi* X, size_t nbits, int flags, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +int mbedtls_mpi_gen_prime(mbedtls_mpi* X, size_t nbits, int flags, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { #ifdef MBEDTLS_HAVE_INT64 // ceil(2^63.5) @@ -2657,8 +2648,7 @@ int mbedtls_mpi_gen_prime( * before doing Miller-Rabin on any of them */ if ((ret = mpi_check_small_factors(X)) == 0 && (ret = mpi_check_small_factors(&Y)) == 0 - && (ret = mpi_miller_rabin(X, rounds, f_rng, p_rng)) == 0 - && (ret = mpi_miller_rabin(&Y, rounds, f_rng, p_rng)) == 0) + && (ret = mpi_miller_rabin(X, rounds, f_rng, p_rng)) == 0 && (ret = mpi_miller_rabin(&Y, rounds, f_rng, p_rng)) == 0) goto cleanup; if (ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) diff --git a/nettls/ssl/blowfish.c b/nettls/ssl/blowfish.c index 1cce539a44e0ce8bf85ef0a73cd15d8657862f48..49007945bfb41f0f16cfbdb711f7d88b595704e5 100644 --- a/nettls/ssl/blowfish.c +++ b/nettls/ssl/blowfish.c @@ -75,8 +75,7 @@ #ifndef GET_UINT32_BE #define GET_UINT32_BE(n, b, i) \ { \ - (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) \ - | ((uint32_t)(b)[(i) + 3]); \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ } #endif @@ -90,10 +89,9 @@ } #endif -static const uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2] = {0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L, 0xA4093822L, - 0x299F31D0L, 0x082EFA98L, 0xEC4E6C89L, 0x452821E6L, 0x38D01377L, - 0xBE5466CFL, 0x34E90C6CL, 0xC0AC29B7L, 0xC97C50DDL, 0x3F84D5B5L, - 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL}; +static const uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2] = {0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L, 0xA4093822L, 0x299F31D0L, + 0x082EFA98L, 0xEC4E6C89L, 0x452821E6L, 0x38D01377L, 0xBE5466CFL, 0x34E90C6CL, + 0xC0AC29B7L, 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL}; /* declarations of data at the end of this file */ static const uint32_t S[4][256]; @@ -242,10 +240,7 @@ int mbedtls_blowfish_setkey(mbedtls_blowfish_context* ctx, const unsigned char* * Blowfish-ECB block encryption/decryption */ int mbedtls_blowfish_crypt_ecb( - mbedtls_blowfish_context* ctx, - int mode, - const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], - unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE]) + mbedtls_blowfish_context* ctx, int mode, const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE]) { uint32_t X0, X1; BLOWFISH_VALIDATE_RET(ctx != NULL); @@ -426,134 +421,102 @@ int mbedtls_blowfish_crypt_ctr( #endif /* MBEDTLS_CIPHER_MODE_CTR */ static const uint32_t S[4][256] = { - {0xD1310BA6L, 0x98DFB5ACL, 0x2FFD72DBL, 0xD01ADFB7L, 0xB8E1AFEDL, 0x6A267E96L, 0xBA7C9045L, 0xF12C7F99L, - 0x24A19947L, 0xB3916CF7L, 0x0801F2E2L, 0x858EFC16L, 0x636920D8L, 0x71574E69L, 0xA458FEA3L, 0xF4933D7EL, - 0x0D95748FL, 0x728EB658L, 0x718BCD58L, 0x82154AEEL, 0x7B54A41DL, 0xC25A59B5L, 0x9C30D539L, 0x2AF26013L, - 0xC5D1B023L, 0x286085F0L, 0xCA417918L, 0xB8DB38EFL, 0x8E79DCB0L, 0x603A180EL, 0x6C9E0E8BL, 0xB01E8A3EL, - 0xD71577C1L, 0xBD314B27L, 0x78AF2FDAL, 0x55605C60L, 0xE65525F3L, 0xAA55AB94L, 0x57489862L, 0x63E81440L, - 0x55CA396AL, 0x2AAB10B6L, 0xB4CC5C34L, 0x1141E8CEL, 0xA15486AFL, 0x7C72E993L, 0xB3EE1411L, 0x636FBC2AL, - 0x2BA9C55DL, 0x741831F6L, 0xCE5C3E16L, 0x9B87931EL, 0xAFD6BA33L, 0x6C24CF5CL, 0x7A325381L, 0x28958677L, - 0x3B8F4898L, 0x6B4BB9AFL, 0xC4BFE81BL, 0x66282193L, 0x61D809CCL, 0xFB21A991L, 0x487CAC60L, 0x5DEC8032L, - 0xEF845D5DL, 0xE98575B1L, 0xDC262302L, 0xEB651B88L, 0x23893E81L, 0xD396ACC5L, 0x0F6D6FF3L, 0x83F44239L, - 0x2E0B4482L, 0xA4842004L, 0x69C8F04AL, 0x9E1F9B5EL, 0x21C66842L, 0xF6E96C9AL, 0x670C9C61L, 0xABD388F0L, - 0x6A51A0D2L, 0xD8542F68L, 0x960FA728L, 0xAB5133A3L, 0x6EEF0B6CL, 0x137A3BE4L, 0xBA3BF050L, 0x7EFB2A98L, - 0xA1F1651DL, 0x39AF0176L, 0x66CA593EL, 0x82430E88L, 0x8CEE8619L, 0x456F9FB4L, 0x7D84A5C3L, 0x3B8B5EBEL, - 0xE06F75D8L, 0x85C12073L, 0x401A449FL, 0x56C16AA6L, 0x4ED3AA62L, 0x363F7706L, 0x1BFEDF72L, 0x429B023DL, - 0x37D0D724L, 0xD00A1248L, 0xDB0FEAD3L, 0x49F1C09BL, 0x075372C9L, 0x80991B7BL, 0x25D479D8L, 0xF6E8DEF7L, - 0xE3FE501AL, 0xB6794C3BL, 0x976CE0BDL, 0x04C006BAL, 0xC1A94FB6L, 0x409F60C4L, 0x5E5C9EC2L, 0x196A2463L, - 0x68FB6FAFL, 0x3E6C53B5L, 0x1339B2EBL, 0x3B52EC6FL, 0x6DFC511FL, 0x9B30952CL, 0xCC814544L, 0xAF5EBD09L, - 0xBEE3D004L, 0xDE334AFDL, 0x660F2807L, 0x192E4BB3L, 0xC0CBA857L, 0x45C8740FL, 0xD20B5F39L, 0xB9D3FBDBL, - 0x5579C0BDL, 0x1A60320AL, 0xD6A100C6L, 0x402C7279L, 0x679F25FEL, 0xFB1FA3CCL, 0x8EA5E9F8L, 0xDB3222F8L, - 0x3C7516DFL, 0xFD616B15L, 0x2F501EC8L, 0xAD0552ABL, 0x323DB5FAL, 0xFD238760L, 0x53317B48L, 0x3E00DF82L, - 0x9E5C57BBL, 0xCA6F8CA0L, 0x1A87562EL, 0xDF1769DBL, 0xD542A8F6L, 0x287EFFC3L, 0xAC6732C6L, 0x8C4F5573L, - 0x695B27B0L, 0xBBCA58C8L, 0xE1FFA35DL, 0xB8F011A0L, 0x10FA3D98L, 0xFD2183B8L, 0x4AFCB56CL, 0x2DD1D35BL, - 0x9A53E479L, 0xB6F84565L, 0xD28E49BCL, 0x4BFB9790L, 0xE1DDF2DAL, 0xA4CB7E33L, 0x62FB1341L, 0xCEE4C6E8L, - 0xEF20CADAL, 0x36774C01L, 0xD07E9EFEL, 0x2BF11FB4L, 0x95DBDA4DL, 0xAE909198L, 0xEAAD8E71L, 0x6B93D5A0L, - 0xD08ED1D0L, 0xAFC725E0L, 0x8E3C5B2FL, 0x8E7594B7L, 0x8FF6E2FBL, 0xF2122B64L, 0x8888B812L, 0x900DF01CL, - 0x4FAD5EA0L, 0x688FC31CL, 0xD1CFF191L, 0xB3A8C1ADL, 0x2F2F2218L, 0xBE0E1777L, 0xEA752DFEL, 0x8B021FA1L, - 0xE5A0CC0FL, 0xB56F74E8L, 0x18ACF3D6L, 0xCE89E299L, 0xB4A84FE0L, 0xFD13E0B7L, 0x7CC43B81L, 0xD2ADA8D9L, - 0x165FA266L, 0x80957705L, 0x93CC7314L, 0x211A1477L, 0xE6AD2065L, 0x77B5FA86L, 0xC75442F5L, 0xFB9D35CFL, - 0xEBCDAF0CL, 0x7B3E89A0L, 0xD6411BD3L, 0xAE1E7E49L, 0x00250E2DL, 0x2071B35EL, 0x226800BBL, 0x57B8E0AFL, - 0x2464369BL, 0xF009B91EL, 0x5563911DL, 0x59DFA6AAL, 0x78C14389L, 0xD95A537FL, 0x207D5BA2L, 0x02E5B9C5L, - 0x83260376L, 0x6295CFA9L, 0x11C81968L, 0x4E734A41L, 0xB3472DCAL, 0x7B14A94AL, 0x1B510052L, 0x9A532915L, - 0xD60F573FL, 0xBC9BC6E4L, 0x2B60A476L, 0x81E67400L, 0x08BA6FB5L, 0x571BE91FL, 0xF296EC6BL, 0x2A0DD915L, - 0xB6636521L, 0xE7B9F9B6L, 0xFF34052EL, 0xC5855664L, 0x53B02D5DL, 0xA99F8FA1L, 0x08BA4799L, 0x6E85076AL}, - {0x4B7A70E9L, 0xB5B32944L, 0xDB75092EL, 0xC4192623L, 0xAD6EA6B0L, 0x49A7DF7DL, 0x9CEE60B8L, 0x8FEDB266L, - 0xECAA8C71L, 0x699A17FFL, 0x5664526CL, 0xC2B19EE1L, 0x193602A5L, 0x75094C29L, 0xA0591340L, 0xE4183A3EL, - 0x3F54989AL, 0x5B429D65L, 0x6B8FE4D6L, 0x99F73FD6L, 0xA1D29C07L, 0xEFE830F5L, 0x4D2D38E6L, 0xF0255DC1L, - 0x4CDD2086L, 0x8470EB26L, 0x6382E9C6L, 0x021ECC5EL, 0x09686B3FL, 0x3EBAEFC9L, 0x3C971814L, 0x6B6A70A1L, - 0x687F3584L, 0x52A0E286L, 0xB79C5305L, 0xAA500737L, 0x3E07841CL, 0x7FDEAE5CL, 0x8E7D44ECL, 0x5716F2B8L, - 0xB03ADA37L, 0xF0500C0DL, 0xF01C1F04L, 0x0200B3FFL, 0xAE0CF51AL, 0x3CB574B2L, 0x25837A58L, 0xDC0921BDL, - 0xD19113F9L, 0x7CA92FF6L, 0x94324773L, 0x22F54701L, 0x3AE5E581L, 0x37C2DADCL, 0xC8B57634L, 0x9AF3DDA7L, - 0xA9446146L, 0x0FD0030EL, 0xECC8C73EL, 0xA4751E41L, 0xE238CD99L, 0x3BEA0E2FL, 0x3280BBA1L, 0x183EB331L, - 0x4E548B38L, 0x4F6DB908L, 0x6F420D03L, 0xF60A04BFL, 0x2CB81290L, 0x24977C79L, 0x5679B072L, 0xBCAF89AFL, - 0xDE9A771FL, 0xD9930810L, 0xB38BAE12L, 0xDCCF3F2EL, 0x5512721FL, 0x2E6B7124L, 0x501ADDE6L, 0x9F84CD87L, - 0x7A584718L, 0x7408DA17L, 0xBC9F9ABCL, 0xE94B7D8CL, 0xEC7AEC3AL, 0xDB851DFAL, 0x63094366L, 0xC464C3D2L, - 0xEF1C1847L, 0x3215D908L, 0xDD433B37L, 0x24C2BA16L, 0x12A14D43L, 0x2A65C451L, 0x50940002L, 0x133AE4DDL, - 0x71DFF89EL, 0x10314E55L, 0x81AC77D6L, 0x5F11199BL, 0x043556F1L, 0xD7A3C76BL, 0x3C11183BL, 0x5924A509L, - 0xF28FE6EDL, 0x97F1FBFAL, 0x9EBABF2CL, 0x1E153C6EL, 0x86E34570L, 0xEAE96FB1L, 0x860E5E0AL, 0x5A3E2AB3L, - 0x771FE71CL, 0x4E3D06FAL, 0x2965DCB9L, 0x99E71D0FL, 0x803E89D6L, 0x5266C825L, 0x2E4CC978L, 0x9C10B36AL, - 0xC6150EBAL, 0x94E2EA78L, 0xA5FC3C53L, 0x1E0A2DF4L, 0xF2F74EA7L, 0x361D2B3DL, 0x1939260FL, 0x19C27960L, - 0x5223A708L, 0xF71312B6L, 0xEBADFE6EL, 0xEAC31F66L, 0xE3BC4595L, 0xA67BC883L, 0xB17F37D1L, 0x018CFF28L, - 0xC332DDEFL, 0xBE6C5AA5L, 0x65582185L, 0x68AB9802L, 0xEECEA50FL, 0xDB2F953BL, 0x2AEF7DADL, 0x5B6E2F84L, - 0x1521B628L, 0x29076170L, 0xECDD4775L, 0x619F1510L, 0x13CCA830L, 0xEB61BD96L, 0x0334FE1EL, 0xAA0363CFL, - 0xB5735C90L, 0x4C70A239L, 0xD59E9E0BL, 0xCBAADE14L, 0xEECC86BCL, 0x60622CA7L, 0x9CAB5CABL, 0xB2F3846EL, - 0x648B1EAFL, 0x19BDF0CAL, 0xA02369B9L, 0x655ABB50L, 0x40685A32L, 0x3C2AB4B3L, 0x319EE9D5L, 0xC021B8F7L, - 0x9B540B19L, 0x875FA099L, 0x95F7997EL, 0x623D7DA8L, 0xF837889AL, 0x97E32D77L, 0x11ED935FL, 0x16681281L, - 0x0E358829L, 0xC7E61FD6L, 0x96DEDFA1L, 0x7858BA99L, 0x57F584A5L, 0x1B227263L, 0x9B83C3FFL, 0x1AC24696L, - 0xCDB30AEBL, 0x532E3054L, 0x8FD948E4L, 0x6DBC3128L, 0x58EBF2EFL, 0x34C6FFEAL, 0xFE28ED61L, 0xEE7C3C73L, - 0x5D4A14D9L, 0xE864B7E3L, 0x42105D14L, 0x203E13E0L, 0x45EEE2B6L, 0xA3AAABEAL, 0xDB6C4F15L, 0xFACB4FD0L, - 0xC742F442L, 0xEF6ABBB5L, 0x654F3B1DL, 0x41CD2105L, 0xD81E799EL, 0x86854DC7L, 0xE44B476AL, 0x3D816250L, - 0xCF62A1F2L, 0x5B8D2646L, 0xFC8883A0L, 0xC1C7B6A3L, 0x7F1524C3L, 0x69CB7492L, 0x47848A0BL, 0x5692B285L, - 0x095BBF00L, 0xAD19489DL, 0x1462B174L, 0x23820E00L, 0x58428D2AL, 0x0C55F5EAL, 0x1DADF43EL, 0x233F7061L, - 0x3372F092L, 0x8D937E41L, 0xD65FECF1L, 0x6C223BDBL, 0x7CDE3759L, 0xCBEE7460L, 0x4085F2A7L, 0xCE77326EL, - 0xA6078084L, 0x19F8509EL, 0xE8EFD855L, 0x61D99735L, 0xA969A7AAL, 0xC50C06C2L, 0x5A04ABFCL, 0x800BCADCL, - 0x9E447A2EL, 0xC3453484L, 0xFDD56705L, 0x0E1E9EC9L, 0xDB73DBD3L, 0x105588CDL, 0x675FDA79L, 0xE3674340L, - 0xC5C43465L, 0x713E38D8L, 0x3D28F89EL, 0xF16DFF20L, 0x153E21E7L, 0x8FB03D4AL, 0xE6E39F2BL, 0xDB83ADF7L}, - {0xE93D5A68L, 0x948140F7L, 0xF64C261CL, 0x94692934L, 0x411520F7L, 0x7602D4F7L, 0xBCF46B2EL, 0xD4A20068L, - 0xD4082471L, 0x3320F46AL, 0x43B7D4B7L, 0x500061AFL, 0x1E39F62EL, 0x97244546L, 0x14214F74L, 0xBF8B8840L, - 0x4D95FC1DL, 0x96B591AFL, 0x70F4DDD3L, 0x66A02F45L, 0xBFBC09ECL, 0x03BD9785L, 0x7FAC6DD0L, 0x31CB8504L, - 0x96EB27B3L, 0x55FD3941L, 0xDA2547E6L, 0xABCA0A9AL, 0x28507825L, 0x530429F4L, 0x0A2C86DAL, 0xE9B66DFBL, - 0x68DC1462L, 0xD7486900L, 0x680EC0A4L, 0x27A18DEEL, 0x4F3FFEA2L, 0xE887AD8CL, 0xB58CE006L, 0x7AF4D6B6L, - 0xAACE1E7CL, 0xD3375FECL, 0xCE78A399L, 0x406B2A42L, 0x20FE9E35L, 0xD9F385B9L, 0xEE39D7ABL, 0x3B124E8BL, - 0x1DC9FAF7L, 0x4B6D1856L, 0x26A36631L, 0xEAE397B2L, 0x3A6EFA74L, 0xDD5B4332L, 0x6841E7F7L, 0xCA7820FBL, - 0xFB0AF54EL, 0xD8FEB397L, 0x454056ACL, 0xBA489527L, 0x55533A3AL, 0x20838D87L, 0xFE6BA9B7L, 0xD096954BL, - 0x55A867BCL, 0xA1159A58L, 0xCCA92963L, 0x99E1DB33L, 0xA62A4A56L, 0x3F3125F9L, 0x5EF47E1CL, 0x9029317CL, - 0xFDF8E802L, 0x04272F70L, 0x80BB155CL, 0x05282CE3L, 0x95C11548L, 0xE4C66D22L, 0x48C1133FL, 0xC70F86DCL, - 0x07F9C9EEL, 0x41041F0FL, 0x404779A4L, 0x5D886E17L, 0x325F51EBL, 0xD59BC0D1L, 0xF2BCC18FL, 0x41113564L, - 0x257B7834L, 0x602A9C60L, 0xDFF8E8A3L, 0x1F636C1BL, 0x0E12B4C2L, 0x02E1329EL, 0xAF664FD1L, 0xCAD18115L, - 0x6B2395E0L, 0x333E92E1L, 0x3B240B62L, 0xEEBEB922L, 0x85B2A20EL, 0xE6BA0D99L, 0xDE720C8CL, 0x2DA2F728L, - 0xD0127845L, 0x95B794FDL, 0x647D0862L, 0xE7CCF5F0L, 0x5449A36FL, 0x877D48FAL, 0xC39DFD27L, 0xF33E8D1EL, - 0x0A476341L, 0x992EFF74L, 0x3A6F6EABL, 0xF4F8FD37L, 0xA812DC60L, 0xA1EBDDF8L, 0x991BE14CL, 0xDB6E6B0DL, - 0xC67B5510L, 0x6D672C37L, 0x2765D43BL, 0xDCD0E804L, 0xF1290DC7L, 0xCC00FFA3L, 0xB5390F92L, 0x690FED0BL, - 0x667B9FFBL, 0xCEDB7D9CL, 0xA091CF0BL, 0xD9155EA3L, 0xBB132F88L, 0x515BAD24L, 0x7B9479BFL, 0x763BD6EBL, - 0x37392EB3L, 0xCC115979L, 0x8026E297L, 0xF42E312DL, 0x6842ADA7L, 0xC66A2B3BL, 0x12754CCCL, 0x782EF11CL, - 0x6A124237L, 0xB79251E7L, 0x06A1BBE6L, 0x4BFB6350L, 0x1A6B1018L, 0x11CAEDFAL, 0x3D25BDD8L, 0xE2E1C3C9L, - 0x44421659L, 0x0A121386L, 0xD90CEC6EL, 0xD5ABEA2AL, 0x64AF674EL, 0xDA86A85FL, 0xBEBFE988L, 0x64E4C3FEL, - 0x9DBC8057L, 0xF0F7C086L, 0x60787BF8L, 0x6003604DL, 0xD1FD8346L, 0xF6381FB0L, 0x7745AE04L, 0xD736FCCCL, - 0x83426B33L, 0xF01EAB71L, 0xB0804187L, 0x3C005E5FL, 0x77A057BEL, 0xBDE8AE24L, 0x55464299L, 0xBF582E61L, - 0x4E58F48FL, 0xF2DDFDA2L, 0xF474EF38L, 0x8789BDC2L, 0x5366F9C3L, 0xC8B38E74L, 0xB475F255L, 0x46FCD9B9L, - 0x7AEB2661L, 0x8B1DDF84L, 0x846A0E79L, 0x915F95E2L, 0x466E598EL, 0x20B45770L, 0x8CD55591L, 0xC902DE4CL, - 0xB90BACE1L, 0xBB8205D0L, 0x11A86248L, 0x7574A99EL, 0xB77F19B6L, 0xE0A9DC09L, 0x662D09A1L, 0xC4324633L, - 0xE85A1F02L, 0x09F0BE8CL, 0x4A99A025L, 0x1D6EFE10L, 0x1AB93D1DL, 0x0BA5A4DFL, 0xA186F20FL, 0x2868F169L, - 0xDCB7DA83L, 0x573906FEL, 0xA1E2CE9BL, 0x4FCD7F52L, 0x50115E01L, 0xA70683FAL, 0xA002B5C4L, 0x0DE6D027L, - 0x9AF88C27L, 0x773F8641L, 0xC3604C06L, 0x61A806B5L, 0xF0177A28L, 0xC0F586E0L, 0x006058AAL, 0x30DC7D62L, - 0x11E69ED7L, 0x2338EA63L, 0x53C2DD94L, 0xC2C21634L, 0xBBCBEE56L, 0x90BCB6DEL, 0xEBFC7DA1L, 0xCE591D76L, - 0x6F05E409L, 0x4B7C0188L, 0x39720A3DL, 0x7C927C24L, 0x86E3725FL, 0x724D9DB9L, 0x1AC15BB4L, 0xD39EB8FCL, - 0xED545578L, 0x08FCA5B5L, 0xD83D7CD3L, 0x4DAD0FC4L, 0x1E50EF5EL, 0xB161E6F8L, 0xA28514D9L, 0x6C51133CL, - 0x6FD5C7E7L, 0x56E14EC4L, 0x362ABFCEL, 0xDDC6C837L, 0xD79A3234L, 0x92638212L, 0x670EFA8EL, 0x406000E0L}, - {0x3A39CE37L, 0xD3FAF5CFL, 0xABC27737L, 0x5AC52D1BL, 0x5CB0679EL, 0x4FA33742L, 0xD3822740L, 0x99BC9BBEL, - 0xD5118E9DL, 0xBF0F7315L, 0xD62D1C7EL, 0xC700C47BL, 0xB78C1B6BL, 0x21A19045L, 0xB26EB1BEL, 0x6A366EB4L, - 0x5748AB2FL, 0xBC946E79L, 0xC6A376D2L, 0x6549C2C8L, 0x530FF8EEL, 0x468DDE7DL, 0xD5730A1DL, 0x4CD04DC6L, - 0x2939BBDBL, 0xA9BA4650L, 0xAC9526E8L, 0xBE5EE304L, 0xA1FAD5F0L, 0x6A2D519AL, 0x63EF8CE2L, 0x9A86EE22L, - 0xC089C2B8L, 0x43242EF6L, 0xA51E03AAL, 0x9CF2D0A4L, 0x83C061BAL, 0x9BE96A4DL, 0x8FE51550L, 0xBA645BD6L, - 0x2826A2F9L, 0xA73A3AE1L, 0x4BA99586L, 0xEF5562E9L, 0xC72FEFD3L, 0xF752F7DAL, 0x3F046F69L, 0x77FA0A59L, - 0x80E4A915L, 0x87B08601L, 0x9B09E6ADL, 0x3B3EE593L, 0xE990FD5AL, 0x9E34D797L, 0x2CF0B7D9L, 0x022B8B51L, - 0x96D5AC3AL, 0x017DA67DL, 0xD1CF3ED6L, 0x7C7D2D28L, 0x1F9F25CFL, 0xADF2B89BL, 0x5AD6B472L, 0x5A88F54CL, - 0xE029AC71L, 0xE019A5E6L, 0x47B0ACFDL, 0xED93FA9BL, 0xE8D3C48DL, 0x283B57CCL, 0xF8D56629L, 0x79132E28L, - 0x785F0191L, 0xED756055L, 0xF7960E44L, 0xE3D35E8CL, 0x15056DD4L, 0x88F46DBAL, 0x03A16125L, 0x0564F0BDL, - 0xC3EB9E15L, 0x3C9057A2L, 0x97271AECL, 0xA93A072AL, 0x1B3F6D9BL, 0x1E6321F5L, 0xF59C66FBL, 0x26DCF319L, - 0x7533D928L, 0xB155FDF5L, 0x03563482L, 0x8ABA3CBBL, 0x28517711L, 0xC20AD9F8L, 0xABCC5167L, 0xCCAD925FL, - 0x4DE81751L, 0x3830DC8EL, 0x379D5862L, 0x9320F991L, 0xEA7A90C2L, 0xFB3E7BCEL, 0x5121CE64L, 0x774FBE32L, - 0xA8B6E37EL, 0xC3293D46L, 0x48DE5369L, 0x6413E680L, 0xA2AE0810L, 0xDD6DB224L, 0x69852DFDL, 0x09072166L, - 0xB39A460AL, 0x6445C0DDL, 0x586CDECFL, 0x1C20C8AEL, 0x5BBEF7DDL, 0x1B588D40L, 0xCCD2017FL, 0x6BB4E3BBL, - 0xDDA26A7EL, 0x3A59FF45L, 0x3E350A44L, 0xBCB4CDD5L, 0x72EACEA8L, 0xFA6484BBL, 0x8D6612AEL, 0xBF3C6F47L, - 0xD29BE463L, 0x542F5D9EL, 0xAEC2771BL, 0xF64E6370L, 0x740E0D8DL, 0xE75B1357L, 0xF8721671L, 0xAF537D5DL, - 0x4040CB08L, 0x4EB4E2CCL, 0x34D2466AL, 0x0115AF84L, 0xE1B00428L, 0x95983A1DL, 0x06B89FB4L, 0xCE6EA048L, - 0x6F3F3B82L, 0x3520AB82L, 0x011A1D4BL, 0x277227F8L, 0x611560B1L, 0xE7933FDCL, 0xBB3A792BL, 0x344525BDL, - 0xA08839E1L, 0x51CE794BL, 0x2F32C9B7L, 0xA01FBAC9L, 0xE01CC87EL, 0xBCC7D1F6L, 0xCF0111C3L, 0xA1E8AAC7L, - 0x1A908749L, 0xD44FBD9AL, 0xD0DADECBL, 0xD50ADA38L, 0x0339C32AL, 0xC6913667L, 0x8DF9317CL, 0xE0B12B4FL, - 0xF79E59B7L, 0x43F5BB3AL, 0xF2D519FFL, 0x27D9459CL, 0xBF97222CL, 0x15E6FC2AL, 0x0F91FC71L, 0x9B941525L, - 0xFAE59361L, 0xCEB69CEBL, 0xC2A86459L, 0x12BAA8D1L, 0xB6C1075EL, 0xE3056A0CL, 0x10D25065L, 0xCB03A442L, - 0xE0EC6E0EL, 0x1698DB3BL, 0x4C98A0BEL, 0x3278E964L, 0x9F1F9532L, 0xE0D392DFL, 0xD3A0342BL, 0x8971F21EL, - 0x1B0A7441L, 0x4BA3348CL, 0xC5BE7120L, 0xC37632D8L, 0xDF359F8DL, 0x9B992F2EL, 0xE60B6F47L, 0x0FE3F11DL, - 0xE54CDA54L, 0x1EDAD891L, 0xCE6279CFL, 0xCD3E7E6FL, 0x1618B166L, 0xFD2C1D05L, 0x848FD2C5L, 0xF6FB2299L, - 0xF523F357L, 0xA6327623L, 0x93A83531L, 0x56CCCD02L, 0xACF08162L, 0x5A75EBB5L, 0x6E163697L, 0x88D273CCL, - 0xDE966292L, 0x81B949D0L, 0x4C50901BL, 0x71C65614L, 0xE6C6C7BDL, 0x327A140AL, 0x45E1D006L, 0xC3F27B9AL, - 0xC9AA53FDL, 0x62A80F00L, 0xBB25BFE2L, 0x35BDD2F6L, 0x71126905L, 0xB2040222L, 0xB6CBCF7CL, 0xCD769C2BL, - 0x53113EC0L, 0x1640E3D3L, 0x38ABBD60L, 0x2547ADF0L, 0xBA38209CL, 0xF746CE76L, 0x77AFA1C5L, 0x20756060L, - 0x85CBFE4EL, 0x8AE88DD8L, 0x7AAAF9B0L, 0x4CF9AA7EL, 0x1948C25CL, 0x02FB8A8CL, 0x01C36AE4L, 0xD6EBE1F9L, - 0x90D4F869L, 0xA65CDEA0L, 0x3F09252DL, 0xC208E69FL, 0xB74E6132L, 0xCE77E25BL, 0x578FDFE3L, 0x3AC372E6L} + {0xD1310BA6L, 0x98DFB5ACL, 0x2FFD72DBL, 0xD01ADFB7L, 0xB8E1AFEDL, 0x6A267E96L, 0xBA7C9045L, 0xF12C7F99L, 0x24A19947L, 0xB3916CF7L, 0x0801F2E2L, + 0x858EFC16L, 0x636920D8L, 0x71574E69L, 0xA458FEA3L, 0xF4933D7EL, 0x0D95748FL, 0x728EB658L, 0x718BCD58L, 0x82154AEEL, 0x7B54A41DL, 0xC25A59B5L, + 0x9C30D539L, 0x2AF26013L, 0xC5D1B023L, 0x286085F0L, 0xCA417918L, 0xB8DB38EFL, 0x8E79DCB0L, 0x603A180EL, 0x6C9E0E8BL, 0xB01E8A3EL, 0xD71577C1L, + 0xBD314B27L, 0x78AF2FDAL, 0x55605C60L, 0xE65525F3L, 0xAA55AB94L, 0x57489862L, 0x63E81440L, 0x55CA396AL, 0x2AAB10B6L, 0xB4CC5C34L, 0x1141E8CEL, + 0xA15486AFL, 0x7C72E993L, 0xB3EE1411L, 0x636FBC2AL, 0x2BA9C55DL, 0x741831F6L, 0xCE5C3E16L, 0x9B87931EL, 0xAFD6BA33L, 0x6C24CF5CL, 0x7A325381L, + 0x28958677L, 0x3B8F4898L, 0x6B4BB9AFL, 0xC4BFE81BL, 0x66282193L, 0x61D809CCL, 0xFB21A991L, 0x487CAC60L, 0x5DEC8032L, 0xEF845D5DL, 0xE98575B1L, + 0xDC262302L, 0xEB651B88L, 0x23893E81L, 0xD396ACC5L, 0x0F6D6FF3L, 0x83F44239L, 0x2E0B4482L, 0xA4842004L, 0x69C8F04AL, 0x9E1F9B5EL, 0x21C66842L, + 0xF6E96C9AL, 0x670C9C61L, 0xABD388F0L, 0x6A51A0D2L, 0xD8542F68L, 0x960FA728L, 0xAB5133A3L, 0x6EEF0B6CL, 0x137A3BE4L, 0xBA3BF050L, 0x7EFB2A98L, + 0xA1F1651DL, 0x39AF0176L, 0x66CA593EL, 0x82430E88L, 0x8CEE8619L, 0x456F9FB4L, 0x7D84A5C3L, 0x3B8B5EBEL, 0xE06F75D8L, 0x85C12073L, 0x401A449FL, + 0x56C16AA6L, 0x4ED3AA62L, 0x363F7706L, 0x1BFEDF72L, 0x429B023DL, 0x37D0D724L, 0xD00A1248L, 0xDB0FEAD3L, 0x49F1C09BL, 0x075372C9L, 0x80991B7BL, + 0x25D479D8L, 0xF6E8DEF7L, 0xE3FE501AL, 0xB6794C3BL, 0x976CE0BDL, 0x04C006BAL, 0xC1A94FB6L, 0x409F60C4L, 0x5E5C9EC2L, 0x196A2463L, 0x68FB6FAFL, + 0x3E6C53B5L, 0x1339B2EBL, 0x3B52EC6FL, 0x6DFC511FL, 0x9B30952CL, 0xCC814544L, 0xAF5EBD09L, 0xBEE3D004L, 0xDE334AFDL, 0x660F2807L, 0x192E4BB3L, + 0xC0CBA857L, 0x45C8740FL, 0xD20B5F39L, 0xB9D3FBDBL, 0x5579C0BDL, 0x1A60320AL, 0xD6A100C6L, 0x402C7279L, 0x679F25FEL, 0xFB1FA3CCL, 0x8EA5E9F8L, + 0xDB3222F8L, 0x3C7516DFL, 0xFD616B15L, 0x2F501EC8L, 0xAD0552ABL, 0x323DB5FAL, 0xFD238760L, 0x53317B48L, 0x3E00DF82L, 0x9E5C57BBL, 0xCA6F8CA0L, + 0x1A87562EL, 0xDF1769DBL, 0xD542A8F6L, 0x287EFFC3L, 0xAC6732C6L, 0x8C4F5573L, 0x695B27B0L, 0xBBCA58C8L, 0xE1FFA35DL, 0xB8F011A0L, 0x10FA3D98L, + 0xFD2183B8L, 0x4AFCB56CL, 0x2DD1D35BL, 0x9A53E479L, 0xB6F84565L, 0xD28E49BCL, 0x4BFB9790L, 0xE1DDF2DAL, 0xA4CB7E33L, 0x62FB1341L, 0xCEE4C6E8L, + 0xEF20CADAL, 0x36774C01L, 0xD07E9EFEL, 0x2BF11FB4L, 0x95DBDA4DL, 0xAE909198L, 0xEAAD8E71L, 0x6B93D5A0L, 0xD08ED1D0L, 0xAFC725E0L, 0x8E3C5B2FL, + 0x8E7594B7L, 0x8FF6E2FBL, 0xF2122B64L, 0x8888B812L, 0x900DF01CL, 0x4FAD5EA0L, 0x688FC31CL, 0xD1CFF191L, 0xB3A8C1ADL, 0x2F2F2218L, 0xBE0E1777L, + 0xEA752DFEL, 0x8B021FA1L, 0xE5A0CC0FL, 0xB56F74E8L, 0x18ACF3D6L, 0xCE89E299L, 0xB4A84FE0L, 0xFD13E0B7L, 0x7CC43B81L, 0xD2ADA8D9L, 0x165FA266L, + 0x80957705L, 0x93CC7314L, 0x211A1477L, 0xE6AD2065L, 0x77B5FA86L, 0xC75442F5L, 0xFB9D35CFL, 0xEBCDAF0CL, 0x7B3E89A0L, 0xD6411BD3L, 0xAE1E7E49L, + 0x00250E2DL, 0x2071B35EL, 0x226800BBL, 0x57B8E0AFL, 0x2464369BL, 0xF009B91EL, 0x5563911DL, 0x59DFA6AAL, 0x78C14389L, 0xD95A537FL, 0x207D5BA2L, + 0x02E5B9C5L, 0x83260376L, 0x6295CFA9L, 0x11C81968L, 0x4E734A41L, 0xB3472DCAL, 0x7B14A94AL, 0x1B510052L, 0x9A532915L, 0xD60F573FL, 0xBC9BC6E4L, + 0x2B60A476L, 0x81E67400L, 0x08BA6FB5L, 0x571BE91FL, 0xF296EC6BL, 0x2A0DD915L, 0xB6636521L, 0xE7B9F9B6L, 0xFF34052EL, 0xC5855664L, 0x53B02D5DL, + 0xA99F8FA1L, 0x08BA4799L, 0x6E85076AL}, + {0x4B7A70E9L, 0xB5B32944L, 0xDB75092EL, 0xC4192623L, 0xAD6EA6B0L, 0x49A7DF7DL, 0x9CEE60B8L, 0x8FEDB266L, 0xECAA8C71L, 0x699A17FFL, 0x5664526CL, + 0xC2B19EE1L, 0x193602A5L, 0x75094C29L, 0xA0591340L, 0xE4183A3EL, 0x3F54989AL, 0x5B429D65L, 0x6B8FE4D6L, 0x99F73FD6L, 0xA1D29C07L, 0xEFE830F5L, + 0x4D2D38E6L, 0xF0255DC1L, 0x4CDD2086L, 0x8470EB26L, 0x6382E9C6L, 0x021ECC5EL, 0x09686B3FL, 0x3EBAEFC9L, 0x3C971814L, 0x6B6A70A1L, 0x687F3584L, + 0x52A0E286L, 0xB79C5305L, 0xAA500737L, 0x3E07841CL, 0x7FDEAE5CL, 0x8E7D44ECL, 0x5716F2B8L, 0xB03ADA37L, 0xF0500C0DL, 0xF01C1F04L, 0x0200B3FFL, + 0xAE0CF51AL, 0x3CB574B2L, 0x25837A58L, 0xDC0921BDL, 0xD19113F9L, 0x7CA92FF6L, 0x94324773L, 0x22F54701L, 0x3AE5E581L, 0x37C2DADCL, 0xC8B57634L, + 0x9AF3DDA7L, 0xA9446146L, 0x0FD0030EL, 0xECC8C73EL, 0xA4751E41L, 0xE238CD99L, 0x3BEA0E2FL, 0x3280BBA1L, 0x183EB331L, 0x4E548B38L, 0x4F6DB908L, + 0x6F420D03L, 0xF60A04BFL, 0x2CB81290L, 0x24977C79L, 0x5679B072L, 0xBCAF89AFL, 0xDE9A771FL, 0xD9930810L, 0xB38BAE12L, 0xDCCF3F2EL, 0x5512721FL, + 0x2E6B7124L, 0x501ADDE6L, 0x9F84CD87L, 0x7A584718L, 0x7408DA17L, 0xBC9F9ABCL, 0xE94B7D8CL, 0xEC7AEC3AL, 0xDB851DFAL, 0x63094366L, 0xC464C3D2L, + 0xEF1C1847L, 0x3215D908L, 0xDD433B37L, 0x24C2BA16L, 0x12A14D43L, 0x2A65C451L, 0x50940002L, 0x133AE4DDL, 0x71DFF89EL, 0x10314E55L, 0x81AC77D6L, + 0x5F11199BL, 0x043556F1L, 0xD7A3C76BL, 0x3C11183BL, 0x5924A509L, 0xF28FE6EDL, 0x97F1FBFAL, 0x9EBABF2CL, 0x1E153C6EL, 0x86E34570L, 0xEAE96FB1L, + 0x860E5E0AL, 0x5A3E2AB3L, 0x771FE71CL, 0x4E3D06FAL, 0x2965DCB9L, 0x99E71D0FL, 0x803E89D6L, 0x5266C825L, 0x2E4CC978L, 0x9C10B36AL, 0xC6150EBAL, + 0x94E2EA78L, 0xA5FC3C53L, 0x1E0A2DF4L, 0xF2F74EA7L, 0x361D2B3DL, 0x1939260FL, 0x19C27960L, 0x5223A708L, 0xF71312B6L, 0xEBADFE6EL, 0xEAC31F66L, + 0xE3BC4595L, 0xA67BC883L, 0xB17F37D1L, 0x018CFF28L, 0xC332DDEFL, 0xBE6C5AA5L, 0x65582185L, 0x68AB9802L, 0xEECEA50FL, 0xDB2F953BL, 0x2AEF7DADL, + 0x5B6E2F84L, 0x1521B628L, 0x29076170L, 0xECDD4775L, 0x619F1510L, 0x13CCA830L, 0xEB61BD96L, 0x0334FE1EL, 0xAA0363CFL, 0xB5735C90L, 0x4C70A239L, + 0xD59E9E0BL, 0xCBAADE14L, 0xEECC86BCL, 0x60622CA7L, 0x9CAB5CABL, 0xB2F3846EL, 0x648B1EAFL, 0x19BDF0CAL, 0xA02369B9L, 0x655ABB50L, 0x40685A32L, + 0x3C2AB4B3L, 0x319EE9D5L, 0xC021B8F7L, 0x9B540B19L, 0x875FA099L, 0x95F7997EL, 0x623D7DA8L, 0xF837889AL, 0x97E32D77L, 0x11ED935FL, 0x16681281L, + 0x0E358829L, 0xC7E61FD6L, 0x96DEDFA1L, 0x7858BA99L, 0x57F584A5L, 0x1B227263L, 0x9B83C3FFL, 0x1AC24696L, 0xCDB30AEBL, 0x532E3054L, 0x8FD948E4L, + 0x6DBC3128L, 0x58EBF2EFL, 0x34C6FFEAL, 0xFE28ED61L, 0xEE7C3C73L, 0x5D4A14D9L, 0xE864B7E3L, 0x42105D14L, 0x203E13E0L, 0x45EEE2B6L, 0xA3AAABEAL, + 0xDB6C4F15L, 0xFACB4FD0L, 0xC742F442L, 0xEF6ABBB5L, 0x654F3B1DL, 0x41CD2105L, 0xD81E799EL, 0x86854DC7L, 0xE44B476AL, 0x3D816250L, 0xCF62A1F2L, + 0x5B8D2646L, 0xFC8883A0L, 0xC1C7B6A3L, 0x7F1524C3L, 0x69CB7492L, 0x47848A0BL, 0x5692B285L, 0x095BBF00L, 0xAD19489DL, 0x1462B174L, 0x23820E00L, + 0x58428D2AL, 0x0C55F5EAL, 0x1DADF43EL, 0x233F7061L, 0x3372F092L, 0x8D937E41L, 0xD65FECF1L, 0x6C223BDBL, 0x7CDE3759L, 0xCBEE7460L, 0x4085F2A7L, + 0xCE77326EL, 0xA6078084L, 0x19F8509EL, 0xE8EFD855L, 0x61D99735L, 0xA969A7AAL, 0xC50C06C2L, 0x5A04ABFCL, 0x800BCADCL, 0x9E447A2EL, 0xC3453484L, + 0xFDD56705L, 0x0E1E9EC9L, 0xDB73DBD3L, 0x105588CDL, 0x675FDA79L, 0xE3674340L, 0xC5C43465L, 0x713E38D8L, 0x3D28F89EL, 0xF16DFF20L, 0x153E21E7L, + 0x8FB03D4AL, 0xE6E39F2BL, 0xDB83ADF7L}, + {0xE93D5A68L, 0x948140F7L, 0xF64C261CL, 0x94692934L, 0x411520F7L, 0x7602D4F7L, 0xBCF46B2EL, 0xD4A20068L, 0xD4082471L, 0x3320F46AL, 0x43B7D4B7L, + 0x500061AFL, 0x1E39F62EL, 0x97244546L, 0x14214F74L, 0xBF8B8840L, 0x4D95FC1DL, 0x96B591AFL, 0x70F4DDD3L, 0x66A02F45L, 0xBFBC09ECL, 0x03BD9785L, + 0x7FAC6DD0L, 0x31CB8504L, 0x96EB27B3L, 0x55FD3941L, 0xDA2547E6L, 0xABCA0A9AL, 0x28507825L, 0x530429F4L, 0x0A2C86DAL, 0xE9B66DFBL, 0x68DC1462L, + 0xD7486900L, 0x680EC0A4L, 0x27A18DEEL, 0x4F3FFEA2L, 0xE887AD8CL, 0xB58CE006L, 0x7AF4D6B6L, 0xAACE1E7CL, 0xD3375FECL, 0xCE78A399L, 0x406B2A42L, + 0x20FE9E35L, 0xD9F385B9L, 0xEE39D7ABL, 0x3B124E8BL, 0x1DC9FAF7L, 0x4B6D1856L, 0x26A36631L, 0xEAE397B2L, 0x3A6EFA74L, 0xDD5B4332L, 0x6841E7F7L, + 0xCA7820FBL, 0xFB0AF54EL, 0xD8FEB397L, 0x454056ACL, 0xBA489527L, 0x55533A3AL, 0x20838D87L, 0xFE6BA9B7L, 0xD096954BL, 0x55A867BCL, 0xA1159A58L, + 0xCCA92963L, 0x99E1DB33L, 0xA62A4A56L, 0x3F3125F9L, 0x5EF47E1CL, 0x9029317CL, 0xFDF8E802L, 0x04272F70L, 0x80BB155CL, 0x05282CE3L, 0x95C11548L, + 0xE4C66D22L, 0x48C1133FL, 0xC70F86DCL, 0x07F9C9EEL, 0x41041F0FL, 0x404779A4L, 0x5D886E17L, 0x325F51EBL, 0xD59BC0D1L, 0xF2BCC18FL, 0x41113564L, + 0x257B7834L, 0x602A9C60L, 0xDFF8E8A3L, 0x1F636C1BL, 0x0E12B4C2L, 0x02E1329EL, 0xAF664FD1L, 0xCAD18115L, 0x6B2395E0L, 0x333E92E1L, 0x3B240B62L, + 0xEEBEB922L, 0x85B2A20EL, 0xE6BA0D99L, 0xDE720C8CL, 0x2DA2F728L, 0xD0127845L, 0x95B794FDL, 0x647D0862L, 0xE7CCF5F0L, 0x5449A36FL, 0x877D48FAL, + 0xC39DFD27L, 0xF33E8D1EL, 0x0A476341L, 0x992EFF74L, 0x3A6F6EABL, 0xF4F8FD37L, 0xA812DC60L, 0xA1EBDDF8L, 0x991BE14CL, 0xDB6E6B0DL, 0xC67B5510L, + 0x6D672C37L, 0x2765D43BL, 0xDCD0E804L, 0xF1290DC7L, 0xCC00FFA3L, 0xB5390F92L, 0x690FED0BL, 0x667B9FFBL, 0xCEDB7D9CL, 0xA091CF0BL, 0xD9155EA3L, + 0xBB132F88L, 0x515BAD24L, 0x7B9479BFL, 0x763BD6EBL, 0x37392EB3L, 0xCC115979L, 0x8026E297L, 0xF42E312DL, 0x6842ADA7L, 0xC66A2B3BL, 0x12754CCCL, + 0x782EF11CL, 0x6A124237L, 0xB79251E7L, 0x06A1BBE6L, 0x4BFB6350L, 0x1A6B1018L, 0x11CAEDFAL, 0x3D25BDD8L, 0xE2E1C3C9L, 0x44421659L, 0x0A121386L, + 0xD90CEC6EL, 0xD5ABEA2AL, 0x64AF674EL, 0xDA86A85FL, 0xBEBFE988L, 0x64E4C3FEL, 0x9DBC8057L, 0xF0F7C086L, 0x60787BF8L, 0x6003604DL, 0xD1FD8346L, + 0xF6381FB0L, 0x7745AE04L, 0xD736FCCCL, 0x83426B33L, 0xF01EAB71L, 0xB0804187L, 0x3C005E5FL, 0x77A057BEL, 0xBDE8AE24L, 0x55464299L, 0xBF582E61L, + 0x4E58F48FL, 0xF2DDFDA2L, 0xF474EF38L, 0x8789BDC2L, 0x5366F9C3L, 0xC8B38E74L, 0xB475F255L, 0x46FCD9B9L, 0x7AEB2661L, 0x8B1DDF84L, 0x846A0E79L, + 0x915F95E2L, 0x466E598EL, 0x20B45770L, 0x8CD55591L, 0xC902DE4CL, 0xB90BACE1L, 0xBB8205D0L, 0x11A86248L, 0x7574A99EL, 0xB77F19B6L, 0xE0A9DC09L, + 0x662D09A1L, 0xC4324633L, 0xE85A1F02L, 0x09F0BE8CL, 0x4A99A025L, 0x1D6EFE10L, 0x1AB93D1DL, 0x0BA5A4DFL, 0xA186F20FL, 0x2868F169L, 0xDCB7DA83L, + 0x573906FEL, 0xA1E2CE9BL, 0x4FCD7F52L, 0x50115E01L, 0xA70683FAL, 0xA002B5C4L, 0x0DE6D027L, 0x9AF88C27L, 0x773F8641L, 0xC3604C06L, 0x61A806B5L, + 0xF0177A28L, 0xC0F586E0L, 0x006058AAL, 0x30DC7D62L, 0x11E69ED7L, 0x2338EA63L, 0x53C2DD94L, 0xC2C21634L, 0xBBCBEE56L, 0x90BCB6DEL, 0xEBFC7DA1L, + 0xCE591D76L, 0x6F05E409L, 0x4B7C0188L, 0x39720A3DL, 0x7C927C24L, 0x86E3725FL, 0x724D9DB9L, 0x1AC15BB4L, 0xD39EB8FCL, 0xED545578L, 0x08FCA5B5L, + 0xD83D7CD3L, 0x4DAD0FC4L, 0x1E50EF5EL, 0xB161E6F8L, 0xA28514D9L, 0x6C51133CL, 0x6FD5C7E7L, 0x56E14EC4L, 0x362ABFCEL, 0xDDC6C837L, 0xD79A3234L, + 0x92638212L, 0x670EFA8EL, 0x406000E0L}, + {0x3A39CE37L, 0xD3FAF5CFL, 0xABC27737L, 0x5AC52D1BL, 0x5CB0679EL, 0x4FA33742L, 0xD3822740L, 0x99BC9BBEL, 0xD5118E9DL, 0xBF0F7315L, 0xD62D1C7EL, + 0xC700C47BL, 0xB78C1B6BL, 0x21A19045L, 0xB26EB1BEL, 0x6A366EB4L, 0x5748AB2FL, 0xBC946E79L, 0xC6A376D2L, 0x6549C2C8L, 0x530FF8EEL, 0x468DDE7DL, + 0xD5730A1DL, 0x4CD04DC6L, 0x2939BBDBL, 0xA9BA4650L, 0xAC9526E8L, 0xBE5EE304L, 0xA1FAD5F0L, 0x6A2D519AL, 0x63EF8CE2L, 0x9A86EE22L, 0xC089C2B8L, + 0x43242EF6L, 0xA51E03AAL, 0x9CF2D0A4L, 0x83C061BAL, 0x9BE96A4DL, 0x8FE51550L, 0xBA645BD6L, 0x2826A2F9L, 0xA73A3AE1L, 0x4BA99586L, 0xEF5562E9L, + 0xC72FEFD3L, 0xF752F7DAL, 0x3F046F69L, 0x77FA0A59L, 0x80E4A915L, 0x87B08601L, 0x9B09E6ADL, 0x3B3EE593L, 0xE990FD5AL, 0x9E34D797L, 0x2CF0B7D9L, + 0x022B8B51L, 0x96D5AC3AL, 0x017DA67DL, 0xD1CF3ED6L, 0x7C7D2D28L, 0x1F9F25CFL, 0xADF2B89BL, 0x5AD6B472L, 0x5A88F54CL, 0xE029AC71L, 0xE019A5E6L, + 0x47B0ACFDL, 0xED93FA9BL, 0xE8D3C48DL, 0x283B57CCL, 0xF8D56629L, 0x79132E28L, 0x785F0191L, 0xED756055L, 0xF7960E44L, 0xE3D35E8CL, 0x15056DD4L, + 0x88F46DBAL, 0x03A16125L, 0x0564F0BDL, 0xC3EB9E15L, 0x3C9057A2L, 0x97271AECL, 0xA93A072AL, 0x1B3F6D9BL, 0x1E6321F5L, 0xF59C66FBL, 0x26DCF319L, + 0x7533D928L, 0xB155FDF5L, 0x03563482L, 0x8ABA3CBBL, 0x28517711L, 0xC20AD9F8L, 0xABCC5167L, 0xCCAD925FL, 0x4DE81751L, 0x3830DC8EL, 0x379D5862L, + 0x9320F991L, 0xEA7A90C2L, 0xFB3E7BCEL, 0x5121CE64L, 0x774FBE32L, 0xA8B6E37EL, 0xC3293D46L, 0x48DE5369L, 0x6413E680L, 0xA2AE0810L, 0xDD6DB224L, + 0x69852DFDL, 0x09072166L, 0xB39A460AL, 0x6445C0DDL, 0x586CDECFL, 0x1C20C8AEL, 0x5BBEF7DDL, 0x1B588D40L, 0xCCD2017FL, 0x6BB4E3BBL, 0xDDA26A7EL, + 0x3A59FF45L, 0x3E350A44L, 0xBCB4CDD5L, 0x72EACEA8L, 0xFA6484BBL, 0x8D6612AEL, 0xBF3C6F47L, 0xD29BE463L, 0x542F5D9EL, 0xAEC2771BL, 0xF64E6370L, + 0x740E0D8DL, 0xE75B1357L, 0xF8721671L, 0xAF537D5DL, 0x4040CB08L, 0x4EB4E2CCL, 0x34D2466AL, 0x0115AF84L, 0xE1B00428L, 0x95983A1DL, 0x06B89FB4L, + 0xCE6EA048L, 0x6F3F3B82L, 0x3520AB82L, 0x011A1D4BL, 0x277227F8L, 0x611560B1L, 0xE7933FDCL, 0xBB3A792BL, 0x344525BDL, 0xA08839E1L, 0x51CE794BL, + 0x2F32C9B7L, 0xA01FBAC9L, 0xE01CC87EL, 0xBCC7D1F6L, 0xCF0111C3L, 0xA1E8AAC7L, 0x1A908749L, 0xD44FBD9AL, 0xD0DADECBL, 0xD50ADA38L, 0x0339C32AL, + 0xC6913667L, 0x8DF9317CL, 0xE0B12B4FL, 0xF79E59B7L, 0x43F5BB3AL, 0xF2D519FFL, 0x27D9459CL, 0xBF97222CL, 0x15E6FC2AL, 0x0F91FC71L, 0x9B941525L, + 0xFAE59361L, 0xCEB69CEBL, 0xC2A86459L, 0x12BAA8D1L, 0xB6C1075EL, 0xE3056A0CL, 0x10D25065L, 0xCB03A442L, 0xE0EC6E0EL, 0x1698DB3BL, 0x4C98A0BEL, + 0x3278E964L, 0x9F1F9532L, 0xE0D392DFL, 0xD3A0342BL, 0x8971F21EL, 0x1B0A7441L, 0x4BA3348CL, 0xC5BE7120L, 0xC37632D8L, 0xDF359F8DL, 0x9B992F2EL, + 0xE60B6F47L, 0x0FE3F11DL, 0xE54CDA54L, 0x1EDAD891L, 0xCE6279CFL, 0xCD3E7E6FL, 0x1618B166L, 0xFD2C1D05L, 0x848FD2C5L, 0xF6FB2299L, 0xF523F357L, + 0xA6327623L, 0x93A83531L, 0x56CCCD02L, 0xACF08162L, 0x5A75EBB5L, 0x6E163697L, 0x88D273CCL, 0xDE966292L, 0x81B949D0L, 0x4C50901BL, 0x71C65614L, + 0xE6C6C7BDL, 0x327A140AL, 0x45E1D006L, 0xC3F27B9AL, 0xC9AA53FDL, 0x62A80F00L, 0xBB25BFE2L, 0x35BDD2F6L, 0x71126905L, 0xB2040222L, 0xB6CBCF7CL, + 0xCD769C2BL, 0x53113EC0L, 0x1640E3D3L, 0x38ABBD60L, 0x2547ADF0L, 0xBA38209CL, 0xF746CE76L, 0x77AFA1C5L, 0x20756060L, 0x85CBFE4EL, 0x8AE88DD8L, + 0x7AAAF9B0L, 0x4CF9AA7EL, 0x1948C25CL, 0x02FB8A8CL, 0x01C36AE4L, 0xD6EBE1F9L, 0x90D4F869L, 0xA65CDEA0L, 0x3F09252DL, 0xC208E69FL, 0xB74E6132L, + 0xCE77E25BL, 0x578FDFE3L, 0x3AC372E6L} }; #endif /* !MBEDTLS_BLOWFISH_ALT */ diff --git a/nettls/ssl/camellia.c b/nettls/ssl/camellia.c index 5d39e9e69e5f146b70ab7aa7f87d52377b2e6a70..ff9d3e61ac961f4414bd626a647b67b3d7a5efa1 100644 --- a/nettls/ssl/camellia.c +++ b/nettls/ssl/camellia.c @@ -75,152 +75,101 @@ #if !defined(MBEDTLS_CAMELLIA_ALT) /* Parameter validation macros */ -#define CAMELLIA_VALIDATE_RET( cond ) \ - MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ) -#define CAMELLIA_VALIDATE( cond ) \ - MBEDTLS_INTERNAL_VALIDATE( cond ) +#define CAMELLIA_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA) +#define CAMELLIA_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) /* * 32-bit integer manipulation macros (big endian) */ #ifndef GET_UINT32_BE -#define GET_UINT32_BE(n,b,i) \ -{ \ - (n) = ( (uint32_t) (b)[(i) ] << 24 ) \ - | ( (uint32_t) (b)[(i) + 1] << 16 ) \ - | ( (uint32_t) (b)[(i) + 2] << 8 ) \ - | ( (uint32_t) (b)[(i) + 3] ); \ -} +#define GET_UINT32_BE(n, b, i) \ + { \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ + } #endif #ifndef PUT_UINT32_BE -#define PUT_UINT32_BE(n,b,i) \ -{ \ - (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) ); \ -} +#define PUT_UINT32_BE(n, b, i) \ + { \ + (b)[(i)] = (unsigned char)((n) >> 24); \ + (b)[(i) + 1] = (unsigned char)((n) >> 16); \ + (b)[(i) + 2] = (unsigned char)((n) >> 8); \ + (b)[(i) + 3] = (unsigned char)((n)); \ + } #endif -static const unsigned char SIGMA_CHARS[6][8] = -{ - { 0xa0, 0x9e, 0x66, 0x7f, 0x3b, 0xcc, 0x90, 0x8b }, - { 0xb6, 0x7a, 0xe8, 0x58, 0x4c, 0xaa, 0x73, 0xb2 }, - { 0xc6, 0xef, 0x37, 0x2f, 0xe9, 0x4f, 0x82, 0xbe }, - { 0x54, 0xff, 0x53, 0xa5, 0xf1, 0xd3, 0x6f, 0x1c }, - { 0x10, 0xe5, 0x27, 0xfa, 0xde, 0x68, 0x2d, 0x1d }, - { 0xb0, 0x56, 0x88, 0xc2, 0xb3, 0xe6, 0xc1, 0xfd } +static const unsigned char SIGMA_CHARS[6][8] = { + {0xa0, 0x9e, 0x66, 0x7f, 0x3b, 0xcc, 0x90, 0x8b}, + {0xb6, 0x7a, 0xe8, 0x58, 0x4c, 0xaa, 0x73, 0xb2}, + {0xc6, 0xef, 0x37, 0x2f, 0xe9, 0x4f, 0x82, 0xbe}, + {0x54, 0xff, 0x53, 0xa5, 0xf1, 0xd3, 0x6f, 0x1c}, + {0x10, 0xe5, 0x27, 0xfa, 0xde, 0x68, 0x2d, 0x1d}, + {0xb0, 0x56, 0x88, 0xc2, 0xb3, 0xe6, 0xc1, 0xfd} }; #if defined(MBEDTLS_CAMELLIA_SMALL_MEMORY) -static const unsigned char FSb[256] = -{ - 112,130, 44,236,179, 39,192,229,228,133, 87, 53,234, 12,174, 65, - 35,239,107,147, 69, 25,165, 33,237, 14, 79, 78, 29,101,146,189, - 134,184,175,143,124,235, 31,206, 62, 48,220, 95, 94,197, 11, 26, - 166,225, 57,202,213, 71, 93, 61,217, 1, 90,214, 81, 86,108, 77, - 139, 13,154,102,251,204,176, 45,116, 18, 43, 32,240,177,132,153, - 223, 76,203,194, 52,126,118, 5,109,183,169, 49,209, 23, 4,215, - 20, 88, 58, 97,222, 27, 17, 28, 50, 15,156, 22, 83, 24,242, 34, - 254, 68,207,178,195,181,122,145, 36, 8,232,168, 96,252,105, 80, - 170,208,160,125,161,137, 98,151, 84, 91, 30,149,224,255,100,210, - 16,196, 0, 72,163,247,117,219,138, 3,230,218, 9, 63,221,148, - 135, 92,131, 2,205, 74,144, 51,115,103,246,243,157,127,191,226, - 82,155,216, 38,200, 55,198, 59,129,150,111, 75, 19,190, 99, 46, - 233,121,167,140,159,110,188,142, 41,245,249,182, 47,253,180, 89, - 120,152, 6,106,231, 70,113,186,212, 37,171, 66,136,162,141,250, - 114, 7,185, 85,248,238,172, 10, 54, 73, 42,104, 60, 56,241,164, - 64, 40,211,123,187,201, 67,193, 21,227,173,244,119,199,128,158 -}; +static const unsigned char FSb[256] = { + 112, 130, 44, 236, 179, 39, 192, 229, 228, 133, 87, 53, 234, 12, 174, 65, 35, 239, 107, 147, 69, 25, 165, 33, 237, 14, 79, 78, 29, + 101, 146, 189, 134, 184, 175, 143, 124, 235, 31, 206, 62, 48, 220, 95, 94, 197, 11, 26, 166, 225, 57, 202, 213, 71, 93, 61, 217, 1, + 90, 214, 81, 86, 108, 77, 139, 13, 154, 102, 251, 204, 176, 45, 116, 18, 43, 32, 240, 177, 132, 153, 223, 76, 203, 194, 52, 126, 118, + 5, 109, 183, 169, 49, 209, 23, 4, 215, 20, 88, 58, 97, 222, 27, 17, 28, 50, 15, 156, 22, 83, 24, 242, 34, 254, 68, 207, 178, + 195, 181, 122, 145, 36, 8, 232, 168, 96, 252, 105, 80, 170, 208, 160, 125, 161, 137, 98, 151, 84, 91, 30, 149, 224, 255, 100, 210, 16, + 196, 0, 72, 163, 247, 117, 219, 138, 3, 230, 218, 9, 63, 221, 148, 135, 92, 131, 2, 205, 74, 144, 51, 115, 103, 246, 243, 157, 127, + 191, 226, 82, 155, 216, 38, 200, 55, 198, 59, 129, 150, 111, 75, 19, 190, 99, 46, 233, 121, 167, 140, 159, 110, 188, 142, 41, 245, 249, + 182, 47, 253, 180, 89, 120, 152, 6, 106, 231, 70, 113, 186, 212, 37, 171, 66, 136, 162, 141, 250, 114, 7, 185, 85, 248, 238, 172, 10, + 54, 73, 42, 104, 60, 56, 241, 164, 64, 40, 211, 123, 187, 201, 67, 193, 21, 227, 173, 244, 119, 199, 128, 158}; #define SBOX1(n) FSb[(n)] #define SBOX2(n) (unsigned char)((FSb[(n)] >> 7 ^ FSb[(n)] << 1) & 0xff) #define SBOX3(n) (unsigned char)((FSb[(n)] >> 1 ^ FSb[(n)] << 7) & 0xff) -#define SBOX4(n) FSb[((n) << 1 ^ (n) >> 7) &0xff] +#define SBOX4(n) FSb[((n) << 1 ^ (n) >> 7) & 0xff] #else /* MBEDTLS_CAMELLIA_SMALL_MEMORY */ -static const unsigned char FSb[256] = -{ - 112, 130, 44, 236, 179, 39, 192, 229, 228, 133, 87, 53, 234, 12, 174, 65, - 35, 239, 107, 147, 69, 25, 165, 33, 237, 14, 79, 78, 29, 101, 146, 189, - 134, 184, 175, 143, 124, 235, 31, 206, 62, 48, 220, 95, 94, 197, 11, 26, - 166, 225, 57, 202, 213, 71, 93, 61, 217, 1, 90, 214, 81, 86, 108, 77, - 139, 13, 154, 102, 251, 204, 176, 45, 116, 18, 43, 32, 240, 177, 132, 153, - 223, 76, 203, 194, 52, 126, 118, 5, 109, 183, 169, 49, 209, 23, 4, 215, - 20, 88, 58, 97, 222, 27, 17, 28, 50, 15, 156, 22, 83, 24, 242, 34, - 254, 68, 207, 178, 195, 181, 122, 145, 36, 8, 232, 168, 96, 252, 105, 80, - 170, 208, 160, 125, 161, 137, 98, 151, 84, 91, 30, 149, 224, 255, 100, 210, - 16, 196, 0, 72, 163, 247, 117, 219, 138, 3, 230, 218, 9, 63, 221, 148, - 135, 92, 131, 2, 205, 74, 144, 51, 115, 103, 246, 243, 157, 127, 191, 226, - 82, 155, 216, 38, 200, 55, 198, 59, 129, 150, 111, 75, 19, 190, 99, 46, - 233, 121, 167, 140, 159, 110, 188, 142, 41, 245, 249, 182, 47, 253, 180, 89, - 120, 152, 6, 106, 231, 70, 113, 186, 212, 37, 171, 66, 136, 162, 141, 250, - 114, 7, 185, 85, 248, 238, 172, 10, 54, 73, 42, 104, 60, 56, 241, 164, - 64, 40, 211, 123, 187, 201, 67, 193, 21, 227, 173, 244, 119, 199, 128, 158 -}; - -static const unsigned char FSb2[256] = -{ - 224, 5, 88, 217, 103, 78, 129, 203, 201, 11, 174, 106, 213, 24, 93, 130, - 70, 223, 214, 39, 138, 50, 75, 66, 219, 28, 158, 156, 58, 202, 37, 123, - 13, 113, 95, 31, 248, 215, 62, 157, 124, 96, 185, 190, 188, 139, 22, 52, - 77, 195, 114, 149, 171, 142, 186, 122, 179, 2, 180, 173, 162, 172, 216, 154, - 23, 26, 53, 204, 247, 153, 97, 90, 232, 36, 86, 64, 225, 99, 9, 51, - 191, 152, 151, 133, 104, 252, 236, 10, 218, 111, 83, 98, 163, 46, 8, 175, - 40, 176, 116, 194, 189, 54, 34, 56, 100, 30, 57, 44, 166, 48, 229, 68, - 253, 136, 159, 101, 135, 107, 244, 35, 72, 16, 209, 81, 192, 249, 210, 160, - 85, 161, 65, 250, 67, 19, 196, 47, 168, 182, 60, 43, 193, 255, 200, 165, - 32, 137, 0, 144, 71, 239, 234, 183, 21, 6, 205, 181, 18, 126, 187, 41, - 15, 184, 7, 4, 155, 148, 33, 102, 230, 206, 237, 231, 59, 254, 127, 197, - 164, 55, 177, 76, 145, 110, 141, 118, 3, 45, 222, 150, 38, 125, 198, 92, - 211, 242, 79, 25, 63, 220, 121, 29, 82, 235, 243, 109, 94, 251, 105, 178, - 240, 49, 12, 212, 207, 140, 226, 117, 169, 74, 87, 132, 17, 69, 27, 245, - 228, 14, 115, 170, 241, 221, 89, 20, 108, 146, 84, 208, 120, 112, 227, 73, - 128, 80, 167, 246, 119, 147, 134, 131, 42, 199, 91, 233, 238, 143, 1, 61 -}; - -static const unsigned char FSb3[256] = -{ - 56, 65, 22, 118, 217, 147, 96, 242, 114, 194, 171, 154, 117, 6, 87, 160, - 145, 247, 181, 201, 162, 140, 210, 144, 246, 7, 167, 39, 142, 178, 73, 222, - 67, 92, 215, 199, 62, 245, 143, 103, 31, 24, 110, 175, 47, 226, 133, 13, - 83, 240, 156, 101, 234, 163, 174, 158, 236, 128, 45, 107, 168, 43, 54, 166, - 197, 134, 77, 51, 253, 102, 88, 150, 58, 9, 149, 16, 120, 216, 66, 204, - 239, 38, 229, 97, 26, 63, 59, 130, 182, 219, 212, 152, 232, 139, 2, 235, - 10, 44, 29, 176, 111, 141, 136, 14, 25, 135, 78, 11, 169, 12, 121, 17, - 127, 34, 231, 89, 225, 218, 61, 200, 18, 4, 116, 84, 48, 126, 180, 40, - 85, 104, 80, 190, 208, 196, 49, 203, 42, 173, 15, 202, 112, 255, 50, 105, - 8, 98, 0, 36, 209, 251, 186, 237, 69, 129, 115, 109, 132, 159, 238, 74, - 195, 46, 193, 1, 230, 37, 72, 153, 185, 179, 123, 249, 206, 191, 223, 113, - 41, 205, 108, 19, 100, 155, 99, 157, 192, 75, 183, 165, 137, 95, 177, 23, - 244, 188, 211, 70, 207, 55, 94, 71, 148, 250, 252, 91, 151, 254, 90, 172, - 60, 76, 3, 53, 243, 35, 184, 93, 106, 146, 213, 33, 68, 81, 198, 125, - 57, 131, 220, 170, 124, 119, 86, 5, 27, 164, 21, 52, 30, 28, 248, 82, - 32, 20, 233, 189, 221, 228, 161, 224, 138, 241, 214, 122, 187, 227, 64, 79 -}; - -static const unsigned char FSb4[256] = -{ - 112, 44, 179, 192, 228, 87, 234, 174, 35, 107, 69, 165, 237, 79, 29, 146, - 134, 175, 124, 31, 62, 220, 94, 11, 166, 57, 213, 93, 217, 90, 81, 108, - 139, 154, 251, 176, 116, 43, 240, 132, 223, 203, 52, 118, 109, 169, 209, 4, - 20, 58, 222, 17, 50, 156, 83, 242, 254, 207, 195, 122, 36, 232, 96, 105, - 170, 160, 161, 98, 84, 30, 224, 100, 16, 0, 163, 117, 138, 230, 9, 221, - 135, 131, 205, 144, 115, 246, 157, 191, 82, 216, 200, 198, 129, 111, 19, 99, - 233, 167, 159, 188, 41, 249, 47, 180, 120, 6, 231, 113, 212, 171, 136, 141, - 114, 185, 248, 172, 54, 42, 60, 241, 64, 211, 187, 67, 21, 173, 119, 128, - 130, 236, 39, 229, 133, 53, 12, 65, 239, 147, 25, 33, 14, 78, 101, 189, - 184, 143, 235, 206, 48, 95, 197, 26, 225, 202, 71, 61, 1, 214, 86, 77, - 13, 102, 204, 45, 18, 32, 177, 153, 76, 194, 126, 5, 183, 49, 23, 215, - 88, 97, 27, 28, 15, 22, 24, 34, 68, 178, 181, 145, 8, 168, 252, 80, - 208, 125, 137, 151, 91, 149, 255, 210, 196, 72, 247, 219, 3, 218, 63, 148, - 92, 2, 74, 51, 103, 243, 127, 226, 155, 38, 55, 59, 150, 75, 190, 46, - 121, 140, 110, 142, 245, 182, 253, 89, 152, 106, 70, 186, 37, 66, 162, 250, - 7, 85, 238, 10, 73, 104, 56, 164, 40, 123, 201, 193, 227, 244, 199, 158 -}; +static const unsigned char FSb[256] = { + 112, 130, 44, 236, 179, 39, 192, 229, 228, 133, 87, 53, 234, 12, 174, 65, 35, 239, 107, 147, 69, 25, 165, 33, 237, 14, 79, 78, 29, + 101, 146, 189, 134, 184, 175, 143, 124, 235, 31, 206, 62, 48, 220, 95, 94, 197, 11, 26, 166, 225, 57, 202, 213, 71, 93, 61, 217, 1, + 90, 214, 81, 86, 108, 77, 139, 13, 154, 102, 251, 204, 176, 45, 116, 18, 43, 32, 240, 177, 132, 153, 223, 76, 203, 194, 52, 126, 118, + 5, 109, 183, 169, 49, 209, 23, 4, 215, 20, 88, 58, 97, 222, 27, 17, 28, 50, 15, 156, 22, 83, 24, 242, 34, 254, 68, 207, 178, + 195, 181, 122, 145, 36, 8, 232, 168, 96, 252, 105, 80, 170, 208, 160, 125, 161, 137, 98, 151, 84, 91, 30, 149, 224, 255, 100, 210, 16, + 196, 0, 72, 163, 247, 117, 219, 138, 3, 230, 218, 9, 63, 221, 148, 135, 92, 131, 2, 205, 74, 144, 51, 115, 103, 246, 243, 157, 127, + 191, 226, 82, 155, 216, 38, 200, 55, 198, 59, 129, 150, 111, 75, 19, 190, 99, 46, 233, 121, 167, 140, 159, 110, 188, 142, 41, 245, 249, + 182, 47, 253, 180, 89, 120, 152, 6, 106, 231, 70, 113, 186, 212, 37, 171, 66, 136, 162, 141, 250, 114, 7, 185, 85, 248, 238, 172, 10, + 54, 73, 42, 104, 60, 56, 241, 164, 64, 40, 211, 123, 187, 201, 67, 193, 21, 227, 173, 244, 119, 199, 128, 158}; + +static const unsigned char FSb2[256] = { + 224, 5, 88, 217, 103, 78, 129, 203, 201, 11, 174, 106, 213, 24, 93, 130, 70, 223, 214, 39, 138, 50, 75, 66, 219, 28, 158, 156, 58, + 202, 37, 123, 13, 113, 95, 31, 248, 215, 62, 157, 124, 96, 185, 190, 188, 139, 22, 52, 77, 195, 114, 149, 171, 142, 186, 122, 179, 2, + 180, 173, 162, 172, 216, 154, 23, 26, 53, 204, 247, 153, 97, 90, 232, 36, 86, 64, 225, 99, 9, 51, 191, 152, 151, 133, 104, 252, 236, + 10, 218, 111, 83, 98, 163, 46, 8, 175, 40, 176, 116, 194, 189, 54, 34, 56, 100, 30, 57, 44, 166, 48, 229, 68, 253, 136, 159, 101, + 135, 107, 244, 35, 72, 16, 209, 81, 192, 249, 210, 160, 85, 161, 65, 250, 67, 19, 196, 47, 168, 182, 60, 43, 193, 255, 200, 165, 32, + 137, 0, 144, 71, 239, 234, 183, 21, 6, 205, 181, 18, 126, 187, 41, 15, 184, 7, 4, 155, 148, 33, 102, 230, 206, 237, 231, 59, 254, + 127, 197, 164, 55, 177, 76, 145, 110, 141, 118, 3, 45, 222, 150, 38, 125, 198, 92, 211, 242, 79, 25, 63, 220, 121, 29, 82, 235, 243, + 109, 94, 251, 105, 178, 240, 49, 12, 212, 207, 140, 226, 117, 169, 74, 87, 132, 17, 69, 27, 245, 228, 14, 115, 170, 241, 221, 89, 20, + 108, 146, 84, 208, 120, 112, 227, 73, 128, 80, 167, 246, 119, 147, 134, 131, 42, 199, 91, 233, 238, 143, 1, 61}; + +static const unsigned char FSb3[256] = { + 56, 65, 22, 118, 217, 147, 96, 242, 114, 194, 171, 154, 117, 6, 87, 160, 145, 247, 181, 201, 162, 140, 210, 144, 246, 7, 167, 39, 142, + 178, 73, 222, 67, 92, 215, 199, 62, 245, 143, 103, 31, 24, 110, 175, 47, 226, 133, 13, 83, 240, 156, 101, 234, 163, 174, 158, 236, 128, + 45, 107, 168, 43, 54, 166, 197, 134, 77, 51, 253, 102, 88, 150, 58, 9, 149, 16, 120, 216, 66, 204, 239, 38, 229, 97, 26, 63, 59, + 130, 182, 219, 212, 152, 232, 139, 2, 235, 10, 44, 29, 176, 111, 141, 136, 14, 25, 135, 78, 11, 169, 12, 121, 17, 127, 34, 231, 89, + 225, 218, 61, 200, 18, 4, 116, 84, 48, 126, 180, 40, 85, 104, 80, 190, 208, 196, 49, 203, 42, 173, 15, 202, 112, 255, 50, 105, 8, + 98, 0, 36, 209, 251, 186, 237, 69, 129, 115, 109, 132, 159, 238, 74, 195, 46, 193, 1, 230, 37, 72, 153, 185, 179, 123, 249, 206, 191, + 223, 113, 41, 205, 108, 19, 100, 155, 99, 157, 192, 75, 183, 165, 137, 95, 177, 23, 244, 188, 211, 70, 207, 55, 94, 71, 148, 250, 252, + 91, 151, 254, 90, 172, 60, 76, 3, 53, 243, 35, 184, 93, 106, 146, 213, 33, 68, 81, 198, 125, 57, 131, 220, 170, 124, 119, 86, 5, + 27, 164, 21, 52, 30, 28, 248, 82, 32, 20, 233, 189, 221, 228, 161, 224, 138, 241, 214, 122, 187, 227, 64, 79}; + +static const unsigned char FSb4[256] = { + 112, 44, 179, 192, 228, 87, 234, 174, 35, 107, 69, 165, 237, 79, 29, 146, 134, 175, 124, 31, 62, 220, 94, 11, 166, 57, 213, 93, 217, + 90, 81, 108, 139, 154, 251, 176, 116, 43, 240, 132, 223, 203, 52, 118, 109, 169, 209, 4, 20, 58, 222, 17, 50, 156, 83, 242, 254, 207, + 195, 122, 36, 232, 96, 105, 170, 160, 161, 98, 84, 30, 224, 100, 16, 0, 163, 117, 138, 230, 9, 221, 135, 131, 205, 144, 115, 246, 157, + 191, 82, 216, 200, 198, 129, 111, 19, 99, 233, 167, 159, 188, 41, 249, 47, 180, 120, 6, 231, 113, 212, 171, 136, 141, 114, 185, 248, 172, + 54, 42, 60, 241, 64, 211, 187, 67, 21, 173, 119, 128, 130, 236, 39, 229, 133, 53, 12, 65, 239, 147, 25, 33, 14, 78, 101, 189, 184, + 143, 235, 206, 48, 95, 197, 26, 225, 202, 71, 61, 1, 214, 86, 77, 13, 102, 204, 45, 18, 32, 177, 153, 76, 194, 126, 5, 183, 49, + 23, 215, 88, 97, 27, 28, 15, 22, 24, 34, 68, 178, 181, 145, 8, 168, 252, 80, 208, 125, 137, 151, 91, 149, 255, 210, 196, 72, 247, + 219, 3, 218, 63, 148, 92, 2, 74, 51, 103, 243, 127, 226, 155, 38, 55, 59, 150, 75, 190, 46, 121, 140, 110, 142, 245, 182, 253, 89, + 152, 106, 70, 186, 37, 66, 162, 250, 7, 85, 238, 10, 73, 104, 56, 164, 40, 123, 201, 193, 227, 244, 199, 158}; #define SBOX1(n) FSb[(n)] #define SBOX2(n) FSb2[(n)] @@ -229,117 +178,89 @@ static const unsigned char FSb4[256] = #endif /* MBEDTLS_CAMELLIA_SMALL_MEMORY */ -static const unsigned char shifts[2][4][4] = -{ +static const unsigned char shifts[2][4][4] = { { - { 1, 1, 1, 1 }, /* KL */ - { 0, 0, 0, 0 }, /* KR */ - { 1, 1, 1, 1 }, /* KA */ - { 0, 0, 0, 0 } /* KB */ + {1, 1, 1, 1}, /* KL */ + {0, 0, 0, 0}, /* KR */ + {1, 1, 1, 1}, /* KA */ + {0, 0, 0, 0} /* KB */ }, { - { 1, 0, 1, 1 }, /* KL */ - { 1, 1, 0, 1 }, /* KR */ - { 1, 1, 1, 0 }, /* KA */ - { 1, 1, 0, 1 } /* KB */ + {1, 0, 1, 1}, /* KL */ + {1, 1, 0, 1}, /* KR */ + {1, 1, 1, 0}, /* KA */ + {1, 1, 0, 1} /* KB */ } }; -static const signed char indexes[2][4][20] = -{ +static const signed char indexes[2][4][20] = { { - { 0, 1, 2, 3, 8, 9, 10, 11, 38, 39, - 36, 37, 23, 20, 21, 22, 27, -1, -1, 26 }, /* KL -> RK */ - { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* KR -> RK */ - { 4, 5, 6, 7, 12, 13, 14, 15, 16, 17, - 18, 19, -1, 24, 25, -1, 31, 28, 29, 30 }, /* KA -> RK */ - { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } /* KB -> RK */ + {0, 1, 2, 3, 8, 9, 10, 11, 38, 39, 36, 37, 23, 20, 21, 22, 27, -1, -1, 26}, /* KL -> RK */ + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /* KR -> RK */ + {4, 5, 6, 7, 12, 13, 14, 15, 16, 17, 18, 19, -1, 24, 25, -1, 31, 28, 29, 30}, /* KA -> RK */ + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1} /* KB -> RK */ }, { - { 0, 1, 2, 3, 61, 62, 63, 60, -1, -1, - -1, -1, 27, 24, 25, 26, 35, 32, 33, 34 }, /* KL -> RK */ - { -1, -1, -1, -1, 8, 9, 10, 11, 16, 17, - 18, 19, -1, -1, -1, -1, 39, 36, 37, 38 }, /* KR -> RK */ - { -1, -1, -1, -1, 12, 13, 14, 15, 58, 59, - 56, 57, 31, 28, 29, 30, -1, -1, -1, -1 }, /* KA -> RK */ - { 4, 5, 6, 7, 65, 66, 67, 64, 20, 21, - 22, 23, -1, -1, -1, -1, 43, 40, 41, 42 } /* KB -> RK */ + {0, 1, 2, 3, 61, 62, 63, 60, -1, -1, -1, -1, 27, 24, 25, 26, 35, 32, 33, 34}, /* KL -> RK */ + {-1, -1, -1, -1, 8, 9, 10, 11, 16, 17, 18, 19, -1, -1, -1, -1, 39, 36, 37, 38}, /* KR -> RK */ + {-1, -1, -1, -1, 12, 13, 14, 15, 58, 59, 56, 57, 31, 28, 29, 30, -1, -1, -1, -1}, /* KA -> RK */ + {4, 5, 6, 7, 65, 66, 67, 64, 20, 21, 22, 23, -1, -1, -1, -1, 43, 40, 41, 42} /* KB -> RK */ } }; -static const signed char transposes[2][20] = -{ - { - 21, 22, 23, 20, - -1, -1, -1, -1, - 18, 19, 16, 17, - 11, 8, 9, 10, - 15, 12, 13, 14 - }, - { - 25, 26, 27, 24, - 29, 30, 31, 28, - 18, 19, 16, 17, - -1, -1, -1, -1, - -1, -1, -1, -1 - } +static const signed char transposes[2][20] = { + {21, 22, 23, 20, -1, -1, -1, -1, 18, 19, 16, 17, 11, 8, 9, 10, 15, 12, 13, 14}, + {25, 26, 27, 24, 29, 30, 31, 28, 18, 19, 16, 17, -1, -1, -1, -1, -1, -1, -1, -1} }; /* Shift macro for 128 bit strings with rotation smaller than 32 bits (!) */ -#define ROTL(DEST, SRC, SHIFT) \ -{ \ - (DEST)[0] = (SRC)[0] << (SHIFT) ^ (SRC)[1] >> (32 - (SHIFT)); \ - (DEST)[1] = (SRC)[1] << (SHIFT) ^ (SRC)[2] >> (32 - (SHIFT)); \ - (DEST)[2] = (SRC)[2] << (SHIFT) ^ (SRC)[3] >> (32 - (SHIFT)); \ - (DEST)[3] = (SRC)[3] << (SHIFT) ^ (SRC)[0] >> (32 - (SHIFT)); \ -} +#define ROTL(DEST, SRC, SHIFT) \ + { \ + (DEST)[0] = (SRC)[0] << (SHIFT) ^ (SRC)[1] >> (32 - (SHIFT)); \ + (DEST)[1] = (SRC)[1] << (SHIFT) ^ (SRC)[2] >> (32 - (SHIFT)); \ + (DEST)[2] = (SRC)[2] << (SHIFT) ^ (SRC)[3] >> (32 - (SHIFT)); \ + (DEST)[3] = (SRC)[3] << (SHIFT) ^ (SRC)[0] >> (32 - (SHIFT)); \ + } -#define FL(XL, XR, KL, KR) \ -{ \ - (XR) = ((((XL) & (KL)) << 1) | (((XL) & (KL)) >> 31)) ^ (XR); \ - (XL) = ((XR) | (KR)) ^ (XL); \ -} +#define FL(XL, XR, KL, KR) \ + { \ + (XR) = ((((XL) & (KL)) << 1) | (((XL) & (KL)) >> 31)) ^ (XR); \ + (XL) = ((XR) | (KR)) ^ (XL); \ + } -#define FLInv(YL, YR, KL, KR) \ -{ \ - (YL) = ((YR) | (KR)) ^ (YL); \ - (YR) = ((((YL) & (KL)) << 1) | (((YL) & (KL)) >> 31)) ^ (YR); \ -} +#define FLInv(YL, YR, KL, KR) \ + { \ + (YL) = ((YR) | (KR)) ^ (YL); \ + (YR) = ((((YL) & (KL)) << 1) | (((YL) & (KL)) >> 31)) ^ (YR); \ + } -#define SHIFT_AND_PLACE(INDEX, OFFSET) \ -{ \ - TK[0] = KC[(OFFSET) * 4 + 0]; \ - TK[1] = KC[(OFFSET) * 4 + 1]; \ - TK[2] = KC[(OFFSET) * 4 + 2]; \ - TK[3] = KC[(OFFSET) * 4 + 3]; \ - \ - for( i = 1; i <= 4; i++ ) \ - if( shifts[(INDEX)][(OFFSET)][i -1] ) \ - ROTL(TK + i * 4, TK, ( 15 * i ) % 32); \ - \ - for( i = 0; i < 20; i++ ) \ - if( indexes[(INDEX)][(OFFSET)][i] != -1 ) { \ - RK[indexes[(INDEX)][(OFFSET)][i]] = TK[ i ]; \ - } \ -} +#define SHIFT_AND_PLACE(INDEX, OFFSET) \ + { \ + TK[0] = KC[(OFFSET)*4 + 0]; \ + TK[1] = KC[(OFFSET)*4 + 1]; \ + TK[2] = KC[(OFFSET)*4 + 2]; \ + TK[3] = KC[(OFFSET)*4 + 3]; \ +\ + for (i = 1; i <= 4; i++) \ + if (shifts[(INDEX)][(OFFSET)][i - 1]) \ + ROTL(TK + i * 4, TK, (15 * i) % 32); \ +\ + for (i = 0; i < 20; i++) \ + if (indexes[(INDEX)][(OFFSET)][i] != -1) { \ + RK[indexes[(INDEX)][(OFFSET)][i]] = TK[i]; \ + } \ + } -static void camellia_feistel( const uint32_t x[2], const uint32_t k[2], - uint32_t z[2]) +static void camellia_feistel(const uint32_t x[2], const uint32_t k[2], uint32_t z[2]) { uint32_t I0, I1; I0 = x[0] ^ k[0]; I1 = x[1] ^ k[1]; - I0 = ((uint32_t) SBOX1((I0 >> 24) & 0xFF) << 24) | - ((uint32_t) SBOX2((I0 >> 16) & 0xFF) << 16) | - ((uint32_t) SBOX3((I0 >> 8) & 0xFF) << 8) | - ((uint32_t) SBOX4((I0 ) & 0xFF) ); - I1 = ((uint32_t) SBOX2((I1 >> 24) & 0xFF) << 24) | - ((uint32_t) SBOX3((I1 >> 16) & 0xFF) << 16) | - ((uint32_t) SBOX4((I1 >> 8) & 0xFF) << 8) | - ((uint32_t) SBOX1((I1 ) & 0xFF) ); + I0 = ((uint32_t)SBOX1((I0 >> 24) & 0xFF) << 24) | ((uint32_t)SBOX2((I0 >> 16) & 0xFF) << 16) | ((uint32_t)SBOX3((I0 >> 8) & 0xFF) << 8) + | ((uint32_t)SBOX4((I0)&0xFF)); + I1 = ((uint32_t)SBOX2((I1 >> 24) & 0xFF) << 24) | ((uint32_t)SBOX3((I1 >> 16) & 0xFF) << 16) | ((uint32_t)SBOX4((I1 >> 8) & 0xFF) << 8) + | ((uint32_t)SBOX1((I1)&0xFF)); I0 ^= (I1 << 8) | (I1 >> 24); I1 ^= (I0 << 16) | (I0 >> 16); @@ -350,97 +271,101 @@ static void camellia_feistel( const uint32_t x[2], const uint32_t k[2], z[1] ^= I0; } -void mbedtls_camellia_init( mbedtls_camellia_context *ctx ) +void mbedtls_camellia_init(mbedtls_camellia_context* ctx) { - CAMELLIA_VALIDATE( ctx != NULL ); - memset( ctx, 0, sizeof( mbedtls_camellia_context ) ); + CAMELLIA_VALIDATE(ctx != NULL); + memset(ctx, 0, sizeof(mbedtls_camellia_context)); } -void mbedtls_camellia_free( mbedtls_camellia_context *ctx ) +void mbedtls_camellia_free(mbedtls_camellia_context* ctx) { - if( ctx == NULL ) + if (ctx == NULL) return; - mbedtls_platform_zeroize( ctx, sizeof( mbedtls_camellia_context ) ); + mbedtls_platform_zeroize(ctx, sizeof(mbedtls_camellia_context)); } /* * Camellia key schedule (encryption) */ -int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, - const unsigned char *key, - unsigned int keybits ) +int mbedtls_camellia_setkey_enc(mbedtls_camellia_context* ctx, const unsigned char* key, unsigned int keybits) { int idx; size_t i; - uint32_t *RK; + uint32_t* RK; unsigned char t[64]; uint32_t SIGMA[6][2]; uint32_t KC[16]; uint32_t TK[20]; - CAMELLIA_VALIDATE_RET( ctx != NULL ); - CAMELLIA_VALIDATE_RET( key != NULL ); + CAMELLIA_VALIDATE_RET(ctx != NULL); + CAMELLIA_VALIDATE_RET(key != NULL); RK = ctx->rk; - memset( t, 0, 64 ); - memset( RK, 0, sizeof(ctx->rk) ); - - switch( keybits ) - { - case 128: ctx->nr = 3; idx = 0; break; - case 192: - case 256: ctx->nr = 4; idx = 1; break; - default : return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + memset(t, 0, 64); + memset(RK, 0, sizeof(ctx->rk)); + + switch (keybits) { + case 128: + ctx->nr = 3; + idx = 0; + break; + case 192: + case 256: + ctx->nr = 4; + idx = 1; + break; + default: + return (MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA); } - for( i = 0; i < keybits / 8; ++i ) + for (i = 0; i < keybits / 8; ++i) t[i] = key[i]; - if( keybits == 192 ) { - for( i = 0; i < 8; i++ ) + if (keybits == 192) { + for (i = 0; i < 8; i++) t[24 + i] = ~t[16 + i]; } /* * Prepare SIGMA values */ - for( i = 0; i < 6; i++ ) { - GET_UINT32_BE( SIGMA[i][0], SIGMA_CHARS[i], 0 ); - GET_UINT32_BE( SIGMA[i][1], SIGMA_CHARS[i], 4 ); + for (i = 0; i < 6; i++) { + GET_UINT32_BE(SIGMA[i][0], SIGMA_CHARS[i], 0); + GET_UINT32_BE(SIGMA[i][1], SIGMA_CHARS[i], 4); } /* * Key storage in KC * Order: KL, KR, KA, KB */ - memset( KC, 0, sizeof(KC) ); + memset(KC, 0, sizeof(KC)); /* Store KL, KR */ - for( i = 0; i < 8; i++ ) - GET_UINT32_BE( KC[i], t, i * 4 ); + for (i = 0; i < 8; i++) + GET_UINT32_BE(KC[i], t, i * 4); /* Generate KA */ - for( i = 0; i < 4; ++i ) + for (i = 0; i < 4; ++i) KC[8 + i] = KC[i] ^ KC[4 + i]; - camellia_feistel( KC + 8, SIGMA[0], KC + 10 ); - camellia_feistel( KC + 10, SIGMA[1], KC + 8 ); + camellia_feistel(KC + 8, SIGMA[0], KC + 10); + camellia_feistel(KC + 10, SIGMA[1], KC + 8); - for( i = 0; i < 4; ++i ) + for (i = 0; i < 4; ++i) KC[8 + i] ^= KC[i]; - camellia_feistel( KC + 8, SIGMA[2], KC + 10 ); - camellia_feistel( KC + 10, SIGMA[3], KC + 8 ); + camellia_feistel(KC + 8, SIGMA[2], KC + 10); + camellia_feistel(KC + 10, SIGMA[3], KC + 8); - if( keybits > 128 ) { + if (keybits > 128) { /* Generate KB */ - for( i = 0; i < 4; ++i ) + for (i = 0; i < 4; ++i) KC[12 + i] = KC[4 + i] ^ KC[8 + i]; - camellia_feistel( KC + 12, SIGMA[4], KC + 14 ); - camellia_feistel( KC + 14, SIGMA[5], KC + 12 ); + camellia_feistel(KC + 12, SIGMA[4], KC + 14); + camellia_feistel(KC + 14, SIGMA[5], KC + 12); } /* @@ -448,54 +373,52 @@ int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, */ /* Manipulating KL */ - SHIFT_AND_PLACE( idx, 0 ); + SHIFT_AND_PLACE(idx, 0); /* Manipulating KR */ - if( keybits > 128 ) { - SHIFT_AND_PLACE( idx, 1 ); + if (keybits > 128) { + SHIFT_AND_PLACE(idx, 1); } /* Manipulating KA */ - SHIFT_AND_PLACE( idx, 2 ); + SHIFT_AND_PLACE(idx, 2); /* Manipulating KB */ - if( keybits > 128 ) { - SHIFT_AND_PLACE( idx, 3 ); + if (keybits > 128) { + SHIFT_AND_PLACE(idx, 3); } /* Do transpositions */ - for( i = 0; i < 20; i++ ) { - if( transposes[idx][i] != -1 ) { + for (i = 0; i < 20; i++) { + if (transposes[idx][i] != -1) { RK[32 + 12 * idx + i] = RK[transposes[idx][i]]; } } - return( 0 ); + return (0); } /* * Camellia key schedule (decryption) */ -int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, - const unsigned char *key, - unsigned int keybits ) +int mbedtls_camellia_setkey_dec(mbedtls_camellia_context* ctx, const unsigned char* key, unsigned int keybits) { int idx, ret; size_t i; mbedtls_camellia_context cty; - uint32_t *RK; - uint32_t *SK; - CAMELLIA_VALIDATE_RET( ctx != NULL ); - CAMELLIA_VALIDATE_RET( key != NULL ); + uint32_t* RK; + uint32_t* SK; + CAMELLIA_VALIDATE_RET(ctx != NULL); + CAMELLIA_VALIDATE_RET(key != NULL); - mbedtls_camellia_init( &cty ); + mbedtls_camellia_init(&cty); /* Also checks keybits */ - if( ( ret = mbedtls_camellia_setkey_enc( &cty, key, keybits ) ) != 0 ) + if ((ret = mbedtls_camellia_setkey_enc(&cty, key, keybits)) != 0) goto exit; ctx->nr = cty.nr; - idx = ( ctx->nr == 4 ); + idx = (ctx->nr == 4); RK = ctx->rk; SK = cty.rk + 24 * 2 + 8 * idx * 2; @@ -505,8 +428,7 @@ int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, *RK++ = *SK++; *RK++ = *SK++; - for( i = 22 + 8 * idx, SK -= 6; i > 0; i--, SK -= 4 ) - { + for (i = 22 + 8 * idx, SK -= 6; i > 0; i--, SK -= 4) { *RK++ = *SK++; *RK++ = *SK++; } @@ -519,58 +441,54 @@ int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, *RK++ = *SK++; exit: - mbedtls_camellia_free( &cty ); + mbedtls_camellia_free(&cty); - return( ret ); + return (ret); } /* * Camellia-ECB block encryption/decryption */ -int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16] ) +int mbedtls_camellia_crypt_ecb(mbedtls_camellia_context* ctx, int mode, const unsigned char input[16], unsigned char output[16]) { int NR; uint32_t *RK, X[4]; - CAMELLIA_VALIDATE_RET( ctx != NULL ); - CAMELLIA_VALIDATE_RET( mode == MBEDTLS_CAMELLIA_ENCRYPT || - mode == MBEDTLS_CAMELLIA_DECRYPT ); - CAMELLIA_VALIDATE_RET( input != NULL ); - CAMELLIA_VALIDATE_RET( output != NULL ); + CAMELLIA_VALIDATE_RET(ctx != NULL); + CAMELLIA_VALIDATE_RET(mode == MBEDTLS_CAMELLIA_ENCRYPT || mode == MBEDTLS_CAMELLIA_DECRYPT); + CAMELLIA_VALIDATE_RET(input != NULL); + CAMELLIA_VALIDATE_RET(output != NULL); - ( (void) mode ); + ((void)mode); NR = ctx->nr; RK = ctx->rk; - GET_UINT32_BE( X[0], input, 0 ); - GET_UINT32_BE( X[1], input, 4 ); - GET_UINT32_BE( X[2], input, 8 ); - GET_UINT32_BE( X[3], input, 12 ); + GET_UINT32_BE(X[0], input, 0); + GET_UINT32_BE(X[1], input, 4); + GET_UINT32_BE(X[2], input, 8); + GET_UINT32_BE(X[3], input, 12); X[0] ^= *RK++; X[1] ^= *RK++; X[2] ^= *RK++; X[3] ^= *RK++; - while( NR ) { + while (NR) { --NR; - camellia_feistel( X, RK, X + 2 ); + camellia_feistel(X, RK, X + 2); RK += 2; - camellia_feistel( X + 2, RK, X ); + camellia_feistel(X + 2, RK, X); RK += 2; - camellia_feistel( X, RK, X + 2 ); + camellia_feistel(X, RK, X + 2); RK += 2; - camellia_feistel( X + 2, RK, X ); + camellia_feistel(X + 2, RK, X); RK += 2; - camellia_feistel( X, RK, X + 2 ); + camellia_feistel(X, RK, X + 2); RK += 2; - camellia_feistel( X + 2, RK, X ); + camellia_feistel(X + 2, RK, X); RK += 2; - if( NR ) { + if (NR) { FL(X[0], X[1], RK[0], RK[1]); RK += 2; FLInv(X[2], X[3], RK[0], RK[1]); @@ -583,71 +501,61 @@ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, X[0] ^= *RK++; X[1] ^= *RK++; - PUT_UINT32_BE( X[2], output, 0 ); - PUT_UINT32_BE( X[3], output, 4 ); - PUT_UINT32_BE( X[0], output, 8 ); - PUT_UINT32_BE( X[1], output, 12 ); + PUT_UINT32_BE(X[2], output, 0); + PUT_UINT32_BE(X[3], output, 4); + PUT_UINT32_BE(X[0], output, 8); + PUT_UINT32_BE(X[1], output, 12); - return( 0 ); + return (0); } #if defined(MBEDTLS_CIPHER_MODE_CBC) /* * Camellia-CBC buffer encryption/decryption */ -int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_camellia_crypt_cbc( + mbedtls_camellia_context* ctx, int mode, size_t length, unsigned char iv[16], const unsigned char* input, unsigned char* output) { int i; unsigned char temp[16]; - CAMELLIA_VALIDATE_RET( ctx != NULL ); - CAMELLIA_VALIDATE_RET( mode == MBEDTLS_CAMELLIA_ENCRYPT || - mode == MBEDTLS_CAMELLIA_DECRYPT ); - CAMELLIA_VALIDATE_RET( iv != NULL ); - CAMELLIA_VALIDATE_RET( length == 0 || input != NULL ); - CAMELLIA_VALIDATE_RET( length == 0 || output != NULL ); + CAMELLIA_VALIDATE_RET(ctx != NULL); + CAMELLIA_VALIDATE_RET(mode == MBEDTLS_CAMELLIA_ENCRYPT || mode == MBEDTLS_CAMELLIA_DECRYPT); + CAMELLIA_VALIDATE_RET(iv != NULL); + CAMELLIA_VALIDATE_RET(length == 0 || input != NULL); + CAMELLIA_VALIDATE_RET(length == 0 || output != NULL); - if( length % 16 ) - return( MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH ); + if (length % 16) + return (MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH); - if( mode == MBEDTLS_CAMELLIA_DECRYPT ) - { - while( length > 0 ) - { - memcpy( temp, input, 16 ); - mbedtls_camellia_crypt_ecb( ctx, mode, input, output ); + if (mode == MBEDTLS_CAMELLIA_DECRYPT) { + while (length > 0) { + memcpy(temp, input, 16); + mbedtls_camellia_crypt_ecb(ctx, mode, input, output); - for( i = 0; i < 16; i++ ) - output[i] = (unsigned char)( output[i] ^ iv[i] ); + for (i = 0; i < 16; i++) + output[i] = (unsigned char)(output[i] ^ iv[i]); - memcpy( iv, temp, 16 ); + memcpy(iv, temp, 16); - input += 16; + input += 16; output += 16; length -= 16; } - } - else - { - while( length > 0 ) - { - for( i = 0; i < 16; i++ ) - output[i] = (unsigned char)( input[i] ^ iv[i] ); + } else { + while (length > 0) { + for (i = 0; i < 16; i++) + output[i] = (unsigned char)(input[i] ^ iv[i]); - mbedtls_camellia_crypt_ecb( ctx, mode, output, output ); - memcpy( iv, output, 16 ); + mbedtls_camellia_crypt_ecb(ctx, mode, output, output); + memcpy(iv, output, 16); - input += 16; + input += 16; output += 16; length -= 16; } } - return( 0 ); + return (0); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -655,58 +563,47 @@ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, /* * Camellia-CFB128 buffer encryption/decryption */ -int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, - int mode, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_camellia_crypt_cfb128( + mbedtls_camellia_context* ctx, int mode, size_t length, size_t* iv_off, unsigned char iv[16], const unsigned char* input, unsigned char* output) { int c; size_t n; - CAMELLIA_VALIDATE_RET( ctx != NULL ); - CAMELLIA_VALIDATE_RET( mode == MBEDTLS_CAMELLIA_ENCRYPT || - mode == MBEDTLS_CAMELLIA_DECRYPT ); - CAMELLIA_VALIDATE_RET( iv != NULL ); - CAMELLIA_VALIDATE_RET( iv_off != NULL ); - CAMELLIA_VALIDATE_RET( length == 0 || input != NULL ); - CAMELLIA_VALIDATE_RET( length == 0 || output != NULL ); + CAMELLIA_VALIDATE_RET(ctx != NULL); + CAMELLIA_VALIDATE_RET(mode == MBEDTLS_CAMELLIA_ENCRYPT || mode == MBEDTLS_CAMELLIA_DECRYPT); + CAMELLIA_VALIDATE_RET(iv != NULL); + CAMELLIA_VALIDATE_RET(iv_off != NULL); + CAMELLIA_VALIDATE_RET(length == 0 || input != NULL); + CAMELLIA_VALIDATE_RET(length == 0 || output != NULL); n = *iv_off; - if( n >= 16 ) - return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + if (n >= 16) + return (MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA); - if( mode == MBEDTLS_CAMELLIA_DECRYPT ) - { - while( length-- ) - { - if( n == 0 ) - mbedtls_camellia_crypt_ecb( ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv ); + if (mode == MBEDTLS_CAMELLIA_DECRYPT) { + while (length--) { + if (n == 0) + mbedtls_camellia_crypt_ecb(ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv); c = *input++; - *output++ = (unsigned char)( c ^ iv[n] ); - iv[n] = (unsigned char) c; + *output++ = (unsigned char)(c ^ iv[n]); + iv[n] = (unsigned char)c; - n = ( n + 1 ) & 0x0F; + n = (n + 1) & 0x0F; } - } - else - { - while( length-- ) - { - if( n == 0 ) - mbedtls_camellia_crypt_ecb( ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv ); + } else { + while (length--) { + if (n == 0) + mbedtls_camellia_crypt_ecb(ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv); - iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); + iv[n] = *output++ = (unsigned char)(iv[n] ^ *input++); - n = ( n + 1 ) & 0x0F; + n = (n + 1) & 0x0F; } } *iv_off = n; - return( 0 ); + return (0); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ @@ -714,46 +611,45 @@ int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, /* * Camellia-CTR buffer encryption/decryption */ -int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, - size_t length, - size_t *nc_off, - unsigned char nonce_counter[16], - unsigned char stream_block[16], - const unsigned char *input, - unsigned char *output ) +int mbedtls_camellia_crypt_ctr( + mbedtls_camellia_context* ctx, + size_t length, + size_t* nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char* input, + unsigned char* output) { int c, i; size_t n; - CAMELLIA_VALIDATE_RET( ctx != NULL ); - CAMELLIA_VALIDATE_RET( nonce_counter != NULL ); - CAMELLIA_VALIDATE_RET( stream_block != NULL ); - CAMELLIA_VALIDATE_RET( nc_off != NULL ); - CAMELLIA_VALIDATE_RET( length == 0 || input != NULL ); - CAMELLIA_VALIDATE_RET( length == 0 || output != NULL ); + CAMELLIA_VALIDATE_RET(ctx != NULL); + CAMELLIA_VALIDATE_RET(nonce_counter != NULL); + CAMELLIA_VALIDATE_RET(stream_block != NULL); + CAMELLIA_VALIDATE_RET(nc_off != NULL); + CAMELLIA_VALIDATE_RET(length == 0 || input != NULL); + CAMELLIA_VALIDATE_RET(length == 0 || output != NULL); n = *nc_off; - if( n >= 16 ) - return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + if (n >= 16) + return (MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA); - while( length-- ) - { - if( n == 0 ) { - mbedtls_camellia_crypt_ecb( ctx, MBEDTLS_CAMELLIA_ENCRYPT, nonce_counter, - stream_block ); + while (length--) { + if (n == 0) { + mbedtls_camellia_crypt_ecb(ctx, MBEDTLS_CAMELLIA_ENCRYPT, nonce_counter, stream_block); - for( i = 16; i > 0; i-- ) - if( ++nonce_counter[i - 1] != 0 ) + for (i = 16; i > 0; i--) + if (++nonce_counter[i - 1] != 0) break; } c = *input++; - *output++ = (unsigned char)( c ^ stream_block[n] ); + *output++ = (unsigned char)(c ^ stream_block[n]); - n = ( n + 1 ) & 0x0F; + n = (n + 1) & 0x0F; } *nc_off = n; - return( 0 ); + return (0); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ #endif /* !MBEDTLS_CAMELLIA_ALT */ @@ -768,127 +664,64 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, * http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/t_camellia.txt * (For each bitlength: Key 0, Nr 39) */ -#define CAMELLIA_TESTS_ECB 2 - -static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] = -{ - { - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } - }, - { - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } - }, - { - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, - 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } - }, +#define CAMELLIA_TESTS_ECB 2 + +static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] = { + {{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, + {{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }, + {{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, }; -static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] = -{ - { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, - { 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } +static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] = { + {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}, + {0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; -static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] = -{ - { - { 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73, - 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 }, - { 0x38, 0x3C, 0x6C, 0x2A, 0xAB, 0xEF, 0x7F, 0xDE, - 0x25, 0xCD, 0x47, 0x0B, 0xF7, 0x74, 0xA3, 0x31 } - }, - { - { 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8, - 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 }, - { 0xD1, 0x76, 0x3F, 0xC0, 0x19, 0xD7, 0x7C, 0xC9, - 0x30, 0xBF, 0xF2, 0xA5, 0x6F, 0x7C, 0x93, 0x64 } - }, - { - { 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c, - 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 }, - { 0x05, 0x03, 0xFB, 0x10, 0xAB, 0x24, 0x1E, 0x7C, - 0xF4, 0x5D, 0x8C, 0xDE, 0xEE, 0x47, 0x43, 0x35 } - } +static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] = { + {{0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73, 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43}, + {0x38, 0x3C, 0x6C, 0x2A, 0xAB, 0xEF, 0x7F, 0xDE, 0x25, 0xCD, 0x47, 0x0B, 0xF7, 0x74, 0xA3, 0x31}}, + {{0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8, 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9}, + {0xD1, 0x76, 0x3F, 0xC0, 0x19, 0xD7, 0x7C, 0xC9, 0x30, 0xBF, 0xF2, 0xA5, 0x6F, 0x7C, 0x93, 0x64}}, + {{0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c, 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09}, + {0x05, 0x03, 0xFB, 0x10, 0xAB, 0x24, 0x1E, 0x7C, 0xF4, 0x5D, 0x8C, 0xDE, 0xEE, 0x47, 0x43, 0x35}} }; #if defined(MBEDTLS_CIPHER_MODE_CBC) -#define CAMELLIA_TESTS_CBC 3 +#define CAMELLIA_TESTS_CBC 3 -static const unsigned char camellia_test_cbc_key[3][32] = -{ - { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, - 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C } - , - { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, - 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, - 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B } - , - { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, - 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, - 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, - 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } +static const unsigned char camellia_test_cbc_key[3][32] = { + {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C}, + {0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B}, + {0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, + 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4} }; static const unsigned char camellia_test_cbc_iv[16] = - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F } -; - -static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] = -{ - { 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, - 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A }, - { 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, - 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51 }, - { 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, - 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF } + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; +static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] = { + {0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A}, + {0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51}, + {0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF} }; -static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] = -{ - { - { 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0, - 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB }, - { 0xA2, 0xF2, 0xCF, 0x67, 0x16, 0x29, 0xEF, 0x78, - 0x40, 0xC5, 0xA5, 0xDF, 0xB5, 0x07, 0x48, 0x87 }, - { 0x0F, 0x06, 0x16, 0x50, 0x08, 0xCF, 0x8B, 0x8B, - 0x5A, 0x63, 0x58, 0x63, 0x62, 0x54, 0x3E, 0x54 } - }, - { - { 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2, - 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93 }, - { 0x5D, 0x5A, 0x86, 0x9B, 0xD1, 0x4C, 0xE5, 0x42, - 0x64, 0xF8, 0x92, 0xA6, 0xDD, 0x2E, 0xC3, 0xD5 }, - { 0x37, 0xD3, 0x59, 0xC3, 0x34, 0x98, 0x36, 0xD8, - 0x84, 0xE3, 0x10, 0xAD, 0xDF, 0x68, 0xC4, 0x49 } - }, - { - { 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A, - 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA }, - { 0x36, 0xCB, 0xEB, 0x73, 0xBD, 0x50, 0x4B, 0x40, - 0x70, 0xB1, 0xB7, 0xDE, 0x2B, 0x21, 0xEB, 0x50 }, - { 0xE3, 0x1A, 0x60, 0x55, 0x29, 0x7D, 0x96, 0xCA, - 0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83 } - } +static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] = { + {{0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0, 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB}, + {0xA2, 0xF2, 0xCF, 0x67, 0x16, 0x29, 0xEF, 0x78, 0x40, 0xC5, 0xA5, 0xDF, 0xB5, 0x07, 0x48, 0x87}, + {0x0F, 0x06, 0x16, 0x50, 0x08, 0xCF, 0x8B, 0x8B, 0x5A, 0x63, 0x58, 0x63, 0x62, 0x54, 0x3E, 0x54}}, + {{0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2, 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93}, + {0x5D, 0x5A, 0x86, 0x9B, 0xD1, 0x4C, 0xE5, 0x42, 0x64, 0xF8, 0x92, 0xA6, 0xDD, 0x2E, 0xC3, 0xD5}, + {0x37, 0xD3, 0x59, 0xC3, 0x34, 0x98, 0x36, 0xD8, 0x84, 0xE3, 0x10, 0xAD, 0xDF, 0x68, 0xC4, 0x49}}, + {{0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A, 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA}, + {0x36, 0xCB, 0xEB, 0x73, 0xBD, 0x50, 0x4B, 0x40, 0x70, 0xB1, 0xB7, 0xDE, 0x2B, 0x21, 0xEB, 0x50}, + {0xE3, 0x1A, 0x60, 0x55, 0x29, 0x7D, 0x96, 0xCA, 0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83}} }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -899,66 +732,43 @@ static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] = * http://www.faqs.org/rfcs/rfc5528.html */ -static const unsigned char camellia_test_ctr_key[3][16] = -{ - { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC, - 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E }, - { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, - 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 }, - { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8, - 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC } +static const unsigned char camellia_test_ctr_key[3][16] = { + {0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC, 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E}, + {0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63}, + {0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8, 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC} }; -static const unsigned char camellia_test_ctr_nonce_counter[3][16] = -{ - { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, - { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, - 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 }, - { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, - 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 } +static const unsigned char camellia_test_ctr_nonce_counter[3][16] = { + {0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01}, + {0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01} }; -static const unsigned char camellia_test_ctr_pt[3][48] = -{ - { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, - 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 }, - - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }, - - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23 } +static const unsigned char camellia_test_ctr_pt[3][48] = { + {0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67}, + + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}, + + {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23} }; -static const unsigned char camellia_test_ctr_ct[3][48] = -{ - { 0xD0, 0x9D, 0xC2, 0x9A, 0x82, 0x14, 0x61, 0x9A, - 0x20, 0x87, 0x7C, 0x76, 0xDB, 0x1F, 0x0B, 0x3F }, - { 0xDB, 0xF3, 0xC7, 0x8D, 0xC0, 0x83, 0x96, 0xD4, - 0xDA, 0x7C, 0x90, 0x77, 0x65, 0xBB, 0xCB, 0x44, - 0x2B, 0x8E, 0x8E, 0x0F, 0x31, 0xF0, 0xDC, 0xA7, - 0x2C, 0x74, 0x17, 0xE3, 0x53, 0x60, 0xE0, 0x48 }, - { 0xB1, 0x9D, 0x1F, 0xCD, 0xCB, 0x75, 0xEB, 0x88, - 0x2F, 0x84, 0x9C, 0xE2, 0x4D, 0x85, 0xCF, 0x73, - 0x9C, 0xE6, 0x4B, 0x2B, 0x5C, 0x9D, 0x73, 0xF1, - 0x4F, 0x2D, 0x5D, 0x9D, 0xCE, 0x98, 0x89, 0xCD, - 0xDF, 0x50, 0x86, 0x96 } +static const unsigned char camellia_test_ctr_ct[3][48] = { + {0xD0, 0x9D, 0xC2, 0x9A, 0x82, 0x14, 0x61, 0x9A, 0x20, 0x87, 0x7C, 0x76, 0xDB, 0x1F, 0x0B, 0x3F}, + {0xDB, 0xF3, 0xC7, 0x8D, 0xC0, 0x83, 0x96, 0xD4, 0xDA, 0x7C, 0x90, 0x77, 0x65, 0xBB, 0xCB, 0x44, + 0x2B, 0x8E, 0x8E, 0x0F, 0x31, 0xF0, 0xDC, 0xA7, 0x2C, 0x74, 0x17, 0xE3, 0x53, 0x60, 0xE0, 0x48}, + {0xB1, 0x9D, 0x1F, 0xCD, 0xCB, 0x75, 0xEB, 0x88, 0x2F, 0x84, 0x9C, 0xE2, 0x4D, 0x85, 0xCF, 0x73, 0x9C, 0xE6, + 0x4B, 0x2B, 0x5C, 0x9D, 0x73, 0xF1, 0x4F, 0x2D, 0x5D, 0x9D, 0xCE, 0x98, 0x89, 0xCD, 0xDF, 0x50, 0x86, 0x96} }; -static const int camellia_test_ctr_len[3] = - { 16, 32, 36 }; +static const int camellia_test_ctr_len[3] = {16, 32, 36}; #endif /* MBEDTLS_CIPHER_MODE_CTR */ /* * Checkup routine */ -int mbedtls_camellia_self_test( int verbose ) +int mbedtls_camellia_self_test(int verbose) { int i, j, u, v; unsigned char key[32]; @@ -976,162 +786,147 @@ int mbedtls_camellia_self_test( int verbose ) mbedtls_camellia_context ctx; - memset( key, 0, 32 ); + memset(key, 0, 32); - for( j = 0; j < 6; j++ ) { + for (j = 0; j < 6; j++) { u = j >> 1; - v = j & 1; - - if( verbose != 0 ) - mbedtls_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64, - (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc"); - - for( i = 0; i < CAMELLIA_TESTS_ECB; i++ ) { - memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u ); - - if( v == MBEDTLS_CAMELLIA_DECRYPT ) { - mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 ); - memcpy( src, camellia_test_ecb_cipher[u][i], 16 ); - memcpy( dst, camellia_test_ecb_plain[i], 16 ); - } else { /* MBEDTLS_CAMELLIA_ENCRYPT */ - mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 ); - memcpy( src, camellia_test_ecb_plain[i], 16 ); - memcpy( dst, camellia_test_ecb_cipher[u][i], 16 ); - } + v = j & 1; + + if (verbose != 0) + mbedtls_printf(" CAMELLIA-ECB-%3d (%s): ", 128 + u * 64, (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc"); - mbedtls_camellia_crypt_ecb( &ctx, v, src, buf ); + for (i = 0; i < CAMELLIA_TESTS_ECB; i++) { + memcpy(key, camellia_test_ecb_key[u][i], 16 + 8 * u); - if( memcmp( buf, dst, 16 ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (v == MBEDTLS_CAMELLIA_DECRYPT) { + mbedtls_camellia_setkey_dec(&ctx, key, 128 + u * 64); + memcpy(src, camellia_test_ecb_cipher[u][i], 16); + memcpy(dst, camellia_test_ecb_plain[i], 16); + } else { /* MBEDTLS_CAMELLIA_ENCRYPT */ + mbedtls_camellia_setkey_enc(&ctx, key, 128 + u * 64); + memcpy(src, camellia_test_ecb_plain[i], 16); + memcpy(dst, camellia_test_ecb_cipher[u][i], 16); + } + + mbedtls_camellia_crypt_ecb(&ctx, v, src, buf); - return( 1 ); + if (memcmp(buf, dst, 16) != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); + + return (1); + } } - } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #if defined(MBEDTLS_CIPHER_MODE_CBC) /* * CBC mode */ - for( j = 0; j < 6; j++ ) - { + for (j = 0; j < 6; j++) { u = j >> 1; - v = j & 1; + v = j & 1; - if( verbose != 0 ) - mbedtls_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64, - ( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" ); + if (verbose != 0) + mbedtls_printf(" CAMELLIA-CBC-%3d (%s): ", 128 + u * 64, (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc"); - memcpy( src, camellia_test_cbc_iv, 16 ); - memcpy( dst, camellia_test_cbc_iv, 16 ); - memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u ); + memcpy(src, camellia_test_cbc_iv, 16); + memcpy(dst, camellia_test_cbc_iv, 16); + memcpy(key, camellia_test_cbc_key[u], 16 + 8 * u); - if( v == MBEDTLS_CAMELLIA_DECRYPT ) { - mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 ); + if (v == MBEDTLS_CAMELLIA_DECRYPT) { + mbedtls_camellia_setkey_dec(&ctx, key, 128 + u * 64); } else { - mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 ); + mbedtls_camellia_setkey_enc(&ctx, key, 128 + u * 64); } - for( i = 0; i < CAMELLIA_TESTS_CBC; i++ ) { - - if( v == MBEDTLS_CAMELLIA_DECRYPT ) { - memcpy( iv , src, 16 ); - memcpy( src, camellia_test_cbc_cipher[u][i], 16 ); - memcpy( dst, camellia_test_cbc_plain[i], 16 ); + for (i = 0; i < CAMELLIA_TESTS_CBC; i++) { + if (v == MBEDTLS_CAMELLIA_DECRYPT) { + memcpy(iv, src, 16); + memcpy(src, camellia_test_cbc_cipher[u][i], 16); + memcpy(dst, camellia_test_cbc_plain[i], 16); } else { /* MBEDTLS_CAMELLIA_ENCRYPT */ - memcpy( iv , dst, 16 ); - memcpy( src, camellia_test_cbc_plain[i], 16 ); - memcpy( dst, camellia_test_cbc_cipher[u][i], 16 ); + memcpy(iv, dst, 16); + memcpy(src, camellia_test_cbc_plain[i], 16); + memcpy(dst, camellia_test_cbc_cipher[u][i], 16); } - mbedtls_camellia_crypt_cbc( &ctx, v, 16, iv, src, buf ); + mbedtls_camellia_crypt_cbc(&ctx, v, 16, iv, src, buf); - if( memcmp( buf, dst, 16 ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (memcmp(buf, dst, 16) != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); - return( 1 ); + return (1); } } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #if defined(MBEDTLS_CIPHER_MODE_CTR) /* * CTR mode */ - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { u = i >> 1; - v = i & 1; + v = i & 1; - if( verbose != 0 ) - mbedtls_printf( " CAMELLIA-CTR-128 (%s): ", - ( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" ); + if (verbose != 0) + mbedtls_printf(" CAMELLIA-CTR-128 (%s): ", (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc"); - memcpy( nonce_counter, camellia_test_ctr_nonce_counter[u], 16 ); - memcpy( key, camellia_test_ctr_key[u], 16 ); + memcpy(nonce_counter, camellia_test_ctr_nonce_counter[u], 16); + memcpy(key, camellia_test_ctr_key[u], 16); offset = 0; - mbedtls_camellia_setkey_enc( &ctx, key, 128 ); + mbedtls_camellia_setkey_enc(&ctx, key, 128); - if( v == MBEDTLS_CAMELLIA_DECRYPT ) - { + if (v == MBEDTLS_CAMELLIA_DECRYPT) { len = camellia_test_ctr_len[u]; - memcpy( buf, camellia_test_ctr_ct[u], len ); + memcpy(buf, camellia_test_ctr_ct[u], len); - mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block, - buf, buf ); + mbedtls_camellia_crypt_ctr(&ctx, len, &offset, nonce_counter, stream_block, buf, buf); - if( memcmp( buf, camellia_test_ctr_pt[u], len ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (memcmp(buf, camellia_test_ctr_pt[u], len) != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); - return( 1 ); + return (1); } - } - else - { + } else { len = camellia_test_ctr_len[u]; - memcpy( buf, camellia_test_ctr_pt[u], len ); + memcpy(buf, camellia_test_ctr_pt[u], len); - mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block, - buf, buf ); + mbedtls_camellia_crypt_ctr(&ctx, len, &offset, nonce_counter, stream_block, buf, buf); - if( memcmp( buf, camellia_test_ctr_ct[u], len ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (memcmp(buf, camellia_test_ctr_ct[u], len) != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); - return( 1 ); + return (1); } } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); #endif /* MBEDTLS_CIPHER_MODE_CTR */ - return( 0 ); + return (0); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/nettls/ssl/ccm.c b/nettls/ssl/ccm.c index 394a5055f4c1f29b0bb2f7d9744c6a5a57ab1ec0..594584d9c846fd411e6b29c6e5107a0bc2604517 100644 --- a/nettls/ssl/ccm.c +++ b/nettls/ssl/ccm.c @@ -77,10 +77,8 @@ #if !defined(MBEDTLS_CCM_ALT) -#define CCM_VALIDATE_RET( cond ) \ - MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_CCM_BAD_INPUT ) -#define CCM_VALIDATE( cond ) \ - MBEDTLS_INTERNAL_VALIDATE( cond ) +#define CCM_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_CCM_BAD_INPUT) +#define CCM_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) #define CCM_ENCRYPT 0 #define CCM_DECRYPT 1 @@ -88,53 +86,48 @@ /* * Initialize context */ -void mbedtls_ccm_init( mbedtls_ccm_context *ctx ) +void mbedtls_ccm_init(mbedtls_ccm_context* ctx) { - CCM_VALIDATE( ctx != NULL ); - memset( ctx, 0, sizeof( mbedtls_ccm_context ) ); + CCM_VALIDATE(ctx != NULL); + memset(ctx, 0, sizeof(mbedtls_ccm_context)); } -int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, - mbedtls_cipher_id_t cipher, - const unsigned char *key, - unsigned int keybits ) +int mbedtls_ccm_setkey(mbedtls_ccm_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits) { int ret; - const mbedtls_cipher_info_t *cipher_info; + const mbedtls_cipher_info_t* cipher_info; - CCM_VALIDATE_RET( ctx != NULL ); - CCM_VALIDATE_RET( key != NULL ); + CCM_VALIDATE_RET(ctx != NULL); + CCM_VALIDATE_RET(key != NULL); - cipher_info = mbedtls_cipher_info_from_values( cipher, keybits, MBEDTLS_MODE_ECB ); - if( cipher_info == NULL ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + cipher_info = mbedtls_cipher_info_from_values(cipher, keybits, MBEDTLS_MODE_ECB); + if (cipher_info == NULL) + return (MBEDTLS_ERR_CCM_BAD_INPUT); - if( cipher_info->block_size != 16 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + if (cipher_info->block_size != 16) + return (MBEDTLS_ERR_CCM_BAD_INPUT); - mbedtls_cipher_free( &ctx->cipher_ctx ); + mbedtls_cipher_free(&ctx->cipher_ctx); - if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_cipher_setup(&ctx->cipher_ctx, cipher_info)) != 0) + return (ret); - if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, - MBEDTLS_ENCRYPT ) ) != 0 ) - { - return( ret ); + if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits, MBEDTLS_ENCRYPT)) != 0) { + return (ret); } - return( 0 ); + return (0); } /* * Free context */ -void mbedtls_ccm_free( mbedtls_ccm_context *ctx ) +void mbedtls_ccm_free(mbedtls_ccm_context* ctx) { - if( ctx == NULL ) + if (ctx == NULL) return; - mbedtls_cipher_free( &ctx->cipher_ctx ); - mbedtls_platform_zeroize( ctx, sizeof( mbedtls_ccm_context ) ); + mbedtls_cipher_free(&ctx->cipher_ctx); + mbedtls_platform_zeroize(ctx, sizeof(mbedtls_ccm_context)); } /* @@ -146,39 +139,43 @@ void mbedtls_ccm_free( mbedtls_ccm_context *ctx ) * Update the CBC-MAC state in y using a block in b * (Always using b as the source helps the compiler optimise a bit better.) */ -#define UPDATE_CBC_MAC \ - for( i = 0; i < 16; i++ ) \ - y[i] ^= b[i]; \ - \ - if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, y, 16, y, &olen ) ) != 0 ) \ - return( ret ); +#define UPDATE_CBC_MAC \ + for (i = 0; i < 16; i++) \ + y[i] ^= b[i]; \ +\ + if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, y, 16, y, &olen)) != 0) \ + return (ret); /* * Encrypt or decrypt a partial block with CTR * Warning: using b for temporary storage! src and dst must not be b! * This avoids allocating one more 16 bytes buffer while allowing src == dst. */ -#define CTR_CRYPT( dst, src, len ) \ - do \ - { \ - if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctr, \ - 16, b, &olen ) ) != 0 ) \ - { \ - return( ret ); \ - } \ - \ - for( i = 0; i < (len); i++ ) \ - (dst)[i] = (src)[i] ^ b[i]; \ - } while( 0 ) +#define CTR_CRYPT(dst, src, len) \ + do { \ + if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctr, 16, b, &olen)) != 0) { \ + return (ret); \ + } \ +\ + for (i = 0; i < (len); i++) \ + (dst)[i] = (src)[i] ^ b[i]; \ + } while (0) /* * Authenticated encryption or decryption */ -static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *add, size_t add_len, - const unsigned char *input, unsigned char *output, - unsigned char *tag, size_t tag_len ) +static int ccm_auth_crypt( + mbedtls_ccm_context* ctx, + int mode, + size_t length, + const unsigned char* iv, + size_t iv_len, + const unsigned char* add, + size_t add_len, + const unsigned char* input, + unsigned char* output, + unsigned char* tag, + size_t tag_len) { int ret; unsigned char i; @@ -187,8 +184,8 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, unsigned char b[16]; unsigned char y[16]; unsigned char ctr[16]; - const unsigned char *src; - unsigned char *dst; + const unsigned char* src; + unsigned char* dst; /* * Check length requirements: SP800-38C A.1 @@ -197,17 +194,17 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, * * Also, loosen the requirements to enable support for CCM* (IEEE 802.15.4). */ - if( tag_len == 2 || tag_len > 16 || tag_len % 2 != 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + if (tag_len == 2 || tag_len > 16 || tag_len % 2 != 0) + return (MBEDTLS_ERR_CCM_BAD_INPUT); /* Also implies q is within bounds */ - if( iv_len < 7 || iv_len > 13 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + if (iv_len < 7 || iv_len > 13) + return (MBEDTLS_ERR_CCM_BAD_INPUT); - if( add_len > 0xFF00 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + if (add_len > 0xFF00) + return (MBEDTLS_ERR_CCM_BAD_INPUT); - q = 16 - 1 - (unsigned char) iv_len; + q = 16 - 1 - (unsigned char)iv_len; /* * First block B_0: @@ -222,50 +219,47 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, * 2 .. 0 q - 1 */ b[0] = 0; - b[0] |= ( add_len > 0 ) << 6; - b[0] |= ( ( tag_len - 2 ) / 2 ) << 3; + b[0] |= (add_len > 0) << 6; + b[0] |= ((tag_len - 2) / 2) << 3; b[0] |= q - 1; - memcpy( b + 1, iv, iv_len ); + memcpy(b + 1, iv, iv_len); - for( i = 0, len_left = length; i < q; i++, len_left >>= 8 ) - b[15-i] = (unsigned char)( len_left & 0xFF ); - - if( len_left > 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); + for (i = 0, len_left = length; i < q; i++, len_left >>= 8) + b[15 - i] = (unsigned char)(len_left & 0xFF); + if (len_left > 0) + return (MBEDTLS_ERR_CCM_BAD_INPUT); /* Start CBC-MAC with first block */ - memset( y, 0, 16 ); + memset(y, 0, 16); UPDATE_CBC_MAC; /* * If there is additional data, update CBC-MAC with * add_len, add, 0 (padding to a block boundary) */ - if( add_len > 0 ) - { + if (add_len > 0) { size_t use_len; len_left = add_len; src = add; - memset( b, 0, 16 ); - b[0] = (unsigned char)( ( add_len >> 8 ) & 0xFF ); - b[1] = (unsigned char)( ( add_len ) & 0xFF ); + memset(b, 0, 16); + b[0] = (unsigned char)((add_len >> 8) & 0xFF); + b[1] = (unsigned char)((add_len)&0xFF); use_len = len_left < 16 - 2 ? len_left : 16 - 2; - memcpy( b + 2, src, use_len ); + memcpy(b + 2, src, use_len); len_left -= use_len; src += use_len; UPDATE_CBC_MAC; - while( len_left > 0 ) - { + while (len_left > 0) { use_len = len_left > 16 ? 16 : len_left; - memset( b, 0, 16 ); - memcpy( b, src, use_len ); + memset(b, 0, 16); + memcpy(b, src, use_len); UPDATE_CBC_MAC; len_left -= use_len; @@ -284,8 +278,8 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, * 2 .. 0 q - 1 */ ctr[0] = q - 1; - memcpy( ctr + 1, iv, iv_len ); - memset( ctr + 1 + iv_len, 0, q ); + memcpy(ctr + 1, iv, iv_len); + memset(ctr + 1 + iv_len, 0, q); ctr[15] = 1; /* @@ -298,23 +292,20 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, src = input; dst = output; - while( len_left > 0 ) - { + while (len_left > 0) { size_t use_len = len_left > 16 ? 16 : len_left; - if( mode == CCM_ENCRYPT ) - { - memset( b, 0, 16 ); - memcpy( b, src, use_len ); + if (mode == CCM_ENCRYPT) { + memset(b, 0, 16); + memcpy(b, src, use_len); UPDATE_CBC_MAC; } - CTR_CRYPT( dst, src, use_len ); + CTR_CRYPT(dst, src, use_len); - if( mode == CCM_DECRYPT ) - { - memset( b, 0, 16 ); - memcpy( b, dst, use_len ); + if (mode == CCM_DECRYPT) { + memset(b, 0, 16); + memcpy(b, dst, use_len); UPDATE_CBC_MAC; } @@ -326,120 +317,137 @@ static int ccm_auth_crypt( mbedtls_ccm_context *ctx, int mode, size_t length, * Increment counter. * No need to check for overflow thanks to the length check above. */ - for( i = 0; i < q; i++ ) - if( ++ctr[15-i] != 0 ) + for (i = 0; i < q; i++) + if (++ctr[15 - i] != 0) break; } /* * Authentication: reset counter and crypt/mask internal tag */ - for( i = 0; i < q; i++ ) - ctr[15-i] = 0; + for (i = 0; i < q; i++) + ctr[15 - i] = 0; - CTR_CRYPT( y, y, 16 ); - memcpy( tag, y, tag_len ); + CTR_CRYPT(y, y, 16); + memcpy(tag, y, tag_len); - return( 0 ); + return (0); } /* * Authenticated encryption */ -int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *add, size_t add_len, - const unsigned char *input, unsigned char *output, - unsigned char *tag, size_t tag_len ) +int mbedtls_ccm_star_encrypt_and_tag( + mbedtls_ccm_context* ctx, + size_t length, + const unsigned char* iv, + size_t iv_len, + const unsigned char* add, + size_t add_len, + const unsigned char* input, + unsigned char* output, + unsigned char* tag, + size_t tag_len) { - CCM_VALIDATE_RET( ctx != NULL ); - CCM_VALIDATE_RET( iv != NULL ); - CCM_VALIDATE_RET( add_len == 0 || add != NULL ); - CCM_VALIDATE_RET( length == 0 || input != NULL ); - CCM_VALIDATE_RET( length == 0 || output != NULL ); - CCM_VALIDATE_RET( tag_len == 0 || tag != NULL ); - return( ccm_auth_crypt( ctx, CCM_ENCRYPT, length, iv, iv_len, - add, add_len, input, output, tag, tag_len ) ); + CCM_VALIDATE_RET(ctx != NULL); + CCM_VALIDATE_RET(iv != NULL); + CCM_VALIDATE_RET(add_len == 0 || add != NULL); + CCM_VALIDATE_RET(length == 0 || input != NULL); + CCM_VALIDATE_RET(length == 0 || output != NULL); + CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); + return (ccm_auth_crypt(ctx, CCM_ENCRYPT, length, iv, iv_len, add, add_len, input, output, tag, tag_len)); } -int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *add, size_t add_len, - const unsigned char *input, unsigned char *output, - unsigned char *tag, size_t tag_len ) +int mbedtls_ccm_encrypt_and_tag( + mbedtls_ccm_context* ctx, + size_t length, + const unsigned char* iv, + size_t iv_len, + const unsigned char* add, + size_t add_len, + const unsigned char* input, + unsigned char* output, + unsigned char* tag, + size_t tag_len) { - CCM_VALIDATE_RET( ctx != NULL ); - CCM_VALIDATE_RET( iv != NULL ); - CCM_VALIDATE_RET( add_len == 0 || add != NULL ); - CCM_VALIDATE_RET( length == 0 || input != NULL ); - CCM_VALIDATE_RET( length == 0 || output != NULL ); - CCM_VALIDATE_RET( tag_len == 0 || tag != NULL ); - if( tag_len == 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); - - return( mbedtls_ccm_star_encrypt_and_tag( ctx, length, iv, iv_len, add, - add_len, input, output, tag, tag_len ) ); + CCM_VALIDATE_RET(ctx != NULL); + CCM_VALIDATE_RET(iv != NULL); + CCM_VALIDATE_RET(add_len == 0 || add != NULL); + CCM_VALIDATE_RET(length == 0 || input != NULL); + CCM_VALIDATE_RET(length == 0 || output != NULL); + CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); + if (tag_len == 0) + return (MBEDTLS_ERR_CCM_BAD_INPUT); + + return (mbedtls_ccm_star_encrypt_and_tag(ctx, length, iv, iv_len, add, add_len, input, output, tag, tag_len)); } /* * Authenticated decryption */ -int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *add, size_t add_len, - const unsigned char *input, unsigned char *output, - const unsigned char *tag, size_t tag_len ) +int mbedtls_ccm_star_auth_decrypt( + mbedtls_ccm_context* ctx, + size_t length, + const unsigned char* iv, + size_t iv_len, + const unsigned char* add, + size_t add_len, + const unsigned char* input, + unsigned char* output, + const unsigned char* tag, + size_t tag_len) { int ret; unsigned char check_tag[16]; unsigned char i; int diff; - CCM_VALIDATE_RET( ctx != NULL ); - CCM_VALIDATE_RET( iv != NULL ); - CCM_VALIDATE_RET( add_len == 0 || add != NULL ); - CCM_VALIDATE_RET( length == 0 || input != NULL ); - CCM_VALIDATE_RET( length == 0 || output != NULL ); - CCM_VALIDATE_RET( tag_len == 0 || tag != NULL ); - - if( ( ret = ccm_auth_crypt( ctx, CCM_DECRYPT, length, - iv, iv_len, add, add_len, - input, output, check_tag, tag_len ) ) != 0 ) - { - return( ret ); + CCM_VALIDATE_RET(ctx != NULL); + CCM_VALIDATE_RET(iv != NULL); + CCM_VALIDATE_RET(add_len == 0 || add != NULL); + CCM_VALIDATE_RET(length == 0 || input != NULL); + CCM_VALIDATE_RET(length == 0 || output != NULL); + CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); + + if ((ret = ccm_auth_crypt(ctx, CCM_DECRYPT, length, iv, iv_len, add, add_len, input, output, check_tag, tag_len)) != 0) { + return (ret); } /* Check tag in "constant-time" */ - for( diff = 0, i = 0; i < tag_len; i++ ) + for (diff = 0, i = 0; i < tag_len; i++) diff |= tag[i] ^ check_tag[i]; - if( diff != 0 ) - { - mbedtls_platform_zeroize( output, length ); - return( MBEDTLS_ERR_CCM_AUTH_FAILED ); + if (diff != 0) { + mbedtls_platform_zeroize(output, length); + return (MBEDTLS_ERR_CCM_AUTH_FAILED); } - return( 0 ); + return (0); } -int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *add, size_t add_len, - const unsigned char *input, unsigned char *output, - const unsigned char *tag, size_t tag_len ) +int mbedtls_ccm_auth_decrypt( + mbedtls_ccm_context* ctx, + size_t length, + const unsigned char* iv, + size_t iv_len, + const unsigned char* add, + size_t add_len, + const unsigned char* input, + unsigned char* output, + const unsigned char* tag, + size_t tag_len) { - CCM_VALIDATE_RET( ctx != NULL ); - CCM_VALIDATE_RET( iv != NULL ); - CCM_VALIDATE_RET( add_len == 0 || add != NULL ); - CCM_VALIDATE_RET( length == 0 || input != NULL ); - CCM_VALIDATE_RET( length == 0 || output != NULL ); - CCM_VALIDATE_RET( tag_len == 0 || tag != NULL ); - - if( tag_len == 0 ) - return( MBEDTLS_ERR_CCM_BAD_INPUT ); - - return( mbedtls_ccm_star_auth_decrypt( ctx, length, iv, iv_len, add, - add_len, input, output, tag, tag_len ) ); + CCM_VALIDATE_RET(ctx != NULL); + CCM_VALIDATE_RET(iv != NULL); + CCM_VALIDATE_RET(add_len == 0 || add != NULL); + CCM_VALIDATE_RET(length == 0 || input != NULL); + CCM_VALIDATE_RET(length == 0 || output != NULL); + CCM_VALIDATE_RET(tag_len == 0 || tag != NULL); + + if (tag_len == 0) + return (MBEDTLS_ERR_CCM_BAD_INPUT); + + return (mbedtls_ccm_star_auth_decrypt(ctx, length, iv, iv_len, add, add_len, input, output, tag, tag_len)); } #endif /* !MBEDTLS_CCM_ALT */ @@ -448,51 +456,36 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, * Examples 1 to 3 from SP800-38C Appendix C */ -#define NB_TESTS 3 +#define NB_TESTS 3 #define CCM_SELFTEST_PT_MAX_LEN 24 #define CCM_SELFTEST_CT_MAX_LEN 32 /* * The data is the same for all tests, only the used length changes */ -static const unsigned char key[] = { - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f -}; +static const unsigned char key[] = {0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f}; -static const unsigned char iv[] = { - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b -}; +static const unsigned char iv[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b}; -static const unsigned char ad[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13 -}; +static const unsigned char ad[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13}; static const unsigned char msg[CCM_SELFTEST_PT_MAX_LEN] = { - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, }; -static const size_t iv_len [NB_TESTS] = { 7, 8, 12 }; -static const size_t add_len[NB_TESTS] = { 8, 16, 20 }; -static const size_t msg_len[NB_TESTS] = { 4, 16, 24 }; -static const size_t tag_len[NB_TESTS] = { 4, 6, 8 }; +static const size_t iv_len[NB_TESTS] = {7, 8, 12}; +static const size_t add_len[NB_TESTS] = {8, 16, 20}; +static const size_t msg_len[NB_TESTS] = {4, 16, 24}; +static const size_t tag_len[NB_TESTS] = {4, 6, 8}; static const unsigned char res[NB_TESTS][CCM_SELFTEST_CT_MAX_LEN] = { - { 0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d }, - { 0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62, - 0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d, - 0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd }, - { 0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a, - 0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b, - 0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5, - 0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51 } + {0x71, 0x62, 0x01, 0x5b, 0x4d, 0xac, 0x25, 0x5d}, + {0xd2, 0xa1, 0xf0, 0xe0, 0x51, 0xea, 0x5f, 0x62, 0x08, 0x1a, 0x77, 0x92, 0x07, 0x3d, 0x59, 0x3d, 0x1f, 0xc6, 0x4f, 0xbf, 0xac, 0xcd}, + {0xe3, 0xb2, 0x01, 0xa9, 0xf5, 0xb7, 0x1a, 0x7a, 0x9b, 0x1c, 0xea, 0xec, 0xcd, 0x97, 0xe7, 0x0b, + 0x61, 0x76, 0xaa, 0xd9, 0xa4, 0x42, 0x8a, 0xa5, 0x48, 0x43, 0x92, 0xfb, 0xc1, 0xb0, 0x99, 0x51} }; -int mbedtls_ccm_self_test( int verbose ) +int mbedtls_ccm_self_test(int verbose) { mbedtls_ccm_context ctx; /* @@ -505,64 +498,53 @@ int mbedtls_ccm_self_test( int verbose ) size_t i; int ret; - mbedtls_ccm_init( &ctx ); + mbedtls_ccm_init(&ctx); - if( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, key, 8 * sizeof key ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( " CCM: setup failed" ); + if (mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, key, 8 * sizeof key) != 0) { + if (verbose != 0) + mbedtls_printf(" CCM: setup failed"); - return( 1 ); + return (1); } - for( i = 0; i < NB_TESTS; i++ ) - { - if( verbose != 0 ) - mbedtls_printf( " CCM-AES #%u: ", (unsigned int) i + 1 ); + for (i = 0; i < NB_TESTS; i++) { + if (verbose != 0) + mbedtls_printf(" CCM-AES #%u: ", (unsigned int)i + 1); - memset( plaintext, 0, CCM_SELFTEST_PT_MAX_LEN ); - memset( ciphertext, 0, CCM_SELFTEST_CT_MAX_LEN ); - memcpy( plaintext, msg, msg_len[i] ); + memset(plaintext, 0, CCM_SELFTEST_PT_MAX_LEN); + memset(ciphertext, 0, CCM_SELFTEST_CT_MAX_LEN); + memcpy(plaintext, msg, msg_len[i]); - ret = mbedtls_ccm_encrypt_and_tag( &ctx, msg_len[i], - iv, iv_len[i], ad, add_len[i], - plaintext, ciphertext, - ciphertext + msg_len[i], tag_len[i] ); + ret = + mbedtls_ccm_encrypt_and_tag(&ctx, msg_len[i], iv, iv_len[i], ad, add_len[i], plaintext, ciphertext, ciphertext + msg_len[i], tag_len[i]); - if( ret != 0 || - memcmp( ciphertext, res[i], msg_len[i] + tag_len[i] ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (ret != 0 || memcmp(ciphertext, res[i], msg_len[i] + tag_len[i]) != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); - return( 1 ); + return (1); } - memset( plaintext, 0, CCM_SELFTEST_PT_MAX_LEN ); + memset(plaintext, 0, CCM_SELFTEST_PT_MAX_LEN); - ret = mbedtls_ccm_auth_decrypt( &ctx, msg_len[i], - iv, iv_len[i], ad, add_len[i], - ciphertext, plaintext, - ciphertext + msg_len[i], tag_len[i] ); + ret = mbedtls_ccm_auth_decrypt(&ctx, msg_len[i], iv, iv_len[i], ad, add_len[i], ciphertext, plaintext, ciphertext + msg_len[i], tag_len[i]); - if( ret != 0 || - memcmp( plaintext, msg, msg_len[i] ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (ret != 0 || memcmp(plaintext, msg, msg_len[i]) != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); - return( 1 ); + return (1); } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - mbedtls_ccm_free( &ctx ); + mbedtls_ccm_free(&ctx); - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); - return( 0 ); + return (0); } #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/nettls/ssl/certs.c b/nettls/ssl/certs.c index 5021f179067f00a48ae86ebe155b04f5e1293494..50e5bb3784c6222e8fa905f553711928648d29d2 100644 --- a/nettls/ssl/certs.c +++ b/nettls/ssl/certs.c @@ -89,37 +89,30 @@ /* BEGIN FILE binary macro TEST_CA_CRT_EC_DER tests/data_files/test-ca2.crt.der */ #define TEST_CA_CRT_EC_DER \ { \ - 0x30, 0x82, 0x02, 0x04, 0x30, 0x82, 0x01, 0x88, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xc1, 0x43, \ - 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, \ - 0x02, 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, \ - 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, \ - 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, \ - 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, \ - 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, \ - 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3e, 0x31, \ - 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, \ - 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, \ - 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, \ - 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, \ - 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x03, 0x62, 0x00, 0x04, \ - 0xc3, 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, 0xba, 0x29, 0x43, 0x4b, \ - 0x4e, 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, 0x39, 0x0b, \ - 0x23, 0xdf, 0x5f, 0x17, 0x24, 0x62, 0x48, 0xfc, 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, 0xc2, 0x88, \ - 0x52, 0x80, 0xaf, 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, 0x1c, 0x6e, 0x58, 0xb8, 0xca, 0xe8, 0xb2, \ - 0x69, 0x8e, 0xf3, 0x41, 0xad, 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, 0x55, \ - 0x69, 0x9a, 0x53, 0x3b, 0x20, 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, \ - 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, \ - 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, \ - 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, \ - 0x18, 0x30, 0x16, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, \ - 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, \ - 0x04, 0x03, 0x02, 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x30, 0x51, 0xca, 0xae, 0x30, 0x0f, \ - 0xa4, 0x70, 0x74, 0x04, 0xdd, 0x5a, 0x2c, 0x7f, 0x13, 0xc1, 0xc2, 0x77, 0xbe, 0x1d, 0x00, 0xc5, 0xe2, \ - 0x99, 0x8f, 0x7d, 0x26, 0x45, 0xd3, 0x8a, 0x06, 0x68, 0x3f, 0x8c, 0xb4, 0xb7, 0xad, 0x4d, 0xe0, 0xf1, \ - 0x54, 0x01, 0x1e, 0x99, 0xfc, 0xb0, 0xe4, 0xd3, 0x07, 0x02, 0x31, 0x00, 0xdc, 0x4f, 0x3b, 0x90, 0x1e, \ - 0xae, 0x29, 0x99, 0x84, 0x28, 0xcc, 0x7b, 0x47, 0x78, 0x09, 0x31, 0xdf, 0xd6, 0x01, 0x59, 0x30, 0x5e, \ - 0xf4, 0xf8, 0x8a, 0x84, 0x3f, 0xea, 0x39, 0x54, 0x7b, 0x08, 0xa7, 0x60, 0xaa, 0xbd, 0xf9, 0x5b, 0xd1, \ - 0x51, 0x96, 0x14, 0x2e, 0x65, 0xf5, 0xae, 0x1c, 0x42 \ + 0x30, 0x82, 0x02, 0x04, 0x30, 0x82, 0x01, 0x88, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, \ + 0xe8, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, \ + 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \ + 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, \ + 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, \ + 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, \ + 0x5a, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ + 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, \ + 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, \ + 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0x03, 0x62, 0x00, \ + 0x04, 0xc3, 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, 0xba, 0x29, 0x43, 0x4b, 0x4e, 0xe0, 0x6e, 0xc3, \ + 0x0e, 0x57, 0x53, 0x33, 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, 0x39, 0x0b, 0x23, 0xdf, 0x5f, 0x17, 0x24, 0x62, 0x48, 0xfc, 0x1a, \ + 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, 0xc2, 0x88, 0x52, 0x80, 0xaf, 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, 0x1c, 0x6e, 0x58, 0xb8, \ + 0xca, 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, 0x55, 0x69, 0x9a, \ + 0x53, 0x3b, 0x20, 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, \ + 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, \ + 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, \ + 0x18, 0x30, 0x16, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, \ + 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, \ + 0x02, 0x30, 0x51, 0xca, 0xae, 0x30, 0x0f, 0xa4, 0x70, 0x74, 0x04, 0xdd, 0x5a, 0x2c, 0x7f, 0x13, 0xc1, 0xc2, 0x77, 0xbe, 0x1d, 0x00, \ + 0xc5, 0xe2, 0x99, 0x8f, 0x7d, 0x26, 0x45, 0xd3, 0x8a, 0x06, 0x68, 0x3f, 0x8c, 0xb4, 0xb7, 0xad, 0x4d, 0xe0, 0xf1, 0x54, 0x01, 0x1e, \ + 0x99, 0xfc, 0xb0, 0xe4, 0xd3, 0x07, 0x02, 0x31, 0x00, 0xdc, 0x4f, 0x3b, 0x90, 0x1e, 0xae, 0x29, 0x99, 0x84, 0x28, 0xcc, 0x7b, 0x47, \ + 0x78, 0x09, 0x31, 0xdf, 0xd6, 0x01, 0x59, 0x30, 0x5e, 0xf4, 0xf8, 0x8a, 0x84, 0x3f, 0xea, 0x39, 0x54, 0x7b, 0x08, 0xa7, 0x60, 0xaa, \ + 0xbd, 0xf9, 0x5b, 0xd1, 0x51, 0x96, 0x14, 0x2e, 0x65, 0xf5, 0xae, 0x1c, 0x42 \ } /* END FILE */ @@ -143,16 +136,14 @@ /* BEGIN FILE binary macro TEST_CA_KEY_EC_DER tests/data_files/test-ca2.key.der */ #define TEST_CA_KEY_EC_DER \ { \ - 0x30, 0x81, 0xa4, 0x02, 0x01, 0x01, 0x04, 0x30, 0x83, 0xd9, 0x15, 0x0e, 0xa0, 0x71, 0xf0, 0x57, 0x10, 0x33, \ - 0xa3, 0x38, 0xb8, 0x86, 0xc1, 0xa6, 0x11, 0x5d, 0x6d, 0xb4, 0x03, 0xe1, 0x29, 0x76, 0x45, 0xd7, 0x87, \ - 0x6f, 0x23, 0xab, 0x44, 0x20, 0xea, 0x64, 0x7b, 0x85, 0xb1, 0x76, 0xe7, 0x85, 0x95, 0xaa, 0x74, 0xd6, \ - 0xd1, 0xa4, 0x5e, 0xea, 0xa0, 0x07, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0xa1, 0x64, 0x03, 0x62, \ - 0x00, 0x04, 0xc3, 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, 0xba, 0x29, \ - 0x43, 0x4b, 0x4e, 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, \ - 0x39, 0x0b, 0x23, 0xdf, 0x5f, 0x17, 0x24, 0x62, 0x48, 0xfc, 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, \ - 0xc2, 0x88, 0x52, 0x80, 0xaf, 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, 0x1c, 0x6e, 0x58, 0xb8, 0xca, \ - 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, 0x6f, 0xd5, 0x19, \ - 0x29, 0x55, 0x69, 0x9a, 0x53, 0x3b, 0x20, 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e \ + 0x30, 0x81, 0xa4, 0x02, 0x01, 0x01, 0x04, 0x30, 0x83, 0xd9, 0x15, 0x0e, 0xa0, 0x71, 0xf0, 0x57, 0x10, 0x33, 0xa3, 0x38, 0xb8, 0x86, 0xc1, \ + 0xa6, 0x11, 0x5d, 0x6d, 0xb4, 0x03, 0xe1, 0x29, 0x76, 0x45, 0xd7, 0x87, 0x6f, 0x23, 0xab, 0x44, 0x20, 0xea, 0x64, 0x7b, 0x85, 0xb1, \ + 0x76, 0xe7, 0x85, 0x95, 0xaa, 0x74, 0xd6, 0xd1, 0xa4, 0x5e, 0xea, 0xa0, 0x07, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x22, 0xa1, 0x64, \ + 0x03, 0x62, 0x00, 0x04, 0xc3, 0xda, 0x2b, 0x34, 0x41, 0x37, 0x58, 0x2f, 0x87, 0x56, 0xfe, 0xfc, 0x89, 0xba, 0x29, 0x43, 0x4b, 0x4e, \ + 0xe0, 0x6e, 0xc3, 0x0e, 0x57, 0x53, 0x33, 0x39, 0x58, 0xd4, 0x52, 0xb4, 0x91, 0x95, 0x39, 0x0b, 0x23, 0xdf, 0x5f, 0x17, 0x24, 0x62, \ + 0x48, 0xfc, 0x1a, 0x95, 0x29, 0xce, 0x2c, 0x2d, 0x87, 0xc2, 0x88, 0x52, 0x80, 0xaf, 0xd6, 0x6a, 0xab, 0x21, 0xdd, 0xb8, 0xd3, 0x1c, \ + 0x6e, 0x58, 0xb8, 0xca, 0xe8, 0xb2, 0x69, 0x8e, 0xf3, 0x41, 0xad, 0x29, 0xc3, 0xb4, 0x5f, 0x75, 0xa7, 0x47, 0x6f, 0xd5, 0x19, 0x29, \ + 0x55, 0x69, 0x9a, 0x53, 0x3b, 0x20, 0xb4, 0x66, 0x16, 0x60, 0x33, 0x1e \ } /* END FILE */ @@ -186,56 +177,44 @@ /* BEGIN FILE binary macro TEST_CA_CRT_RSA_SHA256_DER tests/data_files/test-ca-sha256.crt.der */ #define TEST_CA_CRT_RSA_SHA256_DER \ { \ - 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, \ - 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, \ - 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ - 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, \ - 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, \ - 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \ - 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \ - 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, \ - 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \ - 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, \ - 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, \ - 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, \ - 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, \ - 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, \ - 0xf1, 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, 0x8b, 0xdf, \ - 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, \ - 0xd3, 0x9e, 0xd9, 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, 0xe7, 0x40, \ - 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, \ - 0xec, 0x4a, 0x63, 0xc0, 0xb8, 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \ - 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, 0xc6, 0x9f, 0xcb, \ - 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, \ - 0xb4, 0xd5, 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, 0x41, \ - 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, \ - 0x86, 0xf6, 0x31, 0xab, 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, \ - 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, \ - 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, \ - 0x64, 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, 0xe9, 0xc3, \ - 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, \ - 0x00, 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, \ - 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, \ - 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \ - 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, \ - 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \ - 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, \ - 0x01, 0x00, 0x38, 0xa8, 0x54, 0x82, 0xb6, 0x1d, 0xaa, 0xdb, 0x6b, 0x89, 0x21, 0xd1, 0x38, 0x28, 0x61, \ - 0xc9, 0xb0, 0x98, 0xd5, 0x11, 0xfc, 0x36, 0xff, 0x19, 0xfe, 0x32, 0x44, 0xef, 0x08, 0xc7, 0xf1, 0x56, \ - 0xbb, 0xe6, 0x46, 0xfa, 0x82, 0xb6, 0x31, 0x38, 0xb4, 0xa0, 0xe5, 0xa0, 0xae, 0x0c, 0xc4, 0x53, 0x9e, \ - 0x93, 0x4e, 0xe8, 0x0d, 0x9c, 0x2f, 0xb4, 0x04, 0xfd, 0x8a, 0x39, 0xf5, 0x84, 0x77, 0xed, 0x4c, 0xd4, \ - 0xbb, 0x44, 0x7f, 0x73, 0x77, 0xf7, 0xf1, 0x36, 0x97, 0xdc, 0x1e, 0x73, 0x19, 0x5d, 0x50, 0xb8, 0xc3, \ - 0x80, 0xcd, 0x03, 0x57, 0xd2, 0x00, 0xdb, 0x56, 0xe6, 0xc6, 0x35, 0x24, 0x1e, 0x49, 0x7b, 0xd8, 0xd2, \ - 0x72, 0xbb, 0x0b, 0x49, 0x2f, 0xa6, 0x02, 0x3c, 0xaf, 0xd0, 0xec, 0x37, 0x1d, 0xbd, 0x81, 0x8b, 0x1f, \ - 0x30, 0xbb, 0xbc, 0x4d, 0x36, 0xb5, 0x79, 0x7c, 0x87, 0xfb, 0x51, 0xb9, 0xbe, 0xc2, 0xde, 0x92, 0xa8, \ - 0x40, 0x71, 0xbb, 0x72, 0x9b, 0xf8, 0x47, 0xce, 0x6c, 0x04, 0xf8, 0x86, 0xe7, 0xf7, 0x73, 0x3c, 0xe7, \ - 0x84, 0x7d, 0xc2, 0xd7, 0xb7, 0x9d, 0xe8, 0xd4, 0x9b, 0x5f, 0x0a, 0x17, 0x7d, 0xbc, 0xbb, 0xb2, 0xd5, \ - 0x94, 0x0d, 0xe4, 0x49, 0xbf, 0x4f, 0x11, 0x68, 0x53, 0xb2, 0x91, 0xff, 0xc0, 0x69, 0xee, 0xdb, 0x63, \ - 0x93, 0xcb, 0xc9, 0x35, 0x6b, 0x90, 0x09, 0xe2, 0x90, 0xc9, 0xed, 0x27, 0xd6, 0x08, 0xfa, 0x13, 0x4d, \ - 0x62, 0xdd, 0xe2, 0x9e, 0xaa, 0xb5, 0xd4, 0x0e, 0x5c, 0x37, 0x4f, 0xab, 0x55, 0x3b, 0x2d, 0xf1, 0x42, \ - 0x82, 0xc7, 0x34, 0x38, 0x1a, 0x9b, 0xeb, 0xa1, 0x2c, 0x0f, 0x29, 0x31, 0x64, 0x6c, 0xcc, 0x38, 0xfd, \ - 0xa9, 0xd3, 0xd5, 0xd5, 0x71, 0xaf, 0xf0, 0x6d, 0xc0, 0x97, 0xe2, 0x11, 0x2a, 0x0a, 0xdf, 0xfe, 0x02, \ - 0x79, 0x74, 0x75 \ + 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, \ + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, \ + 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, \ + 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, \ + 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, \ + 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, \ + 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, \ + 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \ + 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \ + 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0xdf, 0x37, \ + 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, 0x99, 0xd4, 0xec, \ + 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, \ + 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, \ + 0xf2, 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, \ + 0x63, 0xc0, 0xb8, 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, \ + 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, 0x4f, 0xfb, 0x58, \ + 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, 0x41, \ + 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, 0xf1, \ + 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, \ + 0x37, 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, \ + 0x38, 0x65, 0x64, 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, \ + 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, \ + 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, \ + 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \ + 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, \ + 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, \ + 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x38, 0xa8, 0x54, 0x82, 0xb6, 0x1d, 0xaa, 0xdb, 0x6b, 0x89, 0x21, 0xd1, 0x38, 0x28, \ + 0x61, 0xc9, 0xb0, 0x98, 0xd5, 0x11, 0xfc, 0x36, 0xff, 0x19, 0xfe, 0x32, 0x44, 0xef, 0x08, 0xc7, 0xf1, 0x56, 0xbb, 0xe6, 0x46, 0xfa, \ + 0x82, 0xb6, 0x31, 0x38, 0xb4, 0xa0, 0xe5, 0xa0, 0xae, 0x0c, 0xc4, 0x53, 0x9e, 0x93, 0x4e, 0xe8, 0x0d, 0x9c, 0x2f, 0xb4, 0x04, 0xfd, \ + 0x8a, 0x39, 0xf5, 0x84, 0x77, 0xed, 0x4c, 0xd4, 0xbb, 0x44, 0x7f, 0x73, 0x77, 0xf7, 0xf1, 0x36, 0x97, 0xdc, 0x1e, 0x73, 0x19, 0x5d, \ + 0x50, 0xb8, 0xc3, 0x80, 0xcd, 0x03, 0x57, 0xd2, 0x00, 0xdb, 0x56, 0xe6, 0xc6, 0x35, 0x24, 0x1e, 0x49, 0x7b, 0xd8, 0xd2, 0x72, 0xbb, \ + 0x0b, 0x49, 0x2f, 0xa6, 0x02, 0x3c, 0xaf, 0xd0, 0xec, 0x37, 0x1d, 0xbd, 0x81, 0x8b, 0x1f, 0x30, 0xbb, 0xbc, 0x4d, 0x36, 0xb5, 0x79, \ + 0x7c, 0x87, 0xfb, 0x51, 0xb9, 0xbe, 0xc2, 0xde, 0x92, 0xa8, 0x40, 0x71, 0xbb, 0x72, 0x9b, 0xf8, 0x47, 0xce, 0x6c, 0x04, 0xf8, 0x86, \ + 0xe7, 0xf7, 0x73, 0x3c, 0xe7, 0x84, 0x7d, 0xc2, 0xd7, 0xb7, 0x9d, 0xe8, 0xd4, 0x9b, 0x5f, 0x0a, 0x17, 0x7d, 0xbc, 0xbb, 0xb2, 0xd5, \ + 0x94, 0x0d, 0xe4, 0x49, 0xbf, 0x4f, 0x11, 0x68, 0x53, 0xb2, 0x91, 0xff, 0xc0, 0x69, 0xee, 0xdb, 0x63, 0x93, 0xcb, 0xc9, 0x35, 0x6b, \ + 0x90, 0x09, 0xe2, 0x90, 0xc9, 0xed, 0x27, 0xd6, 0x08, 0xfa, 0x13, 0x4d, 0x62, 0xdd, 0xe2, 0x9e, 0xaa, 0xb5, 0xd4, 0x0e, 0x5c, 0x37, \ + 0x4f, 0xab, 0x55, 0x3b, 0x2d, 0xf1, 0x42, 0x82, 0xc7, 0x34, 0x38, 0x1a, 0x9b, 0xeb, 0xa1, 0x2c, 0x0f, 0x29, 0x31, 0x64, 0x6c, 0xcc, \ + 0x38, 0xfd, 0xa9, 0xd3, 0xd5, 0xd5, 0x71, 0xaf, 0xf0, 0x6d, 0xc0, 0x97, 0xe2, 0x11, 0x2a, 0x0a, 0xdf, 0xfe, 0x02, 0x79, 0x74, 0x75 \ } /* END FILE */ @@ -268,56 +247,44 @@ /* BEGIN FILE binary macro TEST_CA_CRT_RSA_SHA1_DER tests/data_files/test-ca-sha1.crt.der */ #define TEST_CA_CRT_RSA_SHA1_DER \ { \ - 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, \ - 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, \ - 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ - 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, \ - 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, \ - 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \ - 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \ - 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, \ - 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \ - 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, \ - 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, \ - 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, \ - 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, \ - 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, \ - 0xf1, 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, 0x8b, 0xdf, \ - 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, \ - 0xd3, 0x9e, 0xd9, 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, 0xe7, 0x40, \ - 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, \ - 0xec, 0x4a, 0x63, 0xc0, 0xb8, 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, \ - 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, 0xc6, 0x9f, 0xcb, \ - 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, \ - 0xb4, 0xd5, 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, 0x41, \ - 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, \ - 0x86, 0xf6, 0x31, 0xab, 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, \ - 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, \ - 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, \ - 0x64, 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, 0xe9, 0xc3, \ - 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, \ - 0x00, 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, \ - 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xb4, 0x5a, 0xe4, \ - 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \ - 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, \ - 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \ - 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, \ - 0x01, 0x00, 0x74, 0x66, 0x23, 0x51, 0x15, 0xd8, 0x9a, 0xea, 0x4b, 0x24, 0x68, 0xf9, 0xe1, 0xae, 0xa7, \ - 0xa3, 0x21, 0x1a, 0xbc, 0x60, 0xc1, 0x06, 0x01, 0xfd, 0xa8, 0x20, 0xf9, 0xf2, 0x67, 0xbf, 0x31, 0xa3, \ - 0x21, 0x11, 0x81, 0xcd, 0xf9, 0x94, 0x71, 0xb2, 0x32, 0xdb, 0x0b, 0x85, 0x68, 0x9c, 0x36, 0x33, 0xf8, \ - 0x77, 0xf8, 0x52, 0xf4, 0x0b, 0x38, 0x8f, 0x92, 0x80, 0xda, 0x07, 0x4d, 0x1a, 0x2e, 0x44, 0x4c, 0x0d, \ - 0x57, 0xed, 0x2a, 0x30, 0x58, 0xe1, 0xac, 0xaf, 0x28, 0xaf, 0x4a, 0x93, 0x12, 0x1d, 0x5c, 0xb5, 0xf8, \ - 0x77, 0x5f, 0x5a, 0x5b, 0x18, 0x40, 0xec, 0xe6, 0xf2, 0x8f, 0x9f, 0x69, 0x03, 0x54, 0x9b, 0xc5, 0xf3, \ - 0x3d, 0x59, 0xad, 0xb5, 0xf0, 0x15, 0xb2, 0x9c, 0x5e, 0x1d, 0x2c, 0x49, 0x67, 0x7e, 0x8e, 0xa3, 0xe4, \ - 0x16, 0x67, 0x9c, 0x19, 0x94, 0x22, 0x04, 0xca, 0x31, 0x1d, 0x2d, 0x42, 0x1d, 0xf9, 0x39, 0xb8, 0x07, \ - 0x3d, 0xc1, 0xe6, 0x34, 0x43, 0xcd, 0x96, 0xbf, 0x49, 0xaa, 0x83, 0xa2, 0x4a, 0xba, 0xe8, 0xdd, 0xb3, \ - 0xa5, 0xb8, 0x0a, 0x28, 0x09, 0x77, 0x19, 0x4d, 0x8e, 0xfb, 0xe7, 0xc1, 0xa8, 0xfd, 0x9d, 0x4a, 0x47, \ - 0x50, 0xca, 0x49, 0x93, 0xc6, 0x12, 0xcb, 0x59, 0x13, 0x7c, 0x14, 0x9a, 0xa1, 0x60, 0x04, 0xf2, 0x42, \ - 0x7b, 0x59, 0xd1, 0x04, 0xa2, 0xdd, 0x6f, 0x47, 0x7d, 0x26, 0x4f, 0x9c, 0x54, 0xdc, 0x3c, 0x85, 0xde, \ - 0xa2, 0x23, 0xdd, 0xda, 0x92, 0xe5, 0xc6, 0xdd, 0x61, 0x66, 0xef, 0x1d, 0xc2, 0xcd, 0x8b, 0x4d, 0x71, \ - 0x3a, 0xde, 0xe3, 0xfa, 0x30, 0xce, 0x0b, 0x1e, 0xf5, 0xb1, 0x8a, 0xe2, 0x5a, 0x5a, 0x43, 0xff, 0x9a, \ - 0xdc, 0x72, 0x50, 0x02, 0xe3, 0xda, 0x94, 0x31, 0x46, 0x2b, 0x68, 0xa4, 0xe4, 0x45, 0x41, 0xd9, 0xfb, \ - 0x00, 0xe6, 0x39 \ + 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x03, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, \ + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, \ + 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, \ + 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, \ + 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, \ + 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, \ + 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, \ + 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \ + 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, \ + 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0xdf, 0x37, \ + 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, 0x99, 0xd4, 0xec, \ + 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, \ + 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, 0xd9, 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, \ + 0xf2, 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, \ + 0x63, 0xc0, 0xb8, 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, \ + 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, 0x4f, 0xfb, 0x58, \ + 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, 0x41, \ + 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, 0xf1, \ + 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, \ + 0x37, 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, \ + 0x38, 0x65, 0x64, 0x09, 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, \ + 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, \ + 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, \ + 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, \ + 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, \ + 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, \ + 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x74, 0x66, 0x23, 0x51, 0x15, 0xd8, 0x9a, 0xea, 0x4b, 0x24, 0x68, 0xf9, 0xe1, 0xae, \ + 0xa7, 0xa3, 0x21, 0x1a, 0xbc, 0x60, 0xc1, 0x06, 0x01, 0xfd, 0xa8, 0x20, 0xf9, 0xf2, 0x67, 0xbf, 0x31, 0xa3, 0x21, 0x11, 0x81, 0xcd, \ + 0xf9, 0x94, 0x71, 0xb2, 0x32, 0xdb, 0x0b, 0x85, 0x68, 0x9c, 0x36, 0x33, 0xf8, 0x77, 0xf8, 0x52, 0xf4, 0x0b, 0x38, 0x8f, 0x92, 0x80, \ + 0xda, 0x07, 0x4d, 0x1a, 0x2e, 0x44, 0x4c, 0x0d, 0x57, 0xed, 0x2a, 0x30, 0x58, 0xe1, 0xac, 0xaf, 0x28, 0xaf, 0x4a, 0x93, 0x12, 0x1d, \ + 0x5c, 0xb5, 0xf8, 0x77, 0x5f, 0x5a, 0x5b, 0x18, 0x40, 0xec, 0xe6, 0xf2, 0x8f, 0x9f, 0x69, 0x03, 0x54, 0x9b, 0xc5, 0xf3, 0x3d, 0x59, \ + 0xad, 0xb5, 0xf0, 0x15, 0xb2, 0x9c, 0x5e, 0x1d, 0x2c, 0x49, 0x67, 0x7e, 0x8e, 0xa3, 0xe4, 0x16, 0x67, 0x9c, 0x19, 0x94, 0x22, 0x04, \ + 0xca, 0x31, 0x1d, 0x2d, 0x42, 0x1d, 0xf9, 0x39, 0xb8, 0x07, 0x3d, 0xc1, 0xe6, 0x34, 0x43, 0xcd, 0x96, 0xbf, 0x49, 0xaa, 0x83, 0xa2, \ + 0x4a, 0xba, 0xe8, 0xdd, 0xb3, 0xa5, 0xb8, 0x0a, 0x28, 0x09, 0x77, 0x19, 0x4d, 0x8e, 0xfb, 0xe7, 0xc1, 0xa8, 0xfd, 0x9d, 0x4a, 0x47, \ + 0x50, 0xca, 0x49, 0x93, 0xc6, 0x12, 0xcb, 0x59, 0x13, 0x7c, 0x14, 0x9a, 0xa1, 0x60, 0x04, 0xf2, 0x42, 0x7b, 0x59, 0xd1, 0x04, 0xa2, \ + 0xdd, 0x6f, 0x47, 0x7d, 0x26, 0x4f, 0x9c, 0x54, 0xdc, 0x3c, 0x85, 0xde, 0xa2, 0x23, 0xdd, 0xda, 0x92, 0xe5, 0xc6, 0xdd, 0x61, 0x66, \ + 0xef, 0x1d, 0xc2, 0xcd, 0x8b, 0x4d, 0x71, 0x3a, 0xde, 0xe3, 0xfa, 0x30, 0xce, 0x0b, 0x1e, 0xf5, 0xb1, 0x8a, 0xe2, 0x5a, 0x5a, 0x43, \ + 0xff, 0x9a, 0xdc, 0x72, 0x50, 0x02, 0xe3, 0xda, 0x94, 0x31, 0x46, 0x2b, 0x68, 0xa4, 0xe4, 0x45, 0x41, 0xd9, 0xfb, 0x00, 0xe6, 0x39 \ } /* END FILE */ @@ -362,76 +329,61 @@ /* BEGIN FILE binary macro TEST_CA_KEY_RSA_DER tests/data_files/test-ca.key.der */ #define TEST_CA_KEY_RSA_DER \ { \ - 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, \ - 0xe0, 0x96, 0x9d, 0x3f, 0x86, 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, 0x99, \ - 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, 0xec, 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, \ - 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, 0xd3, 0x9e, \ - 0xd9, 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, 0xe7, 0x40, 0x70, 0x14, \ - 0xcb, 0x44, 0xa2, 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, \ - 0x63, 0xc0, 0xb8, 0x29, 0x00, 0x74, 0x9c, 0x57, 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, 0xbd, 0x83, \ - 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, 0xc6, 0x9f, 0xcb, 0xba, 0xec, \ - 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, \ - 0xfb, 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, 0x41, 0x55, 0xc0, \ - 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, 0xcb, 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, \ - 0x31, 0xab, 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, 0x17, 0xf0, 0x62, 0x6f, 0x27, 0x3e, \ - 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, 0xe9, \ - 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, 0x09, \ - 0xea, 0x0c, 0x6e, 0x8e, 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, \ - 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, 0x58, 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, \ - 0x02, 0x82, 0x01, 0x00, 0x3f, 0xf7, 0x07, 0xd3, 0x34, 0x6f, 0xdb, 0xc9, 0x37, 0xb7, 0x84, 0xdc, 0x37, \ - 0x45, 0xe1, 0x63, 0xad, 0xb8, 0xb6, 0x75, 0xb1, 0xc7, 0x35, 0xb4, 0x77, 0x2a, 0x5b, 0x77, 0xf9, 0x7e, \ - 0xe0, 0xc1, 0xa3, 0xd1, 0xb7, 0xcb, 0xa9, 0x5a, 0xc1, 0x87, 0xda, 0x5a, 0xfa, 0x17, 0xe4, 0xd5, 0x38, \ - 0x03, 0xde, 0x68, 0x98, 0x81, 0xec, 0xb5, 0xf2, 0x2a, 0x8d, 0xe9, 0x2c, 0xf3, 0xa6, 0xe5, 0x32, 0x17, \ - 0x7f, 0x33, 0x81, 0xe8, 0x38, 0x72, 0xd5, 0x9c, 0xfa, 0x4e, 0xfb, 0x26, 0xf5, 0x15, 0x0b, 0xaf, 0x84, \ - 0x66, 0xab, 0x02, 0xe0, 0x18, 0xd5, 0x91, 0x7c, 0xd6, 0x8f, 0xc9, 0x4b, 0x76, 0x08, 0x2b, 0x1d, 0x81, \ - 0x68, 0x30, 0xe1, 0xfa, 0x70, 0x6c, 0x13, 0x4e, 0x10, 0x03, 0x35, 0x3e, 0xc5, 0xca, 0x58, 0x20, 0x8a, \ - 0x21, 0x18, 0x38, 0xa0, 0x0f, 0xed, 0xc4, 0xbb, 0x45, 0x6f, 0xf5, 0x84, 0x5b, 0xb0, 0xcf, 0x4e, 0x9d, \ - 0x58, 0x13, 0x6b, 0x35, 0x35, 0x69, 0xa1, 0xd2, 0xc4, 0xf2, 0xc1, 0x48, 0x04, 0x20, 0x51, 0xb9, 0x6b, \ - 0xa4, 0x5d, 0xa5, 0x4b, 0x84, 0x88, 0x43, 0x48, 0x99, 0x2c, 0xbb, 0xa4, 0x97, 0xd6, 0xd6, 0x18, 0xf6, \ - 0xec, 0x5c, 0xd1, 0x31, 0x49, 0xc9, 0xf2, 0x8f, 0x0b, 0x4d, 0xef, 0x09, 0x02, 0xfe, 0x7d, 0xfd, 0xbb, \ - 0xaf, 0x2b, 0x83, 0x94, 0x22, 0xc4, 0xa7, 0x3e, 0x66, 0xf5, 0xe0, 0x57, 0xdc, 0xf2, 0xed, 0x2c, 0x3e, \ - 0x81, 0x74, 0x76, 0x1e, 0x96, 0x6f, 0x74, 0x1e, 0x32, 0x0e, 0x14, 0x31, 0xd0, 0x74, 0xf0, 0xf4, 0x07, \ - 0xbd, 0xc3, 0xd1, 0x22, 0xc2, 0xa8, 0x95, 0x92, 0x06, 0x7f, 0x43, 0x02, 0x91, 0xbc, 0xdd, 0x23, 0x01, \ - 0x89, 0x94, 0x20, 0x44, 0x64, 0xf5, 0x1d, 0x67, 0xd2, 0x8f, 0xe8, 0x69, 0xa5, 0x29, 0x25, 0xe6, 0x50, \ - 0x9c, 0xe3, 0xe9, 0xcb, 0x75, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x29, 0x3e, 0xaa, 0x6b, 0xd5, 0x59, 0x1e, \ - 0x9c, 0xe6, 0x47, 0xd5, 0xb6, 0xd7, 0xe3, 0xf1, 0x8e, 0x9e, 0xe9, 0x83, 0x5f, 0x10, 0x9f, 0x63, 0xec, \ - 0x04, 0x44, 0xcc, 0x3f, 0xf8, 0xd9, 0x3a, 0x17, 0xe0, 0x4f, 0xfe, 0xd8, 0x4d, 0xcd, 0x46, 0x54, 0x74, \ - 0xbf, 0x0a, 0xc4, 0x67, 0x9c, 0xa7, 0xd8, 0x89, 0x65, 0x4c, 0xfd, 0x58, 0x2a, 0x47, 0x0f, 0xf4, 0x37, \ - 0xb6, 0x55, 0xb0, 0x1d, 0xed, 0xa7, 0x39, 0xfc, 0x4f, 0xa3, 0xc4, 0x75, 0x3a, 0xa3, 0x98, 0xa7, 0x45, \ - 0xf5, 0x66, 0xcb, 0x7c, 0x65, 0xfb, 0x80, 0x23, 0xe6, 0xff, 0xfd, 0x99, 0x1f, 0x8e, 0x6b, 0xff, 0x5e, \ - 0x93, 0x66, 0xdf, 0x6c, 0x6f, 0xc3, 0xf6, 0x38, 0x2e, 0xff, 0x69, 0xb5, 0xac, 0xae, 0xbb, 0xc6, 0x71, \ - 0x16, 0x6b, 0xd0, 0xf8, 0x22, 0xd9, 0xf8, 0xa2, 0x72, 0x20, 0xd2, 0xe2, 0x3a, 0x70, 0x4b, 0xde, 0xab, \ - 0x2f, 0x02, 0x81, 0x81, 0x00, 0xda, 0x51, 0x9b, 0xb8, 0xb2, 0x2a, 0x14, 0x75, 0x58, 0x40, 0x8d, 0x27, \ - 0x70, 0xfa, 0x31, 0x48, 0xb0, 0x20, 0x21, 0x34, 0xfa, 0x4c, 0x57, 0xa8, 0x11, 0x88, 0xf3, 0xa7, 0xae, \ - 0x21, 0xe9, 0xb6, 0x2b, 0xd1, 0xcd, 0xa7, 0xf8, 0xd8, 0x0c, 0x8a, 0x76, 0x22, 0x35, 0x44, 0xce, 0x3f, \ - 0x25, 0x29, 0x83, 0x7d, 0x79, 0xa7, 0x31, 0xd6, 0xec, 0xb2, 0xbf, 0xda, 0x34, 0xb6, 0xf6, 0xb2, 0x3b, \ - 0xf3, 0x78, 0x5a, 0x04, 0x83, 0x33, 0x3e, 0xa2, 0xe2, 0x81, 0x82, 0x13, 0xd4, 0x35, 0x17, 0x63, 0x9b, \ - 0x9e, 0xc4, 0x8d, 0x91, 0x4c, 0x03, 0x77, 0xc7, 0x71, 0x5b, 0xee, 0x83, 0x6d, 0xd5, 0x78, 0x88, 0xf6, \ - 0x2c, 0x79, 0xc2, 0x4a, 0xb4, 0x79, 0x90, 0x70, 0xbf, 0xdf, 0x34, 0x56, 0x96, 0x71, 0xe3, 0x0e, 0x68, \ - 0x91, 0xbc, 0xea, 0xcb, 0x33, 0xc0, 0xbe, 0x45, 0xd7, 0xfc, 0x30, 0xfd, 0x01, 0x3b, 0x02, 0x81, 0x81, \ - 0x00, 0xd2, 0x9f, 0x2a, 0xb7, 0x38, 0x19, 0xc7, 0x17, 0x95, 0x73, 0x78, 0xae, 0xf5, 0xcb, 0x75, 0x83, \ - 0x7f, 0x19, 0x4b, 0xcb, 0x86, 0xfb, 0x4a, 0x15, 0x9a, 0xb6, 0x17, 0x04, 0x49, 0x07, 0x8d, 0xf6, 0x66, \ - 0x4a, 0x06, 0xf6, 0x05, 0xa7, 0xdf, 0x66, 0x82, 0x3c, 0xff, 0xb6, 0x1d, 0x57, 0x89, 0x33, 0x5f, 0x9c, \ - 0x05, 0x75, 0x7f, 0xf3, 0x5d, 0xdc, 0x34, 0x65, 0x72, 0x85, 0x22, 0xa4, 0x14, 0x1b, 0x41, 0xc3, 0xe4, \ - 0xd0, 0x9e, 0x69, 0xd5, 0xeb, 0x38, 0x74, 0x70, 0x43, 0xdc, 0xd9, 0x50, 0xe4, 0x97, 0x6d, 0x73, 0xd6, \ - 0xfb, 0xc8, 0xa7, 0xfa, 0xb4, 0xc2, 0xc4, 0x9d, 0x5d, 0x0c, 0xd5, 0x9f, 0x79, 0xb3, 0x54, 0xc2, 0xb7, \ - 0x6c, 0x3d, 0x7d, 0xcb, 0x2d, 0xf8, 0xc4, 0xf3, 0x78, 0x5a, 0x33, 0x2a, 0xb8, 0x0c, 0x6d, 0x06, 0xfa, \ - 0xf2, 0x62, 0xd3, 0x42, 0xd0, 0xbd, 0xc8, 0x4a, 0xa5, 0x0d, 0x02, 0x81, 0x81, 0x00, 0xd4, 0xa9, 0x90, \ - 0x15, 0xde, 0xbf, 0x2c, 0xc4, 0x8d, 0x9d, 0xfb, 0xa1, 0xc2, 0xe4, 0x83, 0xe3, 0x79, 0x65, 0x22, 0xd3, \ - 0xb7, 0x49, 0x6c, 0x4d, 0x94, 0x1f, 0x22, 0xb1, 0x60, 0xe7, 0x3a, 0x00, 0xb1, 0x38, 0xa2, 0xab, 0x0f, \ - 0xb4, 0x6c, 0xaa, 0xe7, 0x9e, 0x34, 0xe3, 0x7c, 0x40, 0x78, 0x53, 0xb2, 0xf9, 0x23, 0xea, 0xa0, 0x9a, \ - 0xea, 0x60, 0xc8, 0x8f, 0xa6, 0xaf, 0xdf, 0x29, 0x09, 0x4b, 0x06, 0x1e, 0x31, 0xad, 0x17, 0xda, 0xd8, \ - 0xd1, 0xe9, 0x33, 0xab, 0x5b, 0x18, 0x08, 0x5b, 0x87, 0xf8, 0xa5, 0x1f, 0xfd, 0xbb, 0xdc, 0xd8, 0xed, \ - 0x97, 0x57, 0xe4, 0xc3, 0x73, 0xd6, 0xf0, 0x9e, 0x01, 0xa6, 0x9b, 0x48, 0x8e, 0x7a, 0xb4, 0xbb, 0xe5, \ - 0x88, 0x91, 0xc5, 0x2a, 0xdf, 0x4b, 0xba, 0xd0, 0x8b, 0x3e, 0x03, 0x97, 0x77, 0x2f, 0x47, 0x7e, 0x51, \ - 0x0c, 0xae, 0x65, 0x8d, 0xde, 0x87, 0x02, 0x81, 0x80, 0x20, 0x24, 0x0f, 0xd2, 0xaf, 0xc2, 0x28, 0x3b, \ - 0x97, 0x20, 0xb2, 0x92, 0x49, 0xeb, 0x09, 0x68, 0x40, 0xb2, 0xbe, 0xd1, 0xc3, 0x83, 0x94, 0x34, 0x38, \ - 0xd6, 0xc9, 0xec, 0x34, 0x09, 0xf9, 0x41, 0x6d, 0x5c, 0x42, 0x94, 0xf7, 0x04, 0xfc, 0x32, 0x39, 0x69, \ - 0xbc, 0x1c, 0xfb, 0x3e, 0x61, 0x98, 0xc0, 0x80, 0xd8, 0x36, 0x47, 0xc3, 0x6d, 0xc2, 0x2e, 0xe7, 0x81, \ - 0x2a, 0x17, 0x34, 0x64, 0x30, 0x4e, 0x96, 0xbb, 0x26, 0x16, 0xb9, 0x41, 0x36, 0xfe, 0x8a, 0xd6, 0x53, \ - 0x7c, 0xaa, 0xec, 0x39, 0x42, 0x50, 0xef, 0xe3, 0xb3, 0x01, 0x28, 0x32, 0xca, 0x6d, 0xf5, 0x9a, 0x1e, \ - 0x9f, 0x37, 0xbe, 0xfe, 0x38, 0x20, 0x22, 0x91, 0x8c, 0xcd, 0x95, 0x02, 0xf2, 0x4d, 0x6f, 0x1a, 0xb4, \ - 0x43, 0xf0, 0x19, 0xdf, 0x65, 0xc0, 0x92, 0xe7, 0x9d, 0x2f, 0x09, 0xe7, 0xec, 0x69, 0xa8, 0xc2, 0x8f, 0x0d \ + 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc0, 0xdf, 0x37, 0xfc, 0x17, 0xbb, 0xe0, 0x96, 0x9d, 0x3f, 0x86, \ + 0xde, 0x96, 0x32, 0x7d, 0x44, 0xa5, 0x16, 0xa0, 0xcd, 0x21, 0xf1, 0x99, 0xd4, 0xec, 0xea, 0xcb, 0x7c, 0x18, 0x58, 0x08, 0x94, 0xa5, \ + 0xec, 0x9b, 0xc5, 0x8b, 0xdf, 0x1a, 0x1e, 0x99, 0x38, 0x99, 0x87, 0x1e, 0x7b, 0xc0, 0x8d, 0x39, 0xdf, 0x38, 0x5d, 0x70, 0x78, 0x07, \ + 0xd3, 0x9e, 0xd9, 0x93, 0xe8, 0xb9, 0x72, 0x51, 0xc5, 0xce, 0xa3, 0x30, 0x52, 0xa9, 0xf2, 0xe7, 0x40, 0x70, 0x14, 0xcb, 0x44, 0xa2, \ + 0x72, 0x0b, 0xc2, 0xe5, 0x40, 0xf9, 0x3e, 0xe5, 0xa6, 0x0e, 0xb3, 0xf9, 0xec, 0x4a, 0x63, 0xc0, 0xb8, 0x29, 0x00, 0x74, 0x9c, 0x57, \ + 0x3b, 0xa8, 0xa5, 0x04, 0x90, 0x71, 0xf1, 0xbd, 0x83, 0xd9, 0x3f, 0xd6, 0xa5, 0xe2, 0x3c, 0x2a, 0x8f, 0xef, 0x27, 0x60, 0xc3, 0xc6, \ + 0x9f, 0xcb, 0xba, 0xec, 0x60, 0x7d, 0xb7, 0xe6, 0x84, 0x32, 0xbe, 0x4f, 0xfb, 0x58, 0x26, 0x22, 0x03, 0x5b, 0xd4, 0xb4, 0xd5, 0xfb, \ + 0xf5, 0xe3, 0x96, 0x2e, 0x70, 0xc0, 0xe4, 0x2e, 0xbd, 0xfc, 0x2e, 0xee, 0xe2, 0x41, 0x55, 0xc0, 0x34, 0x2e, 0x7d, 0x24, 0x72, 0x69, \ + 0xcb, 0x47, 0xb1, 0x14, 0x40, 0x83, 0x7d, 0x67, 0xf4, 0x86, 0xf6, 0x31, 0xab, 0xf1, 0x79, 0xa4, 0xb2, 0xb5, 0x2e, 0x12, 0xf9, 0x84, \ + 0x17, 0xf0, 0x62, 0x6f, 0x27, 0x3e, 0x13, 0x58, 0xb1, 0x54, 0x0d, 0x21, 0x9a, 0x73, 0x37, 0xa1, 0x30, 0xcf, 0x6f, 0x92, 0xdc, 0xf6, \ + 0xe9, 0xfc, 0xac, 0xdb, 0x2e, 0x28, 0xd1, 0x7e, 0x02, 0x4b, 0x23, 0xa0, 0x15, 0xf2, 0x38, 0x65, 0x64, 0x09, 0xea, 0x0c, 0x6e, 0x8e, \ + 0x1b, 0x17, 0xa0, 0x71, 0xc8, 0xb3, 0x9b, 0xc9, 0xab, 0xe9, 0xc3, 0xf2, 0xcf, 0x87, 0x96, 0x8f, 0x80, 0x02, 0x32, 0x9e, 0x99, 0x58, \ + 0x6f, 0xa2, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, 0x00, 0x3f, 0xf7, 0x07, 0xd3, 0x34, 0x6f, 0xdb, 0xc9, 0x37, 0xb7, \ + 0x84, 0xdc, 0x37, 0x45, 0xe1, 0x63, 0xad, 0xb8, 0xb6, 0x75, 0xb1, 0xc7, 0x35, 0xb4, 0x77, 0x2a, 0x5b, 0x77, 0xf9, 0x7e, 0xe0, 0xc1, \ + 0xa3, 0xd1, 0xb7, 0xcb, 0xa9, 0x5a, 0xc1, 0x87, 0xda, 0x5a, 0xfa, 0x17, 0xe4, 0xd5, 0x38, 0x03, 0xde, 0x68, 0x98, 0x81, 0xec, 0xb5, \ + 0xf2, 0x2a, 0x8d, 0xe9, 0x2c, 0xf3, 0xa6, 0xe5, 0x32, 0x17, 0x7f, 0x33, 0x81, 0xe8, 0x38, 0x72, 0xd5, 0x9c, 0xfa, 0x4e, 0xfb, 0x26, \ + 0xf5, 0x15, 0x0b, 0xaf, 0x84, 0x66, 0xab, 0x02, 0xe0, 0x18, 0xd5, 0x91, 0x7c, 0xd6, 0x8f, 0xc9, 0x4b, 0x76, 0x08, 0x2b, 0x1d, 0x81, \ + 0x68, 0x30, 0xe1, 0xfa, 0x70, 0x6c, 0x13, 0x4e, 0x10, 0x03, 0x35, 0x3e, 0xc5, 0xca, 0x58, 0x20, 0x8a, 0x21, 0x18, 0x38, 0xa0, 0x0f, \ + 0xed, 0xc4, 0xbb, 0x45, 0x6f, 0xf5, 0x84, 0x5b, 0xb0, 0xcf, 0x4e, 0x9d, 0x58, 0x13, 0x6b, 0x35, 0x35, 0x69, 0xa1, 0xd2, 0xc4, 0xf2, \ + 0xc1, 0x48, 0x04, 0x20, 0x51, 0xb9, 0x6b, 0xa4, 0x5d, 0xa5, 0x4b, 0x84, 0x88, 0x43, 0x48, 0x99, 0x2c, 0xbb, 0xa4, 0x97, 0xd6, 0xd6, \ + 0x18, 0xf6, 0xec, 0x5c, 0xd1, 0x31, 0x49, 0xc9, 0xf2, 0x8f, 0x0b, 0x4d, 0xef, 0x09, 0x02, 0xfe, 0x7d, 0xfd, 0xbb, 0xaf, 0x2b, 0x83, \ + 0x94, 0x22, 0xc4, 0xa7, 0x3e, 0x66, 0xf5, 0xe0, 0x57, 0xdc, 0xf2, 0xed, 0x2c, 0x3e, 0x81, 0x74, 0x76, 0x1e, 0x96, 0x6f, 0x74, 0x1e, \ + 0x32, 0x0e, 0x14, 0x31, 0xd0, 0x74, 0xf0, 0xf4, 0x07, 0xbd, 0xc3, 0xd1, 0x22, 0xc2, 0xa8, 0x95, 0x92, 0x06, 0x7f, 0x43, 0x02, 0x91, \ + 0xbc, 0xdd, 0x23, 0x01, 0x89, 0x94, 0x20, 0x44, 0x64, 0xf5, 0x1d, 0x67, 0xd2, 0x8f, 0xe8, 0x69, 0xa5, 0x29, 0x25, 0xe6, 0x50, 0x9c, \ + 0xe3, 0xe9, 0xcb, 0x75, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x29, 0x3e, 0xaa, 0x6b, 0xd5, 0x59, 0x1e, 0x9c, 0xe6, 0x47, 0xd5, 0xb6, 0xd7, \ + 0xe3, 0xf1, 0x8e, 0x9e, 0xe9, 0x83, 0x5f, 0x10, 0x9f, 0x63, 0xec, 0x04, 0x44, 0xcc, 0x3f, 0xf8, 0xd9, 0x3a, 0x17, 0xe0, 0x4f, 0xfe, \ + 0xd8, 0x4d, 0xcd, 0x46, 0x54, 0x74, 0xbf, 0x0a, 0xc4, 0x67, 0x9c, 0xa7, 0xd8, 0x89, 0x65, 0x4c, 0xfd, 0x58, 0x2a, 0x47, 0x0f, 0xf4, \ + 0x37, 0xb6, 0x55, 0xb0, 0x1d, 0xed, 0xa7, 0x39, 0xfc, 0x4f, 0xa3, 0xc4, 0x75, 0x3a, 0xa3, 0x98, 0xa7, 0x45, 0xf5, 0x66, 0xcb, 0x7c, \ + 0x65, 0xfb, 0x80, 0x23, 0xe6, 0xff, 0xfd, 0x99, 0x1f, 0x8e, 0x6b, 0xff, 0x5e, 0x93, 0x66, 0xdf, 0x6c, 0x6f, 0xc3, 0xf6, 0x38, 0x2e, \ + 0xff, 0x69, 0xb5, 0xac, 0xae, 0xbb, 0xc6, 0x71, 0x16, 0x6b, 0xd0, 0xf8, 0x22, 0xd9, 0xf8, 0xa2, 0x72, 0x20, 0xd2, 0xe2, 0x3a, 0x70, \ + 0x4b, 0xde, 0xab, 0x2f, 0x02, 0x81, 0x81, 0x00, 0xda, 0x51, 0x9b, 0xb8, 0xb2, 0x2a, 0x14, 0x75, 0x58, 0x40, 0x8d, 0x27, 0x70, 0xfa, \ + 0x31, 0x48, 0xb0, 0x20, 0x21, 0x34, 0xfa, 0x4c, 0x57, 0xa8, 0x11, 0x88, 0xf3, 0xa7, 0xae, 0x21, 0xe9, 0xb6, 0x2b, 0xd1, 0xcd, 0xa7, \ + 0xf8, 0xd8, 0x0c, 0x8a, 0x76, 0x22, 0x35, 0x44, 0xce, 0x3f, 0x25, 0x29, 0x83, 0x7d, 0x79, 0xa7, 0x31, 0xd6, 0xec, 0xb2, 0xbf, 0xda, \ + 0x34, 0xb6, 0xf6, 0xb2, 0x3b, 0xf3, 0x78, 0x5a, 0x04, 0x83, 0x33, 0x3e, 0xa2, 0xe2, 0x81, 0x82, 0x13, 0xd4, 0x35, 0x17, 0x63, 0x9b, \ + 0x9e, 0xc4, 0x8d, 0x91, 0x4c, 0x03, 0x77, 0xc7, 0x71, 0x5b, 0xee, 0x83, 0x6d, 0xd5, 0x78, 0x88, 0xf6, 0x2c, 0x79, 0xc2, 0x4a, 0xb4, \ + 0x79, 0x90, 0x70, 0xbf, 0xdf, 0x34, 0x56, 0x96, 0x71, 0xe3, 0x0e, 0x68, 0x91, 0xbc, 0xea, 0xcb, 0x33, 0xc0, 0xbe, 0x45, 0xd7, 0xfc, \ + 0x30, 0xfd, 0x01, 0x3b, 0x02, 0x81, 0x81, 0x00, 0xd2, 0x9f, 0x2a, 0xb7, 0x38, 0x19, 0xc7, 0x17, 0x95, 0x73, 0x78, 0xae, 0xf5, 0xcb, \ + 0x75, 0x83, 0x7f, 0x19, 0x4b, 0xcb, 0x86, 0xfb, 0x4a, 0x15, 0x9a, 0xb6, 0x17, 0x04, 0x49, 0x07, 0x8d, 0xf6, 0x66, 0x4a, 0x06, 0xf6, \ + 0x05, 0xa7, 0xdf, 0x66, 0x82, 0x3c, 0xff, 0xb6, 0x1d, 0x57, 0x89, 0x33, 0x5f, 0x9c, 0x05, 0x75, 0x7f, 0xf3, 0x5d, 0xdc, 0x34, 0x65, \ + 0x72, 0x85, 0x22, 0xa4, 0x14, 0x1b, 0x41, 0xc3, 0xe4, 0xd0, 0x9e, 0x69, 0xd5, 0xeb, 0x38, 0x74, 0x70, 0x43, 0xdc, 0xd9, 0x50, 0xe4, \ + 0x97, 0x6d, 0x73, 0xd6, 0xfb, 0xc8, 0xa7, 0xfa, 0xb4, 0xc2, 0xc4, 0x9d, 0x5d, 0x0c, 0xd5, 0x9f, 0x79, 0xb3, 0x54, 0xc2, 0xb7, 0x6c, \ + 0x3d, 0x7d, 0xcb, 0x2d, 0xf8, 0xc4, 0xf3, 0x78, 0x5a, 0x33, 0x2a, 0xb8, 0x0c, 0x6d, 0x06, 0xfa, 0xf2, 0x62, 0xd3, 0x42, 0xd0, 0xbd, \ + 0xc8, 0x4a, 0xa5, 0x0d, 0x02, 0x81, 0x81, 0x00, 0xd4, 0xa9, 0x90, 0x15, 0xde, 0xbf, 0x2c, 0xc4, 0x8d, 0x9d, 0xfb, 0xa1, 0xc2, 0xe4, \ + 0x83, 0xe3, 0x79, 0x65, 0x22, 0xd3, 0xb7, 0x49, 0x6c, 0x4d, 0x94, 0x1f, 0x22, 0xb1, 0x60, 0xe7, 0x3a, 0x00, 0xb1, 0x38, 0xa2, 0xab, \ + 0x0f, 0xb4, 0x6c, 0xaa, 0xe7, 0x9e, 0x34, 0xe3, 0x7c, 0x40, 0x78, 0x53, 0xb2, 0xf9, 0x23, 0xea, 0xa0, 0x9a, 0xea, 0x60, 0xc8, 0x8f, \ + 0xa6, 0xaf, 0xdf, 0x29, 0x09, 0x4b, 0x06, 0x1e, 0x31, 0xad, 0x17, 0xda, 0xd8, 0xd1, 0xe9, 0x33, 0xab, 0x5b, 0x18, 0x08, 0x5b, 0x87, \ + 0xf8, 0xa5, 0x1f, 0xfd, 0xbb, 0xdc, 0xd8, 0xed, 0x97, 0x57, 0xe4, 0xc3, 0x73, 0xd6, 0xf0, 0x9e, 0x01, 0xa6, 0x9b, 0x48, 0x8e, 0x7a, \ + 0xb4, 0xbb, 0xe5, 0x88, 0x91, 0xc5, 0x2a, 0xdf, 0x4b, 0xba, 0xd0, 0x8b, 0x3e, 0x03, 0x97, 0x77, 0x2f, 0x47, 0x7e, 0x51, 0x0c, 0xae, \ + 0x65, 0x8d, 0xde, 0x87, 0x02, 0x81, 0x80, 0x20, 0x24, 0x0f, 0xd2, 0xaf, 0xc2, 0x28, 0x3b, 0x97, 0x20, 0xb2, 0x92, 0x49, 0xeb, 0x09, \ + 0x68, 0x40, 0xb2, 0xbe, 0xd1, 0xc3, 0x83, 0x94, 0x34, 0x38, 0xd6, 0xc9, 0xec, 0x34, 0x09, 0xf9, 0x41, 0x6d, 0x5c, 0x42, 0x94, 0xf7, \ + 0x04, 0xfc, 0x32, 0x39, 0x69, 0xbc, 0x1c, 0xfb, 0x3e, 0x61, 0x98, 0xc0, 0x80, 0xd8, 0x36, 0x47, 0xc3, 0x6d, 0xc2, 0x2e, 0xe7, 0x81, \ + 0x2a, 0x17, 0x34, 0x64, 0x30, 0x4e, 0x96, 0xbb, 0x26, 0x16, 0xb9, 0x41, 0x36, 0xfe, 0x8a, 0xd6, 0x53, 0x7c, 0xaa, 0xec, 0x39, 0x42, \ + 0x50, 0xef, 0xe3, 0xb3, 0x01, 0x28, 0x32, 0xca, 0x6d, 0xf5, 0x9a, 0x1e, 0x9f, 0x37, 0xbe, 0xfe, 0x38, 0x20, 0x22, 0x91, 0x8c, 0xcd, \ + 0x95, 0x02, 0xf2, 0x4d, 0x6f, 0x1a, 0xb4, 0x43, 0xf0, 0x19, 0xdf, 0x65, 0xc0, 0x92, 0xe7, 0x9d, 0x2f, 0x09, 0xe7, 0xec, 0x69, 0xa8, \ + 0xc2, 0x8f, 0x0d \ } /* END FILE */ @@ -471,39 +423,31 @@ /* BEGIN FILE binary macro TEST_SRV_CRT_EC_DER tests/data_files/server5.crt.der */ #define TEST_SRV_CRT_EC_DER \ { \ - 0x30, 0x82, 0x02, 0x1f, 0x30, 0x82, 0x01, 0xa5, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x09, 0x30, 0x0a, \ - 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, \ - 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, \ - 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, \ - 0x04, 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, \ - 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x33, 0x30, 0x39, 0x32, 0x34, 0x31, \ - 0x35, 0x35, 0x32, 0x30, 0x34, 0x5a, 0x17, 0x0d, 0x32, 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x35, \ - 0x32, 0x30, 0x34, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, \ - 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, \ - 0x72, 0x53, 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x6c, 0x6f, \ - 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, \ - 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, \ - 0x37, 0xcc, 0x56, 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, 0x59, 0x2d, 0xff, 0x20, 0x6e, 0xee, \ - 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, 0xad, 0x14, 0xb5, 0xf7, 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, \ - 0x00, 0xd8, 0x23, 0x11, 0xff, 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, 0x8a, 0x88, 0xc2, 0x6b, \ - 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, 0x01, 0xc8, 0xb4, 0xed, 0xff, 0xa3, 0x81, 0x9d, 0x30, \ - 0x81, 0x9a, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, \ - 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x50, 0x61, 0xa5, 0x8f, 0xd4, 0x07, 0xd9, 0xd7, 0x82, 0x01, \ - 0x0c, 0xe5, 0x65, 0x7f, 0x8c, 0x63, 0x46, 0xa7, 0x13, 0xbe, 0x30, 0x6e, 0x06, 0x03, 0x55, 0x1d, 0x23, \ - 0x04, 0x67, 0x30, 0x65, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, \ - 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0xa1, 0x42, 0xa4, 0x40, 0x30, 0x3e, 0x31, 0x0b, \ - 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ - 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, \ - 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, \ - 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, 0x09, 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, \ - 0x43, 0xcc, 0xe8, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x68, \ - 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0x9a, 0x2c, 0x5c, 0xd7, 0xa6, 0xdb, 0xa2, 0xe5, 0x64, 0x0d, 0xf0, \ - 0xb9, 0x4e, 0xdd, 0xd7, 0x61, 0xd6, 0x13, 0x31, 0xc7, 0xab, 0x73, 0x80, 0xbb, 0xd3, 0xd3, 0x73, 0x13, \ - 0x54, 0xad, 0x92, 0x0b, 0x5d, 0xab, 0xd0, 0xbc, 0xf7, 0xae, 0x2f, 0xe6, 0xa1, 0x21, 0x29, 0x35, 0x95, \ - 0xaa, 0x3e, 0x39, 0x02, 0x30, 0x21, 0x36, 0x7f, 0x9d, 0xc6, 0x5d, 0xc6, 0x0b, 0xab, 0x27, 0xf2, 0x25, \ - 0x1d, 0x3b, 0xf1, 0xcf, 0xf1, 0x35, 0x25, 0x14, 0xe7, 0xe5, 0xf1, 0x97, 0xb5, 0x59, 0xe3, 0x5e, 0x15, \ - 0x7c, 0x66, 0xb9, 0x90, 0x7b, 0xc7, 0x01, 0x10, 0x4f, 0x73, 0xc6, 0x00, 0x21, 0x52, 0x2a, 0x0e, 0xf1, \ - 0xc7, 0xd5 \ + 0x30, 0x82, 0x02, 0x1f, 0x30, 0x82, 0x01, 0xa5, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x09, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, \ + 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, \ + 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, \ + 0x03, 0x55, 0x04, 0x03, 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, \ + 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x33, 0x30, 0x39, 0x32, 0x34, 0x31, 0x35, 0x35, 0x32, 0x30, 0x34, 0x5a, 0x17, 0x0d, \ + 0x32, 0x33, 0x30, 0x39, 0x32, 0x32, 0x31, 0x35, 0x35, 0x32, 0x30, 0x34, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, \ + 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, \ + 0x53, 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, \ + 0x74, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, \ + 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x37, 0xcc, 0x56, 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, 0x59, 0x2d, 0xff, 0x20, 0x6e, \ + 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, 0xad, 0x14, 0xb5, 0xf7, 0x68, 0x22, 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, 0xd8, 0x23, 0x11, \ + 0xff, 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, 0x8a, 0x88, 0xc2, 0x6b, 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, 0x01, \ + 0xc8, 0xb4, 0xed, 0xff, 0xa3, 0x81, 0x9d, 0x30, 0x81, 0x9a, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, \ + 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x50, 0x61, 0xa5, 0x8f, 0xd4, 0x07, 0xd9, 0xd7, 0x82, 0x01, 0x0c, 0xe5, \ + 0x65, 0x7f, 0x8c, 0x63, 0x46, 0xa7, 0x13, 0xbe, 0x30, 0x6e, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x67, 0x30, 0x65, 0x80, 0x14, 0x9d, \ + 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0xa1, 0x42, 0xa4, \ + 0x40, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ + 0x55, 0x04, 0x0a, 0x13, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, \ + 0x13, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x73, 0x73, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x82, \ + 0x09, 0x00, 0xc1, 0x43, 0xe2, 0x7e, 0x62, 0x43, 0xcc, 0xe8, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, \ + 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0x9a, 0x2c, 0x5c, 0xd7, 0xa6, 0xdb, 0xa2, 0xe5, 0x64, 0x0d, 0xf0, 0xb9, 0x4e, 0xdd, \ + 0xd7, 0x61, 0xd6, 0x13, 0x31, 0xc7, 0xab, 0x73, 0x80, 0xbb, 0xd3, 0xd3, 0x73, 0x13, 0x54, 0xad, 0x92, 0x0b, 0x5d, 0xab, 0xd0, 0xbc, \ + 0xf7, 0xae, 0x2f, 0xe6, 0xa1, 0x21, 0x29, 0x35, 0x95, 0xaa, 0x3e, 0x39, 0x02, 0x30, 0x21, 0x36, 0x7f, 0x9d, 0xc6, 0x5d, 0xc6, 0x0b, \ + 0xab, 0x27, 0xf2, 0x25, 0x1d, 0x3b, 0xf1, 0xcf, 0xf1, 0x35, 0x25, 0x14, 0xe7, 0xe5, 0xf1, 0x97, 0xb5, 0x59, 0xe3, 0x5e, 0x15, 0x7c, \ + 0x66, 0xb9, 0x90, 0x7b, 0xc7, 0x01, 0x10, 0x4f, 0x73, 0xc6, 0x00, 0x21, 0x52, 0x2a, 0x0e, 0xf1, 0xc7, 0xd5 \ } /* END FILE */ @@ -521,13 +465,12 @@ /* BEGIN FILE binary macro TEST_SRV_KEY_EC_DER tests/data_files/server5.key.der */ #define TEST_SRV_KEY_EC_DER \ { \ - 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf1, 0x2a, 0x13, 0x20, 0x76, 0x02, 0x70, 0xa8, 0x3c, 0xbf, 0xfd, \ - 0x53, 0xf6, 0x03, 0x1e, 0xf7, 0x6a, 0x5d, 0x86, 0xc8, 0xa2, 0x04, 0xf2, 0xc3, 0x0c, 0xa9, 0xeb, 0xf5, \ - 0x1f, 0x0f, 0x0e, 0xa7, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0xa1, \ - 0x44, 0x03, 0x42, 0x00, 0x04, 0x37, 0xcc, 0x56, 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, 0xc7, 0x59, \ - 0x2d, 0xff, 0x20, 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, 0xad, 0x14, 0xb5, 0xf7, 0x68, 0x22, \ - 0x59, 0x62, 0x92, 0x4e, 0xe5, 0x00, 0xd8, 0x23, 0x11, 0xff, 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, \ - 0xbd, 0x8a, 0x88, 0xc2, 0x6b, 0x77, 0x0d, 0x55, 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, 0x01, 0xc8, 0xb4, 0xed, 0xff \ + 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf1, 0x2a, 0x13, 0x20, 0x76, 0x02, 0x70, 0xa8, 0x3c, 0xbf, 0xfd, 0x53, 0xf6, 0x03, 0x1e, 0xf7, \ + 0x6a, 0x5d, 0x86, 0xc8, 0xa2, 0x04, 0xf2, 0xc3, 0x0c, 0xa9, 0xeb, 0xf5, 0x1f, 0x0f, 0x0e, 0xa7, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, \ + 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x37, 0xcc, 0x56, 0xd9, 0x76, 0x09, 0x1e, 0x5a, 0x72, 0x3e, \ + 0xc7, 0x59, 0x2d, 0xff, 0x20, 0x6e, 0xee, 0x7c, 0xf9, 0x06, 0x91, 0x74, 0xd0, 0xad, 0x14, 0xb5, 0xf7, 0x68, 0x22, 0x59, 0x62, 0x92, \ + 0x4e, 0xe5, 0x00, 0xd8, 0x23, 0x11, 0xff, 0xea, 0x2f, 0xd2, 0x34, 0x5d, 0x5d, 0x16, 0xbd, 0x8a, 0x88, 0xc2, 0x6b, 0x77, 0x0d, 0x55, \ + 0xcd, 0x8a, 0x2a, 0x0e, 0xfa, 0x01, 0xc8, 0xb4, 0xed, 0xff \ } /* END FILE */ @@ -560,55 +503,44 @@ /* BEGIN FILE binary macro TEST_SRV_CRT_RSA_SHA256_DER tests/data_files/server2-sha256.crt.der */ #define TEST_SRV_CRT_RSA_SHA256_DER \ { \ - 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, \ - 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, \ - 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ - 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, \ - 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, \ - 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \ - 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \ - 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, \ - 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \ - 0x72, 0x53, 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x6c, 0x6f, \ - 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, \ - 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, \ - 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, \ - 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, \ - 0xcd, 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, \ - 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, \ - 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, 0x36, 0xd4, \ - 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, \ - 0xab, 0x74, 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \ - 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, \ - 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, \ - 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, \ - 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, \ - 0xc6, 0x62, 0x2f, 0xc7, 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, \ - 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, \ - 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, \ - 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, \ - 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, \ - 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \ - 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, \ - 0xa8, 0x64, 0xaf, 0x4d, 0x8b, 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \ - 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, \ - 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, \ - 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x2e, 0x3a, 0xe4, 0x52, 0x61, 0x3e, 0xa7, 0xa5, \ - 0xef, 0x32, 0x67, 0x80, 0x72, 0x07, 0x26, 0xba, 0xa3, 0xff, 0x05, 0x40, 0xc4, 0x60, 0x05, 0x39, 0x31, \ - 0x77, 0xf7, 0xa5, 0xca, 0x01, 0x31, 0x80, 0xa7, 0xe1, 0xd1, 0x0a, 0xa2, 0x7c, 0xd5, 0x1c, 0xba, 0xd0, \ - 0x23, 0x4a, 0xd6, 0x30, 0xf3, 0x93, 0xc7, 0x6f, 0xe8, 0xce, 0x94, 0x1e, 0x84, 0xbb, 0x44, 0x81, 0x62, \ - 0x33, 0xff, 0x6b, 0x5d, 0x00, 0x9b, 0x25, 0xf8, 0x8f, 0x0f, 0x9c, 0x4c, 0x4d, 0xe8, 0xd9, 0xa7, 0x99, \ - 0xf9, 0x51, 0x81, 0xc0, 0x9b, 0x1b, 0x31, 0x0d, 0xa6, 0xb3, 0x7c, 0x0e, 0x45, 0xb8, 0x18, 0x64, 0x7e, \ - 0x89, 0x0a, 0x2b, 0xa8, 0xc3, 0xe0, 0x4a, 0xbd, 0xd4, 0x2f, 0x78, 0xc4, 0x62, 0x9b, 0xe9, 0x7e, 0x3f, \ - 0x56, 0x46, 0x8f, 0x17, 0xb7, 0x2a, 0xa0, 0x10, 0x70, 0xfd, 0xb1, 0xf1, 0x6b, 0x05, 0xdc, 0xd1, 0x41, \ - 0x0f, 0x8e, 0xa6, 0xb2, 0x88, 0x1a, 0x42, 0x61, 0x4f, 0xeb, 0x26, 0x85, 0x59, 0x80, 0xba, 0x85, 0x54, \ - 0xfe, 0xcf, 0xc7, 0x7b, 0x2f, 0x6b, 0x59, 0xce, 0xac, 0xdc, 0x7c, 0xac, 0xf3, 0xc8, 0xd6, 0x12, 0x7e, \ - 0x64, 0xe8, 0x3c, 0x99, 0xa8, 0x8f, 0x4f, 0x11, 0xd9, 0x9c, 0x15, 0x4b, 0x6a, 0x44, 0x92, 0x2d, 0x0c, \ - 0xbf, 0xb1, 0x67, 0x96, 0xc9, 0xac, 0xce, 0xd5, 0x19, 0xeb, 0x6f, 0x18, 0xeb, 0x6e, 0x04, 0x2d, 0x60, \ - 0xac, 0xf4, 0x7b, 0x79, 0xf0, 0x1a, 0x9b, 0xb5, 0xc3, 0x5d, 0xef, 0x7d, 0xc9, 0x05, 0x99, 0x44, 0x81, \ - 0x84, 0x75, 0xc7, 0xec, 0x00, 0x12, 0xfc, 0x7a, 0x4a, 0x0b, 0x82, 0x07, 0xec, 0x6d, 0x86, 0x02, 0x4d, \ - 0xfe, 0x9f, 0xc8, 0x92, 0x48, 0xde, 0xf5, 0xb1, 0x9c, 0xe9, 0xc6, 0x89, 0xd0, 0xc1, 0x56, 0xe8, 0xa4, \ - 0xc6, 0x6a, 0x2e, 0x66, 0xc1, 0x9b, 0xfe, 0xd6, 0x3c, 0xb7 \ + 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, \ + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, \ + 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, \ + 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, \ + 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x17, 0x0d, \ + 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, \ + 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, \ + 0x53, 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, \ + 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, \ + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, \ + 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, 0xa3, 0x00, 0x88, \ + 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, \ + 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, \ + 0xb3, 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, \ + 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, \ + 0x0b, 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, \ + 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, \ + 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, 0x66, \ + 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, \ + 0xde, 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, \ + 0x4b, 0x52, 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, \ + 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, \ + 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, 0xdf, 0x60, 0x0f, \ + 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, \ + 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \ + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x2e, 0x3a, \ + 0xe4, 0x52, 0x61, 0x3e, 0xa7, 0xa5, 0xef, 0x32, 0x67, 0x80, 0x72, 0x07, 0x26, 0xba, 0xa3, 0xff, 0x05, 0x40, 0xc4, 0x60, 0x05, 0x39, \ + 0x31, 0x77, 0xf7, 0xa5, 0xca, 0x01, 0x31, 0x80, 0xa7, 0xe1, 0xd1, 0x0a, 0xa2, 0x7c, 0xd5, 0x1c, 0xba, 0xd0, 0x23, 0x4a, 0xd6, 0x30, \ + 0xf3, 0x93, 0xc7, 0x6f, 0xe8, 0xce, 0x94, 0x1e, 0x84, 0xbb, 0x44, 0x81, 0x62, 0x33, 0xff, 0x6b, 0x5d, 0x00, 0x9b, 0x25, 0xf8, 0x8f, \ + 0x0f, 0x9c, 0x4c, 0x4d, 0xe8, 0xd9, 0xa7, 0x99, 0xf9, 0x51, 0x81, 0xc0, 0x9b, 0x1b, 0x31, 0x0d, 0xa6, 0xb3, 0x7c, 0x0e, 0x45, 0xb8, \ + 0x18, 0x64, 0x7e, 0x89, 0x0a, 0x2b, 0xa8, 0xc3, 0xe0, 0x4a, 0xbd, 0xd4, 0x2f, 0x78, 0xc4, 0x62, 0x9b, 0xe9, 0x7e, 0x3f, 0x56, 0x46, \ + 0x8f, 0x17, 0xb7, 0x2a, 0xa0, 0x10, 0x70, 0xfd, 0xb1, 0xf1, 0x6b, 0x05, 0xdc, 0xd1, 0x41, 0x0f, 0x8e, 0xa6, 0xb2, 0x88, 0x1a, 0x42, \ + 0x61, 0x4f, 0xeb, 0x26, 0x85, 0x59, 0x80, 0xba, 0x85, 0x54, 0xfe, 0xcf, 0xc7, 0x7b, 0x2f, 0x6b, 0x59, 0xce, 0xac, 0xdc, 0x7c, 0xac, \ + 0xf3, 0xc8, 0xd6, 0x12, 0x7e, 0x64, 0xe8, 0x3c, 0x99, 0xa8, 0x8f, 0x4f, 0x11, 0xd9, 0x9c, 0x15, 0x4b, 0x6a, 0x44, 0x92, 0x2d, 0x0c, \ + 0xbf, 0xb1, 0x67, 0x96, 0xc9, 0xac, 0xce, 0xd5, 0x19, 0xeb, 0x6f, 0x18, 0xeb, 0x6e, 0x04, 0x2d, 0x60, 0xac, 0xf4, 0x7b, 0x79, 0xf0, \ + 0x1a, 0x9b, 0xb5, 0xc3, 0x5d, 0xef, 0x7d, 0xc9, 0x05, 0x99, 0x44, 0x81, 0x84, 0x75, 0xc7, 0xec, 0x00, 0x12, 0xfc, 0x7a, 0x4a, 0x0b, \ + 0x82, 0x07, 0xec, 0x6d, 0x86, 0x02, 0x4d, 0xfe, 0x9f, 0xc8, 0x92, 0x48, 0xde, 0xf5, 0xb1, 0x9c, 0xe9, 0xc6, 0x89, 0xd0, 0xc1, 0x56, \ + 0xe8, 0xa4, 0xc6, 0x6a, 0x2e, 0x66, 0xc1, 0x9b, 0xfe, 0xd6, 0x3c, 0xb7 \ } /* END FILE */ @@ -641,55 +573,44 @@ /* BEGIN FILE binary macro TEST_SRV_CRT_RSA_SHA1_DER tests/data_files/server2.crt.der */ #define TEST_SRV_CRT_RSA_SHA1_DER \ { \ - 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, \ - 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, \ - 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ - 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, \ - 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, \ - 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \ - 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \ - 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, \ - 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \ - 0x72, 0x53, 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x6c, 0x6f, \ - 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, \ - 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, \ - 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, \ - 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, \ - 0xcd, 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, \ - 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, \ - 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, 0x36, 0xd4, \ - 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, \ - 0xab, 0x74, 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, \ - 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, \ - 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, 0x61, 0xc3, 0xcd, 0x40, \ - 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, \ - 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, \ - 0xc6, 0x62, 0x2f, 0xc7, 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, \ - 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, \ - 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, 0x52, \ - 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, \ - 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, \ - 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, \ - 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, 0xdf, 0x60, 0x0f, 0x50, 0x12, 0x4d, 0x60, \ - 0xa8, 0x64, 0xaf, 0x4d, 0x8b, 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, \ - 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, \ - 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, \ - 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x99, 0x25, 0x83, 0x74, 0x38, 0x70, 0x1e, 0xef, \ - 0xec, 0x1c, 0xec, 0xc4, 0xcf, 0xef, 0x2f, 0x22, 0x9c, 0x70, 0xee, 0xa8, 0xa7, 0x4f, 0xe0, 0x67, 0x33, \ - 0x38, 0x82, 0x1b, 0x8b, 0xab, 0x66, 0x37, 0xda, 0x49, 0x74, 0xb0, 0xce, 0xa4, 0x48, 0xd5, 0x14, 0x99, \ - 0xdb, 0xae, 0xab, 0x7b, 0xbf, 0xf8, 0x69, 0x94, 0x64, 0xdd, 0x80, 0x3b, 0xfe, 0xdc, 0xf8, 0x7c, 0x3b, \ - 0x84, 0x31, 0x44, 0x22, 0xf6, 0x64, 0xf7, 0xc6, 0x81, 0x1a, 0x30, 0x8b, 0xaa, 0x7d, 0xc3, 0x9a, 0x01, \ - 0xc8, 0xbf, 0xc4, 0xe8, 0x43, 0xae, 0xe7, 0x7a, 0x59, 0x50, 0xc7, 0x1d, 0x94, 0x8f, 0x7d, 0x3d, 0x3d, \ - 0xd8, 0x23, 0x36, 0x2f, 0xeb, 0xf4, 0x73, 0x9c, 0x28, 0xd0, 0x18, 0x3d, 0xb0, 0x5c, 0x83, 0xa3, 0x09, \ - 0x19, 0x65, 0xa3, 0xd9, 0x32, 0x3a, 0xbc, 0xd6, 0x9c, 0x7a, 0x2a, 0x2c, 0xfc, 0x38, 0x4e, 0x63, 0x1e, \ - 0x55, 0xd2, 0x3e, 0x67, 0x7e, 0xa4, 0x89, 0xfe, 0x99, 0xd4, 0xd2, 0x0f, 0x48, 0x82, 0x7d, 0x8b, 0x02, \ - 0x18, 0x18, 0xa4, 0x62, 0x44, 0x88, 0x43, 0x3d, 0xc1, 0x6e, 0xe1, 0x10, 0xc9, 0x30, 0x9a, 0x4d, 0x21, \ - 0xfe, 0xca, 0x99, 0xb2, 0xb2, 0x6c, 0x18, 0x7e, 0x58, 0xb0, 0x5f, 0xd5, 0x4e, 0x14, 0xaa, 0xfc, 0x95, \ - 0x4e, 0xd5, 0xed, 0xa6, 0x64, 0x7d, 0xaf, 0xae, 0xec, 0x99, 0x28, 0x95, 0x41, 0xab, 0xef, 0x2d, 0x0c, \ - 0xd6, 0x29, 0x1e, 0x42, 0xba, 0xb5, 0x2c, 0x95, 0x61, 0x08, 0x73, 0x22, 0xdd, 0xd2, 0xb4, 0xc2, 0x56, \ - 0x28, 0xc9, 0x7f, 0xa3, 0x99, 0x36, 0x01, 0x8c, 0xfa, 0xb5, 0x20, 0xb5, 0xeb, 0x8f, 0xb5, 0xa0, 0x6f, \ - 0x8c, 0x2f, 0x72, 0xd6, 0x83, 0xc5, 0xeb, 0x18, 0xa6, 0xbd, 0xd4, 0x7e, 0x14, 0x38, 0xa6, 0xa9, 0x03, \ - 0x08, 0x24, 0xd3, 0xee, 0x26, 0xd1, 0x3d, 0xb9, 0x70, 0xdb \ + 0x30, 0x82, 0x03, 0x37, 0x30, 0x82, 0x02, 0x1f, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, \ + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, \ + 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, \ + 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, \ + 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x17, 0x0d, \ + 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x30, 0x34, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, \ + 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, \ + 0x53, 0x53, 0x4c, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, \ + 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, \ + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, \ + 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, 0xa3, 0x00, 0x88, \ + 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, \ + 0x77, 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, \ + 0xb3, 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, \ + 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, \ + 0x0b, 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, \ + 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, \ + 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, 0x66, \ + 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, \ + 0xde, 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, \ + 0x4b, 0x52, 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, \ + 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, \ + 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xa5, 0x05, 0xe8, 0x64, 0xb8, 0xdc, 0xdf, 0x60, 0x0f, \ + 0x50, 0x12, 0x4d, 0x60, 0xa8, 0x64, 0xaf, 0x4d, 0x8b, 0x43, 0x93, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, \ + 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, \ + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x99, 0x25, \ + 0x83, 0x74, 0x38, 0x70, 0x1e, 0xef, 0xec, 0x1c, 0xec, 0xc4, 0xcf, 0xef, 0x2f, 0x22, 0x9c, 0x70, 0xee, 0xa8, 0xa7, 0x4f, 0xe0, 0x67, \ + 0x33, 0x38, 0x82, 0x1b, 0x8b, 0xab, 0x66, 0x37, 0xda, 0x49, 0x74, 0xb0, 0xce, 0xa4, 0x48, 0xd5, 0x14, 0x99, 0xdb, 0xae, 0xab, 0x7b, \ + 0xbf, 0xf8, 0x69, 0x94, 0x64, 0xdd, 0x80, 0x3b, 0xfe, 0xdc, 0xf8, 0x7c, 0x3b, 0x84, 0x31, 0x44, 0x22, 0xf6, 0x64, 0xf7, 0xc6, 0x81, \ + 0x1a, 0x30, 0x8b, 0xaa, 0x7d, 0xc3, 0x9a, 0x01, 0xc8, 0xbf, 0xc4, 0xe8, 0x43, 0xae, 0xe7, 0x7a, 0x59, 0x50, 0xc7, 0x1d, 0x94, 0x8f, \ + 0x7d, 0x3d, 0x3d, 0xd8, 0x23, 0x36, 0x2f, 0xeb, 0xf4, 0x73, 0x9c, 0x28, 0xd0, 0x18, 0x3d, 0xb0, 0x5c, 0x83, 0xa3, 0x09, 0x19, 0x65, \ + 0xa3, 0xd9, 0x32, 0x3a, 0xbc, 0xd6, 0x9c, 0x7a, 0x2a, 0x2c, 0xfc, 0x38, 0x4e, 0x63, 0x1e, 0x55, 0xd2, 0x3e, 0x67, 0x7e, 0xa4, 0x89, \ + 0xfe, 0x99, 0xd4, 0xd2, 0x0f, 0x48, 0x82, 0x7d, 0x8b, 0x02, 0x18, 0x18, 0xa4, 0x62, 0x44, 0x88, 0x43, 0x3d, 0xc1, 0x6e, 0xe1, 0x10, \ + 0xc9, 0x30, 0x9a, 0x4d, 0x21, 0xfe, 0xca, 0x99, 0xb2, 0xb2, 0x6c, 0x18, 0x7e, 0x58, 0xb0, 0x5f, 0xd5, 0x4e, 0x14, 0xaa, 0xfc, 0x95, \ + 0x4e, 0xd5, 0xed, 0xa6, 0x64, 0x7d, 0xaf, 0xae, 0xec, 0x99, 0x28, 0x95, 0x41, 0xab, 0xef, 0x2d, 0x0c, 0xd6, 0x29, 0x1e, 0x42, 0xba, \ + 0xb5, 0x2c, 0x95, 0x61, 0x08, 0x73, 0x22, 0xdd, 0xd2, 0xb4, 0xc2, 0x56, 0x28, 0xc9, 0x7f, 0xa3, 0x99, 0x36, 0x01, 0x8c, 0xfa, 0xb5, \ + 0x20, 0xb5, 0xeb, 0x8f, 0xb5, 0xa0, 0x6f, 0x8c, 0x2f, 0x72, 0xd6, 0x83, 0xc5, 0xeb, 0x18, 0xa6, 0xbd, 0xd4, 0x7e, 0x14, 0x38, 0xa6, \ + 0xa9, 0x03, 0x08, 0x24, 0xd3, 0xee, 0x26, 0xd1, 0x3d, 0xb9, 0x70, 0xdb \ } /* END FILE */ @@ -729,76 +650,61 @@ /* BEGIN FILE binary macro TEST_SRV_KEY_RSA_DER tests/data_files/server2.key.der */ #define TEST_SRV_KEY_RSA_DER \ { \ - 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, \ - 0x1d, 0xd1, 0x04, 0xd7, 0x49, 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, \ - 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, 0xa3, 0x00, 0x88, 0xa7, 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, \ - 0x90, 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, 0x77, 0xe0, 0x26, \ - 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, \ - 0x04, 0x52, 0xb3, 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, \ - 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, \ - 0xd9, 0x0d, 0x1c, 0x2d, 0x49, 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, 0x8a, 0x4f, 0x69, 0x0c, \ - 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, \ - 0xe2, 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, \ - 0xb8, 0xaa, 0x11, 0x03, 0x1e, 0x7f, 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, \ - 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, 0x66, 0x8d, 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, \ - 0x89, 0x29, 0x01, 0xc5, 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, 0xc7, \ - 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, \ - 0x5b, 0xcb, 0x73, 0x4b, 0x52, 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, \ - 0xb0, 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, \ - 0x02, 0x82, 0x01, 0x01, 0x00, 0x97, 0x47, 0x44, 0xbc, 0x10, 0x81, 0xc5, 0x18, 0xe4, 0x59, 0xfb, 0xe0, \ - 0x2d, 0x3a, 0x0e, 0x9e, 0x10, 0xdc, 0x43, 0xfb, 0x15, 0x6c, 0xd1, 0xfd, 0x48, 0x78, 0x6c, 0xf9, 0xed, \ - 0x38, 0xe8, 0xdd, 0x09, 0xd7, 0x5f, 0xb5, 0x41, 0x64, 0xd7, 0x63, 0xfa, 0x9d, 0x44, 0x0a, 0xf8, 0x42, \ - 0x13, 0xf1, 0xbb, 0x5e, 0x79, 0x20, 0x53, 0x98, 0x4b, 0x65, 0x7f, 0x86, 0x67, 0x48, 0xe4, 0xcf, 0xfb, \ - 0x6a, 0x24, 0xe2, 0x34, 0xbd, 0x14, 0x9d, 0x2c, 0x16, 0xe2, 0xa4, 0x79, 0xd6, 0xa2, 0xec, 0x81, 0x43, \ - 0x87, 0xbf, 0x03, 0x5c, 0x88, 0x25, 0xd9, 0x41, 0xb6, 0xa5, 0xf1, 0x27, 0x52, 0x84, 0xfe, 0x2b, 0x6e, \ - 0x1d, 0x16, 0xcd, 0x73, 0x88, 0xf8, 0x90, 0xbf, 0x19, 0xfe, 0xbe, 0xa9, 0xbf, 0x09, 0xd3, 0x23, 0x43, \ - 0xd2, 0xc7, 0x61, 0x2a, 0xb3, 0x4e, 0x3c, 0x61, 0xd4, 0xbd, 0xd8, 0xb4, 0xfa, 0xa8, 0x0b, 0xf8, 0x7e, \ - 0x56, 0xcd, 0x0f, 0x13, 0x27, 0xda, 0xe6, 0x3b, 0xb3, 0x8c, 0x9c, 0x4b, 0x84, 0x3c, 0xc3, 0x52, 0x57, \ - 0x9c, 0x27, 0x9a, 0x02, 0x76, 0x26, 0x59, 0x82, 0x39, 0xc3, 0x13, 0xbe, 0x6e, 0xf4, 0x44, 0x2d, 0x1d, \ - 0x8c, 0x73, 0x3e, 0x43, 0x99, 0x59, 0xcb, 0xf2, 0x34, 0x72, 0x9a, 0x5e, 0xa5, 0xeb, 0x9f, 0x36, 0x6d, \ - 0x2b, 0xf9, 0xa2, 0xe7, 0xd1, 0x78, 0x52, 0x1b, 0xc8, 0xf6, 0x5b, 0x41, 0x69, 0x57, 0x81, 0x89, 0xe9, \ - 0xbb, 0xa1, 0xde, 0x19, 0x37, 0x3b, 0x13, 0x5c, 0xca, 0x61, 0x01, 0x86, 0xff, 0xdf, 0x83, 0x41, 0x49, \ - 0x7f, 0xd6, 0xf4, 0x2e, 0x08, 0xfa, 0x90, 0xc2, 0x7c, 0xb4, 0xb5, 0x0a, 0x17, 0xdb, 0x0e, 0x6d, 0x75, \ - 0x8a, 0x5d, 0x31, 0xd5, 0x66, 0xfb, 0x39, 0x0b, 0xb5, 0xb6, 0xa3, 0xcd, 0xd4, 0xef, 0x88, 0x92, 0x5a, \ - 0x4d, 0x6c, 0xcb, 0xea, 0x5b, 0x79, 0x02, 0x81, 0x81, 0x00, 0xdf, 0x3a, 0xf9, 0x25, 0x5e, 0x24, 0x37, \ - 0x26, 0x40, 0x97, 0x2f, 0xe0, 0x4a, 0xba, 0x52, 0x1b, 0x51, 0xaf, 0x84, 0x06, 0x32, 0x24, 0x0c, 0xcf, \ - 0x44, 0xa8, 0x77, 0xa7, 0xad, 0xb5, 0x8c, 0x58, 0xcc, 0xc8, 0x31, 0xb7, 0x0d, 0xbc, 0x08, 0x8a, 0xe0, \ - 0xa6, 0x8c, 0xc2, 0x73, 0xe5, 0x1a, 0x64, 0x92, 0xe8, 0xed, 0x4c, 0x6f, 0x0b, 0xa6, 0xa7, 0xf3, 0x9a, \ - 0xf5, 0x6f, 0x69, 0xca, 0x3c, 0x22, 0xd0, 0x15, 0xa8, 0x20, 0x27, 0x41, 0xf8, 0x43, 0x42, 0x7f, 0xb1, \ - 0x93, 0xa1, 0x04, 0x85, 0xda, 0xa0, 0x1c, 0xd6, 0xc6, 0xf7, 0x8a, 0x9e, 0xea, 0x5c, 0x78, 0xa7, 0x55, \ - 0xc4, 0x6b, 0x05, 0x8b, 0xc0, 0x83, 0xcb, 0xce, 0x83, 0x05, 0xf8, 0xb2, 0x16, 0x2b, 0xdf, 0x06, 0x3f, \ - 0xb8, 0xec, 0x16, 0xda, 0x43, 0x33, 0xc1, 0x8f, 0xb0, 0xb8, 0xac, 0xae, 0xd4, 0x94, 0xb8, 0xda, 0x6f, \ - 0x6a, 0xc3, 0x02, 0x81, 0x81, 0x00, 0xdd, 0xae, 0x00, 0xcd, 0xa0, 0x72, 0x1a, 0x05, 0x8a, 0xee, 0x2f, \ - 0xd4, 0x71, 0x4b, 0xf0, 0x3e, 0xe5, 0xc1, 0xe1, 0x29, 0x8b, 0xa6, 0x67, 0x30, 0x98, 0xe7, 0x12, 0xef, \ - 0xdd, 0x12, 0x01, 0x90, 0x24, 0x58, 0xf0, 0x76, 0x92, 0xe7, 0x3d, 0xbb, 0x23, 0xe1, 0xce, 0xf9, 0xa1, \ - 0xd4, 0x38, 0x1b, 0x3f, 0x20, 0xb3, 0x0f, 0x65, 0x6a, 0x8f, 0x55, 0x57, 0x36, 0xee, 0xb2, 0x84, 0x44, \ - 0xfc, 0x91, 0x88, 0xe1, 0xa4, 0xdd, 0x3b, 0x4a, 0x40, 0x4d, 0x7c, 0x86, 0xed, 0xe1, 0xb5, 0x42, 0xef, \ - 0xb9, 0x61, 0xcd, 0x58, 0x19, 0x77, 0x02, 0xae, 0x58, 0x80, 0xdb, 0x13, 0x3d, 0xc7, 0x1f, 0x9d, 0xed, \ - 0xff, 0xac, 0x98, 0xfc, 0xcd, 0xf9, 0x62, 0x04, 0x83, 0x91, 0x89, 0x0d, 0x86, 0x43, 0x8c, 0x0c, 0xc7, \ - 0x1b, 0x90, 0x4d, 0xbe, 0x2f, 0xc5, 0x7c, 0xcd, 0x42, 0xf5, 0xd3, 0xad, 0x8e, 0xfd, 0x9d, 0x02, 0x81, \ - 0x80, 0x17, 0x4b, 0x79, 0x2a, 0x6c, 0x1b, 0x8d, 0x61, 0xc1, 0x85, 0xc5, 0x6a, 0x3b, 0x82, 0x1c, 0x05, \ - 0x5b, 0xcd, 0xdc, 0x12, 0x25, 0x73, 0x5b, 0x9e, 0xd9, 0x84, 0x57, 0x10, 0x39, 0x71, 0x63, 0x96, 0xf4, \ - 0xaf, 0xc3, 0x78, 0x5d, 0xc7, 0x8c, 0x80, 0xa9, 0x96, 0xd7, 0xc3, 0x87, 0x02, 0x96, 0x71, 0x7e, 0x5f, \ - 0x2e, 0x3c, 0x36, 0xae, 0x59, 0x92, 0xd7, 0x3a, 0x09, 0x78, 0xb9, 0xea, 0x6f, 0xc2, 0x16, 0x42, 0xdc, \ - 0x4b, 0x96, 0xad, 0x2c, 0xb2, 0x20, 0x23, 0x61, 0x2d, 0x8d, 0xb5, 0x02, 0x1e, 0xe1, 0x6c, 0x81, 0x01, \ - 0x3c, 0x5d, 0xcb, 0xdd, 0x9b, 0x0e, 0xc0, 0x2f, 0x94, 0x12, 0xb2, 0xfe, 0x75, 0x75, 0x8b, 0x74, 0x1e, \ - 0x7a, 0x26, 0x0c, 0xb7, 0x81, 0x96, 0x81, 0x79, 0x6e, 0xdb, 0xbc, 0x3a, 0xc4, 0x9e, 0x87, 0x09, 0x6e, \ - 0xa0, 0xa6, 0xec, 0x8b, 0xa4, 0x85, 0x71, 0xce, 0x04, 0xaf, 0x02, 0x81, 0x81, 0x00, 0xc2, 0xa7, 0x47, \ - 0x07, 0x48, 0x6a, 0xc8, 0xd4, 0xb3, 0x20, 0xe1, 0x98, 0xee, 0xff, 0x5a, 0x6f, 0x30, 0x7a, 0xa5, 0x47, \ - 0x40, 0xdc, 0x16, 0x62, 0x42, 0xf1, 0x2c, 0xdc, 0xb8, 0xc7, 0x55, 0xde, 0x07, 0x3c, 0x9d, 0xb1, 0xd0, \ - 0xdf, 0x02, 0x82, 0xb0, 0x48, 0x58, 0xe1, 0x34, 0xab, 0xcf, 0xb4, 0x85, 0x23, 0x26, 0x78, 0x4f, 0x7a, \ - 0x59, 0x6f, 0xfb, 0x8c, 0x3d, 0xdf, 0x3d, 0x6c, 0x02, 0x47, 0x9c, 0xe5, 0x5e, 0x49, 0xf1, 0x05, 0x0b, \ - 0x1f, 0xbf, 0x48, 0x0f, 0xdc, 0x10, 0xb9, 0x3d, 0x1d, 0x10, 0x77, 0x2a, 0x73, 0xf9, 0xdf, 0xbd, 0xcd, \ - 0xf3, 0x1f, 0xeb, 0x6e, 0x64, 0xca, 0x2b, 0x78, 0x4f, 0xf8, 0x73, 0xc2, 0x10, 0xef, 0x79, 0x95, 0x33, \ - 0x1e, 0x79, 0x35, 0x09, 0xff, 0x88, 0x1b, 0xb4, 0x3e, 0x4c, 0xe1, 0x27, 0x2e, 0x75, 0x80, 0x58, 0x11, \ - 0x03, 0x21, 0x23, 0x96, 0x9a, 0xb5, 0x02, 0x81, 0x80, 0x05, 0x12, 0x64, 0x71, 0x83, 0x00, 0x1c, 0xfe, \ - 0xef, 0x83, 0xea, 0xdd, 0x2c, 0xc8, 0x2c, 0x00, 0x62, 0x1e, 0x8f, 0x3a, 0xdb, 0x1c, 0xab, 0xd6, 0x34, \ - 0x8b, 0xd1, 0xb2, 0x5a, 0x4f, 0x3d, 0x37, 0x38, 0x02, 0xe0, 0xd7, 0x70, 0xc1, 0xb0, 0x47, 0xe0, 0x08, \ - 0x1a, 0x84, 0xec, 0x48, 0xc5, 0x7c, 0x76, 0x83, 0x12, 0x67, 0xab, 0x7c, 0x9f, 0x90, 0x97, 0xc8, 0x8f, \ - 0x07, 0xf4, 0xb3, 0x60, 0xf2, 0x3f, 0x49, 0x18, 0xdb, 0x2e, 0x94, 0x6b, 0x53, 0x9e, 0xa2, 0x63, 0xde, \ - 0x63, 0xd9, 0xab, 0x21, 0x2e, 0x2d, 0x0a, 0xe0, 0xd0, 0xe8, 0xba, 0xc4, 0x4c, 0x1e, 0xa5, 0xf5, 0x51, \ - 0xa8, 0xc4, 0x92, 0xf8, 0x7f, 0x21, 0xe7, 0x65, 0xbf, 0x0b, 0xe6, 0x01, 0xaf, 0x9c, 0x1d, 0x5b, 0x6c, \ - 0x3f, 0x1c, 0x2f, 0xa6, 0x0f, 0x68, 0x38, 0x8e, 0x85, 0xc4, 0x6c, 0x78, 0x2f, 0x6f, 0x06, 0x21, 0x2e, 0x56 \ + 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x4d, 0xa3, 0xdd, 0xe7, 0xcd, 0x1d, 0xd1, 0x04, 0xd7, 0x49, \ + 0x72, 0xb8, 0x99, 0xac, 0x0e, 0x78, 0xe4, 0x3a, 0x3c, 0x4a, 0xcf, 0x3a, 0x13, 0x16, 0xd0, 0x5a, 0xe4, 0xcd, 0xa3, 0x00, 0x88, 0xa7, \ + 0xee, 0x1e, 0x6b, 0x96, 0xa7, 0x52, 0xb4, 0x90, 0xef, 0x2d, 0x72, 0x7a, 0x3e, 0x24, 0x9a, 0xfc, 0xb6, 0x34, 0xac, 0x24, 0xf5, 0x77, \ + 0xe0, 0x26, 0x64, 0x8c, 0x9c, 0xb0, 0x28, 0x7d, 0xa1, 0xda, 0xea, 0x8c, 0xe6, 0xc9, 0x1c, 0x96, 0xbc, 0xfe, 0xc1, 0x04, 0x52, 0xb3, \ + 0x36, 0xd4, 0xa3, 0xfa, 0xe1, 0xb1, 0x76, 0xd8, 0x90, 0xc1, 0x61, 0xb4, 0x66, 0x52, 0x36, 0xa2, 0x26, 0x53, 0xaa, 0xab, 0x74, 0x5e, \ + 0x07, 0x7d, 0x19, 0x82, 0xdb, 0x2a, 0xd8, 0x1f, 0xa0, 0xd9, 0x0d, 0x1c, 0x2d, 0x49, 0x66, 0xf7, 0x5b, 0x25, 0x73, 0x46, 0xe8, 0x0b, \ + 0x8a, 0x4f, 0x69, 0x0c, 0xb5, 0x00, 0x90, 0xe1, 0xda, 0x82, 0x10, 0x66, 0x7d, 0xae, 0x54, 0x2b, 0x8b, 0x65, 0x79, 0x91, 0xa1, 0xe2, \ + 0x61, 0xc3, 0xcd, 0x40, 0x49, 0x08, 0xee, 0x68, 0x0c, 0xf1, 0x8b, 0x86, 0xd2, 0x46, 0xbf, 0xd0, 0xb8, 0xaa, 0x11, 0x03, 0x1e, 0x7f, \ + 0x56, 0xa8, 0x1a, 0x1e, 0x44, 0x18, 0x0f, 0x0f, 0x85, 0x8b, 0xda, 0x8b, 0x44, 0x5e, 0xe2, 0x18, 0xc6, 0x62, 0x2f, 0xc7, 0x66, 0x8d, \ + 0xfa, 0x5d, 0xd8, 0x7d, 0xf3, 0x27, 0x89, 0x29, 0x01, 0xc5, 0x90, 0x0e, 0x3f, 0x27, 0xf1, 0x30, 0xc8, 0x4a, 0x0e, 0xef, 0xd6, 0xde, \ + 0xc7, 0xc7, 0x27, 0x6b, 0xc7, 0x05, 0x3d, 0x7a, 0xc4, 0x02, 0x3c, 0x9a, 0x1d, 0x3e, 0x0f, 0xe8, 0x34, 0x98, 0x5b, 0xcb, 0x73, 0x4b, \ + 0x52, 0x96, 0xd8, 0x11, 0xa2, 0x2c, 0x80, 0x88, 0x69, 0x39, 0x5a, 0xd3, 0x0f, 0xb0, 0xde, 0x59, 0x2f, 0x11, 0xc7, 0xf7, 0xea, 0x12, \ + 0x01, 0x30, 0x97, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, 0x01, 0x00, 0x97, 0x47, 0x44, 0xbc, 0x10, 0x81, 0xc5, 0x18, 0xe4, \ + 0x59, 0xfb, 0xe0, 0x2d, 0x3a, 0x0e, 0x9e, 0x10, 0xdc, 0x43, 0xfb, 0x15, 0x6c, 0xd1, 0xfd, 0x48, 0x78, 0x6c, 0xf9, 0xed, 0x38, 0xe8, \ + 0xdd, 0x09, 0xd7, 0x5f, 0xb5, 0x41, 0x64, 0xd7, 0x63, 0xfa, 0x9d, 0x44, 0x0a, 0xf8, 0x42, 0x13, 0xf1, 0xbb, 0x5e, 0x79, 0x20, 0x53, \ + 0x98, 0x4b, 0x65, 0x7f, 0x86, 0x67, 0x48, 0xe4, 0xcf, 0xfb, 0x6a, 0x24, 0xe2, 0x34, 0xbd, 0x14, 0x9d, 0x2c, 0x16, 0xe2, 0xa4, 0x79, \ + 0xd6, 0xa2, 0xec, 0x81, 0x43, 0x87, 0xbf, 0x03, 0x5c, 0x88, 0x25, 0xd9, 0x41, 0xb6, 0xa5, 0xf1, 0x27, 0x52, 0x84, 0xfe, 0x2b, 0x6e, \ + 0x1d, 0x16, 0xcd, 0x73, 0x88, 0xf8, 0x90, 0xbf, 0x19, 0xfe, 0xbe, 0xa9, 0xbf, 0x09, 0xd3, 0x23, 0x43, 0xd2, 0xc7, 0x61, 0x2a, 0xb3, \ + 0x4e, 0x3c, 0x61, 0xd4, 0xbd, 0xd8, 0xb4, 0xfa, 0xa8, 0x0b, 0xf8, 0x7e, 0x56, 0xcd, 0x0f, 0x13, 0x27, 0xda, 0xe6, 0x3b, 0xb3, 0x8c, \ + 0x9c, 0x4b, 0x84, 0x3c, 0xc3, 0x52, 0x57, 0x9c, 0x27, 0x9a, 0x02, 0x76, 0x26, 0x59, 0x82, 0x39, 0xc3, 0x13, 0xbe, 0x6e, 0xf4, 0x44, \ + 0x2d, 0x1d, 0x8c, 0x73, 0x3e, 0x43, 0x99, 0x59, 0xcb, 0xf2, 0x34, 0x72, 0x9a, 0x5e, 0xa5, 0xeb, 0x9f, 0x36, 0x6d, 0x2b, 0xf9, 0xa2, \ + 0xe7, 0xd1, 0x78, 0x52, 0x1b, 0xc8, 0xf6, 0x5b, 0x41, 0x69, 0x57, 0x81, 0x89, 0xe9, 0xbb, 0xa1, 0xde, 0x19, 0x37, 0x3b, 0x13, 0x5c, \ + 0xca, 0x61, 0x01, 0x86, 0xff, 0xdf, 0x83, 0x41, 0x49, 0x7f, 0xd6, 0xf4, 0x2e, 0x08, 0xfa, 0x90, 0xc2, 0x7c, 0xb4, 0xb5, 0x0a, 0x17, \ + 0xdb, 0x0e, 0x6d, 0x75, 0x8a, 0x5d, 0x31, 0xd5, 0x66, 0xfb, 0x39, 0x0b, 0xb5, 0xb6, 0xa3, 0xcd, 0xd4, 0xef, 0x88, 0x92, 0x5a, 0x4d, \ + 0x6c, 0xcb, 0xea, 0x5b, 0x79, 0x02, 0x81, 0x81, 0x00, 0xdf, 0x3a, 0xf9, 0x25, 0x5e, 0x24, 0x37, 0x26, 0x40, 0x97, 0x2f, 0xe0, 0x4a, \ + 0xba, 0x52, 0x1b, 0x51, 0xaf, 0x84, 0x06, 0x32, 0x24, 0x0c, 0xcf, 0x44, 0xa8, 0x77, 0xa7, 0xad, 0xb5, 0x8c, 0x58, 0xcc, 0xc8, 0x31, \ + 0xb7, 0x0d, 0xbc, 0x08, 0x8a, 0xe0, 0xa6, 0x8c, 0xc2, 0x73, 0xe5, 0x1a, 0x64, 0x92, 0xe8, 0xed, 0x4c, 0x6f, 0x0b, 0xa6, 0xa7, 0xf3, \ + 0x9a, 0xf5, 0x6f, 0x69, 0xca, 0x3c, 0x22, 0xd0, 0x15, 0xa8, 0x20, 0x27, 0x41, 0xf8, 0x43, 0x42, 0x7f, 0xb1, 0x93, 0xa1, 0x04, 0x85, \ + 0xda, 0xa0, 0x1c, 0xd6, 0xc6, 0xf7, 0x8a, 0x9e, 0xea, 0x5c, 0x78, 0xa7, 0x55, 0xc4, 0x6b, 0x05, 0x8b, 0xc0, 0x83, 0xcb, 0xce, 0x83, \ + 0x05, 0xf8, 0xb2, 0x16, 0x2b, 0xdf, 0x06, 0x3f, 0xb8, 0xec, 0x16, 0xda, 0x43, 0x33, 0xc1, 0x8f, 0xb0, 0xb8, 0xac, 0xae, 0xd4, 0x94, \ + 0xb8, 0xda, 0x6f, 0x6a, 0xc3, 0x02, 0x81, 0x81, 0x00, 0xdd, 0xae, 0x00, 0xcd, 0xa0, 0x72, 0x1a, 0x05, 0x8a, 0xee, 0x2f, 0xd4, 0x71, \ + 0x4b, 0xf0, 0x3e, 0xe5, 0xc1, 0xe1, 0x29, 0x8b, 0xa6, 0x67, 0x30, 0x98, 0xe7, 0x12, 0xef, 0xdd, 0x12, 0x01, 0x90, 0x24, 0x58, 0xf0, \ + 0x76, 0x92, 0xe7, 0x3d, 0xbb, 0x23, 0xe1, 0xce, 0xf9, 0xa1, 0xd4, 0x38, 0x1b, 0x3f, 0x20, 0xb3, 0x0f, 0x65, 0x6a, 0x8f, 0x55, 0x57, \ + 0x36, 0xee, 0xb2, 0x84, 0x44, 0xfc, 0x91, 0x88, 0xe1, 0xa4, 0xdd, 0x3b, 0x4a, 0x40, 0x4d, 0x7c, 0x86, 0xed, 0xe1, 0xb5, 0x42, 0xef, \ + 0xb9, 0x61, 0xcd, 0x58, 0x19, 0x77, 0x02, 0xae, 0x58, 0x80, 0xdb, 0x13, 0x3d, 0xc7, 0x1f, 0x9d, 0xed, 0xff, 0xac, 0x98, 0xfc, 0xcd, \ + 0xf9, 0x62, 0x04, 0x83, 0x91, 0x89, 0x0d, 0x86, 0x43, 0x8c, 0x0c, 0xc7, 0x1b, 0x90, 0x4d, 0xbe, 0x2f, 0xc5, 0x7c, 0xcd, 0x42, 0xf5, \ + 0xd3, 0xad, 0x8e, 0xfd, 0x9d, 0x02, 0x81, 0x80, 0x17, 0x4b, 0x79, 0x2a, 0x6c, 0x1b, 0x8d, 0x61, 0xc1, 0x85, 0xc5, 0x6a, 0x3b, 0x82, \ + 0x1c, 0x05, 0x5b, 0xcd, 0xdc, 0x12, 0x25, 0x73, 0x5b, 0x9e, 0xd9, 0x84, 0x57, 0x10, 0x39, 0x71, 0x63, 0x96, 0xf4, 0xaf, 0xc3, 0x78, \ + 0x5d, 0xc7, 0x8c, 0x80, 0xa9, 0x96, 0xd7, 0xc3, 0x87, 0x02, 0x96, 0x71, 0x7e, 0x5f, 0x2e, 0x3c, 0x36, 0xae, 0x59, 0x92, 0xd7, 0x3a, \ + 0x09, 0x78, 0xb9, 0xea, 0x6f, 0xc2, 0x16, 0x42, 0xdc, 0x4b, 0x96, 0xad, 0x2c, 0xb2, 0x20, 0x23, 0x61, 0x2d, 0x8d, 0xb5, 0x02, 0x1e, \ + 0xe1, 0x6c, 0x81, 0x01, 0x3c, 0x5d, 0xcb, 0xdd, 0x9b, 0x0e, 0xc0, 0x2f, 0x94, 0x12, 0xb2, 0xfe, 0x75, 0x75, 0x8b, 0x74, 0x1e, 0x7a, \ + 0x26, 0x0c, 0xb7, 0x81, 0x96, 0x81, 0x79, 0x6e, 0xdb, 0xbc, 0x3a, 0xc4, 0x9e, 0x87, 0x09, 0x6e, 0xa0, 0xa6, 0xec, 0x8b, 0xa4, 0x85, \ + 0x71, 0xce, 0x04, 0xaf, 0x02, 0x81, 0x81, 0x00, 0xc2, 0xa7, 0x47, 0x07, 0x48, 0x6a, 0xc8, 0xd4, 0xb3, 0x20, 0xe1, 0x98, 0xee, 0xff, \ + 0x5a, 0x6f, 0x30, 0x7a, 0xa5, 0x47, 0x40, 0xdc, 0x16, 0x62, 0x42, 0xf1, 0x2c, 0xdc, 0xb8, 0xc7, 0x55, 0xde, 0x07, 0x3c, 0x9d, 0xb1, \ + 0xd0, 0xdf, 0x02, 0x82, 0xb0, 0x48, 0x58, 0xe1, 0x34, 0xab, 0xcf, 0xb4, 0x85, 0x23, 0x26, 0x78, 0x4f, 0x7a, 0x59, 0x6f, 0xfb, 0x8c, \ + 0x3d, 0xdf, 0x3d, 0x6c, 0x02, 0x47, 0x9c, 0xe5, 0x5e, 0x49, 0xf1, 0x05, 0x0b, 0x1f, 0xbf, 0x48, 0x0f, 0xdc, 0x10, 0xb9, 0x3d, 0x1d, \ + 0x10, 0x77, 0x2a, 0x73, 0xf9, 0xdf, 0xbd, 0xcd, 0xf3, 0x1f, 0xeb, 0x6e, 0x64, 0xca, 0x2b, 0x78, 0x4f, 0xf8, 0x73, 0xc2, 0x10, 0xef, \ + 0x79, 0x95, 0x33, 0x1e, 0x79, 0x35, 0x09, 0xff, 0x88, 0x1b, 0xb4, 0x3e, 0x4c, 0xe1, 0x27, 0x2e, 0x75, 0x80, 0x58, 0x11, 0x03, 0x21, \ + 0x23, 0x96, 0x9a, 0xb5, 0x02, 0x81, 0x80, 0x05, 0x12, 0x64, 0x71, 0x83, 0x00, 0x1c, 0xfe, 0xef, 0x83, 0xea, 0xdd, 0x2c, 0xc8, 0x2c, \ + 0x00, 0x62, 0x1e, 0x8f, 0x3a, 0xdb, 0x1c, 0xab, 0xd6, 0x34, 0x8b, 0xd1, 0xb2, 0x5a, 0x4f, 0x3d, 0x37, 0x38, 0x02, 0xe0, 0xd7, 0x70, \ + 0xc1, 0xb0, 0x47, 0xe0, 0x08, 0x1a, 0x84, 0xec, 0x48, 0xc5, 0x7c, 0x76, 0x83, 0x12, 0x67, 0xab, 0x7c, 0x9f, 0x90, 0x97, 0xc8, 0x8f, \ + 0x07, 0xf4, 0xb3, 0x60, 0xf2, 0x3f, 0x49, 0x18, 0xdb, 0x2e, 0x94, 0x6b, 0x53, 0x9e, 0xa2, 0x63, 0xde, 0x63, 0xd9, 0xab, 0x21, 0x2e, \ + 0x2d, 0x0a, 0xe0, 0xd0, 0xe8, 0xba, 0xc4, 0x4c, 0x1e, 0xa5, 0xf5, 0x51, 0xa8, 0xc4, 0x92, 0xf8, 0x7f, 0x21, 0xe7, 0x65, 0xbf, 0x0b, \ + 0xe6, 0x01, 0xaf, 0x9c, 0x1d, 0x5b, 0x6c, 0x3f, 0x1c, 0x2f, 0xa6, 0x0f, 0x68, 0x38, 0x8e, 0x85, 0xc4, 0x6c, 0x78, 0x2f, 0x6f, 0x06, \ + 0x21, 0x2e, 0x56 \ } /* END FILE */ @@ -837,35 +743,28 @@ /* BEGIN FILE binary macro TEST_CLI_CRT_EC_DER tests/data_files/cli2.crt.der */ #define TEST_CLI_CRT_EC_DER \ { \ - 0x30, 0x82, 0x01, 0xdf, 0x30, 0x82, 0x01, 0x63, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x0d, 0x30, 0x0c, \ - 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, \ - 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, \ - 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, 0x1a, 0x06, \ - 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, \ - 0x73, 0x74, 0x20, 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, \ - 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \ - 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x30, 0x41, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, \ - 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, \ - 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, \ - 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x6c, 0x69, \ - 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, \ - 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, \ - 0xae, 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, 0xb8, 0x81, 0xff, 0x12, 0xae, 0xee, 0xe6, 0x53, 0xac, \ - 0xce, 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, 0xe3, 0x63, 0x25, 0x0b, 0xdf, 0x98, 0xe2, 0xf3, 0x5c, \ - 0x60, 0x36, 0x96, 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, 0xe5, 0xb0, \ - 0x6c, 0xd5, 0x5c, 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, 0xc7, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, \ - 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, \ - 0x16, 0x04, 0x14, 0x7a, 0x00, 0x5f, 0x86, 0x64, 0xfc, 0xe0, 0x5d, 0xe5, 0x11, 0x10, 0x3b, 0xb2, 0xe6, \ - 0x3b, 0xc4, 0x26, 0x3f, 0xcf, 0xe2, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, \ - 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, 0xb5, 0x19, 0xbc, 0x7e, 0x24, \ - 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, \ - 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0xca, 0xa6, 0x7b, 0x80, 0xca, 0x32, 0x57, \ - 0x54, 0x96, 0x99, 0x43, 0x11, 0x3f, 0x50, 0xe8, 0x4a, 0x6d, 0xad, 0xee, 0xee, 0x51, 0x62, 0xa1, 0xb0, \ - 0xb3, 0x85, 0xfb, 0x33, 0xe4, 0x28, 0x39, 0x5f, 0xce, 0x92, 0x24, 0x25, 0x81, 0x05, 0x81, 0xc9, 0x68, \ - 0x0c, 0x71, 0x98, 0xc3, 0xcd, 0x2e, 0x22, 0x02, 0x30, 0x35, 0xfb, 0x72, 0x3d, 0x7b, 0x1a, 0x6d, 0x3a, \ - 0x8c, 0x33, 0xb8, 0x84, 0x1e, 0x05, 0x69, 0x5f, 0xf1, 0x91, 0xa3, 0x32, 0xa4, 0x95, 0x8f, 0x72, 0x40, \ - 0x8f, 0xf9, 0x7a, 0x80, 0x3a, 0x80, 0x65, 0xbb, 0x63, 0xe8, 0xa6, 0xb8, 0x64, 0x7f, 0xa1, 0xaa, 0x39, \ - 0xc9, 0x23, 0x9b, 0x6b, 0xd5, 0x64 \ + 0x30, 0x82, 0x01, 0xdf, 0x30, 0x82, 0x01, 0x63, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x0d, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, \ + 0xce, 0x3d, 0x04, 0x03, 0x02, 0x05, 0x00, 0x30, 0x3e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, \ + 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1c, 0x30, \ + 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, \ + 0x45, 0x43, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, \ + 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x30, 0x5a, 0x30, 0x41, 0x31, 0x0b, 0x30, 0x09, 0x06, \ + 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, \ + 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x16, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, \ + 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, \ + 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x57, \ + 0xe5, 0xae, 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, 0xb8, 0x81, 0xff, 0x12, 0xae, 0xee, 0xe6, 0x53, 0xac, 0xce, 0x55, 0x53, 0xf6, \ + 0x34, 0x0e, 0xcc, 0x2e, 0xe3, 0x63, 0x25, 0x0b, 0xdf, 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, \ + 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, 0xc7, 0xa3, 0x4d, 0x30, \ + 0x4b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, \ + 0x14, 0x7a, 0x00, 0x5f, 0x86, 0x64, 0xfc, 0xe0, 0x5d, 0xe5, 0x11, 0x10, 0x3b, 0xb2, 0xe6, 0x3b, 0xc4, 0x26, 0x3f, 0xcf, 0xe2, 0x30, \ + 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x9d, 0x6d, 0x20, 0x24, 0x49, 0x01, 0x3f, 0x2b, 0xcb, 0x78, \ + 0xb5, 0x19, 0xbc, 0x7e, 0x24, 0xc9, 0xdb, 0xfb, 0x36, 0x7c, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, \ + 0x05, 0x00, 0x03, 0x68, 0x00, 0x30, 0x65, 0x02, 0x31, 0x00, 0xca, 0xa6, 0x7b, 0x80, 0xca, 0x32, 0x57, 0x54, 0x96, 0x99, 0x43, 0x11, \ + 0x3f, 0x50, 0xe8, 0x4a, 0x6d, 0xad, 0xee, 0xee, 0x51, 0x62, 0xa1, 0xb0, 0xb3, 0x85, 0xfb, 0x33, 0xe4, 0x28, 0x39, 0x5f, 0xce, 0x92, \ + 0x24, 0x25, 0x81, 0x05, 0x81, 0xc9, 0x68, 0x0c, 0x71, 0x98, 0xc3, 0xcd, 0x2e, 0x22, 0x02, 0x30, 0x35, 0xfb, 0x72, 0x3d, 0x7b, 0x1a, \ + 0x6d, 0x3a, 0x8c, 0x33, 0xb8, 0x84, 0x1e, 0x05, 0x69, 0x5f, 0xf1, 0x91, 0xa3, 0x32, 0xa4, 0x95, 0x8f, 0x72, 0x40, 0x8f, 0xf9, 0x7a, \ + 0x80, 0x3a, 0x80, 0x65, 0xbb, 0x63, 0xe8, 0xa6, 0xb8, 0x64, 0x7f, 0xa1, 0xaa, 0x39, 0xc9, 0x23, 0x9b, 0x6b, 0xd5, 0x64 \ } /* END FILE */ @@ -883,13 +782,12 @@ /* BEGIN FILE binary macro TEST_CLI_KEY_EC_DER tests/data_files/cli2.key.der */ #define TEST_CLI_KEY_EC_DER \ { \ - 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf6, 0xf7, 0x86, 0x64, 0xf1, 0x67, 0x7f, 0xe6, 0x64, 0x8d, 0xef, \ - 0xca, 0x4e, 0xe9, 0xdd, 0x4d, 0xf0, 0x05, 0xff, 0x96, 0x22, 0x8a, 0x7a, 0x84, 0x38, 0x64, 0x17, 0x32, \ - 0x61, 0x98, 0xb7, 0x2a, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0xa1, \ - 0x44, 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, 0xae, 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, 0xb8, 0x81, \ - 0xff, 0x12, 0xae, 0xee, 0xe6, 0x53, 0xac, 0xce, 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, 0xe3, 0x63, \ - 0x25, 0x0b, 0xdf, 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, 0x7f, \ - 0x9f, 0xd5, 0x4b, 0x45, 0x18, 0xe5, 0xb0, 0x6c, 0xd5, 0x5c, 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, 0xc7 \ + 0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf6, 0xf7, 0x86, 0x64, 0xf1, 0x67, 0x7f, 0xe6, 0x64, 0x8d, 0xef, 0xca, 0x4e, 0xe9, 0xdd, 0x4d, \ + 0xf0, 0x05, 0xff, 0x96, 0x22, 0x8a, 0x7a, 0x84, 0x38, 0x64, 0x17, 0x32, 0x61, 0x98, 0xb7, 0x2a, 0xa0, 0x0a, 0x06, 0x08, 0x2a, 0x86, \ + 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x57, 0xe5, 0xae, 0xb1, 0x73, 0xdf, 0xd3, 0xac, 0xbb, 0x93, \ + 0xb8, 0x81, 0xff, 0x12, 0xae, 0xee, 0xe6, 0x53, 0xac, 0xce, 0x55, 0x53, 0xf6, 0x34, 0x0e, 0xcc, 0x2e, 0xe3, 0x63, 0x25, 0x0b, 0xdf, \ + 0x98, 0xe2, 0xf3, 0x5c, 0x60, 0x36, 0x96, 0xc0, 0xd5, 0x18, 0x14, 0x70, 0xe5, 0x7f, 0x9f, 0xd5, 0x4b, 0x45, 0x18, 0xe5, 0xb0, 0x6c, \ + 0xd5, 0x5c, 0xf8, 0x96, 0x8f, 0x87, 0x70, 0xa3, 0xe4, 0xc7 \ } /* END FILE */ @@ -923,55 +821,44 @@ /* BEGIN FILE binary macro TEST_CLI_CRT_RSA_DER tests/data_files/cli-rsa-sha256.crt.der */ #define TEST_CLI_CRT_RSA_DER \ { \ - 0x30, 0x82, 0x03, 0x3f, 0x30, 0x82, 0x02, 0x27, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, \ - 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, \ - 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, \ - 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, 0x30, 0x17, \ - 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, \ - 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, \ - 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, \ - 0x34, 0x30, 0x36, 0x5a, 0x30, 0x3c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, \ - 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, \ - 0x72, 0x53, 0x53, 0x4c, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x11, 0x50, 0x6f, \ - 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, 0x82, \ - 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, \ - 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc8, 0x74, 0xc4, \ - 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, 0x45, 0xd9, 0x14, 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, \ - 0x9f, 0x33, 0xad, 0x0d, 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, 0xcc, 0x66, 0x85, 0x07, \ - 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, 0x9e, 0x0a, 0x6e, 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, \ - 0xee, 0x0c, 0x10, 0x93, 0x86, 0x49, 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, 0xd4, 0x2f, \ - 0x77, 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, 0x48, 0x70, 0xf5, 0x6e, 0x4d, 0xb2, 0xd5, \ - 0x13, 0xc3, 0xd2, 0x1a, 0xed, 0xe6, 0x43, 0xea, 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, \ - 0x57, 0x4e, 0xa9, 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, 0x32, 0x30, 0xd5, 0xd3, 0xf6, \ - 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, 0x5f, 0xf9, 0x3d, 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, \ - 0xdf, 0x7d, 0xfb, 0xe5, 0x0c, 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, 0x7f, 0xca, 0xad, \ - 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, 0xe0, 0x9b, 0xf8, 0x10, 0x56, 0xcc, 0xb3, 0x8e, \ - 0x13, 0x15, 0xe6, 0x34, 0x04, 0x66, 0xc7, 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, 0x06, \ - 0x67, 0xf4, 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, 0x3c, 0x8b, 0x35, 0x04, 0x67, 0xba, \ - 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, 0xfc, 0x36, 0x6b, 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, \ - 0x3d, 0x00, 0xcf, 0xaf, 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, 0xe7, 0x50, 0x71, 0xe6, \ - 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, 0xe4, 0xc4, 0xfd, 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, \ - 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, \ - 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x71, 0xa1, 0x00, 0x73, 0x72, \ - 0x40, 0x2f, 0x54, 0x76, 0x5e, 0x33, 0xfc, 0x52, 0x8f, 0xbc, 0xf1, 0xdd, 0x6b, 0x46, 0x21, 0x30, 0x1f, \ - 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, \ - 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, \ - 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, \ - 0x5e, 0x27, 0x6f, 0xd5, 0xde, 0x29, 0x2e, 0x50, 0x62, 0x29, 0x61, 0x03, 0xf7, 0x9a, 0xcc, 0xc9, 0xc0, \ - 0x5d, 0x80, 0x37, 0x20, 0xc8, 0xda, 0x89, 0xc5, 0xa9, 0x05, 0x91, 0x17, 0xd1, 0xc8, 0x0d, 0xb2, 0xd6, \ - 0x69, 0x72, 0x4e, 0x7e, 0xee, 0x05, 0x74, 0x64, 0x34, 0xb6, 0x39, 0x64, 0x5c, 0xca, 0xf3, 0x61, 0x82, \ - 0x8e, 0x4d, 0x90, 0xd8, 0xe0, 0xf8, 0x45, 0x94, 0x82, 0x3c, 0x02, 0x49, 0xa8, 0xba, 0x47, 0x1d, 0x4d, \ - 0xf8, 0xb7, 0xbd, 0x5c, 0x89, 0xf7, 0xef, 0xcb, 0x62, 0x8a, 0xf3, 0x56, 0x2f, 0xaf, 0x17, 0x33, 0x46, \ - 0x13, 0x00, 0x13, 0xae, 0x22, 0xfa, 0xa9, 0xda, 0xc8, 0xfd, 0xd3, 0x77, 0x65, 0xee, 0x58, 0x94, 0x74, \ - 0xe4, 0xf5, 0x4f, 0xa1, 0x27, 0xa6, 0xb0, 0xd1, 0x0b, 0xb3, 0xd8, 0x16, 0xb6, 0xd7, 0x67, 0x63, 0x2d, \ - 0xdc, 0x7b, 0xe1, 0x18, 0xd9, 0x8d, 0x27, 0xed, 0x1b, 0x22, 0xef, 0xdf, 0x36, 0x11, 0xe2, 0xc8, 0x00, \ - 0x0e, 0xc7, 0xe9, 0xc6, 0xb8, 0xd8, 0x4b, 0x3f, 0x35, 0x41, 0xff, 0xfc, 0x96, 0x49, 0x4f, 0x7d, 0x8e, \ - 0x3f, 0x47, 0x68, 0x33, 0x17, 0x83, 0x44, 0x0f, 0xaf, 0xa6, 0x59, 0x0a, 0xa9, 0x32, 0xcb, 0x59, 0xfe, \ - 0xdd, 0x5f, 0x6e, 0x8b, 0x22, 0xb8, 0x81, 0x90, 0x16, 0x91, 0x0a, 0x04, 0x79, 0x62, 0xff, 0x4b, 0x04, \ - 0xf1, 0x5c, 0x34, 0xeb, 0x69, 0xce, 0xef, 0xcb, 0x6e, 0xb6, 0x3b, 0x40, 0x55, 0xca, 0x24, 0xc2, 0x3e, \ - 0x25, 0x70, 0xee, 0x74, 0x2b, 0x0e, 0x9f, 0xc2, 0x82, 0x9a, 0x20, 0x38, 0x77, 0xa1, 0x26, 0x8a, 0xca, \ - 0x9f, 0x87, 0x75, 0x77, 0xe3, 0xce, 0x65, 0xec, 0x71, 0x10, 0x35, 0xcb, 0xcb, 0x4f, 0x19, 0x43, 0xeb, \ - 0x30, 0xd0, 0xca, 0x2d, 0x3f, 0xca, 0x46, 0x14, 0x61, 0x99, 0x30, 0x41, 0x32, 0xb5, 0x37, 0x63, 0x6f, 0x97 \ + 0x30, 0x82, 0x03, 0x3f, 0x30, 0x82, 0x02, 0x27, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, \ + 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x4e, \ + 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x31, 0x19, \ + 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x10, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, \ + 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x17, 0x0d, \ + 0x32, 0x39, 0x30, 0x32, 0x31, 0x30, 0x31, 0x34, 0x34, 0x34, 0x30, 0x36, 0x5a, 0x30, 0x3c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, \ + 0x04, 0x06, 0x13, 0x02, 0x4e, 0x4c, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x08, 0x50, 0x6f, 0x6c, 0x61, 0x72, \ + 0x53, 0x53, 0x4c, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x11, 0x50, 0x6f, 0x6c, 0x61, 0x72, 0x53, 0x53, 0x4c, \ + 0x20, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x20, 0x32, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, \ + 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc8, 0x74, \ + 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, 0x45, 0xd9, 0x14, 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, 0x33, 0xad, 0x0d, \ + 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, 0xcc, 0x66, 0x85, 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, 0x9e, \ + 0x0a, 0x6e, 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, 0x93, 0x86, 0x49, 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, \ + 0x2e, 0xd4, 0x2f, 0x77, 0x29, 0x84, 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, 0x48, 0x70, 0xf5, 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, \ + 0xd2, 0x1a, 0xed, 0xe6, 0x43, 0xea, 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, 0x57, 0x4e, 0xa9, 0xf3, 0xa8, 0xed, 0xd2, \ + 0xe0, 0xc1, 0x30, 0x71, 0x30, 0x32, 0x30, 0xd5, 0xd3, 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, 0x5f, 0xf9, 0x3d, 0x67, 0x91, \ + 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, 0xfb, 0xe5, 0x0c, 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, 0x7f, 0xca, 0xad, \ + 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, 0xe0, 0x9b, 0xf8, 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, 0x04, \ + 0x66, 0xc7, 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, 0x06, 0x67, 0xf4, 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, \ + 0xfe, 0x3c, 0x8b, 0x35, 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, 0x85, 0xfc, 0x7f, 0xfc, 0x36, 0x6b, 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, \ + 0x4e, 0xb3, 0x3d, 0x00, 0xcf, 0xaf, 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, 0xe7, 0x50, 0x71, 0xe6, 0xb5, 0x36, 0x05, \ + 0x77, 0x05, 0x6d, 0x7b, 0xc8, 0xe4, 0xc4, 0xfd, 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x4d, 0x30, 0x4b, 0x30, \ + 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x71, \ + 0xa1, 0x00, 0x73, 0x72, 0x40, 0x2f, 0x54, 0x76, 0x5e, 0x33, 0xfc, 0x52, 0x8f, 0xbc, 0xf1, 0xdd, 0x6b, 0x46, 0x21, 0x30, 0x1f, 0x06, \ + 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xb4, 0x5a, 0xe4, 0xa5, 0xb3, 0xde, 0xd2, 0x52, 0xf6, 0xb9, 0xd5, 0xa6, \ + 0x95, 0x0f, 0xeb, 0x3e, 0xbc, 0xc7, 0xfd, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, \ + 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x5e, 0x27, 0x6f, 0xd5, 0xde, 0x29, 0x2e, 0x50, 0x62, 0x29, 0x61, 0x03, 0xf7, 0x9a, 0xcc, 0xc9, \ + 0xc0, 0x5d, 0x80, 0x37, 0x20, 0xc8, 0xda, 0x89, 0xc5, 0xa9, 0x05, 0x91, 0x17, 0xd1, 0xc8, 0x0d, 0xb2, 0xd6, 0x69, 0x72, 0x4e, 0x7e, \ + 0xee, 0x05, 0x74, 0x64, 0x34, 0xb6, 0x39, 0x64, 0x5c, 0xca, 0xf3, 0x61, 0x82, 0x8e, 0x4d, 0x90, 0xd8, 0xe0, 0xf8, 0x45, 0x94, 0x82, \ + 0x3c, 0x02, 0x49, 0xa8, 0xba, 0x47, 0x1d, 0x4d, 0xf8, 0xb7, 0xbd, 0x5c, 0x89, 0xf7, 0xef, 0xcb, 0x62, 0x8a, 0xf3, 0x56, 0x2f, 0xaf, \ + 0x17, 0x33, 0x46, 0x13, 0x00, 0x13, 0xae, 0x22, 0xfa, 0xa9, 0xda, 0xc8, 0xfd, 0xd3, 0x77, 0x65, 0xee, 0x58, 0x94, 0x74, 0xe4, 0xf5, \ + 0x4f, 0xa1, 0x27, 0xa6, 0xb0, 0xd1, 0x0b, 0xb3, 0xd8, 0x16, 0xb6, 0xd7, 0x67, 0x63, 0x2d, 0xdc, 0x7b, 0xe1, 0x18, 0xd9, 0x8d, 0x27, \ + 0xed, 0x1b, 0x22, 0xef, 0xdf, 0x36, 0x11, 0xe2, 0xc8, 0x00, 0x0e, 0xc7, 0xe9, 0xc6, 0xb8, 0xd8, 0x4b, 0x3f, 0x35, 0x41, 0xff, 0xfc, \ + 0x96, 0x49, 0x4f, 0x7d, 0x8e, 0x3f, 0x47, 0x68, 0x33, 0x17, 0x83, 0x44, 0x0f, 0xaf, 0xa6, 0x59, 0x0a, 0xa9, 0x32, 0xcb, 0x59, 0xfe, \ + 0xdd, 0x5f, 0x6e, 0x8b, 0x22, 0xb8, 0x81, 0x90, 0x16, 0x91, 0x0a, 0x04, 0x79, 0x62, 0xff, 0x4b, 0x04, 0xf1, 0x5c, 0x34, 0xeb, 0x69, \ + 0xce, 0xef, 0xcb, 0x6e, 0xb6, 0x3b, 0x40, 0x55, 0xca, 0x24, 0xc2, 0x3e, 0x25, 0x70, 0xee, 0x74, 0x2b, 0x0e, 0x9f, 0xc2, 0x82, 0x9a, \ + 0x20, 0x38, 0x77, 0xa1, 0x26, 0x8a, 0xca, 0x9f, 0x87, 0x75, 0x77, 0xe3, 0xce, 0x65, 0xec, 0x71, 0x10, 0x35, 0xcb, 0xcb, 0x4f, 0x19, \ + 0x43, 0xeb, 0x30, 0xd0, 0xca, 0x2d, 0x3f, 0xca, 0x46, 0x14, 0x61, 0x99, 0x30, 0x41, 0x32, 0xb5, 0x37, 0x63, 0x6f, 0x97 \ } /* END FILE */ @@ -1010,76 +897,61 @@ /* BEGIN FILE binary macro TEST_CLI_KEY_RSA_DER tests/data_files/cli-rsa.key.der */ #define TEST_CLI_KEY_RSA_DER \ { \ - 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, \ - 0xb5, 0x79, 0xe9, 0x45, 0xd9, 0x14, 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, 0x33, 0xad, \ - 0x0d, 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, 0xcc, 0x66, 0x85, 0x07, 0xd5, 0xf8, 0x27, \ - 0xb0, 0x4a, 0x35, 0xd0, 0x63, 0x9e, 0x0a, 0x6e, 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, 0x0c, 0x10, \ - 0x93, 0x86, 0x49, 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, 0xd4, 0x2f, 0x77, 0x29, 0x84, \ - 0x61, 0x4d, 0x82, 0x50, 0x8f, 0xa7, 0x95, 0x48, 0x70, 0xf5, 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, \ - 0x1a, 0xed, 0xe6, 0x43, 0xea, 0x42, 0x14, 0xeb, 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, 0x57, 0x4e, 0xa9, \ - 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, 0x32, 0x30, 0xd5, 0xd3, 0xf6, 0x08, 0xd0, 0x56, \ - 0x4f, 0x46, 0x8e, 0xf2, 0x5f, 0xf9, 0x3d, 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, 0xfb, \ - 0xe5, 0x0c, 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, 0x7f, 0xca, 0xad, 0x6c, 0x21, 0xd6, \ - 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, 0xe0, 0x9b, 0xf8, 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, \ - 0x34, 0x04, 0x66, 0xc7, 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, 0x09, 0x9a, 0x06, 0x67, 0xf4, 0x65, \ - 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, 0x3c, 0x8b, 0x35, 0x04, 0x67, 0xba, 0xe0, 0x4f, 0x76, \ - 0x85, 0xfc, 0x7f, 0xfc, 0x36, 0x6b, 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, 0x00, 0xcf, \ - 0xaf, 0x76, 0xa0, 0x69, 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, 0xe7, 0x50, 0x71, 0xe6, 0xb5, 0x36, 0x05, \ - 0x77, 0x05, 0x6d, 0x7b, 0xc8, 0xe4, 0xc4, 0xfd, 0x4c, 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, \ - 0x02, 0x82, 0x01, 0x00, 0x67, 0x4d, 0xb5, 0xf6, 0x03, 0x89, 0xaa, 0x7a, 0x6f, 0x3b, 0x2d, 0xca, 0x10, \ - 0xa2, 0x23, 0xc9, 0xbd, 0x4e, 0xda, 0xe1, 0x67, 0x0e, 0x0c, 0x8a, 0xc6, 0x84, 0x68, 0xdf, 0xe5, 0x97, \ - 0x75, 0xd2, 0x8d, 0xa3, 0x86, 0xd9, 0xdb, 0xd5, 0xeb, 0x13, 0x19, 0x08, 0xc5, 0x7e, 0xe5, 0x37, 0x97, \ - 0x0c, 0x73, 0x80, 0x66, 0x76, 0x35, 0xf1, 0x88, 0xb5, 0xf2, 0xfc, 0xf3, 0xe1, 0x4b, 0x76, 0x4e, 0x73, \ - 0x45, 0xce, 0x2c, 0xc2, 0x10, 0x26, 0x0d, 0x68, 0x0d, 0x9f, 0x49, 0x3d, 0xd6, 0x80, 0x89, 0xe7, 0xc5, \ - 0x49, 0x15, 0xdd, 0x85, 0xc0, 0xc8, 0xfe, 0x82, 0x37, 0x12, 0x5a, 0x0a, 0x6b, 0xf6, 0x68, 0x0d, 0x32, \ - 0x16, 0xbd, 0xa4, 0x15, 0x54, 0x9e, 0x68, 0xa1, 0xad, 0xca, 0x6b, 0xe5, 0x8c, 0xda, 0x76, 0x35, 0x59, \ - 0x2f, 0x9b, 0xb4, 0xe1, 0xf1, 0xf0, 0x50, 0x04, 0xee, 0xc8, 0xec, 0x05, 0xe1, 0xcf, 0x8d, 0xe4, 0xd2, \ - 0x64, 0x7b, 0x5e, 0x63, 0xe0, 0x7b, 0x07, 0xbc, 0x02, 0x96, 0x4e, 0x1b, 0x78, 0x6c, 0xb6, 0x43, 0x9a, \ - 0x32, 0xf6, 0xd6, 0x02, 0xf5, 0x80, 0xcc, 0x26, 0x6e, 0xa5, 0xd0, 0xe3, 0x65, 0x88, 0xce, 0x26, 0xa9, \ - 0x40, 0xe1, 0xe1, 0x00, 0xe0, 0x7f, 0x3f, 0xc3, 0xb1, 0x7c, 0xde, 0xbe, 0x42, 0xba, 0x07, 0x81, 0x13, \ - 0xc2, 0xe0, 0x11, 0x11, 0x23, 0x2c, 0xf8, 0xb2, 0x7a, 0x3a, 0xd4, 0xe4, 0x7d, 0x5f, 0xb9, 0xb1, 0x18, \ - 0xfa, 0x1d, 0x1d, 0x97, 0x91, 0xd9, 0x04, 0x9e, 0xbc, 0xc9, 0xb4, 0xd7, 0x7d, 0x0e, 0x54, 0xf6, 0x8f, \ - 0xd0, 0x28, 0x0d, 0xdd, 0x77, 0x4b, 0x68, 0x04, 0x48, 0x61, 0x75, 0x15, 0x03, 0x1b, 0x35, 0xad, 0x8e, \ - 0xfc, 0x24, 0x11, 0x07, 0xea, 0x17, 0x5a, 0xde, 0x19, 0x68, 0xff, 0xb6, 0x87, 0x7f, 0x80, 0x2a, 0x5f, \ - 0x0c, 0x58, 0xba, 0x5f, 0x41, 0x02, 0x81, 0x81, 0x00, 0xe3, 0x03, 0xaf, 0xfe, 0x98, 0xd2, 0x0b, 0x7b, \ - 0x72, 0xe9, 0x3b, 0x8e, 0xbc, 0xa5, 0xf6, 0xac, 0xe5, 0x22, 0x06, 0xb2, 0xd7, 0x5e, 0xfd, 0x89, 0x4b, \ - 0x16, 0x67, 0x32, 0x83, 0x22, 0x58, 0x8e, 0x62, 0xa4, 0xb4, 0x2d, 0xf9, 0x16, 0x13, 0x54, 0xf6, 0x9f, \ - 0x2f, 0xf9, 0xbb, 0x0e, 0x7e, 0x8c, 0x6f, 0x08, 0xda, 0xc8, 0xe9, 0x1c, 0x66, 0x10, 0x70, 0x93, 0x90, \ - 0x8d, 0xcf, 0x90, 0x3a, 0x43, 0x89, 0x49, 0xeb, 0x83, 0x2a, 0xfe, 0x5a, 0x87, 0xce, 0x74, 0x42, 0x41, \ - 0x0d, 0x8c, 0x73, 0x51, 0xbc, 0x7b, 0x20, 0xc5, 0xfd, 0xf6, 0x0b, 0x65, 0xed, 0xa9, 0x2e, 0xfc, 0x0f, \ - 0xf5, 0x50, 0xf9, 0x8d, 0x37, 0x36, 0x9a, 0x20, 0xdf, 0xc3, 0xe3, 0x27, 0xbc, 0x98, 0x72, 0xc1, 0x14, \ - 0x4b, 0x71, 0xe9, 0x83, 0x14, 0xff, 0x24, 0xe2, 0x14, 0x15, 0xb6, 0x6f, 0x0f, 0x32, 0x9d, 0xd9, 0x98, \ - 0xd1, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x0c, 0xfb, 0xc3, 0x33, 0x9b, 0x47, 0x88, 0x27, 0xf2, 0x26, 0xde, \ - 0xeb, 0x5e, 0xee, 0x40, 0xf6, 0x63, 0x5b, 0x35, 0x23, 0xf5, 0xd5, 0x07, 0x61, 0xdf, 0xa2, 0x9f, 0x58, \ - 0x30, 0x04, 0x22, 0x2b, 0xb4, 0xd9, 0xda, 0x46, 0x7f, 0x48, 0xf5, 0x4f, 0xd0, 0xea, 0xd7, 0xa0, 0x45, \ - 0x8a, 0x62, 0x8b, 0x8c, 0xac, 0x73, 0x5e, 0xfa, 0x36, 0x65, 0x3e, 0xba, 0x6c, 0xba, 0x5e, 0x6b, 0x92, \ - 0x29, 0x5e, 0x6a, 0x0f, 0xd6, 0xd2, 0xa5, 0x95, 0x86, 0xda, 0x72, 0xc5, 0x9e, 0xc9, 0x6b, 0x37, 0x5e, \ - 0x4b, 0x9b, 0x77, 0xe1, 0x67, 0x1a, 0x1e, 0x30, 0xd8, 0x41, 0x68, 0x40, 0xd3, 0x9c, 0xb4, 0xf6, 0xeb, \ - 0x2a, 0x22, 0xdf, 0x78, 0x29, 0xd2, 0x64, 0x92, 0x5b, 0x2f, 0x78, 0x64, 0x4a, 0xa2, 0xa6, 0x6b, 0x3e, \ - 0x50, 0xb1, 0x7a, 0xb1, 0x8d, 0x59, 0xb4, 0x55, 0xba, 0xb6, 0x91, 0x85, 0xa3, 0x2f, 0x02, 0x81, 0x80, \ - 0x10, 0x1e, 0x19, 0xe7, 0xbc, 0x97, 0xe5, 0x22, 0xcd, 0xa4, 0xcb, 0x8a, 0xb5, 0xd0, 0x1e, 0xb4, 0x65, \ - 0xcc, 0x45, 0xa7, 0x7a, 0xed, 0x0e, 0x99, 0x29, 0xd0, 0x9c, 0x61, 0x14, 0xb8, 0x62, 0x8b, 0x31, 0x6b, \ - 0xba, 0x33, 0x2d, 0x65, 0x28, 0xd8, 0x36, 0x6e, 0x54, 0xec, 0xa9, 0x20, 0x3d, 0x51, 0xe1, 0x2c, 0x42, \ - 0xc4, 0x52, 0xf0, 0xa6, 0x3a, 0x72, 0x93, 0xb7, 0x86, 0xa9, 0xfe, 0xf6, 0x74, 0x07, 0x12, 0x4d, 0x7b, \ - 0x51, 0x99, 0x1f, 0x7a, 0x56, 0xe9, 0x20, 0x2f, 0x18, 0x34, 0x29, 0x97, 0xdb, 0x06, 0xee, 0xeb, 0xbf, \ - 0xbd, 0x31, 0x4f, 0xfa, 0x50, 0xb1, 0xba, 0x49, 0xb3, 0xc4, 0x1d, 0x03, 0xae, 0xb0, 0xdc, 0xbe, 0x8a, \ - 0xc4, 0x90, 0xa3, 0x28, 0x9b, 0xb6, 0x42, 0x09, 0x1b, 0xd6, 0x29, 0x9b, 0x19, 0xe9, 0x87, 0x87, 0xd9, \ - 0x9f, 0x35, 0x05, 0xab, 0x91, 0x8f, 0x6d, 0x7c, 0x91, 0x02, 0x81, 0x81, 0x00, 0x94, 0x57, 0xf0, 0xe0, \ - 0x28, 0xfd, 0xbd, 0xf3, 0x9c, 0x43, 0x4d, 0x3e, 0xfd, 0x37, 0x4f, 0x23, 0x52, 0x8d, 0xe1, 0x4c, 0xfe, \ - 0x4c, 0x55, 0x80, 0x82, 0xba, 0x3f, 0xfe, 0x51, 0xe1, 0x30, 0xd5, 0x3b, 0xd9, 0x73, 0x1d, 0xcb, 0x25, \ - 0xbc, 0xbb, 0x3f, 0xa5, 0xda, 0x77, 0xa6, 0xb5, 0xfc, 0x1a, 0xaf, 0x79, 0xa1, 0xb2, 0x14, 0xa2, 0x1f, \ - 0x10, 0x52, 0x1a, 0x05, 0x40, 0x48, 0xb6, 0x4f, 0x34, 0xd6, 0xc0, 0xc3, 0xa4, 0x36, 0x98, 0x73, 0x88, \ - 0x0b, 0xd3, 0x45, 0xdc, 0xee, 0x51, 0x6e, 0x04, 0x73, 0x99, 0x93, 0x12, 0x58, 0x96, 0xcb, 0x39, 0x42, \ - 0xb1, 0xa9, 0xb8, 0xe1, 0x25, 0xf5, 0x9c, 0x14, 0xb7, 0x92, 0x2b, 0x14, 0xb0, 0x5d, 0x61, 0xa2, 0xaa, \ - 0x34, 0x7c, 0xcd, 0x54, 0x2d, 0x69, 0x08, 0xf7, 0xdb, 0xfc, 0x9c, 0x87, 0xe8, 0x3a, 0xf6, 0x1d, 0x4c, \ - 0x6a, 0x83, 0x15, 0x30, 0x01, 0x02, 0x81, 0x81, 0x00, 0x9c, 0x53, 0xa1, 0xb6, 0x2f, 0xc0, 0x06, 0xf5, \ - 0xdf, 0x5c, 0xd1, 0x4a, 0x4e, 0xc8, 0xbd, 0x6d, 0x32, 0xf1, 0x5e, 0xe5, 0x3b, 0x70, 0xd0, 0xa8, 0xe5, \ - 0x41, 0x57, 0x6c, 0x87, 0x53, 0x0f, 0xeb, 0x28, 0xa0, 0x62, 0x8f, 0x43, 0x62, 0xec, 0x2e, 0x6c, 0x71, \ - 0x55, 0x5b, 0x6a, 0xf4, 0x74, 0x14, 0xea, 0x7a, 0x03, 0xf6, 0xfc, 0xa4, 0xce, 0xc4, 0xac, 0xda, 0x1d, \ - 0xf0, 0xb5, 0xa9, 0xfd, 0x11, 0x18, 0x3b, 0x14, 0xa0, 0x90, 0x8d, 0x26, 0xb7, 0x75, 0x73, 0x0a, 0x02, \ - 0x2c, 0x6f, 0x0f, 0xd8, 0x41, 0x78, 0xc3, 0x73, 0x81, 0xac, 0xaa, 0xaf, 0xf2, 0xee, 0x32, 0xb5, 0x8d, \ - 0x05, 0xf9, 0x59, 0x5a, 0x9e, 0x3e, 0x65, 0x9b, 0x74, 0xda, 0xa0, 0x74, 0x95, 0x17, 0x5f, 0x8d, 0x58, \ - 0xfc, 0x8e, 0x4e, 0x2c, 0x1e, 0xbc, 0x81, 0x02, 0x18, 0xac, 0x12, 0xc6, 0xf9, 0x64, 0x8b, 0x87, 0xc3, 0x00 \ + 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc8, 0x74, 0xc4, 0xcc, 0xb9, 0xf9, 0xb5, 0x79, 0xe9, 0x45, 0xd9, \ + 0x14, 0x60, 0xb0, 0x7d, 0xbb, 0x93, 0xf2, 0x6b, 0x1e, 0x9f, 0x33, 0xad, 0x0d, 0x8f, 0x8a, 0x3c, 0x56, 0x65, 0xe5, 0xdc, 0x44, 0xd9, \ + 0xcc, 0x66, 0x85, 0x07, 0xd5, 0xf8, 0x27, 0xb0, 0x4a, 0x35, 0xd0, 0x63, 0x9e, 0x0a, 0x6e, 0x1b, 0xb7, 0xda, 0xf0, 0x7e, 0xab, 0xee, \ + 0x0c, 0x10, 0x93, 0x86, 0x49, 0x18, 0x34, 0xf3, 0xa8, 0x2a, 0xd2, 0x57, 0xf5, 0x2e, 0xd4, 0x2f, 0x77, 0x29, 0x84, 0x61, 0x4d, 0x82, \ + 0x50, 0x8f, 0xa7, 0x95, 0x48, 0x70, 0xf5, 0x6e, 0x4d, 0xb2, 0xd5, 0x13, 0xc3, 0xd2, 0x1a, 0xed, 0xe6, 0x43, 0xea, 0x42, 0x14, 0xeb, \ + 0x74, 0xea, 0xc0, 0xed, 0x1f, 0xd4, 0x57, 0x4e, 0xa9, 0xf3, 0xa8, 0xed, 0xd2, 0xe0, 0xc1, 0x30, 0x71, 0x30, 0x32, 0x30, 0xd5, 0xd3, \ + 0xf6, 0x08, 0xd0, 0x56, 0x4f, 0x46, 0x8e, 0xf2, 0x5f, 0xf9, 0x3d, 0x67, 0x91, 0x88, 0x30, 0x2e, 0x42, 0xb2, 0xdf, 0x7d, 0xfb, 0xe5, \ + 0x0c, 0x77, 0xff, 0xec, 0x31, 0xc0, 0x78, 0x8f, 0xbf, 0xc2, 0x7f, 0xca, 0xad, 0x6c, 0x21, 0xd6, 0x8d, 0xd9, 0x8b, 0x6a, 0x8e, 0x6f, \ + 0xe0, 0x9b, 0xf8, 0x10, 0x56, 0xcc, 0xb3, 0x8e, 0x13, 0x15, 0xe6, 0x34, 0x04, 0x66, 0xc7, 0xee, 0xf9, 0x36, 0x0e, 0x6a, 0x95, 0xf6, \ + 0x09, 0x9a, 0x06, 0x67, 0xf4, 0x65, 0x71, 0xf8, 0xca, 0xa4, 0xb1, 0x25, 0xe0, 0xfe, 0x3c, 0x8b, 0x35, 0x04, 0x67, 0xba, 0xe0, 0x4f, \ + 0x76, 0x85, 0xfc, 0x7f, 0xfc, 0x36, 0x6b, 0xb5, 0xe9, 0xcd, 0x2d, 0x03, 0x62, 0x4e, 0xb3, 0x3d, 0x00, 0xcf, 0xaf, 0x76, 0xa0, 0x69, \ + 0x56, 0x83, 0x6a, 0xd2, 0xa8, 0xd4, 0xe7, 0x50, 0x71, 0xe6, 0xb5, 0x36, 0x05, 0x77, 0x05, 0x6d, 0x7b, 0xc8, 0xe4, 0xc4, 0xfd, 0x4c, \ + 0xd5, 0x21, 0x5f, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, 0x00, 0x67, 0x4d, 0xb5, 0xf6, 0x03, 0x89, 0xaa, 0x7a, 0x6f, 0x3b, \ + 0x2d, 0xca, 0x10, 0xa2, 0x23, 0xc9, 0xbd, 0x4e, 0xda, 0xe1, 0x67, 0x0e, 0x0c, 0x8a, 0xc6, 0x84, 0x68, 0xdf, 0xe5, 0x97, 0x75, 0xd2, \ + 0x8d, 0xa3, 0x86, 0xd9, 0xdb, 0xd5, 0xeb, 0x13, 0x19, 0x08, 0xc5, 0x7e, 0xe5, 0x37, 0x97, 0x0c, 0x73, 0x80, 0x66, 0x76, 0x35, 0xf1, \ + 0x88, 0xb5, 0xf2, 0xfc, 0xf3, 0xe1, 0x4b, 0x76, 0x4e, 0x73, 0x45, 0xce, 0x2c, 0xc2, 0x10, 0x26, 0x0d, 0x68, 0x0d, 0x9f, 0x49, 0x3d, \ + 0xd6, 0x80, 0x89, 0xe7, 0xc5, 0x49, 0x15, 0xdd, 0x85, 0xc0, 0xc8, 0xfe, 0x82, 0x37, 0x12, 0x5a, 0x0a, 0x6b, 0xf6, 0x68, 0x0d, 0x32, \ + 0x16, 0xbd, 0xa4, 0x15, 0x54, 0x9e, 0x68, 0xa1, 0xad, 0xca, 0x6b, 0xe5, 0x8c, 0xda, 0x76, 0x35, 0x59, 0x2f, 0x9b, 0xb4, 0xe1, 0xf1, \ + 0xf0, 0x50, 0x04, 0xee, 0xc8, 0xec, 0x05, 0xe1, 0xcf, 0x8d, 0xe4, 0xd2, 0x64, 0x7b, 0x5e, 0x63, 0xe0, 0x7b, 0x07, 0xbc, 0x02, 0x96, \ + 0x4e, 0x1b, 0x78, 0x6c, 0xb6, 0x43, 0x9a, 0x32, 0xf6, 0xd6, 0x02, 0xf5, 0x80, 0xcc, 0x26, 0x6e, 0xa5, 0xd0, 0xe3, 0x65, 0x88, 0xce, \ + 0x26, 0xa9, 0x40, 0xe1, 0xe1, 0x00, 0xe0, 0x7f, 0x3f, 0xc3, 0xb1, 0x7c, 0xde, 0xbe, 0x42, 0xba, 0x07, 0x81, 0x13, 0xc2, 0xe0, 0x11, \ + 0x11, 0x23, 0x2c, 0xf8, 0xb2, 0x7a, 0x3a, 0xd4, 0xe4, 0x7d, 0x5f, 0xb9, 0xb1, 0x18, 0xfa, 0x1d, 0x1d, 0x97, 0x91, 0xd9, 0x04, 0x9e, \ + 0xbc, 0xc9, 0xb4, 0xd7, 0x7d, 0x0e, 0x54, 0xf6, 0x8f, 0xd0, 0x28, 0x0d, 0xdd, 0x77, 0x4b, 0x68, 0x04, 0x48, 0x61, 0x75, 0x15, 0x03, \ + 0x1b, 0x35, 0xad, 0x8e, 0xfc, 0x24, 0x11, 0x07, 0xea, 0x17, 0x5a, 0xde, 0x19, 0x68, 0xff, 0xb6, 0x87, 0x7f, 0x80, 0x2a, 0x5f, 0x0c, \ + 0x58, 0xba, 0x5f, 0x41, 0x02, 0x81, 0x81, 0x00, 0xe3, 0x03, 0xaf, 0xfe, 0x98, 0xd2, 0x0b, 0x7b, 0x72, 0xe9, 0x3b, 0x8e, 0xbc, 0xa5, \ + 0xf6, 0xac, 0xe5, 0x22, 0x06, 0xb2, 0xd7, 0x5e, 0xfd, 0x89, 0x4b, 0x16, 0x67, 0x32, 0x83, 0x22, 0x58, 0x8e, 0x62, 0xa4, 0xb4, 0x2d, \ + 0xf9, 0x16, 0x13, 0x54, 0xf6, 0x9f, 0x2f, 0xf9, 0xbb, 0x0e, 0x7e, 0x8c, 0x6f, 0x08, 0xda, 0xc8, 0xe9, 0x1c, 0x66, 0x10, 0x70, 0x93, \ + 0x90, 0x8d, 0xcf, 0x90, 0x3a, 0x43, 0x89, 0x49, 0xeb, 0x83, 0x2a, 0xfe, 0x5a, 0x87, 0xce, 0x74, 0x42, 0x41, 0x0d, 0x8c, 0x73, 0x51, \ + 0xbc, 0x7b, 0x20, 0xc5, 0xfd, 0xf6, 0x0b, 0x65, 0xed, 0xa9, 0x2e, 0xfc, 0x0f, 0xf5, 0x50, 0xf9, 0x8d, 0x37, 0x36, 0x9a, 0x20, 0xdf, \ + 0xc3, 0xe3, 0x27, 0xbc, 0x98, 0x72, 0xc1, 0x14, 0x4b, 0x71, 0xe9, 0x83, 0x14, 0xff, 0x24, 0xe2, 0x14, 0x15, 0xb6, 0x6f, 0x0f, 0x32, \ + 0x9d, 0xd9, 0x98, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xe2, 0x0c, 0xfb, 0xc3, 0x33, 0x9b, 0x47, 0x88, 0x27, 0xf2, 0x26, 0xde, 0xeb, 0x5e, \ + 0xee, 0x40, 0xf6, 0x63, 0x5b, 0x35, 0x23, 0xf5, 0xd5, 0x07, 0x61, 0xdf, 0xa2, 0x9f, 0x58, 0x30, 0x04, 0x22, 0x2b, 0xb4, 0xd9, 0xda, \ + 0x46, 0x7f, 0x48, 0xf5, 0x4f, 0xd0, 0xea, 0xd7, 0xa0, 0x45, 0x8a, 0x62, 0x8b, 0x8c, 0xac, 0x73, 0x5e, 0xfa, 0x36, 0x65, 0x3e, 0xba, \ + 0x6c, 0xba, 0x5e, 0x6b, 0x92, 0x29, 0x5e, 0x6a, 0x0f, 0xd6, 0xd2, 0xa5, 0x95, 0x86, 0xda, 0x72, 0xc5, 0x9e, 0xc9, 0x6b, 0x37, 0x5e, \ + 0x4b, 0x9b, 0x77, 0xe1, 0x67, 0x1a, 0x1e, 0x30, 0xd8, 0x41, 0x68, 0x40, 0xd3, 0x9c, 0xb4, 0xf6, 0xeb, 0x2a, 0x22, 0xdf, 0x78, 0x29, \ + 0xd2, 0x64, 0x92, 0x5b, 0x2f, 0x78, 0x64, 0x4a, 0xa2, 0xa6, 0x6b, 0x3e, 0x50, 0xb1, 0x7a, 0xb1, 0x8d, 0x59, 0xb4, 0x55, 0xba, 0xb6, \ + 0x91, 0x85, 0xa3, 0x2f, 0x02, 0x81, 0x80, 0x10, 0x1e, 0x19, 0xe7, 0xbc, 0x97, 0xe5, 0x22, 0xcd, 0xa4, 0xcb, 0x8a, 0xb5, 0xd0, 0x1e, \ + 0xb4, 0x65, 0xcc, 0x45, 0xa7, 0x7a, 0xed, 0x0e, 0x99, 0x29, 0xd0, 0x9c, 0x61, 0x14, 0xb8, 0x62, 0x8b, 0x31, 0x6b, 0xba, 0x33, 0x2d, \ + 0x65, 0x28, 0xd8, 0x36, 0x6e, 0x54, 0xec, 0xa9, 0x20, 0x3d, 0x51, 0xe1, 0x2c, 0x42, 0xc4, 0x52, 0xf0, 0xa6, 0x3a, 0x72, 0x93, 0xb7, \ + 0x86, 0xa9, 0xfe, 0xf6, 0x74, 0x07, 0x12, 0x4d, 0x7b, 0x51, 0x99, 0x1f, 0x7a, 0x56, 0xe9, 0x20, 0x2f, 0x18, 0x34, 0x29, 0x97, 0xdb, \ + 0x06, 0xee, 0xeb, 0xbf, 0xbd, 0x31, 0x4f, 0xfa, 0x50, 0xb1, 0xba, 0x49, 0xb3, 0xc4, 0x1d, 0x03, 0xae, 0xb0, 0xdc, 0xbe, 0x8a, 0xc4, \ + 0x90, 0xa3, 0x28, 0x9b, 0xb6, 0x42, 0x09, 0x1b, 0xd6, 0x29, 0x9b, 0x19, 0xe9, 0x87, 0x87, 0xd9, 0x9f, 0x35, 0x05, 0xab, 0x91, 0x8f, \ + 0x6d, 0x7c, 0x91, 0x02, 0x81, 0x81, 0x00, 0x94, 0x57, 0xf0, 0xe0, 0x28, 0xfd, 0xbd, 0xf3, 0x9c, 0x43, 0x4d, 0x3e, 0xfd, 0x37, 0x4f, \ + 0x23, 0x52, 0x8d, 0xe1, 0x4c, 0xfe, 0x4c, 0x55, 0x80, 0x82, 0xba, 0x3f, 0xfe, 0x51, 0xe1, 0x30, 0xd5, 0x3b, 0xd9, 0x73, 0x1d, 0xcb, \ + 0x25, 0xbc, 0xbb, 0x3f, 0xa5, 0xda, 0x77, 0xa6, 0xb5, 0xfc, 0x1a, 0xaf, 0x79, 0xa1, 0xb2, 0x14, 0xa2, 0x1f, 0x10, 0x52, 0x1a, 0x05, \ + 0x40, 0x48, 0xb6, 0x4f, 0x34, 0xd6, 0xc0, 0xc3, 0xa4, 0x36, 0x98, 0x73, 0x88, 0x0b, 0xd3, 0x45, 0xdc, 0xee, 0x51, 0x6e, 0x04, 0x73, \ + 0x99, 0x93, 0x12, 0x58, 0x96, 0xcb, 0x39, 0x42, 0xb1, 0xa9, 0xb8, 0xe1, 0x25, 0xf5, 0x9c, 0x14, 0xb7, 0x92, 0x2b, 0x14, 0xb0, 0x5d, \ + 0x61, 0xa2, 0xaa, 0x34, 0x7c, 0xcd, 0x54, 0x2d, 0x69, 0x08, 0xf7, 0xdb, 0xfc, 0x9c, 0x87, 0xe8, 0x3a, 0xf6, 0x1d, 0x4c, 0x6a, 0x83, \ + 0x15, 0x30, 0x01, 0x02, 0x81, 0x81, 0x00, 0x9c, 0x53, 0xa1, 0xb6, 0x2f, 0xc0, 0x06, 0xf5, 0xdf, 0x5c, 0xd1, 0x4a, 0x4e, 0xc8, 0xbd, \ + 0x6d, 0x32, 0xf1, 0x5e, 0xe5, 0x3b, 0x70, 0xd0, 0xa8, 0xe5, 0x41, 0x57, 0x6c, 0x87, 0x53, 0x0f, 0xeb, 0x28, 0xa0, 0x62, 0x8f, 0x43, \ + 0x62, 0xec, 0x2e, 0x6c, 0x71, 0x55, 0x5b, 0x6a, 0xf4, 0x74, 0x14, 0xea, 0x7a, 0x03, 0xf6, 0xfc, 0xa4, 0xce, 0xc4, 0xac, 0xda, 0x1d, \ + 0xf0, 0xb5, 0xa9, 0xfd, 0x11, 0x18, 0x3b, 0x14, 0xa0, 0x90, 0x8d, 0x26, 0xb7, 0x75, 0x73, 0x0a, 0x02, 0x2c, 0x6f, 0x0f, 0xd8, 0x41, \ + 0x78, 0xc3, 0x73, 0x81, 0xac, 0xaa, 0xaf, 0xf2, 0xee, 0x32, 0xb5, 0x8d, 0x05, 0xf9, 0x59, 0x5a, 0x9e, 0x3e, 0x65, 0x9b, 0x74, 0xda, \ + 0xa0, 0x74, 0x95, 0x17, 0x5f, 0x8d, 0x58, 0xfc, 0x8e, 0x4e, 0x2c, 0x1e, 0xbc, 0x81, 0x02, 0x18, 0xac, 0x12, 0xc6, 0xf9, 0x64, 0x8b, \ + 0x87, 0xc3, 0x00 \ } /* END FILE */ diff --git a/nettls/ssl/chacha20.c b/nettls/ssl/chacha20.c index c5af3911a3bdf7ff3d6ceceb91068cbb5f044006..328d34495a3af932de96efe3b27786ac3ab69073 100644 --- a/nettls/ssl/chacha20.c +++ b/nettls/ssl/chacha20.c @@ -82,8 +82,8 @@ #define CHACHA20_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) #define BYTES_TO_U32_LE(data, offset) \ - ((uint32_t)(data)[offset] | (uint32_t)((uint32_t)(data)[(offset) + 1] << 8) \ - | (uint32_t)((uint32_t)(data)[(offset) + 2] << 16) | (uint32_t)((uint32_t)(data)[(offset) + 3] << 24)) + ((uint32_t)(data)[offset] | (uint32_t)((uint32_t)(data)[(offset) + 1] << 8) | (uint32_t)((uint32_t)(data)[(offset) + 2] << 16) \ + | (uint32_t)((uint32_t)(data)[(offset) + 3] << 24)) #define ROTL32(value, amount) ((uint32_t)((value) << (amount)) | ((value) >> (32 - (amount)))) @@ -258,8 +258,7 @@ int mbedtls_chacha20_starts(mbedtls_chacha20_context* ctx, const unsigned char n return (0); } -int mbedtls_chacha20_update( - mbedtls_chacha20_context* ctx, size_t size, const unsigned char* input, unsigned char* output) +int mbedtls_chacha20_update(mbedtls_chacha20_context* ctx, size_t size, const unsigned char* input, unsigned char* output) { size_t offset = 0U; size_t i; @@ -315,12 +314,7 @@ int mbedtls_chacha20_update( } int mbedtls_chacha20_crypt( - const unsigned char key[32], - const unsigned char nonce[12], - uint32_t counter, - size_t data_len, - const unsigned char* input, - unsigned char* output) + const unsigned char key[32], const unsigned char nonce[12], uint32_t counter, size_t data_len, const unsigned char* input, unsigned char* output) { mbedtls_chacha20_context ctx; int ret; @@ -366,57 +360,47 @@ static const unsigned char test_nonces[2][12] = { static const uint32_t test_counters[2] = {0U, 1U}; static const unsigned char test_input[2][375] = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - { 0x41, 0x6e, 0x79, 0x20, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x61, 0x6c, - 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x20, 0x49, 0x45, 0x54, - 0x46, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x20, 0x6f, 0x72, - 0x20, 0x52, 0x46, 0x43, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, - 0x65, 0x6e, 0x74, 0x20, 0x6d, 0x61, 0x64, 0x65, 0x20, 0x77, 0x69, 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x20, 0x49, 0x45, 0x54, 0x46, - 0x20, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, - 0x65, 0x72, 0x65, 0x64, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x49, 0x45, 0x54, 0x46, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, - 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x2e, 0x20, 0x53, 0x75, 0x63, 0x68, 0x20, 0x73, 0x74, 0x61, 0x74, - 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x6f, 0x72, 0x61, 0x6c, - 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x49, 0x45, 0x54, 0x46, - 0x20, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x61, 0x73, 0x20, 0x77, 0x65, 0x6c, 0x6c, 0x20, - 0x61, 0x73, 0x20, 0x77, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x65, 0x6c, 0x65, 0x63, - 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x20, 0x6d, 0x61, 0x64, 0x65, 0x20, 0x61, 0x74, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, - 0x20, 0x6f, 0x72, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2c, 0x20, 0x77, 0x68, 0x69, 0x63, 0x68, 0x20, 0x61, 0x72, - 0x65, 0x20, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f} + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0x41, 0x6e, 0x79, 0x20, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x49, 0x45, + 0x54, 0x46, 0x20, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, 0x68, 0x65, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, + 0x69, 0x62, 0x75, 0x74, 0x6f, 0x72, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, + 0x73, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x70, 0x61, 0x72, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x20, 0x49, 0x45, 0x54, 0x46, + 0x20, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x52, 0x46, 0x43, 0x20, 0x61, + 0x6e, 0x64, 0x20, 0x61, 0x6e, 0x79, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x6d, 0x61, 0x64, 0x65, 0x20, 0x77, 0x69, + 0x74, 0x68, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x6e, 0x20, 0x49, + 0x45, 0x54, 0x46, 0x20, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x72, + 0x65, 0x64, 0x20, 0x61, 0x6e, 0x20, 0x22, 0x49, 0x45, 0x54, 0x46, 0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, + 0x22, 0x2e, 0x20, 0x53, 0x75, 0x63, 0x68, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x69, 0x6e, 0x63, 0x6c, 0x75, + 0x64, 0x65, 0x20, 0x6f, 0x72, 0x61, 0x6c, 0x20, 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x20, 0x69, 0x6e, 0x20, 0x49, 0x45, + 0x54, 0x46, 0x20, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2c, 0x20, 0x61, 0x73, 0x20, 0x77, 0x65, 0x6c, 0x6c, 0x20, 0x61, 0x73, 0x20, + 0x77, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x72, 0x6f, 0x6e, 0x69, 0x63, 0x20, 0x63, + 0x6f, 0x6d, 0x6d, 0x75, 0x6e, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x6d, 0x61, 0x64, 0x65, 0x20, 0x61, 0x74, 0x20, 0x61, 0x6e, + 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x2c, 0x20, 0x77, 0x68, 0x69, 0x63, 0x68, 0x20, 0x61, + 0x72, 0x65, 0x20, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x20, 0x74, 0x6f} }; static const unsigned char test_output[2][375] = { - {0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, - 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, - 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, - 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86}, - { 0xa3, 0xfb, 0xf0, 0x7d, 0xf3, 0xfa, 0x2f, 0xde, 0x4f, 0x37, 0x6c, 0xa2, 0x3e, 0x82, 0x73, 0x70, 0x41, 0x60, 0x5d, - 0x9f, 0x4f, 0x4f, 0x57, 0xbd, 0x8c, 0xff, 0x2c, 0x1d, 0x4b, 0x79, 0x55, 0xec, 0x2a, 0x97, 0x94, 0x8b, 0xd3, 0x72, - 0x29, 0x15, 0xc8, 0xf3, 0xd3, 0x37, 0xf7, 0xd3, 0x70, 0x05, 0x0e, 0x9e, 0x96, 0xd6, 0x47, 0xb7, 0xc3, 0x9f, 0x56, - 0xe0, 0x31, 0xca, 0x5e, 0xb6, 0x25, 0x0d, 0x40, 0x42, 0xe0, 0x27, 0x85, 0xec, 0xec, 0xfa, 0x4b, 0x4b, 0xb5, 0xe8, - 0xea, 0xd0, 0x44, 0x0e, 0x20, 0xb6, 0xe8, 0xdb, 0x09, 0xd8, 0x81, 0xa7, 0xc6, 0x13, 0x2f, 0x42, 0x0e, 0x52, 0x79, - 0x50, 0x42, 0xbd, 0xfa, 0x77, 0x73, 0xd8, 0xa9, 0x05, 0x14, 0x47, 0xb3, 0x29, 0x1c, 0xe1, 0x41, 0x1c, 0x68, 0x04, - 0x65, 0x55, 0x2a, 0xa6, 0xc4, 0x05, 0xb7, 0x76, 0x4d, 0x5e, 0x87, 0xbe, 0xa8, 0x5a, 0xd0, 0x0f, 0x84, 0x49, 0xed, - 0x8f, 0x72, 0xd0, 0xd6, 0x62, 0xab, 0x05, 0x26, 0x91, 0xca, 0x66, 0x42, 0x4b, 0xc8, 0x6d, 0x2d, 0xf8, 0x0e, 0xa4, - 0x1f, 0x43, 0xab, 0xf9, 0x37, 0xd3, 0x25, 0x9d, 0xc4, 0xb2, 0xd0, 0xdf, 0xb4, 0x8a, 0x6c, 0x91, 0x39, 0xdd, 0xd7, - 0xf7, 0x69, 0x66, 0xe9, 0x28, 0xe6, 0x35, 0x55, 0x3b, 0xa7, 0x6c, 0x5c, 0x87, 0x9d, 0x7b, 0x35, 0xd4, 0x9e, 0xb2, - 0xe6, 0x2b, 0x08, 0x71, 0xcd, 0xac, 0x63, 0x89, 0x39, 0xe2, 0x5e, 0x8a, 0x1e, 0x0e, 0xf9, 0xd5, 0x28, 0x0f, 0xa8, - 0xca, 0x32, 0x8b, 0x35, 0x1c, 0x3c, 0x76, 0x59, 0x89, 0xcb, 0xcf, 0x3d, 0xaa, 0x8b, 0x6c, 0xcc, 0x3a, 0xaf, 0x9f, - 0x39, 0x79, 0xc9, 0x2b, 0x37, 0x20, 0xfc, 0x88, 0xdc, 0x95, 0xed, 0x84, 0xa1, 0xbe, 0x05, 0x9c, 0x64, 0x99, 0xb9, - 0xfd, 0xa2, 0x36, 0xe7, 0xe8, 0x18, 0xb0, 0x4b, 0x0b, 0xc3, 0x9c, 0x1e, 0x87, 0x6b, 0x19, 0x3b, 0xfe, 0x55, 0x69, - 0x75, 0x3f, 0x88, 0x12, 0x8c, 0xc0, 0x8a, 0xaa, 0x9b, 0x63, 0xd1, 0xa1, 0x6f, 0x80, 0xef, 0x25, 0x54, 0xd7, 0x18, - 0x9c, 0x41, 0x1f, 0x58, 0x69, 0xca, 0x52, 0xc5, 0xb8, 0x3f, 0xa3, 0x6f, 0xf2, 0x16, 0xb9, 0xc1, 0xd3, 0x00, 0x62, - 0xbe, 0xbc, 0xfd, 0x2d, 0xc5, 0xbc, 0xe0, 0x91, 0x19, 0x34, 0xfd, 0xa7, 0x9a, 0x86, 0xf6, 0xe6, 0x98, 0xce, 0xd7, - 0x59, 0xc3, 0xff, 0x9b, 0x64, 0x77, 0x33, 0x8f, 0x3d, 0xa4, 0xf9, 0xcd, 0x85, 0x14, 0xea, 0x99, 0x82, 0xcc, 0xaf, - 0xb3, 0x41, 0xb2, 0x38, 0x4d, 0xd9, 0x02, 0xf3, 0xd1, 0xab, 0x7a, 0xc6, 0x1d, 0xd2, 0x9c, 0x6f, 0x21, 0xba, 0x5b, - 0x86, 0x2f, 0x37, 0x30, 0xe3, 0x7c, 0xfd, 0xc4, 0xfd, 0x80, 0x6c, 0x22, 0xf2, 0x21} + {0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, + 0xed, 0x1a, 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, 0x77, 0x24, 0xe0, 0x3f, + 0xb8, 0xd8, 0x4a, 0x37, 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86}, + {0xa3, 0xfb, 0xf0, 0x7d, 0xf3, 0xfa, 0x2f, 0xde, 0x4f, 0x37, 0x6c, 0xa2, 0x3e, 0x82, 0x73, 0x70, 0x41, 0x60, 0x5d, 0x9f, 0x4f, 0x4f, 0x57, 0xbd, + 0x8c, 0xff, 0x2c, 0x1d, 0x4b, 0x79, 0x55, 0xec, 0x2a, 0x97, 0x94, 0x8b, 0xd3, 0x72, 0x29, 0x15, 0xc8, 0xf3, 0xd3, 0x37, 0xf7, 0xd3, 0x70, 0x05, + 0x0e, 0x9e, 0x96, 0xd6, 0x47, 0xb7, 0xc3, 0x9f, 0x56, 0xe0, 0x31, 0xca, 0x5e, 0xb6, 0x25, 0x0d, 0x40, 0x42, 0xe0, 0x27, 0x85, 0xec, 0xec, 0xfa, + 0x4b, 0x4b, 0xb5, 0xe8, 0xea, 0xd0, 0x44, 0x0e, 0x20, 0xb6, 0xe8, 0xdb, 0x09, 0xd8, 0x81, 0xa7, 0xc6, 0x13, 0x2f, 0x42, 0x0e, 0x52, 0x79, 0x50, + 0x42, 0xbd, 0xfa, 0x77, 0x73, 0xd8, 0xa9, 0x05, 0x14, 0x47, 0xb3, 0x29, 0x1c, 0xe1, 0x41, 0x1c, 0x68, 0x04, 0x65, 0x55, 0x2a, 0xa6, 0xc4, 0x05, + 0xb7, 0x76, 0x4d, 0x5e, 0x87, 0xbe, 0xa8, 0x5a, 0xd0, 0x0f, 0x84, 0x49, 0xed, 0x8f, 0x72, 0xd0, 0xd6, 0x62, 0xab, 0x05, 0x26, 0x91, 0xca, 0x66, + 0x42, 0x4b, 0xc8, 0x6d, 0x2d, 0xf8, 0x0e, 0xa4, 0x1f, 0x43, 0xab, 0xf9, 0x37, 0xd3, 0x25, 0x9d, 0xc4, 0xb2, 0xd0, 0xdf, 0xb4, 0x8a, 0x6c, 0x91, + 0x39, 0xdd, 0xd7, 0xf7, 0x69, 0x66, 0xe9, 0x28, 0xe6, 0x35, 0x55, 0x3b, 0xa7, 0x6c, 0x5c, 0x87, 0x9d, 0x7b, 0x35, 0xd4, 0x9e, 0xb2, 0xe6, 0x2b, + 0x08, 0x71, 0xcd, 0xac, 0x63, 0x89, 0x39, 0xe2, 0x5e, 0x8a, 0x1e, 0x0e, 0xf9, 0xd5, 0x28, 0x0f, 0xa8, 0xca, 0x32, 0x8b, 0x35, 0x1c, 0x3c, 0x76, + 0x59, 0x89, 0xcb, 0xcf, 0x3d, 0xaa, 0x8b, 0x6c, 0xcc, 0x3a, 0xaf, 0x9f, 0x39, 0x79, 0xc9, 0x2b, 0x37, 0x20, 0xfc, 0x88, 0xdc, 0x95, 0xed, 0x84, + 0xa1, 0xbe, 0x05, 0x9c, 0x64, 0x99, 0xb9, 0xfd, 0xa2, 0x36, 0xe7, 0xe8, 0x18, 0xb0, 0x4b, 0x0b, 0xc3, 0x9c, 0x1e, 0x87, 0x6b, 0x19, 0x3b, 0xfe, + 0x55, 0x69, 0x75, 0x3f, 0x88, 0x12, 0x8c, 0xc0, 0x8a, 0xaa, 0x9b, 0x63, 0xd1, 0xa1, 0x6f, 0x80, 0xef, 0x25, 0x54, 0xd7, 0x18, 0x9c, 0x41, 0x1f, + 0x58, 0x69, 0xca, 0x52, 0xc5, 0xb8, 0x3f, 0xa3, 0x6f, 0xf2, 0x16, 0xb9, 0xc1, 0xd3, 0x00, 0x62, 0xbe, 0xbc, 0xfd, 0x2d, 0xc5, 0xbc, 0xe0, 0x91, + 0x19, 0x34, 0xfd, 0xa7, 0x9a, 0x86, 0xf6, 0xe6, 0x98, 0xce, 0xd7, 0x59, 0xc3, 0xff, 0x9b, 0x64, 0x77, 0x33, 0x8f, 0x3d, 0xa4, 0xf9, 0xcd, 0x85, + 0x14, 0xea, 0x99, 0x82, 0xcc, 0xaf, 0xb3, 0x41, 0xb2, 0x38, 0x4d, 0xd9, 0x02, 0xf3, 0xd1, 0xab, 0x7a, 0xc6, 0x1d, 0xd2, 0x9c, 0x6f, 0x21, 0xba, + 0x5b, 0x86, 0x2f, 0x37, 0x30, 0xe3, 0x7c, 0xfd, 0xc4, 0xfd, 0x80, 0x6c, 0x22, 0xf2, 0x21} }; static const size_t test_lengths[2] = {64U, 375U}; @@ -441,8 +425,7 @@ int mbedtls_chacha20_self_test(int verbose) if (verbose != 0) mbedtls_printf(" ChaCha20 test %u ", i); - ret = mbedtls_chacha20_crypt( - test_keys[i], test_nonces[i], test_counters[i], test_lengths[i], test_input[i], output); + ret = mbedtls_chacha20_crypt(test_keys[i], test_nonces[i], test_counters[i], test_lengths[i], test_input[i], output); ASSERT(0 == ret, ("error code: %i\n", ret)); diff --git a/nettls/ssl/chachapoly.c b/nettls/ssl/chachapoly.c index 6fba5b0a2624c35924bd2e90eefe3969289ba0bd..b4b9c160e04c0ac071b2ef3130f24cf9a2ceb812 100644 --- a/nettls/ssl/chachapoly.c +++ b/nettls/ssl/chachapoly.c @@ -149,8 +149,7 @@ int mbedtls_chachapoly_setkey(mbedtls_chachapoly_context* ctx, const unsigned ch return (ret); } -int mbedtls_chachapoly_starts( - mbedtls_chachapoly_context* ctx, const unsigned char nonce[12], mbedtls_chachapoly_mode_t mode) +int mbedtls_chachapoly_starts(mbedtls_chachapoly_context* ctx, const unsigned char nonce[12], mbedtls_chachapoly_mode_t mode) { int ret; unsigned char poly1305_key[64]; @@ -199,8 +198,7 @@ int mbedtls_chachapoly_update_aad(mbedtls_chachapoly_context* ctx, const unsigne return (mbedtls_poly1305_update(&ctx->poly1305_ctx, aad, aad_len)); } -int mbedtls_chachapoly_update( - mbedtls_chachapoly_context* ctx, size_t len, const unsigned char* input, unsigned char* output) +int mbedtls_chachapoly_update(mbedtls_chachapoly_context* ctx, size_t len, const unsigned char* input, unsigned char* output) { int ret; CHACHAPOLY_VALIDATE_RET(ctx != NULL); @@ -367,9 +365,7 @@ int mbedtls_chachapoly_auth_decrypt( CHACHAPOLY_VALIDATE_RET(length == 0 || input != NULL); CHACHAPOLY_VALIDATE_RET(length == 0 || output != NULL); - if ((ret = chachapoly_crypt_and_tag( - ctx, MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce, aad, aad_len, input, output, check_tag)) - != 0) { + if ((ret = chachapoly_crypt_and_tag(ctx, MBEDTLS_CHACHAPOLY_DECRYPT, length, nonce, aad, aad_len, input, output, check_tag)) != 0) { return (ret); } @@ -408,21 +404,19 @@ static const unsigned char test_aad[1][12] = { static const size_t test_aad_len[1] = {12U}; static const unsigned char test_input[1][114] = { - {0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, 0x65, 0x6d, 0x65, - 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, - 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, - 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, - 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, - 0x73, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, 0x74, 0x2e} + {0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, + 0x20, 0x63, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x20, 0x6f, + 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, + 0x73, 0x75, 0x6e, 0x73, 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, 0x74, 0x2e} }; static const unsigned char test_output[1][114] = { - {0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2, 0xa4, 0xad, 0xed, - 0x51, 0x29, 0x6e, 0x08, 0xfe, 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6, 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, - 0x67, 0x12, 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b, 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29, 0x05, - 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36, 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c, 0x98, 0x03, 0xae, 0xe3, - 0x28, 0x09, 0x1b, 0x58, 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94, 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, - 0xbc, 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d, 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b, 0x61, 0x16} + {0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb, 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2, 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, + 0xfe, 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6, 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12, 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, + 0x72, 0x8b, 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29, 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36, 0x92, 0xdd, 0xbd, 0x7f, 0x2d, + 0x77, 0x8b, 0x8c, 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58, 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94, 0x55, 0x85, 0x80, 0x8b, + 0x48, 0x31, 0xd7, 0xbc, 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d, 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b, 0x61, 0x16} }; static const size_t test_input_len[1] = {114U}; @@ -458,8 +452,7 @@ int mbedtls_chachapoly_self_test(int verbose) ret = mbedtls_chachapoly_setkey(&ctx, test_key[i]); ASSERT(0 == ret, ("setkey() error code: %i\n", ret)); - ret = mbedtls_chachapoly_encrypt_and_tag( - &ctx, test_input_len[i], test_nonce[i], test_aad[i], test_aad_len[i], test_input[i], output, mac); + ret = mbedtls_chachapoly_encrypt_and_tag(&ctx, test_input_len[i], test_nonce[i], test_aad[i], test_aad_len[i], test_input[i], output, mac); ASSERT(0 == ret, ("crypt_and_tag() error code: %i\n", ret)); diff --git a/nettls/ssl/cipher.c b/nettls/ssl/cipher.c index 793aa28957705295e9bc1ccdfe7dd45a28d495f7..6073cee70397cffe6cbe3600f67f7c4a5a85bf3c 100644 --- a/nettls/ssl/cipher.c +++ b/nettls/ssl/cipher.c @@ -160,14 +160,12 @@ const mbedtls_cipher_info_t* mbedtls_cipher_info_from_string(const char* cipher_ return (NULL); } -const mbedtls_cipher_info_t* mbedtls_cipher_info_from_values( - const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode) +const mbedtls_cipher_info_t* mbedtls_cipher_info_from_values(const mbedtls_cipher_id_t cipher_id, int key_bitlen, const mbedtls_cipher_mode_t mode) { const mbedtls_cipher_definition_t* def; for (def = mbedtls_cipher_definitions; def->info != NULL; def++) - if (def->info->base->cipher == cipher_id && def->info->key_bitlen == (unsigned)key_bitlen - && def->info->mode == mode) + if (def->info->base->cipher == cipher_id && def->info->key_bitlen == (unsigned)key_bitlen && def->info->mode == mode) return (def->info); return (NULL); @@ -224,8 +222,7 @@ int mbedtls_cipher_setup(mbedtls_cipher_context_t* ctx, const mbedtls_cipher_inf return (0); } -int mbedtls_cipher_setkey( - mbedtls_cipher_context_t* ctx, const unsigned char* key, int key_bitlen, const mbedtls_operation_t operation) +int mbedtls_cipher_setkey(mbedtls_cipher_context_t* ctx, const unsigned char* key, int key_bitlen, const mbedtls_operation_t operation) { CIPHER_VALIDATE_RET(ctx != NULL); CIPHER_VALIDATE_RET(key != NULL); @@ -233,8 +230,7 @@ int mbedtls_cipher_setkey( if (ctx->cipher_info == NULL) return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); - if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN) == 0 - && (int)ctx->cipher_info->key_bitlen != key_bitlen) { + if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN) == 0 && (int)ctx->cipher_info->key_bitlen != key_bitlen) { return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } @@ -244,8 +240,8 @@ int mbedtls_cipher_setkey( /* * For OFB, CFB and CTR mode always use the encryption key schedule */ - if (MBEDTLS_ENCRYPT == operation || MBEDTLS_MODE_CFB == ctx->cipher_info->mode - || MBEDTLS_MODE_OFB == ctx->cipher_info->mode || MBEDTLS_MODE_CTR == ctx->cipher_info->mode) { + if (MBEDTLS_ENCRYPT == operation || MBEDTLS_MODE_CFB == ctx->cipher_info->mode || MBEDTLS_MODE_OFB == ctx->cipher_info->mode + || MBEDTLS_MODE_CTR == ctx->cipher_info->mode) { return (ctx->cipher_info->base->setkey_enc_func(ctx->cipher_ctx, key, ctx->key_bitlen)); } @@ -280,8 +276,7 @@ int mbedtls_cipher_set_iv(mbedtls_cipher_context_t* ctx, const unsigned char* iv #if defined(MBEDTLS_CHACHA20_C) if (ctx->cipher_info->type == MBEDTLS_CIPHER_CHACHA20) { - if (0 - != mbedtls_chacha20_starts((mbedtls_chacha20_context*)ctx->cipher_ctx, iv, 0U)) /* Initial counter value */ + if (0 != mbedtls_chacha20_starts((mbedtls_chacha20_context*)ctx->cipher_ctx, iv, 0U)) /* Initial counter value */ { return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } @@ -317,8 +312,7 @@ int mbedtls_cipher_update_ad(mbedtls_cipher_context_t* ctx, const unsigned char* #if defined(MBEDTLS_GCM_C) if (MBEDTLS_MODE_GCM == ctx->cipher_info->mode) { - return (mbedtls_gcm_starts( - (mbedtls_gcm_context*)ctx->cipher_ctx, ctx->operation, ctx->iv, ctx->iv_size, ad, ad_len)); + return (mbedtls_gcm_starts((mbedtls_gcm_context*)ctx->cipher_ctx, ctx->operation, ctx->iv, ctx->iv_size, ad, ad_len)); } #endif @@ -341,8 +335,7 @@ int mbedtls_cipher_update_ad(mbedtls_cipher_context_t* ctx, const unsigned char* } #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ -int mbedtls_cipher_update( - mbedtls_cipher_context_t* ctx, const unsigned char* input, size_t ilen, unsigned char* output, size_t* olen) +int mbedtls_cipher_update(mbedtls_cipher_context_t* ctx, const unsigned char* input, size_t ilen, unsigned char* output, size_t* olen) { int ret; size_t block_size; @@ -399,8 +392,7 @@ int mbedtls_cipher_update( * If there is not enough data for a full block, cache it. */ if ((ctx->operation == MBEDTLS_DECRYPT && NULL != ctx->add_padding && ilen <= block_size - ctx->unprocessed_len) - || (ctx->operation == MBEDTLS_DECRYPT && NULL == ctx->add_padding - && ilen < block_size - ctx->unprocessed_len) + || (ctx->operation == MBEDTLS_DECRYPT && NULL == ctx->add_padding && ilen < block_size - ctx->unprocessed_len) || (ctx->operation == MBEDTLS_ENCRYPT && ilen < block_size - ctx->unprocessed_len)) { memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input, ilen); @@ -416,9 +408,7 @@ int mbedtls_cipher_update( memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input, copy_len); - if (0 - != (ret = ctx->cipher_info->base->cbc_func( - ctx->cipher_ctx, ctx->operation, block_size, ctx->iv, ctx->unprocessed_data, output))) { + if (0 != (ret = ctx->cipher_info->base->cbc_func(ctx->cipher_ctx, ctx->operation, block_size, ctx->iv, ctx->unprocessed_data, output))) { return (ret); } @@ -453,9 +443,7 @@ int mbedtls_cipher_update( * Process remaining full blocks */ if (ilen) { - if (0 - != (ret = ctx->cipher_info->base->cbc_func( - ctx->cipher_ctx, ctx->operation, ilen, ctx->iv, input, output))) { + if (0 != (ret = ctx->cipher_info->base->cbc_func(ctx->cipher_ctx, ctx->operation, ilen, ctx->iv, input, output))) { return (ret); } @@ -468,9 +456,7 @@ int mbedtls_cipher_update( #if defined(MBEDTLS_CIPHER_MODE_CFB) if (ctx->cipher_info->mode == MBEDTLS_MODE_CFB) { - if (0 - != (ret = ctx->cipher_info->base->cfb_func( - ctx->cipher_ctx, ctx->operation, ilen, &ctx->unprocessed_len, ctx->iv, input, output))) { + if (0 != (ret = ctx->cipher_info->base->cfb_func(ctx->cipher_ctx, ctx->operation, ilen, &ctx->unprocessed_len, ctx->iv, input, output))) { return (ret); } @@ -482,9 +468,7 @@ int mbedtls_cipher_update( #if defined(MBEDTLS_CIPHER_MODE_OFB) if (ctx->cipher_info->mode == MBEDTLS_MODE_OFB) { - if (0 - != (ret = ctx->cipher_info->base->ofb_func( - ctx->cipher_ctx, ilen, &ctx->unprocessed_len, ctx->iv, input, output))) { + if (0 != (ret = ctx->cipher_info->base->ofb_func(ctx->cipher_ctx, ilen, &ctx->unprocessed_len, ctx->iv, input, output))) { return (ret); } @@ -497,8 +481,8 @@ int mbedtls_cipher_update( #if defined(MBEDTLS_CIPHER_MODE_CTR) if (ctx->cipher_info->mode == MBEDTLS_MODE_CTR) { if (0 - != (ret = ctx->cipher_info->base->ctr_func( - ctx->cipher_ctx, ilen, &ctx->unprocessed_len, ctx->iv, ctx->unprocessed_data, input, output))) { + != (ret = + ctx->cipher_info->base->ctr_func(ctx->cipher_ctx, ilen, &ctx->unprocessed_len, ctx->iv, ctx->unprocessed_data, input, output))) { return (ret); } @@ -711,14 +695,13 @@ int mbedtls_cipher_finish(mbedtls_cipher_context_t* ctx, unsigned char* output, *olen = 0; - if (MBEDTLS_MODE_CFB == ctx->cipher_info->mode || MBEDTLS_MODE_OFB == ctx->cipher_info->mode - || MBEDTLS_MODE_CTR == ctx->cipher_info->mode || MBEDTLS_MODE_GCM == ctx->cipher_info->mode - || MBEDTLS_MODE_XTS == ctx->cipher_info->mode || MBEDTLS_MODE_STREAM == ctx->cipher_info->mode) { + if (MBEDTLS_MODE_CFB == ctx->cipher_info->mode || MBEDTLS_MODE_OFB == ctx->cipher_info->mode || MBEDTLS_MODE_CTR == ctx->cipher_info->mode + || MBEDTLS_MODE_GCM == ctx->cipher_info->mode || MBEDTLS_MODE_XTS == ctx->cipher_info->mode + || MBEDTLS_MODE_STREAM == ctx->cipher_info->mode) { return (0); } - if ((MBEDTLS_CIPHER_CHACHA20 == ctx->cipher_info->type) - || (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type)) { + if ((MBEDTLS_CIPHER_CHACHA20 == ctx->cipher_info->type) || (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type)) { return (0); } @@ -757,8 +740,7 @@ int mbedtls_cipher_finish(mbedtls_cipher_context_t* ctx, unsigned char* output, /* cipher block */ if (0 != (ret = ctx->cipher_info->base->cbc_func( - ctx->cipher_ctx, ctx->operation, mbedtls_cipher_get_block_size(ctx), ctx->iv, ctx->unprocessed_data, - output))) { + ctx->cipher_ctx, ctx->operation, mbedtls_cipher_get_block_size(ctx), ctx->iv, ctx->unprocessed_data, output))) { return (ret); } @@ -973,15 +955,13 @@ int mbedtls_cipher_auth_encrypt( #if defined(MBEDTLS_GCM_C) if (MBEDTLS_MODE_GCM == ctx->cipher_info->mode) { *olen = ilen; - return (mbedtls_gcm_crypt_and_tag( - ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT, ilen, iv, iv_len, ad, ad_len, input, output, tag_len, tag)); + return (mbedtls_gcm_crypt_and_tag(ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT, ilen, iv, iv_len, ad, ad_len, input, output, tag_len, tag)); } #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) if (MBEDTLS_MODE_CCM == ctx->cipher_info->mode) { *olen = ilen; - return ( - mbedtls_ccm_encrypt_and_tag(ctx->cipher_ctx, ilen, iv, iv_len, ad, ad_len, input, output, tag, tag_len)); + return (mbedtls_ccm_encrypt_and_tag(ctx->cipher_ctx, ilen, iv, iv_len, ad, ad_len, input, output, tag, tag_len)); } #endif /* MBEDTLS_CCM_C */ #if defined(MBEDTLS_CHACHAPOLY_C) diff --git a/nettls/ssl/cipher_wrap.c b/nettls/ssl/cipher_wrap.c index fe19557a2ffc6b2c69e11db1d22087981551f55b..057f682b341fbcc7d74455151c63fd4fbc952b33 100644 --- a/nettls/ssl/cipher_wrap.c +++ b/nettls/ssl/cipher_wrap.c @@ -150,20 +150,14 @@ static void ccm_ctx_free(void* ctx) #if defined(MBEDTLS_AES_C) -static int - aes_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) +static int aes_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) { return mbedtls_aes_crypt_ecb((mbedtls_aes_context*)ctx, operation, input, output); } #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int aes_crypt_cbc_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) +static int + aes_crypt_cbc_wrap(void* ctx, mbedtls_operation_t operation, size_t length, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_aes_crypt_cbc((mbedtls_aes_context*)ctx, operation, length, iv, input, output); } @@ -171,21 +165,14 @@ static int aes_crypt_cbc_wrap( #if defined(MBEDTLS_CIPHER_MODE_CFB) static int aes_crypt_cfb128_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - size_t* iv_off, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) + void* ctx, mbedtls_operation_t operation, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_aes_crypt_cfb128((mbedtls_aes_context*)ctx, operation, length, iv_off, iv, input, output); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) -static int aes_crypt_ofb_wrap( - void* ctx, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output) +static int aes_crypt_ofb_wrap(void* ctx, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_aes_crypt_ofb((mbedtls_aes_context*)ctx, length, iv_off, iv, input, output); } @@ -207,12 +194,7 @@ static int aes_crypt_ctr_wrap( #if defined(MBEDTLS_CIPHER_MODE_XTS) static int aes_crypt_xts_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - const unsigned char data_unit[16], - const unsigned char* input, - unsigned char* output) + void* ctx, mbedtls_operation_t operation, size_t length, const unsigned char data_unit[16], const unsigned char* input, unsigned char* output) { mbedtls_aes_xts_context* xts_ctx = ctx; int mode; @@ -286,24 +268,18 @@ static const mbedtls_cipher_base_t aes_info = { aes_ctx_alloc, aes_ctx_free}; -static const mbedtls_cipher_info_t aes_128_ecb_info = { - MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_MODE_ECB, 128, "AES-128-ECB", 0, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_128_ecb_info = {MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_MODE_ECB, 128, "AES-128-ECB", 0, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_192_ecb_info = { - MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_MODE_ECB, 192, "AES-192-ECB", 0, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_192_ecb_info = {MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_MODE_ECB, 192, "AES-192-ECB", 0, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_256_ecb_info = { - MBEDTLS_CIPHER_AES_256_ECB, MBEDTLS_MODE_ECB, 256, "AES-256-ECB", 0, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_256_ecb_info = {MBEDTLS_CIPHER_AES_256_ECB, MBEDTLS_MODE_ECB, 256, "AES-256-ECB", 0, 0, 16, &aes_info}; #if defined(MBEDTLS_CIPHER_MODE_CBC) -static const mbedtls_cipher_info_t aes_128_cbc_info = { - MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MODE_CBC, 128, "AES-128-CBC", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_128_cbc_info = {MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MODE_CBC, 128, "AES-128-CBC", 16, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_192_cbc_info = { - MBEDTLS_CIPHER_AES_192_CBC, MBEDTLS_MODE_CBC, 192, "AES-192-CBC", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_192_cbc_info = {MBEDTLS_CIPHER_AES_192_CBC, MBEDTLS_MODE_CBC, 192, "AES-192-CBC", 16, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_256_cbc_info = { - MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MODE_CBC, 256, "AES-256-CBC", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_256_cbc_info = {MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MODE_CBC, 256, "AES-256-CBC", 16, 0, 16, &aes_info}; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) @@ -318,25 +294,19 @@ static const mbedtls_cipher_info_t aes_256_cfb128_info = { #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) -static const mbedtls_cipher_info_t aes_128_ofb_info = { - MBEDTLS_CIPHER_AES_128_OFB, MBEDTLS_MODE_OFB, 128, "AES-128-OFB", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_128_ofb_info = {MBEDTLS_CIPHER_AES_128_OFB, MBEDTLS_MODE_OFB, 128, "AES-128-OFB", 16, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_192_ofb_info = { - MBEDTLS_CIPHER_AES_192_OFB, MBEDTLS_MODE_OFB, 192, "AES-192-OFB", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_192_ofb_info = {MBEDTLS_CIPHER_AES_192_OFB, MBEDTLS_MODE_OFB, 192, "AES-192-OFB", 16, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_256_ofb_info = { - MBEDTLS_CIPHER_AES_256_OFB, MBEDTLS_MODE_OFB, 256, "AES-256-OFB", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_256_ofb_info = {MBEDTLS_CIPHER_AES_256_OFB, MBEDTLS_MODE_OFB, 256, "AES-256-OFB", 16, 0, 16, &aes_info}; #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) -static const mbedtls_cipher_info_t aes_128_ctr_info = { - MBEDTLS_CIPHER_AES_128_CTR, MBEDTLS_MODE_CTR, 128, "AES-128-CTR", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_128_ctr_info = {MBEDTLS_CIPHER_AES_128_CTR, MBEDTLS_MODE_CTR, 128, "AES-128-CTR", 16, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_192_ctr_info = { - MBEDTLS_CIPHER_AES_192_CTR, MBEDTLS_MODE_CTR, 192, "AES-192-CTR", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_192_ctr_info = {MBEDTLS_CIPHER_AES_192_CTR, MBEDTLS_MODE_CTR, 192, "AES-192-CTR", 16, 0, 16, &aes_info}; -static const mbedtls_cipher_info_t aes_256_ctr_info = { - MBEDTLS_CIPHER_AES_256_CTR, MBEDTLS_MODE_CTR, 256, "AES-256-CTR", 16, 0, 16, &aes_info}; +static const mbedtls_cipher_info_t aes_256_ctr_info = {MBEDTLS_CIPHER_AES_256_CTR, MBEDTLS_MODE_CTR, 256, "AES-256-CTR", 16, 0, 16, &aes_info}; #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) @@ -399,11 +369,9 @@ static const mbedtls_cipher_base_t xts_aes_info = { xts_aes_ctx_alloc, xts_aes_ctx_free}; -static const mbedtls_cipher_info_t aes_128_xts_info = { - MBEDTLS_CIPHER_AES_128_XTS, MBEDTLS_MODE_XTS, 256, "AES-128-XTS", 16, 0, 16, &xts_aes_info}; +static const mbedtls_cipher_info_t aes_128_xts_info = {MBEDTLS_CIPHER_AES_128_XTS, MBEDTLS_MODE_XTS, 256, "AES-128-XTS", 16, 0, 16, &xts_aes_info}; -static const mbedtls_cipher_info_t aes_256_xts_info = { - MBEDTLS_CIPHER_AES_256_XTS, MBEDTLS_MODE_XTS, 512, "AES-256-XTS", 16, 0, 16, &xts_aes_info}; +static const mbedtls_cipher_info_t aes_256_xts_info = {MBEDTLS_CIPHER_AES_256_XTS, MBEDTLS_MODE_XTS, 512, "AES-256-XTS", 16, 0, 16, &xts_aes_info}; #endif /* MBEDTLS_CIPHER_MODE_XTS */ #if defined(MBEDTLS_GCM_C) @@ -440,34 +408,13 @@ static const mbedtls_cipher_base_t gcm_aes_info = { }; static const mbedtls_cipher_info_t aes_128_gcm_info = { - MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MODE_GCM, - 128, - "AES-128-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_aes_info}; + MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MODE_GCM, 128, "AES-128-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_aes_info}; static const mbedtls_cipher_info_t aes_192_gcm_info = { - MBEDTLS_CIPHER_AES_192_GCM, - MBEDTLS_MODE_GCM, - 192, - "AES-192-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_aes_info}; + MBEDTLS_CIPHER_AES_192_GCM, MBEDTLS_MODE_GCM, 192, "AES-192-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_aes_info}; static const mbedtls_cipher_info_t aes_256_gcm_info = { - MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MODE_GCM, - 256, - "AES-256-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_aes_info}; + MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MODE_GCM, 256, "AES-256-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_aes_info}; #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) @@ -504,54 +451,27 @@ static const mbedtls_cipher_base_t ccm_aes_info = { }; static const mbedtls_cipher_info_t aes_128_ccm_info = { - MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MODE_CCM, - 128, - "AES-128-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_aes_info}; + MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MODE_CCM, 128, "AES-128-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_aes_info}; static const mbedtls_cipher_info_t aes_192_ccm_info = { - MBEDTLS_CIPHER_AES_192_CCM, - MBEDTLS_MODE_CCM, - 192, - "AES-192-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_aes_info}; + MBEDTLS_CIPHER_AES_192_CCM, MBEDTLS_MODE_CCM, 192, "AES-192-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_aes_info}; static const mbedtls_cipher_info_t aes_256_ccm_info = { - MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_MODE_CCM, - 256, - "AES-256-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_aes_info}; + MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MODE_CCM, 256, "AES-256-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_aes_info}; #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) -static int - camellia_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) +static int camellia_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) { return mbedtls_camellia_crypt_ecb((mbedtls_camellia_context*)ctx, operation, input, output); } #if defined(MBEDTLS_CIPHER_MODE_CBC) static int camellia_crypt_cbc_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) + void* ctx, mbedtls_operation_t operation, size_t length, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_camellia_crypt_cbc((mbedtls_camellia_context*)ctx, operation, length, iv, input, output); } @@ -559,13 +479,7 @@ static int camellia_crypt_cbc_wrap( #if defined(MBEDTLS_CIPHER_MODE_CFB) static int camellia_crypt_cfb128_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - size_t* iv_off, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) + void* ctx, mbedtls_operation_t operation, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_camellia_crypt_cfb128((mbedtls_camellia_context*)ctx, operation, length, iv_off, iv, input, output); } @@ -581,8 +495,7 @@ static int camellia_crypt_ctr_wrap( const unsigned char* input, unsigned char* output) { - return mbedtls_camellia_crypt_ctr( - (mbedtls_camellia_context*)ctx, length, nc_off, nonce_counter, stream_block, input, output); + return mbedtls_camellia_crypt_ctr((mbedtls_camellia_context*)ctx, length, nc_off, nonce_counter, stream_block, input, output); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ @@ -717,34 +630,13 @@ static const mbedtls_cipher_base_t gcm_camellia_info = { }; static const mbedtls_cipher_info_t camellia_128_gcm_info = { - MBEDTLS_CIPHER_CAMELLIA_128_GCM, - MBEDTLS_MODE_GCM, - 128, - "CAMELLIA-128-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_camellia_info}; + MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MODE_GCM, 128, "CAMELLIA-128-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_camellia_info}; static const mbedtls_cipher_info_t camellia_192_gcm_info = { - MBEDTLS_CIPHER_CAMELLIA_192_GCM, - MBEDTLS_MODE_GCM, - 192, - "CAMELLIA-192-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_camellia_info}; + MBEDTLS_CIPHER_CAMELLIA_192_GCM, MBEDTLS_MODE_GCM, 192, "CAMELLIA-192-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_camellia_info}; static const mbedtls_cipher_info_t camellia_256_gcm_info = { - MBEDTLS_CIPHER_CAMELLIA_256_GCM, - MBEDTLS_MODE_GCM, - 256, - "CAMELLIA-256-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_camellia_info}; + MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MODE_GCM, 256, "CAMELLIA-256-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_camellia_info}; #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) @@ -781,55 +673,28 @@ static const mbedtls_cipher_base_t ccm_camellia_info = { }; static const mbedtls_cipher_info_t camellia_128_ccm_info = { - MBEDTLS_CIPHER_CAMELLIA_128_CCM, - MBEDTLS_MODE_CCM, - 128, - "CAMELLIA-128-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_camellia_info}; + MBEDTLS_CIPHER_CAMELLIA_128_CCM, MBEDTLS_MODE_CCM, 128, "CAMELLIA-128-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_camellia_info}; static const mbedtls_cipher_info_t camellia_192_ccm_info = { - MBEDTLS_CIPHER_CAMELLIA_192_CCM, - MBEDTLS_MODE_CCM, - 192, - "CAMELLIA-192-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_camellia_info}; + MBEDTLS_CIPHER_CAMELLIA_192_CCM, MBEDTLS_MODE_CCM, 192, "CAMELLIA-192-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_camellia_info}; static const mbedtls_cipher_info_t camellia_256_ccm_info = { - MBEDTLS_CIPHER_CAMELLIA_256_CCM, - MBEDTLS_MODE_CCM, - 256, - "CAMELLIA-256-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_camellia_info}; + MBEDTLS_CIPHER_CAMELLIA_256_CCM, MBEDTLS_MODE_CCM, 256, "CAMELLIA-256-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_camellia_info}; #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ #if defined(MBEDTLS_ARIA_C) -static int - aria_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) +static int aria_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) { (void)operation; return mbedtls_aria_crypt_ecb((mbedtls_aria_context*)ctx, input, output); } #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int aria_crypt_cbc_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) +static int + aria_crypt_cbc_wrap(void* ctx, mbedtls_operation_t operation, size_t length, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_aria_crypt_cbc((mbedtls_aria_context*)ctx, operation, length, iv, input, output); } @@ -837,13 +702,7 @@ static int aria_crypt_cbc_wrap( #if defined(MBEDTLS_CIPHER_MODE_CFB) static int aria_crypt_cfb128_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - size_t* iv_off, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) + void* ctx, mbedtls_operation_t operation, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_aria_crypt_cfb128((mbedtls_aria_context*)ctx, operation, length, iv_off, iv, input, output); } @@ -859,8 +718,7 @@ static int aria_crypt_ctr_wrap( const unsigned char* input, unsigned char* output) { - return mbedtls_aria_crypt_ctr( - (mbedtls_aria_context*)ctx, length, nc_off, nonce_counter, stream_block, input, output); + return mbedtls_aria_crypt_ctr((mbedtls_aria_context*)ctx, length, nc_off, nonce_counter, stream_block, input, output); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ @@ -919,24 +777,18 @@ static const mbedtls_cipher_base_t aria_info = { aria_ctx_alloc, aria_ctx_free}; -static const mbedtls_cipher_info_t aria_128_ecb_info = { - MBEDTLS_CIPHER_ARIA_128_ECB, MBEDTLS_MODE_ECB, 128, "ARIA-128-ECB", 0, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_128_ecb_info = {MBEDTLS_CIPHER_ARIA_128_ECB, MBEDTLS_MODE_ECB, 128, "ARIA-128-ECB", 0, 0, 16, &aria_info}; -static const mbedtls_cipher_info_t aria_192_ecb_info = { - MBEDTLS_CIPHER_ARIA_192_ECB, MBEDTLS_MODE_ECB, 192, "ARIA-192-ECB", 0, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_192_ecb_info = {MBEDTLS_CIPHER_ARIA_192_ECB, MBEDTLS_MODE_ECB, 192, "ARIA-192-ECB", 0, 0, 16, &aria_info}; -static const mbedtls_cipher_info_t aria_256_ecb_info = { - MBEDTLS_CIPHER_ARIA_256_ECB, MBEDTLS_MODE_ECB, 256, "ARIA-256-ECB", 0, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_256_ecb_info = {MBEDTLS_CIPHER_ARIA_256_ECB, MBEDTLS_MODE_ECB, 256, "ARIA-256-ECB", 0, 0, 16, &aria_info}; #if defined(MBEDTLS_CIPHER_MODE_CBC) -static const mbedtls_cipher_info_t aria_128_cbc_info = { - MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MODE_CBC, 128, "ARIA-128-CBC", 16, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_128_cbc_info = {MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MODE_CBC, 128, "ARIA-128-CBC", 16, 0, 16, &aria_info}; -static const mbedtls_cipher_info_t aria_192_cbc_info = { - MBEDTLS_CIPHER_ARIA_192_CBC, MBEDTLS_MODE_CBC, 192, "ARIA-192-CBC", 16, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_192_cbc_info = {MBEDTLS_CIPHER_ARIA_192_CBC, MBEDTLS_MODE_CBC, 192, "ARIA-192-CBC", 16, 0, 16, &aria_info}; -static const mbedtls_cipher_info_t aria_256_cbc_info = { - MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MODE_CBC, 256, "ARIA-256-CBC", 16, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_256_cbc_info = {MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MODE_CBC, 256, "ARIA-256-CBC", 16, 0, 16, &aria_info}; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) @@ -951,14 +803,11 @@ static const mbedtls_cipher_info_t aria_256_cfb128_info = { #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) -static const mbedtls_cipher_info_t aria_128_ctr_info = { - MBEDTLS_CIPHER_ARIA_128_CTR, MBEDTLS_MODE_CTR, 128, "ARIA-128-CTR", 16, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_128_ctr_info = {MBEDTLS_CIPHER_ARIA_128_CTR, MBEDTLS_MODE_CTR, 128, "ARIA-128-CTR", 16, 0, 16, &aria_info}; -static const mbedtls_cipher_info_t aria_192_ctr_info = { - MBEDTLS_CIPHER_ARIA_192_CTR, MBEDTLS_MODE_CTR, 192, "ARIA-192-CTR", 16, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_192_ctr_info = {MBEDTLS_CIPHER_ARIA_192_CTR, MBEDTLS_MODE_CTR, 192, "ARIA-192-CTR", 16, 0, 16, &aria_info}; -static const mbedtls_cipher_info_t aria_256_ctr_info = { - MBEDTLS_CIPHER_ARIA_256_CTR, MBEDTLS_MODE_CTR, 256, "ARIA-256-CTR", 16, 0, 16, &aria_info}; +static const mbedtls_cipher_info_t aria_256_ctr_info = {MBEDTLS_CIPHER_ARIA_256_CTR, MBEDTLS_MODE_CTR, 256, "ARIA-256-CTR", 16, 0, 16, &aria_info}; #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_GCM_C) @@ -995,34 +844,13 @@ static const mbedtls_cipher_base_t gcm_aria_info = { }; static const mbedtls_cipher_info_t aria_128_gcm_info = { - MBEDTLS_CIPHER_ARIA_128_GCM, - MBEDTLS_MODE_GCM, - 128, - "ARIA-128-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_aria_info}; + MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MODE_GCM, 128, "ARIA-128-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_aria_info}; static const mbedtls_cipher_info_t aria_192_gcm_info = { - MBEDTLS_CIPHER_ARIA_192_GCM, - MBEDTLS_MODE_GCM, - 192, - "ARIA-192-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_aria_info}; + MBEDTLS_CIPHER_ARIA_192_GCM, MBEDTLS_MODE_GCM, 192, "ARIA-192-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_aria_info}; static const mbedtls_cipher_info_t aria_256_gcm_info = { - MBEDTLS_CIPHER_ARIA_256_GCM, - MBEDTLS_MODE_GCM, - 256, - "ARIA-256-GCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &gcm_aria_info}; + MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MODE_GCM, 256, "ARIA-256-GCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &gcm_aria_info}; #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) @@ -1059,75 +887,42 @@ static const mbedtls_cipher_base_t ccm_aria_info = { }; static const mbedtls_cipher_info_t aria_128_ccm_info = { - MBEDTLS_CIPHER_ARIA_128_CCM, - MBEDTLS_MODE_CCM, - 128, - "ARIA-128-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_aria_info}; + MBEDTLS_CIPHER_ARIA_128_CCM, MBEDTLS_MODE_CCM, 128, "ARIA-128-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_aria_info}; static const mbedtls_cipher_info_t aria_192_ccm_info = { - MBEDTLS_CIPHER_ARIA_192_CCM, - MBEDTLS_MODE_CCM, - 192, - "ARIA-192-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_aria_info}; + MBEDTLS_CIPHER_ARIA_192_CCM, MBEDTLS_MODE_CCM, 192, "ARIA-192-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_aria_info}; static const mbedtls_cipher_info_t aria_256_ccm_info = { - MBEDTLS_CIPHER_ARIA_256_CCM, - MBEDTLS_MODE_CCM, - 256, - "ARIA-256-CCM", - 12, - MBEDTLS_CIPHER_VARIABLE_IV_LEN, - 16, - &ccm_aria_info}; + MBEDTLS_CIPHER_ARIA_256_CCM, MBEDTLS_MODE_CCM, 256, "ARIA-256-CCM", 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, 16, &ccm_aria_info}; #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_ARIA_C */ #if defined(MBEDTLS_DES_C) -static int - des_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) +static int des_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) { ((void)operation); return mbedtls_des_crypt_ecb((mbedtls_des_context*)ctx, input, output); } -static int - des3_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) +static int des3_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) { ((void)operation); return mbedtls_des3_crypt_ecb((mbedtls_des3_context*)ctx, input, output); } #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int des_crypt_cbc_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) +static int + des_crypt_cbc_wrap(void* ctx, mbedtls_operation_t operation, size_t length, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_des_crypt_cbc((mbedtls_des_context*)ctx, operation, length, iv, input, output); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int des3_crypt_cbc_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) +static int + des3_crypt_cbc_wrap(void* ctx, mbedtls_operation_t operation, size_t length, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_des3_crypt_cbc((mbedtls_des3_context*)ctx, operation, length, iv, input, output); } @@ -1238,12 +1033,10 @@ static const mbedtls_cipher_base_t des_info = { des_ctx_alloc, des_ctx_free}; -static const mbedtls_cipher_info_t des_ecb_info = { - MBEDTLS_CIPHER_DES_ECB, MBEDTLS_MODE_ECB, MBEDTLS_KEY_LENGTH_DES, "DES-ECB", 0, 0, 8, &des_info}; +static const mbedtls_cipher_info_t des_ecb_info = {MBEDTLS_CIPHER_DES_ECB, MBEDTLS_MODE_ECB, MBEDTLS_KEY_LENGTH_DES, "DES-ECB", 0, 0, 8, &des_info}; #if defined(MBEDTLS_CIPHER_MODE_CBC) -static const mbedtls_cipher_info_t des_cbc_info = { - MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MODE_CBC, MBEDTLS_KEY_LENGTH_DES, "DES-CBC", 8, 0, 8, &des_info}; +static const mbedtls_cipher_info_t des_cbc_info = {MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MODE_CBC, MBEDTLS_KEY_LENGTH_DES, "DES-CBC", 8, 0, 8, &des_info}; #endif /* MBEDTLS_CIPHER_MODE_CBC */ static const mbedtls_cipher_base_t des_ede_info = { @@ -1306,42 +1099,24 @@ static const mbedtls_cipher_base_t des_ede3_info = { des3_ctx_alloc, des3_ctx_free}; -static const mbedtls_cipher_info_t des_ede3_ecb_info = {MBEDTLS_CIPHER_DES_EDE3_ECB, - MBEDTLS_MODE_ECB, - MBEDTLS_KEY_LENGTH_DES_EDE3, - "DES-EDE3-ECB", - 0, - 0, - 8, - &des_ede3_info}; +static const mbedtls_cipher_info_t des_ede3_ecb_info = { + MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_MODE_ECB, MBEDTLS_KEY_LENGTH_DES_EDE3, "DES-EDE3-ECB", 0, 0, 8, &des_ede3_info}; #if defined(MBEDTLS_CIPHER_MODE_CBC) -static const mbedtls_cipher_info_t des_ede3_cbc_info = {MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MODE_CBC, - MBEDTLS_KEY_LENGTH_DES_EDE3, - "DES-EDE3-CBC", - 8, - 0, - 8, - &des_ede3_info}; +static const mbedtls_cipher_info_t des_ede3_cbc_info = { + MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MODE_CBC, MBEDTLS_KEY_LENGTH_DES_EDE3, "DES-EDE3-CBC", 8, 0, 8, &des_ede3_info}; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_BLOWFISH_C) -static int - blowfish_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) +static int blowfish_crypt_ecb_wrap(void* ctx, mbedtls_operation_t operation, const unsigned char* input, unsigned char* output) { return mbedtls_blowfish_crypt_ecb((mbedtls_blowfish_context*)ctx, operation, input, output); } #if defined(MBEDTLS_CIPHER_MODE_CBC) static int blowfish_crypt_cbc_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) + void* ctx, mbedtls_operation_t operation, size_t length, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_blowfish_crypt_cbc((mbedtls_blowfish_context*)ctx, operation, length, iv, input, output); } @@ -1349,13 +1124,7 @@ static int blowfish_crypt_cbc_wrap( #if defined(MBEDTLS_CIPHER_MODE_CFB) static int blowfish_crypt_cfb64_wrap( - void* ctx, - mbedtls_operation_t operation, - size_t length, - size_t* iv_off, - unsigned char* iv, - const unsigned char* input, - unsigned char* output) + void* ctx, mbedtls_operation_t operation, size_t length, size_t* iv_off, unsigned char* iv, const unsigned char* input, unsigned char* output) { return mbedtls_blowfish_crypt_cfb64((mbedtls_blowfish_context*)ctx, operation, length, iv_off, iv, input, output); } @@ -1371,8 +1140,7 @@ static int blowfish_crypt_ctr_wrap( const unsigned char* input, unsigned char* output) { - return mbedtls_blowfish_crypt_ctr( - (mbedtls_blowfish_context*)ctx, length, nc_off, nonce_counter, stream_block, input, output); + return mbedtls_blowfish_crypt_ctr((mbedtls_blowfish_context*)ctx, length, nc_off, nonce_counter, stream_block, input, output); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ @@ -1427,49 +1195,21 @@ static const mbedtls_cipher_base_t blowfish_info = { blowfish_ctx_free}; static const mbedtls_cipher_info_t blowfish_ecb_info = { - MBEDTLS_CIPHER_BLOWFISH_ECB, - MBEDTLS_MODE_ECB, - 128, - "BLOWFISH-ECB", - 0, - MBEDTLS_CIPHER_VARIABLE_KEY_LEN, - 8, - &blowfish_info}; + MBEDTLS_CIPHER_BLOWFISH_ECB, MBEDTLS_MODE_ECB, 128, "BLOWFISH-ECB", 0, MBEDTLS_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info}; #if defined(MBEDTLS_CIPHER_MODE_CBC) static const mbedtls_cipher_info_t blowfish_cbc_info = { - MBEDTLS_CIPHER_BLOWFISH_CBC, - MBEDTLS_MODE_CBC, - 128, - "BLOWFISH-CBC", - 8, - MBEDTLS_CIPHER_VARIABLE_KEY_LEN, - 8, - &blowfish_info}; + MBEDTLS_CIPHER_BLOWFISH_CBC, MBEDTLS_MODE_CBC, 128, "BLOWFISH-CBC", 8, MBEDTLS_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info}; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) static const mbedtls_cipher_info_t blowfish_cfb64_info = { - MBEDTLS_CIPHER_BLOWFISH_CFB64, - MBEDTLS_MODE_CFB, - 128, - "BLOWFISH-CFB64", - 8, - MBEDTLS_CIPHER_VARIABLE_KEY_LEN, - 8, - &blowfish_info}; + MBEDTLS_CIPHER_BLOWFISH_CFB64, MBEDTLS_MODE_CFB, 128, "BLOWFISH-CFB64", 8, MBEDTLS_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info}; #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) static const mbedtls_cipher_info_t blowfish_ctr_info = { - MBEDTLS_CIPHER_BLOWFISH_CTR, - MBEDTLS_MODE_CTR, - 128, - "BLOWFISH-CTR", - 8, - MBEDTLS_CIPHER_VARIABLE_KEY_LEN, - 8, - &blowfish_info}; + MBEDTLS_CIPHER_BLOWFISH_CTR, MBEDTLS_MODE_CTR, 128, "BLOWFISH-CTR", 8, MBEDTLS_CIPHER_VARIABLE_KEY_LEN, 8, &blowfish_info}; #endif /* MBEDTLS_CIPHER_MODE_CTR */ #endif /* MBEDTLS_BLOWFISH_C */ @@ -1534,8 +1274,7 @@ static const mbedtls_cipher_base_t arc4_base_info = { arc4_ctx_alloc, arc4_ctx_free}; -static const mbedtls_cipher_info_t arc4_128_info = { - MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MODE_STREAM, 128, "ARC4-128", 0, 0, 1, &arc4_base_info}; +static const mbedtls_cipher_info_t arc4_128_info = {MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MODE_STREAM, 128, "ARC4-128", 0, 0, 1, &arc4_base_info}; #endif /* MBEDTLS_ARC4_C */ #if defined(MBEDTLS_CHACHA20_C) @@ -1606,8 +1345,7 @@ static const mbedtls_cipher_base_t chacha20_base_info = { chacha20_setkey_wrap, chacha20_ctx_alloc, chacha20_ctx_free}; -static const mbedtls_cipher_info_t chacha20_info = { - MBEDTLS_CIPHER_CHACHA20, MBEDTLS_MODE_STREAM, 256, "CHACHA20", 12, 0, 1, &chacha20_base_info}; +static const mbedtls_cipher_info_t chacha20_info = {MBEDTLS_CIPHER_CHACHA20, MBEDTLS_MODE_STREAM, 256, "CHACHA20", 12, 0, 1, &chacha20_base_info}; #endif /* MBEDTLS_CHACHA20_C */ #if defined(MBEDTLS_CHACHAPOLY_C) @@ -1667,14 +1405,8 @@ static const mbedtls_cipher_base_t chachapoly_base_info = { chachapoly_setkey_wrap, chachapoly_ctx_alloc, chachapoly_ctx_free}; -static const mbedtls_cipher_info_t chachapoly_info = {MBEDTLS_CIPHER_CHACHA20_POLY1305, - MBEDTLS_MODE_CHACHAPOLY, - 256, - "CHACHA20-POLY1305", - 12, - 0, - 1, - &chachapoly_base_info}; +static const mbedtls_cipher_info_t chachapoly_info = { + MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MODE_CHACHAPOLY, 256, "CHACHA20-POLY1305", 12, 0, 1, &chachapoly_base_info}; #endif /* MBEDTLS_CHACHAPOLY_C */ #if defined(MBEDTLS_CIPHER_NULL_CIPHER) @@ -1730,8 +1462,7 @@ static const mbedtls_cipher_base_t null_base_info = { null_ctx_alloc, null_ctx_free}; -static const mbedtls_cipher_info_t null_cipher_info = {MBEDTLS_CIPHER_NULL, MBEDTLS_MODE_STREAM, 0, "NULL", 0, 0, 1, - &null_base_info}; +static const mbedtls_cipher_info_t null_cipher_info = {MBEDTLS_CIPHER_NULL, MBEDTLS_MODE_STREAM, 0, "NULL", 0, 0, 1, &null_base_info}; #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] = { diff --git a/nettls/ssl/cmac.c b/nettls/ssl/cmac.c index 03de9a654324d83028e81fda7ad0f8437bfd9231..34c06c2cf1a52892ab98ffb09f531680c22df4c7 100644 --- a/nettls/ssl/cmac.c +++ b/nettls/ssl/cmac.c @@ -180,8 +180,7 @@ exit: #endif /* !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST) */ #if !defined(MBEDTLS_CMAC_ALT) -static void cmac_xor_block( - unsigned char* output, const unsigned char* input1, const unsigned char* input2, const size_t block_size) +static void cmac_xor_block(unsigned char* output, const unsigned char* input1, const unsigned char* input2, const size_t block_size) { size_t idx; @@ -195,11 +194,8 @@ static void cmac_xor_block( * We can't use the padding option from the cipher layer, as it only works for * CBC and we use ECB mode, and anyway we need to XOR K1 or K2 in addition. */ -static void cmac_pad( - unsigned char padded_block[MBEDTLS_CIPHER_BLKSIZE_MAX], - size_t padded_block_len, - const unsigned char* last_block, - size_t last_block_len) +static void + cmac_pad(unsigned char padded_block[MBEDTLS_CIPHER_BLKSIZE_MAX], size_t padded_block_len, const unsigned char* last_block, size_t last_block_len) { size_t j; @@ -375,12 +371,7 @@ int mbedtls_cipher_cmac_reset(mbedtls_cipher_context_t* ctx) } int mbedtls_cipher_cmac( - const mbedtls_cipher_info_t* cipher_info, - const unsigned char* key, - size_t keylen, - const unsigned char* input, - size_t ilen, - unsigned char* output) + const mbedtls_cipher_info_t* cipher_info, const unsigned char* key, size_t keylen, const unsigned char* input, size_t ilen, unsigned char* output) { mbedtls_cipher_context_t ctx; int ret; @@ -413,8 +404,7 @@ exit: /* * Implementation of AES-CMAC-PRF-128 defined in RFC 4615 */ -int mbedtls_aes_cmac_prf_128( - const unsigned char* key, size_t key_length, const unsigned char* input, size_t in_len, unsigned char output[16]) +int mbedtls_aes_cmac_prf_128(const unsigned char* key, size_t key_length, const unsigned char* input, size_t in_len, unsigned char output[16]) { int ret; const mbedtls_cipher_info_t* cipher_info; @@ -470,10 +460,9 @@ exit: /* All CMAC test inputs are truncated from the same 64 byte buffer. */ static const unsigned char test_message[] = { /* PT */ - 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, - 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, - 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, - 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}; + 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, + 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, + 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10}; #endif /* MBEDTLS_AES_C || MBEDTLS_DES_C */ #if defined(MBEDTLS_AES_C) @@ -483,8 +472,7 @@ static const unsigned int aes_message_lengths[NB_CMAC_TESTS_PER_KEY] = { 0, 16, 20, 64}; /* CMAC-AES128 Test Data */ -static const unsigned char aes_128_key[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, - 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}; +static const unsigned char aes_128_key[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}; static const unsigned char aes_128_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = { {/* K1 */ 0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66, 0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde}, @@ -523,9 +511,8 @@ static const unsigned char aes_192_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTL }; /* CMAC-AES256 Test Data */ -static const unsigned char aes_256_key[32] = {0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, - 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, - 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4}; +static const unsigned char aes_256_key[32] = {0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, + 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4}; static const unsigned char aes_256_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = { {/* K1 */ 0xca, 0xd1, 0xed, 0x03, 0x29, 0x9e, 0xed, 0xac, 0x2e, 0x9a, 0x99, 0x80, 0x86, 0x21, 0x50, 0x2f}, @@ -771,48 +758,45 @@ int mbedtls_cmac_self_test(int verbose) #if defined(MBEDTLS_AES_C) /* AES-128 */ if ((ret = cmac_test_subkeys( - verbose, "AES 128", aes_128_key, 128, (const unsigned char*)aes_128_subkeys, MBEDTLS_CIPHER_AES_128_ECB, - MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) + verbose, "AES 128", aes_128_key, 128, (const unsigned char*)aes_128_subkeys, MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_AES_BLOCK_SIZE, + NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } if ((ret = cmac_test_wth_cipher( - verbose, "AES 128", aes_128_key, 128, test_message, aes_message_lengths, - (const unsigned char*)aes_128_expected_result, MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_AES_BLOCK_SIZE, - NB_CMAC_TESTS_PER_KEY)) + verbose, "AES 128", aes_128_key, 128, test_message, aes_message_lengths, (const unsigned char*)aes_128_expected_result, + MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } /* AES-192 */ if ((ret = cmac_test_subkeys( - verbose, "AES 192", aes_192_key, 192, (const unsigned char*)aes_192_subkeys, MBEDTLS_CIPHER_AES_192_ECB, - MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) + verbose, "AES 192", aes_192_key, 192, (const unsigned char*)aes_192_subkeys, MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_AES_BLOCK_SIZE, + NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } if ((ret = cmac_test_wth_cipher( - verbose, "AES 192", aes_192_key, 192, test_message, aes_message_lengths, - (const unsigned char*)aes_192_expected_result, MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_AES_BLOCK_SIZE, - NB_CMAC_TESTS_PER_KEY)) + verbose, "AES 192", aes_192_key, 192, test_message, aes_message_lengths, (const unsigned char*)aes_192_expected_result, + MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } /* AES-256 */ if ((ret = cmac_test_subkeys( - verbose, "AES 256", aes_256_key, 256, (const unsigned char*)aes_256_subkeys, MBEDTLS_CIPHER_AES_256_ECB, - MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) + verbose, "AES 256", aes_256_key, 256, (const unsigned char*)aes_256_subkeys, MBEDTLS_CIPHER_AES_256_ECB, MBEDTLS_AES_BLOCK_SIZE, + NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } if ((ret = cmac_test_wth_cipher( - verbose, "AES 256", aes_256_key, 256, test_message, aes_message_lengths, - (const unsigned char*)aes_256_expected_result, MBEDTLS_CIPHER_AES_256_ECB, MBEDTLS_AES_BLOCK_SIZE, - NB_CMAC_TESTS_PER_KEY)) + verbose, "AES 256", aes_256_key, 256, test_message, aes_message_lengths, (const unsigned char*)aes_256_expected_result, + MBEDTLS_CIPHER_AES_256_ECB, MBEDTLS_AES_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } @@ -821,32 +805,30 @@ int mbedtls_cmac_self_test(int verbose) #if defined(MBEDTLS_DES_C) /* 3DES 2 key */ if ((ret = cmac_test_subkeys( - verbose, "3DES 2 key", des3_2key_key, 192, (const unsigned char*)des3_2key_subkeys, - MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) + verbose, "3DES 2 key", des3_2key_key, 192, (const unsigned char*)des3_2key_subkeys, MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, + NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } if ((ret = cmac_test_wth_cipher( - verbose, "3DES 2 key", des3_2key_key, 192, test_message, des3_message_lengths, - (const unsigned char*)des3_2key_expected_result, MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, - NB_CMAC_TESTS_PER_KEY)) + verbose, "3DES 2 key", des3_2key_key, 192, test_message, des3_message_lengths, (const unsigned char*)des3_2key_expected_result, + MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } /* 3DES 3 key */ if ((ret = cmac_test_subkeys( - verbose, "3DES 3 key", des3_3key_key, 192, (const unsigned char*)des3_3key_subkeys, - MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) + verbose, "3DES 3 key", des3_3key_key, 192, (const unsigned char*)des3_3key_subkeys, MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, + NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } if ((ret = cmac_test_wth_cipher( - verbose, "3DES 3 key", des3_3key_key, 192, test_message, des3_message_lengths, - (const unsigned char*)des3_3key_expected_result, MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, - NB_CMAC_TESTS_PER_KEY)) + verbose, "3DES 3 key", des3_3key_key, 192, test_message, des3_message_lengths, (const unsigned char*)des3_3key_expected_result, + MBEDTLS_CIPHER_DES_EDE3_ECB, MBEDTLS_DES3_BLOCK_SIZE, NB_CMAC_TESTS_PER_KEY)) != 0) { return (ret); } diff --git a/nettls/ssl/ctr_drbg.c b/nettls/ssl/ctr_drbg.c index 752563c12862b02a90022d2a4524c79ecd4fa109..0bb7f36947906c45322617a39647f077dc74797b 100644 --- a/nettls/ssl/ctr_drbg.c +++ b/nettls/ssl/ctr_drbg.c @@ -386,11 +386,7 @@ exit: * ctx = initial_working_state */ int mbedtls_ctr_drbg_seed( - mbedtls_ctr_drbg_context* ctx, - int (*f_entropy)(void*, unsigned char*, size_t), - void* p_entropy, - const unsigned char* custom, - size_t len) + mbedtls_ctr_drbg_context* ctx, int (*f_entropy)(void*, unsigned char*, size_t), void* p_entropy, const unsigned char* custom, size_t len) { int ret; unsigned char key[MBEDTLS_CTR_DRBG_KEYSIZE]; @@ -455,8 +451,7 @@ int mbedtls_ctr_drbg_seed_entropy_len( * returned_bits = output[:output_len] * ctx contains new_working_state */ -int mbedtls_ctr_drbg_random_with_add( - void* p_rng, unsigned char* output, size_t output_len, const unsigned char* additional, size_t add_len) +int mbedtls_ctr_drbg_random_with_add(void* p_rng, unsigned char* output, size_t output_len, const unsigned char* additional, size_t add_len) { int ret = 0; mbedtls_ctr_drbg_context* ctx = (mbedtls_ctr_drbg_context*)p_rng; @@ -605,30 +600,23 @@ exit: #if defined(MBEDTLS_SELF_TEST) static const unsigned char entropy_source_pr[96] = { - 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16, 0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02, - 0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b, 0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb, - 0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9, 0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95, - 0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63, 0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3, - 0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31, 0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4, - 0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56, 0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68}; - -static const unsigned char entropy_source_nopr[64] = { - 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14, 0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe, - 0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d, 0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20, - 0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9, 0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46, - 0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e, 0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e}; - -static const unsigned char nonce_pers_pr[16] = {0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2, - 0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c}; - -static const unsigned char nonce_pers_nopr[16] = {0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5, - 0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f}; - -static const unsigned char result_pr[16] = {0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f, - 0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23}; - -static const unsigned char result_nopr[16] = {0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88, - 0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f}; + 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16, 0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02, 0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b, + 0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb, 0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9, 0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95, + 0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63, 0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3, 0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31, + 0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4, 0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56, 0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68}; + +static const unsigned char entropy_source_nopr[64] = {0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14, 0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe, + 0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d, 0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20, + 0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9, 0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46, + 0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e, 0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e}; + +static const unsigned char nonce_pers_pr[16] = {0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2, 0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c}; + +static const unsigned char nonce_pers_nopr[16] = {0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5, 0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f}; + +static const unsigned char result_pr[16] = {0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f, 0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23}; + +static const unsigned char result_nopr[16] = {0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88, 0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f}; static size_t test_offset; static int ctr_drbg_self_test_entropy(void* data, unsigned char* buf, size_t len) diff --git a/nettls/ssl/debug.c b/nettls/ssl/debug.c index 9cd26215b40d0df9e7b5e3d791d8a985f54e44a0..cddb0bab4eb91c106249fc592df843525e7fc170 100644 --- a/nettls/ssl/debug.c +++ b/nettls/ssl/debug.c @@ -84,8 +84,7 @@ void mbedtls_debug_set_threshold(int threshold) /* * All calls to f_dbg must be made via this function */ -static inline void - debug_send_line(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* str) +static inline void debug_send_line(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* str) { /* * If in a threaded environment, we need a thread identifier. @@ -101,8 +100,7 @@ static inline void #endif } -void mbedtls_debug_print_msg( - const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* format, ...) +void mbedtls_debug_print_msg(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* format, ...) { va_list argp; char str[DEBUG_BUF_SIZE]; @@ -136,8 +134,7 @@ void mbedtls_debug_print_msg( debug_send_line(ssl, level, file, line, str); } -void mbedtls_debug_print_ret( - const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, int ret) +void mbedtls_debug_print_ret(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, int ret) { char str[DEBUG_BUF_SIZE]; @@ -159,13 +156,7 @@ void mbedtls_debug_print_ret( } void mbedtls_debug_print_buf( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const char* text, - const unsigned char* buf, - size_t len) + const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const unsigned char* buf, size_t len) { char str[DEBUG_BUF_SIZE]; char txt[17]; @@ -211,8 +202,7 @@ void mbedtls_debug_print_buf( } #if defined(MBEDTLS_ECP_C) -void mbedtls_debug_print_ecp( - const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_ecp_point* X) +void mbedtls_debug_print_ecp(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_ecp_point* X) { char str[DEBUG_BUF_SIZE]; @@ -229,8 +219,7 @@ void mbedtls_debug_print_ecp( #endif /* MBEDTLS_ECP_C */ #if defined(MBEDTLS_BIGNUM_C) -void mbedtls_debug_print_mpi( - const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_mpi* X) +void mbedtls_debug_print_mpi(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_mpi* X) { char str[DEBUG_BUF_SIZE]; int j, k, zeros = 1; @@ -248,9 +237,7 @@ void mbedtls_debug_print_mpi( if (((X->p[n] >> j) & 1) != 0) break; - mbedtls_snprintf( - str + idx, sizeof(str) - idx, "value of '%s' (%d bits) is:\n", text, - (int)((n * (sizeof(mbedtls_mpi_uint) << 3)) + j + 1)); + mbedtls_snprintf(str + idx, sizeof(str) - idx, "value of '%s' (%d bits) is:\n", text, (int)((n * (sizeof(mbedtls_mpi_uint) << 3)) + j + 1)); debug_send_line(ssl, level, file, line, str); @@ -273,8 +260,7 @@ void mbedtls_debug_print_mpi( } } - idx += - mbedtls_snprintf(str + idx, sizeof(str) - idx, " %02x", (unsigned int)(X->p[i - 1] >> (k << 3)) & 0xFF); + idx += mbedtls_snprintf(str + idx, sizeof(str) - idx, " %02x", (unsigned int)(X->p[i - 1] >> (k << 3)) & 0xFF); j++; } @@ -289,13 +275,7 @@ void mbedtls_debug_print_mpi( #endif /* MBEDTLS_BIGNUM_C */ #if defined(MBEDTLS_X509_CRT_PARSE_C) -static void debug_print_pk( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const char* text, - const mbedtls_pk_context* pk) +static void debug_print_pk(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_pk_context* pk) { size_t i; mbedtls_pk_debug_item items[MBEDTLS_PK_DEBUG_MAX_ITEMS]; @@ -327,8 +307,7 @@ static void debug_print_pk( } } -static void - debug_print_line_by_line(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text) +static void debug_print_line_by_line(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text) { char str[DEBUG_BUF_SIZE]; const char *start, *cur; @@ -350,13 +329,7 @@ static void } } -void mbedtls_debug_print_crt( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const char* text, - const mbedtls_x509_crt* crt) +void mbedtls_debug_print_crt(const mbedtls_ssl_context* ssl, int level, const char* file, int line, const char* text, const mbedtls_x509_crt* crt) { char str[DEBUG_BUF_SIZE]; int i = 0; @@ -383,12 +356,7 @@ void mbedtls_debug_print_crt( #if defined(MBEDTLS_ECDH_C) static void mbedtls_debug_printf_ecdh_internal( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const mbedtls_ecdh_context* ecdh, - mbedtls_debug_ecdh_attr attr) + const mbedtls_ssl_context* ssl, int level, const char* file, int line, const mbedtls_ecdh_context* ecdh, mbedtls_debug_ecdh_attr attr) { #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) const mbedtls_ecdh_context* ctx = ecdh; @@ -412,12 +380,7 @@ static void mbedtls_debug_printf_ecdh_internal( } void mbedtls_debug_printf_ecdh( - const mbedtls_ssl_context* ssl, - int level, - const char* file, - int line, - const mbedtls_ecdh_context* ecdh, - mbedtls_debug_ecdh_attr attr) + const mbedtls_ssl_context* ssl, int level, const char* file, int line, const mbedtls_ecdh_context* ecdh, mbedtls_debug_ecdh_attr attr) { #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) mbedtls_debug_printf_ecdh_internal(ssl, level, file, line, ecdh, attr); diff --git a/nettls/ssl/des.c b/nettls/ssl/des.c index 0e11b41955c7a64388bf043cc38224f3b85ae682..9e4352516568e26ad6fe3a10e85d35e59f274211 100644 --- a/nettls/ssl/des.c +++ b/nettls/ssl/des.c @@ -80,8 +80,7 @@ #ifndef GET_UINT32_BE #define GET_UINT32_BE(n, b, i) \ { \ - (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) \ - | ((uint32_t)(b)[(i) + 3]); \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ } #endif @@ -99,91 +98,74 @@ * Expanded DES S-boxes */ static const uint32_t SB1[64] = { - 0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404, 0x00000004, 0x00010000, - 0x00000400, 0x01010400, 0x01010404, 0x00000400, 0x01000404, 0x01010004, 0x01000000, 0x00000004, - 0x00000404, 0x01000400, 0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000, 0x01000404, - 0x00010004, 0x01000004, 0x01000004, 0x00010004, 0x00000000, 0x00000404, 0x00010404, 0x01000000, - 0x00010000, 0x01010404, 0x00000004, 0x01010000, 0x01010400, 0x01000000, 0x01000000, 0x00000400, - 0x01010004, 0x00010000, 0x00010400, 0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404, - 0x01010404, 0x00010004, 0x01010000, 0x01000404, 0x01000004, 0x00000404, 0x00010404, 0x01010400, - 0x00000404, 0x01000400, 0x01000400, 0x00000000, 0x00010004, 0x00010400, 0x00000000, 0x01010004}; + 0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404, 0x00000004, 0x00010000, 0x00000400, 0x01010400, 0x01010404, + 0x00000400, 0x01000404, 0x01010004, 0x01000000, 0x00000004, 0x00000404, 0x01000400, 0x01000400, 0x00010400, 0x00010400, 0x01010000, + 0x01010000, 0x01000404, 0x00010004, 0x01000004, 0x01000004, 0x00010004, 0x00000000, 0x00000404, 0x00010404, 0x01000000, 0x00010000, + 0x01010404, 0x00000004, 0x01010000, 0x01010400, 0x01000000, 0x01000000, 0x00000400, 0x01010004, 0x00010000, 0x00010400, 0x01000004, + 0x00000400, 0x00000004, 0x01000404, 0x00010404, 0x01010404, 0x00010004, 0x01010000, 0x01000404, 0x01000004, 0x00000404, 0x00010404, + 0x01010400, 0x00000404, 0x01000400, 0x01000400, 0x00000000, 0x00010004, 0x00010400, 0x00000000, 0x01010004}; static const uint32_t SB2[64] = { - 0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020, 0x80100020, 0x80008020, - 0x80000020, 0x80108020, 0x80108000, 0x80000000, 0x80008000, 0x00100000, 0x00000020, 0x80100020, - 0x00108000, 0x00100020, 0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020, 0x80100000, - 0x00100020, 0x80000020, 0x00000000, 0x00108000, 0x00008020, 0x80108000, 0x80100000, 0x00008020, - 0x00000000, 0x00108020, 0x80100020, 0x00100000, 0x80008020, 0x80100000, 0x80108000, 0x00008000, - 0x80100000, 0x80008000, 0x00000020, 0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000, - 0x00008020, 0x80108000, 0x00100000, 0x80000020, 0x00100020, 0x80008020, 0x80000020, 0x00100020, - 0x00108000, 0x00000000, 0x80008000, 0x00008020, 0x80000000, 0x80100020, 0x80108020, 0x00108000}; + 0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020, 0x80100020, 0x80008020, 0x80000020, 0x80108020, 0x80108000, + 0x80000000, 0x80008000, 0x00100000, 0x00000020, 0x80100020, 0x00108000, 0x00100020, 0x80008020, 0x00000000, 0x80000000, 0x00008000, + 0x00108020, 0x80100000, 0x00100020, 0x80000020, 0x00000000, 0x00108000, 0x00008020, 0x80108000, 0x80100000, 0x00008020, 0x00000000, + 0x00108020, 0x80100020, 0x00100000, 0x80008020, 0x80100000, 0x80108000, 0x00008000, 0x80100000, 0x80008000, 0x00000020, 0x80108020, + 0x00108020, 0x00000020, 0x00008000, 0x80000000, 0x00008020, 0x80108000, 0x00100000, 0x80000020, 0x00100020, 0x80008020, 0x80000020, + 0x00100020, 0x00108000, 0x00000000, 0x80008000, 0x00008020, 0x80000000, 0x80100020, 0x80108020, 0x00108000}; static const uint32_t SB3[64] = { - 0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000, 0x00020208, 0x08000200, - 0x00020008, 0x08000008, 0x08000008, 0x00020000, 0x08020208, 0x00020008, 0x08020000, 0x00000208, - 0x08000000, 0x00000008, 0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008, 0x00020208, - 0x08000208, 0x00020200, 0x00020000, 0x08000208, 0x00000008, 0x08020208, 0x00000200, 0x08000000, - 0x08020200, 0x08000000, 0x00020008, 0x00000208, 0x00020000, 0x08020200, 0x08000200, 0x00000000, - 0x00000200, 0x00020008, 0x08020208, 0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008, - 0x08000208, 0x00020000, 0x08000000, 0x08020208, 0x00000008, 0x00020208, 0x00020200, 0x08000008, - 0x08020000, 0x08000208, 0x00000208, 0x08020000, 0x00020208, 0x00000008, 0x08020008, 0x00020200}; + 0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000, 0x00020208, 0x08000200, 0x00020008, 0x08000008, 0x08000008, + 0x00020000, 0x08020208, 0x00020008, 0x08020000, 0x00000208, 0x08000000, 0x00000008, 0x08020200, 0x00000200, 0x00020200, 0x08020000, + 0x08020008, 0x00020208, 0x08000208, 0x00020200, 0x00020000, 0x08000208, 0x00000008, 0x08020208, 0x00000200, 0x08000000, 0x08020200, + 0x08000000, 0x00020008, 0x00000208, 0x00020000, 0x08020200, 0x08000200, 0x00000000, 0x00000200, 0x00020008, 0x08020208, 0x08000200, + 0x08000008, 0x00000200, 0x00000000, 0x08020008, 0x08000208, 0x00020000, 0x08000000, 0x08020208, 0x00000008, 0x00020208, 0x00020200, + 0x08000008, 0x08020000, 0x08000208, 0x00000208, 0x08020000, 0x00020208, 0x00000008, 0x08020008, 0x00020200}; static const uint32_t SB4[64] = { - 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081, 0x00800001, 0x00002001, - 0x00000000, 0x00802000, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00800080, 0x00800001, - 0x00000001, 0x00002000, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001, 0x00002080, - 0x00800081, 0x00000001, 0x00002080, 0x00800080, 0x00002000, 0x00802080, 0x00802081, 0x00000081, - 0x00800080, 0x00800001, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00000000, 0x00802000, - 0x00002080, 0x00800080, 0x00800081, 0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080, - 0x00802081, 0x00000081, 0x00000001, 0x00002000, 0x00800001, 0x00002001, 0x00802080, 0x00800081, - 0x00002001, 0x00002080, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002000, 0x00802080}; + 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081, 0x00800001, 0x00002001, 0x00000000, 0x00802000, 0x00802000, + 0x00802081, 0x00000081, 0x00000000, 0x00800080, 0x00800001, 0x00000001, 0x00002000, 0x00800000, 0x00802001, 0x00000080, 0x00800000, + 0x00002001, 0x00002080, 0x00800081, 0x00000001, 0x00002080, 0x00800080, 0x00002000, 0x00802080, 0x00802081, 0x00000081, 0x00800080, + 0x00800001, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00000000, 0x00802000, 0x00002080, 0x00800080, 0x00800081, 0x00000001, + 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802081, 0x00000081, 0x00000001, 0x00002000, 0x00800001, 0x00002001, 0x00802080, + 0x00800081, 0x00002001, 0x00002080, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002000, 0x00802080}; static const uint32_t SB5[64] = { - 0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100, 0x40000000, 0x02080000, - 0x40080100, 0x00080000, 0x02000100, 0x40080100, 0x42000100, 0x42080000, 0x00080100, 0x40000000, - 0x02000000, 0x40080000, 0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100, 0x02000100, - 0x42080000, 0x40000100, 0x00000000, 0x42000000, 0x02080100, 0x02000000, 0x42000000, 0x00080100, - 0x00080000, 0x42000100, 0x00000100, 0x02000000, 0x40000000, 0x02080000, 0x42000100, 0x40080100, - 0x02000100, 0x40000000, 0x42080000, 0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000, - 0x42080100, 0x00080100, 0x42000000, 0x42080100, 0x02080000, 0x00000000, 0x40080000, 0x42000000, - 0x00080100, 0x02000100, 0x40000100, 0x00080000, 0x00000000, 0x40080000, 0x02080100, 0x40000100}; + 0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100, 0x40000000, 0x02080000, 0x40080100, 0x00080000, 0x02000100, + 0x40080100, 0x42000100, 0x42080000, 0x00080100, 0x40000000, 0x02000000, 0x40080000, 0x40080000, 0x00000000, 0x40000100, 0x42080100, + 0x42080100, 0x02000100, 0x42080000, 0x40000100, 0x00000000, 0x42000000, 0x02080100, 0x02000000, 0x42000000, 0x00080100, 0x00080000, + 0x42000100, 0x00000100, 0x02000000, 0x40000000, 0x02080000, 0x42000100, 0x40080100, 0x02000100, 0x40000000, 0x42080000, 0x02080100, + 0x40080100, 0x00000100, 0x02000000, 0x42080000, 0x42080100, 0x00080100, 0x42000000, 0x42080100, 0x02080000, 0x00000000, 0x40080000, + 0x42000000, 0x00080100, 0x02000100, 0x40000100, 0x00080000, 0x00000000, 0x40080000, 0x02080100, 0x40000100}; static const uint32_t SB6[64] = { - 0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010, 0x20404010, 0x00400000, - 0x20004000, 0x00404010, 0x00400000, 0x20000010, 0x00400010, 0x20004000, 0x20000000, 0x00004010, - 0x00000000, 0x00400010, 0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010, 0x20400010, - 0x20400010, 0x00000000, 0x00404010, 0x20404000, 0x00004010, 0x00404000, 0x20404000, 0x20000000, - 0x20004000, 0x00000010, 0x20400010, 0x00404000, 0x20404010, 0x00400000, 0x00004010, 0x20000010, - 0x00400000, 0x20004000, 0x20000000, 0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000, - 0x00404010, 0x20404000, 0x00000000, 0x20400010, 0x00000010, 0x00004000, 0x20400000, 0x00404010, - 0x00004000, 0x00400010, 0x20004010, 0x00000000, 0x20404000, 0x20000000, 0x00400010, 0x20004010}; + 0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010, 0x20404010, 0x00400000, 0x20004000, 0x00404010, 0x00400000, + 0x20000010, 0x00400010, 0x20004000, 0x20000000, 0x00004010, 0x00000000, 0x00400010, 0x20004010, 0x00004000, 0x00404000, 0x20004010, + 0x00000010, 0x20400010, 0x20400010, 0x00000000, 0x00404010, 0x20404000, 0x00004010, 0x00404000, 0x20404000, 0x20000000, 0x20004000, + 0x00000010, 0x20400010, 0x00404000, 0x20404010, 0x00400000, 0x00004010, 0x20000010, 0x00400000, 0x20004000, 0x20000000, 0x00004010, + 0x20000010, 0x20404010, 0x00404000, 0x20400000, 0x00404010, 0x20404000, 0x00000000, 0x20400010, 0x00000010, 0x00004000, 0x20400000, + 0x00404010, 0x00004000, 0x00400010, 0x20004010, 0x00000000, 0x20404000, 0x20000000, 0x00400010, 0x20004010}; static const uint32_t SB7[64] = { - 0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802, 0x00200802, 0x04200800, - 0x04200802, 0x00200000, 0x00000000, 0x04000002, 0x00000002, 0x04000000, 0x04200002, 0x00000802, - 0x04000800, 0x00200802, 0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800, 0x00200002, - 0x04200000, 0x00000800, 0x00000802, 0x04200802, 0x00200800, 0x00000002, 0x04000000, 0x00200800, - 0x04000000, 0x00200800, 0x00200000, 0x04000802, 0x04000802, 0x04200002, 0x04200002, 0x00000002, - 0x00200002, 0x04000000, 0x04000800, 0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800, - 0x00000802, 0x04000002, 0x04200802, 0x04200000, 0x00200800, 0x00000000, 0x00000002, 0x04200802, - 0x00000000, 0x00200802, 0x04200000, 0x00000800, 0x04000002, 0x04000800, 0x00000800, 0x00200002}; + 0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802, 0x00200802, 0x04200800, 0x04200802, 0x00200000, 0x00000000, + 0x04000002, 0x00000002, 0x04000000, 0x04200002, 0x00000802, 0x04000800, 0x00200802, 0x00200002, 0x04000800, 0x04000002, 0x04200000, + 0x04200800, 0x00200002, 0x04200000, 0x00000800, 0x00000802, 0x04200802, 0x00200800, 0x00000002, 0x04000000, 0x00200800, 0x04000000, + 0x00200800, 0x00200000, 0x04000802, 0x04000802, 0x04200002, 0x04200002, 0x00000002, 0x00200002, 0x04000000, 0x04000800, 0x00200000, + 0x04200800, 0x00000802, 0x00200802, 0x04200800, 0x00000802, 0x04000002, 0x04200802, 0x04200000, 0x00200800, 0x00000000, 0x00000002, + 0x04200802, 0x00000000, 0x00200802, 0x04200000, 0x00000800, 0x04000002, 0x04000800, 0x00000800, 0x00200002}; static const uint32_t SB8[64] = { - 0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040, 0x00000040, 0x10000000, - 0x00040040, 0x10040000, 0x10041040, 0x00041000, 0x10041000, 0x00041040, 0x00001000, 0x00000040, - 0x10040000, 0x10000040, 0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040, 0x10041000, - 0x00001040, 0x00000000, 0x00000000, 0x10040040, 0x10000040, 0x10001000, 0x00041040, 0x00040000, - 0x00041040, 0x00040000, 0x10041000, 0x00001000, 0x00000040, 0x10040040, 0x00001000, 0x00041040, - 0x10001000, 0x00000040, 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040, - 0x00000000, 0x10041040, 0x00040040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0x00000000, - 0x10041040, 0x00041000, 0x00041000, 0x00001040, 0x00001040, 0x00040040, 0x10000000, 0x10041000}; + 0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040, 0x00000040, 0x10000000, 0x00040040, 0x10040000, 0x10041040, + 0x00041000, 0x10041000, 0x00041040, 0x00001000, 0x00000040, 0x10040000, 0x10000040, 0x10001000, 0x00001040, 0x00041000, 0x00040040, + 0x10040040, 0x10041000, 0x00001040, 0x00000000, 0x00000000, 0x10040040, 0x10000040, 0x10001000, 0x00041040, 0x00040000, 0x00041040, + 0x00040000, 0x10041000, 0x00001000, 0x00000040, 0x10040040, 0x00001000, 0x00041040, 0x10001000, 0x00000040, 0x10000040, 0x10040000, + 0x10040040, 0x10000000, 0x00040000, 0x10001040, 0x00000000, 0x10041040, 0x00040040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, + 0x00000000, 0x10041040, 0x00041000, 0x00041000, 0x00001040, 0x00001040, 0x00040040, 0x10000000, 0x10041000}; /* * PC1: left and right halves bit-swap */ -static const uint32_t LHs[16] = {0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, - 0x00010100, 0x00010101, 0x01000000, 0x01000001, 0x01000100, 0x01000101, - 0x01010000, 0x01010001, 0x01010100, 0x01010101}; +static const uint32_t LHs[16] = {0x00000000, 0x00000001, 0x00000100, 0x00000101, 0x00010000, 0x00010001, 0x00010100, 0x00010101, + 0x01000000, 0x01000001, 0x01000100, 0x01000101, 0x01010000, 0x01010001, 0x01010100, 0x01010101}; static const uint32_t RHs[16] = { 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x01000100, 0x00010100, 0x01010100, @@ -285,12 +267,11 @@ void mbedtls_des3_free(mbedtls_des3_context* ctx) } static const unsigned char odd_parity_table[128] = { - 1, 2, 4, 7, 8, 11, 13, 14, 16, 19, 21, 22, 25, 26, 28, 31, 32, 35, 37, 38, 41, 42, - 44, 47, 49, 50, 52, 55, 56, 59, 61, 62, 64, 67, 69, 70, 73, 74, 76, 79, 81, 82, 84, 87, - 88, 91, 93, 94, 97, 98, 100, 103, 104, 107, 109, 110, 112, 115, 117, 118, 121, 122, 124, 127, 128, 131, - 133, 134, 137, 138, 140, 143, 145, 146, 148, 151, 152, 155, 157, 158, 161, 162, 164, 167, 168, 171, 173, 174, - 176, 179, 181, 182, 185, 186, 188, 191, 193, 194, 196, 199, 200, 203, 205, 206, 208, 211, 213, 214, 217, 218, - 220, 223, 224, 227, 229, 230, 233, 234, 236, 239, 241, 242, 244, 247, 248, 251, 253, 254}; + 1, 2, 4, 7, 8, 11, 13, 14, 16, 19, 21, 22, 25, 26, 28, 31, 32, 35, 37, 38, 41, 42, 44, 47, 49, 50, + 52, 55, 56, 59, 61, 62, 64, 67, 69, 70, 73, 74, 76, 79, 81, 82, 84, 87, 88, 91, 93, 94, 97, 98, 100, 103, + 104, 107, 109, 110, 112, 115, 117, 118, 121, 122, 124, 127, 128, 131, 133, 134, 137, 138, 140, 143, 145, 146, 148, 151, 152, 155, + 157, 158, 161, 162, 164, 167, 168, 171, 173, 174, 176, 179, 181, 182, 185, 186, 188, 191, 193, 194, 196, 199, 200, 203, 205, 206, + 208, 211, 213, 214, 217, 218, 220, 223, 224, 227, 229, 230, 233, 234, 236, 239, 241, 242, 244, 247, 248, 251, 253, 254}; void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]) { @@ -387,13 +368,11 @@ void mbedtls_des_setkey(uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KEY X ^= T; Y ^= (T); - X = (LHs[(X)&0xF] << 3) | (LHs[(X >> 8) & 0xF] << 2) | (LHs[(X >> 16) & 0xF] << 1) | (LHs[(X >> 24) & 0xF]) - | (LHs[(X >> 5) & 0xF] << 7) | (LHs[(X >> 13) & 0xF] << 6) | (LHs[(X >> 21) & 0xF] << 5) - | (LHs[(X >> 29) & 0xF] << 4); + X = (LHs[(X)&0xF] << 3) | (LHs[(X >> 8) & 0xF] << 2) | (LHs[(X >> 16) & 0xF] << 1) | (LHs[(X >> 24) & 0xF]) | (LHs[(X >> 5) & 0xF] << 7) + | (LHs[(X >> 13) & 0xF] << 6) | (LHs[(X >> 21) & 0xF] << 5) | (LHs[(X >> 29) & 0xF] << 4); - Y = (RHs[(Y >> 1) & 0xF] << 3) | (RHs[(Y >> 9) & 0xF] << 2) | (RHs[(Y >> 17) & 0xF] << 1) | (RHs[(Y >> 25) & 0xF]) - | (RHs[(Y >> 4) & 0xF] << 7) | (RHs[(Y >> 12) & 0xF] << 6) | (RHs[(Y >> 20) & 0xF] << 5) - | (RHs[(Y >> 28) & 0xF] << 4); + Y = (RHs[(Y >> 1) & 0xF] << 3) | (RHs[(Y >> 9) & 0xF] << 2) | (RHs[(Y >> 17) & 0xF] << 1) | (RHs[(Y >> 25) & 0xF]) | (RHs[(Y >> 4) & 0xF] << 7) + | (RHs[(Y >> 12) & 0xF] << 6) | (RHs[(Y >> 20) & 0xF] << 5) | (RHs[(Y >> 28) & 0xF] << 4); X &= 0x0FFFFFFF; Y &= 0x0FFFFFFF; @@ -410,20 +389,17 @@ void mbedtls_des_setkey(uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KEY Y = ((Y << 2) | (Y >> 26)) & 0x0FFFFFFF; } - *SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000) | ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000) - | ((X << 6) & 0x01000000) | ((X << 9) & 0x00200000) | ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000) - | ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000) | ((Y >> 13) & 0x00002000) - | ((Y >> 4) & 0x00001000) | ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400) | ((Y >> 14) & 0x00000200) - | ((Y)&0x00000100) | ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010) | ((Y >> 3) & 0x00000008) - | ((Y >> 18) & 0x00000004) | ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001); - - *SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000) | ((X << 10) & 0x08000000) - | ((X << 22) & 0x04000000) | ((X >> 2) & 0x02000000) | ((X << 1) & 0x01000000) - | ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000) | ((X << 3) & 0x00080000) - | ((X >> 6) & 0x00040000) | ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000) | ((Y >> 2) & 0x00002000) - | ((Y << 8) & 0x00001000) | ((Y >> 14) & 0x00000808) | ((Y >> 9) & 0x00000400) | ((Y)&0x00000200) - | ((Y << 7) & 0x00000100) | ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011) | ((Y << 2) & 0x00000004) - | ((Y >> 21) & 0x00000002); + *SK++ = ((X << 4) & 0x24000000) | ((X << 28) & 0x10000000) | ((X << 14) & 0x08000000) | ((X << 18) & 0x02080000) | ((X << 6) & 0x01000000) + | ((X << 9) & 0x00200000) | ((X >> 1) & 0x00100000) | ((X << 10) & 0x00040000) | ((X << 2) & 0x00020000) | ((X >> 10) & 0x00010000) + | ((Y >> 13) & 0x00002000) | ((Y >> 4) & 0x00001000) | ((Y << 6) & 0x00000800) | ((Y >> 1) & 0x00000400) | ((Y >> 14) & 0x00000200) + | ((Y)&0x00000100) | ((Y >> 5) & 0x00000020) | ((Y >> 10) & 0x00000010) | ((Y >> 3) & 0x00000008) | ((Y >> 18) & 0x00000004) + | ((Y >> 26) & 0x00000002) | ((Y >> 24) & 0x00000001); + + *SK++ = ((X << 15) & 0x20000000) | ((X << 17) & 0x10000000) | ((X << 10) & 0x08000000) | ((X << 22) & 0x04000000) | ((X >> 2) & 0x02000000) + | ((X << 1) & 0x01000000) | ((X << 16) & 0x00200000) | ((X << 11) & 0x00100000) | ((X << 3) & 0x00080000) | ((X >> 6) & 0x00040000) + | ((X << 15) & 0x00020000) | ((X >> 4) & 0x00010000) | ((Y >> 2) & 0x00002000) | ((Y << 8) & 0x00001000) | ((Y >> 14) & 0x00000808) + | ((Y >> 9) & 0x00000400) | ((Y)&0x00000200) | ((Y << 7) & 0x00000100) | ((Y >> 7) & 0x00000020) | ((Y >> 3) & 0x00000011) + | ((Y << 2) & 0x00000004) | ((Y >> 21) & 0x00000002); } } #endif /* !MBEDTLS_DES_SETKEY_ALT */ @@ -583,13 +559,7 @@ int mbedtls_des_crypt_ecb(mbedtls_des_context* ctx, const unsigned char input[8] /* * DES-CBC buffer encryption/decryption */ -int mbedtls_des_crypt_cbc( - mbedtls_des_context* ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char* input, - unsigned char* output) +int mbedtls_des_crypt_cbc(mbedtls_des_context* ctx, int mode, size_t length, unsigned char iv[8], const unsigned char* input, unsigned char* output) { int i; unsigned char temp[8]; @@ -674,13 +644,7 @@ int mbedtls_des3_crypt_ecb(mbedtls_des3_context* ctx, const unsigned char input[ /* * 3DES-CBC buffer encryption/decryption */ -int mbedtls_des3_crypt_cbc( - mbedtls_des3_context* ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char* input, - unsigned char* output) +int mbedtls_des3_crypt_cbc(mbedtls_des3_context* ctx, int mode, size_t length, unsigned char iv[8], const unsigned char* input, unsigned char* output) { int i; unsigned char temp[8]; @@ -729,9 +693,8 @@ int mbedtls_des3_crypt_cbc( * * http://csrc.nist.gov/groups/STM/cavp/documents/des/tripledes-vectors.zip */ -static const unsigned char des3_test_keys[24] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, - 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, - 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23}; +static const unsigned char des3_test_keys[24] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x23, 0x45, 0x67, 0x89, + 0xAB, 0xCD, 0xEF, 0x01, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01, 0x23}; static const unsigned char des3_test_buf[8] = {0x4E, 0x6F, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74}; @@ -789,9 +752,7 @@ int mbedtls_des_self_test(int verbose) v = i & 1; if (verbose != 0) - mbedtls_printf( - " DES%c-ECB-%3d (%s): ", (u == 0) ? ' ' : '3', 56 + u * 56, - (v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc"); + mbedtls_printf(" DES%c-ECB-%3d (%s): ", (u == 0) ? ' ' : '3', 56 + u * 56, (v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc"); memcpy(buf, des3_test_buf, 8); @@ -856,9 +817,7 @@ int mbedtls_des_self_test(int verbose) v = i & 1; if (verbose != 0) - mbedtls_printf( - " DES%c-CBC-%3d (%s): ", (u == 0) ? ' ' : '3', 56 + u * 56, - (v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc"); + mbedtls_printf(" DES%c-CBC-%3d (%s): ", (u == 0) ? ' ' : '3', 56 + u * 56, (v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc"); memcpy(iv, des3_test_iv, 8); memcpy(prv, des3_test_iv, 8); diff --git a/nettls/ssl/dhm.c b/nettls/ssl/dhm.c index 66e910080bd8686b2eec3f4d6fcb2889649cb89d..87ab5bdd77ea44d9d733de655e341ff72d9a3bf8 100644 --- a/nettls/ssl/dhm.c +++ b/nettls/ssl/dhm.c @@ -177,12 +177,7 @@ int mbedtls_dhm_read_params(mbedtls_dhm_context* ctx, unsigned char** p, const u * Setup and write the ServerKeyExchange parameters */ int mbedtls_dhm_make_params( - mbedtls_dhm_context* ctx, - int x_size, - unsigned char* output, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_dhm_context* ctx, int x_size, unsigned char* output, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret, count = 0; size_t n1, n2, n3; @@ -288,12 +283,7 @@ int mbedtls_dhm_read_public(mbedtls_dhm_context* ctx, const unsigned char* input * Create own private value X and export G^X */ int mbedtls_dhm_make_public( - mbedtls_dhm_context* ctx, - int x_size, - unsigned char* output, - size_t olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_dhm_context* ctx, int x_size, unsigned char* output, size_t olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret, count = 0; DHM_VALIDATE_RET(ctx != NULL); @@ -337,8 +327,7 @@ cleanup: /* * Pick a random R in the range [2, M) for blinding purposes */ -static int - dhm_random_below(mbedtls_mpi* R, const mbedtls_mpi* M, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +static int dhm_random_below(mbedtls_mpi* R, const mbedtls_mpi* M, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret, count; @@ -425,12 +414,7 @@ cleanup: * Derive and export the shared secret (G^Y)^X mod P */ int mbedtls_dhm_calc_secret( - mbedtls_dhm_context* ctx, - unsigned char* output, - size_t output_size, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_dhm_context* ctx, unsigned char* output, size_t output_size, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; mbedtls_mpi GYb; @@ -521,8 +505,7 @@ int mbedtls_dhm_parse_dhm(mbedtls_dhm_context* dhm, const unsigned char* dhmin, if (dhminlen == 0 || dhmin[dhminlen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN DH PARAMETERS-----", "-----END DH PARAMETERS-----", dhmin, NULL, 0, &dhminlen); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN DH PARAMETERS-----", "-----END DH PARAMETERS-----", dhmin, NULL, 0, &dhminlen); if (ret == 0) { /* @@ -672,14 +655,12 @@ static const char mbedtls_test_dhm_params[] = "-----BEGIN DH PARAMETERS-----\r\n "-----END DH PARAMETERS-----\r\n"; #else /* MBEDTLS_PEM_PARSE_C */ static const char mbedtls_test_dhm_params[] = { - 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0x9e, 0x35, 0xf4, 0x30, 0x44, 0x3a, 0x09, 0x90, 0x4f, 0x3a, 0x39, - 0xa9, 0x79, 0x79, 0x7d, 0x07, 0x0d, 0xf5, 0x33, 0x78, 0xe7, 0x9c, 0x24, 0x38, 0xbe, 0xf4, 0xe7, 0x61, 0xf3, - 0xc7, 0x14, 0x55, 0x33, 0x28, 0x58, 0x9b, 0x04, 0x1c, 0x80, 0x9b, 0xe1, 0xd6, 0xc6, 0xb5, 0xf1, 0xfc, 0x9f, - 0x47, 0xd3, 0xa2, 0x54, 0x43, 0x18, 0x82, 0x53, 0xa9, 0x92, 0xa5, 0x68, 0x18, 0xb3, 0x7b, 0xa9, 0xde, 0x5a, - 0x40, 0xd3, 0x62, 0xe5, 0x6e, 0xff, 0x0b, 0xe5, 0x41, 0x74, 0x74, 0xc1, 0x25, 0xc1, 0x99, 0x27, 0x2c, 0x8f, - 0xe4, 0x1d, 0xea, 0x73, 0x3d, 0xf6, 0xf6, 0x62, 0xc9, 0x2a, 0xe7, 0x65, 0x56, 0xe7, 0x55, 0xd1, 0x0c, 0x64, - 0xe6, 0xa5, 0x09, 0x68, 0xf6, 0x7f, 0xc6, 0xea, 0x73, 0xd0, 0xdc, 0xa8, 0x56, 0x9b, 0xe2, 0xba, 0x20, 0x4e, - 0x23, 0x58, 0x0d, 0x8b, 0xca, 0x2f, 0x49, 0x75, 0xb3, 0x02, 0x01, 0x02}; + 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0x9e, 0x35, 0xf4, 0x30, 0x44, 0x3a, 0x09, 0x90, 0x4f, 0x3a, 0x39, 0xa9, 0x79, 0x79, 0x7d, 0x07, + 0x0d, 0xf5, 0x33, 0x78, 0xe7, 0x9c, 0x24, 0x38, 0xbe, 0xf4, 0xe7, 0x61, 0xf3, 0xc7, 0x14, 0x55, 0x33, 0x28, 0x58, 0x9b, 0x04, 0x1c, 0x80, + 0x9b, 0xe1, 0xd6, 0xc6, 0xb5, 0xf1, 0xfc, 0x9f, 0x47, 0xd3, 0xa2, 0x54, 0x43, 0x18, 0x82, 0x53, 0xa9, 0x92, 0xa5, 0x68, 0x18, 0xb3, 0x7b, + 0xa9, 0xde, 0x5a, 0x40, 0xd3, 0x62, 0xe5, 0x6e, 0xff, 0x0b, 0xe5, 0x41, 0x74, 0x74, 0xc1, 0x25, 0xc1, 0x99, 0x27, 0x2c, 0x8f, 0xe4, 0x1d, + 0xea, 0x73, 0x3d, 0xf6, 0xf6, 0x62, 0xc9, 0x2a, 0xe7, 0x65, 0x56, 0xe7, 0x55, 0xd1, 0x0c, 0x64, 0xe6, 0xa5, 0x09, 0x68, 0xf6, 0x7f, 0xc6, + 0xea, 0x73, 0xd0, 0xdc, 0xa8, 0x56, 0x9b, 0xe2, 0xba, 0x20, 0x4e, 0x23, 0x58, 0x0d, 0x8b, 0xca, 0x2f, 0x49, 0x75, 0xb3, 0x02, 0x01, 0x02}; #endif /* MBEDTLS_PEM_PARSE_C */ static const size_t mbedtls_test_dhm_params_len = sizeof(mbedtls_test_dhm_params); @@ -697,8 +678,7 @@ int mbedtls_dhm_self_test(int verbose) if (verbose != 0) mbedtls_printf(" DHM parameter load: "); - if ((ret = mbedtls_dhm_parse_dhm(&dhm, (const unsigned char*)mbedtls_test_dhm_params, mbedtls_test_dhm_params_len)) - != 0) { + if ((ret = mbedtls_dhm_parse_dhm(&dhm, (const unsigned char*)mbedtls_test_dhm_params, mbedtls_test_dhm_params_len)) != 0) { if (verbose != 0) mbedtls_printf("failed\n"); diff --git a/nettls/ssl/ecdh.c b/nettls/ssl/ecdh.c index 97415ec30fd653d38af4d7d532247933c55573b9..f06c926bb4f0aa95e8c5edac641a8dc6f03c2aea 100644 --- a/nettls/ssl/ecdh.c +++ b/nettls/ssl/ecdh.c @@ -114,12 +114,7 @@ cleanup: /* * Generate public key */ -int mbedtls_ecdh_gen_public( - mbedtls_ecp_group* grp, - mbedtls_mpi* d, - mbedtls_ecp_point* Q, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) +int mbedtls_ecdh_gen_public(mbedtls_ecp_group* grp, mbedtls_mpi* d, mbedtls_ecp_point* Q, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { ECDH_VALIDATE_RET(grp != NULL); ECDH_VALIDATE_RET(d != NULL); @@ -358,12 +353,7 @@ static int ecdh_make_params_internal( * } ServerECDHParams; */ int mbedtls_ecdh_make_params( - mbedtls_ecdh_context* ctx, - size_t* olen, - unsigned char* buf, - size_t blen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_ecdh_context* ctx, size_t* olen, unsigned char* buf, size_t blen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int restart_enabled = 0; ECDH_VALIDATE_RET(ctx != NULL); @@ -382,16 +372,14 @@ int mbedtls_ecdh_make_params( #else switch (ctx->var) { case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: - return (ecdh_make_params_internal( - &ctx->ctx.mbed_ecdh, olen, ctx->point_format, buf, blen, f_rng, p_rng, restart_enabled)); + return (ecdh_make_params_internal(&ctx->ctx.mbed_ecdh, olen, ctx->point_format, buf, blen, f_rng, p_rng, restart_enabled)); default: return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; } #endif } -static int - ecdh_read_params_internal(mbedtls_ecdh_context_mbed* ctx, const unsigned char** buf, const unsigned char* end) +static int ecdh_read_params_internal(mbedtls_ecdh_context_mbed* ctx, const unsigned char** buf, const unsigned char* end) { return (mbedtls_ecp_tls_read_point(&ctx->grp, &ctx->Qp, buf, end - *buf)); } @@ -430,8 +418,7 @@ int mbedtls_ecdh_read_params(mbedtls_ecdh_context* ctx, const unsigned char** bu #endif } -static int - ecdh_get_params_internal(mbedtls_ecdh_context_mbed* ctx, const mbedtls_ecp_keypair* key, mbedtls_ecdh_side side) +static int ecdh_get_params_internal(mbedtls_ecdh_context_mbed* ctx, const mbedtls_ecp_keypair* key, mbedtls_ecdh_side side) { int ret; @@ -524,12 +511,7 @@ static int ecdh_make_public_internal( * Setup and export the client public value */ int mbedtls_ecdh_make_public( - mbedtls_ecdh_context* ctx, - size_t* olen, - unsigned char* buf, - size_t blen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_ecdh_context* ctx, size_t* olen, unsigned char* buf, size_t blen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int restart_enabled = 0; ECDH_VALIDATE_RET(ctx != NULL); @@ -546,8 +528,7 @@ int mbedtls_ecdh_make_public( #else switch (ctx->var) { case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: - return (ecdh_make_public_internal( - &ctx->ctx.mbed_ecdh, olen, ctx->point_format, buf, blen, f_rng, p_rng, restart_enabled)); + return (ecdh_make_public_internal(&ctx->ctx.mbed_ecdh, olen, ctx->point_format, buf, blen, f_rng, p_rng, restart_enabled)); default: return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; } @@ -633,12 +614,7 @@ static int ecdh_calc_secret_internal( * Derive and export the shared secret */ int mbedtls_ecdh_calc_secret( - mbedtls_ecdh_context* ctx, - size_t* olen, - unsigned char* buf, - size_t blen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_ecdh_context* ctx, size_t* olen, unsigned char* buf, size_t blen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int restart_enabled = 0; ECDH_VALIDATE_RET(ctx != NULL); diff --git a/nettls/ssl/ecdsa.c b/nettls/ssl/ecdsa.c index 9e1da71cfc684298f7a6d4d98d3adcde734b3ade..6ca8fbd0fec75fa88f87576b4873fe237a2123d4 100644 --- a/nettls/ssl/ecdsa.c +++ b/nettls/ssl/ecdsa.c @@ -484,8 +484,7 @@ sign: ret = mbedtls_ecdsa_sign(grp, r, s, d, buf, blen, mbedtls_hmac_drbg_random, p_rng); #else if (f_rng_blind != NULL) - ret = ecdsa_sign_restartable( - grp, r, s, d, buf, blen, mbedtls_hmac_drbg_random, p_rng, f_rng_blind, p_rng_blind, rs_ctx); + ret = ecdsa_sign_restartable(grp, r, s, d, buf, blen, mbedtls_hmac_drbg_random, p_rng, f_rng_blind, p_rng_blind, rs_ctx); else { mbedtls_hmac_drbg_context* p_rng_blind_det; @@ -532,9 +531,7 @@ sign: * won't be a valid value for f_rng_blind anymore. Therefore it should * be checked by the caller and this branch and check can be removed. */ - ret = ecdsa_sign_restartable( - grp, r, s, d, buf, blen, mbedtls_hmac_drbg_random, p_rng, mbedtls_hmac_drbg_random, p_rng_blind_det, - rs_ctx); + ret = ecdsa_sign_restartable(grp, r, s, d, buf, blen, mbedtls_hmac_drbg_random, p_rng, mbedtls_hmac_drbg_random, p_rng_blind_det, rs_ctx); #if !defined(MBEDTLS_ECP_RESTARTABLE) mbedtls_hmac_drbg_free(&rng_ctx_blind); @@ -555,13 +552,7 @@ cleanup: * Deterministic signature wrappers */ int mbedtls_ecdsa_sign_det( - mbedtls_ecp_group* grp, - mbedtls_mpi* r, - mbedtls_mpi* s, - const mbedtls_mpi* d, - const unsigned char* buf, - size_t blen, - mbedtls_md_type_t md_alg) + mbedtls_ecp_group* grp, mbedtls_mpi* r, mbedtls_mpi* s, const mbedtls_mpi* d, const unsigned char* buf, size_t blen, mbedtls_md_type_t md_alg) { ECDSA_VALIDATE_RET(grp != NULL); ECDSA_VALIDATE_RET(r != NULL); @@ -710,12 +701,7 @@ cleanup: * Verify ECDSA signature of hashed message */ int mbedtls_ecdsa_verify( - mbedtls_ecp_group* grp, - const unsigned char* buf, - size_t blen, - const mbedtls_ecp_point* Q, - const mbedtls_mpi* r, - const mbedtls_mpi* s) + mbedtls_ecp_group* grp, const unsigned char* buf, size_t blen, const mbedtls_ecp_point* Q, const mbedtls_mpi* r, const mbedtls_mpi* s) { ECDSA_VALIDATE_RET(grp != NULL); ECDSA_VALIDATE_RET(Q != NULL); @@ -819,12 +805,7 @@ int mbedtls_ecdsa_write_signature( #if !defined(MBEDTLS_DEPRECATED_REMOVED) && defined(MBEDTLS_ECDSA_DETERMINISTIC) int mbedtls_ecdsa_write_signature_det( - mbedtls_ecdsa_context* ctx, - const unsigned char* hash, - size_t hlen, - unsigned char* sig, - size_t* slen, - mbedtls_md_type_t md_alg) + mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, unsigned char* sig, size_t* slen, mbedtls_md_type_t md_alg) { ECDSA_VALIDATE_RET(ctx != NULL); ECDSA_VALIDATE_RET(hash != NULL); @@ -837,8 +818,7 @@ int mbedtls_ecdsa_write_signature_det( /* * Read and check signature */ -int mbedtls_ecdsa_read_signature( - mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, const unsigned char* sig, size_t slen) +int mbedtls_ecdsa_read_signature(mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, const unsigned char* sig, size_t slen) { ECDSA_VALIDATE_RET(ctx != NULL); ECDSA_VALIDATE_RET(hash != NULL); @@ -850,12 +830,7 @@ int mbedtls_ecdsa_read_signature( * Restartable read and check signature */ int mbedtls_ecdsa_read_signature_restartable( - mbedtls_ecdsa_context* ctx, - const unsigned char* hash, - size_t hlen, - const unsigned char* sig, - size_t slen, - mbedtls_ecdsa_restart_ctx* rs_ctx) + mbedtls_ecdsa_context* ctx, const unsigned char* hash, size_t hlen, const unsigned char* sig, size_t slen, mbedtls_ecdsa_restart_ctx* rs_ctx) { int ret; unsigned char* p = (unsigned char*)sig; @@ -910,8 +885,7 @@ cleanup: /* * Generate key pair */ -int mbedtls_ecdsa_genkey( - mbedtls_ecdsa_context* ctx, mbedtls_ecp_group_id gid, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +int mbedtls_ecdsa_genkey(mbedtls_ecdsa_context* ctx, mbedtls_ecp_group_id gid, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret = 0; ECDSA_VALIDATE_RET(ctx != NULL); diff --git a/nettls/ssl/ecjpake.c b/nettls/ssl/ecjpake.c index 35c78ff05f6e10234a2d72502aa7ce21785c0ee3..541582f1a76fef43c6f425534b70cbfa90f67692 100644 --- a/nettls/ssl/ecjpake.c +++ b/nettls/ssl/ecjpake.c @@ -170,8 +170,8 @@ int mbedtls_ecjpake_check(const mbedtls_ecjpake_context* ctx) /* * Write a point plus its length to a buffer */ -static int ecjpake_write_len_point( - unsigned char** p, const unsigned char* end, const mbedtls_ecp_group* grp, const int pf, const mbedtls_ecp_point* P) +static int + ecjpake_write_len_point(unsigned char** p, const unsigned char* end, const mbedtls_ecp_group* grp, const int pf, const mbedtls_ecp_point* P) { int ret; size_t len; @@ -524,20 +524,14 @@ int mbedtls_ecjpake_read_round_one(mbedtls_ecjpake_context* ctx, const unsigned ECJPAKE_VALIDATE_RET(ctx != NULL); ECJPAKE_VALIDATE_RET(buf != NULL); - return (ecjpake_kkpp_read( - ctx->md_info, &ctx->grp, ctx->point_format, &ctx->grp.G, &ctx->Xp1, &ctx->Xp2, ID_PEER, buf, len)); + return (ecjpake_kkpp_read(ctx->md_info, &ctx->grp, ctx->point_format, &ctx->grp.G, &ctx->Xp1, &ctx->Xp2, ID_PEER, buf, len)); } /* * Generate and write the first round message */ int mbedtls_ecjpake_write_round_one( - mbedtls_ecjpake_context* ctx, - unsigned char* buf, - size_t len, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_ecjpake_context* ctx, unsigned char* buf, size_t len, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { ECJPAKE_VALIDATE_RET(ctx != NULL); ECJPAKE_VALIDATE_RET(buf != NULL); @@ -545,19 +539,14 @@ int mbedtls_ecjpake_write_round_one( ECJPAKE_VALIDATE_RET(f_rng != NULL); return (ecjpake_kkpp_write( - ctx->md_info, &ctx->grp, ctx->point_format, &ctx->grp.G, &ctx->xm1, &ctx->Xm1, &ctx->xm2, &ctx->Xm2, ID_MINE, - buf, len, olen, f_rng, p_rng)); + ctx->md_info, &ctx->grp, ctx->point_format, &ctx->grp.G, &ctx->xm1, &ctx->Xm1, &ctx->xm2, &ctx->Xm2, ID_MINE, buf, len, olen, f_rng, p_rng)); } /* * Compute the sum of three points R = A + B + C */ -static int ecjpake_ecp_add3( - mbedtls_ecp_group* grp, - mbedtls_ecp_point* R, - const mbedtls_ecp_point* A, - const mbedtls_ecp_point* B, - const mbedtls_ecp_point* C) +static int + ecjpake_ecp_add3(mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_ecp_point* A, const mbedtls_ecp_point* B, const mbedtls_ecp_point* C) { int ret; mbedtls_mpi one; @@ -664,12 +653,7 @@ cleanup: * Generate and write the second round message (S: 7.4.2.5, C: 7.4.2.6) */ int mbedtls_ecjpake_write_round_two( - mbedtls_ecjpake_context* ctx, - unsigned char* buf, - size_t len, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_ecjpake_context* ctx, unsigned char* buf, size_t len, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; mbedtls_ecp_point G; /* C: GA, S: GB */ @@ -723,8 +707,7 @@ int mbedtls_ecjpake_write_round_two( MBEDTLS_MPI_CHK(mbedtls_ecp_tls_write_point(&ctx->grp, &Xm, ctx->point_format, &ec_len, p, end - p)); p += ec_len; - MBEDTLS_MPI_CHK( - ecjpake_zkp_write(ctx->md_info, &ctx->grp, ctx->point_format, &G, &xm, &Xm, ID_MINE, &p, end, f_rng, p_rng)); + MBEDTLS_MPI_CHK(ecjpake_zkp_write(ctx->md_info, &ctx->grp, ctx->point_format, &G, &xm, &Xm, ID_MINE, &p, end, f_rng, p_rng)); *olen = p - buf; @@ -740,12 +723,7 @@ cleanup: * Derive PMS (7.4.2.7 / 7.4.2.8) */ int mbedtls_ecjpake_derive_secret( - mbedtls_ecjpake_context* ctx, - unsigned char* buf, - size_t len, - size_t* olen, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_ecjpake_context* ctx, unsigned char* buf, size_t len, size_t* olen, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; mbedtls_ecp_point K; @@ -812,96 +790,77 @@ int mbedtls_ecjpake_self_test(int verbose) } #else -static const unsigned char ecjpake_test_password[] = {0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x6a, 0x70, - 0x61, 0x6b, 0x65, 0x74, 0x65, 0x73, 0x74}; +static const unsigned char ecjpake_test_password[] = {0x74, 0x68, 0x72, 0x65, 0x61, 0x64, 0x6a, 0x70, 0x61, 0x6b, 0x65, 0x74, 0x65, 0x73, 0x74}; #if !defined(MBEDTLS_ECJPAKE_ALT) -static const unsigned char ecjpake_test_x1[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, - 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x21}; +static const unsigned char ecjpake_test_x1[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, + 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x21}; -static const unsigned char ecjpake_test_x2[] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, - 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, - 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81}; +static const unsigned char ecjpake_test_x2[] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81}; -static const unsigned char ecjpake_test_x3[] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, - 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, - 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81}; +static const unsigned char ecjpake_test_x3[] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, + 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x81}; -static const unsigned char ecjpake_test_x4[] = {0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, - 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, - 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe1}; +static const unsigned char ecjpake_test_x4[] = {0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, + 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe1}; static const unsigned char ecjpake_test_cli_one[] = { - 0x41, 0x04, 0xac, 0xcf, 0x01, 0x06, 0xef, 0x85, 0x8f, 0xa2, 0xd9, 0x19, 0x33, 0x13, 0x46, 0x80, 0x5a, 0x78, 0xb5, - 0x8b, 0xba, 0xd0, 0xb8, 0x44, 0xe5, 0xc7, 0x89, 0x28, 0x79, 0x14, 0x61, 0x87, 0xdd, 0x26, 0x66, 0xad, 0xa7, 0x81, - 0xbb, 0x7f, 0x11, 0x13, 0x72, 0x25, 0x1a, 0x89, 0x10, 0x62, 0x1f, 0x63, 0x4d, 0xf1, 0x28, 0xac, 0x48, 0xe3, 0x81, - 0xfd, 0x6e, 0xf9, 0x06, 0x07, 0x31, 0xf6, 0x94, 0xa4, 0x41, 0x04, 0x1d, 0xd0, 0xbd, 0x5d, 0x45, 0x66, 0xc9, 0xbe, - 0xd9, 0xce, 0x7d, 0xe7, 0x01, 0xb5, 0xe8, 0x2e, 0x08, 0xe8, 0x4b, 0x73, 0x04, 0x66, 0x01, 0x8a, 0xb9, 0x03, 0xc7, - 0x9e, 0xb9, 0x82, 0x17, 0x22, 0x36, 0xc0, 0xc1, 0x72, 0x8a, 0xe4, 0xbf, 0x73, 0x61, 0x0d, 0x34, 0xde, 0x44, 0x24, - 0x6e, 0xf3, 0xd9, 0xc0, 0x5a, 0x22, 0x36, 0xfb, 0x66, 0xa6, 0x58, 0x3d, 0x74, 0x49, 0x30, 0x8b, 0xab, 0xce, 0x20, - 0x72, 0xfe, 0x16, 0x66, 0x29, 0x92, 0xe9, 0x23, 0x5c, 0x25, 0x00, 0x2f, 0x11, 0xb1, 0x50, 0x87, 0xb8, 0x27, 0x38, - 0xe0, 0x3c, 0x94, 0x5b, 0xf7, 0xa2, 0x99, 0x5d, 0xda, 0x1e, 0x98, 0x34, 0x58, 0x41, 0x04, 0x7e, 0xa6, 0xe3, 0xa4, - 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18, 0x40, - 0x9a, 0xc5, 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, 0x0a, 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, - 0xab, 0x0f, 0x6c, 0x7f, 0xd1, 0xc3, 0x35, 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7, 0xe3, 0x2b, 0xb0, - 0x13, 0xbb, 0x2b, 0x41, 0x04, 0xa4, 0x95, 0x58, 0xd3, 0x2e, 0xd1, 0xeb, 0xfc, 0x18, 0x16, 0xaf, 0x4f, 0xf0, 0x9b, - 0x55, 0xfc, 0xb4, 0xca, 0x47, 0xb2, 0xa0, 0x2d, 0x1e, 0x7c, 0xaf, 0x11, 0x79, 0xea, 0x3f, 0xe1, 0x39, 0x5b, 0x22, - 0xb8, 0x61, 0x96, 0x40, 0x16, 0xfa, 0xba, 0xf7, 0x2c, 0x97, 0x56, 0x95, 0xd9, 0x3d, 0x4d, 0xf0, 0xe5, 0x19, 0x7f, - 0xe9, 0xf0, 0x40, 0x63, 0x4e, 0xd5, 0x97, 0x64, 0x93, 0x77, 0x87, 0xbe, 0x20, 0xbc, 0x4d, 0xee, 0xbb, 0xf9, 0xb8, - 0xd6, 0x0a, 0x33, 0x5f, 0x04, 0x6c, 0xa3, 0xaa, 0x94, 0x1e, 0x45, 0x86, 0x4c, 0x7c, 0xad, 0xef, 0x9c, 0xf7, 0x5b, - 0x3d, 0x8b, 0x01, 0x0e, 0x44, 0x3e, 0xf0}; + 0x41, 0x04, 0xac, 0xcf, 0x01, 0x06, 0xef, 0x85, 0x8f, 0xa2, 0xd9, 0x19, 0x33, 0x13, 0x46, 0x80, 0x5a, 0x78, 0xb5, 0x8b, 0xba, 0xd0, 0xb8, 0x44, + 0xe5, 0xc7, 0x89, 0x28, 0x79, 0x14, 0x61, 0x87, 0xdd, 0x26, 0x66, 0xad, 0xa7, 0x81, 0xbb, 0x7f, 0x11, 0x13, 0x72, 0x25, 0x1a, 0x89, 0x10, 0x62, + 0x1f, 0x63, 0x4d, 0xf1, 0x28, 0xac, 0x48, 0xe3, 0x81, 0xfd, 0x6e, 0xf9, 0x06, 0x07, 0x31, 0xf6, 0x94, 0xa4, 0x41, 0x04, 0x1d, 0xd0, 0xbd, 0x5d, + 0x45, 0x66, 0xc9, 0xbe, 0xd9, 0xce, 0x7d, 0xe7, 0x01, 0xb5, 0xe8, 0x2e, 0x08, 0xe8, 0x4b, 0x73, 0x04, 0x66, 0x01, 0x8a, 0xb9, 0x03, 0xc7, 0x9e, + 0xb9, 0x82, 0x17, 0x22, 0x36, 0xc0, 0xc1, 0x72, 0x8a, 0xe4, 0xbf, 0x73, 0x61, 0x0d, 0x34, 0xde, 0x44, 0x24, 0x6e, 0xf3, 0xd9, 0xc0, 0x5a, 0x22, + 0x36, 0xfb, 0x66, 0xa6, 0x58, 0x3d, 0x74, 0x49, 0x30, 0x8b, 0xab, 0xce, 0x20, 0x72, 0xfe, 0x16, 0x66, 0x29, 0x92, 0xe9, 0x23, 0x5c, 0x25, 0x00, + 0x2f, 0x11, 0xb1, 0x50, 0x87, 0xb8, 0x27, 0x38, 0xe0, 0x3c, 0x94, 0x5b, 0xf7, 0xa2, 0x99, 0x5d, 0xda, 0x1e, 0x98, 0x34, 0x58, 0x41, 0x04, 0x7e, + 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18, 0x40, 0x9a, 0xc5, + 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, 0x0a, 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f, 0xd1, 0xc3, 0x35, + 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7, 0xe3, 0x2b, 0xb0, 0x13, 0xbb, 0x2b, 0x41, 0x04, 0xa4, 0x95, 0x58, 0xd3, 0x2e, 0xd1, 0xeb, + 0xfc, 0x18, 0x16, 0xaf, 0x4f, 0xf0, 0x9b, 0x55, 0xfc, 0xb4, 0xca, 0x47, 0xb2, 0xa0, 0x2d, 0x1e, 0x7c, 0xaf, 0x11, 0x79, 0xea, 0x3f, 0xe1, 0x39, + 0x5b, 0x22, 0xb8, 0x61, 0x96, 0x40, 0x16, 0xfa, 0xba, 0xf7, 0x2c, 0x97, 0x56, 0x95, 0xd9, 0x3d, 0x4d, 0xf0, 0xe5, 0x19, 0x7f, 0xe9, 0xf0, 0x40, + 0x63, 0x4e, 0xd5, 0x97, 0x64, 0x93, 0x77, 0x87, 0xbe, 0x20, 0xbc, 0x4d, 0xee, 0xbb, 0xf9, 0xb8, 0xd6, 0x0a, 0x33, 0x5f, 0x04, 0x6c, 0xa3, 0xaa, + 0x94, 0x1e, 0x45, 0x86, 0x4c, 0x7c, 0xad, 0xef, 0x9c, 0xf7, 0x5b, 0x3d, 0x8b, 0x01, 0x0e, 0x44, 0x3e, 0xf0}; static const unsigned char ecjpake_test_srv_one[] = { - 0x41, 0x04, 0x7e, 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, - 0x77, 0x99, 0x30, 0xfc, 0x18, 0x40, 0x9a, 0xc5, 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, 0x0a, - 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f, 0xd1, 0xc3, 0x35, 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, - 0xec, 0x91, 0xb7, 0xe3, 0x2b, 0xb0, 0x13, 0xbb, 0x2b, 0x41, 0x04, 0x09, 0xf8, 0x5b, 0x3d, 0x20, 0xeb, 0xd7, 0x88, - 0x5c, 0xe4, 0x64, 0xc0, 0x8d, 0x05, 0x6d, 0x64, 0x28, 0xfe, 0x4d, 0xd9, 0x28, 0x7a, 0xa3, 0x65, 0xf1, 0x31, 0xf4, - 0x36, 0x0f, 0xf3, 0x86, 0xd8, 0x46, 0x89, 0x8b, 0xc4, 0xb4, 0x15, 0x83, 0xc2, 0xa5, 0x19, 0x7f, 0x65, 0xd7, 0x87, - 0x42, 0x74, 0x6c, 0x12, 0xa5, 0xec, 0x0a, 0x4f, 0xfe, 0x2f, 0x27, 0x0a, 0x75, 0x0a, 0x1d, 0x8f, 0xb5, 0x16, 0x20, - 0x93, 0x4d, 0x74, 0xeb, 0x43, 0xe5, 0x4d, 0xf4, 0x24, 0xfd, 0x96, 0x30, 0x6c, 0x01, 0x17, 0xbf, 0x13, 0x1a, 0xfa, - 0xbf, 0x90, 0xa9, 0xd3, 0x3d, 0x11, 0x98, 0xd9, 0x05, 0x19, 0x37, 0x35, 0x14, 0x41, 0x04, 0x19, 0x0a, 0x07, 0x70, - 0x0f, 0xfa, 0x4b, 0xe6, 0xae, 0x1d, 0x79, 0xee, 0x0f, 0x06, 0xae, 0xb5, 0x44, 0xcd, 0x5a, 0xdd, 0xaa, 0xbe, 0xdf, - 0x70, 0xf8, 0x62, 0x33, 0x21, 0x33, 0x2c, 0x54, 0xf3, 0x55, 0xf0, 0xfb, 0xfe, 0xc7, 0x83, 0xed, 0x35, 0x9e, 0x5d, - 0x0b, 0xf7, 0x37, 0x7a, 0x0f, 0xc4, 0xea, 0x7a, 0xce, 0x47, 0x3c, 0x9c, 0x11, 0x2b, 0x41, 0xcc, 0xd4, 0x1a, 0xc5, - 0x6a, 0x56, 0x12, 0x41, 0x04, 0x36, 0x0a, 0x1c, 0xea, 0x33, 0xfc, 0xe6, 0x41, 0x15, 0x64, 0x58, 0xe0, 0xa4, 0xea, - 0xc2, 0x19, 0xe9, 0x68, 0x31, 0xe6, 0xae, 0xbc, 0x88, 0xb3, 0xf3, 0x75, 0x2f, 0x93, 0xa0, 0x28, 0x1d, 0x1b, 0xf1, - 0xfb, 0x10, 0x60, 0x51, 0xdb, 0x96, 0x94, 0xa8, 0xd6, 0xe8, 0x62, 0xa5, 0xef, 0x13, 0x24, 0xa3, 0xd9, 0xe2, 0x78, - 0x94, 0xf1, 0xee, 0x4f, 0x7c, 0x59, 0x19, 0x99, 0x65, 0xa8, 0xdd, 0x4a, 0x20, 0x91, 0x84, 0x7d, 0x2d, 0x22, 0xdf, - 0x3e, 0xe5, 0x5f, 0xaa, 0x2a, 0x3f, 0xb3, 0x3f, 0xd2, 0xd1, 0xe0, 0x55, 0xa0, 0x7a, 0x7c, 0x61, 0xec, 0xfb, 0x8d, - 0x80, 0xec, 0x00, 0xc2, 0xc9, 0xeb, 0x12}; + 0x41, 0x04, 0x7e, 0xa6, 0xe3, 0xa4, 0x48, 0x70, 0x37, 0xa9, 0xe0, 0xdb, 0xd7, 0x92, 0x62, 0xb2, 0xcc, 0x27, 0x3e, 0x77, 0x99, 0x30, 0xfc, 0x18, + 0x40, 0x9a, 0xc5, 0x36, 0x1c, 0x5f, 0xe6, 0x69, 0xd7, 0x02, 0xe1, 0x47, 0x79, 0x0a, 0xeb, 0x4c, 0xe7, 0xfd, 0x65, 0x75, 0xab, 0x0f, 0x6c, 0x7f, + 0xd1, 0xc3, 0x35, 0x93, 0x9a, 0xa8, 0x63, 0xba, 0x37, 0xec, 0x91, 0xb7, 0xe3, 0x2b, 0xb0, 0x13, 0xbb, 0x2b, 0x41, 0x04, 0x09, 0xf8, 0x5b, 0x3d, + 0x20, 0xeb, 0xd7, 0x88, 0x5c, 0xe4, 0x64, 0xc0, 0x8d, 0x05, 0x6d, 0x64, 0x28, 0xfe, 0x4d, 0xd9, 0x28, 0x7a, 0xa3, 0x65, 0xf1, 0x31, 0xf4, 0x36, + 0x0f, 0xf3, 0x86, 0xd8, 0x46, 0x89, 0x8b, 0xc4, 0xb4, 0x15, 0x83, 0xc2, 0xa5, 0x19, 0x7f, 0x65, 0xd7, 0x87, 0x42, 0x74, 0x6c, 0x12, 0xa5, 0xec, + 0x0a, 0x4f, 0xfe, 0x2f, 0x27, 0x0a, 0x75, 0x0a, 0x1d, 0x8f, 0xb5, 0x16, 0x20, 0x93, 0x4d, 0x74, 0xeb, 0x43, 0xe5, 0x4d, 0xf4, 0x24, 0xfd, 0x96, + 0x30, 0x6c, 0x01, 0x17, 0xbf, 0x13, 0x1a, 0xfa, 0xbf, 0x90, 0xa9, 0xd3, 0x3d, 0x11, 0x98, 0xd9, 0x05, 0x19, 0x37, 0x35, 0x14, 0x41, 0x04, 0x19, + 0x0a, 0x07, 0x70, 0x0f, 0xfa, 0x4b, 0xe6, 0xae, 0x1d, 0x79, 0xee, 0x0f, 0x06, 0xae, 0xb5, 0x44, 0xcd, 0x5a, 0xdd, 0xaa, 0xbe, 0xdf, 0x70, 0xf8, + 0x62, 0x33, 0x21, 0x33, 0x2c, 0x54, 0xf3, 0x55, 0xf0, 0xfb, 0xfe, 0xc7, 0x83, 0xed, 0x35, 0x9e, 0x5d, 0x0b, 0xf7, 0x37, 0x7a, 0x0f, 0xc4, 0xea, + 0x7a, 0xce, 0x47, 0x3c, 0x9c, 0x11, 0x2b, 0x41, 0xcc, 0xd4, 0x1a, 0xc5, 0x6a, 0x56, 0x12, 0x41, 0x04, 0x36, 0x0a, 0x1c, 0xea, 0x33, 0xfc, 0xe6, + 0x41, 0x15, 0x64, 0x58, 0xe0, 0xa4, 0xea, 0xc2, 0x19, 0xe9, 0x68, 0x31, 0xe6, 0xae, 0xbc, 0x88, 0xb3, 0xf3, 0x75, 0x2f, 0x93, 0xa0, 0x28, 0x1d, + 0x1b, 0xf1, 0xfb, 0x10, 0x60, 0x51, 0xdb, 0x96, 0x94, 0xa8, 0xd6, 0xe8, 0x62, 0xa5, 0xef, 0x13, 0x24, 0xa3, 0xd9, 0xe2, 0x78, 0x94, 0xf1, 0xee, + 0x4f, 0x7c, 0x59, 0x19, 0x99, 0x65, 0xa8, 0xdd, 0x4a, 0x20, 0x91, 0x84, 0x7d, 0x2d, 0x22, 0xdf, 0x3e, 0xe5, 0x5f, 0xaa, 0x2a, 0x3f, 0xb3, 0x3f, + 0xd2, 0xd1, 0xe0, 0x55, 0xa0, 0x7a, 0x7c, 0x61, 0xec, 0xfb, 0x8d, 0x80, 0xec, 0x00, 0xc2, 0xc9, 0xeb, 0x12}; static const unsigned char ecjpake_test_srv_two[] = { - 0x03, 0x00, 0x17, 0x41, 0x04, 0x0f, 0xb2, 0x2b, 0x1d, 0x5d, 0x11, 0x23, 0xe0, 0xef, 0x9f, 0xeb, 0x9d, 0x8a, 0x2e, - 0x59, 0x0a, 0x1f, 0x4d, 0x7c, 0xed, 0x2c, 0x2b, 0x06, 0x58, 0x6e, 0x8f, 0x2a, 0x16, 0xd4, 0xeb, 0x2f, 0xda, 0x43, - 0x28, 0xa2, 0x0b, 0x07, 0xd8, 0xfd, 0x66, 0x76, 0x54, 0xca, 0x18, 0xc5, 0x4e, 0x32, 0xa3, 0x33, 0xa0, 0x84, 0x54, - 0x51, 0xe9, 0x26, 0xee, 0x88, 0x04, 0xfd, 0x7a, 0xf0, 0xaa, 0xa7, 0xa6, 0x41, 0x04, 0x55, 0x16, 0xea, 0x3e, 0x54, - 0xa0, 0xd5, 0xd8, 0xb2, 0xce, 0x78, 0x6b, 0x38, 0xd3, 0x83, 0x37, 0x00, 0x29, 0xa5, 0xdb, 0xe4, 0x45, 0x9c, 0x9d, - 0xd6, 0x01, 0xb4, 0x08, 0xa2, 0x4a, 0xe6, 0x46, 0x5c, 0x8a, 0xc9, 0x05, 0xb9, 0xeb, 0x03, 0xb5, 0xd3, 0x69, 0x1c, - 0x13, 0x9e, 0xf8, 0x3f, 0x1c, 0xd4, 0x20, 0x0f, 0x6c, 0x9c, 0xd4, 0xec, 0x39, 0x22, 0x18, 0xa5, 0x9e, 0xd2, 0x43, - 0xd3, 0xc8, 0x20, 0xff, 0x72, 0x4a, 0x9a, 0x70, 0xb8, 0x8c, 0xb8, 0x6f, 0x20, 0xb4, 0x34, 0xc6, 0x86, 0x5a, 0xa1, - 0xcd, 0x79, 0x06, 0xdd, 0x7c, 0x9b, 0xce, 0x35, 0x25, 0xf5, 0x08, 0x27, 0x6f, 0x26, 0x83, 0x6c}; + 0x03, 0x00, 0x17, 0x41, 0x04, 0x0f, 0xb2, 0x2b, 0x1d, 0x5d, 0x11, 0x23, 0xe0, 0xef, 0x9f, 0xeb, 0x9d, 0x8a, 0x2e, 0x59, 0x0a, 0x1f, 0x4d, 0x7c, + 0xed, 0x2c, 0x2b, 0x06, 0x58, 0x6e, 0x8f, 0x2a, 0x16, 0xd4, 0xeb, 0x2f, 0xda, 0x43, 0x28, 0xa2, 0x0b, 0x07, 0xd8, 0xfd, 0x66, 0x76, 0x54, 0xca, + 0x18, 0xc5, 0x4e, 0x32, 0xa3, 0x33, 0xa0, 0x84, 0x54, 0x51, 0xe9, 0x26, 0xee, 0x88, 0x04, 0xfd, 0x7a, 0xf0, 0xaa, 0xa7, 0xa6, 0x41, 0x04, 0x55, + 0x16, 0xea, 0x3e, 0x54, 0xa0, 0xd5, 0xd8, 0xb2, 0xce, 0x78, 0x6b, 0x38, 0xd3, 0x83, 0x37, 0x00, 0x29, 0xa5, 0xdb, 0xe4, 0x45, 0x9c, 0x9d, 0xd6, + 0x01, 0xb4, 0x08, 0xa2, 0x4a, 0xe6, 0x46, 0x5c, 0x8a, 0xc9, 0x05, 0xb9, 0xeb, 0x03, 0xb5, 0xd3, 0x69, 0x1c, 0x13, 0x9e, 0xf8, 0x3f, 0x1c, 0xd4, + 0x20, 0x0f, 0x6c, 0x9c, 0xd4, 0xec, 0x39, 0x22, 0x18, 0xa5, 0x9e, 0xd2, 0x43, 0xd3, 0xc8, 0x20, 0xff, 0x72, 0x4a, 0x9a, 0x70, 0xb8, 0x8c, 0xb8, + 0x6f, 0x20, 0xb4, 0x34, 0xc6, 0x86, 0x5a, 0xa1, 0xcd, 0x79, 0x06, 0xdd, 0x7c, 0x9b, 0xce, 0x35, 0x25, 0xf5, 0x08, 0x27, 0x6f, 0x26, 0x83, 0x6c}; static const unsigned char ecjpake_test_cli_two[] = { - 0x41, 0x04, 0x69, 0xd5, 0x4e, 0xe8, 0x5e, 0x90, 0xce, 0x3f, 0x12, 0x46, 0x74, 0x2d, 0xe5, 0x07, 0xe9, 0x39, 0xe8, - 0x1d, 0x1d, 0xc1, 0xc5, 0xcb, 0x98, 0x8b, 0x58, 0xc3, 0x10, 0xc9, 0xfd, 0xd9, 0x52, 0x4d, 0x93, 0x72, 0x0b, 0x45, - 0x54, 0x1c, 0x83, 0xee, 0x88, 0x41, 0x19, 0x1d, 0xa7, 0xce, 0xd8, 0x6e, 0x33, 0x12, 0xd4, 0x36, 0x23, 0xc1, 0xd6, - 0x3e, 0x74, 0x98, 0x9a, 0xba, 0x4a, 0xff, 0xd1, 0xee, 0x41, 0x04, 0x07, 0x7e, 0x8c, 0x31, 0xe2, 0x0e, 0x6b, 0xed, - 0xb7, 0x60, 0xc1, 0x35, 0x93, 0xe6, 0x9f, 0x15, 0xbe, 0x85, 0xc2, 0x7d, 0x68, 0xcd, 0x09, 0xcc, 0xb8, 0xc4, 0x18, - 0x36, 0x08, 0x91, 0x7c, 0x5c, 0x3d, 0x40, 0x9f, 0xac, 0x39, 0xfe, 0xfe, 0xe8, 0x2f, 0x72, 0x92, 0xd3, 0x6f, 0x0d, - 0x23, 0xe0, 0x55, 0x91, 0x3f, 0x45, 0xa5, 0x2b, 0x85, 0xdd, 0x8a, 0x20, 0x52, 0xe9, 0xe1, 0x29, 0xbb, 0x4d, 0x20, - 0x0f, 0x01, 0x1f, 0x19, 0x48, 0x35, 0x35, 0xa6, 0xe8, 0x9a, 0x58, 0x0c, 0x9b, 0x00, 0x03, 0xba, 0xf2, 0x14, 0x62, - 0xec, 0xe9, 0x1a, 0x82, 0xcc, 0x38, 0xdb, 0xdc, 0xae, 0x60, 0xd9, 0xc5, 0x4c}; - -static const unsigned char ecjpake_test_pms[] = {0xf3, 0xd4, 0x7f, 0x59, 0x98, 0x44, 0xdb, 0x92, 0xa5, 0x69, 0xbb, - 0xe7, 0x98, 0x1e, 0x39, 0xd9, 0x31, 0xfd, 0x74, 0x3b, 0xf2, 0x2e, - 0x98, 0xf9, 0xb4, 0x38, 0xf7, 0x19, 0xd3, 0xc4, 0xf3, 0x51}; + 0x41, 0x04, 0x69, 0xd5, 0x4e, 0xe8, 0x5e, 0x90, 0xce, 0x3f, 0x12, 0x46, 0x74, 0x2d, 0xe5, 0x07, 0xe9, 0x39, 0xe8, 0x1d, 0x1d, 0xc1, 0xc5, 0xcb, + 0x98, 0x8b, 0x58, 0xc3, 0x10, 0xc9, 0xfd, 0xd9, 0x52, 0x4d, 0x93, 0x72, 0x0b, 0x45, 0x54, 0x1c, 0x83, 0xee, 0x88, 0x41, 0x19, 0x1d, 0xa7, 0xce, + 0xd8, 0x6e, 0x33, 0x12, 0xd4, 0x36, 0x23, 0xc1, 0xd6, 0x3e, 0x74, 0x98, 0x9a, 0xba, 0x4a, 0xff, 0xd1, 0xee, 0x41, 0x04, 0x07, 0x7e, 0x8c, 0x31, + 0xe2, 0x0e, 0x6b, 0xed, 0xb7, 0x60, 0xc1, 0x35, 0x93, 0xe6, 0x9f, 0x15, 0xbe, 0x85, 0xc2, 0x7d, 0x68, 0xcd, 0x09, 0xcc, 0xb8, 0xc4, 0x18, 0x36, + 0x08, 0x91, 0x7c, 0x5c, 0x3d, 0x40, 0x9f, 0xac, 0x39, 0xfe, 0xfe, 0xe8, 0x2f, 0x72, 0x92, 0xd3, 0x6f, 0x0d, 0x23, 0xe0, 0x55, 0x91, 0x3f, 0x45, + 0xa5, 0x2b, 0x85, 0xdd, 0x8a, 0x20, 0x52, 0xe9, 0xe1, 0x29, 0xbb, 0x4d, 0x20, 0x0f, 0x01, 0x1f, 0x19, 0x48, 0x35, 0x35, 0xa6, 0xe8, 0x9a, 0x58, + 0x0c, 0x9b, 0x00, 0x03, 0xba, 0xf2, 0x14, 0x62, 0xec, 0xe9, 0x1a, 0x82, 0xcc, 0x38, 0xdb, 0xdc, 0xae, 0x60, 0xd9, 0xc5, 0x4c}; + +static const unsigned char ecjpake_test_pms[] = {0xf3, 0xd4, 0x7f, 0x59, 0x98, 0x44, 0xdb, 0x92, 0xa5, 0x69, 0xbb, 0xe7, 0x98, 0x1e, 0x39, 0xd9, + 0x31, 0xfd, 0x74, 0x3b, 0xf2, 0x2e, 0x98, 0xf9, 0xb4, 0x38, 0xf7, 0x19, 0xd3, 0xc4, 0xf3, 0x51}; /* Load my private keys and generate the corresponding public keys */ -static int ecjpake_test_load( - mbedtls_ecjpake_context* ctx, const unsigned char* xm1, size_t len1, const unsigned char* xm2, size_t len2) +static int ecjpake_test_load(mbedtls_ecjpake_context* ctx, const unsigned char* xm1, size_t len1, const unsigned char* xm2, size_t len2) { int ret; @@ -963,14 +922,12 @@ int mbedtls_ecjpake_self_test(int verbose) TEST_ASSERT( mbedtls_ecjpake_setup( - &cli, MBEDTLS_ECJPAKE_CLIENT, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, ecjpake_test_password, - sizeof(ecjpake_test_password)) + &cli, MBEDTLS_ECJPAKE_CLIENT, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, ecjpake_test_password, sizeof(ecjpake_test_password)) == 0); TEST_ASSERT( mbedtls_ecjpake_setup( - &srv, MBEDTLS_ECJPAKE_SERVER, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, ecjpake_test_password, - sizeof(ecjpake_test_password)) + &srv, MBEDTLS_ECJPAKE_SERVER, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, ecjpake_test_password, sizeof(ecjpake_test_password)) == 0); if (verbose != 0) @@ -1015,11 +972,9 @@ int mbedtls_ecjpake_self_test(int verbose) mbedtls_printf(" ECJPAKE test #2 (reference handshake): "); /* Simulate generation of round one */ - MBEDTLS_MPI_CHK( - ecjpake_test_load(&cli, ecjpake_test_x1, sizeof(ecjpake_test_x1), ecjpake_test_x2, sizeof(ecjpake_test_x2))); + MBEDTLS_MPI_CHK(ecjpake_test_load(&cli, ecjpake_test_x1, sizeof(ecjpake_test_x1), ecjpake_test_x2, sizeof(ecjpake_test_x2))); - MBEDTLS_MPI_CHK( - ecjpake_test_load(&srv, ecjpake_test_x3, sizeof(ecjpake_test_x3), ecjpake_test_x4, sizeof(ecjpake_test_x4))); + MBEDTLS_MPI_CHK(ecjpake_test_load(&srv, ecjpake_test_x3, sizeof(ecjpake_test_x3), ecjpake_test_x4, sizeof(ecjpake_test_x4))); /* Read round one */ TEST_ASSERT(mbedtls_ecjpake_read_round_one(&srv, ecjpake_test_cli_one, sizeof(ecjpake_test_cli_one)) == 0); diff --git a/nettls/ssl/ecp.c b/nettls/ssl/ecp.c index 090b0b92e9956f092f319ac21d928a1fdd894e79..e9f384ca56accc2bcd59e53790fa8ab5d0d81cf2 100644 --- a/nettls/ssl/ecp.c +++ b/nettls/ssl/ecp.c @@ -599,12 +599,10 @@ int mbedtls_ecp_check_budget(const mbedtls_ecp_group* grp, mbedtls_ecp_restart_c #endif /* MBEDTLS_ECP_RESTARTABLE */ -#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) \ - || defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) \ - || defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) \ - || defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) \ - || defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) \ - || defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) +#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) \ + || defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) \ + || defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) \ + || defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) #define ECP_SHORTWEIERSTRASS #endif @@ -929,8 +927,7 @@ int mbedtls_ecp_point_cmp(const mbedtls_ecp_point* P, const mbedtls_ecp_point* Q ECP_VALIDATE_RET(P != NULL); ECP_VALIDATE_RET(Q != NULL); - if (mbedtls_mpi_cmp_mpi(&P->X, &Q->X) == 0 && mbedtls_mpi_cmp_mpi(&P->Y, &Q->Y) == 0 - && mbedtls_mpi_cmp_mpi(&P->Z, &Q->Z) == 0) { + if (mbedtls_mpi_cmp_mpi(&P->X, &Q->X) == 0 && mbedtls_mpi_cmp_mpi(&P->Y, &Q->Y) == 0 && mbedtls_mpi_cmp_mpi(&P->Z, &Q->Z) == 0) { return (0); } @@ -959,12 +956,7 @@ cleanup: * Export a point into unsigned binary data (SEC1 2.3.3) */ int mbedtls_ecp_point_write_binary( - const mbedtls_ecp_group* grp, - const mbedtls_ecp_point* P, - int format, - size_t* olen, - unsigned char* buf, - size_t buflen) + const mbedtls_ecp_group* grp, const mbedtls_ecp_point* P, int format, size_t* olen, unsigned char* buf, size_t buflen) { int ret = 0; size_t plen; @@ -1015,8 +1007,7 @@ cleanup: /* * Import a point from unsigned binary data (SEC1 2.3.4) */ -int mbedtls_ecp_point_read_binary( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, const unsigned char* buf, size_t ilen) +int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, const unsigned char* buf, size_t ilen) { int ret; size_t plen; @@ -1056,8 +1047,7 @@ cleanup: * opaque point <1..2^8-1>; * } ECPoint; */ -int mbedtls_ecp_tls_read_point( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, const unsigned char** buf, size_t buf_len) +int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, const unsigned char** buf, size_t buf_len) { unsigned char data_len; const unsigned char* buf_start; @@ -1091,13 +1081,7 @@ int mbedtls_ecp_tls_read_point( * opaque point <1..2^8-1>; * } ECPoint; */ -int mbedtls_ecp_tls_write_point( - const mbedtls_ecp_group* grp, - const mbedtls_ecp_point* pt, - int format, - size_t* olen, - unsigned char* buf, - size_t blen) +int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group* grp, const mbedtls_ecp_point* pt, int format, size_t* olen, unsigned char* buf, size_t blen) { int ret; ECP_VALIDATE_RET(grp != NULL); @@ -1607,8 +1591,7 @@ cleanup: * * Cost: 1A := 8M + 3S */ -static int ecp_add_mixed( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_ecp_point* P, const mbedtls_ecp_point* Q) +static int ecp_add_mixed(const mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_ecp_point* P, const mbedtls_ecp_point* Q) { int ret; mbedtls_mpi T1, T2, T3, T4, X, Y, Z; @@ -1718,8 +1701,7 @@ cleanup: * * This countermeasure was first suggested in [2]. */ -static int ecp_randomize_jac( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +static int ecp_randomize_jac(const mbedtls_ecp_group* grp, mbedtls_ecp_point* pt, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; mbedtls_mpi l, ll; @@ -1894,12 +1876,7 @@ static void ecp_comb_recode_core(unsigned char x[], size_t d, unsigned char w, c * to minimize maximum blocking time. */ static int ecp_precompute_comb( - const mbedtls_ecp_group* grp, - mbedtls_ecp_point T[], - const mbedtls_ecp_point* P, - unsigned char w, - size_t d, - mbedtls_ecp_restart_ctx* rs_ctx) + const mbedtls_ecp_group* grp, mbedtls_ecp_point T[], const mbedtls_ecp_point* P, unsigned char w, size_t d, mbedtls_ecp_restart_ctx* rs_ctx) { int ret; unsigned char i; @@ -2027,12 +2004,7 @@ cleanup: * * See ecp_comb_recode_core() for background */ -static int ecp_select_comb( - const mbedtls_ecp_group* grp, - mbedtls_ecp_point* R, - const mbedtls_ecp_point T[], - unsigned char T_size, - unsigned char i) +static int ecp_select_comb(const mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_ecp_point T[], unsigned char T_size, unsigned char i) { int ret; unsigned char ii, j; @@ -2139,12 +2111,7 @@ cleanup: * See ecp_comb_recode_core() for background. */ static int ecp_comb_recode_scalar( - const mbedtls_ecp_group* grp, - const mbedtls_mpi* m, - unsigned char k[COMB_MAX_D + 1], - size_t d, - unsigned char w, - unsigned char* parity_trick) + const mbedtls_ecp_group* grp, const mbedtls_mpi* m, unsigned char k[COMB_MAX_D + 1], size_t d, unsigned char w, unsigned char* parity_trick) { int ret; mbedtls_mpi M, mm; @@ -2480,8 +2447,7 @@ cleanup: * This countermeasure was first suggested in [2]. * Cost: 2M */ -static int ecp_randomize_mxz( - const mbedtls_ecp_group* grp, mbedtls_ecp_point* P, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +static int ecp_randomize_mxz(const mbedtls_ecp_group* grp, mbedtls_ecp_point* P, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; mbedtls_mpi l; @@ -2812,8 +2778,8 @@ static int ecp_check_pubkey_sw(const mbedtls_ecp_group* grp, const mbedtls_ecp_p mbedtls_mpi YY, RHS; /* pt coordinates must be normalized for our checks */ - if (mbedtls_mpi_cmp_int(&pt->X, 0) < 0 || mbedtls_mpi_cmp_int(&pt->Y, 0) < 0 - || mbedtls_mpi_cmp_mpi(&pt->X, &grp->P) >= 0 || mbedtls_mpi_cmp_mpi(&pt->Y, &grp->P) >= 0) + if (mbedtls_mpi_cmp_int(&pt->X, 0) < 0 || mbedtls_mpi_cmp_int(&pt->Y, 0) < 0 || mbedtls_mpi_cmp_mpi(&pt->X, &grp->P) >= 0 + || mbedtls_mpi_cmp_mpi(&pt->Y, &grp->P) >= 0) return (MBEDTLS_ERR_ECP_INVALID_KEY); mbedtls_mpi_init(&YY); @@ -2859,11 +2825,7 @@ cleanup: * NOT constant-time - ONLY for short Weierstrass! */ static int mbedtls_ecp_mul_shortcuts( - mbedtls_ecp_group* grp, - mbedtls_ecp_point* R, - const mbedtls_mpi* m, - const mbedtls_ecp_point* P, - mbedtls_ecp_restart_ctx* rs_ctx) + mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_mpi* m, const mbedtls_ecp_point* P, mbedtls_ecp_restart_ctx* rs_ctx) { int ret; @@ -2985,12 +2947,7 @@ cleanup: * NOT constant-time */ int mbedtls_ecp_muladd( - mbedtls_ecp_group* grp, - mbedtls_ecp_point* R, - const mbedtls_mpi* m, - const mbedtls_ecp_point* P, - const mbedtls_mpi* n, - const mbedtls_ecp_point* Q) + mbedtls_ecp_group* grp, mbedtls_ecp_point* R, const mbedtls_mpi* m, const mbedtls_ecp_point* P, const mbedtls_mpi* n, const mbedtls_ecp_point* Q) { ECP_VALIDATE_RET(grp != NULL); ECP_VALIDATE_RET(R != NULL); @@ -3078,8 +3035,7 @@ int mbedtls_ecp_check_privkey(const mbedtls_ecp_group* grp, const mbedtls_mpi* d /* * Generate a private key */ -int mbedtls_ecp_gen_privkey( - const mbedtls_ecp_group* grp, mbedtls_mpi* d, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group* grp, mbedtls_mpi* d, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; size_t n_size; @@ -3185,12 +3141,7 @@ cleanup: /* * Generate key pair, wrapper for conventional base point */ -int mbedtls_ecp_gen_keypair( - mbedtls_ecp_group* grp, - mbedtls_mpi* d, - mbedtls_ecp_point* Q, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) +int mbedtls_ecp_gen_keypair(mbedtls_ecp_group* grp, mbedtls_mpi* d, mbedtls_ecp_point* Q, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { ECP_VALIDATE_RET(grp != NULL); ECP_VALIDATE_RET(d != NULL); @@ -3203,8 +3154,7 @@ int mbedtls_ecp_gen_keypair( /* * Generate a keypair, prettier wrapper */ -int mbedtls_ecp_gen_key( - mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair* key, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) +int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair* key, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; ECP_VALIDATE_RET(key != NULL); @@ -3241,8 +3191,7 @@ int mbedtls_ecp_check_pub_priv(const mbedtls_ecp_keypair* pub, const mbedtls_ecp /* Also checks d is valid */ MBEDTLS_MPI_CHK(mbedtls_ecp_mul(&grp, &Q, &prv->d, &prv->grp.G, NULL, NULL)); - if (mbedtls_mpi_cmp_mpi(&Q.X, &prv->Q.X) || mbedtls_mpi_cmp_mpi(&Q.Y, &prv->Q.Y) - || mbedtls_mpi_cmp_mpi(&Q.Z, &prv->Q.Z)) { + if (mbedtls_mpi_cmp_mpi(&Q.X, &prv->Q.X) || mbedtls_mpi_cmp_mpi(&Q.Y, &prv->Q.Y) || mbedtls_mpi_cmp_mpi(&Q.Z, &prv->Q.Z)) { ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; goto cleanup; } @@ -3272,9 +3221,8 @@ static const uint8_t test_kdf_z[16] = { 0x3b, 0xa9, 0x79, 0xe9, 0xbc, 0x5e, 0x3e, 0xc7, 0x61, 0x30, 0x36, 0xb6, 0xf5, 0x1c, 0xd5, 0xaa, }; static const uint8_t test_kdf_out[40] = { - 0x3e, 0xf6, 0xda, 0xf9, 0x51, 0x60, 0x70, 0x5f, 0xdf, 0x21, 0xcd, 0xab, 0xac, 0x25, - 0x7b, 0x05, 0xfe, 0xc1, 0xab, 0x7c, 0xc9, 0x68, 0x43, 0x25, 0x8a, 0xfc, 0x40, 0x6e, - 0x5b, 0xf7, 0x98, 0x27, 0x10, 0xfa, 0x7b, 0x93, 0x52, 0xd4, 0x16, 0xaa, + 0x3e, 0xf6, 0xda, 0xf9, 0x51, 0x60, 0x70, 0x5f, 0xdf, 0x21, 0xcd, 0xab, 0xac, 0x25, 0x7b, 0x05, 0xfe, 0xc1, 0xab, 0x7c, + 0xc9, 0x68, 0x43, 0x25, 0x8a, 0xfc, 0x40, 0x6e, 0x5b, 0xf7, 0x98, 0x27, 0x10, 0xfa, 0x7b, 0x93, 0x52, 0xd4, 0x16, 0xaa, }; #elif defined(MBEDTLS_SHA256_C) @@ -3283,9 +3231,8 @@ static const uint8_t test_kdf_z[16] = { 0xc8, 0x3e, 0x35, 0x8e, 0x99, 0xa6, 0x89, 0xc6, 0x7d, 0xb4, 0xfe, 0x39, 0xcf, 0x8f, 0x26, 0xe1, }; static const uint8_t test_kdf_out[40] = { - 0x7d, 0xf6, 0x41, 0xf8, 0x3c, 0x47, 0xdc, 0x28, 0x5f, 0x7f, 0xaa, 0xde, 0x05, 0x64, - 0xd6, 0x25, 0x00, 0x6a, 0x47, 0xd9, 0x1e, 0xa4, 0xa0, 0x8c, 0xd7, 0xf7, 0x0c, 0x99, - 0xaa, 0xa0, 0x72, 0x66, 0x69, 0x0e, 0x25, 0xaa, 0xa1, 0x63, 0x14, 0x79, + 0x7d, 0xf6, 0x41, 0xf8, 0x3c, 0x47, 0xdc, 0x28, 0x5f, 0x7f, 0xaa, 0xde, 0x05, 0x64, 0xd6, 0x25, 0x00, 0x6a, 0x47, 0xd9, + 0x1e, 0xa4, 0xa0, 0x8c, 0xd7, 0xf7, 0x0c, 0x99, 0xaa, 0xa0, 0x72, 0x66, 0x69, 0x0e, 0x25, 0xaa, 0xa1, 0x63, 0x14, 0x79, }; #endif diff --git a/nettls/ssl/ecp_curves.c b/nettls/ssl/ecp_curves.c index 7f7865a427d8f09e567b0afca49e86d421cf221f..61a79de70b0d4c63e260169ebcf336f107cfa2bd 100644 --- a/nettls/ssl/ecp_curves.c +++ b/nettls/ssl/ecp_curves.c @@ -74,8 +74,7 @@ #if defined(MBEDTLS_HAVE_INT32) #define BYTES_TO_T_UINT_4(a, b, c, d) \ - ((mbedtls_mpi_uint)(a) << 0) | ((mbedtls_mpi_uint)(b) << 8) | ((mbedtls_mpi_uint)(c) << 16) \ - | ((mbedtls_mpi_uint)(d) << 24) + ((mbedtls_mpi_uint)(a) << 0) | ((mbedtls_mpi_uint)(b) << 8) | ((mbedtls_mpi_uint)(c) << 16) | ((mbedtls_mpi_uint)(d) << 24) #define BYTES_TO_T_UINT_2(a, b) BYTES_TO_T_UINT_4(a, b, 0, 0) @@ -84,9 +83,8 @@ #else /* 64-bits */ #define BYTES_TO_T_UINT_8(a, b, c, d, e, f, g, h) \ - ((mbedtls_mpi_uint)(a) << 0) | ((mbedtls_mpi_uint)(b) << 8) | ((mbedtls_mpi_uint)(c) << 16) \ - | ((mbedtls_mpi_uint)(d) << 24) | ((mbedtls_mpi_uint)(e) << 32) | ((mbedtls_mpi_uint)(f) << 40) \ - | ((mbedtls_mpi_uint)(g) << 48) | ((mbedtls_mpi_uint)(h) << 56) + ((mbedtls_mpi_uint)(a) << 0) | ((mbedtls_mpi_uint)(b) << 8) | ((mbedtls_mpi_uint)(c) << 16) | ((mbedtls_mpi_uint)(d) << 24) \ + | ((mbedtls_mpi_uint)(e) << 32) | ((mbedtls_mpi_uint)(f) << 40) | ((mbedtls_mpi_uint)(g) << 48) | ((mbedtls_mpi_uint)(h) << 56) #define BYTES_TO_T_UINT_4(a, b, c, d) BYTES_TO_T_UINT_8(a, b, c, d, 0, 0, 0, 0) @@ -207,44 +205,29 @@ static const mbedtls_mpi_uint secp256r1_n[] = { */ #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) static const mbedtls_mpi_uint secp384r1_p[] = { - BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00), - BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF), - BYTES_TO_T_UINT_8(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), - BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), - BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), - BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), + BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00), BYTES_TO_T_UINT_8(0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF), + BYTES_TO_T_UINT_8(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), + BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), }; static const mbedtls_mpi_uint secp384r1_b[] = { - BYTES_TO_T_UINT_8(0xEF, 0x2A, 0xEC, 0xD3, 0xED, 0xC8, 0x85, 0x2A), - BYTES_TO_T_UINT_8(0x9D, 0xD1, 0x2E, 0x8A, 0x8D, 0x39, 0x56, 0xC6), - BYTES_TO_T_UINT_8(0x5A, 0x87, 0x13, 0x50, 0x8F, 0x08, 0x14, 0x03), - BYTES_TO_T_UINT_8(0x12, 0x41, 0x81, 0xFE, 0x6E, 0x9C, 0x1D, 0x18), - BYTES_TO_T_UINT_8(0x19, 0x2D, 0xF8, 0xE3, 0x6B, 0x05, 0x8E, 0x98), - BYTES_TO_T_UINT_8(0xE4, 0xE7, 0x3E, 0xE2, 0xA7, 0x2F, 0x31, 0xB3), + BYTES_TO_T_UINT_8(0xEF, 0x2A, 0xEC, 0xD3, 0xED, 0xC8, 0x85, 0x2A), BYTES_TO_T_UINT_8(0x9D, 0xD1, 0x2E, 0x8A, 0x8D, 0x39, 0x56, 0xC6), + BYTES_TO_T_UINT_8(0x5A, 0x87, 0x13, 0x50, 0x8F, 0x08, 0x14, 0x03), BYTES_TO_T_UINT_8(0x12, 0x41, 0x81, 0xFE, 0x6E, 0x9C, 0x1D, 0x18), + BYTES_TO_T_UINT_8(0x19, 0x2D, 0xF8, 0xE3, 0x6B, 0x05, 0x8E, 0x98), BYTES_TO_T_UINT_8(0xE4, 0xE7, 0x3E, 0xE2, 0xA7, 0x2F, 0x31, 0xB3), }; static const mbedtls_mpi_uint secp384r1_gx[] = { - BYTES_TO_T_UINT_8(0xB7, 0x0A, 0x76, 0x72, 0x38, 0x5E, 0x54, 0x3A), - BYTES_TO_T_UINT_8(0x6C, 0x29, 0x55, 0xBF, 0x5D, 0xF2, 0x02, 0x55), - BYTES_TO_T_UINT_8(0x38, 0x2A, 0x54, 0x82, 0xE0, 0x41, 0xF7, 0x59), - BYTES_TO_T_UINT_8(0x98, 0x9B, 0xA7, 0x8B, 0x62, 0x3B, 0x1D, 0x6E), - BYTES_TO_T_UINT_8(0x74, 0xAD, 0x20, 0xF3, 0x1E, 0xC7, 0xB1, 0x8E), - BYTES_TO_T_UINT_8(0x37, 0x05, 0x8B, 0xBE, 0x22, 0xCA, 0x87, 0xAA), + BYTES_TO_T_UINT_8(0xB7, 0x0A, 0x76, 0x72, 0x38, 0x5E, 0x54, 0x3A), BYTES_TO_T_UINT_8(0x6C, 0x29, 0x55, 0xBF, 0x5D, 0xF2, 0x02, 0x55), + BYTES_TO_T_UINT_8(0x38, 0x2A, 0x54, 0x82, 0xE0, 0x41, 0xF7, 0x59), BYTES_TO_T_UINT_8(0x98, 0x9B, 0xA7, 0x8B, 0x62, 0x3B, 0x1D, 0x6E), + BYTES_TO_T_UINT_8(0x74, 0xAD, 0x20, 0xF3, 0x1E, 0xC7, 0xB1, 0x8E), BYTES_TO_T_UINT_8(0x37, 0x05, 0x8B, 0xBE, 0x22, 0xCA, 0x87, 0xAA), }; static const mbedtls_mpi_uint secp384r1_gy[] = { - BYTES_TO_T_UINT_8(0x5F, 0x0E, 0xEA, 0x90, 0x7C, 0x1D, 0x43, 0x7A), - BYTES_TO_T_UINT_8(0x9D, 0x81, 0x7E, 0x1D, 0xCE, 0xB1, 0x60, 0x0A), - BYTES_TO_T_UINT_8(0xC0, 0xB8, 0xF0, 0xB5, 0x13, 0x31, 0xDA, 0xE9), - BYTES_TO_T_UINT_8(0x7C, 0x14, 0x9A, 0x28, 0xBD, 0x1D, 0xF4, 0xF8), - BYTES_TO_T_UINT_8(0x29, 0xDC, 0x92, 0x92, 0xBF, 0x98, 0x9E, 0x5D), - BYTES_TO_T_UINT_8(0x6F, 0x2C, 0x26, 0x96, 0x4A, 0xDE, 0x17, 0x36), + BYTES_TO_T_UINT_8(0x5F, 0x0E, 0xEA, 0x90, 0x7C, 0x1D, 0x43, 0x7A), BYTES_TO_T_UINT_8(0x9D, 0x81, 0x7E, 0x1D, 0xCE, 0xB1, 0x60, 0x0A), + BYTES_TO_T_UINT_8(0xC0, 0xB8, 0xF0, 0xB5, 0x13, 0x31, 0xDA, 0xE9), BYTES_TO_T_UINT_8(0x7C, 0x14, 0x9A, 0x28, 0xBD, 0x1D, 0xF4, 0xF8), + BYTES_TO_T_UINT_8(0x29, 0xDC, 0x92, 0x92, 0xBF, 0x98, 0x9E, 0x5D), BYTES_TO_T_UINT_8(0x6F, 0x2C, 0x26, 0x96, 0x4A, 0xDE, 0x17, 0x36), }; static const mbedtls_mpi_uint secp384r1_n[] = { - BYTES_TO_T_UINT_8(0x73, 0x29, 0xC5, 0xCC, 0x6A, 0x19, 0xEC, 0xEC), - BYTES_TO_T_UINT_8(0x7A, 0xA7, 0xB0, 0x48, 0xB2, 0x0D, 0x1A, 0x58), - BYTES_TO_T_UINT_8(0xDF, 0x2D, 0x37, 0xF4, 0x81, 0x4D, 0x63, 0xC7), - BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), - BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), - BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), + BYTES_TO_T_UINT_8(0x73, 0x29, 0xC5, 0xCC, 0x6A, 0x19, 0xEC, 0xEC), BYTES_TO_T_UINT_8(0x7A, 0xA7, 0xB0, 0x48, 0xB2, 0x0D, 0x1A, 0x58), + BYTES_TO_T_UINT_8(0xDF, 0x2D, 0x37, 0xF4, 0x81, 0x4D, 0x63, 0xC7), BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), + BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), BYTES_TO_T_UINT_8(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), }; #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ @@ -451,52 +434,34 @@ static const mbedtls_mpi_uint brainpoolP256r1_n[] = { */ #if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) static const mbedtls_mpi_uint brainpoolP384r1_p[] = { - BYTES_TO_T_UINT_8(0x53, 0xEC, 0x07, 0x31, 0x13, 0x00, 0x47, 0x87), - BYTES_TO_T_UINT_8(0x71, 0x1A, 0x1D, 0x90, 0x29, 0xA7, 0xD3, 0xAC), - BYTES_TO_T_UINT_8(0x23, 0x11, 0xB7, 0x7F, 0x19, 0xDA, 0xB1, 0x12), - BYTES_TO_T_UINT_8(0xB4, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15), - BYTES_TO_T_UINT_8(0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F), - BYTES_TO_T_UINT_8(0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C), + BYTES_TO_T_UINT_8(0x53, 0xEC, 0x07, 0x31, 0x13, 0x00, 0x47, 0x87), BYTES_TO_T_UINT_8(0x71, 0x1A, 0x1D, 0x90, 0x29, 0xA7, 0xD3, 0xAC), + BYTES_TO_T_UINT_8(0x23, 0x11, 0xB7, 0x7F, 0x19, 0xDA, 0xB1, 0x12), BYTES_TO_T_UINT_8(0xB4, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15), + BYTES_TO_T_UINT_8(0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F), BYTES_TO_T_UINT_8(0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C), }; static const mbedtls_mpi_uint brainpoolP384r1_a[] = { - BYTES_TO_T_UINT_8(0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04), - BYTES_TO_T_UINT_8(0xEB, 0xD4, 0x3A, 0x50, 0x4A, 0x81, 0xA5, 0x8A), - BYTES_TO_T_UINT_8(0x0F, 0xF9, 0x91, 0xBA, 0xEF, 0x65, 0x91, 0x13), - BYTES_TO_T_UINT_8(0x87, 0x27, 0xB2, 0x4F, 0x8E, 0xA2, 0xBE, 0xC2), - BYTES_TO_T_UINT_8(0xA0, 0xAF, 0x05, 0xCE, 0x0A, 0x08, 0x72, 0x3C), - BYTES_TO_T_UINT_8(0x0C, 0x15, 0x8C, 0x3D, 0xC6, 0x82, 0xC3, 0x7B), + BYTES_TO_T_UINT_8(0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04), BYTES_TO_T_UINT_8(0xEB, 0xD4, 0x3A, 0x50, 0x4A, 0x81, 0xA5, 0x8A), + BYTES_TO_T_UINT_8(0x0F, 0xF9, 0x91, 0xBA, 0xEF, 0x65, 0x91, 0x13), BYTES_TO_T_UINT_8(0x87, 0x27, 0xB2, 0x4F, 0x8E, 0xA2, 0xBE, 0xC2), + BYTES_TO_T_UINT_8(0xA0, 0xAF, 0x05, 0xCE, 0x0A, 0x08, 0x72, 0x3C), BYTES_TO_T_UINT_8(0x0C, 0x15, 0x8C, 0x3D, 0xC6, 0x82, 0xC3, 0x7B), }; static const mbedtls_mpi_uint brainpoolP384r1_b[] = { - BYTES_TO_T_UINT_8(0x11, 0x4C, 0x50, 0xFA, 0x96, 0x86, 0xB7, 0x3A), - BYTES_TO_T_UINT_8(0x94, 0xC9, 0xDB, 0x95, 0x02, 0x39, 0xB4, 0x7C), - BYTES_TO_T_UINT_8(0xD5, 0x62, 0xEB, 0x3E, 0xA5, 0x0E, 0x88, 0x2E), - BYTES_TO_T_UINT_8(0xA6, 0xD2, 0xDC, 0x07, 0xE1, 0x7D, 0xB7, 0x2F), - BYTES_TO_T_UINT_8(0x7C, 0x44, 0xF0, 0x16, 0x54, 0xB5, 0x39, 0x8B), - BYTES_TO_T_UINT_8(0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04), + BYTES_TO_T_UINT_8(0x11, 0x4C, 0x50, 0xFA, 0x96, 0x86, 0xB7, 0x3A), BYTES_TO_T_UINT_8(0x94, 0xC9, 0xDB, 0x95, 0x02, 0x39, 0xB4, 0x7C), + BYTES_TO_T_UINT_8(0xD5, 0x62, 0xEB, 0x3E, 0xA5, 0x0E, 0x88, 0x2E), BYTES_TO_T_UINT_8(0xA6, 0xD2, 0xDC, 0x07, 0xE1, 0x7D, 0xB7, 0x2F), + BYTES_TO_T_UINT_8(0x7C, 0x44, 0xF0, 0x16, 0x54, 0xB5, 0x39, 0x8B), BYTES_TO_T_UINT_8(0x26, 0x28, 0xCE, 0x22, 0xDD, 0xC7, 0xA8, 0x04), }; static const mbedtls_mpi_uint brainpoolP384r1_gx[] = { - BYTES_TO_T_UINT_8(0x1E, 0xAF, 0xD4, 0x47, 0xE2, 0xB2, 0x87, 0xEF), - BYTES_TO_T_UINT_8(0xAA, 0x46, 0xD6, 0x36, 0x34, 0xE0, 0x26, 0xE8), - BYTES_TO_T_UINT_8(0xE8, 0x10, 0xBD, 0x0C, 0xFE, 0xCA, 0x7F, 0xDB), - BYTES_TO_T_UINT_8(0xE3, 0x4F, 0xF1, 0x7E, 0xE7, 0xA3, 0x47, 0x88), - BYTES_TO_T_UINT_8(0x6B, 0x3F, 0xC1, 0xB7, 0x81, 0x3A, 0xA6, 0xA2), - BYTES_TO_T_UINT_8(0xFF, 0x45, 0xCF, 0x68, 0xF0, 0x64, 0x1C, 0x1D), + BYTES_TO_T_UINT_8(0x1E, 0xAF, 0xD4, 0x47, 0xE2, 0xB2, 0x87, 0xEF), BYTES_TO_T_UINT_8(0xAA, 0x46, 0xD6, 0x36, 0x34, 0xE0, 0x26, 0xE8), + BYTES_TO_T_UINT_8(0xE8, 0x10, 0xBD, 0x0C, 0xFE, 0xCA, 0x7F, 0xDB), BYTES_TO_T_UINT_8(0xE3, 0x4F, 0xF1, 0x7E, 0xE7, 0xA3, 0x47, 0x88), + BYTES_TO_T_UINT_8(0x6B, 0x3F, 0xC1, 0xB7, 0x81, 0x3A, 0xA6, 0xA2), BYTES_TO_T_UINT_8(0xFF, 0x45, 0xCF, 0x68, 0xF0, 0x64, 0x1C, 0x1D), }; static const mbedtls_mpi_uint brainpoolP384r1_gy[] = { - BYTES_TO_T_UINT_8(0x15, 0x53, 0x3C, 0x26, 0x41, 0x03, 0x82, 0x42), - BYTES_TO_T_UINT_8(0x11, 0x81, 0x91, 0x77, 0x21, 0x46, 0x46, 0x0E), - BYTES_TO_T_UINT_8(0x28, 0x29, 0x91, 0xF9, 0x4F, 0x05, 0x9C, 0xE1), - BYTES_TO_T_UINT_8(0x64, 0x58, 0xEC, 0xFE, 0x29, 0x0B, 0xB7, 0x62), - BYTES_TO_T_UINT_8(0x52, 0xD5, 0xCF, 0x95, 0x8E, 0xEB, 0xB1, 0x5C), - BYTES_TO_T_UINT_8(0xA4, 0xC2, 0xF9, 0x20, 0x75, 0x1D, 0xBE, 0x8A), + BYTES_TO_T_UINT_8(0x15, 0x53, 0x3C, 0x26, 0x41, 0x03, 0x82, 0x42), BYTES_TO_T_UINT_8(0x11, 0x81, 0x91, 0x77, 0x21, 0x46, 0x46, 0x0E), + BYTES_TO_T_UINT_8(0x28, 0x29, 0x91, 0xF9, 0x4F, 0x05, 0x9C, 0xE1), BYTES_TO_T_UINT_8(0x64, 0x58, 0xEC, 0xFE, 0x29, 0x0B, 0xB7, 0x62), + BYTES_TO_T_UINT_8(0x52, 0xD5, 0xCF, 0x95, 0x8E, 0xEB, 0xB1, 0x5C), BYTES_TO_T_UINT_8(0xA4, 0xC2, 0xF9, 0x20, 0x75, 0x1D, 0xBE, 0x8A), }; static const mbedtls_mpi_uint brainpoolP384r1_n[] = { - BYTES_TO_T_UINT_8(0x65, 0x65, 0x04, 0xE9, 0x02, 0x32, 0x88, 0x3B), - BYTES_TO_T_UINT_8(0x10, 0xC3, 0x7F, 0x6B, 0xAF, 0xB6, 0x3A, 0xCF), - BYTES_TO_T_UINT_8(0xA7, 0x25, 0x04, 0xAC, 0x6C, 0x6E, 0x16, 0x1F), - BYTES_TO_T_UINT_8(0xB3, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15), - BYTES_TO_T_UINT_8(0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F), - BYTES_TO_T_UINT_8(0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C), + BYTES_TO_T_UINT_8(0x65, 0x65, 0x04, 0xE9, 0x02, 0x32, 0x88, 0x3B), BYTES_TO_T_UINT_8(0x10, 0xC3, 0x7F, 0x6B, 0xAF, 0xB6, 0x3A, 0xCF), + BYTES_TO_T_UINT_8(0xA7, 0x25, 0x04, 0xAC, 0x6C, 0x6E, 0x16, 0x1F), BYTES_TO_T_UINT_8(0xB3, 0x56, 0x54, 0xED, 0x09, 0x71, 0x2F, 0x15), + BYTES_TO_T_UINT_8(0xDF, 0x41, 0xE6, 0x50, 0x7E, 0x6F, 0x5D, 0x0F), BYTES_TO_T_UINT_8(0x28, 0x6D, 0x38, 0xA3, 0x82, 0x1E, 0xB9, 0x8C), }; #endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */ @@ -505,64 +470,40 @@ static const mbedtls_mpi_uint brainpoolP384r1_n[] = { */ #if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) static const mbedtls_mpi_uint brainpoolP512r1_p[] = { - BYTES_TO_T_UINT_8(0xF3, 0x48, 0x3A, 0x58, 0x56, 0x60, 0xAA, 0x28), - BYTES_TO_T_UINT_8(0x85, 0xC6, 0x82, 0x2D, 0x2F, 0xFF, 0x81, 0x28), - BYTES_TO_T_UINT_8(0xE6, 0x80, 0xA3, 0xE6, 0x2A, 0xA1, 0xCD, 0xAE), - BYTES_TO_T_UINT_8(0x42, 0x68, 0xC6, 0x9B, 0x00, 0x9B, 0x4D, 0x7D), - BYTES_TO_T_UINT_8(0x71, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6), - BYTES_TO_T_UINT_8(0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB), - BYTES_TO_T_UINT_8(0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F), - BYTES_TO_T_UINT_8(0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA), + BYTES_TO_T_UINT_8(0xF3, 0x48, 0x3A, 0x58, 0x56, 0x60, 0xAA, 0x28), BYTES_TO_T_UINT_8(0x85, 0xC6, 0x82, 0x2D, 0x2F, 0xFF, 0x81, 0x28), + BYTES_TO_T_UINT_8(0xE6, 0x80, 0xA3, 0xE6, 0x2A, 0xA1, 0xCD, 0xAE), BYTES_TO_T_UINT_8(0x42, 0x68, 0xC6, 0x9B, 0x00, 0x9B, 0x4D, 0x7D), + BYTES_TO_T_UINT_8(0x71, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6), BYTES_TO_T_UINT_8(0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB), + BYTES_TO_T_UINT_8(0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F), BYTES_TO_T_UINT_8(0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA), }; static const mbedtls_mpi_uint brainpoolP512r1_a[] = { - BYTES_TO_T_UINT_8(0xCA, 0x94, 0xFC, 0x77, 0x4D, 0xAC, 0xC1, 0xE7), - BYTES_TO_T_UINT_8(0xB9, 0xC7, 0xF2, 0x2B, 0xA7, 0x17, 0x11, 0x7F), - BYTES_TO_T_UINT_8(0xB5, 0xC8, 0x9A, 0x8B, 0xC9, 0xF1, 0x2E, 0x0A), - BYTES_TO_T_UINT_8(0xA1, 0x3A, 0x25, 0xA8, 0x5A, 0x5D, 0xED, 0x2D), - BYTES_TO_T_UINT_8(0xBC, 0x63, 0x98, 0xEA, 0xCA, 0x41, 0x34, 0xA8), - BYTES_TO_T_UINT_8(0x10, 0x16, 0xF9, 0x3D, 0x8D, 0xDD, 0xCB, 0x94), - BYTES_TO_T_UINT_8(0xC5, 0x4C, 0x23, 0xAC, 0x45, 0x71, 0x32, 0xE2), - BYTES_TO_T_UINT_8(0x89, 0x3B, 0x60, 0x8B, 0x31, 0xA3, 0x30, 0x78), + BYTES_TO_T_UINT_8(0xCA, 0x94, 0xFC, 0x77, 0x4D, 0xAC, 0xC1, 0xE7), BYTES_TO_T_UINT_8(0xB9, 0xC7, 0xF2, 0x2B, 0xA7, 0x17, 0x11, 0x7F), + BYTES_TO_T_UINT_8(0xB5, 0xC8, 0x9A, 0x8B, 0xC9, 0xF1, 0x2E, 0x0A), BYTES_TO_T_UINT_8(0xA1, 0x3A, 0x25, 0xA8, 0x5A, 0x5D, 0xED, 0x2D), + BYTES_TO_T_UINT_8(0xBC, 0x63, 0x98, 0xEA, 0xCA, 0x41, 0x34, 0xA8), BYTES_TO_T_UINT_8(0x10, 0x16, 0xF9, 0x3D, 0x8D, 0xDD, 0xCB, 0x94), + BYTES_TO_T_UINT_8(0xC5, 0x4C, 0x23, 0xAC, 0x45, 0x71, 0x32, 0xE2), BYTES_TO_T_UINT_8(0x89, 0x3B, 0x60, 0x8B, 0x31, 0xA3, 0x30, 0x78), }; static const mbedtls_mpi_uint brainpoolP512r1_b[] = { - BYTES_TO_T_UINT_8(0x23, 0xF7, 0x16, 0x80, 0x63, 0xBD, 0x09, 0x28), - BYTES_TO_T_UINT_8(0xDD, 0xE5, 0xBA, 0x5E, 0xB7, 0x50, 0x40, 0x98), - BYTES_TO_T_UINT_8(0x67, 0x3E, 0x08, 0xDC, 0xCA, 0x94, 0xFC, 0x77), - BYTES_TO_T_UINT_8(0x4D, 0xAC, 0xC1, 0xE7, 0xB9, 0xC7, 0xF2, 0x2B), - BYTES_TO_T_UINT_8(0xA7, 0x17, 0x11, 0x7F, 0xB5, 0xC8, 0x9A, 0x8B), - BYTES_TO_T_UINT_8(0xC9, 0xF1, 0x2E, 0x0A, 0xA1, 0x3A, 0x25, 0xA8), - BYTES_TO_T_UINT_8(0x5A, 0x5D, 0xED, 0x2D, 0xBC, 0x63, 0x98, 0xEA), - BYTES_TO_T_UINT_8(0xCA, 0x41, 0x34, 0xA8, 0x10, 0x16, 0xF9, 0x3D), + BYTES_TO_T_UINT_8(0x23, 0xF7, 0x16, 0x80, 0x63, 0xBD, 0x09, 0x28), BYTES_TO_T_UINT_8(0xDD, 0xE5, 0xBA, 0x5E, 0xB7, 0x50, 0x40, 0x98), + BYTES_TO_T_UINT_8(0x67, 0x3E, 0x08, 0xDC, 0xCA, 0x94, 0xFC, 0x77), BYTES_TO_T_UINT_8(0x4D, 0xAC, 0xC1, 0xE7, 0xB9, 0xC7, 0xF2, 0x2B), + BYTES_TO_T_UINT_8(0xA7, 0x17, 0x11, 0x7F, 0xB5, 0xC8, 0x9A, 0x8B), BYTES_TO_T_UINT_8(0xC9, 0xF1, 0x2E, 0x0A, 0xA1, 0x3A, 0x25, 0xA8), + BYTES_TO_T_UINT_8(0x5A, 0x5D, 0xED, 0x2D, 0xBC, 0x63, 0x98, 0xEA), BYTES_TO_T_UINT_8(0xCA, 0x41, 0x34, 0xA8, 0x10, 0x16, 0xF9, 0x3D), }; static const mbedtls_mpi_uint brainpoolP512r1_gx[] = { - BYTES_TO_T_UINT_8(0x22, 0xF8, 0xB9, 0xBC, 0x09, 0x22, 0x35, 0x8B), - BYTES_TO_T_UINT_8(0x68, 0x5E, 0x6A, 0x40, 0x47, 0x50, 0x6D, 0x7C), - BYTES_TO_T_UINT_8(0x5F, 0x7D, 0xB9, 0x93, 0x7B, 0x68, 0xD1, 0x50), - BYTES_TO_T_UINT_8(0x8D, 0xD4, 0xD0, 0xE2, 0x78, 0x1F, 0x3B, 0xFF), - BYTES_TO_T_UINT_8(0x8E, 0x09, 0xD0, 0xF4, 0xEE, 0x62, 0x3B, 0xB4), - BYTES_TO_T_UINT_8(0xC1, 0x16, 0xD9, 0xB5, 0x70, 0x9F, 0xED, 0x85), - BYTES_TO_T_UINT_8(0x93, 0x6A, 0x4C, 0x9C, 0x2E, 0x32, 0x21, 0x5A), - BYTES_TO_T_UINT_8(0x64, 0xD9, 0x2E, 0xD8, 0xBD, 0xE4, 0xAE, 0x81), + BYTES_TO_T_UINT_8(0x22, 0xF8, 0xB9, 0xBC, 0x09, 0x22, 0x35, 0x8B), BYTES_TO_T_UINT_8(0x68, 0x5E, 0x6A, 0x40, 0x47, 0x50, 0x6D, 0x7C), + BYTES_TO_T_UINT_8(0x5F, 0x7D, 0xB9, 0x93, 0x7B, 0x68, 0xD1, 0x50), BYTES_TO_T_UINT_8(0x8D, 0xD4, 0xD0, 0xE2, 0x78, 0x1F, 0x3B, 0xFF), + BYTES_TO_T_UINT_8(0x8E, 0x09, 0xD0, 0xF4, 0xEE, 0x62, 0x3B, 0xB4), BYTES_TO_T_UINT_8(0xC1, 0x16, 0xD9, 0xB5, 0x70, 0x9F, 0xED, 0x85), + BYTES_TO_T_UINT_8(0x93, 0x6A, 0x4C, 0x9C, 0x2E, 0x32, 0x21, 0x5A), BYTES_TO_T_UINT_8(0x64, 0xD9, 0x2E, 0xD8, 0xBD, 0xE4, 0xAE, 0x81), }; static const mbedtls_mpi_uint brainpoolP512r1_gy[] = { - BYTES_TO_T_UINT_8(0x92, 0x08, 0xD8, 0x3A, 0x0F, 0x1E, 0xCD, 0x78), - BYTES_TO_T_UINT_8(0x06, 0x54, 0xF0, 0xA8, 0x2F, 0x2B, 0xCA, 0xD1), - BYTES_TO_T_UINT_8(0xAE, 0x63, 0x27, 0x8A, 0xD8, 0x4B, 0xCA, 0x5B), - BYTES_TO_T_UINT_8(0x5E, 0x48, 0x5F, 0x4A, 0x49, 0xDE, 0xDC, 0xB2), - BYTES_TO_T_UINT_8(0x11, 0x81, 0x1F, 0x88, 0x5B, 0xC5, 0x00, 0xA0), - BYTES_TO_T_UINT_8(0x1A, 0x7B, 0xA5, 0x24, 0x00, 0xF7, 0x09, 0xF2), - BYTES_TO_T_UINT_8(0xFD, 0x22, 0x78, 0xCF, 0xA9, 0xBF, 0xEA, 0xC0), - BYTES_TO_T_UINT_8(0xEC, 0x32, 0x63, 0x56, 0x5D, 0x38, 0xDE, 0x7D), + BYTES_TO_T_UINT_8(0x92, 0x08, 0xD8, 0x3A, 0x0F, 0x1E, 0xCD, 0x78), BYTES_TO_T_UINT_8(0x06, 0x54, 0xF0, 0xA8, 0x2F, 0x2B, 0xCA, 0xD1), + BYTES_TO_T_UINT_8(0xAE, 0x63, 0x27, 0x8A, 0xD8, 0x4B, 0xCA, 0x5B), BYTES_TO_T_UINT_8(0x5E, 0x48, 0x5F, 0x4A, 0x49, 0xDE, 0xDC, 0xB2), + BYTES_TO_T_UINT_8(0x11, 0x81, 0x1F, 0x88, 0x5B, 0xC5, 0x00, 0xA0), BYTES_TO_T_UINT_8(0x1A, 0x7B, 0xA5, 0x24, 0x00, 0xF7, 0x09, 0xF2), + BYTES_TO_T_UINT_8(0xFD, 0x22, 0x78, 0xCF, 0xA9, 0xBF, 0xEA, 0xC0), BYTES_TO_T_UINT_8(0xEC, 0x32, 0x63, 0x56, 0x5D, 0x38, 0xDE, 0x7D), }; static const mbedtls_mpi_uint brainpoolP512r1_n[] = { - BYTES_TO_T_UINT_8(0x69, 0x00, 0xA9, 0x9C, 0x82, 0x96, 0x87, 0xB5), - BYTES_TO_T_UINT_8(0xDD, 0xDA, 0x5D, 0x08, 0x81, 0xD3, 0xB1, 0x1D), - BYTES_TO_T_UINT_8(0x47, 0x10, 0xAC, 0x7F, 0x19, 0x61, 0x86, 0x41), - BYTES_TO_T_UINT_8(0x19, 0x26, 0xA9, 0x4C, 0x41, 0x5C, 0x3E, 0x55), - BYTES_TO_T_UINT_8(0x70, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6), - BYTES_TO_T_UINT_8(0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB), - BYTES_TO_T_UINT_8(0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F), - BYTES_TO_T_UINT_8(0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA), + BYTES_TO_T_UINT_8(0x69, 0x00, 0xA9, 0x9C, 0x82, 0x96, 0x87, 0xB5), BYTES_TO_T_UINT_8(0xDD, 0xDA, 0x5D, 0x08, 0x81, 0xD3, 0xB1, 0x1D), + BYTES_TO_T_UINT_8(0x47, 0x10, 0xAC, 0x7F, 0x19, 0x61, 0x86, 0x41), BYTES_TO_T_UINT_8(0x19, 0x26, 0xA9, 0x4C, 0x41, 0x5C, 0x3E, 0x55), + BYTES_TO_T_UINT_8(0x70, 0x08, 0x33, 0x70, 0xCA, 0x9C, 0x63, 0xD6), BYTES_TO_T_UINT_8(0x0E, 0xD2, 0xC9, 0xB3, 0xB3, 0x8D, 0x30, 0xCB), + BYTES_TO_T_UINT_8(0x07, 0xFC, 0xC9, 0x33, 0xAE, 0xE6, 0xD4, 0x3F), BYTES_TO_T_UINT_8(0x8B, 0xC4, 0xE9, 0xDB, 0xB8, 0x9D, 0xDD, 0xAA), }; #endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */ @@ -666,13 +607,10 @@ static int ecp_mod_p256k1(mbedtls_mpi*); #define LOAD_GROUP_A(G) \ ecp_group_load( \ - grp, G##_p, sizeof(G##_p), G##_a, sizeof(G##_a), G##_b, sizeof(G##_b), G##_gx, sizeof(G##_gx), G##_gy, \ - sizeof(G##_gy), G##_n, sizeof(G##_n)) + grp, G##_p, sizeof(G##_p), G##_a, sizeof(G##_a), G##_b, sizeof(G##_b), G##_gx, sizeof(G##_gx), G##_gy, sizeof(G##_gy), G##_n, sizeof(G##_n)) #define LOAD_GROUP(G) \ - ecp_group_load( \ - grp, G##_p, sizeof(G##_p), NULL, 0, G##_b, sizeof(G##_b), G##_gx, sizeof(G##_gx), G##_gy, sizeof(G##_gy), \ - G##_n, sizeof(G##_n)) + ecp_group_load(grp, G##_p, sizeof(G##_p), NULL, 0, G##_b, sizeof(G##_b), G##_gx, sizeof(G##_gx), G##_gy, sizeof(G##_gy), G##_n, sizeof(G##_n)) #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) /* @@ -946,8 +884,7 @@ cleanup: #undef LAST #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ -#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) \ - || defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) +#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) /* * The reader is advised to first understand ecp_mod_p192() since the same * general structure is used here, but with additional complications: @@ -1483,8 +1420,7 @@ cleanup: } #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */ -#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) \ - || defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) +#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) /* * Fast quasi-reduction modulo P = 2^s - R, * with R about 33 bits, used by the Koblitz curves. @@ -1494,8 +1430,7 @@ cleanup: */ #define P_KOBLITZ_MAX (256 / 8 / sizeof(mbedtls_mpi_uint)) // Max limbs in P #define P_KOBLITZ_R (8 / sizeof(mbedtls_mpi_uint)) // Limbs in R -static inline int ecp_mod_koblitz( - mbedtls_mpi* N, mbedtls_mpi_uint* Rp, size_t p_limbs, size_t adjust, size_t shift, mbedtls_mpi_uint mask) +static inline int ecp_mod_koblitz(mbedtls_mpi* N, mbedtls_mpi_uint* Rp, size_t p_limbs, size_t adjust, size_t shift, mbedtls_mpi_uint mask) { int ret; size_t i; diff --git a/nettls/ssl/entropy.c b/nettls/ssl/entropy.c index 202f061a1c08a0fadbb59dc67ba1ce496d511f1a..18f7c8fb70324e11a2c1f5da0fa04fe7935b2ee1 100644 --- a/nettls/ssl/entropy.c +++ b/nettls/ssl/entropy.c @@ -104,8 +104,7 @@ void mbedtls_entropy_init(mbedtls_entropy_context* ctx) #if !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) - mbedtls_entropy_add_source( - ctx, mbedtls_platform_entropy_poll, NULL, MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_SOURCE_STRONG); + mbedtls_entropy_add_source(ctx, mbedtls_platform_entropy_poll, NULL, MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_SOURCE_STRONG); #endif #endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */ @@ -132,8 +131,7 @@ void mbedtls_entropy_free(mbedtls_entropy_context* ctx) ctx->accumulator_started = -1; } -int mbedtls_entropy_add_source( - mbedtls_entropy_context* ctx, mbedtls_entropy_f_source_ptr f_source, void* p_source, size_t threshold, int strong) +int mbedtls_entropy_add_source(mbedtls_entropy_context* ctx, mbedtls_entropy_f_source_ptr f_source, void* p_source, size_t threshold, int strong) { int idx, ret = 0; diff --git a/nettls/ssl/entropy_poll.c b/nettls/ssl/entropy_poll.c index 42b7aea216d35dd15370005738c4083a5153a395..a25630211db397df3c94dc7aab212a2bb99ced42 100644 --- a/nettls/ssl/entropy_poll.c +++ b/nettls/ssl/entropy_poll.c @@ -64,8 +64,7 @@ #if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) -#if !defined(unix) && !defined(__unix__) && !defined(__unix) && !defined(__APPLE__) && !defined(_WIN32) \ - && !defined(__QNXNTO__) && !defined(__HAIKU__) +#if !defined(unix) && !defined(__unix__) && !defined(__unix) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__HAIKU__) #error "Platform entropy sources only work on Unix and Windows, see MBEDTLS_NO_PLATFORM_ENTROPY in config.h" #endif diff --git a/nettls/ssl/error.c b/nettls/ssl/error.c index 561b6d9aeca0d91a618dc9a14fdb9db02bb48df7..15238284c208fb2118f682147cf0692575d89d85 100644 --- a/nettls/ssl/error.c +++ b/nettls/ssl/error.c @@ -319,8 +319,7 @@ void mbedtls_strerror(int ret, char* buf, size_t buflen) if (use_ret == -(MBEDTLS_ERR_ECP_HW_ACCEL_FAILED)) mbedtls_snprintf(buf, buflen, "ECP - The ECP hardware accelerator failed"); if (use_ret == -(MBEDTLS_ERR_ECP_IN_PROGRESS)) - mbedtls_snprintf( - buf, buflen, "ECP - Operation in progress, call again with the same parameters to continue"); + mbedtls_snprintf(buf, buflen, "ECP - Operation in progress, call again with the same parameters to continue"); #endif /* MBEDTLS_ECP_C */ #if defined(MBEDTLS_MD_C) @@ -547,8 +546,7 @@ void mbedtls_strerror(int ret, char* buf, size_t buflen) "SSL - None of the common ciphersuites is usable (eg, no suitable certificate, see " "debug messages)"); if (use_ret == -(MBEDTLS_ERR_SSL_WANT_READ)) - mbedtls_snprintf( - buf, buflen, "SSL - No data of requested type currently available on underlying transport"); + mbedtls_snprintf(buf, buflen, "SSL - No data of requested type currently available on underlying transport"); if (use_ret == -(MBEDTLS_ERR_SSL_WANT_WRITE)) mbedtls_snprintf(buf, buflen, "SSL - Connection requires a write call"); if (use_ret == -(MBEDTLS_ERR_SSL_TIMEOUT)) @@ -602,11 +600,9 @@ void mbedtls_strerror(int ret, char* buf, size_t buflen) if (use_ret == -(MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG)) mbedtls_snprintf(buf, buflen, "X509 - Signature algorithm (oid) is unsupported"); if (use_ret == -(MBEDTLS_ERR_X509_SIG_MISMATCH)) - mbedtls_snprintf( - buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)"); + mbedtls_snprintf(buf, buflen, "X509 - Signature algorithms do not match. (see \\c ::mbedtls_x509_crt sig_oid)"); if (use_ret == -(MBEDTLS_ERR_X509_CERT_VERIFY_FAILED)) - mbedtls_snprintf( - buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed"); + mbedtls_snprintf(buf, buflen, "X509 - Certificate verification failed, e.g. CRL, CA or signature check failed"); if (use_ret == -(MBEDTLS_ERR_X509_CERT_UNKNOWN_FORMAT)) mbedtls_snprintf(buf, buflen, "X509 - Format not recognized as DER or PEM"); if (use_ret == -(MBEDTLS_ERR_X509_BAD_INPUT_DATA)) @@ -755,8 +751,7 @@ void mbedtls_strerror(int ret, char* buf, size_t buflen) if (use_ret == -(MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA)) mbedtls_snprintf(buf, buflen, "CHACHA20 - Invalid input parameter(s)"); if (use_ret == -(MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE)) - mbedtls_snprintf( - buf, buflen, "CHACHA20 - Feature not available. For example, s part of the API is not implemented"); + mbedtls_snprintf(buf, buflen, "CHACHA20 - Feature not available. For example, s part of the API is not implemented"); if (use_ret == -(MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED)) mbedtls_snprintf(buf, buflen, "CHACHA20 - Chacha20 hardware accelerator failed"); #endif /* MBEDTLS_CHACHA20_C */ @@ -891,8 +886,7 @@ void mbedtls_strerror(int ret, char* buf, size_t buflen) if (use_ret == -(MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA)) mbedtls_snprintf(buf, buflen, "POLY1305 - Invalid input parameter(s)"); if (use_ret == -(MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE)) - mbedtls_snprintf( - buf, buflen, "POLY1305 - Feature not available. For example, s part of the API is not implemented"); + mbedtls_snprintf(buf, buflen, "POLY1305 - Feature not available. For example, s part of the API is not implemented"); if (use_ret == -(MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED)) mbedtls_snprintf(buf, buflen, "POLY1305 - Poly1305 hardware accelerator failed"); #endif /* MBEDTLS_POLY1305_C */ diff --git a/nettls/ssl/gcm.c b/nettls/ssl/gcm.c index d838b6b92efdecd010ee7772798f2c3933c7a433..95f34764f3125194cd0668de96d49c9de30330ad 100644 --- a/nettls/ssl/gcm.c +++ b/nettls/ssl/gcm.c @@ -67,7 +67,6 @@ #include - #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) #include "nettls/aes.h" #include "nettls/platform.h" @@ -80,41 +79,36 @@ #if !defined(MBEDTLS_GCM_ALT) /* Parameter validation macros */ -#define GCM_VALIDATE_RET( cond ) \ - MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_GCM_BAD_INPUT ) -#define GCM_VALIDATE( cond ) \ - MBEDTLS_INTERNAL_VALIDATE( cond ) +#define GCM_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_GCM_BAD_INPUT) +#define GCM_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) /* * 32-bit integer manipulation macros (big endian) */ #ifndef GET_UINT32_BE -#define GET_UINT32_BE(n,b,i) \ -{ \ - (n) = ( (uint32_t) (b)[(i) ] << 24 ) \ - | ( (uint32_t) (b)[(i) + 1] << 16 ) \ - | ( (uint32_t) (b)[(i) + 2] << 8 ) \ - | ( (uint32_t) (b)[(i) + 3] ); \ -} +#define GET_UINT32_BE(n, b, i) \ + { \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ + } #endif #ifndef PUT_UINT32_BE -#define PUT_UINT32_BE(n,b,i) \ -{ \ - (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) ); \ -} +#define PUT_UINT32_BE(n, b, i) \ + { \ + (b)[(i)] = (unsigned char)((n) >> 24); \ + (b)[(i) + 1] = (unsigned char)((n) >> 16); \ + (b)[(i) + 2] = (unsigned char)((n) >> 8); \ + (b)[(i) + 3] = (unsigned char)((n)); \ + } #endif /* * Initialize a context */ -void mbedtls_gcm_init( mbedtls_gcm_context *ctx ) +void mbedtls_gcm_init(mbedtls_gcm_context* ctx) { - GCM_VALIDATE( ctx != NULL ); - memset( ctx, 0, sizeof( mbedtls_gcm_context ) ); + GCM_VALIDATE(ctx != NULL); + memset(ctx, 0, sizeof(mbedtls_gcm_context)); } /* @@ -125,7 +119,7 @@ void mbedtls_gcm_init( mbedtls_gcm_context *ctx ) * is the high-order bit of HH corresponds to P^0 and the low-order bit of HL * corresponds to P^127. */ -static int gcm_gen_table( mbedtls_gcm_context *ctx ) +static int gcm_gen_table(mbedtls_gcm_context* ctx) { int ret, i, j; uint64_t hi, lo; @@ -133,87 +127,78 @@ static int gcm_gen_table( mbedtls_gcm_context *ctx ) unsigned char h[16]; size_t olen = 0; - memset( h, 0, 16 ); - if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, h, 16, h, &olen ) ) != 0 ) - return( ret ); + memset(h, 0, 16); + if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, h, 16, h, &olen)) != 0) + return (ret); /* pack h as two 64-bits ints, big-endian */ - GET_UINT32_BE( hi, h, 0 ); - GET_UINT32_BE( lo, h, 4 ); - vh = (uint64_t) hi << 32 | lo; + GET_UINT32_BE(hi, h, 0); + GET_UINT32_BE(lo, h, 4); + vh = (uint64_t)hi << 32 | lo; - GET_UINT32_BE( hi, h, 8 ); - GET_UINT32_BE( lo, h, 12 ); - vl = (uint64_t) hi << 32 | lo; + GET_UINT32_BE(hi, h, 8); + GET_UINT32_BE(lo, h, 12); + vl = (uint64_t)hi << 32 | lo; /* 8 = 1000 corresponds to 1 in GF(2^128) */ ctx->HL[8] = vl; ctx->HH[8] = vh; - /* 0 corresponds to 0 in GF(2^128) */ ctx->HH[0] = 0; ctx->HL[0] = 0; - for( i = 4; i > 0; i >>= 1 ) - { - uint32_t T = ( vl & 1 ) * 0xe1000000U; - vl = ( vh << 63 ) | ( vl >> 1 ); - vh = ( vh >> 1 ) ^ ( (uint64_t) T << 32); + for (i = 4; i > 0; i >>= 1) { + uint32_t T = (vl & 1) * 0xe1000000U; + vl = (vh << 63) | (vl >> 1); + vh = (vh >> 1) ^ ((uint64_t)T << 32); ctx->HL[i] = vl; ctx->HH[i] = vh; } - for( i = 2; i <= 8; i *= 2 ) - { + for (i = 2; i <= 8; i *= 2) { uint64_t *HiL = ctx->HL + i, *HiH = ctx->HH + i; vh = *HiH; vl = *HiL; - for( j = 1; j < i; j++ ) - { + for (j = 1; j < i; j++) { HiH[j] = vh ^ ctx->HH[j]; HiL[j] = vl ^ ctx->HL[j]; } } - return( 0 ); + return (0); } -int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, - mbedtls_cipher_id_t cipher, - const unsigned char *key, - unsigned int keybits ) +int mbedtls_gcm_setkey(mbedtls_gcm_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits) { int ret; - const mbedtls_cipher_info_t *cipher_info; + const mbedtls_cipher_info_t* cipher_info; - GCM_VALIDATE_RET( ctx != NULL ); - GCM_VALIDATE_RET( key != NULL ); - GCM_VALIDATE_RET( keybits == 128 || keybits == 192 || keybits == 256 ); + GCM_VALIDATE_RET(ctx != NULL); + GCM_VALIDATE_RET(key != NULL); + GCM_VALIDATE_RET(keybits == 128 || keybits == 192 || keybits == 256); - cipher_info = mbedtls_cipher_info_from_values( cipher, keybits, MBEDTLS_MODE_ECB ); - if( cipher_info == NULL ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + cipher_info = mbedtls_cipher_info_from_values(cipher, keybits, MBEDTLS_MODE_ECB); + if (cipher_info == NULL) + return (MBEDTLS_ERR_GCM_BAD_INPUT); - if( cipher_info->block_size != 16 ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + if (cipher_info->block_size != 16) + return (MBEDTLS_ERR_GCM_BAD_INPUT); - mbedtls_cipher_free( &ctx->cipher_ctx ); + mbedtls_cipher_free(&ctx->cipher_ctx); - if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_cipher_setup(&ctx->cipher_ctx, cipher_info)) != 0) + return (ret); - if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, - MBEDTLS_ENCRYPT ) ) != 0 ) - { - return( ret ); + if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits, MBEDTLS_ENCRYPT)) != 0) { + return (ret); } - if( ( ret = gcm_gen_table( ctx ) ) != 0 ) - return( ret ); + if ((ret = gcm_gen_table(ctx)) != 0) + return (ret); - return( 0 ); + return (0); } /* @@ -221,335 +206,295 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, * last4[x] = x times P^128 * where x and last4[x] are seen as elements of GF(2^128) as in [MGV] */ -static const uint64_t last4[16] = -{ - 0x0000, 0x1c20, 0x3840, 0x2460, - 0x7080, 0x6ca0, 0x48c0, 0x54e0, - 0xe100, 0xfd20, 0xd940, 0xc560, - 0x9180, 0x8da0, 0xa9c0, 0xb5e0 -}; +static const uint64_t last4[16] = {0x0000, 0x1c20, 0x3840, 0x2460, 0x7080, 0x6ca0, 0x48c0, 0x54e0, + 0xe100, 0xfd20, 0xd940, 0xc560, 0x9180, 0x8da0, 0xa9c0, 0xb5e0}; /* * Sets output to x times H using the precomputed tables. * x and output are seen as elements of GF(2^128) as in [MGV]. */ -static void gcm_mult( mbedtls_gcm_context *ctx, const unsigned char x[16], - unsigned char output[16] ) +static void gcm_mult(mbedtls_gcm_context* ctx, const unsigned char x[16], unsigned char output[16]) { int i = 0; unsigned char lo, hi, rem; uint64_t zh, zl; - - lo = x[15] & 0xf; zh = ctx->HH[lo]; zl = ctx->HL[lo]; - for( i = 15; i >= 0; i-- ) - { + for (i = 15; i >= 0; i--) { lo = x[i] & 0xf; hi = x[i] >> 4; - if( i != 15 ) - { - rem = (unsigned char) zl & 0xf; - zl = ( zh << 60 ) | ( zl >> 4 ); - zh = ( zh >> 4 ); - zh ^= (uint64_t) last4[rem] << 48; + if (i != 15) { + rem = (unsigned char)zl & 0xf; + zl = (zh << 60) | (zl >> 4); + zh = (zh >> 4); + zh ^= (uint64_t)last4[rem] << 48; zh ^= ctx->HH[lo]; zl ^= ctx->HL[lo]; - } - rem = (unsigned char) zl & 0xf; - zl = ( zh << 60 ) | ( zl >> 4 ); - zh = ( zh >> 4 ); - zh ^= (uint64_t) last4[rem] << 48; + rem = (unsigned char)zl & 0xf; + zl = (zh << 60) | (zl >> 4); + zh = (zh >> 4); + zh ^= (uint64_t)last4[rem] << 48; zh ^= ctx->HH[hi]; zl ^= ctx->HL[hi]; } - PUT_UINT32_BE( zh >> 32, output, 0 ); - PUT_UINT32_BE( zh, output, 4 ); - PUT_UINT32_BE( zl >> 32, output, 8 ); - PUT_UINT32_BE( zl, output, 12 ); + PUT_UINT32_BE(zh >> 32, output, 0); + PUT_UINT32_BE(zh, output, 4); + PUT_UINT32_BE(zl >> 32, output, 8); + PUT_UINT32_BE(zl, output, 12); } -int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, - int mode, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len ) +int mbedtls_gcm_starts(mbedtls_gcm_context* ctx, int mode, const unsigned char* iv, size_t iv_len, const unsigned char* add, size_t add_len) { int ret; unsigned char work_buf[16]; size_t i; - const unsigned char *p; + const unsigned char* p; size_t use_len, olen = 0; - GCM_VALIDATE_RET( ctx != NULL ); - GCM_VALIDATE_RET( iv != NULL ); - GCM_VALIDATE_RET( add_len == 0 || add != NULL ); + GCM_VALIDATE_RET(ctx != NULL); + GCM_VALIDATE_RET(iv != NULL); + GCM_VALIDATE_RET(add_len == 0 || add != NULL); /* IV and AD are limited to 2^64 bits, so 2^61 bytes */ /* IV is not allowed to be zero length */ - if( iv_len == 0 || - ( (uint64_t) iv_len ) >> 61 != 0 || - ( (uint64_t) add_len ) >> 61 != 0 ) - { - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + if (iv_len == 0 || ((uint64_t)iv_len) >> 61 != 0 || ((uint64_t)add_len) >> 61 != 0) { + return (MBEDTLS_ERR_GCM_BAD_INPUT); } - memset( ctx->y, 0x00, sizeof(ctx->y) ); - memset( ctx->buf, 0x00, sizeof(ctx->buf) ); + memset(ctx->y, 0x00, sizeof(ctx->y)); + memset(ctx->buf, 0x00, sizeof(ctx->buf)); ctx->mode = mode; ctx->len = 0; ctx->add_len = 0; - if( iv_len == 12 ) - { - memcpy( ctx->y, iv, iv_len ); + if (iv_len == 12) { + memcpy(ctx->y, iv, iv_len); ctx->y[15] = 1; - } - else - { - memset( work_buf, 0x00, 16 ); - PUT_UINT32_BE( iv_len * 8, work_buf, 12 ); + } else { + memset(work_buf, 0x00, 16); + PUT_UINT32_BE(iv_len * 8, work_buf, 12); p = iv; - while( iv_len > 0 ) - { - use_len = ( iv_len < 16 ) ? iv_len : 16; + while (iv_len > 0) { + use_len = (iv_len < 16) ? iv_len : 16; - for( i = 0; i < use_len; i++ ) + for (i = 0; i < use_len; i++) ctx->y[i] ^= p[i]; - gcm_mult( ctx, ctx->y, ctx->y ); + gcm_mult(ctx, ctx->y, ctx->y); iv_len -= use_len; p += use_len; } - for( i = 0; i < 16; i++ ) + for (i = 0; i < 16; i++) ctx->y[i] ^= work_buf[i]; - gcm_mult( ctx, ctx->y, ctx->y ); + gcm_mult(ctx, ctx->y, ctx->y); } - if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctx->y, 16, ctx->base_ectr, - &olen ) ) != 0 ) - { - return( ret ); + if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->base_ectr, &olen)) != 0) { + return (ret); } ctx->add_len = add_len; p = add; - while( add_len > 0 ) - { - use_len = ( add_len < 16 ) ? add_len : 16; + while (add_len > 0) { + use_len = (add_len < 16) ? add_len : 16; - for( i = 0; i < use_len; i++ ) + for (i = 0; i < use_len; i++) ctx->buf[i] ^= p[i]; - gcm_mult( ctx, ctx->buf, ctx->buf ); + gcm_mult(ctx, ctx->buf, ctx->buf); add_len -= use_len; p += use_len; } - return( 0 ); + return (0); } -int mbedtls_gcm_update( mbedtls_gcm_context *ctx, - size_t length, - const unsigned char *input, - unsigned char *output ) +int mbedtls_gcm_update(mbedtls_gcm_context* ctx, size_t length, const unsigned char* input, unsigned char* output) { int ret; unsigned char ectr[16]; size_t i; - const unsigned char *p; - unsigned char *out_p = output; + const unsigned char* p; + unsigned char* out_p = output; size_t use_len, olen = 0; - GCM_VALIDATE_RET( ctx != NULL ); - GCM_VALIDATE_RET( length == 0 || input != NULL ); - GCM_VALIDATE_RET( length == 0 || output != NULL ); + GCM_VALIDATE_RET(ctx != NULL); + GCM_VALIDATE_RET(length == 0 || input != NULL); + GCM_VALIDATE_RET(length == 0 || output != NULL); - if( output > input && (size_t) ( output - input ) < length ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + if (output > input && (size_t)(output - input) < length) + return (MBEDTLS_ERR_GCM_BAD_INPUT); /* Total length is restricted to 2^39 - 256 bits, ie 2^36 - 2^5 bytes * Also check for possible overflow */ - if( ctx->len + length < ctx->len || - (uint64_t) ctx->len + length > 0xFFFFFFFE0ull ) - { - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + if (ctx->len + length < ctx->len || (uint64_t)ctx->len + length > 0xFFFFFFFE0ull) { + return (MBEDTLS_ERR_GCM_BAD_INPUT); } ctx->len += length; p = input; - while( length > 0 ) - { - use_len = ( length < 16 ) ? length : 16; + while (length > 0) { + use_len = (length < 16) ? length : 16; - for( i = 16; i > 12; i-- ) - if( ++ctx->y[i - 1] != 0 ) + for (i = 16; i > 12; i--) + if (++ctx->y[i - 1] != 0) break; - if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctx->y, 16, ectr, - &olen ) ) != 0 ) - { - return( ret ); + if ((ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ectr, &olen)) != 0) { + return (ret); } - for( i = 0; i < use_len; i++ ) - { - if( ctx->mode == MBEDTLS_GCM_DECRYPT ) + for (i = 0; i < use_len; i++) { + if (ctx->mode == MBEDTLS_GCM_DECRYPT) ctx->buf[i] ^= p[i]; out_p[i] = ectr[i] ^ p[i]; - if( ctx->mode == MBEDTLS_GCM_ENCRYPT ) + if (ctx->mode == MBEDTLS_GCM_ENCRYPT) ctx->buf[i] ^= out_p[i]; } - gcm_mult( ctx, ctx->buf, ctx->buf ); + gcm_mult(ctx, ctx->buf, ctx->buf); length -= use_len; p += use_len; out_p += use_len; } - return( 0 ); + return (0); } -int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, - unsigned char *tag, - size_t tag_len ) +int mbedtls_gcm_finish(mbedtls_gcm_context* ctx, unsigned char* tag, size_t tag_len) { unsigned char work_buf[16]; size_t i; uint64_t orig_len; uint64_t orig_add_len; - GCM_VALIDATE_RET( ctx != NULL ); - GCM_VALIDATE_RET( tag != NULL ); + GCM_VALIDATE_RET(ctx != NULL); + GCM_VALIDATE_RET(tag != NULL); orig_len = ctx->len * 8; orig_add_len = ctx->add_len * 8; - if( tag_len > 16 || tag_len < 4 ) - return( MBEDTLS_ERR_GCM_BAD_INPUT ); + if (tag_len > 16 || tag_len < 4) + return (MBEDTLS_ERR_GCM_BAD_INPUT); - memcpy( tag, ctx->base_ectr, tag_len ); + memcpy(tag, ctx->base_ectr, tag_len); - if( orig_len || orig_add_len ) - { - memset( work_buf, 0x00, 16 ); + if (orig_len || orig_add_len) { + memset(work_buf, 0x00, 16); - PUT_UINT32_BE( ( orig_add_len >> 32 ), work_buf, 0 ); - PUT_UINT32_BE( ( orig_add_len ), work_buf, 4 ); - PUT_UINT32_BE( ( orig_len >> 32 ), work_buf, 8 ); - PUT_UINT32_BE( ( orig_len ), work_buf, 12 ); + PUT_UINT32_BE((orig_add_len >> 32), work_buf, 0); + PUT_UINT32_BE((orig_add_len), work_buf, 4); + PUT_UINT32_BE((orig_len >> 32), work_buf, 8); + PUT_UINT32_BE((orig_len), work_buf, 12); - for( i = 0; i < 16; i++ ) + for (i = 0; i < 16; i++) ctx->buf[i] ^= work_buf[i]; - gcm_mult( ctx, ctx->buf, ctx->buf ); + gcm_mult(ctx, ctx->buf, ctx->buf); - for( i = 0; i < tag_len; i++ ) + for (i = 0; i < tag_len; i++) tag[i] ^= ctx->buf[i]; } - return( 0 ); + return (0); } -int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, - int mode, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *input, - unsigned char *output, - size_t tag_len, - unsigned char *tag ) +int mbedtls_gcm_crypt_and_tag( + mbedtls_gcm_context* ctx, + int mode, + size_t length, + const unsigned char* iv, + size_t iv_len, + const unsigned char* add, + size_t add_len, + const unsigned char* input, + unsigned char* output, + size_t tag_len, + unsigned char* tag) { int ret; - GCM_VALIDATE_RET( ctx != NULL ); - GCM_VALIDATE_RET( iv != NULL ); - GCM_VALIDATE_RET( add_len == 0 || add != NULL ); - GCM_VALIDATE_RET( length == 0 || input != NULL ); - GCM_VALIDATE_RET( length == 0 || output != NULL ); - GCM_VALIDATE_RET( tag != NULL ); + GCM_VALIDATE_RET(ctx != NULL); + GCM_VALIDATE_RET(iv != NULL); + GCM_VALIDATE_RET(add_len == 0 || add != NULL); + GCM_VALIDATE_RET(length == 0 || input != NULL); + GCM_VALIDATE_RET(length == 0 || output != NULL); + GCM_VALIDATE_RET(tag != NULL); - if( ( ret = mbedtls_gcm_starts( ctx, mode, iv, iv_len, add, add_len ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_gcm_starts(ctx, mode, iv, iv_len, add, add_len)) != 0) + return (ret); - if( ( ret = mbedtls_gcm_update( ctx, length, input, output ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_gcm_update(ctx, length, input, output)) != 0) + return (ret); - if( ( ret = mbedtls_gcm_finish( ctx, tag, tag_len ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_gcm_finish(ctx, tag, tag_len)) != 0) + return (ret); - return( 0 ); + return (0); } -int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *tag, - size_t tag_len, - const unsigned char *input, - unsigned char *output ) +int mbedtls_gcm_auth_decrypt( + mbedtls_gcm_context* ctx, + size_t length, + const unsigned char* iv, + size_t iv_len, + const unsigned char* add, + size_t add_len, + const unsigned char* tag, + size_t tag_len, + const unsigned char* input, + unsigned char* output) { int ret; unsigned char check_tag[16]; size_t i; int diff; - GCM_VALIDATE_RET( ctx != NULL ); - GCM_VALIDATE_RET( iv != NULL ); - GCM_VALIDATE_RET( add_len == 0 || add != NULL ); - GCM_VALIDATE_RET( tag != NULL ); - GCM_VALIDATE_RET( length == 0 || input != NULL ); - GCM_VALIDATE_RET( length == 0 || output != NULL ); - - if( ( ret = mbedtls_gcm_crypt_and_tag( ctx, MBEDTLS_GCM_DECRYPT, length, - iv, iv_len, add, add_len, - input, output, tag_len, check_tag ) ) != 0 ) - { - return( ret ); + GCM_VALIDATE_RET(ctx != NULL); + GCM_VALIDATE_RET(iv != NULL); + GCM_VALIDATE_RET(add_len == 0 || add != NULL); + GCM_VALIDATE_RET(tag != NULL); + GCM_VALIDATE_RET(length == 0 || input != NULL); + GCM_VALIDATE_RET(length == 0 || output != NULL); + + if ((ret = mbedtls_gcm_crypt_and_tag(ctx, MBEDTLS_GCM_DECRYPT, length, iv, iv_len, add, add_len, input, output, tag_len, check_tag)) != 0) { + return (ret); } /* Check tag in "constant-time" */ - for( diff = 0, i = 0; i < tag_len; i++ ) + for (diff = 0, i = 0; i < tag_len; i++) diff |= tag[i] ^ check_tag[i]; - if( diff != 0 ) - { - mbedtls_platform_zeroize( output, length ); - return( MBEDTLS_ERR_GCM_AUTH_FAILED ); + if (diff != 0) { + mbedtls_platform_zeroize(output, length); + return (MBEDTLS_ERR_GCM_AUTH_FAILED); } - return( 0 ); + return (0); } -void mbedtls_gcm_free( mbedtls_gcm_context *ctx ) +void mbedtls_gcm_free(mbedtls_gcm_context* ctx) { - if( ctx == NULL ) + if (ctx == NULL) return; - mbedtls_cipher_free( &ctx->cipher_ctx ); - mbedtls_platform_zeroize( ctx, sizeof( mbedtls_gcm_context ) ); + mbedtls_cipher_free(&ctx->cipher_ctx); + mbedtls_platform_zeroize(ctx, sizeof(mbedtls_gcm_context)); } #endif /* !MBEDTLS_GCM_ALT */ @@ -560,229 +505,116 @@ void mbedtls_gcm_free( mbedtls_gcm_context *ctx ) * * http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip */ -#define MAX_TESTS 6 +#define MAX_TESTS 6 -static const int key_index[MAX_TESTS] = - { 0, 0, 1, 1, 1, 1 }; +static const int key_index[MAX_TESTS] = {0, 0, 1, 1, 1, 1}; -static const unsigned char key[MAX_TESTS][32] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, - 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, - 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, - 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 }, +static const unsigned char key[MAX_TESTS][32] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, + 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08}, }; -static const size_t iv_len[MAX_TESTS] = - { 12, 12, 12, 12, 8, 60 }; +static const size_t iv_len[MAX_TESTS] = {12, 12, 12, 12, 8, 60}; -static const int iv_index[MAX_TESTS] = - { 0, 0, 1, 1, 1, 2 }; +static const int iv_index[MAX_TESTS] = {0, 0, 1, 1, 1, 2}; -static const unsigned char iv[MAX_TESTS][64] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 }, - { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, - 0xde, 0xca, 0xf8, 0x88 }, - { 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, - 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, - 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, - 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, - 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, - 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, - 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, - 0xa6, 0x37, 0xb3, 0x9b }, +static const unsigned char iv[MAX_TESTS][64] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88}, + {0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, 0x6a, 0x7a, 0x95, 0x38, + 0x53, 0x4f, 0x7d, 0xa1, 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, + 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, 0xa6, 0x37, 0xb3, 0x9b}, }; -static const size_t add_len[MAX_TESTS] = - { 0, 0, 0, 20, 20, 20 }; +static const size_t add_len[MAX_TESTS] = {0, 0, 0, 20, 20, 20}; -static const int add_index[MAX_TESTS] = - { 0, 0, 0, 1, 1, 1 }; +static const int add_index[MAX_TESTS] = {0, 0, 0, 1, 1, 1}; -static const unsigned char additional[MAX_TESTS][64] = -{ - { 0x00 }, - { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, - 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, - 0xab, 0xad, 0xda, 0xd2 }, +static const unsigned char additional[MAX_TESTS][64] = { + {0x00}, + {0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xab, 0xad, 0xda, 0xd2}, }; -static const size_t pt_len[MAX_TESTS] = - { 0, 16, 64, 60, 60, 60 }; +static const size_t pt_len[MAX_TESTS] = {0, 16, 64, 60, 60, 60}; -static const int pt_index[MAX_TESTS] = - { 0, 0, 1, 1, 1, 1 }; +static const int pt_index[MAX_TESTS] = {0, 0, 1, 1, 1, 1}; -static const unsigned char pt[MAX_TESTS][64] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, - 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, - 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, - 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, - 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, - 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, - 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, - 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 }, +static const unsigned char pt[MAX_TESTS][64] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + {0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, + 0xf7, 0xda, 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, + 0x49, 0xa6, 0xb5, 0x25, 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55}, }; -static const unsigned char ct[MAX_TESTS * 3][64] = -{ - { 0x00 }, - { 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, - 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78 }, - { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, - 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, - 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, - 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, - 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, - 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, - 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, - 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85 }, - { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, - 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, - 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, - 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, - 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, - 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, - 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, - 0x3d, 0x58, 0xe0, 0x91 }, - { 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a, - 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55, - 0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8, - 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23, - 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2, - 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42, - 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07, - 0xc2, 0x3f, 0x45, 0x98 }, - { 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6, - 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94, - 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8, - 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7, - 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90, - 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, - 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, - 0x4c, 0x34, 0xae, 0xe5 }, - { 0x00 }, - { 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41, - 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00 }, - { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, - 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, - 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84, - 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, - 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, - 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47, - 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, - 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56 }, - { 0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, - 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, - 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, 0xd9, 0x84, - 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, - 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, - 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47, - 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, - 0xcc, 0xda, 0x27, 0x10 }, - { 0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54, - 0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8, - 0xc5, 0x66, 0x63, 0x2e, 0xf2, 0xbb, 0xb3, 0x4f, - 0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57, - 0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75, - 0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9, - 0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f, - 0xa0, 0xf0, 0x62, 0xf7 }, - { 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c, - 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff, - 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef, - 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45, - 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9, - 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3, - 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7, - 0xe9, 0xb7, 0x37, 0x3b }, - { 0x00 }, - { 0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e, - 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18 }, - { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, - 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, - 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, - 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, - 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, - 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, - 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, - 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad }, - { 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, - 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, - 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9, - 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, - 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, - 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, - 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, - 0xbc, 0xc9, 0xf6, 0x62 }, - { 0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32, - 0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb, - 0xaf, 0x1a, 0xe1, 0x4d, 0x0b, 0x97, 0x6a, 0xfa, - 0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0, - 0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0, - 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78, - 0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99, - 0xf4, 0x7c, 0x9b, 0x1f }, - { 0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1, - 0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20, - 0xee, 0xb2, 0xb2, 0x2a, 0xaf, 0xde, 0x64, 0x19, - 0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4, - 0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45, - 0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde, - 0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e, - 0x44, 0xae, 0x7e, 0x3f }, +static const unsigned char ct[MAX_TESTS * 3][64] = { + {0x00}, + {0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, 0xf3, 0x28, 0xc2, 0xb9, 0x71, 0xb2, 0xfe, 0x78}, + {0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, + 0xa4, 0xe0, 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a, + 0xac, 0x84, 0xaa, 0x05, 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85}, + {0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, + 0x2c, 0x02, 0xa4, 0xe0, 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, + 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 0x3d, 0x58, 0xe0, 0x91}, + {0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a, 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55, 0x69, 0x9b, 0x2a, 0x71, + 0x4f, 0xcd, 0xc6, 0xf8, 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23, 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2, + 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42, 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07, 0xc2, 0x3f, 0x45, 0x98}, + {0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6, 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94, 0xbe, 0x91, 0x12, 0xa5, + 0xc3, 0xa2, 0x11, 0xa8, 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7, 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90, + 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, 0x4c, 0x34, 0xae, 0xe5}, + {0x00}, + {0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41, 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00}, + {0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, 0x85, 0x9e, 0x1c, 0xea, 0xa6, 0xef, + 0xd9, 0x84, 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, 0xac, 0x61, 0x9d, 0x18, + 0xc8, 0x4a, 0x3f, 0x47, 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, 0xcc, 0xda, 0x27, 0x10, 0xac, 0xad, 0xe2, 0x56}, + {0x39, 0x80, 0xca, 0x0b, 0x3c, 0x00, 0xe8, 0x41, 0xeb, 0x06, 0xfa, 0xc4, 0x87, 0x2a, 0x27, 0x57, 0x85, 0x9e, 0x1c, 0xea, + 0xa6, 0xef, 0xd9, 0x84, 0x62, 0x85, 0x93, 0xb4, 0x0c, 0xa1, 0xe1, 0x9c, 0x7d, 0x77, 0x3d, 0x00, 0xc1, 0x44, 0xc5, 0x25, + 0xac, 0x61, 0x9d, 0x18, 0xc8, 0x4a, 0x3f, 0x47, 0x18, 0xe2, 0x44, 0x8b, 0x2f, 0xe3, 0x24, 0xd9, 0xcc, 0xda, 0x27, 0x10}, + {0x0f, 0x10, 0xf5, 0x99, 0xae, 0x14, 0xa1, 0x54, 0xed, 0x24, 0xb3, 0x6e, 0x25, 0x32, 0x4d, 0xb8, 0xc5, 0x66, 0x63, 0x2e, + 0xf2, 0xbb, 0xb3, 0x4f, 0x83, 0x47, 0x28, 0x0f, 0xc4, 0x50, 0x70, 0x57, 0xfd, 0xdc, 0x29, 0xdf, 0x9a, 0x47, 0x1f, 0x75, + 0xc6, 0x65, 0x41, 0xd4, 0xd4, 0xda, 0xd1, 0xc9, 0xe9, 0x3a, 0x19, 0xa5, 0x8e, 0x8b, 0x47, 0x3f, 0xa0, 0xf0, 0x62, 0xf7}, + {0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c, 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff, 0x1d, 0xe9, 0xa1, 0xd8, + 0xe6, 0xb4, 0x47, 0xef, 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45, 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9, + 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3, 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7, 0xe9, 0xb7, 0x37, 0x3b}, + {0x00}, + {0xce, 0xa7, 0x40, 0x3d, 0x4d, 0x60, 0x6b, 0x6e, 0x07, 0x4e, 0xc5, 0xd3, 0xba, 0xf3, 0x9d, 0x18}, + {0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, + 0xc0, 0xc9, 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, 0xa7, 0xb0, 0x8b, 0x10, + 0x56, 0x82, 0x88, 0x38, 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, 0xbc, 0xc9, 0xf6, 0x62, 0x89, 0x80, 0x15, 0xad}, + {0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07, 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d, 0x64, 0x3a, 0x8c, 0xdc, + 0xbf, 0xe5, 0xc0, 0xc9, 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa, 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d, + 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38, 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a, 0xbc, 0xc9, 0xf6, 0x62}, + {0xc3, 0x76, 0x2d, 0xf1, 0xca, 0x78, 0x7d, 0x32, 0xae, 0x47, 0xc1, 0x3b, 0xf1, 0x98, 0x44, 0xcb, 0xaf, 0x1a, 0xe1, 0x4d, + 0x0b, 0x97, 0x6a, 0xfa, 0xc5, 0x2f, 0xf7, 0xd7, 0x9b, 0xba, 0x9d, 0xe0, 0xfe, 0xb5, 0x82, 0xd3, 0x39, 0x34, 0xa4, 0xf0, + 0x95, 0x4c, 0xc2, 0x36, 0x3b, 0xc7, 0x3f, 0x78, 0x62, 0xac, 0x43, 0x0e, 0x64, 0xab, 0xe4, 0x99, 0xf4, 0x7c, 0x9b, 0x1f}, + {0x5a, 0x8d, 0xef, 0x2f, 0x0c, 0x9e, 0x53, 0xf1, 0xf7, 0x5d, 0x78, 0x53, 0x65, 0x9e, 0x2a, 0x20, 0xee, 0xb2, 0xb2, 0x2a, + 0xaf, 0xde, 0x64, 0x19, 0xa0, 0x58, 0xab, 0x4f, 0x6f, 0x74, 0x6b, 0xf4, 0x0f, 0xc0, 0xc3, 0xb7, 0x80, 0xf2, 0x44, 0x45, + 0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde, 0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e, 0x44, 0xae, 0x7e, 0x3f}, }; -static const unsigned char tag[MAX_TESTS * 3][16] = -{ - { 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61, - 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a }, - { 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd, - 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf }, - { 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, - 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4 }, - { 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb, - 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47 }, - { 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85, - 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb }, - { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, - 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50 }, - { 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b, - 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35 }, - { 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab, - 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb }, - { 0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf, - 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14 }, - { 0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f, - 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c }, - { 0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24, - 0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8 }, - { 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb, - 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9 }, - { 0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9, - 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b }, - { 0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0, - 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19 }, - { 0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd, - 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c }, - { 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68, - 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b }, - { 0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4, - 0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2 }, - { 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0, - 0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a }, +static const unsigned char tag[MAX_TESTS * 3][16] = { + {0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61, 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a}, + {0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec, 0x13, 0xbd, 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf}, + {0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4}, + {0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb, 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47}, + {0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85, 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb}, + {0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50}, + {0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b, 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35}, + {0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab, 0x8e, 0xf4, 0xd4, 0x58, 0x75, 0x14, 0xf0, 0xfb}, + {0x99, 0x24, 0xa7, 0xc8, 0x58, 0x73, 0x36, 0xbf, 0xb1, 0x18, 0x02, 0x4d, 0xb8, 0x67, 0x4a, 0x14}, + {0x25, 0x19, 0x49, 0x8e, 0x80, 0xf1, 0x47, 0x8f, 0x37, 0xba, 0x55, 0xbd, 0x6d, 0x27, 0x61, 0x8c}, + {0x65, 0xdc, 0xc5, 0x7f, 0xcf, 0x62, 0x3a, 0x24, 0x09, 0x4f, 0xcc, 0xa4, 0x0d, 0x35, 0x33, 0xf8}, + {0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb, 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9}, + {0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9, 0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b}, + {0xd0, 0xd1, 0xc8, 0xa7, 0x99, 0x99, 0x6b, 0xf0, 0x26, 0x5b, 0x98, 0xb5, 0xd4, 0x8a, 0xb9, 0x19}, + {0xb0, 0x94, 0xda, 0xc5, 0xd9, 0x34, 0x71, 0xbd, 0xec, 0x1a, 0x50, 0x22, 0x70, 0xe3, 0xcc, 0x6c}, + {0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68, 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b}, + {0x3a, 0x33, 0x7d, 0xbf, 0x46, 0xa7, 0x92, 0xc4, 0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2}, + {0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0, 0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a}, }; -int mbedtls_gcm_self_test( int verbose ) +int mbedtls_gcm_self_test(int verbose) { mbedtls_gcm_context ctx; unsigned char buf[64]; @@ -790,208 +622,169 @@ int mbedtls_gcm_self_test( int verbose ) int i, j, ret; mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES; - for( j = 0; j < 3; j++ ) - { + for (j = 0; j < 3; j++) { int key_len = 128 + 64 * j; - for( i = 0; i < MAX_TESTS; i++ ) - { - mbedtls_gcm_init( &ctx ); + for (i = 0; i < MAX_TESTS; i++) { + mbedtls_gcm_init(&ctx); - if( verbose != 0 ) - mbedtls_printf( " AES-GCM-%3d #%d (%s): ", - key_len, i, "enc" ); + if (verbose != 0) + mbedtls_printf(" AES-GCM-%3d #%d (%s): ", key_len, i, "enc"); - ret = mbedtls_gcm_setkey( &ctx, cipher, key[key_index[i]], - key_len ); + ret = mbedtls_gcm_setkey(&ctx, cipher, key[key_index[i]], key_len); /* * AES-192 is an optional feature that may be unavailable when * there is an alternative underlying implementation i.e. when * MBEDTLS_AES_ALT is defined. */ - if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && key_len == 192 ) - { - mbedtls_printf( "skipped\n" ); + if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && key_len == 192) { + mbedtls_printf("skipped\n"); break; - } - else if( ret != 0 ) - { + } else if (ret != 0) { goto exit; } - ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, - pt_len[i], - iv[iv_index[i]], iv_len[i], - additional[add_index[i]], add_len[i], - pt[pt_index[i]], buf, 16, tag_buf ); - if( ret != 0 ) + ret = mbedtls_gcm_crypt_and_tag( + &ctx, MBEDTLS_GCM_ENCRYPT, pt_len[i], iv[iv_index[i]], iv_len[i], additional[add_index[i]], add_len[i], pt[pt_index[i]], buf, 16, + tag_buf); + if (ret != 0) goto exit; - if ( memcmp( buf, ct[j * 6 + i], pt_len[i] ) != 0 || - memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) - { + if (memcmp(buf, ct[j * 6 + i], pt_len[i]) != 0 || memcmp(tag_buf, tag[j * 6 + i], 16) != 0) { ret = 1; goto exit; } - mbedtls_gcm_free( &ctx ); + mbedtls_gcm_free(&ctx); - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); - mbedtls_gcm_init( &ctx ); + mbedtls_gcm_init(&ctx); - if( verbose != 0 ) - mbedtls_printf( " AES-GCM-%3d #%d (%s): ", - key_len, i, "dec" ); + if (verbose != 0) + mbedtls_printf(" AES-GCM-%3d #%d (%s): ", key_len, i, "dec"); - ret = mbedtls_gcm_setkey( &ctx, cipher, key[key_index[i]], - key_len ); - if( ret != 0 ) + ret = mbedtls_gcm_setkey(&ctx, cipher, key[key_index[i]], key_len); + if (ret != 0) goto exit; - ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_DECRYPT, - pt_len[i], - iv[iv_index[i]], iv_len[i], - additional[add_index[i]], add_len[i], - ct[j * 6 + i], buf, 16, tag_buf ); + ret = mbedtls_gcm_crypt_and_tag( + &ctx, MBEDTLS_GCM_DECRYPT, pt_len[i], iv[iv_index[i]], iv_len[i], additional[add_index[i]], add_len[i], ct[j * 6 + i], buf, 16, + tag_buf); - if( ret != 0 ) + if (ret != 0) goto exit; - if( memcmp( buf, pt[pt_index[i]], pt_len[i] ) != 0 || - memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) - { + if (memcmp(buf, pt[pt_index[i]], pt_len[i]) != 0 || memcmp(tag_buf, tag[j * 6 + i], 16) != 0) { ret = 1; goto exit; } - mbedtls_gcm_free( &ctx ); + mbedtls_gcm_free(&ctx); - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); - mbedtls_gcm_init( &ctx ); + mbedtls_gcm_init(&ctx); - if( verbose != 0 ) - mbedtls_printf( " AES-GCM-%3d #%d split (%s): ", - key_len, i, "enc" ); + if (verbose != 0) + mbedtls_printf(" AES-GCM-%3d #%d split (%s): ", key_len, i, "enc"); - ret = mbedtls_gcm_setkey( &ctx, cipher, key[key_index[i]], - key_len ); - if( ret != 0 ) + ret = mbedtls_gcm_setkey(&ctx, cipher, key[key_index[i]], key_len); + if (ret != 0) goto exit; - ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_ENCRYPT, - iv[iv_index[i]], iv_len[i], - additional[add_index[i]], add_len[i] ); - if( ret != 0 ) + ret = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_ENCRYPT, iv[iv_index[i]], iv_len[i], additional[add_index[i]], add_len[i]); + if (ret != 0) goto exit; - if( pt_len[i] > 32 ) - { + if (pt_len[i] > 32) { size_t rest_len = pt_len[i] - 32; - ret = mbedtls_gcm_update( &ctx, 32, pt[pt_index[i]], buf ); - if( ret != 0 ) + ret = mbedtls_gcm_update(&ctx, 32, pt[pt_index[i]], buf); + if (ret != 0) goto exit; - ret = mbedtls_gcm_update( &ctx, rest_len, pt[pt_index[i]] + 32, - buf + 32 ); - if( ret != 0 ) + ret = mbedtls_gcm_update(&ctx, rest_len, pt[pt_index[i]] + 32, buf + 32); + if (ret != 0) goto exit; - } - else - { - ret = mbedtls_gcm_update( &ctx, pt_len[i], pt[pt_index[i]], buf ); - if( ret != 0 ) + } else { + ret = mbedtls_gcm_update(&ctx, pt_len[i], pt[pt_index[i]], buf); + if (ret != 0) goto exit; } - ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 ); - if( ret != 0 ) + ret = mbedtls_gcm_finish(&ctx, tag_buf, 16); + if (ret != 0) goto exit; - if( memcmp( buf, ct[j * 6 + i], pt_len[i] ) != 0 || - memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) - { + if (memcmp(buf, ct[j * 6 + i], pt_len[i]) != 0 || memcmp(tag_buf, tag[j * 6 + i], 16) != 0) { ret = 1; goto exit; } - mbedtls_gcm_free( &ctx ); + mbedtls_gcm_free(&ctx); - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); - mbedtls_gcm_init( &ctx ); + mbedtls_gcm_init(&ctx); - if( verbose != 0 ) - mbedtls_printf( " AES-GCM-%3d #%d split (%s): ", - key_len, i, "dec" ); + if (verbose != 0) + mbedtls_printf(" AES-GCM-%3d #%d split (%s): ", key_len, i, "dec"); - ret = mbedtls_gcm_setkey( &ctx, cipher, key[key_index[i]], - key_len ); - if( ret != 0 ) + ret = mbedtls_gcm_setkey(&ctx, cipher, key[key_index[i]], key_len); + if (ret != 0) goto exit; - ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_DECRYPT, - iv[iv_index[i]], iv_len[i], - additional[add_index[i]], add_len[i] ); - if( ret != 0 ) + ret = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_DECRYPT, iv[iv_index[i]], iv_len[i], additional[add_index[i]], add_len[i]); + if (ret != 0) goto exit; - if( pt_len[i] > 32 ) - { + if (pt_len[i] > 32) { size_t rest_len = pt_len[i] - 32; - ret = mbedtls_gcm_update( &ctx, 32, ct[j * 6 + i], buf ); - if( ret != 0 ) + ret = mbedtls_gcm_update(&ctx, 32, ct[j * 6 + i], buf); + if (ret != 0) goto exit; - ret = mbedtls_gcm_update( &ctx, rest_len, ct[j * 6 + i] + 32, - buf + 32 ); - if( ret != 0 ) + ret = mbedtls_gcm_update(&ctx, rest_len, ct[j * 6 + i] + 32, buf + 32); + if (ret != 0) goto exit; - } - else - { - ret = mbedtls_gcm_update( &ctx, pt_len[i], ct[j * 6 + i], - buf ); - if( ret != 0 ) + } else { + ret = mbedtls_gcm_update(&ctx, pt_len[i], ct[j * 6 + i], buf); + if (ret != 0) goto exit; } - ret = mbedtls_gcm_finish( &ctx, tag_buf, 16 ); - if( ret != 0 ) + ret = mbedtls_gcm_finish(&ctx, tag_buf, 16); + if (ret != 0) goto exit; - if( memcmp( buf, pt[pt_index[i]], pt_len[i] ) != 0 || - memcmp( tag_buf, tag[j * 6 + i], 16 ) != 0 ) - { + if (memcmp(buf, pt[pt_index[i]], pt_len[i]) != 0 || memcmp(tag_buf, tag[j * 6 + i], 16) != 0) { ret = 1; goto exit; } - mbedtls_gcm_free( &ctx ); + mbedtls_gcm_free(&ctx); - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); ret = 0; exit: - if( ret != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); - mbedtls_gcm_free( &ctx ); + if (ret != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); + mbedtls_gcm_free(&ctx); } - return( ret ); + return (ret); } #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/nettls/ssl/hkdf.c b/nettls/ssl/hkdf.c index 32be4a90906339adcb41b798cbdd73ffdfa0bbb9..7d1915feb296e7b4aaef1f09262211fbc5cba6d2 100644 --- a/nettls/ssl/hkdf.c +++ b/nettls/ssl/hkdf.c @@ -81,12 +81,7 @@ int mbedtls_hkdf( } int mbedtls_hkdf_extract( - const mbedtls_md_info_t* md, - const unsigned char* salt, - size_t salt_len, - const unsigned char* ikm, - size_t ikm_len, - unsigned char* prk) + const mbedtls_md_info_t* md, const unsigned char* salt, size_t salt_len, const unsigned char* ikm, size_t ikm_len, unsigned char* prk) { unsigned char null_salt[MBEDTLS_MD_MAX_SIZE] = {'\0'}; diff --git a/nettls/ssl/hmac_drbg.c b/nettls/ssl/hmac_drbg.c index 6fcf0384c9f99ad7f023f8849734fbbfaf339675..e6694af9a5e2cdb627bd65a18de88d0f1c690999 100644 --- a/nettls/ssl/hmac_drbg.c +++ b/nettls/ssl/hmac_drbg.c @@ -136,8 +136,7 @@ void mbedtls_hmac_drbg_update(mbedtls_hmac_drbg_context* ctx, const unsigned cha /* * Simplified HMAC_DRBG initialisation (for use with deterministic ECDSA) */ -int mbedtls_hmac_drbg_seed_buf( - mbedtls_hmac_drbg_context* ctx, const mbedtls_md_info_t* md_info, const unsigned char* data, size_t data_len) +int mbedtls_hmac_drbg_seed_buf(mbedtls_hmac_drbg_context* ctx, const mbedtls_md_info_t* md_info, const unsigned char* data, size_t data_len) { int ret; @@ -168,8 +167,7 @@ int mbedtls_hmac_drbg_seed_buf( * Comments starting with arabic numbers refer to section 10.1.2.4 * of SP800-90A, while roman numbers refer to section 9.2. */ -static int - hmac_drbg_reseed_core(mbedtls_hmac_drbg_context* ctx, const unsigned char* additional, size_t len, int use_nonce) +static int hmac_drbg_reseed_core(mbedtls_hmac_drbg_context* ctx, const unsigned char* additional, size_t len, int use_nonce) { unsigned char seed[MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT]; size_t seedlen = 0; @@ -329,8 +327,7 @@ void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context* ctx, int i * HMAC_DRBG random function with optional additional data: * 10.1.2.5 (arabic) + 9.3 (Roman) */ -int mbedtls_hmac_drbg_random_with_add( - void* p_rng, unsigned char* output, size_t out_len, const unsigned char* additional, size_t add_len) +int mbedtls_hmac_drbg_random_with_add(void* p_rng, unsigned char* output, size_t out_len, const unsigned char* additional, size_t add_len) { int ret; mbedtls_hmac_drbg_context* ctx = (mbedtls_hmac_drbg_context*)p_rng; @@ -507,28 +504,25 @@ int mbedtls_hmac_drbg_self_test(int verbose) #define OUTPUT_LEN 80 /* From a NIST PR=true test vector */ -static const unsigned char entropy_pr[] = { - 0xa0, 0xc9, 0xab, 0x58, 0xf1, 0xe2, 0xe5, 0xa4, 0xde, 0x3e, 0xbd, 0x4f, 0xf7, 0x3e, 0x9c, 0x5b, 0x64, 0xef, 0xd8, - 0xca, 0x02, 0x8c, 0xf8, 0x11, 0x48, 0xa5, 0x84, 0xfe, 0x69, 0xab, 0x5a, 0xee, 0x42, 0xaa, 0x4d, 0x42, 0x17, 0x60, - 0x99, 0xd4, 0x5e, 0x13, 0x97, 0xdc, 0x40, 0x4d, 0x86, 0xa3, 0x7b, 0xf5, 0x59, 0x54, 0x75, 0x69, 0x51, 0xe4}; -static const unsigned char result_pr[OUTPUT_LEN] = { - 0x9a, 0x00, 0xa2, 0xd0, 0x0e, 0xd5, 0x9b, 0xfe, 0x31, 0xec, 0xb1, 0x39, 0x9b, 0x60, 0x81, 0x48, - 0xd1, 0x96, 0x9d, 0x25, 0x0d, 0x3c, 0x1e, 0x94, 0x10, 0x10, 0x98, 0x12, 0x93, 0x25, 0xca, 0xb8, - 0xfc, 0xcc, 0x2d, 0x54, 0x73, 0x19, 0x70, 0xc0, 0x10, 0x7a, 0xa4, 0x89, 0x25, 0x19, 0x95, 0x5e, - 0x4b, 0xc6, 0x00, 0x1d, 0x7f, 0x4e, 0x6a, 0x2b, 0xf8, 0xa3, 0x01, 0xab, 0x46, 0x05, 0x5c, 0x09, - 0xa6, 0x71, 0x88, 0xf1, 0xa7, 0x40, 0xee, 0xf3, 0xe1, 0x5c, 0x02, 0x9b, 0x44, 0xaf, 0x03, 0x44}; +static const unsigned char entropy_pr[] = {0xa0, 0xc9, 0xab, 0x58, 0xf1, 0xe2, 0xe5, 0xa4, 0xde, 0x3e, 0xbd, 0x4f, 0xf7, 0x3e, + 0x9c, 0x5b, 0x64, 0xef, 0xd8, 0xca, 0x02, 0x8c, 0xf8, 0x11, 0x48, 0xa5, 0x84, 0xfe, + 0x69, 0xab, 0x5a, 0xee, 0x42, 0xaa, 0x4d, 0x42, 0x17, 0x60, 0x99, 0xd4, 0x5e, 0x13, + 0x97, 0xdc, 0x40, 0x4d, 0x86, 0xa3, 0x7b, 0xf5, 0x59, 0x54, 0x75, 0x69, 0x51, 0xe4}; +static const unsigned char result_pr[OUTPUT_LEN] = {0x9a, 0x00, 0xa2, 0xd0, 0x0e, 0xd5, 0x9b, 0xfe, 0x31, 0xec, 0xb1, 0x39, 0x9b, 0x60, 0x81, 0x48, + 0xd1, 0x96, 0x9d, 0x25, 0x0d, 0x3c, 0x1e, 0x94, 0x10, 0x10, 0x98, 0x12, 0x93, 0x25, 0xca, 0xb8, + 0xfc, 0xcc, 0x2d, 0x54, 0x73, 0x19, 0x70, 0xc0, 0x10, 0x7a, 0xa4, 0x89, 0x25, 0x19, 0x95, 0x5e, + 0x4b, 0xc6, 0x00, 0x1d, 0x7f, 0x4e, 0x6a, 0x2b, 0xf8, 0xa3, 0x01, 0xab, 0x46, 0x05, 0x5c, 0x09, + 0xa6, 0x71, 0x88, 0xf1, 0xa7, 0x40, 0xee, 0xf3, 0xe1, 0x5c, 0x02, 0x9b, 0x44, 0xaf, 0x03, 0x44}; /* From a NIST PR=false test vector */ -static const unsigned char entropy_nopr[] = {0x79, 0x34, 0x9b, 0xbf, 0x7c, 0xdd, 0xa5, 0x79, 0x95, 0x57, - 0x86, 0x66, 0x21, 0xc9, 0x13, 0x83, 0x11, 0x46, 0x73, 0x3a, - 0xbf, 0x8c, 0x35, 0xc8, 0xc7, 0x21, 0x5b, 0x5b, 0x96, 0xc4, - 0x8e, 0x9b, 0x33, 0x8c, 0x74, 0xe3, 0xe9, 0x9d, 0xfe, 0xdf}; -static const unsigned char result_nopr[OUTPUT_LEN] = { - 0xc6, 0xa1, 0x6a, 0xb8, 0xd4, 0x20, 0x70, 0x6f, 0x0f, 0x34, 0xab, 0x7f, 0xec, 0x5a, 0xdc, 0xa9, - 0xd8, 0xca, 0x3a, 0x13, 0x3e, 0x15, 0x9c, 0xa6, 0xac, 0x43, 0xc6, 0xf8, 0xa2, 0xbe, 0x22, 0x83, - 0x4a, 0x4c, 0x0a, 0x0a, 0xff, 0xb1, 0x0d, 0x71, 0x94, 0xf1, 0xc1, 0xa5, 0xcf, 0x73, 0x22, 0xec, - 0x1a, 0xe0, 0x96, 0x4e, 0xd4, 0xbf, 0x12, 0x27, 0x46, 0xe0, 0x87, 0xfd, 0xb5, 0xb3, 0xe9, 0x1b, - 0x34, 0x93, 0xd5, 0xbb, 0x98, 0xfa, 0xed, 0x49, 0xe8, 0x5f, 0x13, 0x0f, 0xc8, 0xa4, 0x59, 0xb7}; +static const unsigned char entropy_nopr[] = {0x79, 0x34, 0x9b, 0xbf, 0x7c, 0xdd, 0xa5, 0x79, 0x95, 0x57, 0x86, 0x66, 0x21, 0xc9, + 0x13, 0x83, 0x11, 0x46, 0x73, 0x3a, 0xbf, 0x8c, 0x35, 0xc8, 0xc7, 0x21, 0x5b, 0x5b, + 0x96, 0xc4, 0x8e, 0x9b, 0x33, 0x8c, 0x74, 0xe3, 0xe9, 0x9d, 0xfe, 0xdf}; +static const unsigned char result_nopr[OUTPUT_LEN] = {0xc6, 0xa1, 0x6a, 0xb8, 0xd4, 0x20, 0x70, 0x6f, 0x0f, 0x34, 0xab, 0x7f, 0xec, 0x5a, 0xdc, 0xa9, + 0xd8, 0xca, 0x3a, 0x13, 0x3e, 0x15, 0x9c, 0xa6, 0xac, 0x43, 0xc6, 0xf8, 0xa2, 0xbe, 0x22, 0x83, + 0x4a, 0x4c, 0x0a, 0x0a, 0xff, 0xb1, 0x0d, 0x71, 0x94, 0xf1, 0xc1, 0xa5, 0xcf, 0x73, 0x22, 0xec, + 0x1a, 0xe0, 0x96, 0x4e, 0xd4, 0xbf, 0x12, 0x27, 0x46, 0xe0, 0x87, 0xfd, 0xb5, 0xb3, 0xe9, 0x1b, + 0x34, 0x93, 0xd5, 0xbb, 0x98, 0xfa, 0xed, 0x49, 0xe8, 0x5f, 0x13, 0x0f, 0xc8, 0xa4, 0x59, 0xb7}; /* "Entropy" from buffer */ static size_t test_offset; diff --git a/nettls/ssl/md.c b/nettls/ssl/md.c index 89b1c31e22034271fbb0c016bc99ac9b08ad188f..80ec852401aa6d52027fa53b08cdb9a9ea95e6b5 100644 --- a/nettls/ssl/md.c +++ b/nettls/ssl/md.c @@ -418,12 +418,7 @@ int mbedtls_md_hmac_reset(mbedtls_md_context_t* ctx) } int mbedtls_md_hmac( - const mbedtls_md_info_t* md_info, - const unsigned char* key, - size_t keylen, - const unsigned char* input, - size_t ilen, - unsigned char* output) + const mbedtls_md_info_t* md_info, const unsigned char* key, size_t keylen, const unsigned char* input, size_t ilen, unsigned char* output) { mbedtls_md_context_t ctx; int ret; diff --git a/nettls/ssl/md5.c b/nettls/ssl/md5.c index 2e9ef41ce61eda5f13d4c14406e34584bfac0aec..6ee59ad4b502fa2233d1cb0f06c01aecdfdd9cb6 100644 --- a/nettls/ssl/md5.c +++ b/nettls/ssl/md5.c @@ -79,8 +79,7 @@ #ifndef GET_UINT32_LE #define GET_UINT32_LE(n, b, i) \ { \ - (n) = ((uint32_t)(b)[(i)]) | ((uint32_t)(b)[(i) + 1] << 8) | ((uint32_t)(b)[(i) + 2] << 16) \ - | ((uint32_t)(b)[(i) + 3] << 24); \ + (n) = ((uint32_t)(b)[(i)]) | ((uint32_t)(b)[(i) + 1] << 8) | ((uint32_t)(b)[(i) + 2] << 16) | ((uint32_t)(b)[(i) + 3] << 24); \ } #endif diff --git a/nettls/ssl/md_wrap.c b/nettls/ssl/md_wrap.c index 9425ea6cf652eb003df6d6015e6b1ac40e86f2f2..a6b742663ce316f8c4df8bef619ae899853049e4 100644 --- a/nettls/ssl/md_wrap.c +++ b/nettls/ssl/md_wrap.c @@ -140,17 +140,7 @@ static int md2_process_wrap(void* ctx, const unsigned char* data) } const mbedtls_md_info_t mbedtls_md2_info = { - MBEDTLS_MD_MD2, - "MD2", - 16, - 16, - md2_starts_wrap, - md2_update_wrap, - md2_finish_wrap, - mbedtls_md2_ret, - md2_ctx_alloc, - md2_ctx_free, - md2_clone_wrap, + MBEDTLS_MD_MD2, "MD2", 16, 16, md2_starts_wrap, md2_update_wrap, md2_finish_wrap, mbedtls_md2_ret, md2_ctx_alloc, md2_ctx_free, md2_clone_wrap, md2_process_wrap, }; @@ -200,17 +190,7 @@ static int md4_process_wrap(void* ctx, const unsigned char* data) } const mbedtls_md_info_t mbedtls_md4_info = { - MBEDTLS_MD_MD4, - "MD4", - 16, - 64, - md4_starts_wrap, - md4_update_wrap, - md4_finish_wrap, - mbedtls_md4_ret, - md4_ctx_alloc, - md4_ctx_free, - md4_clone_wrap, + MBEDTLS_MD_MD4, "MD4", 16, 64, md4_starts_wrap, md4_update_wrap, md4_finish_wrap, mbedtls_md4_ret, md4_ctx_alloc, md4_ctx_free, md4_clone_wrap, md4_process_wrap, }; @@ -260,17 +240,7 @@ static int md5_process_wrap(void* ctx, const unsigned char* data) } const mbedtls_md_info_t mbedtls_md5_info = { - MBEDTLS_MD_MD5, - "MD5", - 16, - 64, - md5_starts_wrap, - md5_update_wrap, - md5_finish_wrap, - mbedtls_md5_ret, - md5_ctx_alloc, - md5_ctx_free, - md5_clone_wrap, + MBEDTLS_MD_MD5, "MD5", 16, 64, md5_starts_wrap, md5_update_wrap, md5_finish_wrap, mbedtls_md5_ret, md5_ctx_alloc, md5_ctx_free, md5_clone_wrap, md5_process_wrap, }; diff --git a/nettls/ssl/net_sockets.c b/nettls/ssl/net_sockets.c index 5071ce73a4298828650cf467e0b25e111e90ba29..8a8c0de9652510bea062437ab383551a08dfe7d2 100644 --- a/nettls/ssl/net_sockets.c +++ b/nettls/ssl/net_sockets.c @@ -61,8 +61,7 @@ #if defined(MBEDTLS_NET_C) -#if !defined(unix) && !defined(__unix__) && !defined(__unix) && !defined(__APPLE__) && !defined(_WIN32) \ - && !defined(__QNXNTO__) && !defined(__HAIKU__) +#if !defined(unix) && !defined(__unix__) && !defined(__unix) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__HAIKU__) #error "This module only works on Unix and Windows, see MBEDTLS_NET_C in config.h" #endif @@ -317,16 +316,15 @@ static int net_would_block(const mbedtls_net_context* ctx) /* * Accept a connection from a remote client */ -int mbedtls_net_accept( - mbedtls_net_context* bind_ctx, mbedtls_net_context* client_ctx, void* client_ip, size_t buf_size, size_t* ip_len) +int mbedtls_net_accept(mbedtls_net_context* bind_ctx, mbedtls_net_context* client_ctx, void* client_ip, size_t buf_size, size_t* ip_len) { int ret; int type; struct sockaddr_storage client_addr; -#if defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(_SOCKLEN_T_DECLARED) \ - || defined(__DEFINED_socklen_t) || (defined(__NetBSD__) && defined(socklen_t)) +#if defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(_SOCKLEN_T_DECLARED) || defined(__DEFINED_socklen_t) \ + || (defined(__NetBSD__) && defined(socklen_t)) socklen_t n = (socklen_t)sizeof(client_addr); socklen_t type_len = (socklen_t)sizeof(type); #else @@ -335,8 +333,7 @@ int mbedtls_net_accept( #endif /* Is this a TCP or UDP socket? */ - if (getsockopt(bind_ctx->fd, SOL_SOCKET, SO_TYPE, (void*)&type, &type_len) != 0 - || (type != SOCK_STREAM && type != SOCK_DGRAM)) { + if (getsockopt(bind_ctx->fd, SOL_SOCKET, SO_TYPE, (void*)&type, &type_len) != 0 || (type != SOCK_STREAM && type != SOCK_DGRAM)) { return (MBEDTLS_ERR_NET_ACCEPT_FAILED); } diff --git a/nettls/ssl/nist_kw.c b/nettls/ssl/nist_kw.c index 2ff951d48a928d299a10cf67ab453132be5faba2..1b02fe5f8e59ba665a5d8a72fe6d9788d0595afd 100644 --- a/nettls/ssl/nist_kw.c +++ b/nettls/ssl/nist_kw.c @@ -79,19 +79,18 @@ #if !defined(MBEDTLS_NIST_KW_ALT) -#define KW_SEMIBLOCK_LENGTH 8 -#define MIN_SEMIBLOCKS_COUNT 3 +#define KW_SEMIBLOCK_LENGTH 8 +#define MIN_SEMIBLOCKS_COUNT 3 /* constant-time buffer comparison */ -static inline unsigned char mbedtls_nist_kw_safer_memcmp( const void *a, const void *b, size_t n ) +static inline unsigned char mbedtls_nist_kw_safer_memcmp(const void* a, const void* b, size_t n) { size_t i; - volatile const unsigned char *A = (volatile const unsigned char *) a; - volatile const unsigned char *B = (volatile const unsigned char *) b; + volatile const unsigned char* A = (volatile const unsigned char*)a; + volatile const unsigned char* B = (volatile const unsigned char*)b; volatile unsigned char diff = 0; - for( i = 0; i < n; i++ ) - { + for (i = 0; i < n; i++) { /* Read volatile data in order before computing diff. * This avoids IAR compiler warning: * 'the order of volatile accesses is undefined ..' */ @@ -99,59 +98,51 @@ static inline unsigned char mbedtls_nist_kw_safer_memcmp( const void *a, const v diff |= x ^ y; } - return( diff ); + return (diff); } /*! The 64-bit default integrity check value (ICV) for KW mode. */ static const unsigned char NIST_KW_ICV1[] = {0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6}; /*! The 32-bit default integrity check value (ICV) for KWP mode. */ -static const unsigned char NIST_KW_ICV2[] = {0xA6, 0x59, 0x59, 0xA6}; +static const unsigned char NIST_KW_ICV2[] = {0xA6, 0x59, 0x59, 0xA6}; #ifndef GET_UINT32_BE -#define GET_UINT32_BE(n,b,i) \ -do { \ - (n) = ( (uint32_t) (b)[(i) ] << 24 ) \ - | ( (uint32_t) (b)[(i) + 1] << 16 ) \ - | ( (uint32_t) (b)[(i) + 2] << 8 ) \ - | ( (uint32_t) (b)[(i) + 3] ); \ -} while( 0 ) +#define GET_UINT32_BE(n, b, i) \ + do { \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ + } while (0) #endif #ifndef PUT_UINT32_BE -#define PUT_UINT32_BE(n,b,i) \ -do { \ - (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) ); \ -} while( 0 ) +#define PUT_UINT32_BE(n, b, i) \ + do { \ + (b)[(i)] = (unsigned char)((n) >> 24); \ + (b)[(i) + 1] = (unsigned char)((n) >> 16); \ + (b)[(i) + 2] = (unsigned char)((n) >> 8); \ + (b)[(i) + 3] = (unsigned char)((n)); \ + } while (0) #endif /* * Initialize context */ -void mbedtls_nist_kw_init( mbedtls_nist_kw_context *ctx ) +void mbedtls_nist_kw_init(mbedtls_nist_kw_context* ctx) { - memset( ctx, 0, sizeof( mbedtls_nist_kw_context ) ); + memset(ctx, 0, sizeof(mbedtls_nist_kw_context)); } -int mbedtls_nist_kw_setkey( mbedtls_nist_kw_context *ctx, - mbedtls_cipher_id_t cipher, - const unsigned char *key, - unsigned int keybits, - const int is_wrap ) +int mbedtls_nist_kw_setkey( + mbedtls_nist_kw_context* ctx, mbedtls_cipher_id_t cipher, const unsigned char* key, unsigned int keybits, const int is_wrap) { int ret; - const mbedtls_cipher_info_t *cipher_info; + const mbedtls_cipher_info_t* cipher_info; - cipher_info = mbedtls_cipher_info_from_values( cipher, - keybits, - MBEDTLS_MODE_ECB ); - if( cipher_info == NULL ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + cipher_info = mbedtls_cipher_info_from_values(cipher, keybits, MBEDTLS_MODE_ECB); + if (cipher_info == NULL) + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); - if( cipher_info->block_size != 16 ) - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + if (cipher_info->block_size != 16) + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); /* * SP 800-38F currently defines AES cipher as the only block cipher allowed: @@ -162,44 +153,39 @@ int mbedtls_nist_kw_setkey( mbedtls_nist_kw_context *ctx, * Currently we don't support other 128 bit block ciphers for key wrapping, * such as Camellia and Aria. */ - if( cipher != MBEDTLS_CIPHER_ID_AES ) - return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + if (cipher != MBEDTLS_CIPHER_ID_AES) + return (MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE); - mbedtls_cipher_free( &ctx->cipher_ctx ); + mbedtls_cipher_free(&ctx->cipher_ctx); - if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_cipher_setup(&ctx->cipher_ctx, cipher_info)) != 0) + return (ret); - if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, - is_wrap ? MBEDTLS_ENCRYPT : - MBEDTLS_DECRYPT ) - ) != 0 ) - { - return( ret ); + if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits, is_wrap ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT)) != 0) { + return (ret); } - return( 0 ); + return (0); } /* * Free context */ -void mbedtls_nist_kw_free( mbedtls_nist_kw_context *ctx ) +void mbedtls_nist_kw_free(mbedtls_nist_kw_context* ctx) { - mbedtls_cipher_free( &ctx->cipher_ctx ); - mbedtls_platform_zeroize( ctx, sizeof( mbedtls_nist_kw_context ) ); + mbedtls_cipher_free(&ctx->cipher_ctx); + mbedtls_platform_zeroize(ctx, sizeof(mbedtls_nist_kw_context)); } /* * Helper function for Xoring the uint64_t "t" with the encrypted A. * Defined in NIST SP 800-38F section 6.1 */ -static void calc_a_xor_t( unsigned char A[KW_SEMIBLOCK_LENGTH], uint64_t t ) +static void calc_a_xor_t(unsigned char A[KW_SEMIBLOCK_LENGTH], uint64_t t) { size_t i = 0; - for( i = 0; i < sizeof( t ); i++ ) - { - A[i] ^= ( t >> ( ( sizeof( t ) - 1 - i ) * 8 ) ) & 0xff; + for (i = 0; i < sizeof(t); i++) { + A[i] ^= (t >> ((sizeof(t) - 1 - i) * 8)) & 0xff; } } @@ -207,10 +193,14 @@ static void calc_a_xor_t( unsigned char A[KW_SEMIBLOCK_LENGTH], uint64_t t ) * KW-AE as defined in SP 800-38F section 6.2 * KWP-AE as defined in SP 800-38F section 6.3 */ -int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, - mbedtls_nist_kw_mode_t mode, - const unsigned char *input, size_t in_len, - unsigned char *output, size_t *out_len, size_t out_size ) +int mbedtls_nist_kw_wrap( + mbedtls_nist_kw_context* ctx, + mbedtls_nist_kw_mode_t mode, + const unsigned char* input, + size_t in_len, + unsigned char* output, + size_t* out_len, + size_t out_size) { int ret = 0; size_t semiblocks = 0; @@ -219,109 +209,92 @@ int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, uint64_t t = 0; unsigned char outbuff[KW_SEMIBLOCK_LENGTH * 2]; unsigned char inbuff[KW_SEMIBLOCK_LENGTH * 2]; - unsigned char *R2 = output + KW_SEMIBLOCK_LENGTH; - unsigned char *A = output; + unsigned char* R2 = output + KW_SEMIBLOCK_LENGTH; + unsigned char* A = output; *out_len = 0; /* * Generate the String to work on */ - if( mode == MBEDTLS_KW_MODE_KW ) - { - if( out_size < in_len + KW_SEMIBLOCK_LENGTH ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + if (mode == MBEDTLS_KW_MODE_KW) { + if (out_size < in_len + KW_SEMIBLOCK_LENGTH) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } /* * According to SP 800-38F Table 1, the plaintext length for KW * must be between 2 to 2^54-1 semiblocks inclusive. */ - if( in_len < 16 || + if (in_len < 16 || #if SIZE_MAX > 0x1FFFFFFFFFFFFF8 in_len > 0x1FFFFFFFFFFFFF8 || #endif - in_len % KW_SEMIBLOCK_LENGTH != 0 ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + in_len % KW_SEMIBLOCK_LENGTH != 0) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } - memcpy( output, NIST_KW_ICV1, KW_SEMIBLOCK_LENGTH ); - memmove( output + KW_SEMIBLOCK_LENGTH, input, in_len ); - } - else - { - if( in_len % 8 != 0 ) - { - padlen = ( 8 - ( in_len % 8 ) ); + memcpy(output, NIST_KW_ICV1, KW_SEMIBLOCK_LENGTH); + memmove(output + KW_SEMIBLOCK_LENGTH, input, in_len); + } else { + if (in_len % 8 != 0) { + padlen = (8 - (in_len % 8)); } - if( out_size < in_len + KW_SEMIBLOCK_LENGTH + padlen ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + if (out_size < in_len + KW_SEMIBLOCK_LENGTH + padlen) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } /* * According to SP 800-38F Table 1, the plaintext length for KWP * must be between 1 and 2^32-1 octets inclusive. */ - if( in_len < 1 + if (in_len < 1 #if SIZE_MAX > 0xFFFFFFFF || in_len > 0xFFFFFFFF #endif - ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + ) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } - memcpy( output, NIST_KW_ICV2, KW_SEMIBLOCK_LENGTH / 2 ); - PUT_UINT32_BE( ( in_len & 0xffffffff ), output, - KW_SEMIBLOCK_LENGTH / 2 ); + memcpy(output, NIST_KW_ICV2, KW_SEMIBLOCK_LENGTH / 2); + PUT_UINT32_BE((in_len & 0xffffffff), output, KW_SEMIBLOCK_LENGTH / 2); - memcpy( output + KW_SEMIBLOCK_LENGTH, input, in_len ); - memset( output + KW_SEMIBLOCK_LENGTH + in_len, 0, padlen ); + memcpy(output + KW_SEMIBLOCK_LENGTH, input, in_len); + memset(output + KW_SEMIBLOCK_LENGTH + in_len, 0, padlen); } - semiblocks = ( ( in_len + padlen ) / KW_SEMIBLOCK_LENGTH ) + 1; + semiblocks = ((in_len + padlen) / KW_SEMIBLOCK_LENGTH) + 1; - s = 6 * ( semiblocks - 1 ); + s = 6 * (semiblocks - 1); - if( mode == MBEDTLS_KW_MODE_KWP - && in_len <= KW_SEMIBLOCK_LENGTH ) - { - memcpy( inbuff, output, 16 ); - ret = mbedtls_cipher_update( &ctx->cipher_ctx, - inbuff, 16, output, &olen ); - if( ret != 0 ) + if (mode == MBEDTLS_KW_MODE_KWP && in_len <= KW_SEMIBLOCK_LENGTH) { + memcpy(inbuff, output, 16); + ret = mbedtls_cipher_update(&ctx->cipher_ctx, inbuff, 16, output, &olen); + if (ret != 0) goto cleanup; - } - else - { + } else { /* * Do the wrapping function W, as defined in RFC 3394 section 2.2.1 */ - if( semiblocks < MIN_SEMIBLOCKS_COUNT ) - { + if (semiblocks < MIN_SEMIBLOCKS_COUNT) { ret = MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; goto cleanup; } /* Calculate intermediate values */ - for( t = 1; t <= s; t++ ) - { - memcpy( inbuff, A, KW_SEMIBLOCK_LENGTH ); - memcpy( inbuff + KW_SEMIBLOCK_LENGTH, R2, KW_SEMIBLOCK_LENGTH ); - - ret = mbedtls_cipher_update( &ctx->cipher_ctx, - inbuff, 16, outbuff, &olen ); - if( ret != 0 ) + for (t = 1; t <= s; t++) { + memcpy(inbuff, A, KW_SEMIBLOCK_LENGTH); + memcpy(inbuff + KW_SEMIBLOCK_LENGTH, R2, KW_SEMIBLOCK_LENGTH); + + ret = mbedtls_cipher_update(&ctx->cipher_ctx, inbuff, 16, outbuff, &olen); + if (ret != 0) goto cleanup; - memcpy( A, outbuff, KW_SEMIBLOCK_LENGTH ); - calc_a_xor_t( A, t ); + memcpy(A, outbuff, KW_SEMIBLOCK_LENGTH); + calc_a_xor_t(A, t); - memcpy( R2, outbuff + KW_SEMIBLOCK_LENGTH, KW_SEMIBLOCK_LENGTH ); + memcpy(R2, outbuff + KW_SEMIBLOCK_LENGTH, KW_SEMIBLOCK_LENGTH); R2 += KW_SEMIBLOCK_LENGTH; - if( R2 >= output + ( semiblocks * KW_SEMIBLOCK_LENGTH ) ) + if (R2 >= output + (semiblocks * KW_SEMIBLOCK_LENGTH)) R2 = output + KW_SEMIBLOCK_LENGTH; } } @@ -330,14 +303,13 @@ int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, cleanup: - if( ret != 0) - { - memset( output, 0, semiblocks * KW_SEMIBLOCK_LENGTH ); + if (ret != 0) { + memset(output, 0, semiblocks * KW_SEMIBLOCK_LENGTH); } - mbedtls_platform_zeroize( inbuff, KW_SEMIBLOCK_LENGTH * 2 ); - mbedtls_platform_zeroize( outbuff, KW_SEMIBLOCK_LENGTH * 2 ); + mbedtls_platform_zeroize(inbuff, KW_SEMIBLOCK_LENGTH * 2); + mbedtls_platform_zeroize(outbuff, KW_SEMIBLOCK_LENGTH * 2); - return( ret ); + return (ret); } /* @@ -348,71 +320,75 @@ cleanup: * 3. Minimal number of semiblocks is 3. * 4. A is a buffer to hold the first semiblock of the input buffer. */ -static int unwrap( mbedtls_nist_kw_context *ctx, - const unsigned char *input, size_t semiblocks, - unsigned char A[KW_SEMIBLOCK_LENGTH], - unsigned char *output, size_t* out_len ) +static int unwrap( + mbedtls_nist_kw_context* ctx, + const unsigned char* input, + size_t semiblocks, + unsigned char A[KW_SEMIBLOCK_LENGTH], + unsigned char* output, + size_t* out_len) { int ret = 0; - const size_t s = 6 * ( semiblocks - 1 ); + const size_t s = 6 * (semiblocks - 1); size_t olen; uint64_t t = 0; unsigned char outbuff[KW_SEMIBLOCK_LENGTH * 2]; unsigned char inbuff[KW_SEMIBLOCK_LENGTH * 2]; - unsigned char *R = output + ( semiblocks - 2 ) * KW_SEMIBLOCK_LENGTH; + unsigned char* R = output + (semiblocks - 2) * KW_SEMIBLOCK_LENGTH; *out_len = 0; - if( semiblocks < MIN_SEMIBLOCKS_COUNT ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + if (semiblocks < MIN_SEMIBLOCKS_COUNT) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } - memcpy( A, input, KW_SEMIBLOCK_LENGTH ); - memmove( output, input + KW_SEMIBLOCK_LENGTH, ( semiblocks - 1 ) * KW_SEMIBLOCK_LENGTH ); + memcpy(A, input, KW_SEMIBLOCK_LENGTH); + memmove(output, input + KW_SEMIBLOCK_LENGTH, (semiblocks - 1) * KW_SEMIBLOCK_LENGTH); /* Calculate intermediate values */ - for( t = s; t >= 1; t-- ) - { - calc_a_xor_t( A, t ); + for (t = s; t >= 1; t--) { + calc_a_xor_t(A, t); - memcpy( inbuff, A, KW_SEMIBLOCK_LENGTH ); - memcpy( inbuff + KW_SEMIBLOCK_LENGTH, R, KW_SEMIBLOCK_LENGTH ); + memcpy(inbuff, A, KW_SEMIBLOCK_LENGTH); + memcpy(inbuff + KW_SEMIBLOCK_LENGTH, R, KW_SEMIBLOCK_LENGTH); - ret = mbedtls_cipher_update( &ctx->cipher_ctx, - inbuff, 16, outbuff, &olen ); - if( ret != 0 ) + ret = mbedtls_cipher_update(&ctx->cipher_ctx, inbuff, 16, outbuff, &olen); + if (ret != 0) goto cleanup; - memcpy( A, outbuff, KW_SEMIBLOCK_LENGTH ); + memcpy(A, outbuff, KW_SEMIBLOCK_LENGTH); /* Set R as LSB64 of outbuff */ - memcpy( R, outbuff + KW_SEMIBLOCK_LENGTH, KW_SEMIBLOCK_LENGTH ); + memcpy(R, outbuff + KW_SEMIBLOCK_LENGTH, KW_SEMIBLOCK_LENGTH); - if( R == output ) - R = output + ( semiblocks - 2 ) * KW_SEMIBLOCK_LENGTH; + if (R == output) + R = output + (semiblocks - 2) * KW_SEMIBLOCK_LENGTH; else R -= KW_SEMIBLOCK_LENGTH; } - *out_len = ( semiblocks - 1 ) * KW_SEMIBLOCK_LENGTH; + *out_len = (semiblocks - 1) * KW_SEMIBLOCK_LENGTH; cleanup: - if( ret != 0) - memset( output, 0, ( semiblocks - 1 ) * KW_SEMIBLOCK_LENGTH ); - mbedtls_platform_zeroize( inbuff, sizeof( inbuff ) ); - mbedtls_platform_zeroize( outbuff, sizeof( outbuff ) ); + if (ret != 0) + memset(output, 0, (semiblocks - 1) * KW_SEMIBLOCK_LENGTH); + mbedtls_platform_zeroize(inbuff, sizeof(inbuff)); + mbedtls_platform_zeroize(outbuff, sizeof(outbuff)); - return( ret ); + return (ret); } /* * KW-AD as defined in SP 800-38F section 6.2 * KWP-AD as defined in SP 800-38F section 6.3 */ -int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, - mbedtls_nist_kw_mode_t mode, - const unsigned char *input, size_t in_len, - unsigned char *output, size_t *out_len, size_t out_size ) +int mbedtls_nist_kw_unwrap( + mbedtls_nist_kw_context* ctx, + mbedtls_nist_kw_mode_t mode, + const unsigned char* input, + size_t in_len, + unsigned char* output, + size_t* out_len, + size_t out_size) { int ret = 0; size_t i, olen; @@ -420,89 +396,75 @@ int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, unsigned char diff, bad_padding = 0; *out_len = 0; - if( out_size < in_len - KW_SEMIBLOCK_LENGTH ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + if (out_size < in_len - KW_SEMIBLOCK_LENGTH) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } - if( mode == MBEDTLS_KW_MODE_KW ) - { + if (mode == MBEDTLS_KW_MODE_KW) { /* * According to SP 800-38F Table 1, the ciphertext length for KW * must be between 3 to 2^54 semiblocks inclusive. */ - if( in_len < 24 || + if (in_len < 24 || #if SIZE_MAX > 0x200000000000000 in_len > 0x200000000000000 || #endif - in_len % KW_SEMIBLOCK_LENGTH != 0 ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + in_len % KW_SEMIBLOCK_LENGTH != 0) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } - ret = unwrap( ctx, input, in_len / KW_SEMIBLOCK_LENGTH, - A, output, out_len ); - if( ret != 0 ) + ret = unwrap(ctx, input, in_len / KW_SEMIBLOCK_LENGTH, A, output, out_len); + if (ret != 0) goto cleanup; /* Check ICV in "constant-time" */ - diff = mbedtls_nist_kw_safer_memcmp( NIST_KW_ICV1, A, KW_SEMIBLOCK_LENGTH ); + diff = mbedtls_nist_kw_safer_memcmp(NIST_KW_ICV1, A, KW_SEMIBLOCK_LENGTH); - if( diff != 0 ) - { + if (diff != 0) { ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; goto cleanup; } - } - else if( mode == MBEDTLS_KW_MODE_KWP ) - { + } else if (mode == MBEDTLS_KW_MODE_KWP) { size_t padlen = 0; uint32_t Plen; /* * According to SP 800-38F Table 1, the ciphertext length for KWP * must be between 2 to 2^29 semiblocks inclusive. */ - if( in_len < KW_SEMIBLOCK_LENGTH * 2 || + if (in_len < KW_SEMIBLOCK_LENGTH * 2 || #if SIZE_MAX > 0x100000000 in_len > 0x100000000 || #endif - in_len % KW_SEMIBLOCK_LENGTH != 0 ) - { - return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + in_len % KW_SEMIBLOCK_LENGTH != 0) { + return (MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); } - if( in_len == KW_SEMIBLOCK_LENGTH * 2 ) - { + if (in_len == KW_SEMIBLOCK_LENGTH * 2) { unsigned char outbuff[KW_SEMIBLOCK_LENGTH * 2]; - ret = mbedtls_cipher_update( &ctx->cipher_ctx, - input, 16, outbuff, &olen ); - if( ret != 0 ) + ret = mbedtls_cipher_update(&ctx->cipher_ctx, input, 16, outbuff, &olen); + if (ret != 0) goto cleanup; - memcpy( A, outbuff, KW_SEMIBLOCK_LENGTH ); - memcpy( output, outbuff + KW_SEMIBLOCK_LENGTH, KW_SEMIBLOCK_LENGTH ); - mbedtls_platform_zeroize( outbuff, sizeof( outbuff ) ); + memcpy(A, outbuff, KW_SEMIBLOCK_LENGTH); + memcpy(output, outbuff + KW_SEMIBLOCK_LENGTH, KW_SEMIBLOCK_LENGTH); + mbedtls_platform_zeroize(outbuff, sizeof(outbuff)); *out_len = KW_SEMIBLOCK_LENGTH; - } - else - { + } else { /* in_len >= KW_SEMIBLOCK_LENGTH * 3 */ - ret = unwrap( ctx, input, in_len / KW_SEMIBLOCK_LENGTH, - A, output, out_len ); - if( ret != 0 ) + ret = unwrap(ctx, input, in_len / KW_SEMIBLOCK_LENGTH, A, output, out_len); + if (ret != 0) goto cleanup; } /* Check ICV in "constant-time" */ - diff = mbedtls_nist_kw_safer_memcmp( NIST_KW_ICV2, A, KW_SEMIBLOCK_LENGTH / 2 ); + diff = mbedtls_nist_kw_safer_memcmp(NIST_KW_ICV2, A, KW_SEMIBLOCK_LENGTH / 2); - if( diff != 0 ) - { + if (diff != 0) { ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; } - GET_UINT32_BE( Plen, A, KW_SEMIBLOCK_LENGTH / 2 ); + GET_UINT32_BE(Plen, A, KW_SEMIBLOCK_LENGTH / 2); /* * Plen is the length of the plaintext, when the input is valid. @@ -510,51 +472,44 @@ int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, * larger than 8, because of the type wrap around. */ padlen = in_len - KW_SEMIBLOCK_LENGTH - Plen; - if ( padlen > 7 ) - { + if (padlen > 7) { padlen &= 7; ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; } /* Check padding in "constant-time" */ - for( diff = 0, i = 0; i < KW_SEMIBLOCK_LENGTH; i++ ) - { - if( i >= KW_SEMIBLOCK_LENGTH - padlen ) - diff |= output[*out_len - KW_SEMIBLOCK_LENGTH + i]; - else - bad_padding |= output[*out_len - KW_SEMIBLOCK_LENGTH + i]; + for (diff = 0, i = 0; i < KW_SEMIBLOCK_LENGTH; i++) { + if (i >= KW_SEMIBLOCK_LENGTH - padlen) + diff |= output[*out_len - KW_SEMIBLOCK_LENGTH + i]; + else + bad_padding |= output[*out_len - KW_SEMIBLOCK_LENGTH + i]; } - if( diff != 0 ) - { + if (diff != 0) { ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; } - if( ret != 0 ) - { + if (ret != 0) { goto cleanup; } - memset( output + Plen, 0, padlen ); + memset(output + Plen, 0, padlen); *out_len = Plen; - } - else - { + } else { ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; goto cleanup; } cleanup: - if( ret != 0 ) - { - memset( output, 0, *out_len ); + if (ret != 0) { + memset(output, 0, *out_len); *out_len = 0; } - mbedtls_platform_zeroize( &bad_padding, sizeof( bad_padding) ); - mbedtls_platform_zeroize( &diff, sizeof( diff ) ); - mbedtls_platform_zeroize( A, sizeof( A ) ); + mbedtls_platform_zeroize(&bad_padding, sizeof(bad_padding)); + mbedtls_platform_zeroize(&diff, sizeof(diff)); + mbedtls_platform_zeroize(A, sizeof(A)); - return( ret ); + return (ret); } #endif /* !MBEDTLS_NIST_KW_ALT */ @@ -567,212 +522,155 @@ cleanup: * Test vectors taken from NIST * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES#KW */ -static const unsigned int key_len[KW_TESTS] = { 16, 24, 32 }; +static const unsigned int key_len[KW_TESTS] = {16, 24, 32}; static const unsigned char kw_key[KW_TESTS][32] = { - { 0x75, 0x75, 0xda, 0x3a, 0x93, 0x60, 0x7c, 0xc2, - 0xbf, 0xd8, 0xce, 0xc7, 0xaa, 0xdf, 0xd9, 0xa6 }, - { 0x2d, 0x85, 0x26, 0x08, 0x1d, 0x02, 0xfb, 0x5b, - 0x85, 0xf6, 0x9a, 0xc2, 0x86, 0xec, 0xd5, 0x7d, - 0x40, 0xdf, 0x5d, 0xf3, 0x49, 0x47, 0x44, 0xd3 }, - { 0x11, 0x2a, 0xd4, 0x1b, 0x48, 0x56, 0xc7, 0x25, - 0x4a, 0x98, 0x48, 0xd3, 0x0f, 0xdd, 0x78, 0x33, - 0x5b, 0x03, 0x9a, 0x48, 0xa8, 0x96, 0x2c, 0x4d, - 0x1c, 0xb7, 0x8e, 0xab, 0xd5, 0xda, 0xd7, 0x88 } + {0x75, 0x75, 0xda, 0x3a, 0x93, 0x60, 0x7c, 0xc2, 0xbf, 0xd8, 0xce, 0xc7, 0xaa, 0xdf, 0xd9, 0xa6}, + {0x2d, 0x85, 0x26, 0x08, 0x1d, 0x02, 0xfb, 0x5b, 0x85, 0xf6, 0x9a, 0xc2, 0x86, 0xec, 0xd5, 0x7d, 0x40, 0xdf, 0x5d, 0xf3, 0x49, 0x47, 0x44, 0xd3}, + {0x11, 0x2a, 0xd4, 0x1b, 0x48, 0x56, 0xc7, 0x25, 0x4a, 0x98, 0x48, 0xd3, 0x0f, 0xdd, 0x78, 0x33, + 0x5b, 0x03, 0x9a, 0x48, 0xa8, 0x96, 0x2c, 0x4d, 0x1c, 0xb7, 0x8e, 0xab, 0xd5, 0xda, 0xd7, 0x88} }; static const unsigned char kw_msg[KW_TESTS][40] = { - { 0x42, 0x13, 0x6d, 0x3c, 0x38, 0x4a, 0x3e, 0xea, - 0xc9, 0x5a, 0x06, 0x6f, 0xd2, 0x8f, 0xed, 0x3f }, - { 0x95, 0xc1, 0x1b, 0xf5, 0x35, 0x3a, 0xfe, 0xdb, - 0x98, 0xfd, 0xd6, 0xc8, 0xca, 0x6f, 0xdb, 0x6d, - 0xa5, 0x4b, 0x74, 0xb4, 0x99, 0x0f, 0xdc, 0x45, - 0xc0, 0x9d, 0x15, 0x8f, 0x51, 0xce, 0x62, 0x9d, - 0xe2, 0xaf, 0x26, 0xe3, 0x25, 0x0e, 0x6b, 0x4c }, - { 0x1b, 0x20, 0xbf, 0x19, 0x90, 0xb0, 0x65, 0xd7, - 0x98, 0xe1, 0xb3, 0x22, 0x64, 0xad, 0x50, 0xa8, - 0x74, 0x74, 0x92, 0xba, 0x09, 0xa0, 0x4d, 0xd1 } + {0x42, 0x13, 0x6d, 0x3c, 0x38, 0x4a, 0x3e, 0xea, 0xc9, 0x5a, 0x06, 0x6f, 0xd2, 0x8f, 0xed, 0x3f}, + {0x95, 0xc1, 0x1b, 0xf5, 0x35, 0x3a, 0xfe, 0xdb, 0x98, 0xfd, 0xd6, 0xc8, 0xca, 0x6f, 0xdb, 0x6d, 0xa5, 0x4b, 0x74, 0xb4, + 0x99, 0x0f, 0xdc, 0x45, 0xc0, 0x9d, 0x15, 0x8f, 0x51, 0xce, 0x62, 0x9d, 0xe2, 0xaf, 0x26, 0xe3, 0x25, 0x0e, 0x6b, 0x4c}, + {0x1b, 0x20, 0xbf, 0x19, 0x90, 0xb0, 0x65, 0xd7, 0x98, 0xe1, 0xb3, 0x22, 0x64, 0xad, 0x50, 0xa8, 0x74, 0x74, 0x92, 0xba, 0x09, 0xa0, 0x4d, 0xd1} }; -static const size_t kw_msg_len[KW_TESTS] = { 16, 40, 24 }; -static const size_t kw_out_len[KW_TESTS] = { 24, 48, 32 }; +static const size_t kw_msg_len[KW_TESTS] = {16, 40, 24}; +static const size_t kw_out_len[KW_TESTS] = {24, 48, 32}; static const unsigned char kw_res[KW_TESTS][48] = { - { 0x03, 0x1f, 0x6b, 0xd7, 0xe6, 0x1e, 0x64, 0x3d, - 0xf6, 0x85, 0x94, 0x81, 0x6f, 0x64, 0xca, 0xa3, - 0xf5, 0x6f, 0xab, 0xea, 0x25, 0x48, 0xf5, 0xfb }, - { 0x44, 0x3c, 0x6f, 0x15, 0x09, 0x83, 0x71, 0x91, - 0x3e, 0x5c, 0x81, 0x4c, 0xa1, 0xa0, 0x42, 0xec, - 0x68, 0x2f, 0x7b, 0x13, 0x6d, 0x24, 0x3a, 0x4d, - 0x6c, 0x42, 0x6f, 0xc6, 0x97, 0x15, 0x63, 0xe8, - 0xa1, 0x4a, 0x55, 0x8e, 0x09, 0x64, 0x16, 0x19, - 0xbf, 0x03, 0xfc, 0xaf, 0x90, 0xb1, 0xfc, 0x2d }, - { 0xba, 0x8a, 0x25, 0x9a, 0x47, 0x1b, 0x78, 0x7d, - 0xd5, 0xd5, 0x40, 0xec, 0x25, 0xd4, 0x3d, 0x87, - 0x20, 0x0f, 0xda, 0xdc, 0x6d, 0x1f, 0x05, 0xd9, - 0x16, 0x58, 0x4f, 0xa9, 0xf6, 0xcb, 0xf5, 0x12 } + {0x03, 0x1f, 0x6b, 0xd7, 0xe6, 0x1e, 0x64, 0x3d, 0xf6, 0x85, 0x94, 0x81, 0x6f, 0x64, 0xca, 0xa3, 0xf5, 0x6f, 0xab, 0xea, 0x25, 0x48, 0xf5, 0xfb}, + {0x44, 0x3c, 0x6f, 0x15, 0x09, 0x83, 0x71, 0x91, 0x3e, 0x5c, 0x81, 0x4c, 0xa1, 0xa0, 0x42, 0xec, 0x68, 0x2f, 0x7b, 0x13, 0x6d, 0x24, 0x3a, 0x4d, + 0x6c, 0x42, 0x6f, 0xc6, 0x97, 0x15, 0x63, 0xe8, 0xa1, 0x4a, 0x55, 0x8e, 0x09, 0x64, 0x16, 0x19, 0xbf, 0x03, 0xfc, 0xaf, 0x90, 0xb1, 0xfc, 0x2d}, + {0xba, 0x8a, 0x25, 0x9a, 0x47, 0x1b, 0x78, 0x7d, 0xd5, 0xd5, 0x40, 0xec, 0x25, 0xd4, 0x3d, 0x87, + 0x20, 0x0f, 0xda, 0xdc, 0x6d, 0x1f, 0x05, 0xd9, 0x16, 0x58, 0x4f, 0xa9, 0xf6, 0xcb, 0xf5, 0x12} }; static const unsigned char kwp_key[KW_TESTS][32] = { - { 0x78, 0x65, 0xe2, 0x0f, 0x3c, 0x21, 0x65, 0x9a, - 0xb4, 0x69, 0x0b, 0x62, 0x9c, 0xdf, 0x3c, 0xc4 }, - { 0xf5, 0xf8, 0x96, 0xa3, 0xbd, 0x2f, 0x4a, 0x98, - 0x23, 0xef, 0x16, 0x2b, 0x00, 0xb8, 0x05, 0xd7, - 0xde, 0x1e, 0xa4, 0x66, 0x26, 0x96, 0xa2, 0x58 }, - { 0x95, 0xda, 0x27, 0x00, 0xca, 0x6f, 0xd9, 0xa5, - 0x25, 0x54, 0xee, 0x2a, 0x8d, 0xf1, 0x38, 0x6f, - 0x5b, 0x94, 0xa1, 0xa6, 0x0e, 0xd8, 0xa4, 0xae, - 0xf6, 0x0a, 0x8d, 0x61, 0xab, 0x5f, 0x22, 0x5a } + {0x78, 0x65, 0xe2, 0x0f, 0x3c, 0x21, 0x65, 0x9a, 0xb4, 0x69, 0x0b, 0x62, 0x9c, 0xdf, 0x3c, 0xc4}, + {0xf5, 0xf8, 0x96, 0xa3, 0xbd, 0x2f, 0x4a, 0x98, 0x23, 0xef, 0x16, 0x2b, 0x00, 0xb8, 0x05, 0xd7, 0xde, 0x1e, 0xa4, 0x66, 0x26, 0x96, 0xa2, 0x58}, + {0x95, 0xda, 0x27, 0x00, 0xca, 0x6f, 0xd9, 0xa5, 0x25, 0x54, 0xee, 0x2a, 0x8d, 0xf1, 0x38, 0x6f, + 0x5b, 0x94, 0xa1, 0xa6, 0x0e, 0xd8, 0xa4, 0xae, 0xf6, 0x0a, 0x8d, 0x61, 0xab, 0x5f, 0x22, 0x5a} }; static const unsigned char kwp_msg[KW_TESTS][31] = { - { 0xbd, 0x68, 0x43, 0xd4, 0x20, 0x37, 0x8d, 0xc8, - 0x96 }, - { 0x6c, 0xcd, 0xd5, 0x85, 0x18, 0x40, 0x97, 0xeb, - 0xd5, 0xc3, 0xaf, 0x3e, 0x47, 0xd0, 0x2c, 0x19, - 0x14, 0x7b, 0x4d, 0x99, 0x5f, 0x96, 0x43, 0x66, - 0x91, 0x56, 0x75, 0x8c, 0x13, 0x16, 0x8f }, - { 0xd1 } + {0xbd, 0x68, 0x43, 0xd4, 0x20, 0x37, 0x8d, 0xc8, 0x96}, + {0x6c, 0xcd, 0xd5, 0x85, 0x18, 0x40, 0x97, 0xeb, 0xd5, 0xc3, 0xaf, 0x3e, 0x47, 0xd0, 0x2c, 0x19, + 0x14, 0x7b, 0x4d, 0x99, 0x5f, 0x96, 0x43, 0x66, 0x91, 0x56, 0x75, 0x8c, 0x13, 0x16, 0x8f}, + {0xd1} }; -static const size_t kwp_msg_len[KW_TESTS] = { 9, 31, 1 }; +static const size_t kwp_msg_len[KW_TESTS] = {9, 31, 1}; static const unsigned char kwp_res[KW_TESTS][48] = { - { 0x41, 0xec, 0xa9, 0x56, 0xd4, 0xaa, 0x04, 0x7e, - 0xb5, 0xcf, 0x4e, 0xfe, 0x65, 0x96, 0x61, 0xe7, - 0x4d, 0xb6, 0xf8, 0xc5, 0x64, 0xe2, 0x35, 0x00 }, - { 0x4e, 0x9b, 0xc2, 0xbc, 0xbc, 0x6c, 0x1e, 0x13, - 0xd3, 0x35, 0xbc, 0xc0, 0xf7, 0x73, 0x6a, 0x88, - 0xfa, 0x87, 0x53, 0x66, 0x15, 0xbb, 0x8e, 0x63, - 0x8b, 0xcc, 0x81, 0x66, 0x84, 0x68, 0x17, 0x90, - 0x67, 0xcf, 0xa9, 0x8a, 0x9d, 0x0e, 0x33, 0x26 }, - { 0x06, 0xba, 0x7a, 0xe6, 0xf3, 0x24, 0x8c, 0xfd, - 0xcf, 0x26, 0x75, 0x07, 0xfa, 0x00, 0x1b, 0xc4 } + {0x41, 0xec, 0xa9, 0x56, 0xd4, 0xaa, 0x04, 0x7e, 0xb5, 0xcf, 0x4e, 0xfe, 0x65, 0x96, 0x61, 0xe7, 0x4d, 0xb6, 0xf8, 0xc5, 0x64, 0xe2, 0x35, 0x00}, + {0x4e, 0x9b, 0xc2, 0xbc, 0xbc, 0x6c, 0x1e, 0x13, 0xd3, 0x35, 0xbc, 0xc0, 0xf7, 0x73, 0x6a, 0x88, 0xfa, 0x87, 0x53, 0x66, + 0x15, 0xbb, 0x8e, 0x63, 0x8b, 0xcc, 0x81, 0x66, 0x84, 0x68, 0x17, 0x90, 0x67, 0xcf, 0xa9, 0x8a, 0x9d, 0x0e, 0x33, 0x26}, + {0x06, 0xba, 0x7a, 0xe6, 0xf3, 0x24, 0x8c, 0xfd, 0xcf, 0x26, 0x75, 0x07, 0xfa, 0x00, 0x1b, 0xc4} }; -static const size_t kwp_out_len[KW_TESTS] = { 24, 40, 16 }; +static const size_t kwp_out_len[KW_TESTS] = {24, 40, 16}; -int mbedtls_nist_kw_self_test( int verbose ) +int mbedtls_nist_kw_self_test(int verbose) { mbedtls_nist_kw_context ctx; unsigned char out[48]; size_t olen; int i; int ret = 0; - mbedtls_nist_kw_init( &ctx ); + mbedtls_nist_kw_init(&ctx); - for( i = 0; i < KW_TESTS; i++ ) - { - if( verbose != 0 ) - mbedtls_printf( " KW-AES-%u ", (unsigned int) key_len[i] * 8 ); + for (i = 0; i < KW_TESTS; i++) { + if (verbose != 0) + mbedtls_printf(" KW-AES-%u ", (unsigned int)key_len[i] * 8); - ret = mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, - kw_key[i], key_len[i] * 8, 1 ); - if( ret != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( " KW: setup failed " ); + ret = mbedtls_nist_kw_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, kw_key[i], key_len[i] * 8, 1); + if (ret != 0) { + if (verbose != 0) + mbedtls_printf(" KW: setup failed "); goto end; } - ret = mbedtls_nist_kw_wrap( &ctx, MBEDTLS_KW_MODE_KW, kw_msg[i], - kw_msg_len[i], out, &olen, sizeof( out ) ); - if( ret != 0 || kw_out_len[i] != olen || - memcmp( out, kw_res[i], kw_out_len[i] ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed. "); + ret = mbedtls_nist_kw_wrap(&ctx, MBEDTLS_KW_MODE_KW, kw_msg[i], kw_msg_len[i], out, &olen, sizeof(out)); + if (ret != 0 || kw_out_len[i] != olen || memcmp(out, kw_res[i], kw_out_len[i]) != 0) { + if (verbose != 0) + mbedtls_printf("failed. "); ret = 1; goto end; } - if( ( ret = mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, - kw_key[i], key_len[i] * 8, 0 ) ) - != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( " KW: setup failed "); + if ((ret = mbedtls_nist_kw_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, kw_key[i], key_len[i] * 8, 0)) != 0) { + if (verbose != 0) + mbedtls_printf(" KW: setup failed "); goto end; } - ret = mbedtls_nist_kw_unwrap( &ctx, MBEDTLS_KW_MODE_KW, - out, olen, out, &olen, sizeof( out ) ); + ret = mbedtls_nist_kw_unwrap(&ctx, MBEDTLS_KW_MODE_KW, out, olen, out, &olen, sizeof(out)); - if( ret != 0 || olen != kw_msg_len[i] || - memcmp( out, kw_msg[i], kw_msg_len[i] ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (ret != 0 || olen != kw_msg_len[i] || memcmp(out, kw_msg[i], kw_msg_len[i]) != 0) { + if (verbose != 0) + mbedtls_printf("failed\n"); ret = 1; goto end; } - if( verbose != 0 ) - mbedtls_printf( " passed\n" ); + if (verbose != 0) + mbedtls_printf(" passed\n"); } - for( i = 0; i < KW_TESTS; i++ ) - { - olen = sizeof( out ); - if( verbose != 0 ) - mbedtls_printf( " KWP-AES-%u ", (unsigned int) key_len[i] * 8 ); + for (i = 0; i < KW_TESTS; i++) { + olen = sizeof(out); + if (verbose != 0) + mbedtls_printf(" KWP-AES-%u ", (unsigned int)key_len[i] * 8); - ret = mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, kwp_key[i], - key_len[i] * 8, 1 ); - if( ret != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( " KWP: setup failed " ); + ret = mbedtls_nist_kw_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, kwp_key[i], key_len[i] * 8, 1); + if (ret != 0) { + if (verbose != 0) + mbedtls_printf(" KWP: setup failed "); goto end; } - ret = mbedtls_nist_kw_wrap( &ctx, MBEDTLS_KW_MODE_KWP, kwp_msg[i], - kwp_msg_len[i], out, &olen, sizeof( out ) ); + ret = mbedtls_nist_kw_wrap(&ctx, MBEDTLS_KW_MODE_KWP, kwp_msg[i], kwp_msg_len[i], out, &olen, sizeof(out)); - if( ret != 0 || kwp_out_len[i] != olen || - memcmp( out, kwp_res[i], kwp_out_len[i] ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed. "); + if (ret != 0 || kwp_out_len[i] != olen || memcmp(out, kwp_res[i], kwp_out_len[i]) != 0) { + if (verbose != 0) + mbedtls_printf("failed. "); ret = 1; goto end; } - if( ( ret = mbedtls_nist_kw_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, - kwp_key[i], key_len[i] * 8, 0 ) ) - != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( " KWP: setup failed "); + if ((ret = mbedtls_nist_kw_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, kwp_key[i], key_len[i] * 8, 0)) != 0) { + if (verbose != 0) + mbedtls_printf(" KWP: setup failed "); goto end; } - ret = mbedtls_nist_kw_unwrap( &ctx, MBEDTLS_KW_MODE_KWP, out, - olen, out, &olen, sizeof( out ) ); + ret = mbedtls_nist_kw_unwrap(&ctx, MBEDTLS_KW_MODE_KWP, out, olen, out, &olen, sizeof(out)); - if( ret != 0 || olen != kwp_msg_len[i] || - memcmp( out, kwp_msg[i], kwp_msg_len[i] ) != 0 ) - { - if( verbose != 0 ) - mbedtls_printf( "failed. "); + if (ret != 0 || olen != kwp_msg_len[i] || memcmp(out, kwp_msg[i], kwp_msg_len[i]) != 0) { + if (verbose != 0) + mbedtls_printf("failed. "); ret = 1; goto end; } - if( verbose != 0 ) - mbedtls_printf( " passed\n" ); + if (verbose != 0) + mbedtls_printf(" passed\n"); } end: - mbedtls_nist_kw_free( &ctx ); + mbedtls_nist_kw_free(&ctx); - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); - return( ret ); + return (ret); } #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/nettls/ssl/oid.c b/nettls/ssl/oid.c index 8749978f312a85d620edb0f446b33a76d08bb309..3b27941d4993359c154c62fef1c4078cbff703e9 100644 --- a/nettls/ssl/oid.c +++ b/nettls/ssl/oid.c @@ -285,13 +285,13 @@ FN_OID_TYPED_FROM_ASN1(oid_x509_ext_t, x509_ext, oid_x509_ext) FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int, ext_type) static const mbedtls_oid_descriptor_t oid_ext_key_usage[] = { - {ADD_LEN(MBEDTLS_OID_SERVER_AUTH), "id-kp-serverAuth", "TLS Web Server Authentication" }, - { ADD_LEN(MBEDTLS_OID_CLIENT_AUTH), "id-kp-clientAuth", "TLS Web Client Authentication" }, - { ADD_LEN(MBEDTLS_OID_CODE_SIGNING), "id-kp-codeSigning", "Code Signing" }, - { ADD_LEN(MBEDTLS_OID_EMAIL_PROTECTION), "id-kp-emailProtection", "E-mail Protection" }, - { ADD_LEN(MBEDTLS_OID_TIME_STAMPING), "id-kp-timeStamping", "Time Stamping"}, - { ADD_LEN(MBEDTLS_OID_OCSP_SIGNING), "id-kp-OCSPSigning", "OCSP Signing" }, - { NULL, 0, NULL, NULL}, + {ADD_LEN(MBEDTLS_OID_SERVER_AUTH), "id-kp-serverAuth", "TLS Web Server Authentication"}, + {ADD_LEN(MBEDTLS_OID_CLIENT_AUTH), "id-kp-clientAuth", "TLS Web Client Authentication"}, + {ADD_LEN(MBEDTLS_OID_CODE_SIGNING), "id-kp-codeSigning", "Code Signing"}, + {ADD_LEN(MBEDTLS_OID_EMAIL_PROTECTION), "id-kp-emailProtection", "E-mail Protection"}, + {ADD_LEN(MBEDTLS_OID_TIME_STAMPING), "id-kp-timeStamping", "Time Stamping"}, + {ADD_LEN(MBEDTLS_OID_OCSP_SIGNING), "id-kp-OCSPSigning", "OCSP Signing"}, + {NULL, 0, NULL, NULL}, }; FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage) @@ -404,8 +404,7 @@ static const oid_sig_alg_t oid_sig_alg[] = { FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg) FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc, oid_sig_alg_t, sig_alg, const char*, description) FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg, oid_sig_alg_t, sig_alg, mbedtls_md_type_t, md_alg, mbedtls_pk_type_t, pk_alg) -FN_OID_GET_OID_BY_ATTR2( - mbedtls_oid_get_oid_by_sig_alg, oid_sig_alg_t, oid_sig_alg, mbedtls_pk_type_t, pk_alg, mbedtls_md_type_t, md_alg) +FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg, oid_sig_alg_t, oid_sig_alg, mbedtls_pk_type_t, pk_alg, mbedtls_md_type_t, md_alg) #endif /* MBEDTLS_MD_C */ /* @@ -641,13 +640,11 @@ typedef struct { static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] = { { - {ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC), "pbeWithSHAAnd3-KeyTripleDES-CBC", - "PBE with SHA1 and 3-Key 3DES"}, + {ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC), "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES"}, MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE3_CBC, }, { - {ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC), "pbeWithSHAAnd2-KeyTripleDES-CBC", - "PBE with SHA1 and 2-Key 3DES"}, + {ADD_LEN(MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC), "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES"}, MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE_CBC, }, { @@ -657,14 +654,7 @@ static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] = { }; FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg) -FN_OID_GET_ATTR2( - mbedtls_oid_get_pkcs12_pbe_alg, - oid_pkcs12_pbe_alg_t, - pkcs12_pbe_alg, - mbedtls_md_type_t, - md_alg, - mbedtls_cipher_type_t, - cipher_alg) +FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg, oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, mbedtls_md_type_t, md_alg, mbedtls_cipher_type_t, cipher_alg) #endif /* MBEDTLS_PKCS12_C */ #define OID_SAFE_SNPRINTF \ diff --git a/nettls/ssl/pem.c b/nettls/ssl/pem.c index 6c4ee92a6947916710a126a0f5122d1ccf5b662f..f2ad688e2893f994c3ee6514034bdd8baf8d0f30 100644 --- a/nettls/ssl/pem.c +++ b/nettls/ssl/pem.c @@ -163,8 +163,7 @@ exit: /* * Decrypt with DES-CBC, using PBKDF1 for key derivation */ -static int - pem_des_decrypt(unsigned char des_iv[8], unsigned char* buf, size_t buflen, const unsigned char* pwd, size_t pwdlen) +static int pem_des_decrypt(unsigned char des_iv[8], unsigned char* buf, size_t buflen, const unsigned char* pwd, size_t pwdlen) { mbedtls_des_context des_ctx; unsigned char des_key[8]; @@ -189,8 +188,7 @@ exit: /* * Decrypt with 3DES-CBC, using PBKDF1 for key derivation */ -static int pem_des3_decrypt( - unsigned char des3_iv[8], unsigned char* buf, size_t buflen, const unsigned char* pwd, size_t pwdlen) +static int pem_des3_decrypt(unsigned char des3_iv[8], unsigned char* buf, size_t buflen, const unsigned char* pwd, size_t pwdlen) { mbedtls_des3_context des3_ctx; unsigned char des3_key[24]; @@ -217,13 +215,7 @@ exit: /* * Decrypt with AES-XXX-CBC, using PBKDF1 for key derivation */ -static int pem_aes_decrypt( - unsigned char aes_iv[16], - unsigned int keylen, - unsigned char* buf, - size_t buflen, - const unsigned char* pwd, - size_t pwdlen) +static int pem_aes_decrypt(unsigned char aes_iv[16], unsigned int keylen, unsigned char* buf, size_t buflen, const unsigned char* pwd, size_t pwdlen) { mbedtls_aes_context aes_ctx; unsigned char aes_key[32]; @@ -461,13 +453,7 @@ void mbedtls_pem_free(mbedtls_pem_context* ctx) #if defined(MBEDTLS_PEM_WRITE_C) int mbedtls_pem_write_buffer( - const char* header, - const char* footer, - const unsigned char* der_data, - size_t der_len, - unsigned char* buf, - size_t buf_len, - size_t* olen) + const char* header, const char* footer, const unsigned char* der_data, size_t der_len, unsigned char* buf, size_t buf_len, size_t* olen) { int ret; unsigned char *encode_buf = NULL, *c, *p = buf; diff --git a/nettls/ssl/pk.c b/nettls/ssl/pk.c index 4d08785c2a06632da1a7d45020aeeea4e34b92f1..0d503aae1321b8dcc2a8c694420ae0f7dcd55927 100644 --- a/nettls/ssl/pk.c +++ b/nettls/ssl/pk.c @@ -304,12 +304,7 @@ int mbedtls_pk_verify_restartable( * Verify a signature */ int mbedtls_pk_verify( - mbedtls_pk_context* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len) + mbedtls_pk_context* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len) { return (mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len, sig, sig_len, NULL)); } @@ -356,8 +351,8 @@ int mbedtls_pk_verify_ext( return (MBEDTLS_ERR_RSA_VERIFY_FAILED); ret = mbedtls_rsa_rsassa_pss_verify_ext( - mbedtls_pk_rsa(*ctx), NULL, NULL, MBEDTLS_RSA_PUBLIC, md_alg, (unsigned int)hash_len, hash, - pss_opts->mgf1_hash_id, pss_opts->expected_salt_len, sig); + mbedtls_pk_rsa(*ctx), NULL, NULL, MBEDTLS_RSA_PUBLIC, md_alg, (unsigned int)hash_len, hash, pss_opts->mgf1_hash_id, + pss_opts->expected_salt_len, sig); if (ret != 0) return (ret); @@ -406,8 +401,7 @@ int mbedtls_pk_sign_restartable( if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) return (ret); - ret = - ctx->pk_info->sign_rs_func(ctx->pk_ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, rs_ctx->rs_ctx); + ret = ctx->pk_info->sign_rs_func(ctx->pk_ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, rs_ctx->rs_ctx); if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) mbedtls_pk_restart_free(rs_ctx); diff --git a/nettls/ssl/pk_wrap.c b/nettls/ssl/pk_wrap.c index 94b7c1f92afd7cf3e1ed7f699fb5f3dee6f42e2f..f4b940cd5c80d54e54b63c082e50cf3414eeb1e2 100644 --- a/nettls/ssl/pk_wrap.c +++ b/nettls/ssl/pk_wrap.c @@ -93,13 +93,7 @@ static size_t rsa_get_bitlen(const void* ctx) return (8 * mbedtls_rsa_get_len(rsa)); } -static int rsa_verify_wrap( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len) +static int rsa_verify_wrap(void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len) { int ret; mbedtls_rsa_context* rsa = (mbedtls_rsa_context*)ctx; @@ -113,8 +107,7 @@ static int rsa_verify_wrap( if (sig_len < rsa_len) return (MBEDTLS_ERR_RSA_VERIFY_FAILED); - if ((ret = mbedtls_rsa_pkcs1_verify(rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, md_alg, (unsigned int)hash_len, hash, sig)) - != 0) + if ((ret = mbedtls_rsa_pkcs1_verify(rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, md_alg, (unsigned int)hash_len, hash, sig)) != 0) return (ret); /* The buffer contains a valid signature followed by extra data. @@ -261,13 +254,8 @@ static size_t eckey_get_bitlen(const void* ctx) #if defined(MBEDTLS_ECDSA_C) /* Forward declarations */ -static int ecdsa_verify_wrap( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len); +static int + ecdsa_verify_wrap(void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len); static int ecdsa_sign_wrap( void* ctx, @@ -279,13 +267,8 @@ static int ecdsa_sign_wrap( int (*f_rng)(void*, unsigned char*, size_t), void* p_rng); -static int eckey_verify_wrap( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len) +static int + eckey_verify_wrap(void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len) { int ret; mbedtls_ecdsa_context ecdsa; @@ -326,13 +309,7 @@ static int eckey_sign_wrap( #if defined(MBEDTLS_ECP_RESTARTABLE) /* Forward declarations */ static int ecdsa_verify_rs_wrap( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len, - void* rs_ctx); + void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len, void* rs_ctx); static int ecdsa_sign_rs_wrap( void* ctx, @@ -386,13 +363,7 @@ static void eckey_rs_free(void* ctx) } static int eckey_verify_rs_wrap( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len, - void* rs_ctx) + void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len, void* rs_ctx) { int ret; eckey_restart_ctx* rs = rs_ctx; @@ -433,8 +404,7 @@ static int eckey_sign_rs_wrap( if (rs->ecdsa_ctx.grp.pbits == 0) MBEDTLS_MPI_CHK(mbedtls_ecdsa_from_keypair(&rs->ecdsa_ctx, ctx)); - MBEDTLS_MPI_CHK( - ecdsa_sign_rs_wrap(&rs->ecdsa_ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, &rs->ecdsa_rs)); + MBEDTLS_MPI_CHK(ecdsa_sign_rs_wrap(&rs->ecdsa_ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, &rs->ecdsa_rs)); cleanup: return (ret); @@ -536,13 +506,8 @@ static int ecdsa_can_do(mbedtls_pk_type_t type) return (type == MBEDTLS_PK_ECDSA); } -static int ecdsa_verify_wrap( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len) +static int + ecdsa_verify_wrap(void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len) { int ret; ((void)md_alg); @@ -565,25 +530,17 @@ static int ecdsa_sign_wrap( int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { - return ( - mbedtls_ecdsa_write_signature((mbedtls_ecdsa_context*)ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng)); + return (mbedtls_ecdsa_write_signature((mbedtls_ecdsa_context*)ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng)); } #if defined(MBEDTLS_ECP_RESTARTABLE) static int ecdsa_verify_rs_wrap( - void* ctx, - mbedtls_md_type_t md_alg, - const unsigned char* hash, - size_t hash_len, - const unsigned char* sig, - size_t sig_len, - void* rs_ctx) + void* ctx, mbedtls_md_type_t md_alg, const unsigned char* hash, size_t hash_len, const unsigned char* sig, size_t sig_len, void* rs_ctx) { int ret; ((void)md_alg); - ret = mbedtls_ecdsa_read_signature_restartable( - (mbedtls_ecdsa_context*)ctx, hash, hash_len, sig, sig_len, (mbedtls_ecdsa_restart_ctx*)rs_ctx); + ret = mbedtls_ecdsa_read_signature_restartable((mbedtls_ecdsa_context*)ctx, hash, hash_len, sig, sig_len, (mbedtls_ecdsa_restart_ctx*)rs_ctx); if (ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) return (MBEDTLS_ERR_PK_SIG_LEN_MISMATCH); @@ -603,8 +560,7 @@ static int ecdsa_sign_rs_wrap( void* rs_ctx) { return (mbedtls_ecdsa_write_signature_restartable( - (mbedtls_ecdsa_context*)ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, - (mbedtls_ecdsa_restart_ctx*)rs_ctx)); + (mbedtls_ecdsa_context*)ctx, md_alg, hash, hash_len, sig, sig_len, f_rng, p_rng, (mbedtls_ecdsa_restart_ctx*)rs_ctx)); } #endif /* MBEDTLS_ECP_RESTARTABLE */ @@ -702,8 +658,7 @@ static int rsa_alt_sign_wrap( *sig_len = rsa_alt->key_len_func(rsa_alt->key); - return ( - rsa_alt->sign_func(rsa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, md_alg, (unsigned int)hash_len, hash, sig)); + return (rsa_alt->sign_func(rsa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE, md_alg, (unsigned int)hash_len, hash, sig)); } static int rsa_alt_decrypt_wrap( diff --git a/nettls/ssl/pkcs11.c b/nettls/ssl/pkcs11.c index 8b49729cf7d3c7a692f7f4cf5104c6a33409fff5..34c10359da70be1589c6a64e198b2b500291715d 100644 --- a/nettls/ssl/pkcs11.c +++ b/nettls/ssl/pkcs11.c @@ -143,12 +143,7 @@ void mbedtls_pkcs11_priv_key_free(mbedtls_pkcs11_context* priv_key) } int mbedtls_pkcs11_decrypt( - mbedtls_pkcs11_context* ctx, - int mode, - size_t* olen, - const unsigned char* input, - unsigned char* output, - size_t output_max_len) + mbedtls_pkcs11_context* ctx, int mode, size_t* olen, const unsigned char* input, unsigned char* output, size_t output_max_len) { size_t input_len, output_len; @@ -164,16 +159,14 @@ int mbedtls_pkcs11_decrypt( return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); /* Determine size of output buffer */ - if (pkcs11h_certificate_decryptAny(ctx->pkcs11h_cert, CKM_RSA_PKCS, input, input_len, NULL, &output_len) - != CKR_OK) { + if (pkcs11h_certificate_decryptAny(ctx->pkcs11h_cert, CKM_RSA_PKCS, input, input_len, NULL, &output_len) != CKR_OK) { return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); } if (output_len > output_max_len) return (MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE); - if (pkcs11h_certificate_decryptAny(ctx->pkcs11h_cert, CKM_RSA_PKCS, input, input_len, output, &output_len) - != CKR_OK) { + if (pkcs11h_certificate_decryptAny(ctx->pkcs11h_cert, CKM_RSA_PKCS, input, input_len, output, &output_len) != CKR_OK) { return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); } *olen = output_len; @@ -181,12 +174,7 @@ int mbedtls_pkcs11_decrypt( } int mbedtls_pkcs11_sign( - mbedtls_pkcs11_context* ctx, - int mode, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char* hash, - unsigned char* sig) + mbedtls_pkcs11_context* ctx, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char* hash, unsigned char* sig) { size_t sig_len = 0, asn_len = 0, oid_size = 0; unsigned char* p = sig; diff --git a/nettls/ssl/pkcs12.c b/nettls/ssl/pkcs12.c index 7622a038a21d682af1e8b7d0c0f1877b341022e8..d55211f4cf36ec14d3b0226220abfb8f188ea79c 100644 --- a/nettls/ssl/pkcs12.c +++ b/nettls/ssl/pkcs12.c @@ -135,8 +135,7 @@ static int pkcs12_pbe_derive_key_iv( for (i = 0; i < pwdlen; i++) unipwd[i * 2 + 1] = pwd[i]; - if ((ret = mbedtls_pkcs12_derivation( - key, keylen, unipwd, pwdlen * 2 + 2, salt.p, salt.len, md_type, MBEDTLS_PKCS12_DERIVE_KEY, iterations)) + if ((ret = mbedtls_pkcs12_derivation(key, keylen, unipwd, pwdlen * 2 + 2, salt.p, salt.len, md_type, MBEDTLS_PKCS12_DERIVE_KEY, iterations)) != 0) { return (ret); } @@ -144,9 +143,7 @@ static int pkcs12_pbe_derive_key_iv( if (iv == NULL || ivlen == 0) return (0); - if ((ret = mbedtls_pkcs12_derivation( - iv, ivlen, unipwd, pwdlen * 2 + 2, salt.p, salt.len, md_type, MBEDTLS_PKCS12_DERIVE_IV, iterations)) - != 0) { + if ((ret = mbedtls_pkcs12_derivation(iv, ivlen, unipwd, pwdlen * 2 + 2, salt.p, salt.len, md_type, MBEDTLS_PKCS12_DERIVE_IV, iterations)) != 0) { return (ret); } return (0); @@ -155,13 +152,7 @@ static int pkcs12_pbe_derive_key_iv( #undef PKCS12_MAX_PWDLEN int mbedtls_pkcs12_pbe_sha1_rc4_128( - mbedtls_asn1_buf* pbe_params, - int mode, - const unsigned char* pwd, - size_t pwdlen, - const unsigned char* data, - size_t len, - unsigned char* output) + mbedtls_asn1_buf* pbe_params, int mode, const unsigned char* pwd, size_t pwdlen, const unsigned char* data, size_t len, unsigned char* output) { #if !defined(MBEDTLS_ARC4_C) ((void)pbe_params); @@ -220,8 +211,7 @@ int mbedtls_pkcs12_pbe( keylen = cipher_info->key_bitlen / 8; - if ((ret = pkcs12_pbe_derive_key_iv(pbe_params, md_type, pwd, pwdlen, key, keylen, iv, cipher_info->iv_size)) - != 0) { + if ((ret = pkcs12_pbe_derive_key_iv(pbe_params, md_type, pwd, pwdlen, key, keylen, iv, cipher_info->iv_size)) != 0) { return (ret); } diff --git a/nettls/ssl/pkcs5.c b/nettls/ssl/pkcs5.c index 368827c1ff4ac2f4f1d3cc1ee871b85050a728ec..121f0d4eefc5299e834459f759c7a6bd137cafd0 100644 --- a/nettls/ssl/pkcs5.c +++ b/nettls/ssl/pkcs5.c @@ -80,8 +80,7 @@ #endif #if defined(MBEDTLS_ASN1_PARSE_C) -static int pkcs5_parse_pbkdf2_params( - const mbedtls_asn1_buf* params, mbedtls_asn1_buf* salt, int* iterations, int* keylen, mbedtls_md_type_t* md_type) +static int pkcs5_parse_pbkdf2_params(const mbedtls_asn1_buf* params, mbedtls_asn1_buf* salt, int* iterations, int* keylen, mbedtls_md_type_t* md_type) { int ret; mbedtls_asn1_buf prf_alg_oid; @@ -343,15 +342,12 @@ static const uint32_t it_cnt[MAX_TESTS] = {1, 2, 4096, 4096, 4096}; static const uint32_t key_len[MAX_TESTS] = {20, 20, 20, 25, 16}; static const unsigned char result_key[MAX_TESTS][32] = { - {0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, 0xf3, 0xa9, - 0xb5, 0x24, 0xaf, 0x60, 0x12,0x06, 0x2f, 0xe0, 0x37, 0xa6}, - {0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, - 0xd9, 0x2a, 0xce, 0x1d, 0x41,0xf0,0xd8, 0xde, 0x89, 0x57}, - {0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, 0xbe, 0xad, - 0x49, 0xd9, 0x26, 0xf7, 0x21,0xd0,0x65, 0xa4, 0x29, 0xc1}, - {0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b, 0x80, 0xc8, 0xd8, 0x36,0x62, - 0xc0,0xe4,0x4a,0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70, 0x38}, - {0x56, 0xfa, 0x6a, 0xa7, 0x55,0x48,0x09,0x9d,0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3 }, + {0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06, 0x2f, 0xe0, 0x37, 0xa6}, + {0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0, 0xd8, 0xde, 0x89, 0x57}, + {0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, 0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0, 0x65, 0xa4, 0x29, 0xc1}, + {0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b, 0x80, 0xc8, 0xd8, 0x36, 0x62, + 0xc0, 0xe4, 0x4a, 0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70, 0x38}, + {0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d, 0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3}, }; int mbedtls_pkcs5_self_test(int verbose) diff --git a/nettls/ssl/pkparse.c b/nettls/ssl/pkparse.c index 9ae17f7ccf9fd5399ed7b743f9c4f750176c161d..5952a534f38b5a07a36bbb21e5d6decc656858cd 100644 --- a/nettls/ssl/pkparse.c +++ b/nettls/ssl/pkparse.c @@ -290,8 +290,7 @@ static int pk_group_from_specified(const mbedtls_asn1_buf* params, mbedtls_ecp_g if ((ret = mbedtls_asn1_get_tag(&p, end_field, &len, MBEDTLS_ASN1_OID)) != 0) return (ret); - if (len != MBEDTLS_OID_SIZE(MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD) - || memcmp(p, MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD, len) != 0) { + if (len != MBEDTLS_OID_SIZE(MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD) || memcmp(p, MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD, len) != 0) { return (MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE); } @@ -324,15 +323,13 @@ static int pk_group_from_specified(const mbedtls_asn1_buf* params, mbedtls_ecp_g * FieldElement ::= OCTET STRING * containing an integer in the case of a prime field */ - if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 - || (ret = mbedtls_mpi_read_binary(&grp->A, p, len)) != 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 || (ret = mbedtls_mpi_read_binary(&grp->A, p, len)) != 0) { return (MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret); } p += len; - if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 - || (ret = mbedtls_mpi_read_binary(&grp->B, p, len)) != 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 || (ret = mbedtls_mpi_read_binary(&grp->B, p, len)) != 0) { return (MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret); } @@ -356,9 +353,9 @@ static int pk_group_from_specified(const mbedtls_asn1_buf* params, mbedtls_ecp_g * If we can't read the point because it's compressed, cheat by * reading only the X coordinate and the parity bit of Y. */ - if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE || (p[0] != 0x02 && p[0] != 0x03) - || len != mbedtls_mpi_size(&grp->P) + 1 || mbedtls_mpi_read_binary(&grp->G.X, p + 1, len - 1) != 0 - || mbedtls_mpi_lset(&grp->G.Y, p[0] - 2) != 0 || mbedtls_mpi_lset(&grp->G.Z, 1) != 0) { + if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE || (p[0] != 0x02 && p[0] != 0x03) || len != mbedtls_mpi_size(&grp->P) + 1 + || mbedtls_mpi_read_binary(&grp->G.X, p + 1, len - 1) != 0 || mbedtls_mpi_lset(&grp->G.Y, p[0] - 2) != 0 + || mbedtls_mpi_lset(&grp->G.Z, 1) != 0) { return (MBEDTLS_ERR_PK_KEY_INVALID_FORMAT); } } @@ -399,9 +396,8 @@ static int pk_group_id_from_group(const mbedtls_ecp_group* grp, mbedtls_ecp_grou /* Compare to the group we were given, starting with easy tests */ if (grp->pbits == ref.pbits && grp->nbits == ref.nbits && mbedtls_mpi_cmp_mpi(&grp->P, &ref.P) == 0 - && mbedtls_mpi_cmp_mpi(&grp->A, &ref.A) == 0 && mbedtls_mpi_cmp_mpi(&grp->B, &ref.B) == 0 - && mbedtls_mpi_cmp_mpi(&grp->N, &ref.N) == 0 && mbedtls_mpi_cmp_mpi(&grp->G.X, &ref.G.X) == 0 - && mbedtls_mpi_cmp_mpi(&grp->G.Z, &ref.G.Z) == 0 && + && mbedtls_mpi_cmp_mpi(&grp->A, &ref.A) == 0 && mbedtls_mpi_cmp_mpi(&grp->B, &ref.B) == 0 && mbedtls_mpi_cmp_mpi(&grp->N, &ref.N) == 0 + && mbedtls_mpi_cmp_mpi(&grp->G.X, &ref.G.X) == 0 && mbedtls_mpi_cmp_mpi(&grp->G.Z, &ref.G.Z) == 0 && /* For Y we may only know the parity bit, so compare only that */ mbedtls_mpi_get_bit(&grp->G.Y, 0) == mbedtls_mpi_get_bit(&ref.G.Y, 0)) { break; @@ -555,8 +551,7 @@ static int pk_get_rsapubkey(unsigned char** p, const unsigned char* end, mbedtls * algorithm OBJECT IDENTIFIER, * parameters ANY DEFINED BY algorithm OPTIONAL } */ -static int - pk_get_pk_alg(unsigned char** p, const unsigned char* end, mbedtls_pk_type_t* pk_alg, mbedtls_asn1_buf* params) +static int pk_get_pk_alg(unsigned char** p, const unsigned char* end, mbedtls_pk_type_t* pk_alg, mbedtls_asn1_buf* params) { int ret; mbedtls_asn1_buf alg_oid; @@ -712,28 +707,23 @@ static int pk_parse_key_pkcs1_der(mbedtls_rsa_context* rsa, const unsigned char* } /* Import N */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 - || (ret = mbedtls_rsa_import(rsa, &T, NULL, NULL, NULL, NULL)) != 0) + if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || (ret = mbedtls_rsa_import(rsa, &T, NULL, NULL, NULL, NULL)) != 0) goto cleanup; /* Import E */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 - || (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, NULL, &T)) != 0) + if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, NULL, &T)) != 0) goto cleanup; /* Import D */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 - || (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, &T, NULL)) != 0) + if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, &T, NULL)) != 0) goto cleanup; /* Import P */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 - || (ret = mbedtls_rsa_import(rsa, NULL, &T, NULL, NULL, NULL)) != 0) + if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || (ret = mbedtls_rsa_import(rsa, NULL, &T, NULL, NULL, NULL)) != 0) goto cleanup; /* Import Q */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 - || (ret = mbedtls_rsa_import(rsa, NULL, NULL, &T, NULL, NULL)) != 0) + if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || (ret = mbedtls_rsa_import(rsa, NULL, NULL, &T, NULL, NULL)) != 0) goto cleanup; #if !defined(MBEDTLS_RSA_NO_CRT) && !defined(MBEDTLS_RSA_ALT) @@ -853,10 +843,8 @@ static int pk_parse_key_sec1_der(mbedtls_ecp_keypair* eck, const unsigned char* /* * Is 'parameters' present? */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)) - == 0) { - if ((ret = pk_get_ecparams(&p, p + len, ¶ms)) != 0 - || (ret = pk_use_ecparams(¶ms, &eck->grp)) != 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)) == 0) { + if ((ret = pk_get_ecparams(&p, p + len, ¶ms)) != 0 || (ret = pk_use_ecparams(¶ms, &eck->grp)) != 0) { mbedtls_ecp_keypair_free(eck); return (ret); } @@ -871,8 +859,7 @@ static int pk_parse_key_sec1_der(mbedtls_ecp_keypair* eck, const unsigned char* * Is 'publickey' present? If not, or if we can't read it (eg because it * is compressed), create it from the private key. */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 1)) - == 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 1)) == 0) { end2 = p + len; if ((ret = mbedtls_asn1_get_bitstring_null(&p, end2, &len)) != 0) @@ -987,8 +974,7 @@ static int pk_parse_key_pkcs8_unencrypted_der(mbedtls_pk_context* pk, const unsi #endif /* MBEDTLS_RSA_C */ #if defined(MBEDTLS_ECP_C) if (pk_alg == MBEDTLS_PK_ECKEY || pk_alg == MBEDTLS_PK_ECKEY_DH) { - if ((ret = pk_use_ecparams(¶ms, &mbedtls_pk_ec(*pk)->grp)) != 0 - || (ret = pk_parse_key_sec1_der(mbedtls_pk_ec(*pk), p, len)) != 0) { + if ((ret = pk_use_ecparams(¶ms, &mbedtls_pk_ec(*pk)->grp)) != 0 || (ret = pk_parse_key_sec1_der(mbedtls_pk_ec(*pk), p, len)) != 0) { mbedtls_pk_free(pk); return (ret); } @@ -1009,8 +995,7 @@ static int pk_parse_key_pkcs8_unencrypted_der(mbedtls_pk_context* pk, const unsi * */ #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C) -static int pk_parse_key_pkcs8_encrypted_der( - mbedtls_pk_context* pk, unsigned char* key, size_t keylen, const unsigned char* pwd, size_t pwdlen) +static int pk_parse_key_pkcs8_encrypted_der(mbedtls_pk_context* pk, unsigned char* key, size_t keylen, const unsigned char* pwd, size_t pwdlen) { int ret, decrypted = 0; size_t len; @@ -1062,9 +1047,7 @@ static int pk_parse_key_pkcs8_encrypted_der( */ #if defined(MBEDTLS_PKCS12_C) if (mbedtls_oid_get_pkcs12_pbe_alg(&pbe_alg_oid, &md_alg, &cipher_alg) == 0) { - if ((ret = mbedtls_pkcs12_pbe( - &pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, cipher_alg, md_alg, pwd, pwdlen, p, len, buf)) - != 0) { + if ((ret = mbedtls_pkcs12_pbe(&pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, cipher_alg, md_alg, pwd, pwdlen, p, len, buf)) != 0) { if (ret == MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) return (MBEDTLS_ERR_PK_PASSWORD_MISMATCH); @@ -1073,8 +1056,7 @@ static int pk_parse_key_pkcs8_encrypted_der( decrypted = 1; } else if (MBEDTLS_OID_CMP(MBEDTLS_OID_PKCS12_PBE_SHA1_RC4_128, &pbe_alg_oid) == 0) { - if ((ret = mbedtls_pkcs12_pbe_sha1_rc4_128(&pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, pwd, pwdlen, p, len, buf)) - != 0) { + if ((ret = mbedtls_pkcs12_pbe_sha1_rc4_128(&pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, pwd, pwdlen, p, len, buf)) != 0) { return (ret); } @@ -1113,8 +1095,7 @@ static int pk_parse_key_pkcs8_encrypted_der( /* * Parse a private key */ -int mbedtls_pk_parse_key( - mbedtls_pk_context* pk, const unsigned char* key, size_t keylen, const unsigned char* pwd, size_t pwdlen) +int mbedtls_pk_parse_key(mbedtls_pk_context* pk, const unsigned char* key, size_t keylen, const unsigned char* pwd, size_t pwdlen) { int ret; const mbedtls_pk_info_t* pk_info; @@ -1136,13 +1117,11 @@ int mbedtls_pk_parse_key( if (key[keylen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----", key, pwd, pwdlen, &len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----", key, pwd, pwdlen, &len); if (ret == 0) { pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA); - if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 - || (ret = pk_parse_key_pkcs1_der(mbedtls_pk_rsa(*pk), pem.buf, pem.buflen)) != 0) { + if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 || (ret = pk_parse_key_pkcs1_der(mbedtls_pk_rsa(*pk), pem.buf, pem.buflen)) != 0) { mbedtls_pk_free(pk); } @@ -1161,13 +1140,11 @@ int mbedtls_pk_parse_key( if (key[keylen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN EC PRIVATE KEY-----", "-----END EC PRIVATE KEY-----", key, pwd, pwdlen, &len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN EC PRIVATE KEY-----", "-----END EC PRIVATE KEY-----", key, pwd, pwdlen, &len); if (ret == 0) { pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY); - if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 - || (ret = pk_parse_key_sec1_der(mbedtls_pk_ec(*pk), pem.buf, pem.buflen)) != 0) { + if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 || (ret = pk_parse_key_sec1_der(mbedtls_pk_ec(*pk), pem.buf, pem.buflen)) != 0) { mbedtls_pk_free(pk); } @@ -1185,8 +1162,7 @@ int mbedtls_pk_parse_key( if (key[keylen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN PRIVATE KEY-----", "-----END PRIVATE KEY-----", key, NULL, 0, &len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN PRIVATE KEY-----", "-----END PRIVATE KEY-----", key, NULL, 0, &len); if (ret == 0) { if ((ret = pk_parse_key_pkcs8_unencrypted_der(pk, pem.buf, pem.buflen)) != 0) { mbedtls_pk_free(pk); @@ -1202,8 +1178,7 @@ int mbedtls_pk_parse_key( if (key[keylen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN ENCRYPTED PRIVATE KEY-----", "-----END ENCRYPTED PRIVATE KEY-----", key, NULL, 0, &len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN ENCRYPTED PRIVATE KEY-----", "-----END ENCRYPTED PRIVATE KEY-----", key, NULL, 0, &len); if (ret == 0) { if ((ret = pk_parse_key_pkcs8_encrypted_der(pk, pem.buf, pem.buflen, pwd, pwdlen)) != 0) { mbedtls_pk_free(pk); @@ -1317,8 +1292,7 @@ int mbedtls_pk_parse_public_key(mbedtls_pk_context* ctx, const unsigned char* ke if (key[keylen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----", key, NULL, 0, &len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----", key, NULL, 0, &len); if (ret == 0) { p = pem.buf; @@ -1343,8 +1317,7 @@ int mbedtls_pk_parse_public_key(mbedtls_pk_context* ctx, const unsigned char* ke if (key[keylen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = - mbedtls_pem_read_buffer(&pem, "-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", key, NULL, 0, &len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", key, NULL, 0, &len); if (ret == 0) { /* diff --git a/nettls/ssl/pkwrite.c b/nettls/ssl/pkwrite.c index e2ca137500b7c69d1896bbf86ca0a0cf6af95669..8077af826bd4f343e35e27308001763afbdb89f7 100644 --- a/nettls/ssl/pkwrite.c +++ b/nettls/ssl/pkwrite.c @@ -102,14 +102,12 @@ static int pk_write_rsa_pubkey(unsigned char** p, unsigned char* start, mbedtls_ mbedtls_mpi_init(&T); /* Export E */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 - || (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) + if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 || (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) goto end_of_export; len += ret; /* Export N */ - if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 - || (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) + if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 || (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) goto end_of_export; len += ret; @@ -136,8 +134,7 @@ static int pk_write_ec_pubkey(unsigned char** p, unsigned char* start, mbedtls_e size_t len = 0; unsigned char buf[MBEDTLS_ECP_MAX_PT_LEN]; - if ((ret = mbedtls_ecp_point_write_binary(&ec->grp, &ec->Q, MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof(buf))) - != 0) { + if ((ret = mbedtls_ecp_point_write_binary(&ec->grp, &ec->Q, MBEDTLS_ECP_PF_UNCOMPRESSED, &len, buf, sizeof(buf))) != 0) { return (ret); } @@ -303,32 +300,27 @@ int mbedtls_pk_write_key_der(mbedtls_pk_context* key, unsigned char* buf, size_t len += ret; /* Export Q */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, &T, NULL, NULL)) != 0 - || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) + if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, &T, NULL, NULL)) != 0 || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) goto end_of_export; len += ret; /* Export P */ - if ((ret = mbedtls_rsa_export(rsa, NULL, &T, NULL, NULL, NULL)) != 0 - || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) + if ((ret = mbedtls_rsa_export(rsa, NULL, &T, NULL, NULL, NULL)) != 0 || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) goto end_of_export; len += ret; /* Export D */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, &T, NULL)) != 0 - || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) + if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, &T, NULL)) != 0 || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) goto end_of_export; len += ret; /* Export E */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 - || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) + if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) goto end_of_export; len += ret; /* Export N */ - if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 - || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) + if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 || (ret = mbedtls_asn1_write_mpi(&c, buf, &T)) < 0) goto end_of_export; len += ret; @@ -371,16 +363,14 @@ int mbedtls_pk_write_key_der(mbedtls_pk_context* key, unsigned char* buf, size_t MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_BIT_STRING)); MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_asn1_write_len(&c, buf, pub_len)); - MBEDTLS_ASN1_CHK_ADD( - pub_len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 1)); + MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 1)); len += pub_len; /* parameters */ MBEDTLS_ASN1_CHK_ADD(par_len, pk_write_ec_param(&c, buf, ec)); MBEDTLS_ASN1_CHK_ADD(par_len, mbedtls_asn1_write_len(&c, buf, par_len)); - MBEDTLS_ASN1_CHK_ADD( - par_len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)); + MBEDTLS_ASN1_CHK_ADD(par_len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)); len += par_len; /* privateKey */ @@ -484,10 +474,8 @@ int mbedtls_pk_write_key_der(mbedtls_pk_context* key, unsigned char* buf, size_t #endif /* MBEDTLS_ECP_C */ -#define PUB_DER_MAX_BYTES \ - (RSA_PUB_DER_MAX_BYTES > ECP_PUB_DER_MAX_BYTES ? RSA_PUB_DER_MAX_BYTES : ECP_PUB_DER_MAX_BYTES) -#define PRV_DER_MAX_BYTES \ - (RSA_PRV_DER_MAX_BYTES > ECP_PRV_DER_MAX_BYTES ? RSA_PRV_DER_MAX_BYTES : ECP_PRV_DER_MAX_BYTES) +#define PUB_DER_MAX_BYTES (RSA_PUB_DER_MAX_BYTES > ECP_PUB_DER_MAX_BYTES ? RSA_PUB_DER_MAX_BYTES : ECP_PUB_DER_MAX_BYTES) +#define PRV_DER_MAX_BYTES (RSA_PRV_DER_MAX_BYTES > ECP_PRV_DER_MAX_BYTES ? RSA_PRV_DER_MAX_BYTES : ECP_PRV_DER_MAX_BYTES) int mbedtls_pk_write_pubkey_pem(mbedtls_pk_context* key, unsigned char* buf, size_t size) { @@ -502,8 +490,7 @@ int mbedtls_pk_write_pubkey_pem(mbedtls_pk_context* key, unsigned char* buf, siz return (ret); } - if ((ret = mbedtls_pem_write_buffer( - PEM_BEGIN_PUBLIC_KEY, PEM_END_PUBLIC_KEY, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen)) + if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_PUBLIC_KEY, PEM_END_PUBLIC_KEY, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen)) != 0) { return (ret); } @@ -538,8 +525,7 @@ int mbedtls_pk_write_key_pem(mbedtls_pk_context* key, unsigned char* buf, size_t #endif return (MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE); - if ((ret = mbedtls_pem_write_buffer(begin, end, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen)) - != 0) { + if ((ret = mbedtls_pem_write_buffer(begin, end, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen)) != 0) { return (ret); } diff --git a/nettls/ssl/platform.c b/nettls/ssl/platform.c index 7ea7d6910bc4e218622e15c1d32dc921e08336e9..bae99e5131edd2e64b2bb2b35d1046ac6d1e0a55 100644 --- a/nettls/ssl/platform.c +++ b/nettls/ssl/platform.c @@ -59,8 +59,7 @@ * MBEDTLS_PLATFORM_{FREE/CALLOC}_MACRO takes precedence over the runtime * configuration via mbedtls_platform_set_calloc_free(). So, omit everything * related to the latter if MBEDTLS_PLATFORM_{FREE/CALLOC}_MACRO are defined. */ -#if defined(MBEDTLS_PLATFORM_MEMORY) \ - && !(defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && defined(MBEDTLS_PLATFORM_FREE_MACRO)) +#if defined(MBEDTLS_PLATFORM_MEMORY) && !(defined(MBEDTLS_PLATFORM_CALLOC_MACRO) && defined(MBEDTLS_PLATFORM_FREE_MACRO)) #if !defined(MBEDTLS_PLATFORM_STD_CALLOC) static void* platform_calloc_uninit(size_t n, size_t size) diff --git a/nettls/ssl/platform_util.c b/nettls/ssl/platform_util.c index b795998311f2137145da73defd1196d4abfe90d6..7a82134366ee99ca2e82aefab92298019a38dd5a 100644 --- a/nettls/ssl/platform_util.c +++ b/nettls/ssl/platform_util.c @@ -106,15 +106,12 @@ void mbedtls_platform_zeroize(void* buf, size_t len) #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT) #include -#if !defined(_WIN32) \ - && (defined(unix) || defined(__unix) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))) +#if !defined(_WIN32) && (defined(unix) || defined(__unix) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))) #include #endif /* !_WIN32 && (unix || __unix || __unix__ || \ * (__APPLE__ && __MACH__)) */ -#if !( \ - (defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L) \ - || (defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_THREAD_SAFE_FUNCTIONS >= 200112L)) +#if !((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L) || (defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_THREAD_SAFE_FUNCTIONS >= 200112L)) /* * This is a convenience shorthand macro to avoid checking the long * preprocessor conditions above. Ideally, we could expose this macro in diff --git a/nettls/ssl/poly1305.c b/nettls/ssl/poly1305.c index 527a91150e4254c019261be4e152831a4d057a23..0f6cd055addcb86e33ce17f3f0108552da2bf5d6 100644 --- a/nettls/ssl/poly1305.c +++ b/nettls/ssl/poly1305.c @@ -80,8 +80,8 @@ #define POLY1305_BLOCK_SIZE_BYTES (16U) #define BYTES_TO_U32_LE(data, offset) \ - ((uint32_t)(data)[offset] | (uint32_t)((uint32_t)(data)[(offset) + 1] << 8) \ - | (uint32_t)((uint32_t)(data)[(offset) + 2] << 16) | (uint32_t)((uint32_t)(data)[(offset) + 3] << 24)) + ((uint32_t)(data)[offset] | (uint32_t)((uint32_t)(data)[(offset) + 1] << 8) | (uint32_t)((uint32_t)(data)[(offset) + 2] << 16) \ + | (uint32_t)((uint32_t)(data)[(offset) + 3] << 24)) /* * Our implementation is tuned for 32-bit platforms with a 64-bit multiplier. @@ -121,8 +121,7 @@ static inline uint64_t mul64(uint32_t a, uint32_t b) * applied to the input data before calling this * function. Otherwise, set this parameter to 1. */ -static void - poly1305_process(mbedtls_poly1305_context* ctx, size_t nblocks, const unsigned char* input, uint32_t needs_padding) +static void poly1305_process(mbedtls_poly1305_context* ctx, size_t nblocks, const unsigned char* input, uint32_t needs_padding) { uint64_t d0, d1, d2, d3; uint32_t acc0, acc1, acc2, acc3, acc4; @@ -437,15 +436,14 @@ static const unsigned char test_keys[2][32] = { }; static const unsigned char test_data[2][127] = { - {0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x46, 0x6f, 0x72, - 0x75, 0x6d, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f, 0x75, 0x70}, - { 0x27, 0x54, 0x77, 0x61, 0x73, 0x20, 0x62, 0x72, 0x69, 0x6c, 0x6c, 0x69, 0x67, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x73, 0x6c, 0x69, 0x74, 0x68, 0x79, 0x20, 0x74, 0x6f, 0x76, 0x65, 0x73, 0x0a, 0x44, 0x69, - 0x64, 0x20, 0x67, 0x79, 0x72, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x67, 0x69, 0x6d, 0x62, 0x6c, 0x65, 0x20, 0x69, - 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x61, 0x62, 0x65, 0x3a, 0x0a, 0x41, 0x6c, 0x6c, 0x20, 0x6d, 0x69, 0x6d, - 0x73, 0x79, 0x20, 0x77, 0x65, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x6f, 0x72, 0x6f, 0x67, 0x6f, 0x76, - 0x65, 0x73, 0x2c, 0x0a, 0x41, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6d, 0x6f, 0x6d, 0x65, 0x20, 0x72, 0x61, - 0x74, 0x68, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x67, 0x72, 0x61, 0x62, 0x65, 0x2e} + {0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x20, 0x46, 0x6f, 0x72, + 0x75, 0x6d, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6f, 0x75, 0x70}, + {0x27, 0x54, 0x77, 0x61, 0x73, 0x20, 0x62, 0x72, 0x69, 0x6c, 0x6c, 0x69, 0x67, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, + 0x20, 0x73, 0x6c, 0x69, 0x74, 0x68, 0x79, 0x20, 0x74, 0x6f, 0x76, 0x65, 0x73, 0x0a, 0x44, 0x69, 0x64, 0x20, 0x67, 0x79, 0x72, 0x65, + 0x20, 0x61, 0x6e, 0x64, 0x20, 0x67, 0x69, 0x6d, 0x62, 0x6c, 0x65, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x77, 0x61, 0x62, + 0x65, 0x3a, 0x0a, 0x41, 0x6c, 0x6c, 0x20, 0x6d, 0x69, 0x6d, 0x73, 0x79, 0x20, 0x77, 0x65, 0x72, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, + 0x62, 0x6f, 0x72, 0x6f, 0x67, 0x6f, 0x76, 0x65, 0x73, 0x2c, 0x0a, 0x41, 0x6e, 0x64, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6d, 0x6f, 0x6d, + 0x65, 0x20, 0x72, 0x61, 0x74, 0x68, 0x73, 0x20, 0x6f, 0x75, 0x74, 0x67, 0x72, 0x61, 0x62, 0x65, 0x2e} }; static const size_t test_data_len[2] = {34U, 127U}; diff --git a/nettls/ssl/ripemd160.c b/nettls/ssl/ripemd160.c index 05fe353a94c2194a88580cbfd4d067f19580ac57..d4444f4cc762c5c86fcc8e54571623bd6cae05ba 100644 --- a/nettls/ssl/ripemd160.c +++ b/nettls/ssl/ripemd160.c @@ -80,8 +80,7 @@ #ifndef GET_UINT32_LE #define GET_UINT32_LE(n, b, i) \ { \ - (n) = ((uint32_t)(b)[(i)]) | ((uint32_t)(b)[(i) + 1] << 8) | ((uint32_t)(b)[(i) + 2] << 16) \ - | ((uint32_t)(b)[(i) + 3] << 24); \ + (n) = ((uint32_t)(b)[(i)]) | ((uint32_t)(b)[(i) + 1] << 8) | ((uint32_t)(b)[(i) + 2] << 16) | ((uint32_t)(b)[(i) + 3] << 24); \ } #endif @@ -493,22 +492,14 @@ static const unsigned char ripemd160_test_str[TESTS][81] = { static const size_t ripemd160_test_strlen[TESTS] = {0, 1, 3, 14, 26, 56, 62, 80}; static const unsigned char ripemd160_test_md[TESTS][20] = { - {0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, 0x61, 0x28, - 0x08, 0x97, 0x7e, 0xe8, 0xf5, 0x48, 0xb2, 0x25, 0x8d, 0x31}, - {0x0b, 0xdc, 0x9d, 0x2d, 0x25, 0x6b, 0x3e, 0xe9, 0xda, 0xae, - 0x34, 0x7b, 0xe6, 0xf4, 0xdc, 0x83, 0x5a, 0x46, 0x7f, 0xfe}, - {0x8e, 0xb2, 0x08, 0xf7, 0xe0, 0x5d, 0x98, 0x7a, 0x9b, 0x04, - 0x4a, 0x8e, 0x98, 0xc6, 0xb0, 0x87, 0xf1, 0x5a, 0x0b, 0xfc}, - {0x5d, 0x06, 0x89, 0xef, 0x49, 0xd2, 0xfa, 0xe5, 0x72, 0xb8, - 0x81, 0xb1, 0x23, 0xa8, 0x5f, 0xfa, 0x21, 0x59, 0x5f, 0x36}, - {0xf7, 0x1c, 0x27, 0x10, 0x9c, 0x69, 0x2c, 0x1b, 0x56, 0xbb, - 0xdc, 0xeb, 0x5b, 0x9d, 0x28, 0x65, 0xb3, 0x70, 0x8d, 0xbc}, - {0x12, 0xa0, 0x53, 0x38, 0x4a, 0x9c, 0x0c, 0x88, 0xe4, 0x05, - 0xa0, 0x6c, 0x27, 0xdc, 0xf4, 0x9a, 0xda, 0x62, 0xeb, 0x2b}, - {0xb0, 0xe2, 0x0b, 0x6e, 0x31, 0x16, 0x64, 0x02, 0x86, 0xed, - 0x3a, 0x87, 0xa5, 0x71, 0x30, 0x79, 0xb2, 0x1f, 0x51, 0x89}, - {0x9b, 0x75, 0x2e, 0x45, 0x57, 0x3d, 0x4b, 0x39, 0xf4, 0xdb, - 0xd3, 0x32, 0x3c, 0xab, 0x82, 0xbf, 0x63, 0x32, 0x6b, 0xfb}, + {0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, 0x61, 0x28, 0x08, 0x97, 0x7e, 0xe8, 0xf5, 0x48, 0xb2, 0x25, 0x8d, 0x31}, + {0x0b, 0xdc, 0x9d, 0x2d, 0x25, 0x6b, 0x3e, 0xe9, 0xda, 0xae, 0x34, 0x7b, 0xe6, 0xf4, 0xdc, 0x83, 0x5a, 0x46, 0x7f, 0xfe}, + {0x8e, 0xb2, 0x08, 0xf7, 0xe0, 0x5d, 0x98, 0x7a, 0x9b, 0x04, 0x4a, 0x8e, 0x98, 0xc6, 0xb0, 0x87, 0xf1, 0x5a, 0x0b, 0xfc}, + {0x5d, 0x06, 0x89, 0xef, 0x49, 0xd2, 0xfa, 0xe5, 0x72, 0xb8, 0x81, 0xb1, 0x23, 0xa8, 0x5f, 0xfa, 0x21, 0x59, 0x5f, 0x36}, + {0xf7, 0x1c, 0x27, 0x10, 0x9c, 0x69, 0x2c, 0x1b, 0x56, 0xbb, 0xdc, 0xeb, 0x5b, 0x9d, 0x28, 0x65, 0xb3, 0x70, 0x8d, 0xbc}, + {0x12, 0xa0, 0x53, 0x38, 0x4a, 0x9c, 0x0c, 0x88, 0xe4, 0x05, 0xa0, 0x6c, 0x27, 0xdc, 0xf4, 0x9a, 0xda, 0x62, 0xeb, 0x2b}, + {0xb0, 0xe2, 0x0b, 0x6e, 0x31, 0x16, 0x64, 0x02, 0x86, 0xed, 0x3a, 0x87, 0xa5, 0x71, 0x30, 0x79, 0xb2, 0x1f, 0x51, 0x89}, + {0x9b, 0x75, 0x2e, 0x45, 0x57, 0x3d, 0x4b, 0x39, 0xf4, 0xdb, 0xd3, 0x32, 0x3c, 0xab, 0x82, 0xbf, 0x63, 0x32, 0x6b, 0xfb}, }; /* diff --git a/nettls/ssl/rsa.c b/nettls/ssl/rsa.c index f256acba3be257ebd7dca9207ffc5f37c1b9bbfc..b8a235a12da3abacb02299b68856d6be3b19aaa2 100644 --- a/nettls/ssl/rsa.c +++ b/nettls/ssl/rsa.c @@ -117,20 +117,13 @@ static inline int mbedtls_safer_memcmp(const void* a, const void* b, size_t n) #endif /* MBEDTLS_PKCS1_V15 */ int mbedtls_rsa_import( - mbedtls_rsa_context* ctx, - const mbedtls_mpi* N, - const mbedtls_mpi* P, - const mbedtls_mpi* Q, - const mbedtls_mpi* D, - const mbedtls_mpi* E) + mbedtls_rsa_context* ctx, const mbedtls_mpi* N, const mbedtls_mpi* P, const mbedtls_mpi* Q, const mbedtls_mpi* D, const mbedtls_mpi* E) { int ret; RSA_VALIDATE_RET(ctx != NULL); - if ((N != NULL && (ret = mbedtls_mpi_copy(&ctx->N, N)) != 0) - || (P != NULL && (ret = mbedtls_mpi_copy(&ctx->P, P)) != 0) - || (Q != NULL && (ret = mbedtls_mpi_copy(&ctx->Q, Q)) != 0) - || (D != NULL && (ret = mbedtls_mpi_copy(&ctx->D, D)) != 0) + if ((N != NULL && (ret = mbedtls_mpi_copy(&ctx->N, N)) != 0) || (P != NULL && (ret = mbedtls_mpi_copy(&ctx->P, P)) != 0) + || (Q != NULL && (ret = mbedtls_mpi_copy(&ctx->Q, Q)) != 0) || (D != NULL && (ret = mbedtls_mpi_copy(&ctx->D, D)) != 0) || (E != NULL && (ret = mbedtls_mpi_copy(&ctx->E, E)) != 0)) { return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret); } @@ -214,8 +207,8 @@ static int rsa_check_context(mbedtls_rsa_context const* ctx, int is_priv, int bl * used for private key operations and if CRT * is used. */ if (is_priv - && (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 || mbedtls_mpi_get_bit(&ctx->P, 0) == 0 - || mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0 || mbedtls_mpi_get_bit(&ctx->Q, 0) == 0)) { + && (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 || mbedtls_mpi_get_bit(&ctx->P, 0) == 0 || mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0 + || mbedtls_mpi_get_bit(&ctx->Q, 0) == 0)) { return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); } #endif /* !MBEDTLS_RSA_NO_CRT */ @@ -368,9 +361,8 @@ int mbedtls_rsa_export_raw( RSA_VALIDATE_RET(ctx != NULL); /* Check if key is private or public */ - is_priv = mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 - && mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 - && mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; + is_priv = mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 + && mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; if (!is_priv) { /* If we're trying to export private parameters for a public key, @@ -399,17 +391,15 @@ cleanup: return (ret); } -int mbedtls_rsa_export( - const mbedtls_rsa_context* ctx, mbedtls_mpi* N, mbedtls_mpi* P, mbedtls_mpi* Q, mbedtls_mpi* D, mbedtls_mpi* E) +int mbedtls_rsa_export(const mbedtls_rsa_context* ctx, mbedtls_mpi* N, mbedtls_mpi* P, mbedtls_mpi* Q, mbedtls_mpi* D, mbedtls_mpi* E) { int ret; int is_priv; RSA_VALIDATE_RET(ctx != NULL); /* Check if key is private or public */ - is_priv = mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 - && mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 - && mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; + is_priv = mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 + && mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; if (!is_priv) { /* If we're trying to export private parameters for a public key, @@ -420,10 +410,8 @@ int mbedtls_rsa_export( /* Export all requested core parameters. */ - if ((N != NULL && (ret = mbedtls_mpi_copy(N, &ctx->N)) != 0) - || (P != NULL && (ret = mbedtls_mpi_copy(P, &ctx->P)) != 0) - || (Q != NULL && (ret = mbedtls_mpi_copy(Q, &ctx->Q)) != 0) - || (D != NULL && (ret = mbedtls_mpi_copy(D, &ctx->D)) != 0) + if ((N != NULL && (ret = mbedtls_mpi_copy(N, &ctx->N)) != 0) || (P != NULL && (ret = mbedtls_mpi_copy(P, &ctx->P)) != 0) + || (Q != NULL && (ret = mbedtls_mpi_copy(Q, &ctx->Q)) != 0) || (D != NULL && (ret = mbedtls_mpi_copy(D, &ctx->D)) != 0) || (E != NULL && (ret = mbedtls_mpi_copy(E, &ctx->E)) != 0)) { return (ret); } @@ -444,17 +432,15 @@ int mbedtls_rsa_export_crt(const mbedtls_rsa_context* ctx, mbedtls_mpi* DP, mbed RSA_VALIDATE_RET(ctx != NULL); /* Check if key is private or public */ - is_priv = mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 - && mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 - && mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; + is_priv = mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 + && mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 && mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; if (!is_priv) return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); #if !defined(MBEDTLS_RSA_NO_CRT) /* Export all requested blinding parameters. */ - if ((DP != NULL && (ret = mbedtls_mpi_copy(DP, &ctx->DP)) != 0) - || (DQ != NULL && (ret = mbedtls_mpi_copy(DQ, &ctx->DQ)) != 0) + if ((DP != NULL && (ret = mbedtls_mpi_copy(DP, &ctx->DP)) != 0) || (DQ != NULL && (ret = mbedtls_mpi_copy(DQ, &ctx->DQ)) != 0) || (QP != NULL && (ret = mbedtls_mpi_copy(QP, &ctx->QP)) != 0)) { return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA + ret); } @@ -516,12 +502,7 @@ size_t mbedtls_rsa_get_len(const mbedtls_rsa_context* ctx) * This generation method follows the RSA key pair generation procedure of * FIPS 186-4 if 2^16 < exponent < 2^256 and nbits = 2048 or nbits = 3072. */ -int mbedtls_rsa_gen_key( - mbedtls_rsa_context* ctx, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng, - unsigned int nbits, - int exponent) +int mbedtls_rsa_gen_key(mbedtls_rsa_context* ctx, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng, unsigned int nbits, int exponent) { int ret; mbedtls_mpi H, G, L; @@ -642,8 +623,7 @@ int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context* ctx) return (MBEDTLS_ERR_RSA_KEY_CHECK_FAILED); } - if (mbedtls_mpi_get_bit(&ctx->E, 0) == 0 || mbedtls_mpi_bitlen(&ctx->E) < 2 - || mbedtls_mpi_cmp_mpi(&ctx->E, &ctx->N) >= 0) { + if (mbedtls_mpi_get_bit(&ctx->E, 0) == 0 || mbedtls_mpi_bitlen(&ctx->E) < 2 || mbedtls_mpi_cmp_mpi(&ctx->E, &ctx->N) >= 0) { return (MBEDTLS_ERR_RSA_KEY_CHECK_FAILED); } @@ -825,11 +805,7 @@ cleanup: * Do an RSA private key operation */ int mbedtls_rsa_private( - mbedtls_rsa_context* ctx, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng, - const unsigned char* input, - unsigned char* output) + mbedtls_rsa_context* ctx, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng, const unsigned char* input, unsigned char* output) { int ret; size_t olen; @@ -1177,9 +1153,7 @@ exit: if (ret != 0) return (ret); - return ( - (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, output, output) - : mbedtls_rsa_private(ctx, f_rng, p_rng, output, output)); + return ((mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, output, output) : mbedtls_rsa_private(ctx, f_rng, p_rng, output, output)); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -1246,9 +1220,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( *p++ = 0; memcpy(p, input, ilen); - return ( - (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, output, output) - : mbedtls_rsa_private(ctx, f_rng, p_rng, output, output)); + return ((mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, output, output) : mbedtls_rsa_private(ctx, f_rng, p_rng, output, output)); } #endif /* MBEDTLS_PKCS1_V15 */ @@ -1341,8 +1313,7 @@ int mbedtls_rsa_rsaes_oaep_decrypt( /* * RSA operation */ - ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, input, buf) - : mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf); + ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, input, buf) : mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf); if (ret != 0) goto cleanup; @@ -1559,8 +1530,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( if (ilen < 16 || ilen > sizeof(buf)) return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); - ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, input, buf) - : mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf); + ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, input, buf) : mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf); if (ret != 0) goto cleanup; @@ -1619,8 +1589,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( * - OUTPUT_TOO_LARGE if the padding is good but the decrypted * plaintext does not fit in the output buffer. * - 0 if the padding is correct. */ - ret = -(int)if_int( - bad, -MBEDTLS_ERR_RSA_INVALID_PADDING, if_int(output_too_large, -MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE, 0)); + ret = -(int)if_int(bad, -MBEDTLS_ERR_RSA_INVALID_PADDING, if_int(output_too_large, -MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE, 0)); /* If the padding is bad or the plaintext is too large, zero the * data that we're about to copy to the output buffer. @@ -1813,9 +1782,7 @@ exit: if (ret != 0) return (ret); - return ( - (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, sig, sig) - : mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig)); + return ((mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, sig, sig) : mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig)); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -1842,8 +1809,7 @@ exit: * - dst points to a buffer of size at least dst_len. * */ -static int rsa_rsassa_pkcs1_v15_encode( - mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char* hash, size_t dst_len, unsigned char* dst) +static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char* hash, size_t dst_len, unsigned char* dst) { size_t oid_size = 0; size_t nb_pad = dst_len; @@ -2093,8 +2059,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext( if (siglen < 16 || siglen > sizeof(buf)) return (MBEDTLS_ERR_RSA_BAD_INPUT_DATA); - ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, sig, buf) - : mbedtls_rsa_private(ctx, f_rng, p_rng, sig, buf); + ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, sig, buf) : mbedtls_rsa_private(ctx, f_rng, p_rng, sig, buf); if (ret != 0) return (ret); @@ -2215,8 +2180,7 @@ int mbedtls_rsa_rsassa_pss_verify( mgf1_hash_id = (ctx->hash_id != MBEDTLS_MD_NONE) ? (mbedtls_md_type_t)ctx->hash_id : md_alg; - return (mbedtls_rsa_rsassa_pss_verify_ext( - ctx, f_rng, p_rng, mode, md_alg, hashlen, hash, mgf1_hash_id, MBEDTLS_RSA_SALT_LEN_ANY, sig)); + return (mbedtls_rsa_rsassa_pss_verify_ext(ctx, f_rng, p_rng, mode, md_alg, hashlen, hash, mgf1_hash_id, MBEDTLS_RSA_SALT_LEN_ANY, sig)); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -2264,8 +2228,7 @@ int mbedtls_rsa_rsassa_pkcs1_v15_verify( * Apply RSA primitive to get what should be PKCS1 encoded hash. */ - ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, sig, encoded) - : mbedtls_rsa_private(ctx, f_rng, p_rng, sig, encoded); + ret = (mode == MBEDTLS_RSA_PUBLIC) ? mbedtls_rsa_public(ctx, sig, encoded) : mbedtls_rsa_private(ctx, f_rng, p_rng, sig, encoded); if (ret != 0) goto cleanup; @@ -2536,9 +2499,7 @@ int mbedtls_rsa_self_test(int verbose) if (verbose != 0) mbedtls_printf("passed\n PKCS#1 decryption : "); - if (mbedtls_rsa_pkcs1_decrypt( - &rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, &len, rsa_ciphertext, rsa_decrypted, sizeof(rsa_decrypted)) - != 0) { + if (mbedtls_rsa_pkcs1_decrypt(&rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, &len, rsa_ciphertext, rsa_decrypted, sizeof(rsa_decrypted)) != 0) { if (verbose != 0) mbedtls_printf("failed\n"); @@ -2568,8 +2529,7 @@ int mbedtls_rsa_self_test(int verbose) return (1); } - if (mbedtls_rsa_pkcs1_sign(&rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 0, sha1sum, rsa_ciphertext) - != 0) { + if (mbedtls_rsa_pkcs1_sign(&rsa, myrand, NULL, MBEDTLS_RSA_PRIVATE, MBEDTLS_MD_SHA1, 0, sha1sum, rsa_ciphertext) != 0) { if (verbose != 0) mbedtls_printf("failed\n"); @@ -2580,8 +2540,7 @@ int mbedtls_rsa_self_test(int verbose) if (verbose != 0) mbedtls_printf("passed\n PKCS#1 sig. verify: "); - if (mbedtls_rsa_pkcs1_verify(&rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 0, sha1sum, rsa_ciphertext) - != 0) { + if (mbedtls_rsa_pkcs1_verify(&rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA1, 0, sha1sum, rsa_ciphertext) != 0) { if (verbose != 0) mbedtls_printf("failed\n"); diff --git a/nettls/ssl/rsa_internal.c b/nettls/ssl/rsa_internal.c index 2e83ff667defdd1639efbcad21566cf7e7a6840d..9fd06a6722e7a1dbb9b09799254b6c74e1c84da4 100644 --- a/nettls/ssl/rsa_internal.c +++ b/nettls/ssl/rsa_internal.c @@ -90,8 +90,7 @@ * of (a) and (b) above to attempt to factor N. * */ -int mbedtls_rsa_deduce_primes( - mbedtls_mpi const* N, mbedtls_mpi const* E, mbedtls_mpi const* D, mbedtls_mpi* P, mbedtls_mpi* Q) +int mbedtls_rsa_deduce_primes(mbedtls_mpi const* N, mbedtls_mpi const* E, mbedtls_mpi const* D, mbedtls_mpi* P, mbedtls_mpi* Q) { int ret = 0; @@ -103,18 +102,17 @@ int mbedtls_rsa_deduce_primes( mbedtls_mpi T; /* Holds largest odd divisor of DE - 1 */ mbedtls_mpi K; /* Temporary holding the current candidate */ - const unsigned char primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, - 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, - 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, - 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251}; + const unsigned char primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, + 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, + 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251}; const size_t num_primes = sizeof(primes) / sizeof(*primes); if (P == NULL || Q == NULL || P->p != NULL || Q->p != NULL) return (MBEDTLS_ERR_MPI_BAD_INPUT_DATA); - if (mbedtls_mpi_cmp_int(N, 0) <= 0 || mbedtls_mpi_cmp_int(D, 1) <= 0 || mbedtls_mpi_cmp_mpi(D, N) >= 0 - || mbedtls_mpi_cmp_int(E, 1) <= 0 || mbedtls_mpi_cmp_mpi(E, N) >= 0) { + if (mbedtls_mpi_cmp_int(N, 0) <= 0 || mbedtls_mpi_cmp_int(D, 1) <= 0 || mbedtls_mpi_cmp_mpi(D, N) >= 0 || mbedtls_mpi_cmp_int(E, 1) <= 0 + || mbedtls_mpi_cmp_mpi(E, N) >= 0) { return (MBEDTLS_ERR_MPI_BAD_INPUT_DATA); } @@ -209,8 +207,7 @@ cleanup: * Given P, Q and the public exponent E, deduce D. * This is essentially a modular inversion. */ -int mbedtls_rsa_deduce_private_exponent( - mbedtls_mpi const* P, mbedtls_mpi const* Q, mbedtls_mpi const* E, mbedtls_mpi* D) +int mbedtls_rsa_deduce_private_exponent(mbedtls_mpi const* P, mbedtls_mpi const* Q, mbedtls_mpi const* E, mbedtls_mpi* D) { int ret = 0; mbedtls_mpi K, L; @@ -251,12 +248,7 @@ cleanup: * Check that RSA CRT parameters are in accordance with core parameters. */ int mbedtls_rsa_validate_crt( - const mbedtls_mpi* P, - const mbedtls_mpi* Q, - const mbedtls_mpi* D, - const mbedtls_mpi* DP, - const mbedtls_mpi* DQ, - const mbedtls_mpi* QP) + const mbedtls_mpi* P, const mbedtls_mpi* Q, const mbedtls_mpi* D, const mbedtls_mpi* DP, const mbedtls_mpi* DQ, const mbedtls_mpi* QP) { int ret = 0; @@ -386,8 +378,7 @@ int mbedtls_rsa_validate_params( */ if (N != NULL && D != NULL && E != NULL) { - if (mbedtls_mpi_cmp_int(D, 1) <= 0 || mbedtls_mpi_cmp_int(E, 1) <= 0 || mbedtls_mpi_cmp_mpi(D, N) >= 0 - || mbedtls_mpi_cmp_mpi(E, N) >= 0) { + if (mbedtls_mpi_cmp_int(D, 1) <= 0 || mbedtls_mpi_cmp_int(E, 1) <= 0 || mbedtls_mpi_cmp_mpi(D, N) >= 0 || mbedtls_mpi_cmp_mpi(E, N) >= 0) { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } @@ -437,8 +428,7 @@ cleanup: return (ret); } -int mbedtls_rsa_deduce_crt( - const mbedtls_mpi* P, const mbedtls_mpi* Q, const mbedtls_mpi* D, mbedtls_mpi* DP, mbedtls_mpi* DQ, mbedtls_mpi* QP) +int mbedtls_rsa_deduce_crt(const mbedtls_mpi* P, const mbedtls_mpi* Q, const mbedtls_mpi* D, mbedtls_mpi* DP, mbedtls_mpi* DQ, mbedtls_mpi* QP) { int ret = 0; mbedtls_mpi K; diff --git a/nettls/ssl/sha1.c b/nettls/ssl/sha1.c index 27c3f3169e470ac4ad73562fedff43987a2f72d4..8a691d435285dafe3b9414725465eb0f96ea0fc3 100644 --- a/nettls/ssl/sha1.c +++ b/nettls/ssl/sha1.c @@ -83,8 +83,7 @@ #ifndef GET_UINT32_BE #define GET_UINT32_BE(n, b, i) \ { \ - (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) \ - | ((uint32_t)(b)[(i) + 3]); \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ } #endif @@ -480,18 +479,14 @@ void mbedtls_sha1(const unsigned char* input, size_t ilen, unsigned char output[ /* * FIPS-180-1 test vectors */ -static const unsigned char sha1_test_buf[3][57] = { - {"abc"}, {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"}, {""}}; +static const unsigned char sha1_test_buf[3][57] = {{"abc"}, {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"}, {""}}; static const size_t sha1_test_buflen[3] = {3, 56, 1000}; static const unsigned char sha1_test_sum[3][20] = { - {0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, - 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D}, - {0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, - 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1}, - {0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E, - 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F} + {0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D}, + {0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1}, + {0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E, 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F} }; /* diff --git a/nettls/ssl/sha256.c b/nettls/ssl/sha256.c index 1af64953a53e66507607285d1666321beed83b57..d3f1d9f37ace041d68b3c23dce3d709540a0fba4 100644 --- a/nettls/ssl/sha256.c +++ b/nettls/ssl/sha256.c @@ -69,14 +69,13 @@ #include #include #define mbedtls_printf printf -#define mbedtls_calloc calloc -#define mbedtls_free free +#define mbedtls_calloc calloc +#define mbedtls_free free #endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_SELF_TEST */ -#define SHA256_VALIDATE_RET(cond) \ - MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA256_BAD_INPUT_DATA ) -#define SHA256_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) +#define SHA256_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_SHA256_BAD_INPUT_DATA) +#define SHA256_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) #if !defined(MBEDTLS_SHA256_ALT) @@ -84,45 +83,41 @@ * 32-bit integer manipulation macros (big endian) */ #ifndef GET_UINT32_BE -#define GET_UINT32_BE(n,b,i) \ -do { \ - (n) = ( (uint32_t) (b)[(i) ] << 24 ) \ - | ( (uint32_t) (b)[(i) + 1] << 16 ) \ - | ( (uint32_t) (b)[(i) + 2] << 8 ) \ - | ( (uint32_t) (b)[(i) + 3] ); \ -} while( 0 ) +#define GET_UINT32_BE(n, b, i) \ + do { \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ + } while (0) #endif #ifndef PUT_UINT32_BE -#define PUT_UINT32_BE(n,b,i) \ -do { \ - (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) ); \ -} while( 0 ) +#define PUT_UINT32_BE(n, b, i) \ + do { \ + (b)[(i)] = (unsigned char)((n) >> 24); \ + (b)[(i) + 1] = (unsigned char)((n) >> 16); \ + (b)[(i) + 2] = (unsigned char)((n) >> 8); \ + (b)[(i) + 3] = (unsigned char)((n)); \ + } while (0) #endif -void mbedtls_sha256_init( mbedtls_sha256_context *ctx ) +void mbedtls_sha256_init(mbedtls_sha256_context* ctx) { - SHA256_VALIDATE( ctx != NULL ); + SHA256_VALIDATE(ctx != NULL); - memset( ctx, 0, sizeof( mbedtls_sha256_context ) ); + memset(ctx, 0, sizeof(mbedtls_sha256_context)); } -void mbedtls_sha256_free( mbedtls_sha256_context *ctx ) +void mbedtls_sha256_free(mbedtls_sha256_context* ctx) { - if( ctx == NULL ) + if (ctx == NULL) return; - mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha256_context ) ); + mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha256_context)); } -void mbedtls_sha256_clone( mbedtls_sha256_context *dst, - const mbedtls_sha256_context *src ) +void mbedtls_sha256_clone(mbedtls_sha256_context* dst, const mbedtls_sha256_context* src) { - SHA256_VALIDATE( dst != NULL ); - SHA256_VALIDATE( src != NULL ); + SHA256_VALIDATE(dst != NULL); + SHA256_VALIDATE(src != NULL); *dst = *src; } @@ -130,16 +125,15 @@ void mbedtls_sha256_clone( mbedtls_sha256_context *dst, /* * SHA-256 context setup */ -int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ) +int mbedtls_sha256_starts_ret(mbedtls_sha256_context* ctx, int is224) { - SHA256_VALIDATE_RET( ctx != NULL ); - SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); + SHA256_VALIDATE_RET(ctx != NULL); + SHA256_VALIDATE_RET(is224 == 0 || is224 == 1); ctx->total[0] = 0; ctx->total[1] = 0; - if( is224 == 0 ) - { + if (is224 == 0) { /* SHA-256 */ ctx->state[0] = 0x6A09E667; ctx->state[1] = 0xBB67AE85; @@ -149,9 +143,7 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ) ctx->state[5] = 0x9B05688C; ctx->state[6] = 0x1F83D9AB; ctx->state[7] = 0x5BE0CD19; - } - else - { + } else { /* SHA-224 */ ctx->state[0] = 0xC1059ED8; ctx->state[1] = 0x367CD507; @@ -165,157 +157,122 @@ int mbedtls_sha256_starts_ret( mbedtls_sha256_context *ctx, int is224 ) ctx->is224 = is224; - return( 0 ); + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha256_starts( mbedtls_sha256_context *ctx, - int is224 ) +void mbedtls_sha256_starts(mbedtls_sha256_context* ctx, int is224) { - mbedtls_sha256_starts_ret( ctx, is224 ); + mbedtls_sha256_starts_ret(ctx, is224); } #endif #if !defined(MBEDTLS_SHA256_PROCESS_ALT) -static const uint32_t K[] = -{ - 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, - 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, - 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, - 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, - 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, - 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, - 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, - 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, - 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, - 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, - 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, - 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, - 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, - 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, - 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, - 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2, +static const uint32_t K[] = { + 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, + 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, + 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, 0x27B70A85, + 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, + 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, + 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2, }; -#define SHR(x,n) (((x) & 0xFFFFFFFF) >> (n)) -#define ROTR(x,n) (SHR(x,n) | ((x) << (32 - (n)))) +#define SHR(x, n) (((x)&0xFFFFFFFF) >> (n)) +#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n)))) -#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) -#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) +#define S0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define S1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) -#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22)) -#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25)) +#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) -#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) -#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) +#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define R(t) \ - ( \ - local.W[t] = S1(local.W[(t) - 2]) + local.W[(t) - 7] + \ - S0(local.W[(t) - 15]) + local.W[(t) - 16] \ - ) +#define R(t) (local.W[t] = S1(local.W[(t)-2]) + local.W[(t)-7] + S0(local.W[(t)-15]) + local.W[(t)-16]) -#define P(a,b,c,d,e,f,g,h,x,K) \ - do \ - { \ - local.temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \ - local.temp2 = S2(a) + F0((a),(b),(c)); \ - (d) += local.temp1; (h) = local.temp1 + local.temp2; \ - } while( 0 ) +#define P(a, b, c, d, e, f, g, h, x, K) \ + do { \ + local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x); \ + local.temp2 = S2(a) + F0((a), (b), (c)); \ + (d) += local.temp1; \ + (h) = local.temp1 + local.temp2; \ + } while (0) -int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, - const unsigned char data[64] ) +int mbedtls_internal_sha256_process(mbedtls_sha256_context* ctx, const unsigned char data[64]) { - struct - { + struct { uint32_t temp1, temp2, W[64]; uint32_t A[8]; } local; unsigned int i; - SHA256_VALIDATE_RET( ctx != NULL ); - SHA256_VALIDATE_RET( (const unsigned char *)data != NULL ); + SHA256_VALIDATE_RET(ctx != NULL); + SHA256_VALIDATE_RET((const unsigned char*)data != NULL); - for( i = 0; i < 8; i++ ) + for (i = 0; i < 8; i++) local.A[i] = ctx->state[i]; #if defined(MBEDTLS_SHA256_SMALLER) - for( i = 0; i < 64; i++ ) - { - if( i < 16 ) - GET_UINT32_BE( local.W[i], data, 4 * i ); + for (i = 0; i < 64; i++) { + if (i < 16) + GET_UINT32_BE(local.W[i], data, 4 * i); else - R( i ); - - P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], - local.A[5], local.A[6], local.A[7], local.W[i], K[i] ); - - local.temp1 = local.A[7]; local.A[7] = local.A[6]; - local.A[6] = local.A[5]; local.A[5] = local.A[4]; - local.A[4] = local.A[3]; local.A[3] = local.A[2]; - local.A[2] = local.A[1]; local.A[1] = local.A[0]; + R(i); + + P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.W[i], K[i]); + + local.temp1 = local.A[7]; + local.A[7] = local.A[6]; + local.A[6] = local.A[5]; + local.A[5] = local.A[4]; + local.A[4] = local.A[3]; + local.A[3] = local.A[2]; + local.A[2] = local.A[1]; + local.A[1] = local.A[0]; local.A[0] = local.temp1; } -#else /* MBEDTLS_SHA256_SMALLER */ - for( i = 0; i < 16; i++ ) - GET_UINT32_BE( local.W[i], data, 4 * i ); - - for( i = 0; i < 16; i += 8 ) - { - P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], - local.A[5], local.A[6], local.A[7], local.W[i+0], K[i+0] ); - P( local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], - local.A[4], local.A[5], local.A[6], local.W[i+1], K[i+1] ); - P( local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], - local.A[3], local.A[4], local.A[5], local.W[i+2], K[i+2] ); - P( local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], - local.A[2], local.A[3], local.A[4], local.W[i+3], K[i+3] ); - P( local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], - local.A[1], local.A[2], local.A[3], local.W[i+4], K[i+4] ); - P( local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], - local.A[0], local.A[1], local.A[2], local.W[i+5], K[i+5] ); - P( local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], - local.A[7], local.A[0], local.A[1], local.W[i+6], K[i+6] ); - P( local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], - local.A[6], local.A[7], local.A[0], local.W[i+7], K[i+7] ); +#else /* MBEDTLS_SHA256_SMALLER */ + for (i = 0; i < 16; i++) + GET_UINT32_BE(local.W[i], data, 4 * i); + + for (i = 0; i < 16; i += 8) { + P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.W[i + 0], K[i + 0]); + P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.W[i + 1], K[i + 1]); + P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.W[i + 2], K[i + 2]); + P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.W[i + 3], K[i + 3]); + P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], local.W[i + 4], K[i + 4]); + P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], local.W[i + 5], K[i + 5]); + P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], local.W[i + 6], K[i + 6]); + P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], local.W[i + 7], K[i + 7]); } - for( i = 16; i < 64; i += 8 ) - { - P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], - local.A[5], local.A[6], local.A[7], R(i+0), K[i+0] ); - P( local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], - local.A[4], local.A[5], local.A[6], R(i+1), K[i+1] ); - P( local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], - local.A[3], local.A[4], local.A[5], R(i+2), K[i+2] ); - P( local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], - local.A[2], local.A[3], local.A[4], R(i+3), K[i+3] ); - P( local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], - local.A[1], local.A[2], local.A[3], R(i+4), K[i+4] ); - P( local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], - local.A[0], local.A[1], local.A[2], R(i+5), K[i+5] ); - P( local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], - local.A[7], local.A[0], local.A[1], R(i+6), K[i+6] ); - P( local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], - local.A[6], local.A[7], local.A[0], R(i+7), K[i+7] ); + for (i = 16; i < 64; i += 8) { + P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], R(i + 0), K[i + 0]); + P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], R(i + 1), K[i + 1]); + P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], R(i + 2), K[i + 2]); + P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], R(i + 3), K[i + 3]); + P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], R(i + 4), K[i + 4]); + P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], R(i + 5), K[i + 5]); + P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], R(i + 6), K[i + 6]); + P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], R(i + 7), K[i + 7]); } #endif /* MBEDTLS_SHA256_SMALLER */ - for( i = 0; i < 8; i++ ) + for (i = 0; i < 8; i++) ctx->state[i] += local.A[i]; /* Zeroise buffers and variables to clear sensitive data from memory. */ - mbedtls_platform_zeroize( &local, sizeof( local ) ); + mbedtls_platform_zeroize(&local, sizeof(local)); - return( 0 ); + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha256_process( mbedtls_sha256_context *ctx, - const unsigned char data[64] ) +void mbedtls_sha256_process(mbedtls_sha256_context* ctx, const unsigned char data[64]) { - mbedtls_internal_sha256_process( ctx, data ); + mbedtls_internal_sha256_process(ctx, data); } #endif #endif /* !MBEDTLS_SHA256_PROCESS_ALT */ @@ -323,77 +280,70 @@ void mbedtls_sha256_process( mbedtls_sha256_context *ctx, /* * SHA-256 process buffer */ -int mbedtls_sha256_update_ret( mbedtls_sha256_context *ctx, - const unsigned char *input, - size_t ilen ) +int mbedtls_sha256_update_ret(mbedtls_sha256_context* ctx, const unsigned char* input, size_t ilen) { int ret; size_t fill; uint32_t left; - SHA256_VALIDATE_RET( ctx != NULL ); - SHA256_VALIDATE_RET( ilen == 0 || input != NULL ); + SHA256_VALIDATE_RET(ctx != NULL); + SHA256_VALIDATE_RET(ilen == 0 || input != NULL); - if( ilen == 0 ) - return( 0 ); + if (ilen == 0) + return (0); left = ctx->total[0] & 0x3F; fill = 64 - left; - ctx->total[0] += (uint32_t) ilen; + ctx->total[0] += (uint32_t)ilen; ctx->total[0] &= 0xFFFFFFFF; - if( ctx->total[0] < (uint32_t) ilen ) + if (ctx->total[0] < (uint32_t)ilen) ctx->total[1]++; - if( left && ilen >= fill ) - { - memcpy( (void *) (ctx->buffer + left), input, fill ); + if (left && ilen >= fill) { + memcpy((void*)(ctx->buffer + left), input, fill); - if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) + return (ret); input += fill; - ilen -= fill; + ilen -= fill; left = 0; } - while( ilen >= 64 ) - { - if( ( ret = mbedtls_internal_sha256_process( ctx, input ) ) != 0 ) - return( ret ); + while (ilen >= 64) { + if ((ret = mbedtls_internal_sha256_process(ctx, input)) != 0) + return (ret); input += 64; - ilen -= 64; + ilen -= 64; } - if( ilen > 0 ) - memcpy( (void *) (ctx->buffer + left), input, ilen ); + if (ilen > 0) + memcpy((void*)(ctx->buffer + left), input, ilen); - return( 0 ); + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha256_update( mbedtls_sha256_context *ctx, - const unsigned char *input, - size_t ilen ) +void mbedtls_sha256_update(mbedtls_sha256_context* ctx, const unsigned char* input, size_t ilen) { - mbedtls_sha256_update_ret( ctx, input, ilen ); + mbedtls_sha256_update_ret(ctx, input, ilen); } #endif /* * SHA-256 final digest */ -int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, - unsigned char output[32] ) +int mbedtls_sha256_finish_ret(mbedtls_sha256_context* ctx, unsigned char output[32]) { int ret; uint32_t used; uint32_t high, low; - SHA256_VALIDATE_RET( ctx != NULL ); - SHA256_VALIDATE_RET( (unsigned char *)output != NULL ); + SHA256_VALIDATE_RET(ctx != NULL); + SHA256_VALIDATE_RET((unsigned char*)output != NULL); /* * Add padding: 0x80 then 0x00 until 8 bytes remain for the length @@ -402,57 +352,52 @@ int mbedtls_sha256_finish_ret( mbedtls_sha256_context *ctx, ctx->buffer[used++] = 0x80; - if( used <= 56 ) - { + if (used <= 56) { /* Enough room for padding + length in current block */ - memset( ctx->buffer + used, 0, 56 - used ); - } - else - { + memset(ctx->buffer + used, 0, 56 - used); + } else { /* We'll need an extra block */ - memset( ctx->buffer + used, 0, 64 - used ); + memset(ctx->buffer + used, 0, 64 - used); - if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) + return (ret); - memset( ctx->buffer, 0, 56 ); + memset(ctx->buffer, 0, 56); } /* * Add message length */ - high = ( ctx->total[0] >> 29 ) - | ( ctx->total[1] << 3 ); - low = ( ctx->total[0] << 3 ); + high = (ctx->total[0] >> 29) | (ctx->total[1] << 3); + low = (ctx->total[0] << 3); - PUT_UINT32_BE( high, ctx->buffer, 56 ); - PUT_UINT32_BE( low, ctx->buffer, 60 ); + PUT_UINT32_BE(high, ctx->buffer, 56); + PUT_UINT32_BE(low, ctx->buffer, 60); - if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) + return (ret); /* * Output final state */ - PUT_UINT32_BE( ctx->state[0], output, 0 ); - PUT_UINT32_BE( ctx->state[1], output, 4 ); - PUT_UINT32_BE( ctx->state[2], output, 8 ); - PUT_UINT32_BE( ctx->state[3], output, 12 ); - PUT_UINT32_BE( ctx->state[4], output, 16 ); - PUT_UINT32_BE( ctx->state[5], output, 20 ); - PUT_UINT32_BE( ctx->state[6], output, 24 ); - - if( ctx->is224 == 0 ) - PUT_UINT32_BE( ctx->state[7], output, 28 ); - - return( 0 ); + PUT_UINT32_BE(ctx->state[0], output, 0); + PUT_UINT32_BE(ctx->state[1], output, 4); + PUT_UINT32_BE(ctx->state[2], output, 8); + PUT_UINT32_BE(ctx->state[3], output, 12); + PUT_UINT32_BE(ctx->state[4], output, 16); + PUT_UINT32_BE(ctx->state[5], output, 20); + PUT_UINT32_BE(ctx->state[6], output, 24); + + if (ctx->is224 == 0) + PUT_UINT32_BE(ctx->state[7], output, 28); + + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, - unsigned char output[32] ) +void mbedtls_sha256_finish(mbedtls_sha256_context* ctx, unsigned char output[32]) { - mbedtls_sha256_finish_ret( ctx, output ); + mbedtls_sha256_finish_ret(ctx, output); } #endif @@ -461,42 +406,36 @@ void mbedtls_sha256_finish( mbedtls_sha256_context *ctx, /* * output = SHA-256( input buffer ) */ -int mbedtls_sha256_ret( const unsigned char *input, - size_t ilen, - unsigned char output[32], - int is224 ) +int mbedtls_sha256_ret(const unsigned char* input, size_t ilen, unsigned char output[32], int is224) { int ret; mbedtls_sha256_context ctx; - SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); - SHA256_VALIDATE_RET( ilen == 0 || input != NULL ); - SHA256_VALIDATE_RET( (unsigned char *)output != NULL ); + SHA256_VALIDATE_RET(is224 == 0 || is224 == 1); + SHA256_VALIDATE_RET(ilen == 0 || input != NULL); + SHA256_VALIDATE_RET((unsigned char*)output != NULL); - mbedtls_sha256_init( &ctx ); + mbedtls_sha256_init(&ctx); - if( ( ret = mbedtls_sha256_starts_ret( &ctx, is224 ) ) != 0 ) + if ((ret = mbedtls_sha256_starts_ret(&ctx, is224)) != 0) goto exit; - if( ( ret = mbedtls_sha256_update_ret( &ctx, input, ilen ) ) != 0 ) + if ((ret = mbedtls_sha256_update_ret(&ctx, input, ilen)) != 0) goto exit; - if( ( ret = mbedtls_sha256_finish_ret( &ctx, output ) ) != 0 ) + if ((ret = mbedtls_sha256_finish_ret(&ctx, output)) != 0) goto exit; exit: - mbedtls_sha256_free( &ctx ); + mbedtls_sha256_free(&ctx); - return( ret ); + return (ret); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha256( const unsigned char *input, - size_t ilen, - unsigned char output[32], - int is224 ) +void mbedtls_sha256(const unsigned char* input, size_t ilen, unsigned char output[32], int is224) { - mbedtls_sha256_ret( input, ilen, output, is224 ); + mbedtls_sha256_ret(input, ilen, output, is224); } #endif @@ -504,133 +443,103 @@ void mbedtls_sha256( const unsigned char *input, /* * FIPS-180-2 test vectors */ -static const unsigned char sha256_test_buf[3][57] = -{ - { "abc" }, - { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }, - { "" } -}; - -static const size_t sha256_test_buflen[3] = -{ - 3, 56, 1000 -}; - -static const unsigned char sha256_test_sum[6][32] = -{ - /* - * SHA-224 test vectors - */ - { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, - 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3, - 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7, - 0xE3, 0x6C, 0x9D, 0xA7 }, - { 0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC, - 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, 0x01, 0x50, - 0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19, - 0x52, 0x52, 0x25, 0x25 }, - { 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8, - 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B, - 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE, - 0x4E, 0xE7, 0xAD, 0x67 }, - - /* - * SHA-256 test vectors - */ - { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, - 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, - 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, - 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD }, - { 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, - 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39, - 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, - 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 }, - { 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92, - 0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67, - 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E, - 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 } +static const unsigned char sha256_test_buf[3][57] = {{"abc"}, {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"}, {""}}; + +static const size_t sha256_test_buflen[3] = {3, 56, 1000}; + +static const unsigned char sha256_test_sum[6][32] = { + /* + * SHA-224 test vectors + */ + {0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, + 0x55, 0xB3, 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7, 0xE3, 0x6C, 0x9D, 0xA7}, + {0x75, 0x38, 0x8B, 0x16, 0x51, 0x27, 0x76, 0xCC, 0x5D, 0xBA, 0x5D, 0xA1, 0xFD, 0x89, + 0x01, 0x50, 0xB0, 0xC6, 0x45, 0x5C, 0xB4, 0xF5, 0x8B, 0x19, 0x52, 0x52, 0x25, 0x25}, + {0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8, 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, + 0x8A, 0x4B, 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE, 0x4E, 0xE7, 0xAD, 0x67}, + + /* + * SHA-256 test vectors + */ + {0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, + 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD}, + {0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39, + 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1}, + {0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92, 0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67, + 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E, 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0} }; /* * Checkup routine */ -int mbedtls_sha256_self_test( int verbose ) +int mbedtls_sha256_self_test(int verbose) { int i, j, k, buflen, ret = 0; - unsigned char *buf; + unsigned char* buf; unsigned char sha256sum[32]; mbedtls_sha256_context ctx; - buf = mbedtls_calloc( 1024, sizeof(unsigned char) ); - if( NULL == buf ) - { - if( verbose != 0 ) - mbedtls_printf( "Buffer allocation failed\n" ); + buf = mbedtls_calloc(1024, sizeof(unsigned char)); + if (NULL == buf) { + if (verbose != 0) + mbedtls_printf("Buffer allocation failed\n"); - return( 1 ); + return (1); } - mbedtls_sha256_init( &ctx ); + mbedtls_sha256_init(&ctx); - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { j = i % 3; k = i < 3; - if( verbose != 0 ) - mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 ); + if (verbose != 0) + mbedtls_printf(" SHA-%d test #%d: ", 256 - k * 32, j + 1); - if( ( ret = mbedtls_sha256_starts_ret( &ctx, k ) ) != 0 ) + if ((ret = mbedtls_sha256_starts_ret(&ctx, k)) != 0) goto fail; - if( j == 2 ) - { - memset( buf, 'a', buflen = 1000 ); + if (j == 2) { + memset(buf, 'a', buflen = 1000); - for( j = 0; j < 1000; j++ ) - { - ret = mbedtls_sha256_update_ret( &ctx, buf, buflen ); - if( ret != 0 ) + for (j = 0; j < 1000; j++) { + ret = mbedtls_sha256_update_ret(&ctx, buf, buflen); + if (ret != 0) goto fail; } - } - else - { - ret = mbedtls_sha256_update_ret( &ctx, sha256_test_buf[j], - sha256_test_buflen[j] ); - if( ret != 0 ) - goto fail; + } else { + ret = mbedtls_sha256_update_ret(&ctx, sha256_test_buf[j], sha256_test_buflen[j]); + if (ret != 0) + goto fail; } - if( ( ret = mbedtls_sha256_finish_ret( &ctx, sha256sum ) ) != 0 ) + if ((ret = mbedtls_sha256_finish_ret(&ctx, sha256sum)) != 0) goto fail; - - if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 ) - { + if (memcmp(sha256sum, sha256_test_sum[i], 32 - k * 4) != 0) { ret = 1; goto fail; } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); goto exit; fail: - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (verbose != 0) + mbedtls_printf("failed\n"); exit: - mbedtls_sha256_free( &ctx ); - mbedtls_free( buf ); + mbedtls_sha256_free(&ctx); + mbedtls_free(buf); - return( ret ); + return (ret); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/nettls/ssl/sha512.c b/nettls/ssl/sha512.c index 860730cdaefdc9fed58d6668906c11e8e542cdb2..b4004b0a237417fe4563805d06b7aa73ffec3b0f 100644 --- a/nettls/ssl/sha512.c +++ b/nettls/ssl/sha512.c @@ -61,9 +61,9 @@ #include "nettls/platform_util.h" #if defined(_MSC_VER) || defined(__WATCOMC__) - #define UL64(x) x##ui64 +#define UL64(x) x##ui64 #else - #define UL64(x) x##ULL +#define UL64(x) x##ULL #endif #include @@ -75,14 +75,13 @@ #include #include #define mbedtls_printf printf -#define mbedtls_calloc calloc -#define mbedtls_free free +#define mbedtls_calloc calloc +#define mbedtls_free free #endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_SELF_TEST */ -#define SHA512_VALIDATE_RET(cond) \ - MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA512_BAD_INPUT_DATA ) -#define SHA512_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) +#define SHA512_VALIDATE_RET(cond) MBEDTLS_INTERNAL_VALIDATE_RET(cond, MBEDTLS_ERR_SHA512_BAD_INPUT_DATA) +#define SHA512_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE(cond) #if !defined(MBEDTLS_SHA512_ALT) @@ -90,53 +89,46 @@ * 64-bit integer manipulation macros (big endian) */ #ifndef GET_UINT64_BE -#define GET_UINT64_BE(n,b,i) \ -{ \ - (n) = ( (uint64_t) (b)[(i) ] << 56 ) \ - | ( (uint64_t) (b)[(i) + 1] << 48 ) \ - | ( (uint64_t) (b)[(i) + 2] << 40 ) \ - | ( (uint64_t) (b)[(i) + 3] << 32 ) \ - | ( (uint64_t) (b)[(i) + 4] << 24 ) \ - | ( (uint64_t) (b)[(i) + 5] << 16 ) \ - | ( (uint64_t) (b)[(i) + 6] << 8 ) \ - | ( (uint64_t) (b)[(i) + 7] ); \ -} +#define GET_UINT64_BE(n, b, i) \ + { \ + (n) = ((uint64_t)(b)[(i)] << 56) | ((uint64_t)(b)[(i) + 1] << 48) | ((uint64_t)(b)[(i) + 2] << 40) | ((uint64_t)(b)[(i) + 3] << 32) \ + | ((uint64_t)(b)[(i) + 4] << 24) | ((uint64_t)(b)[(i) + 5] << 16) | ((uint64_t)(b)[(i) + 6] << 8) | ((uint64_t)(b)[(i) + 7]); \ + } #endif /* GET_UINT64_BE */ #ifndef PUT_UINT64_BE -#define PUT_UINT64_BE(n,b,i) \ -{ \ - (b)[(i) ] = (unsigned char) ( (n) >> 56 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 48 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 40 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) >> 32 ); \ - (b)[(i) + 4] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 5] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 6] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 7] = (unsigned char) ( (n) ); \ -} +#define PUT_UINT64_BE(n, b, i) \ + { \ + (b)[(i)] = (unsigned char)((n) >> 56); \ + (b)[(i) + 1] = (unsigned char)((n) >> 48); \ + (b)[(i) + 2] = (unsigned char)((n) >> 40); \ + (b)[(i) + 3] = (unsigned char)((n) >> 32); \ + (b)[(i) + 4] = (unsigned char)((n) >> 24); \ + (b)[(i) + 5] = (unsigned char)((n) >> 16); \ + (b)[(i) + 6] = (unsigned char)((n) >> 8); \ + (b)[(i) + 7] = (unsigned char)((n)); \ + } #endif /* PUT_UINT64_BE */ -void mbedtls_sha512_init( mbedtls_sha512_context *ctx ) +void mbedtls_sha512_init(mbedtls_sha512_context* ctx) { - SHA512_VALIDATE( ctx != NULL ); + SHA512_VALIDATE(ctx != NULL); - memset( ctx, 0, sizeof( mbedtls_sha512_context ) ); + memset(ctx, 0, sizeof(mbedtls_sha512_context)); } -void mbedtls_sha512_free( mbedtls_sha512_context *ctx ) +void mbedtls_sha512_free(mbedtls_sha512_context* ctx) { - if( ctx == NULL ) + if (ctx == NULL) return; - mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha512_context ) ); + mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha512_context)); } -void mbedtls_sha512_clone( mbedtls_sha512_context *dst, - const mbedtls_sha512_context *src ) +void mbedtls_sha512_clone(mbedtls_sha512_context* dst, const mbedtls_sha512_context* src) { - SHA512_VALIDATE( dst != NULL ); - SHA512_VALIDATE( src != NULL ); + SHA512_VALIDATE(dst != NULL); + SHA512_VALIDATE(src != NULL); *dst = *src; } @@ -144,16 +136,15 @@ void mbedtls_sha512_clone( mbedtls_sha512_context *dst, /* * SHA-512 context setup */ -int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 ) +int mbedtls_sha512_starts_ret(mbedtls_sha512_context* ctx, int is384) { - SHA512_VALIDATE_RET( ctx != NULL ); - SHA512_VALIDATE_RET( is384 == 0 || is384 == 1 ); + SHA512_VALIDATE_RET(ctx != NULL); + SHA512_VALIDATE_RET(is384 == 0 || is384 == 1); ctx->total[0] = 0; ctx->total[1] = 0; - if( is384 == 0 ) - { + if (is384 == 0) { /* SHA-512 */ ctx->state[0] = UL64(0x6A09E667F3BCC908); ctx->state[1] = UL64(0xBB67AE8584CAA73B); @@ -163,9 +154,7 @@ int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 ) ctx->state[5] = UL64(0x9B05688C2B3E6C1F); ctx->state[6] = UL64(0x1F83D9ABFB41BD6B); ctx->state[7] = UL64(0x5BE0CD19137E2179); - } - else - { + } else { /* SHA-384 */ ctx->state[0] = UL64(0xCBBB9D5DC1059ED8); ctx->state[1] = UL64(0x629A292A367CD507); @@ -179,14 +168,13 @@ int mbedtls_sha512_starts_ret( mbedtls_sha512_context *ctx, int is384 ) ctx->is384 = is384; - return( 0 ); + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, - int is384 ) +void mbedtls_sha512_starts(mbedtls_sha512_context* ctx, int is384) { - mbedtls_sha512_starts_ret( ctx, is384 ); + mbedtls_sha512_starts_ret(ctx, is384); } #endif @@ -195,92 +183,61 @@ void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, /* * Round constants */ -static const uint64_t K[80] = -{ - UL64(0x428A2F98D728AE22), UL64(0x7137449123EF65CD), - UL64(0xB5C0FBCFEC4D3B2F), UL64(0xE9B5DBA58189DBBC), - UL64(0x3956C25BF348B538), UL64(0x59F111F1B605D019), - UL64(0x923F82A4AF194F9B), UL64(0xAB1C5ED5DA6D8118), - UL64(0xD807AA98A3030242), UL64(0x12835B0145706FBE), - UL64(0x243185BE4EE4B28C), UL64(0x550C7DC3D5FFB4E2), - UL64(0x72BE5D74F27B896F), UL64(0x80DEB1FE3B1696B1), - UL64(0x9BDC06A725C71235), UL64(0xC19BF174CF692694), - UL64(0xE49B69C19EF14AD2), UL64(0xEFBE4786384F25E3), - UL64(0x0FC19DC68B8CD5B5), UL64(0x240CA1CC77AC9C65), - UL64(0x2DE92C6F592B0275), UL64(0x4A7484AA6EA6E483), - UL64(0x5CB0A9DCBD41FBD4), UL64(0x76F988DA831153B5), - UL64(0x983E5152EE66DFAB), UL64(0xA831C66D2DB43210), - UL64(0xB00327C898FB213F), UL64(0xBF597FC7BEEF0EE4), - UL64(0xC6E00BF33DA88FC2), UL64(0xD5A79147930AA725), - UL64(0x06CA6351E003826F), UL64(0x142929670A0E6E70), - UL64(0x27B70A8546D22FFC), UL64(0x2E1B21385C26C926), - UL64(0x4D2C6DFC5AC42AED), UL64(0x53380D139D95B3DF), - UL64(0x650A73548BAF63DE), UL64(0x766A0ABB3C77B2A8), - UL64(0x81C2C92E47EDAEE6), UL64(0x92722C851482353B), - UL64(0xA2BFE8A14CF10364), UL64(0xA81A664BBC423001), - UL64(0xC24B8B70D0F89791), UL64(0xC76C51A30654BE30), - UL64(0xD192E819D6EF5218), UL64(0xD69906245565A910), - UL64(0xF40E35855771202A), UL64(0x106AA07032BBD1B8), - UL64(0x19A4C116B8D2D0C8), UL64(0x1E376C085141AB53), - UL64(0x2748774CDF8EEB99), UL64(0x34B0BCB5E19B48A8), - UL64(0x391C0CB3C5C95A63), UL64(0x4ED8AA4AE3418ACB), - UL64(0x5B9CCA4F7763E373), UL64(0x682E6FF3D6B2B8A3), - UL64(0x748F82EE5DEFB2FC), UL64(0x78A5636F43172F60), - UL64(0x84C87814A1F0AB72), UL64(0x8CC702081A6439EC), - UL64(0x90BEFFFA23631E28), UL64(0xA4506CEBDE82BDE9), - UL64(0xBEF9A3F7B2C67915), UL64(0xC67178F2E372532B), - UL64(0xCA273ECEEA26619C), UL64(0xD186B8C721C0C207), - UL64(0xEADA7DD6CDE0EB1E), UL64(0xF57D4F7FEE6ED178), - UL64(0x06F067AA72176FBA), UL64(0x0A637DC5A2C898A6), - UL64(0x113F9804BEF90DAE), UL64(0x1B710B35131C471B), - UL64(0x28DB77F523047D84), UL64(0x32CAAB7B40C72493), - UL64(0x3C9EBE0A15C9BEBC), UL64(0x431D67C49C100D4C), - UL64(0x4CC5D4BECB3E42B6), UL64(0x597F299CFC657E2A), - UL64(0x5FCB6FAB3AD6FAEC), UL64(0x6C44198C4A475817) -}; - -int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, - const unsigned char data[128] ) +static const uint64_t K[80] = { + UL64(0x428A2F98D728AE22), UL64(0x7137449123EF65CD), UL64(0xB5C0FBCFEC4D3B2F), UL64(0xE9B5DBA58189DBBC), UL64(0x3956C25BF348B538), + UL64(0x59F111F1B605D019), UL64(0x923F82A4AF194F9B), UL64(0xAB1C5ED5DA6D8118), UL64(0xD807AA98A3030242), UL64(0x12835B0145706FBE), + UL64(0x243185BE4EE4B28C), UL64(0x550C7DC3D5FFB4E2), UL64(0x72BE5D74F27B896F), UL64(0x80DEB1FE3B1696B1), UL64(0x9BDC06A725C71235), + UL64(0xC19BF174CF692694), UL64(0xE49B69C19EF14AD2), UL64(0xEFBE4786384F25E3), UL64(0x0FC19DC68B8CD5B5), UL64(0x240CA1CC77AC9C65), + UL64(0x2DE92C6F592B0275), UL64(0x4A7484AA6EA6E483), UL64(0x5CB0A9DCBD41FBD4), UL64(0x76F988DA831153B5), UL64(0x983E5152EE66DFAB), + UL64(0xA831C66D2DB43210), UL64(0xB00327C898FB213F), UL64(0xBF597FC7BEEF0EE4), UL64(0xC6E00BF33DA88FC2), UL64(0xD5A79147930AA725), + UL64(0x06CA6351E003826F), UL64(0x142929670A0E6E70), UL64(0x27B70A8546D22FFC), UL64(0x2E1B21385C26C926), UL64(0x4D2C6DFC5AC42AED), + UL64(0x53380D139D95B3DF), UL64(0x650A73548BAF63DE), UL64(0x766A0ABB3C77B2A8), UL64(0x81C2C92E47EDAEE6), UL64(0x92722C851482353B), + UL64(0xA2BFE8A14CF10364), UL64(0xA81A664BBC423001), UL64(0xC24B8B70D0F89791), UL64(0xC76C51A30654BE30), UL64(0xD192E819D6EF5218), + UL64(0xD69906245565A910), UL64(0xF40E35855771202A), UL64(0x106AA07032BBD1B8), UL64(0x19A4C116B8D2D0C8), UL64(0x1E376C085141AB53), + UL64(0x2748774CDF8EEB99), UL64(0x34B0BCB5E19B48A8), UL64(0x391C0CB3C5C95A63), UL64(0x4ED8AA4AE3418ACB), UL64(0x5B9CCA4F7763E373), + UL64(0x682E6FF3D6B2B8A3), UL64(0x748F82EE5DEFB2FC), UL64(0x78A5636F43172F60), UL64(0x84C87814A1F0AB72), UL64(0x8CC702081A6439EC), + UL64(0x90BEFFFA23631E28), UL64(0xA4506CEBDE82BDE9), UL64(0xBEF9A3F7B2C67915), UL64(0xC67178F2E372532B), UL64(0xCA273ECEEA26619C), + UL64(0xD186B8C721C0C207), UL64(0xEADA7DD6CDE0EB1E), UL64(0xF57D4F7FEE6ED178), UL64(0x06F067AA72176FBA), UL64(0x0A637DC5A2C898A6), + UL64(0x113F9804BEF90DAE), UL64(0x1B710B35131C471B), UL64(0x28DB77F523047D84), UL64(0x32CAAB7B40C72493), UL64(0x3C9EBE0A15C9BEBC), + UL64(0x431D67C49C100D4C), UL64(0x4CC5D4BECB3E42B6), UL64(0x597F299CFC657E2A), UL64(0x5FCB6FAB3AD6FAEC), UL64(0x6C44198C4A475817)}; + +int mbedtls_internal_sha512_process(mbedtls_sha512_context* ctx, const unsigned char data[128]) { int i; - struct - { + struct { uint64_t temp1, temp2, W[80]; uint64_t A, B, C, D, E, F, G, H; } local; - SHA512_VALIDATE_RET( ctx != NULL ); - SHA512_VALIDATE_RET( (const unsigned char *)data != NULL ); + SHA512_VALIDATE_RET(ctx != NULL); + SHA512_VALIDATE_RET((const unsigned char*)data != NULL); -#define SHR(x,n) ((x) >> (n)) -#define ROTR(x,n) (SHR((x),(n)) | ((x) << (64 - (n)))) +#define SHR(x, n) ((x) >> (n)) +#define ROTR(x, n) (SHR((x), (n)) | ((x) << (64 - (n)))) -#define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7)) -#define S1(x) (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x, 6)) +#define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7)) +#define S1(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ SHR(x, 6)) -#define S2(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39)) -#define S3(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41)) +#define S2(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39)) +#define S3(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41)) -#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) -#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) +#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define P(a,b,c,d,e,f,g,h,x,K) \ - do \ - { \ - local.temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \ - local.temp2 = S2(a) + F0((a),(b),(c)); \ - (d) += local.temp1; (h) = local.temp1 + local.temp2; \ - } while( 0 ) +#define P(a, b, c, d, e, f, g, h, x, K) \ + do { \ + local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x); \ + local.temp2 = S2(a) + F0((a), (b), (c)); \ + (d) += local.temp1; \ + (h) = local.temp1 + local.temp2; \ + } while (0) - for( i = 0; i < 16; i++ ) - { - GET_UINT64_BE( local.W[i], data, i << 3 ); + for (i = 0; i < 16; i++) { + GET_UINT64_BE(local.W[i], data, i << 3); } - for( ; i < 80; i++ ) - { - local.W[i] = S1(local.W[i - 2]) + local.W[i - 7] + - S0(local.W[i - 15]) + local.W[i - 16]; + for (; i < 80; i++) { + local.W[i] = S1(local.W[i - 2]) + local.W[i - 7] + S0(local.W[i - 15]) + local.W[i - 16]; } local.A = ctx->state[0]; @@ -293,26 +250,24 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, local.H = ctx->state[7]; i = 0; - do - { - P( local.A, local.B, local.C, local.D, local.E, - local.F, local.G, local.H, local.W[i], K[i] ); i++; - P( local.H, local.A, local.B, local.C, local.D, - local.E, local.F, local.G, local.W[i], K[i] ); i++; - P( local.G, local.H, local.A, local.B, local.C, - local.D, local.E, local.F, local.W[i], K[i] ); i++; - P( local.F, local.G, local.H, local.A, local.B, - local.C, local.D, local.E, local.W[i], K[i] ); i++; - P( local.E, local.F, local.G, local.H, local.A, - local.B, local.C, local.D, local.W[i], K[i] ); i++; - P( local.D, local.E, local.F, local.G, local.H, - local.A, local.B, local.C, local.W[i], K[i] ); i++; - P( local.C, local.D, local.E, local.F, local.G, - local.H, local.A, local.B, local.W[i], K[i] ); i++; - P( local.B, local.C, local.D, local.E, local.F, - local.G, local.H, local.A, local.W[i], K[i] ); i++; - } - while( i < 80 ); + do { + P(local.A, local.B, local.C, local.D, local.E, local.F, local.G, local.H, local.W[i], K[i]); + i++; + P(local.H, local.A, local.B, local.C, local.D, local.E, local.F, local.G, local.W[i], K[i]); + i++; + P(local.G, local.H, local.A, local.B, local.C, local.D, local.E, local.F, local.W[i], K[i]); + i++; + P(local.F, local.G, local.H, local.A, local.B, local.C, local.D, local.E, local.W[i], K[i]); + i++; + P(local.E, local.F, local.G, local.H, local.A, local.B, local.C, local.D, local.W[i], K[i]); + i++; + P(local.D, local.E, local.F, local.G, local.H, local.A, local.B, local.C, local.W[i], K[i]); + i++; + P(local.C, local.D, local.E, local.F, local.G, local.H, local.A, local.B, local.W[i], K[i]); + i++; + P(local.B, local.C, local.D, local.E, local.F, local.G, local.H, local.A, local.W[i], K[i]); + i++; + } while (i < 80); ctx->state[0] += local.A; ctx->state[1] += local.B; @@ -324,16 +279,15 @@ int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, ctx->state[7] += local.H; /* Zeroise buffers and variables to clear sensitive data from memory. */ - mbedtls_platform_zeroize( &local, sizeof( local ) ); + mbedtls_platform_zeroize(&local, sizeof(local)); - return( 0 ); + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha512_process( mbedtls_sha512_context *ctx, - const unsigned char data[128] ) +void mbedtls_sha512_process(mbedtls_sha512_context* ctx, const unsigned char data[128]) { - mbedtls_internal_sha512_process( ctx, data ); + mbedtls_internal_sha512_process(ctx, data); } #endif #endif /* !MBEDTLS_SHA512_PROCESS_ALT */ @@ -341,76 +295,69 @@ void mbedtls_sha512_process( mbedtls_sha512_context *ctx, /* * SHA-512 process buffer */ -int mbedtls_sha512_update_ret( mbedtls_sha512_context *ctx, - const unsigned char *input, - size_t ilen ) +int mbedtls_sha512_update_ret(mbedtls_sha512_context* ctx, const unsigned char* input, size_t ilen) { int ret; size_t fill; unsigned int left; - SHA512_VALIDATE_RET( ctx != NULL ); - SHA512_VALIDATE_RET( ilen == 0 || input != NULL ); + SHA512_VALIDATE_RET(ctx != NULL); + SHA512_VALIDATE_RET(ilen == 0 || input != NULL); - if( ilen == 0 ) - return( 0 ); + if (ilen == 0) + return (0); - left = (unsigned int) (ctx->total[0] & 0x7F); + left = (unsigned int)(ctx->total[0] & 0x7F); fill = 128 - left; - ctx->total[0] += (uint64_t) ilen; + ctx->total[0] += (uint64_t)ilen; - if( ctx->total[0] < (uint64_t) ilen ) + if (ctx->total[0] < (uint64_t)ilen) ctx->total[1]++; - if( left && ilen >= fill ) - { - memcpy( (void *) (ctx->buffer + left), input, fill ); + if (left && ilen >= fill) { + memcpy((void*)(ctx->buffer + left), input, fill); - if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) + return (ret); input += fill; - ilen -= fill; + ilen -= fill; left = 0; } - while( ilen >= 128 ) - { - if( ( ret = mbedtls_internal_sha512_process( ctx, input ) ) != 0 ) - return( ret ); + while (ilen >= 128) { + if ((ret = mbedtls_internal_sha512_process(ctx, input)) != 0) + return (ret); input += 128; - ilen -= 128; + ilen -= 128; } - if( ilen > 0 ) - memcpy( (void *) (ctx->buffer + left), input, ilen ); + if (ilen > 0) + memcpy((void*)(ctx->buffer + left), input, ilen); - return( 0 ); + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha512_update( mbedtls_sha512_context *ctx, - const unsigned char *input, - size_t ilen ) +void mbedtls_sha512_update(mbedtls_sha512_context* ctx, const unsigned char* input, size_t ilen) { - mbedtls_sha512_update_ret( ctx, input, ilen ); + mbedtls_sha512_update_ret(ctx, input, ilen); } #endif /* * SHA-512 final digest */ -int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx, - unsigned char output[64] ) +int mbedtls_sha512_finish_ret(mbedtls_sha512_context* ctx, unsigned char output[64]) { int ret; unsigned used; uint64_t high, low; - SHA512_VALIDATE_RET( ctx != NULL ); - SHA512_VALIDATE_RET( (unsigned char *)output != NULL ); + SHA512_VALIDATE_RET(ctx != NULL); + SHA512_VALIDATE_RET((unsigned char*)output != NULL); /* * Add padding: 0x80 then 0x00 until 16 bytes remain for the length @@ -419,59 +366,53 @@ int mbedtls_sha512_finish_ret( mbedtls_sha512_context *ctx, ctx->buffer[used++] = 0x80; - if( used <= 112 ) - { + if (used <= 112) { /* Enough room for padding + length in current block */ - memset( ctx->buffer + used, 0, 112 - used ); - } - else - { + memset(ctx->buffer + used, 0, 112 - used); + } else { /* We'll need an extra block */ - memset( ctx->buffer + used, 0, 128 - used ); + memset(ctx->buffer + used, 0, 128 - used); - if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) + return (ret); - memset( ctx->buffer, 0, 112 ); + memset(ctx->buffer, 0, 112); } /* * Add message length */ - high = ( ctx->total[0] >> 61 ) - | ( ctx->total[1] << 3 ); - low = ( ctx->total[0] << 3 ); + high = (ctx->total[0] >> 61) | (ctx->total[1] << 3); + low = (ctx->total[0] << 3); - PUT_UINT64_BE( high, ctx->buffer, 112 ); - PUT_UINT64_BE( low, ctx->buffer, 120 ); + PUT_UINT64_BE(high, ctx->buffer, 112); + PUT_UINT64_BE(low, ctx->buffer, 120); - if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) - return( ret ); + if ((ret = mbedtls_internal_sha512_process(ctx, ctx->buffer)) != 0) + return (ret); /* * Output final state */ - PUT_UINT64_BE( ctx->state[0], output, 0 ); - PUT_UINT64_BE( ctx->state[1], output, 8 ); - PUT_UINT64_BE( ctx->state[2], output, 16 ); - PUT_UINT64_BE( ctx->state[3], output, 24 ); - PUT_UINT64_BE( ctx->state[4], output, 32 ); - PUT_UINT64_BE( ctx->state[5], output, 40 ); - - if( ctx->is384 == 0 ) - { - PUT_UINT64_BE( ctx->state[6], output, 48 ); - PUT_UINT64_BE( ctx->state[7], output, 56 ); + PUT_UINT64_BE(ctx->state[0], output, 0); + PUT_UINT64_BE(ctx->state[1], output, 8); + PUT_UINT64_BE(ctx->state[2], output, 16); + PUT_UINT64_BE(ctx->state[3], output, 24); + PUT_UINT64_BE(ctx->state[4], output, 32); + PUT_UINT64_BE(ctx->state[5], output, 40); + + if (ctx->is384 == 0) { + PUT_UINT64_BE(ctx->state[6], output, 48); + PUT_UINT64_BE(ctx->state[7], output, 56); } - return( 0 ); + return (0); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, - unsigned char output[64] ) +void mbedtls_sha512_finish(mbedtls_sha512_context* ctx, unsigned char output[64]) { - mbedtls_sha512_finish_ret( ctx, output ); + mbedtls_sha512_finish_ret(ctx, output); } #endif @@ -480,42 +421,36 @@ void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, /* * output = SHA-512( input buffer ) */ -int mbedtls_sha512_ret( const unsigned char *input, - size_t ilen, - unsigned char output[64], - int is384 ) +int mbedtls_sha512_ret(const unsigned char* input, size_t ilen, unsigned char output[64], int is384) { int ret; mbedtls_sha512_context ctx; - SHA512_VALIDATE_RET( is384 == 0 || is384 == 1 ); - SHA512_VALIDATE_RET( ilen == 0 || input != NULL ); - SHA512_VALIDATE_RET( (unsigned char *)output != NULL ); + SHA512_VALIDATE_RET(is384 == 0 || is384 == 1); + SHA512_VALIDATE_RET(ilen == 0 || input != NULL); + SHA512_VALIDATE_RET((unsigned char*)output != NULL); - mbedtls_sha512_init( &ctx ); + mbedtls_sha512_init(&ctx); - if( ( ret = mbedtls_sha512_starts_ret( &ctx, is384 ) ) != 0 ) + if ((ret = mbedtls_sha512_starts_ret(&ctx, is384)) != 0) goto exit; - if( ( ret = mbedtls_sha512_update_ret( &ctx, input, ilen ) ) != 0 ) + if ((ret = mbedtls_sha512_update_ret(&ctx, input, ilen)) != 0) goto exit; - if( ( ret = mbedtls_sha512_finish_ret( &ctx, output ) ) != 0 ) + if ((ret = mbedtls_sha512_finish_ret(&ctx, output)) != 0) goto exit; exit: - mbedtls_sha512_free( &ctx ); + mbedtls_sha512_free(&ctx); - return( ret ); + return (ret); } #if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_sha512( const unsigned char *input, - size_t ilen, - unsigned char output[64], - int is384 ) +void mbedtls_sha512(const unsigned char* input, size_t ilen, unsigned char output[64], int is384) { - mbedtls_sha512_ret( input, ilen, output, is384 ); + mbedtls_sha512_ret(input, ilen, output, is384); } #endif @@ -524,150 +459,109 @@ void mbedtls_sha512( const unsigned char *input, /* * FIPS-180-2 test vectors */ -static const unsigned char sha512_test_buf[3][113] = -{ - { "abc" }, - { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" - "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" }, - { "" } -}; - -static const size_t sha512_test_buflen[3] = -{ - 3, 112, 1000 -}; - -static const unsigned char sha512_test_sum[6][64] = -{ - /* - * SHA-384 test vectors - */ - { 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B, - 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07, - 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63, - 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED, - 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23, - 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7 }, - { 0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8, - 0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47, - 0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2, - 0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12, - 0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9, - 0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39 }, - { 0x9D, 0x0E, 0x18, 0x09, 0x71, 0x64, 0x74, 0xCB, - 0x08, 0x6E, 0x83, 0x4E, 0x31, 0x0A, 0x4A, 0x1C, - 0xED, 0x14, 0x9E, 0x9C, 0x00, 0xF2, 0x48, 0x52, - 0x79, 0x72, 0xCE, 0xC5, 0x70, 0x4C, 0x2A, 0x5B, - 0x07, 0xB8, 0xB3, 0xDC, 0x38, 0xEC, 0xC4, 0xEB, - 0xAE, 0x97, 0xDD, 0xD8, 0x7F, 0x3D, 0x89, 0x85 }, - - /* - * SHA-512 test vectors - */ - { 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA, - 0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31, - 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2, - 0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A, - 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8, - 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD, - 0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E, - 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F }, - { 0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA, - 0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F, - 0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, 0x7F, 0xA1, - 0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18, - 0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4, - 0x33, 0x1B, 0x99, 0xDE, 0xC4, 0xB5, 0x43, 0x3A, - 0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54, - 0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09 }, - { 0xE7, 0x18, 0x48, 0x3D, 0x0C, 0xE7, 0x69, 0x64, - 0x4E, 0x2E, 0x42, 0xC7, 0xBC, 0x15, 0xB4, 0x63, - 0x8E, 0x1F, 0x98, 0xB1, 0x3B, 0x20, 0x44, 0x28, - 0x56, 0x32, 0xA8, 0x03, 0xAF, 0xA9, 0x73, 0xEB, - 0xDE, 0x0F, 0xF2, 0x44, 0x87, 0x7E, 0xA6, 0x0A, - 0x4C, 0xB0, 0x43, 0x2C, 0xE5, 0x77, 0xC3, 0x1B, - 0xEB, 0x00, 0x9C, 0x5C, 0x2C, 0x49, 0xAA, 0x2E, - 0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B } +static const unsigned char sha512_test_buf[3][113] = { + {"abc"}, + {"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" + "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"}, + {""}}; + +static const size_t sha512_test_buflen[3] = {3, 112, 1000}; + +static const unsigned char sha512_test_sum[6][64] = { + /* + * SHA-384 test vectors + */ + {0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B, 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07, 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63, + 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED, 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23, 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7}, + {0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8, 0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47, 0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2, + 0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12, 0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9, 0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39}, + {0x9D, 0x0E, 0x18, 0x09, 0x71, 0x64, 0x74, 0xCB, 0x08, 0x6E, 0x83, 0x4E, 0x31, 0x0A, 0x4A, 0x1C, 0xED, 0x14, 0x9E, 0x9C, 0x00, 0xF2, 0x48, 0x52, + 0x79, 0x72, 0xCE, 0xC5, 0x70, 0x4C, 0x2A, 0x5B, 0x07, 0xB8, 0xB3, 0xDC, 0x38, 0xEC, 0xC4, 0xEB, 0xAE, 0x97, 0xDD, 0xD8, 0x7F, 0x3D, 0x89, 0x85}, + + /* + * SHA-512 test vectors + */ + {0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA, 0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31, 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, + 0x7E, 0xA2, 0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A, 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8, 0x36, 0xBA, 0x3C, 0x23, + 0xA3, 0xFE, 0xEB, 0xBD, 0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E, 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F}, + {0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA, 0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F, 0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, + 0x7F, 0xA1, 0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18, 0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4, 0x33, 0x1B, 0x99, 0xDE, + 0xC4, 0xB5, 0x43, 0x3A, 0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54, 0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09}, + {0xE7, 0x18, 0x48, 0x3D, 0x0C, 0xE7, 0x69, 0x64, 0x4E, 0x2E, 0x42, 0xC7, 0xBC, 0x15, 0xB4, 0x63, 0x8E, 0x1F, 0x98, 0xB1, 0x3B, 0x20, + 0x44, 0x28, 0x56, 0x32, 0xA8, 0x03, 0xAF, 0xA9, 0x73, 0xEB, 0xDE, 0x0F, 0xF2, 0x44, 0x87, 0x7E, 0xA6, 0x0A, 0x4C, 0xB0, 0x43, 0x2C, + 0xE5, 0x77, 0xC3, 0x1B, 0xEB, 0x00, 0x9C, 0x5C, 0x2C, 0x49, 0xAA, 0x2E, 0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B} }; /* * Checkup routine */ -int mbedtls_sha512_self_test( int verbose ) +int mbedtls_sha512_self_test(int verbose) { int i, j, k, buflen, ret = 0; - unsigned char *buf; + unsigned char* buf; unsigned char sha512sum[64]; mbedtls_sha512_context ctx; - buf = mbedtls_calloc( 1024, sizeof(unsigned char) ); - if( NULL == buf ) - { - if( verbose != 0 ) - mbedtls_printf( "Buffer allocation failed\n" ); + buf = mbedtls_calloc(1024, sizeof(unsigned char)); + if (NULL == buf) { + if (verbose != 0) + mbedtls_printf("Buffer allocation failed\n"); - return( 1 ); + return (1); } - mbedtls_sha512_init( &ctx ); + mbedtls_sha512_init(&ctx); - for( i = 0; i < 6; i++ ) - { + for (i = 0; i < 6; i++) { j = i % 3; k = i < 3; - if( verbose != 0 ) - mbedtls_printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 ); + if (verbose != 0) + mbedtls_printf(" SHA-%d test #%d: ", 512 - k * 128, j + 1); - if( ( ret = mbedtls_sha512_starts_ret( &ctx, k ) ) != 0 ) + if ((ret = mbedtls_sha512_starts_ret(&ctx, k)) != 0) goto fail; - if( j == 2 ) - { - memset( buf, 'a', buflen = 1000 ); + if (j == 2) { + memset(buf, 'a', buflen = 1000); - for( j = 0; j < 1000; j++ ) - { - ret = mbedtls_sha512_update_ret( &ctx, buf, buflen ); - if( ret != 0 ) + for (j = 0; j < 1000; j++) { + ret = mbedtls_sha512_update_ret(&ctx, buf, buflen); + if (ret != 0) goto fail; } - } - else - { - ret = mbedtls_sha512_update_ret( &ctx, sha512_test_buf[j], - sha512_test_buflen[j] ); - if( ret != 0 ) + } else { + ret = mbedtls_sha512_update_ret(&ctx, sha512_test_buf[j], sha512_test_buflen[j]); + if (ret != 0) goto fail; } - if( ( ret = mbedtls_sha512_finish_ret( &ctx, sha512sum ) ) != 0 ) + if ((ret = mbedtls_sha512_finish_ret(&ctx, sha512sum)) != 0) goto fail; - if( memcmp( sha512sum, sha512_test_sum[i], 64 - k * 16 ) != 0 ) - { + if (memcmp(sha512sum, sha512_test_sum[i], 64 - k * 16) != 0) { ret = 1; goto fail; } - if( verbose != 0 ) - mbedtls_printf( "passed\n" ); + if (verbose != 0) + mbedtls_printf("passed\n"); } - if( verbose != 0 ) - mbedtls_printf( "\n" ); + if (verbose != 0) + mbedtls_printf("\n"); goto exit; fail: - if( verbose != 0 ) - mbedtls_printf( "failed\n" ); + if (verbose != 0) + mbedtls_printf("failed\n"); exit: - mbedtls_sha512_free( &ctx ); - mbedtls_free( buf ); + mbedtls_sha512_free(&ctx); + mbedtls_free(buf); - return( ret ); + return (ret); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/nettls/ssl/ssl_ciphersuites.c b/nettls/ssl/ssl_ciphersuites.c index e06bcf912a3beb5f166a3b67233ed83a2108cdbc..c8f492bbca60dc3911eb0bdeeaeed53ad6a5b176 100644 --- a/nettls/ssl/ssl_ciphersuites.c +++ b/nettls/ssl/ssl_ciphersuites.c @@ -86,12 +86,10 @@ static const int ciphersuite_preference[] = { MBEDTLS_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256, /* All AES-256 ephemeral suites */ - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8, /* All CAMELLIA-256 ephemeral suites */ @@ -101,17 +99,14 @@ static const int ciphersuite_preference[] = { MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, /* All ARIA-256 ephemeral suites */ - MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384, - MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384, - MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384, /* All AES-128 ephemeral suites */ - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, - MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8, /* All CAMELLIA-128 ephemeral suites */ @@ -121,102 +116,85 @@ static const int ciphersuite_preference[] = { MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, /* All ARIA-128 ephemeral suites */ - MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256, - MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256, - MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256, MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256, MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256, MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256, /* The PSK ephemeral suites */ MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256, - MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM, - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA, + MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM, MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, + MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384, - MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8, - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384, - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384, + MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8, MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384, + MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384, - MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM, - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256, - MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA, + MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM, MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, + MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, - MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8, - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256, - MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256, + MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8, MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256, + MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256, /* The ECJPAKE suite */ MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8, /* All AES-256 suites */ MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_RSA_WITH_AES_256_CCM, MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256, - MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, - MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, + MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, + MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8, /* All CAMELLIA-256 suites */ - MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256, - MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384, - MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384, MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384, - MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384, + MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256, MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, + MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384, + MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384, /* All ARIA-256 suites */ - MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384, - MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384, - MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384, + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384, + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384, /* All AES-128 suites */ MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_RSA_WITH_AES_128_CCM, MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256, - MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, - MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, - MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, + MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, + MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8, /* All CAMELLIA-128 suites */ - MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256, - MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256, - MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256, - MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256, + MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, + MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256, + MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256, /* All ARIA-128 suites */ - MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256, - MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256, - MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256, MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256, + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256, + MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256, MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256, MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256, /* The RSA PSK suites */ - MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384, - MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA, - MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384, + MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, + MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384, - MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256, - MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256, - MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256, + MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA, + MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256, /* The PSK suites */ - MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256, MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384, - MBEDTLS_TLS_PSK_WITH_AES_256_CCM, MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA, - MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384, MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384, - MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384, + MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256, MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_PSK_WITH_AES_256_CCM, + MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384, MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA, MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384, + MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384, MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384, MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384, MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_PSK_WITH_AES_128_CCM, MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256, - MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256, - MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8, - MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256, + MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA, MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256, + MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8, MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256, MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256, /* 3DES suites */ - MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA, /* RC4 suites */ - MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA, - MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA, MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA, MBEDTLS_TLS_RSA_WITH_RC4_128_SHA, - MBEDTLS_TLS_RSA_WITH_RC4_128_MD5, MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA, MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA, - MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA, MBEDTLS_TLS_PSK_WITH_RC4_128_SHA, + MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA, MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA, + MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA, MBEDTLS_TLS_RSA_WITH_RC4_128_SHA, MBEDTLS_TLS_RSA_WITH_RC4_128_MD5, MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA, + MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA, MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA, MBEDTLS_TLS_PSK_WITH_RC4_128_SHA, /* Weak suites */ MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA, MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA, @@ -226,10 +204,9 @@ static const int ciphersuite_preference[] = { MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256, MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA, MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA, - MBEDTLS_TLS_RSA_WITH_NULL_SHA256, MBEDTLS_TLS_RSA_WITH_NULL_SHA, MBEDTLS_TLS_RSA_WITH_NULL_MD5, - MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA, MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA, MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384, - MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA, MBEDTLS_TLS_PSK_WITH_NULL_SHA384, - MBEDTLS_TLS_PSK_WITH_NULL_SHA256, MBEDTLS_TLS_PSK_WITH_NULL_SHA, + MBEDTLS_TLS_RSA_WITH_NULL_SHA256, MBEDTLS_TLS_RSA_WITH_NULL_SHA, MBEDTLS_TLS_RSA_WITH_NULL_MD5, MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA, + MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA, MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256, + MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA, MBEDTLS_TLS_PSK_WITH_NULL_SHA384, MBEDTLS_TLS_PSK_WITH_NULL_SHA256, MBEDTLS_TLS_PSK_WITH_NULL_SHA, #endif /* MBEDTLS_SSL_CIPHERSUITES */ 0}; @@ -237,39 +214,38 @@ static const int ciphersuite_preference[] = { static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CHACHAPOLY_C) && defined(MBEDTLS_SHA256_C) && defined(MBEDTLS_SSL_PROTO_TLS1_2) #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) - {MBEDTLS_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, "TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256", - MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, "TLS-ECDHE-RSA-WITH-CHACHA20-POLY1305-SHA256", MBEDTLS_CIPHER_CHACHA20_POLY1305, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, "TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256", - MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, "TLS-ECDHE-ECDSA-WITH-CHACHA20-POLY1305-SHA256", MBEDTLS_CIPHER_CHACHA20_POLY1305, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) - {MBEDTLS_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256, "TLS-DHE-RSA-WITH-CHACHA20-POLY1305-SHA256", - MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256, "TLS-DHE-RSA-WITH-CHACHA20-POLY1305-SHA256", MBEDTLS_CIPHER_CHACHA20_POLY1305, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) - {MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-PSK-WITH-CHACHA20-POLY1305-SHA256", - MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-PSK-WITH-CHACHA20-POLY1305-SHA256", MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) - {MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-ECDHE-PSK-WITH-CHACHA20-POLY1305-SHA256", - MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-ECDHE-PSK-WITH-CHACHA20-POLY1305-SHA256", MBEDTLS_CIPHER_CHACHA20_POLY1305, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) - {MBEDTLS_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-DHE-PSK-WITH-CHACHA20-POLY1305-SHA256", - MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-DHE-PSK-WITH-CHACHA20-POLY1305-SHA256", MBEDTLS_CIPHER_CHACHA20_POLY1305, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) - {MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-RSA-PSK-WITH-CHACHA20-POLY1305-SHA256", - MBEDTLS_CIPHER_CHACHA20_POLY1305, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256, "TLS-RSA-PSK-WITH-CHACHA20-POLY1305-SHA256", MBEDTLS_CIPHER_CHACHA20_POLY1305, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_CHACHAPOLY_C && \ MBEDTLS_SHA256_C && \ @@ -278,78 +254,78 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_SHA1_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256", - MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, "TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256", - MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384", - MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, "TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, "TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384", - MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, "TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA512_C */ #if defined(MBEDTLS_CCM_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, "TLS-ECDHE-ECDSA-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, "TLS-ECDHE-ECDSA-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, "TLS-ECDHE-ECDSA-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, "TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, "TLS-ECDHE-ECDSA-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, "TLS-ECDHE-ECDSA-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, "TLS-ECDHE-ECDSA-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, "TLS-ECDHE-ECDSA-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDHE-ECDSA-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -357,26 +333,25 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA", - MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDHE-ECDSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, "TLS-ECDHE-ECDSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, "TLS-ECDHE-ECDSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #if defined(MBEDTLS_CIPHER_NULL_CIPHER) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA, "TLS-ECDHE-ECDSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_NULL_SHA, "TLS-ECDHE-ECDSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_NULL_CIPHER */ #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */ @@ -385,36 +360,36 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_SHA1_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, "TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, "TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, "TLS-ECDHE-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, "TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, "TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, "TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_AES_C */ @@ -422,27 +397,27 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDHE-RSA-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDHE-RSA-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDHE-RSA-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDHE-RSA-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDHE-RSA-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDHE-RSA-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -450,26 +425,25 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDHE-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDHE-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA, "TLS-ECDHE-RSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_RC4_128_SHA, "TLS-ECDHE-RSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #if defined(MBEDTLS_CIPHER_NULL_CIPHER) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA, "TLS-ECDHE-RSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_NULL_SHA, "TLS-ECDHE-RSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_NULL_CIPHER */ #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED */ @@ -477,89 +451,89 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_SHA512_C) && defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, "TLS-DHE-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, "TLS-DHE-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C && MBEDTLS_GCM_C */ #if defined(MBEDTLS_SHA256_C) #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, "TLS-DHE-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, "TLS-DHE-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, "TLS-DHE-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, "TLS-DHE-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, - {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, "TLS-DHE-RSA-WITH-AES-256-CBC-SHA256", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, "TLS-DHE-RSA-WITH-AES-256-CBC-SHA256", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA, "TLS-DHE-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CBC_SHA, "TLS-DHE-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, - {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA, "TLS-DHE-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CBC_SHA, "TLS-DHE-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CCM_C) - {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM, "TLS-DHE-RSA-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8, "TLS-DHE-RSA-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, - {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM, "TLS-DHE-RSA-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8, "TLS-DHE-RSA-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM, "TLS-DHE-RSA-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_256_CCM_8, "TLS-DHE-RSA-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM, "TLS-DHE-RSA-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_AES_128_CCM_8, "TLS-DHE-RSA-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, - {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256, "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256, "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, "TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA", MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, - {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA, "TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA", MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-DHE-RSA-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-DHE-RSA-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-DHE-RSA-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-DHE-RSA-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -567,9 +541,9 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-DHE-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ @@ -578,90 +552,76 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_SHA512_C) && defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384, "TLS-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_256_GCM_SHA384, "TLS-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C && MBEDTLS_GCM_C */ #if defined(MBEDTLS_SHA256_C) #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256, "TLS-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256, "TLS-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256, "TLS-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA256, "TLS-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256, "TLS-RSA-WITH-AES-256-CBC-SHA256", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA256, "TLS-RSA-WITH-AES-256-CBC-SHA256", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA1_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA, "TLS-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_128_CBC_SHA, "TLS-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA, "TLS-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_256_CBC_SHA, "TLS-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_CCM_C) - {MBEDTLS_TLS_RSA_WITH_AES_256_CCM, "TLS-RSA-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8, "TLS-RSA-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, - {MBEDTLS_TLS_RSA_WITH_AES_128_CCM, "TLS-RSA-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8, "TLS-RSA-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, + {MBEDTLS_TLS_RSA_WITH_AES_256_CCM, "TLS-RSA-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_256_CCM_8, "TLS-RSA-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, + {MBEDTLS_TLS_RSA_WITH_AES_128_CCM, "TLS-RSA-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_AES_128_CCM_8, "TLS-RSA-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256, "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256, "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA", MBEDTLS_CIPHER_CAMELLIA_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA, "TLS-RSA-WITH-CAMELLIA-128-CBC-SHA", MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA", MBEDTLS_CIPHER_CAMELLIA_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA, "TLS-RSA-WITH-CAMELLIA-256-CBC-SHA", MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-RSA-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-RSA-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-RSA-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-RSA-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -669,24 +629,21 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_MD5_C) - {MBEDTLS_TLS_RSA_WITH_RC4_128_MD5, "TLS-RSA-WITH-RC4-128-MD5", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_MD5, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_RSA_WITH_RC4_128_MD5, "TLS-RSA-WITH-RC4-128-MD5", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_MD5, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_WITH_RC4_128_SHA, "TLS-RSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_RSA_WITH_RC4_128_SHA, "TLS-RSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif #endif /* MBEDTLS_ARC4_C */ #endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */ @@ -695,36 +652,36 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_SHA1_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, "TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, "TLS-ECDH-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, "TLS-ECDH-RSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, "TLS-ECDH-RSA-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, "TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, "TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_AES_C */ @@ -732,27 +689,27 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDH-RSA-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDH-RSA-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDH-RSA-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDH-RSA-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDH-RSA-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDH-RSA-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -760,26 +717,24 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDH-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDH-RSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA, "TLS-ECDH-RSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_ECDH_RSA_WITH_RC4_128_SHA, "TLS-ECDH-RSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #if defined(MBEDTLS_CIPHER_NULL_CIPHER) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA, "TLS-ECDH-RSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_ECDH_RSA_WITH_NULL_SHA, "TLS-ECDH-RSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_NULL_CIPHER */ #endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED */ @@ -788,36 +743,36 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_SHA1_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256", - MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, "TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, "TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256", - MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, "TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384", - MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, "TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, "TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384", - MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, "TLS-ECDH-ECDSA-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_AES_C */ @@ -825,27 +780,27 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256, "TLS-ECDH-ECDSA-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384, "TLS-ECDH-ECDSA-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -853,26 +808,25 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, "TLS-ECDH-ECDSA-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA, "TLS-ECDH-ECDSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_RC4_128_SHA, "TLS-ECDH-ECDSA-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #if defined(MBEDTLS_CIPHER_NULL_CIPHER) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA, "TLS-ECDH-ECDSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_NULL_SHA, "TLS-ECDH-ECDSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_NULL_CIPHER */ #endif /* MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */ @@ -881,83 +835,71 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256, "TLS-PSK-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256, "TLS-PSK-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384, "TLS-PSK-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384, "TLS-PSK-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256, "TLS-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA256, "TLS-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384, "TLS-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA384, "TLS-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA, "TLS-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_128_CBC_SHA, "TLS-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA, "TLS-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_256_CBC_SHA, "TLS-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CCM_C) - {MBEDTLS_TLS_PSK_WITH_AES_256_CCM, "TLS-PSK-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, "TLS-PSK-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, - {MBEDTLS_TLS_PSK_WITH_AES_128_CCM, "TLS-PSK-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8, "TLS-PSK-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, + {MBEDTLS_TLS_PSK_WITH_AES_256_CCM, "TLS-PSK-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_256_CCM_8, "TLS-PSK-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, + {MBEDTLS_TLS_PSK_WITH_AES_128_CCM, "TLS-PSK-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8, "TLS-PSK-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-PSK-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-PSK-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-PSK-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-PSK-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256, "TLS-PSK-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256, "TLS-PSK-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384, "TLS-PSK-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384, "TLS-PSK-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -965,18 +907,16 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_PSK_WITH_RC4_128_SHA, "TLS-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_PSK_WITH_RC4_128_SHA, "TLS-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */ @@ -985,83 +925,83 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256, "TLS-DHE-PSK-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256, "TLS-DHE-PSK-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, "TLS-DHE-PSK-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, "TLS-DHE-PSK-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256, "TLS-DHE-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256, "TLS-DHE-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, "TLS-DHE-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, "TLS-DHE-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA, "TLS-DHE-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CBC_SHA, "TLS-DHE-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, - {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA, "TLS-DHE-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CBC_SHA, "TLS-DHE-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CCM_C) - {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM, "TLS-DHE-PSK-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8, "TLS-DHE-PSK-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, - {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM, "TLS-DHE-PSK-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8, "TLS-DHE-PSK-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM, "TLS-DHE-PSK-WITH-AES-256-CCM", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM_8, "TLS-DHE-PSK-WITH-AES-256-CCM-8", MBEDTLS_CIPHER_AES_256_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM, "TLS-DHE-PSK-WITH-AES-128-CCM", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8, "TLS-DHE-PSK-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-DHE-PSK-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-DHE-PSK-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-DHE-PSK-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-DHE-PSK-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256, "TLS-DHE-PSK-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256, "TLS-DHE-PSK-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384, "TLS-DHE-PSK-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384, "TLS-DHE-PSK-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -1069,18 +1009,17 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-DHE-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-DHE-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA, "TLS-DHE-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_DHE_PSK_WITH_RC4_128_SHA, "TLS-DHE-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #endif /* MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */ @@ -1090,25 +1029,25 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, "TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, "TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, "TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, "TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, "TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, "TLS-ECDHE-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, - {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, "TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, "TLS-ECDHE-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_AES_C */ @@ -1116,15 +1055,15 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDHE-PSK-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-ECDHE-PSK-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, + MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDHE-PSK-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-ECDHE-PSK-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, + MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -1132,18 +1071,18 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-ECDHE-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-ECDHE-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA, "TLS-ECDHE-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_RC4_128_SHA, "TLS-ECDHE-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ @@ -1152,39 +1091,39 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256, "TLS-RSA-PSK-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256, "TLS-RSA-PSK-WITH-AES-128-GCM-SHA256", MBEDTLS_CIPHER_AES_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384, "TLS-RSA-PSK-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384, "TLS-RSA-PSK-WITH-AES-256-GCM-SHA384", MBEDTLS_CIPHER_AES_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256, "TLS-RSA-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256, "TLS-RSA-PSK-WITH-AES-128-CBC-SHA256", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, "TLS-RSA-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, "TLS-RSA-PSK-WITH-AES-256-CBC-SHA384", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA, "TLS-RSA-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_AES_128_CBC_SHA, "TLS-RSA-PSK-WITH-AES-128-CBC-SHA", MBEDTLS_CIPHER_AES_128_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, - {MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA, "TLS-RSA-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA, "TLS-RSA-PSK-WITH-AES-256-CBC-SHA", MBEDTLS_CIPHER_AES_256_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_AES_C */ @@ -1192,29 +1131,29 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CAMELLIA_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-RSA-PSK-WITH-CAMELLIA-128-CBC-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256, "TLS-RSA-PSK-WITH-CAMELLIA-128-CBC-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-RSA-PSK-WITH-CAMELLIA-256-CBC-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384, "TLS-RSA-PSK-WITH-CAMELLIA-256-CBC-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256, "TLS-RSA-PSK-WITH-CAMELLIA-128-GCM-SHA256", - MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256, "TLS-RSA-PSK-WITH-CAMELLIA-128-GCM-SHA256", MBEDTLS_CIPHER_CAMELLIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA256_C */ #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384, "TLS-RSA-PSK-WITH-CAMELLIA-256-GCM-SHA384", - MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384, "TLS-RSA-PSK-WITH-CAMELLIA-256-GCM-SHA384", MBEDTLS_CIPHER_CAMELLIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA512_C */ #endif /* MBEDTLS_GCM_C */ #endif /* MBEDTLS_CAMELLIA_C */ @@ -1222,18 +1161,17 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_DES_C) #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-RSA-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA, "TLS-RSA-PSK-WITH-3DES-EDE-CBC-SHA", MBEDTLS_CIPHER_DES_EDE3_CBC, MBEDTLS_MD_SHA1, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_ARC4_C) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA, "TLS-RSA-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, + {MBEDTLS_TLS_RSA_PSK_WITH_RC4_128_SHA, "TLS-RSA-PSK-WITH-RC4-128-SHA", MBEDTLS_CIPHER_ARC4_128, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_NODTLS }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_ARC4_C */ #endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */ @@ -1241,9 +1179,9 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) #if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_CCM_C) - {MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8, "TLS-ECJPAKE-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECJPAKE, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_SHORT_TAG}, + {MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8, "TLS-ECJPAKE-WITH-AES-128-CCM-8", MBEDTLS_CIPHER_AES_128_CCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECJPAKE, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + MBEDTLS_CIPHERSUITE_SHORT_TAG }, #endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_AES_C */ #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ @@ -1252,101 +1190,86 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CIPHER_NULL_CIPHER) #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) #if defined(MBEDTLS_MD5_C) - {MBEDTLS_TLS_RSA_WITH_NULL_MD5, "TLS-RSA-WITH-NULL-MD5", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_MD5, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_RSA_WITH_NULL_MD5, "TLS-RSA-WITH-NULL-MD5", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_MD5, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_WITH_NULL_SHA, "TLS-RSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_RSA_WITH_NULL_SHA, "TLS-RSA-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_WITH_NULL_SHA256, "TLS-RSA-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_RSA_WITH_NULL_SHA256, "TLS-RSA-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_PSK_WITH_NULL_SHA, "TLS-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_PSK_WITH_NULL_SHA, "TLS-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_PSK_WITH_NULL_SHA256, "TLS-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_PSK_WITH_NULL_SHA256, "TLS-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_PSK_WITH_NULL_SHA384, "TLS-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, - MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_PSK_WITH_NULL_SHA384, "TLS-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA, "TLS-DHE-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA, "TLS-DHE-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256, "TLS-DHE-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA256, "TLS-DHE-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384, "TLS-DHE-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, - MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_DHE_PSK_WITH_NULL_SHA384, "TLS-DHE-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA, "TLS-ECDHE-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA, "TLS-ECDHE-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256, "TLS-ECDHE-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA256, "TLS-ECDHE-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384, "TLS-ECDHE-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, - MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_NULL_SHA384, "TLS-ECDHE-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA, "TLS-RSA-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA, "TLS-RSA-PSK-WITH-NULL-SHA", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #if defined(MBEDTLS_SHA256_C) - {MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256, "TLS-RSA-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, - MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA256, "TLS-RSA-PSK-WITH-NULL-SHA256", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #if defined(MBEDTLS_SHA512_C) - {MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384, "TLS-RSA-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, - MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_RSA_PSK_WITH_NULL_SHA384, "TLS-RSA-PSK-WITH-NULL-SHA384", MBEDTLS_CIPHER_NULL, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA_PSK, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_1, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */ #endif /* MBEDTLS_CIPHER_NULL_CIPHER */ @@ -1355,17 +1278,15 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_CIPHER_MODE_CBC) #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA, "TLS-DHE-RSA-WITH-DES-CBC-SHA", MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_DHE_RSA_WITH_DES_CBC_SHA, "TLS-DHE-RSA-WITH-DES-CBC-SHA", MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_DHE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) #if defined(MBEDTLS_SHA1_C) - {MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA, "TLS-RSA-WITH-DES-CBC-SHA", MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MD_SHA1, - MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, + {MBEDTLS_TLS_RSA_WITH_DES_CBC_SHA, "TLS-RSA-WITH-DES-CBC-SHA", MBEDTLS_CIPHER_DES_CBC, MBEDTLS_MD_SHA1, MBEDTLS_KEY_EXCHANGE_RSA, + MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_0, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_CIPHERSUITE_WEAK }, #endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */ #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -1377,24 +1298,20 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-RSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-RSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-RSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-RSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-RSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-RSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-RSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-RSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED */ @@ -1402,24 +1319,24 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384, "TLS-RSA-PSK-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384, "TLS-RSA-PSK-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-RSA-PSK-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-RSA-PSK-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256, "TLS-RSA-PSK-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256, "TLS-RSA-PSK-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-RSA-PSK-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-RSA-PSK-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_RSA_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */ @@ -1427,24 +1344,20 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384, "TLS-PSK-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384, "TLS-PSK-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-PSK-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-PSK-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256, "TLS-PSK-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256, "TLS-PSK-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-PSK-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-PSK-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED */ @@ -1452,24 +1365,24 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDH-RSA-WITH-ARIA-256-GCM-SHA384", - MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDH-RSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDH-RSA-WITH-ARIA-256-CBC-SHA384", - MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDH-RSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDH-RSA-WITH-ARIA-128-GCM-SHA256", - MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDH-RSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDH-RSA-WITH-ARIA-128-CBC-SHA256", - MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDH-RSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED */ @@ -1477,24 +1390,24 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDHE-RSA-WITH-ARIA-256-GCM-SHA384", - MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDHE-RSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDHE-RSA-WITH-ARIA-256-CBC-SHA384", - MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDHE-RSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDHE-RSA-WITH-ARIA-128-GCM-SHA256", - MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDHE-RSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDHE-RSA-WITH-ARIA-128-CBC-SHA256", - MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDHE-RSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED */ @@ -1502,14 +1415,14 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-ECDHE-PSK-WITH-ARIA-256-CBC-SHA384", - MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-ECDHE-PSK-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-ECDHE-PSK-WITH-ARIA-128-CBC-SHA256", - MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-ECDHE-PSK-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED */ @@ -1517,24 +1430,24 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDHE-ECDSA-WITH-ARIA-256-GCM-SHA384", - MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDHE-ECDSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDHE-ECDSA-WITH-ARIA-256-CBC-SHA384", - MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDHE-ECDSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDHE-ECDSA-WITH-ARIA-128-GCM-SHA256", - MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDHE-ECDSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDHE-ECDSA-WITH-ARIA-128-CBC-SHA256", - MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDHE-ECDSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */ @@ -1542,24 +1455,24 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDH-ECDSA-WITH-ARIA-256-GCM-SHA384", - MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384, "TLS-ECDH-ECDSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDH-ECDSA-WITH-ARIA-256-CBC-SHA384", - MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384, "TLS-ECDH-ECDSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDH-ECDSA-WITH-ARIA-128-GCM-SHA256", - MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256, "TLS-ECDH-ECDSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDH-ECDSA-WITH-ARIA-128-CBC-SHA256", - MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, - MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256, "TLS-ECDH-ECDSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, + MBEDTLS_SSL_MINOR_VERSION_3, 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED */ @@ -1567,24 +1480,24 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-DHE-RSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384, "TLS-DHE-RSA-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-DHE-RSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384, "TLS-DHE-RSA-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-DHE-RSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256, "TLS-DHE-RSA-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-DHE-RSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256, "TLS-DHE-RSA-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_RSA, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED */ @@ -1592,31 +1505,31 @@ static const mbedtls_ssl_ciphersuite_t ciphersuite_definitions[] = { #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384, "TLS-DHE-PSK-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384, "TLS-DHE-PSK-WITH-ARIA-256-GCM-SHA384", MBEDTLS_CIPHER_ARIA_256_GCM, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA512_C)) - {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-DHE-PSK-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, - MBEDTLS_MD_SHA384, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384, "TLS-DHE-PSK-WITH-ARIA-256-CBC-SHA384", MBEDTLS_CIPHER_ARIA_256_CBC, MBEDTLS_MD_SHA384, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256, "TLS-DHE-PSK-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256, "TLS-DHE-PSK-WITH-ARIA-128-GCM-SHA256", MBEDTLS_CIPHER_ARIA_128_GCM, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #if (defined(MBEDTLS_CIPHER_MODE_CBC) && defined(MBEDTLS_SHA256_C)) - {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-DHE-PSK-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, - MBEDTLS_MD_SHA256, MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, - MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, 0 }, + {MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256, "TLS-DHE-PSK-WITH-ARIA-128-CBC-SHA256", MBEDTLS_CIPHER_ARIA_128_CBC, MBEDTLS_MD_SHA256, + MBEDTLS_KEY_EXCHANGE_DHE_PSK, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3, + 0 }, #endif #endif /* MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */ #endif /* MBEDTLS_ARIA_C */ - {0, "", MBEDTLS_CIPHER_NONE, MBEDTLS_MD_NONE, MBEDTLS_KEY_EXCHANGE_NONE, 0, 0, 0, 0, 0 } + {0, "", MBEDTLS_CIPHER_NONE, MBEDTLS_MD_NONE, MBEDTLS_KEY_EXCHANGE_NONE, 0, 0, 0, 0, 0 } }; #if defined(MBEDTLS_SSL_CIPHERSUITES) @@ -1657,8 +1570,7 @@ const int* mbedtls_ssl_list_ciphersuites(void) const int* p; int* q; - for (p = ciphersuite_preference, q = supported_ciphersuites; - *p != 0 && q < supported_ciphersuites + MAX_CIPHERSUITES - 1; p++) { + for (p = ciphersuite_preference, q = supported_ciphersuites; *p != 0 && q < supported_ciphersuites + MAX_CIPHERSUITES - 1; p++) { const mbedtls_ssl_ciphersuite_t* cs_info; if ((cs_info = mbedtls_ssl_ciphersuite_from_id(*p)) != NULL && !ciphersuite_is_removed(cs_info)) { *(q++) = *p; diff --git a/nettls/ssl/ssl_cli.c b/nettls/ssl/ssl_cli.c index 6bf2b94140a784ee2cee576d3c8b363699f24f9d..81a65e7fef17275336c05f933ae81199dd3fc0ec 100644 --- a/nettls/ssl/ssl_cli.c +++ b/nettls/ssl/ssl_cli.c @@ -141,8 +141,7 @@ static int ssl_write_hostname_ext(mbedtls_ssl_context* ssl, unsigned char* buf, #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */ #if defined(MBEDTLS_SSL_RENEGOTIATION) -static int - ssl_write_renegotiation_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_renegotiation_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; @@ -180,8 +179,7 @@ static int * Only if we handle at least one key exchange that needs signatures. */ #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) -static int ssl_write_signature_algorithms_ext( - mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_signature_algorithms_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; size_t sig_alg_len = 0; @@ -270,8 +268,7 @@ static int ssl_write_signature_algorithms_ext( MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */ #if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) -static int ssl_write_supported_elliptic_curves_ext( - mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_supported_elliptic_curves_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; unsigned char* elliptic_curve_list = p + 6; @@ -328,8 +325,7 @@ static int ssl_write_supported_elliptic_curves_ext( return (0); } -static int ssl_write_supported_point_formats_ext( - mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_supported_point_formats_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; (void)ssl; /* ssl used for debugging only */ @@ -356,8 +352,7 @@ static int ssl_write_supported_point_formats_ext( MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) -static int - ssl_write_ecjpake_kkpp_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_ecjpake_kkpp_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { int ret; unsigned char* p = buf; @@ -384,8 +379,7 @@ static int if (ssl->handshake->ecjpake_cache == NULL || ssl->handshake->ecjpake_cache_len == 0) { MBEDTLS_SSL_DEBUG_MSG(3, ("generating new ecjpake parameters")); - ret = mbedtls_ecjpake_write_round_one( - &ssl->handshake->ecjpake_ctx, p + 2, end - p - 2, &kkpp_len, ssl->conf->f_rng, ssl->conf->p_rng); + ret = mbedtls_ecjpake_write_round_one(&ssl->handshake->ecjpake_ctx, p + 2, end - p - 2, &kkpp_len, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_write_round_one", ret); return (ret); @@ -418,8 +412,7 @@ static int #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) -static int ssl_write_max_fragment_length_ext( - mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_max_fragment_length_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; @@ -447,8 +440,7 @@ static int ssl_write_max_fragment_length_ext( #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */ #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) -static int - ssl_write_truncated_hmac_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_truncated_hmac_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; @@ -474,15 +466,13 @@ static int #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */ #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) -static int - ssl_write_encrypt_then_mac_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_encrypt_then_mac_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; *olen = 0; - if (ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED - || ssl->conf->max_minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) + if (ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED || ssl->conf->max_minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) return (0); MBEDTLS_SSL_DEBUG_MSG(3, ("client hello, adding encrypt_then_mac extension")); @@ -502,15 +492,13 @@ static int #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */ #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) -static int - ssl_write_extended_ms_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_extended_ms_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; *olen = 0; - if (ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED - || ssl->conf->max_minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) + if (ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED || ssl->conf->max_minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) return (0); MBEDTLS_SSL_DEBUG_MSG(3, ("client hello, adding extended_master_secret extension")); @@ -530,8 +518,7 @@ static int #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */ #if defined(MBEDTLS_SSL_SESSION_TICKETS) -static int - ssl_write_session_ticket_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) +static int ssl_write_session_ticket_ext(mbedtls_ssl_context* ssl, unsigned char* buf, const unsigned char* end, size_t* olen) { unsigned char* p = buf; size_t tlen = ssl->session_negotiate->ticket_len; @@ -675,8 +662,7 @@ static int ssl_generate_random(mbedtls_ssl_context* ssl) * * \return 0 if valid, else 1 */ -static int ssl_validate_ciphersuite( - const mbedtls_ssl_ciphersuite_t* suite_info, const mbedtls_ssl_context* ssl, int min_minor_ver, int max_minor_ver) +static int ssl_validate_ciphersuite(const mbedtls_ssl_ciphersuite_t* suite_info, const mbedtls_ssl_context* ssl, int min_minor_ver, int max_minor_ver) { (void)ssl; if (suite_info == NULL) @@ -696,8 +682,7 @@ static int ssl_validate_ciphersuite( #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) - if (suite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE - && mbedtls_ecjpake_check(&ssl->handshake->ecjpake_ctx) != 0) + if (suite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE && mbedtls_ecjpake_check(&ssl->handshake->ecjpake_ctx) != 0) return (1); #endif @@ -863,8 +848,7 @@ int ssl_write_client_hello(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(3, ("no verify cookie to send")); *p++ = 0; } else { - MBEDTLS_SSL_DEBUG_BUF( - 3, "client hello, cookie", ssl->handshake->verify_cookie, ssl->handshake->verify_cookie_len); + MBEDTLS_SSL_DEBUG_BUF(3, "client hello, cookie", ssl->handshake->verify_cookie, ssl->handshake->verify_cookie_len); *p++ = ssl->handshake->verify_cookie_len; @@ -952,8 +936,7 @@ int ssl_write_client_hello(mbedtls_ssl_context* ssl) if (offer_compress) { MBEDTLS_SSL_DEBUG_MSG(3, ("client hello, compress len.: %d", 2)); - MBEDTLS_SSL_DEBUG_MSG( - 3, ("client hello, compress alg.: %d %d", MBEDTLS_SSL_COMPRESS_DEFLATE, MBEDTLS_SSL_COMPRESS_NULL)); + MBEDTLS_SSL_DEBUG_MSG(3, ("client hello, compress alg.: %d %d", MBEDTLS_SSL_COMPRESS_DEFLATE, MBEDTLS_SSL_COMPRESS_NULL)); MBEDTLS_SSL_CHK_BUF_PTR(p, end, 3); *p++ = 2; @@ -1118,8 +1101,7 @@ static int ssl_parse_renegotiation_info(mbedtls_ssl_context* ssl, const unsigned /* Check verify-data in constant-time. The length OTOH is no secret */ if (len != 1 + ssl->verify_data_len * 2 || buf[0] != ssl->verify_data_len * 2 || mbedtls_ssl_safer_memcmp(buf + 1, ssl->own_verify_data, ssl->verify_data_len) != 0 - || mbedtls_ssl_safer_memcmp(buf + 1 + ssl->verify_data_len, ssl->peer_verify_data, ssl->verify_data_len) - != 0) { + || mbedtls_ssl_safer_memcmp(buf + 1 + ssl->verify_data_len, ssl->peer_verify_data, ssl->verify_data_len) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("non-matching renegotiation info")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); return (MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO); @@ -1176,8 +1158,7 @@ static int ssl_parse_truncated_hmac_ext(mbedtls_ssl_context* ssl, const unsigned #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) static int ssl_parse_encrypt_then_mac_ext(mbedtls_ssl_context* ssl, const unsigned char* buf, size_t len) { - if (ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 - || len != 0) { + if (ssl->conf->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 || len != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("non-matching encrypt-then-MAC extension")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); return (MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO); @@ -1194,8 +1175,7 @@ static int ssl_parse_encrypt_then_mac_ext(mbedtls_ssl_context* ssl, const unsign #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) static int ssl_parse_extended_ms_ext(mbedtls_ssl_context* ssl, const unsigned char* buf, size_t len) { - if (ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 - || len != 0) { + if (ssl->conf->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 || len != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("non-matching extended master secret extension")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); return (MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO); @@ -1379,8 +1359,8 @@ static int ssl_parse_hello_verify_request(mbedtls_ssl_context* ssl) * Since the RFC is not clear on this point, accept DTLS 1.0 (TLS 1.1) * even is lower than our min version. */ - if (major_ver < MBEDTLS_SSL_MAJOR_VERSION_3 || minor_ver < MBEDTLS_SSL_MINOR_VERSION_2 - || major_ver > ssl->conf->max_major_ver || minor_ver > ssl->conf->max_minor_ver) { + if (major_ver < MBEDTLS_SSL_MAJOR_VERSION_3 || minor_ver < MBEDTLS_SSL_MINOR_VERSION_2 || major_ver > ssl->conf->max_major_ver + || minor_ver > ssl->conf->max_minor_ver) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad server version")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION); @@ -1502,12 +1482,11 @@ static int ssl_parse_server_hello(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_BUF(3, "server hello, version", buf + 0, 2); mbedtls_ssl_read_version(&ssl->major_ver, &ssl->minor_ver, ssl->conf->transport, buf + 0); - if (ssl->major_ver < ssl->conf->min_major_ver || ssl->minor_ver < ssl->conf->min_minor_ver - || ssl->major_ver > ssl->conf->max_major_ver || ssl->minor_ver > ssl->conf->max_minor_ver) { + if (ssl->major_ver < ssl->conf->min_major_ver || ssl->minor_ver < ssl->conf->min_minor_ver || ssl->major_ver > ssl->conf->max_major_ver + || ssl->minor_ver > ssl->conf->max_minor_ver) { MBEDTLS_SSL_DEBUG_MSG( - 1, ("server version out of bounds - min: [%d:%d], server: [%d:%d], max: [%d:%d]", ssl->conf->min_major_ver, - ssl->conf->min_minor_ver, ssl->major_ver, ssl->minor_ver, ssl->conf->max_major_ver, - ssl->conf->max_minor_ver)); + 1, ("server version out of bounds - min: [%d:%d], server: [%d:%d], max: [%d:%d]", ssl->conf->min_major_ver, ssl->conf->min_minor_ver, + ssl->major_ver, ssl->minor_ver, ssl->conf->max_major_ver, ssl->conf->max_minor_ver)); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION); @@ -1515,8 +1494,7 @@ static int ssl_parse_server_hello(mbedtls_ssl_context* ssl) } MBEDTLS_SSL_DEBUG_MSG( - 3, ("server hello, current time: %lu", - ((uint32_t)buf[2] << 24) | ((uint32_t)buf[3] << 16) | ((uint32_t)buf[4] << 8) | ((uint32_t)buf[5]))); + 3, ("server hello, current time: %lu", ((uint32_t)buf[2] << 24) | ((uint32_t)buf[3] << 16) | ((uint32_t)buf[4] << 8) | ((uint32_t)buf[5]))); memcpy(ssl->handshake->randbytes + 32, buf + 2, 32); @@ -1583,8 +1561,8 @@ static int ssl_parse_server_hello(mbedtls_ssl_context* ssl) #if defined(MBEDTLS_SSL_RENEGOTIATION) ssl->renego_status != MBEDTLS_SSL_INITIAL_HANDSHAKE || #endif - ssl->session_negotiate->ciphersuite != i || ssl->session_negotiate->compression != comp - || ssl->session_negotiate->id_len != n || memcmp(ssl->session_negotiate->id, buf + 35, n) != 0) { + ssl->session_negotiate->ciphersuite != i || ssl->session_negotiate->compression != comp || ssl->session_negotiate->id_len != n + || memcmp(ssl->session_negotiate->id, buf + 35, n) != 0) { ssl->state++; ssl->handshake->resume = 0; #if defined(MBEDTLS_HAVE_TIME) @@ -1784,19 +1762,18 @@ static int ssl_parse_server_hello(mbedtls_ssl_context* ssl) } #if defined(MBEDTLS_SSL_RENEGOTIATION) else if ( - ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS - && ssl->secure_renegotiation == MBEDTLS_SSL_SECURE_RENEGOTIATION && renegotiation_info_seen == 0) { + ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && ssl->secure_renegotiation == MBEDTLS_SSL_SECURE_RENEGOTIATION + && renegotiation_info_seen == 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("renegotiation_info extension missing (secure)")); handshake_failure = 1; } else if ( - ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS - && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION + ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && ssl->conf->allow_legacy_renegotiation == MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION) { MBEDTLS_SSL_DEBUG_MSG(1, ("legacy renegotiation not allowed")); handshake_failure = 1; } else if ( - ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS - && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && renegotiation_info_seen == 1) { + ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION + && renegotiation_info_seen == 1) { MBEDTLS_SSL_DEBUG_MSG(1, ("renegotiation_info extension present (legacy)")); handshake_failure = 1; } @@ -1832,8 +1809,7 @@ static int ssl_parse_server_dh_params(mbedtls_ssl_context* ssl, unsigned char** } if (ssl->handshake->dhm_ctx.len * 8 < ssl->conf->dhm_min_bitlen) { - MBEDTLS_SSL_DEBUG_MSG( - 1, ("DHM prime too short: %d < %d", ssl->handshake->dhm_ctx.len * 8, ssl->conf->dhm_min_bitlen)); + MBEDTLS_SSL_DEBUG_MSG(1, ("DHM prime too short: %d < %d", ssl->handshake->dhm_ctx.len * 8, ssl->conf->dhm_min_bitlen)); return (MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE); } @@ -2023,11 +1999,7 @@ static int ssl_write_encrypted_pms(mbedtls_ssl_context* ssl, size_t offset, size #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) static int ssl_parse_signature_algorithm( - mbedtls_ssl_context* ssl, - unsigned char** p, - unsigned char* end, - mbedtls_md_type_t* md_alg, - mbedtls_pk_type_t* pk_alg) + mbedtls_ssl_context* ssl, unsigned char** p, unsigned char* end, mbedtls_md_type_t* md_alg, mbedtls_pk_type_t* pk_alg) { ((void)ssl); *md_alg = MBEDTLS_MD_NONE; @@ -2128,8 +2100,7 @@ static int ssl_parse_server_key_exchange(mbedtls_ssl_context* ssl) #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) { if ((ret = ssl_get_ecdh_params_from_cert(ssl)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "ssl_get_ecdh_params_from_cert", ret); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); @@ -2167,8 +2138,7 @@ static int ssl_parse_server_key_exchange(mbedtls_ssl_context* ssl) * doesn't use a psk_identity_hint */ if (ssl->in_msg[0] != MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE) { - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK) { /* Current message is probably either * CertificateRequest or ServerHelloDone */ ssl->keep_current_message = 1; @@ -2192,10 +2162,8 @@ start_processing: MBEDTLS_SSL_DEBUG_BUF(3, "server key exchange", p, end - p); #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK) { if (ssl_parse_server_psk_hint(ssl, &p, end) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad server key exchange message")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER); @@ -2205,15 +2173,13 @@ start_processing: #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK) + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK) ; /* nothing more to do */ else #endif /* MBEDTLS_KEY_EXCHANGE_PSK_ENABLED || \ MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_RSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_RSA || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK) { if (ssl_parse_server_dh_params(ssl, &p, end) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad server key exchange message")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER); @@ -2224,8 +2190,7 @@ start_processing: MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) \ || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA) { if (ssl_parse_server_ecdh_params(ssl, &p, end) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad server key exchange message")); @@ -2268,15 +2233,13 @@ start_processing: if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3) { if (ssl_parse_signature_algorithm(ssl, &p, end, &md_alg, &pk_alg) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad server key exchange message")); - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER); return (MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE); } if (pk_alg != mbedtls_ssl_get_ciphersuite_sig_pk_alg(ciphersuite_info)) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad server key exchange message")); - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER); return (MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE); } } else @@ -2362,9 +2325,7 @@ start_processing: rs_ctx = &ssl->handshake->ecrs_ctx.pk; #endif - if ((ret = mbedtls_pk_verify_restartable( - &ssl->session_negotiate->peer_cert->pk, md_alg, hash, hashlen, p, sig_len, rs_ctx)) - != 0) { + if ((ret = mbedtls_pk_verify_restartable(&ssl->session_negotiate->peer_cert->pk, md_alg, hash, hashlen, p, sig_len, rs_ctx)) != 0) { #if defined(MBEDTLS_SSL__ECP_RESTARTABLE) if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) #endif @@ -2496,8 +2457,7 @@ static int ssl_parse_certificate_request(mbedtls_ssl_context* ssl) /* supported_signature_algorithms */ #if defined(MBEDTLS_SSL_PROTO_TLS1_2) if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3) { - size_t sig_alg_len = - ((buf[mbedtls_ssl_hs_hdr_len(ssl) + 1 + n] << 8) | (buf[mbedtls_ssl_hs_hdr_len(ssl) + 2 + n])); + size_t sig_alg_len = ((buf[mbedtls_ssl_hs_hdr_len(ssl) + 1 + n] << 8) | (buf[mbedtls_ssl_hs_hdr_len(ssl) + 2 + n])); #if defined(MBEDTLS_DEBUG_C) unsigned char* sig_alg; size_t i; @@ -2603,8 +2563,7 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) i = 6; ret = mbedtls_dhm_make_public( - &ssl->handshake->dhm_ctx, (int)mbedtls_mpi_size(&ssl->handshake->dhm_ctx.P), &ssl->out_msg[i], n, - ssl->conf->f_rng, ssl->conf->p_rng); + &ssl->handshake->dhm_ctx, (int)mbedtls_mpi_size(&ssl->handshake->dhm_ctx.P), &ssl->out_msg[i], n, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_dhm_make_public", ret); return (ret); @@ -2614,8 +2573,8 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MPI(3, "DHM: GX", &ssl->handshake->dhm_ctx.GX); if ((ret = mbedtls_dhm_calc_secret( - &ssl->handshake->dhm_ctx, ssl->handshake->premaster, MBEDTLS_PREMASTER_SIZE, &ssl->handshake->pmslen, - ssl->conf->f_rng, ssl->conf->p_rng)) + &ssl->handshake->dhm_ctx, ssl->handshake->premaster, MBEDTLS_PREMASTER_SIZE, &ssl->handshake->pmslen, ssl->conf->f_rng, + ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_dhm_calc_secret", ret); return (ret); @@ -2626,10 +2585,8 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) #endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) \ || defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) { /* * ECDH key exchange -- send client public value */ @@ -2644,8 +2601,7 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) } #endif - ret = mbedtls_ecdh_make_public( - &ssl->handshake->ecdh_ctx, &n, &ssl->out_msg[i], 1000, ssl->conf->f_rng, ssl->conf->p_rng); + ret = mbedtls_ecdh_make_public(&ssl->handshake->ecdh_ctx, &n, &ssl->out_msg[i], 1000, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_make_public", ret); #if defined(MBEDTLS_SSL__ECP_RESTARTABLE) @@ -2668,8 +2624,8 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) n = ssl->handshake->ecrs_n; #endif if ((ret = mbedtls_ecdh_calc_secret( - &ssl->handshake->ecdh_ctx, &ssl->handshake->pmslen, ssl->handshake->premaster, MBEDTLS_MPI_MAX_SIZE, - ssl->conf->f_rng, ssl->conf->p_rng)) + &ssl->handshake->ecdh_ctx, &ssl->handshake->pmslen, ssl->handshake->premaster, MBEDTLS_MPI_MAX_SIZE, ssl->conf->f_rng, + ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_calc_secret", ret); #if defined(MBEDTLS_SSL__ECP_RESTARTABLE) @@ -2736,8 +2692,7 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) ssl->out_msg[i++] = (unsigned char)(n); ret = mbedtls_dhm_make_public( - &ssl->handshake->dhm_ctx, (int)mbedtls_mpi_size(&ssl->handshake->dhm_ctx.P), &ssl->out_msg[i], n, - ssl->conf->f_rng, ssl->conf->p_rng); + &ssl->handshake->dhm_ctx, (int)mbedtls_mpi_size(&ssl->handshake->dhm_ctx.P), &ssl->out_msg[i], n, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_dhm_make_public", ret); return (ret); @@ -2750,8 +2705,7 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) * ClientECDiffieHellmanPublic public; */ ret = mbedtls_ecdh_make_public( - &ssl->handshake->ecdh_ctx, &n, &ssl->out_msg[i], MBEDTLS_SSL_OUT_CONTENT_LEN - i, ssl->conf->f_rng, - ssl->conf->p_rng); + &ssl->handshake->ecdh_ctx, &n, &ssl->out_msg[i], MBEDTLS_SSL_OUT_CONTENT_LEN - i, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_make_public", ret); return (ret); @@ -2783,16 +2737,14 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) i = 4; ret = mbedtls_ecjpake_write_round_two( - &ssl->handshake->ecjpake_ctx, ssl->out_msg + i, MBEDTLS_SSL_OUT_CONTENT_LEN - i, &n, ssl->conf->f_rng, - ssl->conf->p_rng); + &ssl->handshake->ecjpake_ctx, ssl->out_msg + i, MBEDTLS_SSL_OUT_CONTENT_LEN - i, &n, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_write_round_two", ret); return (ret); } ret = mbedtls_ecjpake_derive_secret( - &ssl->handshake->ecjpake_ctx, ssl->handshake->premaster, 32, &ssl->handshake->pmslen, ssl->conf->f_rng, - ssl->conf->p_rng); + &ssl->handshake->ecjpake_ctx, ssl->handshake->premaster, 32, &ssl->handshake->pmslen, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_derive_secret", ret); return (ret); @@ -2821,9 +2773,9 @@ static int ssl_write_client_key_exchange(mbedtls_ssl_context* ssl) return (0); } -#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) +#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) static int ssl_write_certificate_verify(mbedtls_ssl_context* ssl) { const mbedtls_ssl_ciphersuite_t* ciphersuite_info = ssl->transform_negotiate->ciphersuite_info; @@ -2836,10 +2788,8 @@ static int ssl_write_certificate_verify(mbedtls_ssl_context* ssl) return (ret); } - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip write certificate verify")); ssl->state++; @@ -2874,10 +2824,8 @@ static int ssl_write_certificate_verify(mbedtls_ssl_context* ssl) return (ret); } - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip write certificate verify")); ssl->state++; @@ -2978,8 +2926,7 @@ sign: #endif if ((ret = mbedtls_pk_sign_restartable( - mbedtls_ssl_own_key(ssl), md_alg, hash_start, hashlen, ssl->out_msg + 6 + offset, &n, ssl->conf->f_rng, - ssl->conf->p_rng, rs_ctx)) + mbedtls_ssl_own_key(ssl), md_alg, hash_start, hashlen, ssl->out_msg + 6 + offset, &n, ssl->conf->f_rng, ssl->conf->p_rng, rs_ctx)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_pk_sign", ret); #if defined(MBEDTLS_SSL__ECP_RESTARTABLE) @@ -3124,8 +3071,7 @@ int mbedtls_ssl_handshake_client_step(mbedtls_ssl_context* ssl) return (ret); #if defined(MBEDTLS_SSL_PROTO_DTLS) - if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM - && ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING) { + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING) { if ((ret = mbedtls_ssl_flight_transmit(ssl)) != 0) return (ret); } diff --git a/nettls/ssl/ssl_cookie.c b/nettls/ssl/ssl_cookie.c index bf5c4592d7b82bef041a6d0d07c50d5c57676c9d..c4d027085b7dd7c5ddc8cce551ba61e33c2ea381 100644 --- a/nettls/ssl/ssl_cookie.c +++ b/nettls/ssl/ssl_cookie.c @@ -162,8 +162,7 @@ static int ssl_cookie_hmac( MBEDTLS_SSL_CHK_BUF_PTR(*p, end, COOKIE_HMAC_LEN); if (mbedtls_md_hmac_reset(hmac_ctx) != 0 || mbedtls_md_hmac_update(hmac_ctx, time, 4) != 0 - || mbedtls_md_hmac_update(hmac_ctx, cli_id, cli_id_len) != 0 - || mbedtls_md_hmac_finish(hmac_ctx, hmac_out) != 0) { + || mbedtls_md_hmac_update(hmac_ctx, cli_id, cli_id_len) != 0 || mbedtls_md_hmac_finish(hmac_ctx, hmac_out) != 0) { return (MBEDTLS_ERR_SSL_INTERNAL_ERROR); } @@ -176,8 +175,7 @@ static int ssl_cookie_hmac( /* * Generate cookie for DTLS ClientHello verification */ -int mbedtls_ssl_cookie_write( - void* p_ctx, unsigned char** p, unsigned char* end, const unsigned char* cli_id, size_t cli_id_len) +int mbedtls_ssl_cookie_write(void* p_ctx, unsigned char** p, unsigned char* end, const unsigned char* cli_id, size_t cli_id_len) { int ret; mbedtls_ssl_cookie_ctx* ctx = (mbedtls_ssl_cookie_ctx*)p_ctx; @@ -218,8 +216,7 @@ int mbedtls_ssl_cookie_write( /* * Check a cookie */ -int mbedtls_ssl_cookie_check( - void* p_ctx, const unsigned char* cookie, size_t cookie_len, const unsigned char* cli_id, size_t cli_id_len) +int mbedtls_ssl_cookie_check(void* p_ctx, const unsigned char* cookie, size_t cookie_len, const unsigned char* cli_id, size_t cli_id_len) { unsigned char ref_hmac[COOKIE_HMAC_LEN]; int ret = 0; @@ -258,8 +255,7 @@ int mbedtls_ssl_cookie_check( cur_time = ctx->serial; #endif - cookie_time = ((unsigned long)cookie[0] << 24) | ((unsigned long)cookie[1] << 16) | ((unsigned long)cookie[2] << 8) - | ((unsigned long)cookie[3]); + cookie_time = ((unsigned long)cookie[0] << 24) | ((unsigned long)cookie[1] << 16) | ((unsigned long)cookie[2] << 8) | ((unsigned long)cookie[3]); if (ctx->timeout != 0 && cur_time - cookie_time > ctx->timeout) return (-1); diff --git a/nettls/ssl/ssl_srv.c b/nettls/ssl/ssl_srv.c index fda12a1950c32030e61aaf2059a6ee9f270c5b20..ee9926c5faa7ea067a294f41f1dc5ba68e6edc1e 100644 --- a/nettls/ssl/ssl_srv.c +++ b/nettls/ssl/ssl_srv.c @@ -93,10 +93,7 @@ int mbedtls_ssl_set_client_transport_id(mbedtls_ssl_context* ssl, const unsigned } void mbedtls_ssl_conf_dtls_cookies( - mbedtls_ssl_config* conf, - mbedtls_ssl_cookie_write_t* f_cookie_write, - mbedtls_ssl_cookie_check_t* f_cookie_check, - void* p_cookie) + mbedtls_ssl_config* conf, mbedtls_ssl_cookie_write_t* f_cookie_write, mbedtls_ssl_cookie_check_t* f_cookie_check, void* p_cookie) { conf->f_cookie_write = f_cookie_write; conf->f_cookie_check = f_cookie_check; @@ -138,8 +135,7 @@ static int ssl_parse_servername_ext(mbedtls_ssl_context* ssl, const unsigned cha ret = ssl->conf->f_sni(ssl->conf->p_sni, ssl, p + 3, hostname_len); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "ssl_sni_wrapper", ret); - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO); } return (0); @@ -712,8 +708,7 @@ static int ssl_pick_cert(mbedtls_ssl_context* ssl, const mbedtls_ssl_ciphersuite * Check if a given ciphersuite is suitable for use with our config/keys/etc * Sets ciphersuite_info only if the suite matches. */ -static int - ssl_ciphersuite_match(mbedtls_ssl_context* ssl, int suite_id, const mbedtls_ssl_ciphersuite_t** ciphersuite_info) +static int ssl_ciphersuite_match(mbedtls_ssl_context* ssl, int suite_id, const mbedtls_ssl_ciphersuite_t** ciphersuite_info) { const mbedtls_ssl_ciphersuite_t* suite_info; @@ -747,8 +742,7 @@ static int #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) - if (suite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE - && (ssl->handshake->cli_exts & MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK) == 0) { + if (suite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE && (ssl->handshake->cli_exts & MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK) == 0) { MBEDTLS_SSL_DEBUG_MSG( 3, ("ciphersuite mismatch: ecjpake " "not configured or ext missing")); @@ -757,8 +751,7 @@ static int #endif #if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) - if (mbedtls_ssl_ciphersuite_uses_ec(suite_info) - && (ssl->handshake->curves == NULL || ssl->handshake->curves[0] == NULL)) { + if (mbedtls_ssl_ciphersuite_uses_ec(suite_info) && (ssl->handshake->curves == NULL || ssl->handshake->curves[0] == NULL)) { MBEDTLS_SSL_DEBUG_MSG( 3, ("ciphersuite mismatch: " "no common elliptic curve")); @@ -770,8 +763,7 @@ static int /* If the ciphersuite requires a pre-shared key and we don't * have one, skip it now rather than failing later */ if (mbedtls_ssl_ciphersuite_uses_psk(suite_info) && ssl->conf->f_psk == NULL - && (ssl->conf->psk == NULL || ssl->conf->psk_identity == NULL || ssl->conf->psk_identity_len == 0 - || ssl->conf->psk_len == 0)) { + && (ssl->conf->psk == NULL || ssl->conf->psk_identity == NULL || ssl->conf->psk_identity_len == 0 || ssl->conf->psk_len == 0)) { MBEDTLS_SSL_DEBUG_MSG(3, ("ciphersuite mismatch: no pre-shared key")); return (0); } @@ -782,8 +774,7 @@ static int * a suitable hash algorithm is present. */ if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3) { sig_type = mbedtls_ssl_get_ciphersuite_sig_alg(suite_info); - if (sig_type != MBEDTLS_PK_NONE - && mbedtls_ssl_sig_hash_set_find(&ssl->handshake->hash_algs, sig_type) == MBEDTLS_MD_NONE) { + if (sig_type != MBEDTLS_PK_NONE && mbedtls_ssl_sig_hash_set_find(&ssl->handshake->hash_algs, sig_type) == MBEDTLS_MD_NONE) { MBEDTLS_SSL_DEBUG_MSG( 3, ("ciphersuite mismatch: no suitable hash algorithm " "for signature algorithm %d", @@ -956,8 +947,7 @@ static int ssl_parse_client_hello_v2(mbedtls_ssl_context* ssl) 1, ("received RENEGOTIATION SCSV " "during renegotiation")); - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO); } #endif /* MBEDTLS_SSL_RENEGOTIATION */ @@ -975,8 +965,7 @@ static int ssl_parse_client_hello_v2(mbedtls_ssl_context* ssl) if (ssl->minor_ver < ssl->conf->max_minor_ver) { MBEDTLS_SSL_DEBUG_MSG(1, ("inapropriate fallback")); - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO); } @@ -1261,8 +1250,7 @@ read_record_header: * For now we don't support fragmentation, so make sure * fragment_offset == 0 and fragment_length == length */ - if (ssl->in_msg[6] != 0 || ssl->in_msg[7] != 0 || ssl->in_msg[8] != 0 - || memcmp(ssl->in_msg + 1, ssl->in_msg + 9, 3) != 0) { + if (ssl->in_msg[6] != 0 || ssl->in_msg[7] != 0 || ssl->in_msg[8] != 0 || memcmp(ssl->in_msg + 1, ssl->in_msg + 9, 3) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("ClientHello fragmentation not supported")); return (MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE); } @@ -1335,8 +1323,7 @@ read_record_header: */ sess_len = buf[34]; - if (sess_len > sizeof(ssl->session_negotiate->id) - || sess_len + 34 + 2 > msg_len) /* 2 for cipherlist length field */ + if (sess_len > sizeof(ssl->session_negotiate->id) || sess_len + 34 + 2 > msg_len) /* 2 for cipherlist length field */ { MBEDTLS_SSL_DEBUG_MSG(1, ("bad client hello message")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR); @@ -1371,9 +1358,7 @@ read_record_header: && ssl->renego_status == MBEDTLS_SSL_INITIAL_HANDSHAKE #endif ) { - if (ssl->conf->f_cookie_check( - ssl->conf->p_cookie, buf + cookie_offset + 1, cookie_len, ssl->cli_id, ssl->cli_id_len) - != 0) { + if (ssl->conf->f_cookie_check(ssl->conf->p_cookie, buf + cookie_offset + 1, cookie_len, ssl->cli_id, ssl->cli_id_len) != 0) { MBEDTLS_SSL_DEBUG_MSG(2, ("cookie verification failed")); ssl->handshake->verify_cookie_len = 1; } else { @@ -1632,8 +1617,7 @@ read_record_header: if (ssl->minor_ver < ssl->conf->max_minor_ver) { MBEDTLS_SSL_DEBUG_MSG(1, ("inapropriate fallback")); - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO); } @@ -1672,8 +1656,7 @@ read_record_header: MBEDTLS_SSL_DEBUG_MSG( 1, ("received RENEGOTIATION SCSV " "during renegotiation")); - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO); } #endif @@ -1692,19 +1675,18 @@ read_record_header: } #if defined(MBEDTLS_SSL_RENEGOTIATION) else if ( - ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS - && ssl->secure_renegotiation == MBEDTLS_SSL_SECURE_RENEGOTIATION && renegotiation_info_seen == 0) { + ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && ssl->secure_renegotiation == MBEDTLS_SSL_SECURE_RENEGOTIATION + && renegotiation_info_seen == 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("renegotiation_info extension missing (secure)")); handshake_failure = 1; } else if ( - ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS - && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION + ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && ssl->conf->allow_legacy_renegotiation == MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION) { MBEDTLS_SSL_DEBUG_MSG(1, ("legacy renegotiation not allowed")); handshake_failure = 1; } else if ( - ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS - && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION && renegotiation_info_seen == 1) { + ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && ssl->secure_renegotiation == MBEDTLS_SSL_LEGACY_RENEGOTIATION + && renegotiation_info_seen == 1) { MBEDTLS_SSL_DEBUG_MSG(1, ("renegotiation_info extension present (legacy)")); handshake_failure = 1; } @@ -1774,8 +1756,7 @@ have_ciphersuite: mbedtls_pk_type_t sig_alg = mbedtls_ssl_get_ciphersuite_sig_alg(ciphersuite_info); if (sig_alg != MBEDTLS_PK_NONE) { mbedtls_md_type_t md_alg = mbedtls_ssl_sig_hash_set_find(&ssl->handshake->hash_algs, sig_alg); - MBEDTLS_SSL_DEBUG_MSG( - 3, ("client hello v3, signature_algorithm ext: %d", mbedtls_ssl_hash_from_md_alg(md_alg))); + MBEDTLS_SSL_DEBUG_MSG(3, ("client hello v3, signature_algorithm ext: %d", mbedtls_ssl_hash_from_md_alg(md_alg))); } else { MBEDTLS_SSL_DEBUG_MSG( 3, ("no hash algorithm for signature algorithm " @@ -1819,8 +1800,7 @@ static void ssl_write_encrypt_then_mac_ext(mbedtls_ssl_context* ssl, unsigned ch const mbedtls_ssl_ciphersuite_t* suite = NULL; const mbedtls_cipher_info_t* cipher = NULL; - if (ssl->session_negotiate->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED - || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { + if (ssl->session_negotiate->encrypt_then_mac == MBEDTLS_SSL_ETM_DISABLED || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { *olen = 0; return; } @@ -1854,8 +1834,7 @@ static void ssl_write_extended_ms_ext(mbedtls_ssl_context* ssl, unsigned char* b { unsigned char* p = buf; - if (ssl->handshake->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED - || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { + if (ssl->handshake->extended_ms == MBEDTLS_SSL_EXTENDED_MS_DISABLED || ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { *olen = 0; return; } @@ -2005,8 +1984,7 @@ static void ssl_write_ecjpake_kkpp_ext(mbedtls_ssl_context* ssl, unsigned char* *p++ = (unsigned char)((MBEDTLS_TLS_EXT_ECJPAKE_KKPP >> 8) & 0xFF); *p++ = (unsigned char)((MBEDTLS_TLS_EXT_ECJPAKE_KKPP)&0xFF); - ret = mbedtls_ecjpake_write_round_one( - &ssl->handshake->ecjpake_ctx, p + 2, end - p - 2, &kkpp_len, ssl->conf->f_rng, ssl->conf->p_rng); + ret = mbedtls_ecjpake_write_round_one(&ssl->handshake->ecjpake_ctx, p + 2, end - p - 2, &kkpp_len, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_write_round_one", ret); return; @@ -2084,9 +2062,7 @@ static int ssl_write_hello_verify_request(mbedtls_ssl_context* ssl) /* Skip length byte until we know the length */ cookie_len_byte = p++; - if ((ret = ssl->conf->f_cookie_write( - ssl->conf->p_cookie, &p, ssl->out_buf + MBEDTLS_SSL_OUT_BUFFER_LEN, ssl->cli_id, ssl->cli_id_len)) - != 0) { + if ((ret = ssl->conf->f_cookie_write(ssl->conf->p_cookie, &p, ssl->out_buf + MBEDTLS_SSL_OUT_BUFFER_LEN, ssl->cli_id, ssl->cli_id_len)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "f_cookie_write", ret); return (ret); } @@ -2253,9 +2229,7 @@ static int ssl_write_server_hello(mbedtls_ssl_context* ssl) *p++ = (unsigned char)(ssl->session_negotiate->ciphersuite); *p++ = (unsigned char)(ssl->session_negotiate->compression); - MBEDTLS_SSL_DEBUG_MSG( - 3, ("server hello, chosen ciphersuite: %s", - mbedtls_ssl_get_ciphersuite_name(ssl->session_negotiate->ciphersuite))); + MBEDTLS_SSL_DEBUG_MSG(3, ("server hello, chosen ciphersuite: %s", mbedtls_ssl_get_ciphersuite_name(ssl->session_negotiate->ciphersuite))); MBEDTLS_SSL_DEBUG_MSG(3, ("server hello, compress alg.: 0x%02X", ssl->session_negotiate->compression)); /* Do not write the extensions if the protocol is SSLv3 */ @@ -2334,19 +2308,17 @@ static int ssl_write_server_hello(mbedtls_ssl_context* ssl) return (ret); } -#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) +#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) static int ssl_write_certificate_request(mbedtls_ssl_context* ssl) { const mbedtls_ssl_ciphersuite_t* ciphersuite_info = ssl->transform_negotiate->ciphersuite_info; MBEDTLS_SSL_DEBUG_MSG(2, ("=> write certificate request")); - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip write certificate request")); ssl->state++; @@ -2379,10 +2351,8 @@ static int ssl_write_certificate_request(mbedtls_ssl_context* ssl) #endif authmode = ssl->conf->authmode; - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE || authmode == MBEDTLS_SSL_VERIFY_NONE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip write certificate request")); return (0); @@ -2530,9 +2500,7 @@ static int ssl_get_ecdh_params_from_cert(mbedtls_ssl_context* ssl) return (MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH); } - if ((ret = mbedtls_ecdh_get_params( - &ssl->handshake->ecdh_ctx, mbedtls_pk_ec(*mbedtls_ssl_own_key(ssl)), MBEDTLS_ECDH_OURS)) - != 0) { + if ((ret = mbedtls_ecdh_get_params(&ssl->handshake->ecdh_ctx, mbedtls_pk_ec(*mbedtls_ssl_own_key(ssl)), MBEDTLS_ECDH_OURS)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, ("mbedtls_ecdh_get_params"), ret); return (ret); } @@ -2597,8 +2565,8 @@ static int ssl_prepare_server_key_exchange(mbedtls_ssl_context* ssl, size_t* sig size_t len = 0; ret = mbedtls_ecjpake_write_round_two( - &ssl->handshake->ecjpake_ctx, ssl->out_msg + ssl->out_msglen, MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, - &len, ssl->conf->f_rng, ssl->conf->p_rng); + &ssl->handshake->ecjpake_ctx, ssl->out_msg + ssl->out_msglen, MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, &len, ssl->conf->f_rng, + ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_write_round_two", ret); return (ret); @@ -2614,8 +2582,7 @@ static int ssl_prepare_server_key_exchange(mbedtls_ssl_context* ssl, size_t* sig * we use empty support identity hints here. **/ #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK) { ssl->out_msg[ssl->out_msglen++] = 0x00; ssl->out_msg[ssl->out_msglen++] = 0x00; } @@ -2650,8 +2617,8 @@ static int ssl_prepare_server_key_exchange(mbedtls_ssl_context* ssl, size_t* sig } if ((ret = mbedtls_dhm_make_params( - &ssl->handshake->dhm_ctx, (int)mbedtls_mpi_size(&ssl->handshake->dhm_ctx.P), - ssl->out_msg + ssl->out_msglen, &len, ssl->conf->f_rng, ssl->conf->p_rng)) + &ssl->handshake->dhm_ctx, (int)mbedtls_mpi_size(&ssl->handshake->dhm_ctx.P), ssl->out_msg + ssl->out_msglen, &len, ssl->conf->f_rng, + ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_dhm_make_params", ret); return (ret); @@ -2708,8 +2675,8 @@ static int ssl_prepare_server_key_exchange(mbedtls_ssl_context* ssl, size_t* sig } if ((ret = mbedtls_ecdh_make_params( - &ssl->handshake->ecdh_ctx, &len, ssl->out_msg + ssl->out_msglen, - MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, ssl->conf->f_rng, ssl->conf->p_rng)) + &ssl->handshake->ecdh_ctx, &len, ssl->out_msg + ssl->out_msglen, MBEDTLS_SSL_OUT_CONTENT_LEN - ssl->out_msglen, ssl->conf->f_rng, + ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_make_params", ret); return (ret); @@ -2754,8 +2721,7 @@ static int ssl_prepare_server_key_exchange(mbedtls_ssl_context* ssl, size_t* sig if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3) { /* A: For TLS 1.2, obey signature-hash-algorithm extension * (RFC 5246, Sec. 7.4.1.4.1). */ - if (sig_alg == MBEDTLS_PK_NONE - || (md_alg = mbedtls_ssl_sig_hash_set_find(&ssl->handshake->hash_algs, sig_alg)) == MBEDTLS_MD_NONE) { + if (sig_alg == MBEDTLS_PK_NONE || (md_alg = mbedtls_ssl_sig_hash_set_find(&ssl->handshake->hash_algs, sig_alg)) == MBEDTLS_MD_NONE) { MBEDTLS_SSL_DEBUG_MSG(1, ("should never happen")); /* (... because we choose a cipher suite * only if there is a matching hash.) */ @@ -2861,8 +2827,8 @@ static int ssl_prepare_server_key_exchange(mbedtls_ssl_context* ssl, size_t* sig * ssl_write_server_key_exchange also takes care of incrementing * ssl->out_msglen. */ if ((ret = mbedtls_pk_sign( - mbedtls_ssl_own_key(ssl), md_alg, hash, hashlen, ssl->out_msg + ssl->out_msglen + 2, signature_len, - ssl->conf->f_rng, ssl->conf->p_rng)) + mbedtls_ssl_own_key(ssl), md_alg, hash, hashlen, ssl->out_msg + ssl->out_msglen + 2, signature_len, ssl->conf->f_rng, + ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_pk_sign", ret); return (ret); @@ -3036,8 +3002,7 @@ static int ssl_parse_client_dh_public(mbedtls_ssl_context* ssl, unsigned char** #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) #if defined(MBEDTLS_SSL_ASYNC_PRIVATE) -static int - ssl_resume_decrypt_pms(mbedtls_ssl_context* ssl, unsigned char* peer_pms, size_t* peer_pmslen, size_t peer_pmssize) +static int ssl_resume_decrypt_pms(mbedtls_ssl_context* ssl, unsigned char* peer_pms, size_t* peer_pmslen, size_t peer_pmssize) { int ret = ssl->conf->f_async_resume(ssl, peer_pms, peer_pmslen, peer_pmssize); if (ret != MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS) { @@ -3050,12 +3015,7 @@ static int #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */ static int ssl_decrypt_encrypted_pms( - mbedtls_ssl_context* ssl, - const unsigned char* p, - const unsigned char* end, - unsigned char* peer_pms, - size_t* peer_pmslen, - size_t peer_pmssize) + mbedtls_ssl_context* ssl, const unsigned char* p, const unsigned char* end, unsigned char* peer_pms, size_t* peer_pmslen, size_t peer_pmssize) { int ret; mbedtls_pk_context* private_key = mbedtls_ssl_own_key(ssl); @@ -3120,13 +3080,11 @@ static int ssl_decrypt_encrypted_pms( return (MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED); } - ret = mbedtls_pk_decrypt( - private_key, p, len, peer_pms, peer_pmslen, peer_pmssize, ssl->conf->f_rng, ssl->conf->p_rng); + ret = mbedtls_pk_decrypt(private_key, p, len, peer_pms, peer_pmslen, peer_pmssize, ssl->conf->f_rng, ssl->conf->p_rng); return (ret); } -static int ssl_parse_encrypted_pms( - mbedtls_ssl_context* ssl, const unsigned char* p, const unsigned char* end, size_t pms_offset) +static int ssl_parse_encrypted_pms(mbedtls_ssl_context* ssl, const unsigned char* p, const unsigned char* end, size_t pms_offset) { int ret; unsigned char* pms = ssl->handshake->premaster + pms_offset; @@ -3219,8 +3177,7 @@ static int ssl_parse_client_psk_identity(mbedtls_ssl_context* ssl, unsigned char size_t n; if (ssl->conf->f_psk == NULL - && (ssl->conf->psk == NULL || ssl->conf->psk_identity == NULL || ssl->conf->psk_identity_len == 0 - || ssl->conf->psk_len == 0)) { + && (ssl->conf->psk == NULL || ssl->conf->psk_identity == NULL || ssl->conf->psk_identity_len == 0 || ssl->conf->psk_len == 0)) { MBEDTLS_SSL_DEBUG_MSG(1, ("got no pre-shared key")); return (MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED); } @@ -3274,10 +3231,8 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(2, ("=> parse client key exchange")); -#if defined(MBEDTLS_SSL_ASYNC_PRIVATE) \ - && (defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)) - if ((ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA) +#if defined(MBEDTLS_SSL_ASYNC_PRIVATE) && (defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)) + if ((ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA) && (ssl->handshake->async_in_progress != 0)) { /* We've already read a record and there is an asynchronous * operation in progress to decrypt it. So skip reading the @@ -3316,8 +3271,8 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context* ssl) } if ((ret = mbedtls_dhm_calc_secret( - &ssl->handshake->dhm_ctx, ssl->handshake->premaster, MBEDTLS_PREMASTER_SIZE, &ssl->handshake->pmslen, - ssl->conf->f_rng, ssl->conf->p_rng)) + &ssl->handshake->dhm_ctx, ssl->handshake->premaster, MBEDTLS_PREMASTER_SIZE, &ssl->handshake->pmslen, ssl->conf->f_rng, + ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_dhm_calc_secret", ret); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS); @@ -3328,10 +3283,8 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context* ssl) #endif /* MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) \ || defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_RSA || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_RSA || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA) { if ((ret = mbedtls_ecdh_read_public(&ssl->handshake->ecdh_ctx, p, end - p)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_read_public", ret); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP); @@ -3340,8 +3293,8 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_ECDH(3, &ssl->handshake->ecdh_ctx, MBEDTLS_DEBUG_ECDH_QP); if ((ret = mbedtls_ecdh_calc_secret( - &ssl->handshake->ecdh_ctx, &ssl->handshake->pmslen, ssl->handshake->premaster, MBEDTLS_MPI_MAX_SIZE, - ssl->conf->f_rng, ssl->conf->p_rng)) + &ssl->handshake->ecdh_ctx, &ssl->handshake->pmslen, ssl->handshake->premaster, MBEDTLS_MPI_MAX_SIZE, ssl->conf->f_rng, + ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_calc_secret", ret); return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS); @@ -3459,8 +3412,7 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context* ssl) } ret = mbedtls_ecjpake_derive_secret( - &ssl->handshake->ecjpake_ctx, ssl->handshake->premaster, 32, &ssl->handshake->pmslen, ssl->conf->f_rng, - ssl->conf->p_rng); + &ssl->handshake->ecjpake_ctx, ssl->handshake->premaster, 32, &ssl->handshake->pmslen, ssl->conf->f_rng, ssl->conf->p_rng); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecjpake_derive_secret", ret); return (ret); @@ -3484,19 +3436,17 @@ static int ssl_parse_client_key_exchange(mbedtls_ssl_context* ssl) return (0); } -#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) +#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) static int ssl_parse_certificate_verify(mbedtls_ssl_context* ssl) { const mbedtls_ssl_ciphersuite_t* ciphersuite_info = ssl->transform_negotiate->ciphersuite_info; MBEDTLS_SSL_DEBUG_MSG(2, ("=> parse certificate verify")); - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip parse certificate verify")); ssl->state++; @@ -3522,12 +3472,9 @@ static int ssl_parse_certificate_verify(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(2, ("=> parse certificate verify")); - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE - || ssl->session_negotiate->peer_cert == NULL) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE || ssl->session_negotiate->peer_cert == NULL) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip parse certificate verify")); ssl->state++; return (0); @@ -3641,9 +3588,7 @@ static int ssl_parse_certificate_verify(mbedtls_ssl_context* ssl) /* Calculate hash and verify signature */ ssl->handshake->calc_verify(ssl, hash); - if ((ret = mbedtls_pk_verify( - &ssl->session_negotiate->peer_cert->pk, md_alg, hash_start, hashlen, ssl->in_msg + i, sig_len)) - != 0) { + if ((ret = mbedtls_pk_verify(&ssl->session_negotiate->peer_cert->pk, md_alg, hash_start, hashlen, ssl->in_msg + i, sig_len)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_pk_verify", ret); return (ret); } @@ -3685,8 +3630,7 @@ static int ssl_write_new_session_ticket(mbedtls_ssl_context* ssl) */ if ((ret = ssl->conf->f_ticket_write( - ssl->conf->p_ticket, ssl->session_negotiate, ssl->out_msg + 10, ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN, - &tlen, &lifetime)) + ssl->conf->p_ticket, ssl->session_negotiate, ssl->out_msg + 10, ssl->out_msg + MBEDTLS_SSL_OUT_CONTENT_LEN, &tlen, &lifetime)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ssl_ticket_write", ret); tlen = 0; @@ -3735,8 +3679,7 @@ int mbedtls_ssl_handshake_server_step(mbedtls_ssl_context* ssl) return (ret); #if defined(MBEDTLS_SSL_PROTO_DTLS) - if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM - && ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING) { + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->handshake->retransmit_state == MBEDTLS_SSL_RETRANS_SENDING) { if ((ret = mbedtls_ssl_flight_transmit(ssl)) != 0) return (ret); } diff --git a/nettls/ssl/ssl_ticket.c b/nettls/ssl/ssl_ticket.c index 8e29a4f2f549c584d7a4ceb0bad3c9a68e39d338..519be347b3c168a9b564286b672e7ad5bf2c56c1 100644 --- a/nettls/ssl/ssl_ticket.c +++ b/nettls/ssl/ssl_ticket.c @@ -143,11 +143,7 @@ static int ssl_ticket_update_keys(mbedtls_ssl_ticket_context* ctx) * Setup context for actual use */ int mbedtls_ssl_ticket_setup( - mbedtls_ssl_ticket_context* ctx, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng, - mbedtls_cipher_type_t cipher, - uint32_t lifetime) + mbedtls_ssl_ticket_context* ctx, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng, mbedtls_cipher_type_t cipher, uint32_t lifetime) { int ret; const mbedtls_cipher_info_t* cipher_info; @@ -168,8 +164,7 @@ int mbedtls_ssl_ticket_setup( if (cipher_info->key_bitlen > 8 * MAX_KEY_BYTES) return (MBEDTLS_ERR_SSL_BAD_INPUT_DATA); - if ((ret = mbedtls_cipher_setup(&ctx->keys[0].ctx, cipher_info)) != 0 - || (ret = mbedtls_cipher_setup(&ctx->keys[1].ctx, cipher_info)) != 0) { + if ((ret = mbedtls_cipher_setup(&ctx->keys[0].ctx, cipher_info)) != 0 || (ret = mbedtls_cipher_setup(&ctx->keys[1].ctx, cipher_info)) != 0) { return (ret); } @@ -296,12 +291,7 @@ static int ssl_load_session(mbedtls_ssl_session* session, const unsigned char* b */ int mbedtls_ssl_ticket_write( - void* p_ticket, - const mbedtls_ssl_session* session, - unsigned char* start, - const unsigned char* end, - size_t* tlen, - uint32_t* ticket_lifetime) + void* p_ticket, const mbedtls_ssl_session* session, unsigned char* start, const unsigned char* end, size_t* tlen, uint32_t* ticket_lifetime) { int ret; mbedtls_ssl_ticket_context* ctx = p_ticket; diff --git a/nettls/ssl/ssl_tls.c b/nettls/ssl/ssl_tls.c index b560101761ab43e6ef7e060fc6f46bfb2f7a9c28..030cfea6b91a0c3e1fb670aeb6659e11f40cd3fb 100644 --- a/nettls/ssl/ssl_tls.c +++ b/nettls/ssl/ssl_tls.c @@ -152,7 +152,7 @@ static size_t ssl_get_maximum_datagram_size(mbedtls_ssl_context const* ssl) return (MBEDTLS_SSL_OUT_BUFFER_LEN); } -static int ssl_get_remaining_space_in_datagram(mbedtls_ssl_context const* ssl) +int ssl_get_remaining_space_in_datagram(mbedtls_ssl_context const* ssl) { size_t const bytes_written = ssl->out_left; size_t const mtu = ssl_get_maximum_datagram_size(ssl); @@ -167,7 +167,7 @@ static int ssl_get_remaining_space_in_datagram(mbedtls_ssl_context const* ssl) return ((int)(mtu - bytes_written)); } -static int ssl_get_remaining_payload_in_datagram(mbedtls_ssl_context const* ssl) +int ssl_get_remaining_payload_in_datagram(mbedtls_ssl_context const* ssl) { int ret; size_t remaining, expansion; @@ -346,13 +346,7 @@ int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context* ssl) = NULL; */ #if defined(MBEDTLS_SSL_PROTO_SSL3) static int ssl3_prf( - const unsigned char* secret, - size_t slen, - const char* label, - const unsigned char* random, - size_t rlen, - unsigned char* dstbuf, - size_t dlen) + const unsigned char* secret, size_t slen, const char* label, const unsigned char* random, size_t rlen, unsigned char* dstbuf, size_t dlen) { int ret = 0; size_t i; @@ -410,13 +404,7 @@ exit: #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) static int tls1_prf( - const unsigned char* secret, - size_t slen, - const char* label, - const unsigned char* random, - size_t rlen, - unsigned char* dstbuf, - size_t dlen) + const unsigned char* secret, size_t slen, const char* label, const unsigned char* random, size_t rlen, unsigned char* dstbuf, size_t dlen) { size_t nb, hs; size_t i, j, k; @@ -577,13 +565,7 @@ static int tls_prf_generic( #if defined(MBEDTLS_SHA256_C) static int tls_prf_sha256( - const unsigned char* secret, - size_t slen, - const char* label, - const unsigned char* random, - size_t rlen, - unsigned char* dstbuf, - size_t dlen) + const unsigned char* secret, size_t slen, const char* label, const unsigned char* random, size_t rlen, unsigned char* dstbuf, size_t dlen) { return (tls_prf_generic(MBEDTLS_MD_SHA256, secret, slen, label, random, rlen, dstbuf, dlen)); } @@ -591,13 +573,7 @@ static int tls_prf_sha256( #if defined(MBEDTLS_SHA512_C) static int tls_prf_sha384( - const unsigned char* secret, - size_t slen, - const char* label, - const unsigned char* random, - size_t rlen, - unsigned char* dstbuf, - size_t dlen) + const unsigned char* secret, size_t slen, const char* label, const unsigned char* random, size_t rlen, unsigned char* dstbuf, size_t dlen) { return (tls_prf_generic(MBEDTLS_MD_SHA384, secret, slen, label, random, rlen, dstbuf, dlen)); } @@ -740,9 +716,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_BUF(3, "session hash", session_hash, hash_len); - ret = handshake->tls_prf( - handshake->premaster, handshake->pmslen, "extended master secret", session_hash, hash_len, - session->master, 48); + ret = handshake->tls_prf(handshake->premaster, handshake->pmslen, "extended master secret", session_hash, hash_len, session->master, 48); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "prf", ret); return (ret); @@ -750,9 +724,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) } else #endif - ret = handshake->tls_prf( - handshake->premaster, handshake->pmslen, "master secret", handshake->randbytes, 64, session->master, - 48); + ret = handshake->tls_prf(handshake->premaster, handshake->pmslen, "master secret", handshake->randbytes, 64, session->master, 48); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "prf", ret); return (ret); @@ -801,8 +773,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) transform->keylen = cipher_info->key_bitlen / 8; - if (cipher_info->mode == MBEDTLS_MODE_GCM || cipher_info->mode == MBEDTLS_MODE_CCM - || cipher_info->mode == MBEDTLS_MODE_CHACHAPOLY) { + if (cipher_info->mode == MBEDTLS_MODE_GCM || cipher_info->mode == MBEDTLS_MODE_CCM || cipher_info->mode == MBEDTLS_MODE_CHACHAPOLY) { size_t taglen, explicit_ivlen; transform->maclen = 0; @@ -826,8 +797,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) transform->minlen = explicit_ivlen + taglen; } else { /* Initialize HMAC contexts */ - if ((ret = mbedtls_md_setup(&transform->md_ctx_enc, md_info, 1)) != 0 - || (ret = mbedtls_md_setup(&transform->md_ctx_dec, md_info, 1)) != 0) { + if ((ret = mbedtls_md_setup(&transform->md_ctx_enc, md_info, 1)) != 0 || (ret = mbedtls_md_setup(&transform->md_ctx_dec, md_info, 1)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_md_setup", ret); return (ret); } @@ -873,8 +843,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) } else #endif { - transform->minlen = - transform->maclen + cipher_info->block_size - transform->maclen % cipher_info->block_size; + transform->minlen = transform->maclen + cipher_info->block_size - transform->maclen % cipher_info->block_size; } #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) @@ -895,8 +864,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) } MBEDTLS_SSL_DEBUG_MSG( - 3, ("keylen: %d, minlen: %d, ivlen: %d, maclen: %d", transform->keylen, transform->minlen, transform->ivlen, - transform->maclen)); + 3, ("keylen: %d, minlen: %d, ivlen: %d, maclen: %d", transform->keylen, transform->minlen, transform->ivlen, transform->maclen)); /* * Finally setup the cipher contexts, IVs and MAC secrets. @@ -969,8 +937,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(2, ("going for mbedtls_ssl_hw_record_init()")); if ((ret = mbedtls_ssl_hw_record_init( - ssl, key1, key2, transform->keylen, transform->iv_enc, transform->iv_dec, iv_copy_len, mac_enc, - mac_dec, mac_key_len)) + ssl, key1, key2, transform->keylen, transform->iv_enc, transform->iv_dec, iv_copy_len, mac_enc, mac_dec, mac_key_len)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ssl_hw_record_init", ret); return (MBEDTLS_ERR_SSL_HW_ACCEL_FAILED); @@ -980,8 +947,7 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) #if defined(MBEDTLS_SSL_EXPORT_KEYS) if (ssl->conf->f_export_keys != NULL) { - ssl->conf->f_export_keys( - ssl->conf->p_export_keys, session->master, keyblk, mac_key_len, transform->keylen, iv_copy_len); + ssl->conf->f_export_keys(ssl->conf->p_export_keys, session->master, keyblk, mac_key_len, transform->keylen, iv_copy_len); } #endif @@ -995,14 +961,12 @@ int mbedtls_ssl_derive_keys(mbedtls_ssl_context* ssl) return (ret); } - if ((ret = mbedtls_cipher_setkey(&transform->cipher_ctx_enc, key1, cipher_info->key_bitlen, MBEDTLS_ENCRYPT)) - != 0) { + if ((ret = mbedtls_cipher_setkey(&transform->cipher_ctx_enc, key1, cipher_info->key_bitlen, MBEDTLS_ENCRYPT)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_setkey", ret); return (ret); } - if ((ret = mbedtls_cipher_setkey(&transform->cipher_ctx_dec, key2, cipher_info->key_bitlen, MBEDTLS_DECRYPT)) - != 0) { + if ((ret = mbedtls_cipher_setkey(&transform->cipher_ctx_dec, key2, cipher_info->key_bitlen, MBEDTLS_DECRYPT)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_setkey", ret); return (ret); } @@ -1204,9 +1168,7 @@ int mbedtls_ssl_psk_derive_premaster(mbedtls_ssl_context* ssl, mbedtls_key_excha size_t len; /* Write length only when we know the actual value */ - if ((ret = mbedtls_dhm_calc_secret( - &ssl->handshake->dhm_ctx, p + 2, end - (p + 2), &len, ssl->conf->f_rng, ssl->conf->p_rng)) - != 0) { + if ((ret = mbedtls_dhm_calc_secret(&ssl->handshake->dhm_ctx, p + 2, end - (p + 2), &len, ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_dhm_calc_secret", ret); return (ret); } @@ -1222,9 +1184,7 @@ int mbedtls_ssl_psk_derive_premaster(mbedtls_ssl_context* ssl, mbedtls_key_excha int ret; size_t zlen; - if ((ret = mbedtls_ecdh_calc_secret( - &ssl->handshake->ecdh_ctx, &zlen, p + 2, end - (p + 2), ssl->conf->f_rng, ssl->conf->p_rng)) - != 0) { + if ((ret = mbedtls_ecdh_calc_secret(&ssl->handshake->ecdh_ctx, &zlen, p + 2, end - (p + 2), ssl->conf->f_rng, ssl->conf->p_rng)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ecdh_calc_secret", ret); return (ret); } @@ -1315,7 +1275,7 @@ static void ssl_mac( /* * Encryption/decryption functions */ -static int ssl_encrypt_buf(mbedtls_ssl_context* ssl) +int ssl_encrypt_buf(mbedtls_ssl_context* ssl) { mbedtls_cipher_mode_t mode; int auth_done = 0; @@ -1345,9 +1305,7 @@ static int ssl_encrypt_buf(mbedtls_ssl_context* ssl) if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { unsigned char mac[SSL_MAC_MAX_BYTES]; - ssl_mac( - &ssl->transform_out->md_ctx_enc, ssl->transform_out->mac_enc, ssl->out_msg, ssl->out_msglen, - ssl->out_ctr, ssl->out_msgtype, mac); + ssl_mac(&ssl->transform_out->md_ctx_enc, ssl->transform_out->mac_enc, ssl->out_msg, ssl->out_msglen, ssl->out_ctr, ssl->out_msgtype, mac); memcpy(ssl->out_msg + ssl->out_msglen, mac, ssl->transform_out->maclen); } else @@ -1392,8 +1350,8 @@ static int ssl_encrypt_buf(mbedtls_ssl_context* ssl) ssl->out_msglen, 0)); if ((ret = mbedtls_cipher_crypt( - &ssl->transform_out->cipher_ctx_enc, ssl->transform_out->iv_enc, ssl->transform_out->ivlen, - ssl->out_msg, ssl->out_msglen, ssl->out_msg, &olen)) + &ssl->transform_out->cipher_ctx_enc, ssl->transform_out->iv_enc, ssl->transform_out->ivlen, ssl->out_msg, ssl->out_msglen, + ssl->out_msg, &olen)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_crypt", ret); return (ret); @@ -1469,8 +1427,7 @@ static int ssl_encrypt_buf(mbedtls_ssl_context* ssl) * Encrypt and authenticate */ if ((ret = mbedtls_cipher_auth_encrypt( - &transform->cipher_ctx_enc, iv, transform->ivlen, add_data, 13, enc_msg, enc_msglen, enc_msg, &olen, - enc_msg + enc_msglen, taglen)) + &transform->cipher_ctx_enc, iv, transform->ivlen, add_data, 13, enc_msg, enc_msglen, enc_msg, &olen, enc_msg + enc_msglen, taglen)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_auth_encrypt", ret); return (ret); @@ -1535,8 +1492,7 @@ static int ssl_encrypt_buf(mbedtls_ssl_context* ssl) ssl->out_msglen, ssl->transform_out->ivlen, padlen + 1)); if ((ret = mbedtls_cipher_crypt( - &ssl->transform_out->cipher_ctx_enc, ssl->transform_out->iv_enc, ssl->transform_out->ivlen, enc_msg, - enc_msglen, enc_msg, &olen)) + &ssl->transform_out->cipher_ctx_enc, ssl->transform_out->iv_enc, ssl->transform_out->ivlen, enc_msg, enc_msglen, enc_msg, &olen)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_crypt", ret); return (ret); @@ -1741,12 +1697,7 @@ cleanup: * - but with execution flow independent from the value of offset_secret. */ void mbedtls_ssl_cf_memcpy_offset( - unsigned char* dst, - const unsigned char* src_base, - size_t offset_secret, - size_t offset_min, - size_t offset_max, - size_t len) + unsigned char* dst, const unsigned char* src_base, size_t offset_secret, size_t offset_min, size_t offset_max, size_t len) { size_t offset; @@ -1756,7 +1707,7 @@ void mbedtls_ssl_cf_memcpy_offset( } #endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ -static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) +int ssl_decrypt_buf(mbedtls_ssl_context* ssl) { mbedtls_cipher_mode_t mode; int auth_done = 0; @@ -1786,8 +1737,8 @@ static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) padlen = 0; if ((ret = mbedtls_cipher_crypt( - &ssl->transform_in->cipher_ctx_dec, ssl->transform_in->iv_dec, ssl->transform_in->ivlen, ssl->in_msg, - ssl->in_msglen, ssl->in_msg, &olen)) + &ssl->transform_in->cipher_ctx_dec, ssl->transform_in->iv_dec, ssl->transform_in->ivlen, ssl->in_msg, ssl->in_msglen, ssl->in_msg, + &olen)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_crypt", ret); return (ret); @@ -1867,8 +1818,8 @@ static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) * Decrypt and authenticate */ if ((ret = mbedtls_cipher_auth_decrypt( - &ssl->transform_in->cipher_ctx_dec, iv, transform->ivlen, add_data, 13, dec_msg, dec_msglen, - dec_msg_result, &olen, dec_msg + dec_msglen, taglen)) + &ssl->transform_in->cipher_ctx_dec, iv, transform->ivlen, add_data, 13, dec_msg, dec_msglen, dec_msg_result, &olen, + dec_msg + dec_msglen, taglen)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_auth_decrypt", ret); @@ -1905,8 +1856,7 @@ static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) minlen += ssl->transform_in->ivlen; #endif - if (ssl->in_msglen < minlen + ssl->transform_in->ivlen - || ssl->in_msglen < minlen + ssl->transform_in->maclen + 1) { + if (ssl->in_msglen < minlen + ssl->transform_in->ivlen || ssl->in_msglen < minlen + ssl->transform_in->maclen + 1) { MBEDTLS_SSL_DEBUG_MSG( 1, ("msglen (%d) < max( ivlen(%d), maclen (%d) " "+ 1 ) ( + expl IV )", @@ -1978,8 +1928,7 @@ static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) #endif /* MBEDTLS_SSL_PROTO_TLS1_1 || MBEDTLS_SSL_PROTO_TLS1_2 */ if ((ret = mbedtls_cipher_crypt( - &ssl->transform_in->cipher_ctx_dec, ssl->transform_in->iv_dec, ssl->transform_in->ivlen, dec_msg, - dec_msglen, dec_msg_result, &olen)) + &ssl->transform_in->cipher_ctx_dec, ssl->transform_in->iv_dec, ssl->transform_in->ivlen, dec_msg, dec_msglen, dec_msg_result, &olen)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_cipher_crypt", ret); return (ret); @@ -2003,8 +1952,7 @@ static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) if (ssl->in_msglen < ssl->transform_in->maclen + padlen && auth_done == 0) { #if defined(MBEDTLS_SSL_DEBUG_ALL) - MBEDTLS_SSL_DEBUG_MSG( - 1, ("msglen (%d) < maclen (%d) + padlen (%d)", ssl->in_msglen, ssl->transform_in->maclen, padlen)); + MBEDTLS_SSL_DEBUG_MSG(1, ("msglen (%d) < maclen (%d) + padlen (%d)", ssl->in_msglen, ssl->transform_in->maclen, padlen)); #endif padlen = 0; correct = 0; @@ -2097,8 +2045,7 @@ static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) #if defined(MBEDTLS_SSL_PROTO_SSL3) if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { ssl_mac( - &ssl->transform_in->md_ctx_dec, ssl->transform_in->mac_dec, ssl->in_msg, ssl->in_msglen, ssl->in_ctr, - ssl->in_msgtype, mac_expect); + &ssl->transform_in->md_ctx_dec, ssl->transform_in->mac_dec, ssl->in_msg, ssl->in_msglen, ssl->in_ctr, ssl->in_msgtype, mac_expect); memcpy(mac_peer, ssl->in_msg + ssl->in_msglen, ssl->transform_in->maclen); } else #endif /* MBEDTLS_SSL_PROTO_SSL3 */ @@ -2125,15 +2072,13 @@ static int ssl_decrypt_buf(mbedtls_ssl_context* ssl) memcpy(add_data + 11, ssl->in_len, 2); ret = mbedtls_ssl_cf_hmac( - &ssl->transform_in->md_ctx_dec, add_data, sizeof(add_data), ssl->in_msg, ssl->in_msglen, min_len, - max_len, mac_expect); + &ssl->transform_in->md_ctx_dec, add_data, sizeof(add_data), ssl->in_msg, ssl->in_msglen, min_len, max_len, mac_expect); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ssl_cf_hmac", ret); return (ret); } - mbedtls_ssl_cf_memcpy_offset( - mac_peer, ssl->in_msg, ssl->in_msglen, min_len, max_len, ssl->transform_in->maclen); + mbedtls_ssl_cf_memcpy_offset(mac_peer, ssl->in_msg, ssl->in_msglen, min_len, max_len, ssl->transform_in->maclen); } else #endif /* MBEDTLS_SSL_PROTO_TLS1 || MBEDTLS_SSL_PROTO_TLS1_1 || \ MBEDTLS_SSL_PROTO_TLS1_2 */ @@ -2387,9 +2332,7 @@ int mbedtls_ssl_fetch_input(mbedtls_ssl_context* ssl, size_t nb_want) return (MBEDTLS_ERR_SSL_WANT_READ); } #if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_RENEGOTIATION) - else if ( - ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER - && ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_PENDING) { + else if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER && ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_PENDING) { if ((ret = ssl_resend_hello_request(ssl)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "ssl_resend_hello_request", ret); return (ret); @@ -2432,8 +2375,7 @@ int mbedtls_ssl_fetch_input(mbedtls_ssl_context* ssl, size_t nb_want) return (ret); if ((size_t)ret > len || (INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX)) { - MBEDTLS_SSL_DEBUG_MSG( - 1, ("f_recv returned %d bytes but only %lu were requested", ret, (unsigned long)len)); + MBEDTLS_SSL_DEBUG_MSG(1, ("f_recv returned %d bytes but only %lu were requested", ret, (unsigned long)len)); return (MBEDTLS_ERR_SSL_INTERNAL_ERROR); } @@ -2470,8 +2412,7 @@ int mbedtls_ssl_flush_output(mbedtls_ssl_context* ssl) } while (ssl->out_left > 0) { - MBEDTLS_SSL_DEBUG_MSG( - 2, ("message length: %d, out_left: %d", mbedtls_ssl_hdr_len(ssl) + ssl->out_msglen, ssl->out_left)); + MBEDTLS_SSL_DEBUG_MSG(2, ("message length: %d, out_left: %d", mbedtls_ssl_hdr_len(ssl) + ssl->out_msglen, ssl->out_left)); buf = ssl->out_hdr - ssl->out_left; ret = ssl->f_send(ssl->p_bio, buf, ssl->out_left); @@ -2482,8 +2423,7 @@ int mbedtls_ssl_flush_output(mbedtls_ssl_context* ssl) return (ret); if ((size_t)ret > ssl->out_left || (INT_MAX > SIZE_MAX && ret > (int)SIZE_MAX)) { - MBEDTLS_SSL_DEBUG_MSG( - 1, ("f_send returned %d bytes but only %lu bytes were sent", ret, (unsigned long)ssl->out_left)); + MBEDTLS_SSL_DEBUG_MSG(1, ("f_send returned %d bytes but only %lu bytes were sent", ret, (unsigned long)ssl->out_left)); return (MBEDTLS_ERR_SSL_INTERNAL_ERROR); } @@ -2714,9 +2654,7 @@ int mbedtls_ssl_flight_transmit(mbedtls_ssl_context* ssl) cur_hs_frag_len = rem_len > max_hs_frag_len ? max_hs_frag_len : rem_len; if (frag_off == 0 && cur_hs_frag_len != hs_len) { - MBEDTLS_SSL_DEBUG_MSG( - 2, - ("fragmenting handshake message (%u > %u)", (unsigned)cur_hs_frag_len, (unsigned)max_hs_frag_len)); + MBEDTLS_SSL_DEBUG_MSG(2, ("fragmenting handshake message (%u > %u)", (unsigned)cur_hs_frag_len, (unsigned)max_hs_frag_len)); } /* Messages are stored with handshake headers as if not fragmented, @@ -2871,8 +2809,7 @@ int mbedtls_ssl_write_handshake_msg(mbedtls_ssl_context* ssl) /* Whenever we send anything different from a * HelloRequest we should be in a handshake - double check. */ - if (!(ssl->out_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE && hs_type == MBEDTLS_SSL_HS_HELLO_REQUEST) - && ssl->handshake == NULL) { + if (!(ssl->out_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE && hs_type == MBEDTLS_SSL_HS_HELLO_REQUEST) && ssl->handshake == NULL) { MBEDTLS_SSL_DEBUG_MSG(1, ("should never happen")); return (MBEDTLS_ERR_SSL_INTERNAL_ERROR); } @@ -3101,8 +3038,7 @@ int mbedtls_ssl_write_record(mbedtls_ssl_context* ssl, uint8_t force_flush) static int ssl_hs_is_proper_fragment(mbedtls_ssl_context* ssl) { - if (ssl->in_msglen < ssl->in_hslen || memcmp(ssl->in_msg + 6, "\0\0\0", 3) != 0 - || memcmp(ssl->in_msg + 9, ssl->in_msg + 1, 3) != 0) { + if (ssl->in_msglen < ssl->in_hslen || memcmp(ssl->in_msg + 6, "\0\0\0", 3) != 0 || memcmp(ssl->in_msg + 9, ssl->in_msg + 1, 3) != 0) { return (1); } return (0); @@ -3246,16 +3182,14 @@ int mbedtls_ssl_prepare_handshake_record(mbedtls_ssl_context* ssl) || (ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER && ssl->in_msg[0] != MBEDTLS_SSL_HS_CLIENT_HELLO))) { if (recv_msg_seq > ssl->handshake->in_msg_seq) { MBEDTLS_SSL_DEBUG_MSG( - 2, ("received future handshake message of sequence number %u (next %u)", recv_msg_seq, - ssl->handshake->in_msg_seq)); + 2, ("received future handshake message of sequence number %u (next %u)", recv_msg_seq, ssl->handshake->in_msg_seq)); return (MBEDTLS_ERR_SSL_EARLY_MESSAGE); } /* Retransmit only on last message from previous flight, to avoid * too many retransmissions. * Besides, No sane server ever retransmits HelloVerifyRequest */ - if (recv_msg_seq == ssl->handshake->in_flight_start_seq - 1 - && ssl->in_msg[0] != MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST) { + if (recv_msg_seq == ssl->handshake->in_flight_start_seq - 1 && ssl->in_msg[0] != MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST) { MBEDTLS_SSL_DEBUG_MSG( 2, ("received message from last flight, " "message_seq = %d, start_of_flight = %d", @@ -3350,8 +3284,8 @@ static void ssl_dtls_replay_reset(mbedtls_ssl_context* ssl) static inline uint64_t ssl_load_six_bytes(unsigned char* buf) { return ( - ((uint64_t)buf[0] << 40) | ((uint64_t)buf[1] << 32) | ((uint64_t)buf[2] << 24) | ((uint64_t)buf[3] << 16) - | ((uint64_t)buf[4] << 8) | ((uint64_t)buf[5])); + ((uint64_t)buf[0] << 40) | ((uint64_t)buf[1] << 32) | ((uint64_t)buf[2] << 24) | ((uint64_t)buf[3] << 16) | ((uint64_t)buf[4] << 8) + | ((uint64_t)buf[5])); } /* @@ -3470,8 +3404,7 @@ static int ssl_check_dtls_clihlo_cookie( * * Minimum length is 61 bytes. */ - if (in_len < 61 || in[0] != MBEDTLS_SSL_MSG_HANDSHAKE || in[3] != 0 || in[4] != 0 || in[19] != 0 || in[20] != 0 - || in[21] != 0) { + if (in_len < 61 || in[0] != MBEDTLS_SSL_MSG_HANDSHAKE || in[3] != 0 || in[4] != 0 || in[19] != 0 || in[20] != 0 || in[21] != 0) { return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO); } @@ -3563,8 +3496,8 @@ static int ssl_handle_possible_reconnect(mbedtls_ssl_context* ssl) size_t len; ret = ssl_check_dtls_clihlo_cookie( - ssl->conf->f_cookie_write, ssl->conf->f_cookie_check, ssl->conf->p_cookie, ssl->cli_id, ssl->cli_id_len, - ssl->in_buf, ssl->in_left, ssl->out_buf, MBEDTLS_SSL_OUT_CONTENT_LEN, &len); + ssl->conf->f_cookie_write, ssl->conf->f_cookie_check, ssl->conf->p_cookie, ssl->cli_id, ssl->cli_id_len, ssl->in_buf, ssl->in_left, + ssl->out_buf, MBEDTLS_SSL_OUT_CONTENT_LEN, &len); MBEDTLS_SSL_DEBUG_RET(2, "ssl_check_dtls_clihlo_cookie", ret); @@ -3615,7 +3548,7 @@ static int ssl_handle_possible_reconnect(mbedtls_ssl_context* ssl) * Point 2 is needed when the peer is resending, and we have already received * the first record from a datagram but are still waiting for the others. */ -static int ssl_parse_record_header(mbedtls_ssl_context* ssl) +int ssl_parse_record_header(mbedtls_ssl_context* ssl) { int major_ver, minor_ver; @@ -3632,8 +3565,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context* ssl) /* Check record type */ if (ssl->in_msgtype != MBEDTLS_SSL_MSG_HANDSHAKE && ssl->in_msgtype != MBEDTLS_SSL_MSG_ALERT - && ssl->in_msgtype != MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC - && ssl->in_msgtype != MBEDTLS_SSL_MSG_APPLICATION_DATA) { + && ssl->in_msgtype != MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC && ssl->in_msgtype != MBEDTLS_SSL_MSG_APPLICATION_DATA) { MBEDTLS_SSL_DEBUG_MSG(1, ("unknown record type")); #if defined(MBEDTLS_SSL_PROTO_DTLS) @@ -3641,8 +3573,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context* ssl) * Section 4.1.2.7 */ if (ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM) #endif /* MBEDTLS_SSL_PROTO_DTLS */ - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE); return (MBEDTLS_ERR_SSL_INVALID_RECORD); } @@ -3694,9 +3625,8 @@ static int ssl_parse_record_header(mbedtls_ssl_context* ssl) * have an active transform (possibly iv_len != 0), so use the * fact that the record header len is 13 instead. */ - if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER && ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER - && rec_epoch == 0 && ssl->in_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE && ssl->in_left > 13 - && ssl->in_buf[13] == MBEDTLS_SSL_HS_CLIENT_HELLO) { + if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER && ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER && rec_epoch == 0 + && ssl->in_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE && ssl->in_left > 13 && ssl->in_buf[13] == MBEDTLS_SSL_HS_CLIENT_HELLO) { MBEDTLS_SSL_DEBUG_MSG( 1, ("possible client reconnect " "from the same port")); @@ -3748,8 +3678,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context* ssl) } #if defined(MBEDTLS_SSL_PROTO_SSL3) - if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 - && ssl->in_msglen > ssl->transform_in->minlen + MBEDTLS_SSL_IN_CONTENT_LEN) { + if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 && ssl->in_msglen > ssl->transform_in->minlen + MBEDTLS_SSL_IN_CONTENT_LEN) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad message length")); return (MBEDTLS_ERR_SSL_INVALID_RECORD); } @@ -3758,8 +3687,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context* ssl) /* * TLS encrypted messages can have up to 256 bytes of padding */ - if (ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 - && ssl->in_msglen > ssl->transform_in->minlen + MBEDTLS_SSL_IN_CONTENT_LEN + 256) { + if (ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 && ssl->in_msglen > ssl->transform_in->minlen + MBEDTLS_SSL_IN_CONTENT_LEN + 256) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad message length")); return (MBEDTLS_ERR_SSL_INVALID_RECORD); } @@ -3772,7 +3700,7 @@ static int ssl_parse_record_header(mbedtls_ssl_context* ssl) /* * If applicable, decrypt (and decompress) record content */ -static int ssl_prepare_record_content(mbedtls_ssl_context* ssl) +int ssl_prepare_record_content(mbedtls_ssl_context* ssl) { int ret, done = 0; @@ -3848,8 +3776,7 @@ int mbedtls_ssl_read_record(mbedtls_ssl_context* ssl, unsigned update_hs_digest) /* We only check for buffered messages if the * current datagram is fully consumed. */ - if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM - && ssl_next_record_is_in_datagram(ssl) == 0) { + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl_next_record_is_in_datagram(ssl) == 0) { if (ssl_load_buffered_message(ssl) == 0) have_buffered = 1; } @@ -3951,8 +3878,7 @@ static int ssl_load_buffered_message(mbedtls_ssl_context* ssl) hs_buf = &hs->buffering.hs[offset]; if (hs_buf->is_valid == 1) { MBEDTLS_SSL_DEBUG_MSG( - 2, ("Future message with sequence number %u %s buffered.", hs->in_msg_seq + offset, - hs_buf->is_complete ? "fully" : "partially")); + 2, ("Future message with sequence number %u %s buffered.", hs->in_msg_seq + offset, hs_buf->is_complete ? "fully" : "partially")); } } } @@ -4013,8 +3939,7 @@ static int ssl_buffer_make_space(mbedtls_ssl_context* ssl, size_t desired) * message. Remove buffers used for future messages to gain space, * starting with the most distant one. */ for (offset = MBEDTLS_SSL_MAX_BUFFERED_HS - 1; offset >= 0; offset--) { - MBEDTLS_SSL_DEBUG_MSG( - 2, ("Free buffering slot %d to make space for reassembly of next handshake message", offset)); + MBEDTLS_SSL_DEBUG_MSG(2, ("Free buffering slot %d to make space for reassembly of next handshake message", offset)); ssl_buffering_free_slot(ssl, (uint8_t)offset); @@ -4064,14 +3989,12 @@ static int ssl_buffer_message(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG( 2, ("Ignore future HS message with sequence number %u, " "buffering window %u - %u", - recv_msg_seq, ssl->handshake->in_msg_seq, - ssl->handshake->in_msg_seq + MBEDTLS_SSL_MAX_BUFFERED_HS - 1)); + recv_msg_seq, ssl->handshake->in_msg_seq, ssl->handshake->in_msg_seq + MBEDTLS_SSL_MAX_BUFFERED_HS - 1)); goto exit; } - MBEDTLS_SSL_DEBUG_MSG( - 2, ("Buffering HS message with sequence number %u, offset %u ", recv_msg_seq, recv_msg_seq_offset)); + MBEDTLS_SSL_DEBUG_MSG(2, ("Buffering HS message with sequence number %u, offset %u ", recv_msg_seq, recv_msg_seq_offset)); hs_buf = &hs->buffering.hs[recv_msg_seq_offset]; @@ -4106,16 +4029,14 @@ static int ssl_buffer_message(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG( 2, ("Buffering of future message of size %u would exceed the compile-time " "limit %u (already %u bytes buffered) -- ignore\n", - (unsigned)msg_len, MBEDTLS_SSL_DTLS_MAX_BUFFERING, - (unsigned)hs->buffering.total_bytes_buffered)); + (unsigned)msg_len, MBEDTLS_SSL_DTLS_MAX_BUFFERING, (unsigned)hs->buffering.total_bytes_buffered)); goto exit; } else { MBEDTLS_SSL_DEBUG_MSG( 2, ("Buffering of future message of size %u would exceed the compile-time " "limit %u (already %u bytes buffered) -- attempt to make space by " "freeing buffered future messages\n", - (unsigned)msg_len, MBEDTLS_SSL_DTLS_MAX_BUFFERING, - (unsigned)hs->buffering.total_bytes_buffered)); + (unsigned)msg_len, MBEDTLS_SSL_DTLS_MAX_BUFFERING, (unsigned)hs->buffering.total_bytes_buffered)); } if (ssl_buffer_make_space(ssl, reassembly_buf_sz) != 0) { @@ -4490,8 +4411,7 @@ static int ssl_get_next_record(mbedtls_ssl_context* ssl) if (ssl->state == MBEDTLS_SSL_CLIENT_FINISHED || ssl->state == MBEDTLS_SSL_SERVER_FINISHED) { #if defined(MBEDTLS_SSL_ALL_ALERT_MESSAGES) if (ret == MBEDTLS_ERR_SSL_INVALID_MAC) { - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC); } #endif return (ret); @@ -4521,8 +4441,7 @@ static int ssl_get_next_record(mbedtls_ssl_context* ssl) /* Error out (and send alert) on invalid records */ #if defined(MBEDTLS_SSL_ALL_ALERT_MESSAGES) if (ret == MBEDTLS_ERR_SSL_INVALID_MAC) { - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC); } #endif return (ret); @@ -4557,8 +4476,7 @@ int mbedtls_ssl_handle_message_type(mbedtls_ssl_context* ssl) } #if defined(MBEDTLS_SSL_PROTO_DTLS) - if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM - && ssl->state != MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->state != MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC && ssl->state != MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC) { if (ssl->handshake == NULL) { MBEDTLS_SSL_DEBUG_MSG(1, ("dropping ChangeCipherSpec outside handshake")); @@ -4596,8 +4514,7 @@ int mbedtls_ssl_handle_message_type(mbedtls_ssl_context* ssl) } #if defined(MBEDTLS_SSL_RENEGOTIATION_ENABLED) - if (ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING - && ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION) { + if (ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING && ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION) { MBEDTLS_SSL_DEBUG_MSG(2, ("is a SSLv3 no renegotiation alert")); /* Will be handled when trying to parse ServerHello */ return (0); @@ -4618,8 +4535,7 @@ int mbedtls_ssl_handle_message_type(mbedtls_ssl_context* ssl) } #if defined(MBEDTLS_SSL_PROTO_DTLS) - if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->handshake != NULL - && ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER) { + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->handshake != NULL && ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER) { ssl_handshake_wrapup_free_hs_transform(ssl); } #endif @@ -4631,9 +4547,7 @@ int mbedtls_ssl_send_fatal_handshake_failure(mbedtls_ssl_context* ssl) { int ret; - if ((ret = mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE)) - != 0) { + if ((ret = mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE)) != 0) { return (ret); } @@ -4667,10 +4581,9 @@ int mbedtls_ssl_send_alert_message(mbedtls_ssl_context* ssl, unsigned char level /* * Handshake functions */ -#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) \ - && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) +#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) \ + && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) /* No certificate support -> dummy functions */ int mbedtls_ssl_write_certificate(mbedtls_ssl_context* ssl) { @@ -4678,10 +4591,8 @@ int mbedtls_ssl_write_certificate(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(2, ("=> write certificate")); - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip write certificate")); ssl->state++; return (0); @@ -4697,10 +4608,8 @@ int mbedtls_ssl_parse_certificate(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(2, ("=> parse certificate")); - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip parse certificate")); ssl->state++; return (0); @@ -4722,10 +4631,8 @@ int mbedtls_ssl_write_certificate(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(2, ("=> write certificate")); - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip write certificate")); ssl->state++; return (0); @@ -4836,8 +4743,8 @@ static int ssl_parse_certificate_chain(mbedtls_ssl_context* ssl) * Check if the client sent an empty certificate */ if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER && ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { - if (ssl->in_msglen == 2 && ssl->in_msgtype == MBEDTLS_SSL_MSG_ALERT - && ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING && ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_NO_CERT) { + if (ssl->in_msglen == 2 && ssl->in_msgtype == MBEDTLS_SSL_MSG_ALERT && ssl->in_msg[0] == MBEDTLS_SSL_ALERT_LEVEL_WARNING + && ssl->in_msg[1] == MBEDTLS_SSL_ALERT_MSG_NO_CERT) { MBEDTLS_SSL_DEBUG_MSG(1, ("SSLv3 client has no certificate")); /* The client was asked for a certificate but didn't send @@ -4852,8 +4759,7 @@ static int ssl_parse_certificate_chain(mbedtls_ssl_context* ssl) #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2) if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER && ssl->minor_ver != MBEDTLS_SSL_MINOR_VERSION_0) { if (ssl->in_hslen == 3 + mbedtls_ssl_hs_hdr_len(ssl) && ssl->in_msgtype == MBEDTLS_SSL_MSG_HANDSHAKE - && ssl->in_msg[0] == MBEDTLS_SSL_HS_CERTIFICATE - && memcmp(ssl->in_msg + mbedtls_ssl_hs_hdr_len(ssl), "\0\0\0", 3) == 0) { + && ssl->in_msg[0] == MBEDTLS_SSL_HS_CERTIFICATE && memcmp(ssl->in_msg + mbedtls_ssl_hs_hdr_len(ssl), "\0\0\0", 3) == 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("TLSv1 client has no certificate")); /* The client was asked for a certificate but didn't send @@ -4971,10 +4877,7 @@ static int ssl_parse_certificate_chain(mbedtls_ssl_context* ssl) } if (ssl->session->peer_cert->raw.len != ssl->session_negotiate->peer_cert->raw.len - || memcmp( - ssl->session->peer_cert->raw.p, ssl->session_negotiate->peer_cert->raw.p, - ssl->session->peer_cert->raw.len) - != 0) { + || memcmp(ssl->session->peer_cert->raw.p, ssl->session_negotiate->peer_cert->raw.p, ssl->session->peer_cert->raw.len) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("server cert changed during renegotiation")); mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED); return (MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE); @@ -4990,8 +4893,7 @@ int mbedtls_ssl_parse_certificate(mbedtls_ssl_context* ssl) int ret; const mbedtls_ssl_ciphersuite_t* const ciphersuite_info = ssl->transform_negotiate->ciphersuite_info; #if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) - const int authmode = - ssl->handshake->sni_authmode != MBEDTLS_SSL_VERIFY_UNSET ? ssl->handshake->sni_authmode : ssl->conf->authmode; + const int authmode = ssl->handshake->sni_authmode != MBEDTLS_SSL_VERIFY_UNSET ? ssl->handshake->sni_authmode : ssl->conf->authmode; #else const int authmode = ssl->conf->authmode; #endif @@ -4999,18 +4901,15 @@ int mbedtls_ssl_parse_certificate(mbedtls_ssl_context* ssl) MBEDTLS_SSL_DEBUG_MSG(2, ("=> parse certificate")); - if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK - || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { + if (ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK + || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK || ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip parse certificate")); ssl->state++; return (0); } #if defined(MBEDTLS_SSL_SRV_C) - if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER - && ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK) { + if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER && ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK) { MBEDTLS_SSL_DEBUG_MSG(2, ("<= skip parse certificate")); ssl->state++; return (0); @@ -5077,8 +4976,8 @@ crt_verify: * Main check: verify certificate */ ret = mbedtls_x509_crt_verify_restartable( - ssl->session_negotiate->peer_cert, ca_chain, ca_crl, ssl->conf->cert_profile, ssl->hostname, - &ssl->session_negotiate->verify_result, ssl->conf->f_vrfy, ssl->conf->p_vrfy, rs_ctx); + ssl->session_negotiate->peer_cert, ca_chain, ca_crl, ssl->conf->cert_profile, ssl->hostname, &ssl->session_negotiate->verify_result, + ssl->conf->f_vrfy, ssl->conf->p_vrfy, rs_ctx); if (ret != 0) { MBEDTLS_SSL_DEBUG_RET(1, "x509_verify_cert", ret); @@ -5098,8 +4997,7 @@ crt_verify: const mbedtls_pk_context* pk = &ssl->session_negotiate->peer_cert->pk; /* If certificate uses an EC key, make sure the curve is OK */ - if (mbedtls_pk_can_do(pk, MBEDTLS_PK_ECKEY) - && mbedtls_ssl_check_curve(ssl, mbedtls_pk_ec(*pk)->grp.id) != 0) { + if (mbedtls_pk_can_do(pk, MBEDTLS_PK_ECKEY) && mbedtls_ssl_check_curve(ssl, mbedtls_pk_ec(*pk)->grp.id) != 0) { ssl->session_negotiate->verify_result |= MBEDTLS_X509_BADCERT_BAD_KEY; MBEDTLS_SSL_DEBUG_MSG(1, ("bad certificate (EC key curve)")); @@ -5110,8 +5008,7 @@ crt_verify: #endif /* MBEDTLS_ECP_C */ if (mbedtls_ssl_check_cert_usage( - ssl->session_negotiate->peer_cert, ciphersuite_info, !ssl->conf->endpoint, - &ssl->session_negotiate->verify_result) + ssl->session_negotiate->peer_cert, ciphersuite_info, !ssl->conf->endpoint, &ssl->session_negotiate->verify_result) != 0) { MBEDTLS_SSL_DEBUG_MSG(1, ("bad certificate (usage extensions)")); if (ret == 0) @@ -5124,8 +5021,7 @@ crt_verify: * of error codes, including those from the user provided f_vrfy * functions, are treated as fatal and lead to a failure of * ssl_parse_certificate even if verification was optional. */ - if (authmode == MBEDTLS_SSL_VERIFY_OPTIONAL - && (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED || ret == MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE)) { + if (authmode == MBEDTLS_SSL_VERIFY_OPTIONAL && (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED || ret == MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE)) { ret = 0; } @@ -5979,8 +5875,7 @@ static int ssl_handshake_init(mbedtls_ssl_context* ssl) #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C) /* Dummy cookie callbacks for defaults */ -static int ssl_cookie_write_dummy( - void* ctx, unsigned char** p, unsigned char* end, const unsigned char* cli_id, size_t cli_id_len) +static int ssl_cookie_write_dummy(void* ctx, unsigned char** p, unsigned char* end, const unsigned char* cli_id, size_t cli_id_len) { ((void)ctx); ((void)p); @@ -5991,8 +5886,7 @@ static int ssl_cookie_write_dummy( return (MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE); } -static int ssl_cookie_check_dummy( - void* ctx, const unsigned char* cookie, size_t cookie_len, const unsigned char* cli_id, size_t cli_id_len) +static int ssl_cookie_check_dummy(void* ctx, const unsigned char* cookie, size_t cookie_len, const unsigned char* cli_id, size_t cli_id_len) { ((void)ctx); ((void)cookie); @@ -6326,8 +6220,7 @@ void mbedtls_ssl_conf_authmode(mbedtls_ssl_config* conf, int authmode) } #if defined(MBEDTLS_X509_CRT_PARSE_C) -void mbedtls_ssl_conf_verify( - mbedtls_ssl_config* conf, int (*f_vrfy)(void*, mbedtls_x509_crt*, int, uint32_t*), void* p_vrfy) +void mbedtls_ssl_conf_verify(mbedtls_ssl_config* conf, int (*f_vrfy)(void*, mbedtls_x509_crt*, int, uint32_t*), void* p_vrfy) { conf->f_vrfy = f_vrfy; conf->p_vrfy = p_vrfy; @@ -6340,19 +6233,14 @@ void mbedtls_ssl_conf_rng(mbedtls_ssl_config* conf, int (*f_rng)(void*, unsigned conf->p_rng = p_rng; } -void mbedtls_ssl_conf_dbg( - mbedtls_ssl_config* conf, void (*f_dbg)(void*, int, const char*, int, const char*), void* p_dbg) +void mbedtls_ssl_conf_dbg(mbedtls_ssl_config* conf, void (*f_dbg)(void*, int, const char*, int, const char*), void* p_dbg) { conf->f_dbg = f_dbg; conf->p_dbg = p_dbg; } void mbedtls_ssl_set_bio( - mbedtls_ssl_context* ssl, - void* p_bio, - mbedtls_ssl_send_t* f_send, - mbedtls_ssl_recv_t* f_recv, - mbedtls_ssl_recv_timeout_t* f_recv_timeout) + mbedtls_ssl_context* ssl, void* p_bio, mbedtls_ssl_send_t* f_send, mbedtls_ssl_recv_t* f_recv, mbedtls_ssl_recv_timeout_t* f_recv_timeout) { ssl->p_bio = p_bio; ssl->f_send = f_send; @@ -6372,8 +6260,7 @@ void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config* conf, uint32_t timeout) conf->read_timeout = timeout; } -void mbedtls_ssl_set_timer_cb( - mbedtls_ssl_context* ssl, void* p_timer, mbedtls_ssl_set_timer_t* f_set_timer, mbedtls_ssl_get_timer_t* f_get_timer) +void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context* ssl, void* p_timer, mbedtls_ssl_set_timer_t* f_set_timer, mbedtls_ssl_get_timer_t* f_get_timer) { ssl->p_timer = p_timer; ssl->f_set_timer = f_set_timer; @@ -6385,10 +6272,7 @@ void mbedtls_ssl_set_timer_cb( #if defined(MBEDTLS_SSL_SRV_C) void mbedtls_ssl_conf_session_cache( - mbedtls_ssl_config* conf, - void* p_cache, - int (*f_get_cache)(void*, mbedtls_ssl_session*), - int (*f_set_cache)(void*, const mbedtls_ssl_session*)) + mbedtls_ssl_config* conf, void* p_cache, int (*f_get_cache)(void*, mbedtls_ssl_session*), int (*f_set_cache)(void*, const mbedtls_ssl_session*)) { conf->p_cache = p_cache; conf->f_get_cache = f_get_cache; @@ -6401,8 +6285,7 @@ int mbedtls_ssl_set_session(mbedtls_ssl_context* ssl, const mbedtls_ssl_session* { int ret; - if (ssl == NULL || session == NULL || ssl->session_negotiate == NULL - || ssl->conf->endpoint != MBEDTLS_SSL_IS_CLIENT) { + if (ssl == NULL || session == NULL || ssl->session_negotiate == NULL || ssl->conf->endpoint != MBEDTLS_SSL_IS_CLIENT) { return (MBEDTLS_ERR_SSL_BAD_INPUT_DATA); } @@ -6512,18 +6395,13 @@ int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context* ssl, const unsigned else role = MBEDTLS_ECJPAKE_CLIENT; - return (mbedtls_ecjpake_setup( - &ssl->handshake->ecjpake_ctx, role, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len)); + return (mbedtls_ecjpake_setup(&ssl->handshake->ecjpake_ctx, role, MBEDTLS_MD_SHA256, MBEDTLS_ECP_DP_SECP256R1, pw, pw_len)); } #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) int mbedtls_ssl_conf_psk( - mbedtls_ssl_config* conf, - const unsigned char* psk, - size_t psk_len, - const unsigned char* psk_identity, - size_t psk_identity_len) + mbedtls_ssl_config* conf, const unsigned char* psk, size_t psk_len, const unsigned char* psk_identity, size_t psk_identity_len) { if (psk == NULL || psk_identity == NULL) return (MBEDTLS_ERR_SSL_BAD_INPUT_DATA); @@ -6549,8 +6427,7 @@ int mbedtls_ssl_conf_psk( conf->psk_identity_len = 0; } - if ((conf->psk = mbedtls_calloc(1, psk_len)) == NULL - || (conf->psk_identity = mbedtls_calloc(1, psk_identity_len)) == NULL) { + if ((conf->psk = mbedtls_calloc(1, psk_len)) == NULL || (conf->psk_identity = mbedtls_calloc(1, psk_identity_len)) == NULL) { mbedtls_free(conf->psk); mbedtls_free(conf->psk_identity); conf->psk = NULL; @@ -6590,8 +6467,7 @@ int mbedtls_ssl_set_hs_psk(mbedtls_ssl_context* ssl, const unsigned char* psk, s return (0); } -void mbedtls_ssl_conf_psk_cb( - mbedtls_ssl_config* conf, int (*f_psk)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_psk) +void mbedtls_ssl_conf_psk_cb(mbedtls_ssl_config* conf, int (*f_psk)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_psk) { conf->f_psk = f_psk; conf->p_psk = p_psk; @@ -6605,8 +6481,7 @@ int mbedtls_ssl_conf_dh_param(mbedtls_ssl_config* conf, const char* dhm_P, const { int ret; - if ((ret = mbedtls_mpi_read_string(&conf->dhm_P, 16, dhm_P)) != 0 - || (ret = mbedtls_mpi_read_string(&conf->dhm_G, 16, dhm_G)) != 0) { + if ((ret = mbedtls_mpi_read_string(&conf->dhm_P, 16, dhm_P)) != 0 || (ret = mbedtls_mpi_read_string(&conf->dhm_G, 16, dhm_G)) != 0) { mbedtls_mpi_free(&conf->dhm_P); mbedtls_mpi_free(&conf->dhm_G); return (ret); @@ -6616,13 +6491,11 @@ int mbedtls_ssl_conf_dh_param(mbedtls_ssl_config* conf, const char* dhm_P, const } #endif /* MBEDTLS_DEPRECATED_REMOVED */ -int mbedtls_ssl_conf_dh_param_bin( - mbedtls_ssl_config* conf, const unsigned char* dhm_P, size_t P_len, const unsigned char* dhm_G, size_t G_len) +int mbedtls_ssl_conf_dh_param_bin(mbedtls_ssl_config* conf, const unsigned char* dhm_P, size_t P_len, const unsigned char* dhm_G, size_t G_len) { int ret; - if ((ret = mbedtls_mpi_read_binary(&conf->dhm_P, dhm_P, P_len)) != 0 - || (ret = mbedtls_mpi_read_binary(&conf->dhm_G, dhm_G, G_len)) != 0) { + if ((ret = mbedtls_mpi_read_binary(&conf->dhm_P, dhm_P, P_len)) != 0 || (ret = mbedtls_mpi_read_binary(&conf->dhm_G, dhm_G, G_len)) != 0) { mbedtls_mpi_free(&conf->dhm_P); mbedtls_mpi_free(&conf->dhm_G); return (ret); @@ -6635,8 +6508,7 @@ int mbedtls_ssl_conf_dh_param_ctx(mbedtls_ssl_config* conf, mbedtls_dhm_context* { int ret; - if ((ret = mbedtls_mpi_copy(&conf->dhm_P, &dhm_ctx->P)) != 0 - || (ret = mbedtls_mpi_copy(&conf->dhm_G, &dhm_ctx->G)) != 0) { + if ((ret = mbedtls_mpi_copy(&conf->dhm_P, &dhm_ctx->P)) != 0 || (ret = mbedtls_mpi_copy(&conf->dhm_G, &dhm_ctx->G)) != 0) { mbedtls_mpi_free(&conf->dhm_P); mbedtls_mpi_free(&conf->dhm_G); return (ret); @@ -6718,8 +6590,7 @@ int mbedtls_ssl_set_hostname(mbedtls_ssl_context* ssl, const char* hostname) #endif /* MBEDTLS_X509_CRT_PARSE_C */ #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) -void mbedtls_ssl_conf_sni( - mbedtls_ssl_config* conf, int (*f_sni)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_sni) +void mbedtls_ssl_conf_sni(mbedtls_ssl_config* conf, int (*f_sni)(void*, mbedtls_ssl_context*, const unsigned char*, size_t), void* p_sni) { conf->f_sni = f_sni; conf->p_sni = p_sni; @@ -6807,8 +6678,7 @@ void mbedtls_ssl_conf_arc4_support(mbedtls_ssl_config* conf, char arc4) #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config* conf, unsigned char mfl_code) { - if (mfl_code >= MBEDTLS_SSL_MAX_FRAG_LEN_INVALID - || ssl_mfl_code_to_length(mfl_code) > MBEDTLS_TLS_EXT_ADV_CONTENT_LEN) { + if (mfl_code >= MBEDTLS_SSL_MAX_FRAG_LEN_INVALID || ssl_mfl_code_to_length(mfl_code) > MBEDTLS_TLS_EXT_ADV_CONTENT_LEN) { return (MBEDTLS_ERR_SSL_BAD_INPUT_DATA); } @@ -6864,10 +6734,7 @@ void mbedtls_ssl_conf_session_tickets(mbedtls_ssl_config* conf, int use_tickets) #if defined(MBEDTLS_SSL_SRV_C) void mbedtls_ssl_conf_session_tickets_cb( - mbedtls_ssl_config* conf, - mbedtls_ssl_ticket_write_t* f_ticket_write, - mbedtls_ssl_ticket_parse_t* f_ticket_parse, - void* p_ticket) + mbedtls_ssl_config* conf, mbedtls_ssl_ticket_write_t* f_ticket_write, mbedtls_ssl_ticket_parse_t* f_ticket_parse, void* p_ticket) { conf->f_ticket_write = f_ticket_write; conf->f_ticket_parse = f_ticket_parse; @@ -6877,8 +6744,7 @@ void mbedtls_ssl_conf_session_tickets_cb( #endif /* MBEDTLS_SSL_SESSION_TICKETS */ #if defined(MBEDTLS_SSL_EXPORT_KEYS) -void mbedtls_ssl_conf_export_keys_cb( - mbedtls_ssl_config* conf, mbedtls_ssl_export_keys_t* f_export_keys, void* p_export_keys) +void mbedtls_ssl_conf_export_keys_cb(mbedtls_ssl_config* conf, mbedtls_ssl_export_keys_t* f_export_keys, void* p_export_keys) { conf->f_export_keys = f_export_keys; conf->p_export_keys = p_export_keys; @@ -7107,8 +6973,7 @@ size_t mbedtls_ssl_get_max_frag_len(const mbedtls_ssl_context* ssl) static size_t ssl_get_current_mtu(const mbedtls_ssl_context* ssl) { /* Return unlimited mtu for client hello messages to avoid fragmentation. */ - if (ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT - && (ssl->state == MBEDTLS_SSL_CLIENT_HELLO || ssl->state == MBEDTLS_SSL_SERVER_HELLO)) + if (ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT && (ssl->state == MBEDTLS_SSL_CLIENT_HELLO || ssl->state == MBEDTLS_SSL_SERVER_HELLO)) return (0); if (ssl->handshake == NULL || ssl->handshake->mtu == 0) @@ -7276,8 +7141,7 @@ static int ssl_start_renegotiation(mbedtls_ssl_context* ssl) /* RFC 6347 4.2.2: "[...] the HelloRequest will have message_seq = 0 and * the ServerHello will have message_seq = 1" */ #if defined(MBEDTLS_SSL_PROTO_DTLS) - if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM - && ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_PENDING) { + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_PENDING) { if (ssl->conf->endpoint == MBEDTLS_SSL_IS_SERVER) ssl->handshake->out_msg_seq = 1; else @@ -7505,8 +7369,7 @@ int mbedtls_ssl_read(mbedtls_ssl_context* ssl, unsigned char* buf, size_t len) /* DTLS clients need to know renego is server-initiated */ #if defined(MBEDTLS_SSL_PROTO_DTLS) - if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM - && ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT) { + if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM && ssl->conf->endpoint == MBEDTLS_SSL_IS_CLIENT) { ssl->renego_status = MBEDTLS_SSL_RENEGOTIATION_PENDING; } #endif @@ -7528,16 +7391,13 @@ int mbedtls_ssl_read(mbedtls_ssl_context* ssl, unsigned char* buf, size_t len) if (ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0) { /* SSLv3 does not have a "no_renegotiation" warning, so we send a fatal alert and abort the connection. */ - mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE); + mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE); return (MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE); } else #endif /* MBEDTLS_SSL_PROTO_SSL3 */ #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2) if (ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1) { - if ((ret = mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_WARNING, MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION)) - != 0) { + if ((ret = mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_WARNING, MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION)) != 0) { return (ret); } } else @@ -7715,8 +7575,7 @@ static int ssl_write_split(mbedtls_ssl_context* ssl, const unsigned char* buf, s { int ret; - if (ssl->conf->cbc_record_splitting == MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED || len <= 1 - || ssl->minor_ver > MBEDTLS_SSL_MINOR_VERSION_1 + if (ssl->conf->cbc_record_splitting == MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED || len <= 1 || ssl->minor_ver > MBEDTLS_SSL_MINOR_VERSION_1 || mbedtls_cipher_get_cipher_mode(&ssl->transform_out->cipher_ctx_enc) != MBEDTLS_MODE_CBC) { return (ssl_write_real(ssl, buf, len)); } @@ -7788,9 +7647,7 @@ int mbedtls_ssl_close_notify(mbedtls_ssl_context* ssl) return (mbedtls_ssl_flush_output(ssl)); if (ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER) { - if ((ret = mbedtls_ssl_send_alert_message( - ssl, MBEDTLS_SSL_ALERT_LEVEL_WARNING, MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY)) - != 0) { + if ((ret = mbedtls_ssl_send_alert_message(ssl, MBEDTLS_SSL_ALERT_LEVEL_WARNING, MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY)) != 0) { MBEDTLS_SSL_DEBUG_RET(1, "mbedtls_ssl_send_alert_message", ret); return (ret); } @@ -8050,8 +7907,7 @@ static int ssl_preset_default_hashes[] = { MBEDTLS_MD_NONE}; #endif -static int ssl_preset_suiteb_ciphersuites[] = { - MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, 0}; +static int ssl_preset_suiteb_ciphersuites[] = {MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, 0}; #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) static int ssl_preset_suiteb_hashes[] = {MBEDTLS_MD_SHA256, MBEDTLS_MD_SHA384, MBEDTLS_MD_NONE}; @@ -8179,12 +8035,10 @@ int mbedtls_ssl_config_defaults(mbedtls_ssl_config* conf, int endpoint, int tran * Default */ default: - conf->min_major_ver = (MBEDTLS_SSL_MIN_MAJOR_VERSION > MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION) - ? MBEDTLS_SSL_MIN_MAJOR_VERSION - : MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION; - conf->min_minor_ver = (MBEDTLS_SSL_MIN_MINOR_VERSION > MBEDTLS_SSL_MIN_VALID_MINOR_VERSION) - ? MBEDTLS_SSL_MIN_MINOR_VERSION - : MBEDTLS_SSL_MIN_VALID_MINOR_VERSION; + conf->min_major_ver = (MBEDTLS_SSL_MIN_MAJOR_VERSION > MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION) ? MBEDTLS_SSL_MIN_MAJOR_VERSION + : MBEDTLS_SSL_MIN_VALID_MAJOR_VERSION; + conf->min_minor_ver = (MBEDTLS_SSL_MIN_MINOR_VERSION > MBEDTLS_SSL_MIN_VALID_MINOR_VERSION) ? MBEDTLS_SSL_MIN_MINOR_VERSION + : MBEDTLS_SSL_MIN_VALID_MINOR_VERSION; conf->max_major_ver = MBEDTLS_SSL_MAX_MAJOR_VERSION; conf->max_minor_ver = MBEDTLS_SSL_MAX_MINOR_VERSION; @@ -8444,8 +8298,7 @@ int mbedtls_ssl_check_sig_hash(const mbedtls_ssl_context* ssl, mbedtls_md_type_t #endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */ #if defined(MBEDTLS_X509_CRT_PARSE_C) -int mbedtls_ssl_check_cert_usage( - const mbedtls_x509_crt* cert, const mbedtls_ssl_ciphersuite_t* ciphersuite, int cert_endpoint, uint32_t* flags) +int mbedtls_ssl_check_cert_usage(const mbedtls_x509_crt* cert, const mbedtls_ssl_ciphersuite_t* ciphersuite, int cert_endpoint, uint32_t* flags) { int ret = 0; #if defined(MBEDTLS_X509_CHECK_KEY_USAGE) @@ -8611,8 +8464,7 @@ int mbedtls_ssl_set_calc_verify_md(mbedtls_ssl_context* ssl, int md) } #if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) -int mbedtls_ssl_get_key_exchange_md_ssl_tls( - mbedtls_ssl_context* ssl, unsigned char* output, unsigned char* data, size_t data_len) +int mbedtls_ssl_get_key_exchange_md_ssl_tls(mbedtls_ssl_context* ssl, unsigned char* output, unsigned char* data, size_t data_len) { int ret = 0; mbedtls_md5_context mbedtls_md5; @@ -8682,12 +8534,7 @@ exit: #if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || defined(MBEDTLS_SSL_PROTO_TLS1_2) int mbedtls_ssl_get_key_exchange_md_tls1_2( - mbedtls_ssl_context* ssl, - unsigned char* hash, - size_t* hashlen, - unsigned char* data, - size_t data_len, - mbedtls_md_type_t md_alg) + mbedtls_ssl_context* ssl, unsigned char* hash, size_t* hashlen, unsigned char* data, size_t data_len, mbedtls_md_type_t md_alg) { int ret = 0; mbedtls_md_context_t ctx; diff --git a/nettls/ssl/x509.c b/nettls/ssl/x509.c index 7c073601c70f4f9ee68216b0b8b3101c0288092d..526642a97238a6be00d1296087d459dd03865a4b 100644 --- a/nettls/ssl/x509.c +++ b/nettls/ssl/x509.c @@ -222,8 +222,7 @@ static int x509_get_hash_alg(const mbedtls_x509_buf* alg, mbedtls_md_type_t* md_ * of trailerField MUST be 1, and PKCS#1 v2.2 doesn't even define any other * option. Enfore this at parsing time. */ -int mbedtls_x509_get_rsassa_pss_params( - const mbedtls_x509_buf* params, mbedtls_md_type_t* md_alg, mbedtls_md_type_t* mgf_md, int* salt_len) +int mbedtls_x509_get_rsassa_pss_params(const mbedtls_x509_buf* params, mbedtls_md_type_t* md_alg, mbedtls_md_type_t* mgf_md, int* salt_len) { int ret; unsigned char* p; @@ -249,8 +248,7 @@ int mbedtls_x509_get_rsassa_pss_params( /* * HashAlgorithm */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)) - == 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)) == 0) { end2 = p + len; /* HashAlgorithm ::= AlgorithmIdentifier (without parameters) */ @@ -271,8 +269,7 @@ int mbedtls_x509_get_rsassa_pss_params( /* * MaskGenAlgorithm */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 1)) - == 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 1)) == 0) { end2 = p + len; /* MaskGenAlgorithm ::= AlgorithmIdentifier (params = HashAlgorithm) */ @@ -298,8 +295,7 @@ int mbedtls_x509_get_rsassa_pss_params( /* * salt_len */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 2)) - == 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 2)) == 0) { end2 = p + len; if ((ret = mbedtls_asn1_get_int(&p, end2, salt_len)) != 0) @@ -316,8 +312,7 @@ int mbedtls_x509_get_rsassa_pss_params( /* * trailer_field (if present, must be 1) */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 3)) - == 0) { + if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 3)) == 0) { int trailer_field; end2 = p + len; @@ -376,9 +371,8 @@ static int x509_get_attr_type_value(unsigned char** p, const unsigned char* end, if ((end - *p) < 1) return (MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA); - if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING && **p != MBEDTLS_ASN1_T61_STRING - && **p != MBEDTLS_ASN1_PRINTABLE_STRING && **p != MBEDTLS_ASN1_IA5_STRING - && **p != MBEDTLS_ASN1_UNIVERSAL_STRING && **p != MBEDTLS_ASN1_BIT_STRING) + if (**p != MBEDTLS_ASN1_BMP_STRING && **p != MBEDTLS_ASN1_UTF8_STRING && **p != MBEDTLS_ASN1_T61_STRING && **p != MBEDTLS_ASN1_PRINTABLE_STRING + && **p != MBEDTLS_ASN1_IA5_STRING && **p != MBEDTLS_ASN1_UNIVERSAL_STRING && **p != MBEDTLS_ASN1_BIT_STRING) return (MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG); val = &cur->val; @@ -644,11 +638,7 @@ int mbedtls_x509_get_sig(unsigned char** p, const unsigned char* end, mbedtls_x5 * Get signature algorithm from alg OID and optional parameters */ int mbedtls_x509_get_sig_alg( - const mbedtls_x509_buf* sig_oid, - const mbedtls_x509_buf* sig_params, - mbedtls_md_type_t* md_alg, - mbedtls_pk_type_t* pk_alg, - void** sig_opts) + const mbedtls_x509_buf* sig_oid, const mbedtls_x509_buf* sig_params, mbedtls_md_type_t* md_alg, mbedtls_pk_type_t* pk_alg, void** sig_opts) { int ret; @@ -666,8 +656,7 @@ int mbedtls_x509_get_sig_alg( if (pss_opts == NULL) return (MBEDTLS_ERR_X509_ALLOC_FAILED); - ret = mbedtls_x509_get_rsassa_pss_params( - sig_params, md_alg, &pss_opts->mgf1_hash_id, &pss_opts->expected_salt_len); + ret = mbedtls_x509_get_rsassa_pss_params(sig_params, md_alg, &pss_opts->mgf1_hash_id, &pss_opts->expected_salt_len); if (ret != 0) { mbedtls_free(pss_opts); return (ret); @@ -811,12 +800,7 @@ int mbedtls_x509_serial_gets(char* buf, size_t size, const mbedtls_x509_buf* ser * Helper for writing signature algorithms */ int mbedtls_x509_sig_alg_gets( - char* buf, - size_t size, - const mbedtls_x509_buf* sig_oid, - mbedtls_pk_type_t pk_alg, - mbedtls_md_type_t md_alg, - const void* sig_opts) + char* buf, size_t size, const mbedtls_x509_buf* sig_oid, mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, const void* sig_opts) { int ret; char* p = buf; @@ -841,8 +825,8 @@ int mbedtls_x509_sig_alg_gets( mgf_md_info = mbedtls_md_info_from_type(pss_opts->mgf1_hash_id); ret = mbedtls_snprintf( - p, n, " (%s, MGF1-%s, 0x%02X)", md_info ? mbedtls_md_get_name(md_info) : "???", - mgf_md_info ? mbedtls_md_get_name(mgf_md_info) : "???", pss_opts->expected_salt_len); + p, n, " (%s, MGF1-%s, 0x%02X)", md_info ? mbedtls_md_get_name(md_info) : "???", mgf_md_info ? mbedtls_md_get_name(mgf_md_info) : "???", + pss_opts->expected_salt_len); MBEDTLS_X509_SAFE_SNPRINTF; } #else @@ -911,16 +895,15 @@ static int x509_check_time(const mbedtls_x509_time* before, const mbedtls_x509_t if (before->year == after->year && before->mon == after->mon && before->day > after->day) return (1); - if (before->year == after->year && before->mon == after->mon && before->day == after->day - && before->hour > after->hour) + if (before->year == after->year && before->mon == after->mon && before->day == after->day && before->hour > after->hour) return (1); - if (before->year == after->year && before->mon == after->mon && before->day == after->day - && before->hour == after->hour && before->min > after->min) + if (before->year == after->year && before->mon == after->mon && before->day == after->day && before->hour == after->hour + && before->min > after->min) return (1); - if (before->year == after->year && before->mon == after->mon && before->day == after->day - && before->hour == after->hour && before->min == after->min && before->sec > after->sec) + if (before->year == after->year && before->mon == after->mon && before->day == after->day && before->hour == after->hour + && before->min == after->min && before->sec > after->sec) return (1); return (0); diff --git a/nettls/ssl/x509_create.c b/nettls/ssl/x509_create.c index 09d18118ec86d3d7ed06601ed78b4cc1e8542844..cf6a8a408b7c8e568fd2502040edb1ea198f3905 100644 --- a/nettls/ssl/x509_create.c +++ b/nettls/ssl/x509_create.c @@ -61,115 +61,82 @@ /* Structure linking OIDs for X.509 DN AttributeTypes to their * string representations and default string encodings used by Mbed TLS. */ typedef struct { - const char *name; /* String representation of AttributeType, e.g. - * "CN" or "emailAddress". */ - size_t name_len; /* Length of 'name', without trailing 0 byte. */ - const char *oid; /* String representation of OID of AttributeType, - * as per RFC 5280, Appendix A.1. */ - int default_tag; /* The default character encoding used for the - * given attribute type, e.g. - * MBEDTLS_ASN1_UTF8_STRING for UTF-8. */ + const char* name; /* String representation of AttributeType, e.g. + * "CN" or "emailAddress". */ + size_t name_len; /* Length of 'name', without trailing 0 byte. */ + const char* oid; /* String representation of OID of AttributeType, + * as per RFC 5280, Appendix A.1. */ + int default_tag; /* The default character encoding used for the + * given attribute type, e.g. + * MBEDTLS_ASN1_UTF8_STRING for UTF-8. */ } x509_attr_descriptor_t; -#define ADD_STRLEN( s ) s, sizeof( s ) - 1 +#define ADD_STRLEN(s) s, sizeof(s) - 1 /* X.509 DN attributes from RFC 5280, Appendix A.1. */ -static const x509_attr_descriptor_t x509_attrs[] = -{ - { ADD_STRLEN( "CN" ), - MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "commonName" ), - MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "C" ), - MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING }, - { ADD_STRLEN( "countryName" ), - MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING }, - { ADD_STRLEN( "O" ), - MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "organizationName" ), - MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "L" ), - MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "locality" ), - MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "R" ), - MBEDTLS_OID_PKCS9_EMAIL, MBEDTLS_ASN1_IA5_STRING }, - { ADD_STRLEN( "OU" ), - MBEDTLS_OID_AT_ORG_UNIT, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "organizationalUnitName" ), - MBEDTLS_OID_AT_ORG_UNIT, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "ST" ), - MBEDTLS_OID_AT_STATE, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "stateOrProvinceName" ), - MBEDTLS_OID_AT_STATE, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "emailAddress" ), - MBEDTLS_OID_PKCS9_EMAIL, MBEDTLS_ASN1_IA5_STRING }, - { ADD_STRLEN( "serialNumber" ), - MBEDTLS_OID_AT_SERIAL_NUMBER, MBEDTLS_ASN1_PRINTABLE_STRING }, - { ADD_STRLEN( "postalAddress" ), - MBEDTLS_OID_AT_POSTAL_ADDRESS, MBEDTLS_ASN1_PRINTABLE_STRING }, - { ADD_STRLEN( "postalCode" ), - MBEDTLS_OID_AT_POSTAL_CODE, MBEDTLS_ASN1_PRINTABLE_STRING }, - { ADD_STRLEN( "dnQualifier" ), - MBEDTLS_OID_AT_DN_QUALIFIER, MBEDTLS_ASN1_PRINTABLE_STRING }, - { ADD_STRLEN( "title" ), - MBEDTLS_OID_AT_TITLE, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "surName" ), - MBEDTLS_OID_AT_SUR_NAME, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "SN" ), - MBEDTLS_OID_AT_SUR_NAME, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "givenName" ), - MBEDTLS_OID_AT_GIVEN_NAME, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "GN" ), - MBEDTLS_OID_AT_GIVEN_NAME, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "initials" ), - MBEDTLS_OID_AT_INITIALS, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "pseudonym" ), - MBEDTLS_OID_AT_PSEUDONYM, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "generationQualifier" ), - MBEDTLS_OID_AT_GENERATION_QUALIFIER, MBEDTLS_ASN1_UTF8_STRING }, - { ADD_STRLEN( "domainComponent" ), - MBEDTLS_OID_DOMAIN_COMPONENT, MBEDTLS_ASN1_IA5_STRING }, - { ADD_STRLEN( "DC" ), - MBEDTLS_OID_DOMAIN_COMPONENT, MBEDTLS_ASN1_IA5_STRING }, - { NULL, 0, NULL, MBEDTLS_ASN1_NULL } +static const x509_attr_descriptor_t x509_attrs[] = { + {ADD_STRLEN("CN"), MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("commonName"), MBEDTLS_OID_AT_CN, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("C"), MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING}, + {ADD_STRLEN("countryName"), MBEDTLS_OID_AT_COUNTRY, MBEDTLS_ASN1_PRINTABLE_STRING}, + {ADD_STRLEN("O"), MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("organizationName"), MBEDTLS_OID_AT_ORGANIZATION, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("L"), MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("locality"), MBEDTLS_OID_AT_LOCALITY, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("R"), MBEDTLS_OID_PKCS9_EMAIL, MBEDTLS_ASN1_IA5_STRING}, + {ADD_STRLEN("OU"), MBEDTLS_OID_AT_ORG_UNIT, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("organizationalUnitName"), MBEDTLS_OID_AT_ORG_UNIT, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("ST"), MBEDTLS_OID_AT_STATE, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("stateOrProvinceName"), MBEDTLS_OID_AT_STATE, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("emailAddress"), MBEDTLS_OID_PKCS9_EMAIL, MBEDTLS_ASN1_IA5_STRING}, + {ADD_STRLEN("serialNumber"), MBEDTLS_OID_AT_SERIAL_NUMBER, MBEDTLS_ASN1_PRINTABLE_STRING}, + {ADD_STRLEN("postalAddress"), MBEDTLS_OID_AT_POSTAL_ADDRESS, MBEDTLS_ASN1_PRINTABLE_STRING}, + {ADD_STRLEN("postalCode"), MBEDTLS_OID_AT_POSTAL_CODE, MBEDTLS_ASN1_PRINTABLE_STRING}, + {ADD_STRLEN("dnQualifier"), MBEDTLS_OID_AT_DN_QUALIFIER, MBEDTLS_ASN1_PRINTABLE_STRING}, + {ADD_STRLEN("title"), MBEDTLS_OID_AT_TITLE, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("surName"), MBEDTLS_OID_AT_SUR_NAME, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("SN"), MBEDTLS_OID_AT_SUR_NAME, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("givenName"), MBEDTLS_OID_AT_GIVEN_NAME, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("GN"), MBEDTLS_OID_AT_GIVEN_NAME, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("initials"), MBEDTLS_OID_AT_INITIALS, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("pseudonym"), MBEDTLS_OID_AT_PSEUDONYM, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("generationQualifier"), MBEDTLS_OID_AT_GENERATION_QUALIFIER, MBEDTLS_ASN1_UTF8_STRING}, + {ADD_STRLEN("domainComponent"), MBEDTLS_OID_DOMAIN_COMPONENT, MBEDTLS_ASN1_IA5_STRING}, + {ADD_STRLEN("DC"), MBEDTLS_OID_DOMAIN_COMPONENT, MBEDTLS_ASN1_IA5_STRING}, + {NULL, 0, NULL, MBEDTLS_ASN1_NULL} }; -static const x509_attr_descriptor_t *x509_attr_descr_from_name( const char *name, size_t name_len ) +static const x509_attr_descriptor_t* x509_attr_descr_from_name(const char* name, size_t name_len) { - const x509_attr_descriptor_t *cur; + const x509_attr_descriptor_t* cur; - for( cur = x509_attrs; cur->name != NULL; cur++ ) - if( cur->name_len == name_len && - strncmp( cur->name, name, name_len ) == 0 ) + for (cur = x509_attrs; cur->name != NULL; cur++) + if (cur->name_len == name_len && strncmp(cur->name, name, name_len) == 0) break; - if ( cur->name == NULL ) - return( NULL ); + if (cur->name == NULL) + return (NULL); - return( cur ); + return (cur); } -int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *name ) +int mbedtls_x509_string_to_names(mbedtls_asn1_named_data** head, const char* name) { int ret = 0; const char *s = name, *c = s; - const char *end = s + strlen( s ); - const char *oid = NULL; + const char* end = s + strlen(s); + const char* oid = NULL; const x509_attr_descriptor_t* attr_descr = NULL; int in_tag = 1; char data[MBEDTLS_X509_MAX_DN_NAME_SIZE]; - char *d = data; + char* d = data; /* Clear existing chain if present */ - mbedtls_asn1_free_named_data_list( head ); - - while( c <= end ) - { - if( in_tag && *c == '=' ) - { - if( ( attr_descr = x509_attr_descr_from_name( s, c - s ) ) == NULL ) - { + mbedtls_asn1_free_named_data_list(head); + + while (c <= end) { + if (in_tag && *c == '=') { + if ((attr_descr = x509_attr_descr_from_name(s, c - s)) == NULL) { ret = MBEDTLS_ERR_X509_UNKNOWN_OID; goto exit; } @@ -180,45 +147,35 @@ int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *na d = data; } - if( !in_tag && *c == '\\' && c != end ) - { + if (!in_tag && *c == '\\' && c != end) { c++; /* Check for valid escaped characters */ - if( c == end || *c != ',' ) - { + if (c == end || *c != ',') { ret = MBEDTLS_ERR_X509_INVALID_NAME; goto exit; } - } - else if( !in_tag && ( *c == ',' || c == end ) ) - { - mbedtls_asn1_named_data* cur = - mbedtls_asn1_store_named_data( head, oid, strlen( oid ), - (unsigned char *) data, - d - data ); - - if(cur == NULL ) - { - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + } else if (!in_tag && (*c == ',' || c == end)) { + mbedtls_asn1_named_data* cur = mbedtls_asn1_store_named_data(head, oid, strlen(oid), (unsigned char*)data, d - data); + + if (cur == NULL) { + return (MBEDTLS_ERR_X509_ALLOC_FAILED); } // set tagType cur->val.tag = attr_descr->default_tag; - while( c < end && *(c + 1) == ' ' ) + while (c < end && *(c + 1) == ' ') c++; s = c + 1; in_tag = 1; } - if( !in_tag && s != c + 1 ) - { + if (!in_tag && s != c + 1) { *(d++) = *c; - if( d - data == MBEDTLS_X509_MAX_DN_NAME_SIZE ) - { + if (d - data == MBEDTLS_X509_MAX_DN_NAME_SIZE) { ret = MBEDTLS_ERR_X509_INVALID_NAME; goto exit; } @@ -229,27 +186,25 @@ int mbedtls_x509_string_to_names( mbedtls_asn1_named_data **head, const char *na exit: - return( ret ); + return (ret); } /* The first byte of the value in the mbedtls_asn1_named_data structure is reserved * to store the critical boolean for us */ -int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, size_t oid_len, - int critical, const unsigned char *val, size_t val_len ) +int mbedtls_x509_set_extension( + mbedtls_asn1_named_data** head, const char* oid, size_t oid_len, int critical, const unsigned char* val, size_t val_len) { - mbedtls_asn1_named_data *cur; + mbedtls_asn1_named_data* cur; - if( ( cur = mbedtls_asn1_store_named_data( head, oid, oid_len, - NULL, val_len + 1 ) ) == NULL ) - { - return( MBEDTLS_ERR_X509_ALLOC_FAILED ); + if ((cur = mbedtls_asn1_store_named_data(head, oid, oid_len, NULL, val_len + 1)) == NULL) { + return (MBEDTLS_ERR_X509_ALLOC_FAILED); } cur->val.p[0] = critical; - memcpy( cur->val.p + 1, val, val_len ); + memcpy(cur->val.p + 1, val, val_len); - return( 0 ); + return (0); } /* @@ -264,115 +219,96 @@ int mbedtls_x509_set_extension( mbedtls_asn1_named_data **head, const char *oid, * * AttributeValue ::= ANY DEFINED BY AttributeType */ -static int x509_write_name( unsigned char **p, unsigned char *start, mbedtls_asn1_named_data* cur_name) +static int x509_write_name(unsigned char** p, unsigned char* start, mbedtls_asn1_named_data* cur_name) { int ret; size_t len = 0; - const char *oid = (const char*)cur_name->oid.p; - size_t oid_len = cur_name->oid.len; - const unsigned char *name = cur_name->val.p; - size_t name_len = cur_name->val.len; + const char* oid = (const char*)cur_name->oid.p; + size_t oid_len = cur_name->oid.len; + const unsigned char* name = cur_name->val.p; + size_t name_len = cur_name->val.len; // Write correct string tag and value - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tagged_string( p, start, - cur_name->val.tag, - (const char *) name, - name_len ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tagged_string(p, start, cur_name->val.tag, (const char*)name, name_len)); // Write OID // - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_oid( p, start, oid, - oid_len ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(p, start, oid, oid_len)); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, - MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, - MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SET ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)); - return( (int) len ); + return ((int)len); } -int mbedtls_x509_write_names( unsigned char **p, unsigned char *start, - mbedtls_asn1_named_data *first ) +int mbedtls_x509_write_names(unsigned char** p, unsigned char* start, mbedtls_asn1_named_data* first) { int ret; size_t len = 0; - mbedtls_asn1_named_data *cur = first; + mbedtls_asn1_named_data* cur = first; - while( cur != NULL ) - { - MBEDTLS_ASN1_CHK_ADD( len, x509_write_name( p, start, cur ) ); + while (cur != NULL) { + MBEDTLS_ASN1_CHK_ADD(len, x509_write_name(p, start, cur)); cur = cur->next; } - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); - return( (int) len ); + return ((int)len); } -int mbedtls_x509_write_sig( unsigned char **p, unsigned char *start, - const char *oid, size_t oid_len, - unsigned char *sig, size_t size ) +int mbedtls_x509_write_sig(unsigned char** p, unsigned char* start, const char* oid, size_t oid_len, unsigned char* sig, size_t size) { int ret; size_t len = 0; - if( *p < start || (size_t)( *p - start ) < size ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + if (*p < start || (size_t)(*p - start) < size) + return (MBEDTLS_ERR_ASN1_BUF_TOO_SMALL); len = size; (*p) -= len; - memcpy( *p, sig, len ); + memcpy(*p, sig, len); - if( *p - start < 1 ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + if (*p - start < 1) + return (MBEDTLS_ERR_ASN1_BUF_TOO_SMALL); *--(*p) = 0; len += 1; - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_BIT_STRING ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_BIT_STRING)); // Write OID // - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( p, start, oid, - oid_len, 0 ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_algorithm_identifier(p, start, oid, oid_len, 0)); - return( (int) len ); + return ((int)len); } -static int x509_write_extension( unsigned char **p, unsigned char *start, - mbedtls_asn1_named_data *ext ) +static int x509_write_extension(unsigned char** p, unsigned char* start, mbedtls_asn1_named_data* ext) { int ret; size_t len = 0; - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_raw_buffer( p, start, ext->val.p + 1, - ext->val.len - 1 ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, ext->val.len - 1 ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_OCTET_STRING ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, ext->val.p + 1, ext->val.len - 1)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, ext->val.len - 1)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_OCTET_STRING)); - if( ext->val.p[0] != 0 ) - { - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_bool( p, start, 1 ) ); + if (ext->val.p[0] != 0) { + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_bool(p, start, 1)); } - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_raw_buffer( p, start, ext->oid.p, - ext->oid.len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, ext->oid.len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_OID ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, ext->oid.p, ext->oid.len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, ext->oid.len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_OID)); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); - return( (int) len ); + return ((int)len); } /* @@ -385,20 +321,18 @@ static int x509_write_extension( unsigned char **p, unsigned char *start, * -- by extnID * } */ -int mbedtls_x509_write_extensions( unsigned char **p, unsigned char *start, - mbedtls_asn1_named_data *first ) +int mbedtls_x509_write_extensions(unsigned char** p, unsigned char* start, mbedtls_asn1_named_data* first) { int ret; size_t len = 0; - mbedtls_asn1_named_data *cur_ext = first; + mbedtls_asn1_named_data* cur_ext = first; - while( cur_ext != NULL ) - { - MBEDTLS_ASN1_CHK_ADD( len, x509_write_extension( p, start, cur_ext ) ); + while (cur_ext != NULL) { + MBEDTLS_ASN1_CHK_ADD(len, x509_write_extension(p, start, cur_ext)); cur_ext = cur_ext->next; } - return( (int) len ); + return ((int)len); } #endif /* MBEDTLS_X509_CREATE_C */ diff --git a/nettls/ssl/x509_crl.c b/nettls/ssl/x509_crl.c index fa57c4bda3343063f296e13176944f641137fb60..b6878d2bee6e830d696e3071a444686212beb617 100644 --- a/nettls/ssl/x509_crl.c +++ b/nettls/ssl/x509_crl.c @@ -158,8 +158,7 @@ static int x509_get_crl_ext(unsigned char** p, const unsigned char* end, mbedtls *p += len; /* Get optional critical */ - if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 - && (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) { + if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 && (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) { return (MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret); } @@ -375,8 +374,7 @@ int mbedtls_x509_crl_parse_der(mbedtls_x509_crl* chain, const unsigned char* buf * * signature AlgorithmIdentifier */ - if ((ret = x509_crl_get_version(&p, end, &crl->version)) != 0 - || (ret = mbedtls_x509_get_alg(&p, end, &crl->sig_oid, &sig_params1)) != 0) { + if ((ret = x509_crl_get_version(&p, end, &crl->version)) != 0 || (ret = mbedtls_x509_get_alg(&p, end, &crl->sig_oid, &sig_params1)) != 0) { mbedtls_x509_crl_free(crl); return (ret); } @@ -388,8 +386,7 @@ int mbedtls_x509_crl_parse_der(mbedtls_x509_crl* chain, const unsigned char* buf crl->version++; - if ((ret = mbedtls_x509_get_sig_alg(&crl->sig_oid, &sig_params1, &crl->sig_md, &crl->sig_pk, &crl->sig_opts)) - != 0) { + if ((ret = mbedtls_x509_get_sig_alg(&crl->sig_oid, &sig_params1, &crl->sig_md, &crl->sig_pk, &crl->sig_opts)) != 0) { mbedtls_x509_crl_free(crl); return (MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG); } @@ -470,8 +467,7 @@ int mbedtls_x509_crl_parse_der(mbedtls_x509_crl* chain, const unsigned char* buf return (ret); } - if (crl->sig_oid.len != sig_oid2.len || memcmp(crl->sig_oid.p, sig_oid2.p, crl->sig_oid.len) != 0 - || sig_params1.len != sig_params2.len + if (crl->sig_oid.len != sig_oid2.len || memcmp(crl->sig_oid.p, sig_oid2.p, crl->sig_oid.len) != 0 || sig_params1.len != sig_params2.len || (sig_params1.len != 0 && memcmp(sig_params1.p, sig_params2.p, sig_params1.len) != 0)) { mbedtls_x509_crl_free(crl); return (MBEDTLS_ERR_X509_SIG_MISMATCH); @@ -512,8 +508,7 @@ int mbedtls_x509_crl_parse(mbedtls_x509_crl* chain, const unsigned char* buf, si if (buflen == 0 || buf[buflen - 1] != '\0') ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN X509 CRL-----", "-----END X509 CRL-----", buf, NULL, 0, &use_len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN X509 CRL-----", "-----END X509 CRL-----", buf, NULL, 0, &use_len); if (ret == 0) { /* @@ -598,16 +593,14 @@ int mbedtls_x509_crl_info(char* buf, size_t size, const char* prefix, const mbed p, n, "\n%sthis update : " "%04d-%02d-%02d %02d:%02d:%02d", - prefix, crl->this_update.year, crl->this_update.mon, crl->this_update.day, crl->this_update.hour, - crl->this_update.min, crl->this_update.sec); + prefix, crl->this_update.year, crl->this_update.mon, crl->this_update.day, crl->this_update.hour, crl->this_update.min, crl->this_update.sec); MBEDTLS_X509_SAFE_SNPRINTF; ret = mbedtls_snprintf( p, n, "\n%snext update : " "%04d-%02d-%02d %02d:%02d:%02d", - prefix, crl->next_update.year, crl->next_update.mon, crl->next_update.day, crl->next_update.hour, - crl->next_update.min, crl->next_update.sec); + prefix, crl->next_update.year, crl->next_update.mon, crl->next_update.day, crl->next_update.hour, crl->next_update.min, crl->next_update.sec); MBEDTLS_X509_SAFE_SNPRINTF; entry = &crl->entry; @@ -626,8 +619,8 @@ int mbedtls_x509_crl_info(char* buf, size_t size, const char* prefix, const mbed p, n, " revocation date: " "%04d-%02d-%02d %02d:%02d:%02d", - entry->revocation_date.year, entry->revocation_date.mon, entry->revocation_date.day, - entry->revocation_date.hour, entry->revocation_date.min, entry->revocation_date.sec); + entry->revocation_date.year, entry->revocation_date.mon, entry->revocation_date.day, entry->revocation_date.hour, + entry->revocation_date.min, entry->revocation_date.sec); MBEDTLS_X509_SAFE_SNPRINTF; entry = entry->next; diff --git a/nettls/ssl/x509_crt.c b/nettls/ssl/x509_crt.c index c0d9400a91979035367272ed14e880f08aa2588c..11c73033589f26a61a865d983abb249dd7913e88 100644 --- a/nettls/ssl/x509_crt.c +++ b/nettls/ssl/x509_crt.c @@ -125,8 +125,8 @@ const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default = { MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA1) | #endif /* Only SHA-2 hashes */ - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) - | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), + MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA224) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) + | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), 0xFFFFFFF, /* Any PK alg */ 0xFFFFFFF, /* Any curve */ 2048, @@ -137,14 +137,12 @@ const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default = { */ const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_next = { /* Hashes from SHA-256 and above */ - MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) - | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), + MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA256) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA384) | MBEDTLS_X509_ID_FLAG(MBEDTLS_MD_SHA512), 0xFFFFFFF, /* Any PK alg */ #if defined(MBEDTLS_ECP_C) /* Curves at or above 128-bit security level */ - MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP256R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP384R1) - | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP521R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP256R1) - | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP384R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP512R1) + MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP256R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP384R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP521R1) + | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP256R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP384R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_BP512R1) | MBEDTLS_X509_ID_FLAG(MBEDTLS_ECP_DP_SECP256K1), #else 0, @@ -428,8 +426,7 @@ static int x509_get_uid(unsigned char** p, const unsigned char* end, mbedtls_x50 uid->tag = **p; - if ((ret = mbedtls_asn1_get_tag(p, end, &uid->len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | n)) - != 0) { + if ((ret = mbedtls_asn1_get_tag(p, end, &uid->len, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | n)) != 0) { if (ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) return (0); @@ -573,8 +570,7 @@ static int x509_get_ext_key_usage(unsigned char** p, const unsigned char* end, m * * NOTE: we only parse and use dNSName at this point. */ -static int - x509_get_subject_alt_name(unsigned char** p, const unsigned char* end, mbedtls_x509_sequence* subject_alt_name) +static int x509_get_subject_alt_name(unsigned char** p, const unsigned char* end, mbedtls_x509_sequence* subject_alt_name) { int ret; size_t len, tag_len; @@ -679,8 +675,7 @@ static int x509_get_crt_ext(unsigned char** p, const unsigned char* end, mbedtls *p += extn_oid.len; /* Get optional critical */ - if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 - && (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) + if ((ret = mbedtls_asn1_get_bool(p, end_ext_data, &is_critical)) != 0 && (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG)) return (MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret); /* Data should be octet string type */ @@ -832,8 +827,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt* crt, const unsigned char* b * * signature AlgorithmIdentifier */ - if ((ret = x509_get_version(&p, end, &crt->version)) != 0 - || (ret = mbedtls_x509_get_serial(&p, end, &crt->serial)) != 0 + if ((ret = x509_get_version(&p, end, &crt->version)) != 0 || (ret = mbedtls_x509_get_serial(&p, end, &crt->serial)) != 0 || (ret = mbedtls_x509_get_alg(&p, end, &crt->sig_oid, &sig_params1)) != 0) { mbedtls_x509_crt_free(crt); return (ret); @@ -846,8 +840,7 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt* crt, const unsigned char* b crt->version++; - if ((ret = mbedtls_x509_get_sig_alg(&crt->sig_oid, &sig_params1, &crt->sig_md, &crt->sig_pk, &crt->sig_opts)) - != 0) { + if ((ret = mbedtls_x509_get_sig_alg(&crt->sig_oid, &sig_params1, &crt->sig_md, &crt->sig_pk, &crt->sig_opts)) != 0) { mbedtls_x509_crt_free(crt); return (ret); } @@ -959,9 +952,8 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt* crt, const unsigned char* b return (ret); } - if (crt->sig_oid.len != sig_oid2.len || memcmp(crt->sig_oid.p, sig_oid2.p, crt->sig_oid.len) != 0 - || sig_params1.tag != sig_params2.tag || sig_params1.len != sig_params2.len - || (sig_params1.len != 0 && memcmp(sig_params1.p, sig_params2.p, sig_params1.len) != 0)) { + if (crt->sig_oid.len != sig_oid2.len || memcmp(crt->sig_oid.p, sig_oid2.p, crt->sig_oid.len) != 0 || sig_params1.tag != sig_params2.tag + || sig_params1.len != sig_params2.len || (sig_params1.len != 0 && memcmp(sig_params1.p, sig_params2.p, sig_params1.len) != 0)) { mbedtls_x509_crt_free(crt); return (MBEDTLS_ERR_X509_SIG_MISMATCH); } @@ -1069,8 +1061,7 @@ int mbedtls_x509_crt_parse(mbedtls_x509_crt* chain, const unsigned char* buf, si mbedtls_pem_init(&pem); /* If we get there, we know the string is null-terminated */ - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----", buf, NULL, 0, &use_len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----", buf, NULL, 0, &use_len); if (ret == 0) { /* @@ -1187,8 +1178,7 @@ int mbedtls_x509_crt_parse_path(mbedtls_x509_crt* chain, const char* path) if (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; - w_ret = WideCharToMultiByte( - CP_ACP, 0, file_data.cFileName, lstrlenW(file_data.cFileName), p, (int)len - 1, NULL, NULL); + w_ret = WideCharToMultiByte(CP_ACP, 0, file_data.cFileName, lstrlenW(file_data.cFileName), p, (int)len - 1, NULL, NULL); if (w_ret == 0) { ret = MBEDTLS_ERR_X509_FILE_IO_ERROR; goto cleanup; @@ -1427,16 +1417,14 @@ int mbedtls_x509_crt_info(char* buf, size_t size, const char* prefix, const mbed p, n, "\n%sissued on : " "%04d-%02d-%02d %02d:%02d:%02d", - prefix, crt->valid_from.year, crt->valid_from.mon, crt->valid_from.day, crt->valid_from.hour, - crt->valid_from.min, crt->valid_from.sec); + prefix, crt->valid_from.year, crt->valid_from.mon, crt->valid_from.day, crt->valid_from.hour, crt->valid_from.min, crt->valid_from.sec); MBEDTLS_X509_SAFE_SNPRINTF; ret = mbedtls_snprintf( p, n, "\n%sexpires on : " "%04d-%02d-%02d %02d:%02d:%02d", - prefix, crt->valid_to.year, crt->valid_to.mon, crt->valid_to.day, crt->valid_to.hour, crt->valid_to.min, - crt->valid_to.sec); + prefix, crt->valid_to.year, crt->valid_to.mon, crt->valid_to.day, crt->valid_to.hour, crt->valid_to.min, crt->valid_to.sec); MBEDTLS_X509_SAFE_SNPRINTF; ret = mbedtls_snprintf(p, n, "\n%ssigned using : ", prefix); @@ -1635,8 +1623,7 @@ int mbedtls_x509_crt_is_revoked(const mbedtls_x509_crt* crt, const mbedtls_x509_ * Check that the given certificate is not revoked according to the CRL. * Skip validation if no CRL for the given CA is present. */ -static int x509_crt_verifycrl( - mbedtls_x509_crt* crt, mbedtls_x509_crt* ca, mbedtls_x509_crl* crl_list, const mbedtls_x509_crt_profile* profile) +static int x509_crt_verifycrl(mbedtls_x509_crt* crt, mbedtls_x509_crt* ca, mbedtls_x509_crl* crl_list, const mbedtls_x509_crt_profile* profile) { int flags = 0; unsigned char hash[MBEDTLS_MD_MAX_SIZE]; @@ -1681,8 +1668,8 @@ static int x509_crt_verifycrl( flags |= MBEDTLS_X509_BADCERT_BAD_KEY; if (mbedtls_pk_verify_ext( - crl_list->sig_pk, crl_list->sig_opts, &ca->pk, crl_list->sig_md, hash, mbedtls_md_get_size(md_info), - crl_list->sig.p, crl_list->sig.len) + crl_list->sig_pk, crl_list->sig_opts, &ca->pk, crl_list->sig_md, hash, mbedtls_md_get_size(md_info), crl_list->sig.p, + crl_list->sig.len) != 0) { flags |= MBEDTLS_X509_BADCRL_NOT_TRUSTED; break; @@ -1715,8 +1702,7 @@ static int x509_crt_verifycrl( /* * Check the signature of a certificate by its parent */ -static int x509_crt_check_signature( - const mbedtls_x509_crt* child, mbedtls_x509_crt* parent, mbedtls_x509_crt_restart_ctx* rs_ctx) +static int x509_crt_check_signature(const mbedtls_x509_crt* child, mbedtls_x509_crt* parent, mbedtls_x509_crt_restart_ctx* rs_ctx) { const mbedtls_md_info_t* md_info; unsigned char hash[MBEDTLS_MD_MAX_SIZE]; @@ -1733,16 +1719,15 @@ static int x509_crt_check_signature( #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) if (rs_ctx != NULL && child->sig_pk == MBEDTLS_PK_ECDSA) { - return (mbedtls_pk_verify_restartable( - &parent->pk, child->sig_md, hash, mbedtls_md_get_size(md_info), child->sig.p, child->sig.len, &rs_ctx->pk)); + return ( + mbedtls_pk_verify_restartable(&parent->pk, child->sig_md, hash, mbedtls_md_get_size(md_info), child->sig.p, child->sig.len, &rs_ctx->pk)); } #else (void)rs_ctx; #endif return (mbedtls_pk_verify_ext( - child->sig_pk, child->sig_opts, &parent->pk, child->sig_md, hash, mbedtls_md_get_size(md_info), child->sig.p, - child->sig.len)); + child->sig_pk, child->sig_opts, &parent->pk, child->sig_md, hash, mbedtls_md_get_size(md_info), child->sig.p, child->sig.len)); } /* @@ -1961,8 +1946,7 @@ static int x509_crt_find_parent( while (1) { search_list = *parent_is_trusted ? trust_ca : child->next; - ret = x509_crt_find_parent_in( - child, search_list, parent, signature_is_good, *parent_is_trusted, path_cnt, self_cnt, rs_ctx); + ret = x509_crt_find_parent_in(child, search_list, parent, signature_is_good, *parent_is_trusted, path_cnt, self_cnt, rs_ctx); #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) { @@ -2132,8 +2116,7 @@ static int x509_crt_verify_chain( find_parent: #endif /* Look for a parent in trusted CAs or up the chain */ - ret = x509_crt_find_parent( - child, trust_ca, &parent, &parent_is_trusted, &signature_is_good, ver_chain->len - 1, self_cnt, rs_ctx); + ret = x509_crt_find_parent(child, trust_ca, &parent, &parent_is_trusted, &signature_is_good, ver_chain->len - 1, self_cnt, rs_ctx); #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) if (rs_ctx != NULL && ret == MBEDTLS_ERR_ECP_IN_PROGRESS) { @@ -2242,10 +2225,7 @@ static void x509_crt_verify_name(const mbedtls_x509_crt* crt, const char* cn, ui * Merge the flags for all certs in the chain, after calling callback */ static int x509_crt_merge_flags_with_cb( - uint32_t* flags, - const mbedtls_x509_crt_verify_chain* ver_chain, - int (*f_vrfy)(void*, mbedtls_x509_crt*, int, uint32_t*), - void* p_vrfy) + uint32_t* flags, const mbedtls_x509_crt_verify_chain* ver_chain, int (*f_vrfy)(void*, mbedtls_x509_crt*, int, uint32_t*), void* p_vrfy) { int ret; unsigned i; @@ -2278,8 +2258,7 @@ int mbedtls_x509_crt_verify( int (*f_vrfy)(void*, mbedtls_x509_crt*, int, uint32_t*), void* p_vrfy) { - return (mbedtls_x509_crt_verify_restartable( - crt, trust_ca, ca_crl, &mbedtls_x509_crt_profile_default, cn, flags, f_vrfy, p_vrfy, NULL)); + return (mbedtls_x509_crt_verify_restartable(crt, trust_ca, ca_crl, &mbedtls_x509_crt_profile_default, cn, flags, f_vrfy, p_vrfy, NULL)); } /* diff --git a/nettls/ssl/x509_csr.c b/nettls/ssl/x509_csr.c index 70bc630fd890f2d5aaa95ef73d2793572ccd644d..8b5b443090c2fd6e170a2ba743e7b652e887d738 100644 --- a/nettls/ssl/x509_csr.c +++ b/nettls/ssl/x509_csr.c @@ -276,12 +276,10 @@ int mbedtls_x509_csr_parse(mbedtls_x509_csr* csr, const unsigned char* buf, size /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ if (buf[buflen - 1] == '\0') { mbedtls_pem_init(&pem); - ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN CERTIFICATE REQUEST-----", "-----END CERTIFICATE REQUEST-----", buf, NULL, 0, &use_len); + ret = mbedtls_pem_read_buffer(&pem, "-----BEGIN CERTIFICATE REQUEST-----", "-----END CERTIFICATE REQUEST-----", buf, NULL, 0, &use_len); if (ret == MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { ret = mbedtls_pem_read_buffer( - &pem, "-----BEGIN NEW CERTIFICATE REQUEST-----", "-----END NEW CERTIFICATE REQUEST-----", buf, NULL, 0, - &use_len); + &pem, "-----BEGIN NEW CERTIFICATE REQUEST-----", "-----END NEW CERTIFICATE REQUEST-----", buf, NULL, 0, &use_len); } if (ret == 0) { @@ -354,8 +352,7 @@ int mbedtls_x509_csr_info(char* buf, size_t size, const char* prefix, const mbed return (ret); } - ret = - mbedtls_snprintf(p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str, (int)mbedtls_pk_get_bitlen(&csr->pk)); + ret = mbedtls_snprintf(p, n, "\n%s%-" BC "s: %d bits\n", prefix, key_size_str, (int)mbedtls_pk_get_bitlen(&csr->pk)); MBEDTLS_X509_SAFE_SNPRINTF; return ((int)(size - n)); diff --git a/nettls/ssl/x509write_crt.c b/nettls/ssl/x509write_crt.c index 27a630068ea65767acff425171bf759fc045265e..3810614206fbb251fae47d41f7973cb1d55976cc 100644 --- a/nettls/ssl/x509write_crt.c +++ b/nettls/ssl/x509write_crt.c @@ -141,8 +141,7 @@ int mbedtls_x509write_crt_set_serial(mbedtls_x509write_cert* ctx, const mbedtls_ int mbedtls_x509write_crt_set_validity(mbedtls_x509write_cert* ctx, const char* not_before, const char* not_after) { - if (strlen(not_before) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1 - || strlen(not_after) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1) { + if (strlen(not_before) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1 || strlen(not_after) != MBEDTLS_X509_RFC5280_UTC_TIME_LEN - 1) { return (MBEDTLS_ERR_X509_BAD_INPUT_DATA); } strncpy(ctx->not_before, not_before, MBEDTLS_X509_RFC5280_UTC_TIME_LEN); @@ -154,12 +153,7 @@ int mbedtls_x509write_crt_set_validity(mbedtls_x509write_cert* ctx, const char* } int mbedtls_x509write_crt_set_extension( - mbedtls_x509write_cert* ctx, - const char* oid, - size_t oid_len, - int critical, - const unsigned char* val, - size_t val_len) + mbedtls_x509write_cert* ctx, const char* oid, size_t oid_len, int critical, const unsigned char* val, size_t val_len) { return (mbedtls_x509_set_extension(&ctx->extensions, oid, oid_len, critical, val, val_len)); } @@ -187,8 +181,7 @@ int mbedtls_x509write_crt_set_basic_constraints(mbedtls_x509write_cert* ctx, int MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); return (mbedtls_x509write_crt_set_extension( - ctx, MBEDTLS_OID_BASIC_CONSTRAINTS, MBEDTLS_OID_SIZE(MBEDTLS_OID_BASIC_CONSTRAINTS), 0, buf + sizeof(buf) - len, - len)); + ctx, MBEDTLS_OID_BASIC_CONSTRAINTS, MBEDTLS_OID_SIZE(MBEDTLS_OID_BASIC_CONSTRAINTS), 0, buf + sizeof(buf) - len, len)); } #if defined(MBEDTLS_SHA1_C) @@ -212,8 +205,7 @@ int mbedtls_x509write_crt_set_subject_key_identifier(mbedtls_x509write_cert* ctx MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_OCTET_STRING)); return mbedtls_x509write_crt_set_extension( - ctx, MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER, MBEDTLS_OID_SIZE(MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER), 0, - buf + sizeof(buf) - len, len); + ctx, MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER, MBEDTLS_OID_SIZE(MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER), 0, buf + sizeof(buf) - len, len); } int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert* ctx) @@ -239,8 +231,7 @@ int mbedtls_x509write_crt_set_authority_key_identifier(mbedtls_x509write_cert* c MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); return mbedtls_x509write_crt_set_extension( - ctx, MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER, MBEDTLS_OID_SIZE(MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER), 0, - buf + sizeof(buf) - len, len); + ctx, MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER, MBEDTLS_OID_SIZE(MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER), 0, buf + sizeof(buf) - len, len); } #endif /* MBEDTLS_SHA1_C */ @@ -262,9 +253,8 @@ int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert* ctx, unsigned in unsigned char* c; int ret; size_t unused_bits; - const unsigned int allowed_bits = MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION - | MBEDTLS_X509_KU_KEY_ENCIPHERMENT | MBEDTLS_X509_KU_DATA_ENCIPHERMENT - | MBEDTLS_X509_KU_KEY_AGREEMENT | MBEDTLS_X509_KU_KEY_CERT_SIGN + const unsigned int allowed_bits = MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT + | MBEDTLS_X509_KU_DATA_ENCIPHERMENT | MBEDTLS_X509_KU_KEY_AGREEMENT | MBEDTLS_X509_KU_KEY_CERT_SIGN | MBEDTLS_X509_KU_CRL_SIGN; /* Check that nothing other than the allowed flags is set */ @@ -281,8 +271,7 @@ int mbedtls_x509write_crt_set_key_usage(mbedtls_x509write_cert* ctx, unsigned in else if (ret < 3 || ret > 4) return (MBEDTLS_ERR_X509_INVALID_FORMAT); - ret = mbedtls_x509write_crt_set_extension( - ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE(MBEDTLS_OID_KEY_USAGE), 1, c, (size_t)ret); + ret = mbedtls_x509write_crt_set_extension(ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE(MBEDTLS_OID_KEY_USAGE), 1, c, (size_t)ret); if (ret != 0) return (ret); @@ -303,8 +292,7 @@ int mbedtls_x509write_crt_set_ns_cert_type(mbedtls_x509write_cert* ctx, unsigned if (ret < 3 || ret > 4) return (ret); - ret = mbedtls_x509write_crt_set_extension( - ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE(MBEDTLS_OID_NS_CERT_TYPE), 0, c, (size_t)ret); + ret = mbedtls_x509write_crt_set_extension(ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE(MBEDTLS_OID_NS_CERT_TYPE), 0, c, (size_t)ret); if (ret != 0) return (ret); @@ -332,12 +320,7 @@ static int x509_write_time(unsigned char** p, unsigned char* start, const char* return ((int)len); } -int mbedtls_x509write_crt_der( - mbedtls_x509write_cert* ctx, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) +int mbedtls_x509write_crt_der(mbedtls_x509write_cert* ctx, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; const char* sig_oid; @@ -379,8 +362,7 @@ int mbedtls_x509write_crt_der( MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len)); MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len)); - MBEDTLS_ASN1_CHK_ADD( - len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 3)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 3)); } /* @@ -435,8 +417,7 @@ int mbedtls_x509write_crt_der( MBEDTLS_ASN1_CHK_ADD(sub_len, mbedtls_asn1_write_int(&c, buf, ctx->version)); len += sub_len; MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, sub_len)); - MBEDTLS_ASN1_CHK_ADD( - len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0)); } MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len)); @@ -488,12 +469,7 @@ int mbedtls_x509write_crt_der( #define PEM_END_CRT "-----END CERTIFICATE-----\n" #if defined(MBEDTLS_PEM_WRITE_C) -int mbedtls_x509write_crt_pem( - mbedtls_x509write_cert* crt, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) +int mbedtls_x509write_crt_pem(mbedtls_x509write_cert* crt, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; size_t olen; diff --git a/nettls/ssl/x509write_csr.c b/nettls/ssl/x509write_csr.c index 95fbcc754008b091d918409b40700d7eff7c105d..b7ab3e00bbd6f4d7ae806cab760d9cd52a0c4c22 100644 --- a/nettls/ssl/x509write_csr.c +++ b/nettls/ssl/x509write_csr.c @@ -115,8 +115,7 @@ int mbedtls_x509write_csr_set_subject_name(mbedtls_x509write_csr* ctx, const cha return mbedtls_x509_string_to_names(&ctx->subject, subject_name); } -int mbedtls_x509write_csr_set_extension( - mbedtls_x509write_csr* ctx, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len) +int mbedtls_x509write_csr_set_extension(mbedtls_x509write_csr* ctx, const char* oid, size_t oid_len, const unsigned char* val, size_t val_len) { return mbedtls_x509_set_extension(&ctx->extensions, oid, oid_len, 0, val, val_len); } @@ -150,8 +149,7 @@ int mbedtls_x509write_csr_set_key_usage(mbedtls_x509write_csr* ctx, unsigned cha else if (ret < 3 || ret > 4) return (MBEDTLS_ERR_X509_INVALID_FORMAT); - ret = mbedtls_x509write_csr_set_extension( - ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE(MBEDTLS_OID_KEY_USAGE), c, (size_t)ret); + ret = mbedtls_x509write_csr_set_extension(ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE(MBEDTLS_OID_KEY_USAGE), c, (size_t)ret); if (ret != 0) return (ret); @@ -175,8 +173,7 @@ int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr* ctx, unsigned else if (ret < 3 || ret > 4) return (ret); - ret = mbedtls_x509write_csr_set_extension( - ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE(MBEDTLS_OID_NS_CERT_TYPE), c, (size_t)ret); + ret = mbedtls_x509write_csr_set_extension(ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE(MBEDTLS_OID_NS_CERT_TYPE), c, (size_t)ret); if (ret != 0) return (ret); @@ -184,12 +181,7 @@ int mbedtls_x509write_csr_set_ns_cert_type(mbedtls_x509write_csr* ctx, unsigned } static int x509write_csr_der_internal( - mbedtls_x509write_csr* ctx, - unsigned char* buf, - size_t size, - unsigned char* sig, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) + mbedtls_x509write_csr* ctx, unsigned char* buf, size_t size, unsigned char* sig, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; const char* sig_oid; @@ -212,17 +204,14 @@ static int x509write_csr_der_internal( MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len)); MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET)); - MBEDTLS_ASN1_CHK_ADD( - len, mbedtls_asn1_write_oid( - &c, buf, MBEDTLS_OID_PKCS9_CSR_EXT_REQ, MBEDTLS_OID_SIZE(MBEDTLS_OID_PKCS9_CSR_EXT_REQ))); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(&c, buf, MBEDTLS_OID_PKCS9_CSR_EXT_REQ, MBEDTLS_OID_SIZE(MBEDTLS_OID_PKCS9_CSR_EXT_REQ))); MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len)); MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)); } MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(&c, buf, len)); - MBEDTLS_ASN1_CHK_ADD( - len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC)); + MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(&c, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC)); MBEDTLS_ASN1_CHK_ADD(pub_len, mbedtls_pk_write_pubkey_der(ctx->key, buf, c - buf)); c -= pub_len; @@ -296,12 +285,7 @@ static int x509write_csr_der_internal( return ((int)len); } -int mbedtls_x509write_csr_der( - mbedtls_x509write_csr* ctx, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) +int mbedtls_x509write_csr_der(mbedtls_x509write_csr* ctx, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; unsigned char* sig; @@ -321,12 +305,7 @@ int mbedtls_x509write_csr_der( #define PEM_END_CSR "-----END CERTIFICATE REQUEST-----\n" #if defined(MBEDTLS_PEM_WRITE_C) -int mbedtls_x509write_csr_pem( - mbedtls_x509write_csr* ctx, - unsigned char* buf, - size_t size, - int (*f_rng)(void*, unsigned char*, size_t), - void* p_rng) +int mbedtls_x509write_csr_pem(mbedtls_x509write_csr* ctx, unsigned char* buf, size_t size, int (*f_rng)(void*, unsigned char*, size_t), void* p_rng) { int ret; unsigned char output_buf[4096]; @@ -336,9 +315,7 @@ int mbedtls_x509write_csr_pem( return (ret); } - if ((ret = mbedtls_pem_write_buffer( - PEM_BEGIN_CSR, PEM_END_CSR, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen)) - != 0) { + if ((ret = mbedtls_pem_write_buffer(PEM_BEGIN_CSR, PEM_END_CSR, output_buf + sizeof(output_buf) - ret, ret, buf, size, &olen)) != 0) { return (ret); } diff --git a/nettls/ssl/xtea.c b/nettls/ssl/xtea.c index 2945974736acfbbd5760644279812047fda00917..61043fa4f1c1f99df5f346a2447f2c167357fcff 100644 --- a/nettls/ssl/xtea.c +++ b/nettls/ssl/xtea.c @@ -74,8 +74,7 @@ #ifndef GET_UINT32_BE #define GET_UINT32_BE(n, b, i) \ { \ - (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) \ - | ((uint32_t)(b)[(i) + 3]); \ + (n) = ((uint32_t)(b)[(i)] << 24) | ((uint32_t)(b)[(i) + 1] << 16) | ((uint32_t)(b)[(i) + 2] << 8) | ((uint32_t)(b)[(i) + 3]); \ } #endif @@ -157,13 +156,7 @@ int mbedtls_xtea_crypt_ecb(mbedtls_xtea_context* ctx, int mode, const unsigned c /* * XTEA-CBC buffer encryption/decryption */ -int mbedtls_xtea_crypt_cbc( - mbedtls_xtea_context* ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char* input, - unsigned char* output) +int mbedtls_xtea_crypt_cbc(mbedtls_xtea_context* ctx, int mode, size_t length, unsigned char iv[8], const unsigned char* input, unsigned char* output) { int i; unsigned char temp[8]; diff --git a/polipo/chunk.c b/polipo/chunk.c index 0d8a66d6311ae1b2e379a403fe9c8febb53cdd0c..89762c602f85a2fdbad114e251dc4a49670f4aed 100644 --- a/polipo/chunk.c +++ b/polipo/chunk.c @@ -73,8 +73,7 @@ static void initChunksCommon() if (chunkCriticalMark <= 0) q = 1; if (chunkCriticalMark >= chunkHighMark - 2 * CHUNK_SIZE || chunkCriticalMark <= chunkLowMark + 2 * CHUNK_SIZE) { - chunkCriticalMark = - MIN(chunkHighMark - 2 * CHUNK_SIZE, chunkLowMark + (chunkHighMark - chunkLowMark) * 15 / 16); + chunkCriticalMark = MIN(chunkHighMark - 2 * CHUNK_SIZE, chunkLowMark + (chunkHighMark - chunkLowMark) * 15 / 16); ROUND_CHUNKS(chunkCriticalMark); if (!q) do_log( @@ -271,8 +270,7 @@ typedef struct _ChunkArena { static ChunkArenaPtr chunkArenas, currentArena; static int numArenas; #define CHUNK_IN_ARENA(chunk, arena) \ - ((arena)->chunks && (char*)(chunk) >= (arena)->chunks \ - && (char*)(chunk) < (arena)->chunks + (ARENA_CHUNKS * CHUNK_SIZE)) + ((arena)->chunks && (char*)(chunk) >= (arena)->chunks && (char*)(chunk) < (arena)->chunks + (ARENA_CHUNKS * CHUNK_SIZE)) #define CHUNK_ARENA_INDEX(chunk, arena) ((unsigned)((unsigned long)(((char*)(chunk) - (arena)->chunks)) / CHUNK_SIZE)) diff --git a/polipo/client.c b/polipo/client.c index 8dc33ec481f43484d9eef2d0e10ade6200c2de6f..e35501526c4fa820ce681be2b8df4f4957ae9438 100644 --- a/polipo/client.c +++ b/polipo/client.c @@ -104,8 +104,7 @@ int httpAccept(int fd, FdEventHandlerPtr event, AcceptRequestPtr request) connection->flags = CONN_READER; - do_stream_buf( - IO_READ | IO_NOTNOW, connection->fd, 0, &connection->reqbuf, CHUNK_SIZE, httpClientHandler, connection); + do_stream_buf(IO_READ | IO_NOTNOW, connection->fd, 0, &connection->reqbuf, CHUNK_SIZE, httpClientHandler, connection); return 0; } @@ -206,9 +205,8 @@ void httpClientFinish(HTTPConnectionPtr connection, int s) connection->flags |= CONN_READER; httpSetTimeout(connection, clientTimeout); do_stream_buf( - IO_READ | IO_NOTNOW | (connection->reqlen ? IO_IMMEDIATE : 0), connection->fd, connection->reqlen, - &connection->reqbuf, (connection->flags & CONN_BIGREQBUF) ? bigBufferSize : CHUNK_SIZE, - httpClientHandler, connection); + IO_READ | IO_NOTNOW | (connection->reqlen ? IO_IMMEDIATE : 0), connection->fd, connection->reqlen, &connection->reqbuf, + (connection->flags & CONN_BIGREQBUF) ? bigBufferSize : CHUNK_SIZE, httpClientHandler, connection); } /* The request has already been validated when it first got into the queue */ @@ -325,8 +323,7 @@ static int httpClientDelayedShutdownHandler(TimeEventHandlerPtr event) httpClientFinish(connection, 1); return 1; } - do_stream( - IO_READ | IO_NOTNOW, connection->fd, 0, client_shutdown_buffer, 17, httpClientShutdownHandler, connection); + do_stream(IO_READ | IO_NOTNOW, connection->fd, 0, client_shutdown_buffer, 17, httpClientShutdownHandler, connection); return 1; } @@ -371,9 +368,7 @@ int httpClientHandler(int status, FdEventHandlerPtr event, StreamRequestPtr requ if (!(connection->flags & CONN_BIGREQBUF)) rc = httpConnectionBigifyReqbuf(connection); if ((connection->flags & CONN_BIGREQBUF) && connection->reqlen < bigBufferSize) { - do_stream( - IO_READ, connection->fd, connection->reqlen, connection->reqbuf, bigBufferSize, httpClientHandler, - connection); + do_stream(IO_READ, connection->fd, connection->reqlen, connection->reqbuf, bigBufferSize, httpClientHandler, connection); return 1; } connection->reqlen = 0; @@ -427,8 +422,8 @@ int httpClientRawErrorHeaders(HTTPConnectionPtr connection, int code, AtomPtr me } n = httpWriteErrorHeaders( - connection->buf, CHUNK_SIZE, 0, connection->request && connection->request->method != METHOD_HEAD, code, - message, close > 0, headers, url, url_len, etag); + connection->buf, CHUNK_SIZE, 0, connection->request && connection->request->method != METHOD_HEAD, code, message, close > 0, headers, url, + url_len, etag); if (n <= 0) { shutdown(connection->fd, 1); if (close >= 0) @@ -659,8 +654,8 @@ int httpClientRequest(HTTPRequestPtr request, AtomPtr url) assert(connection->reqbuf); i = httpParseHeaders( - 1, url, connection->reqbuf, connection->reqbegin, request, &headers, &body_len, &cache_control, &condition, - &body_te, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &expect, &range, NULL, NULL, &via, &auth); + 1, url, connection->reqbuf, connection->reqbegin, request, &headers, &body_len, &cache_control, &condition, &body_te, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, &expect, &range, NULL, NULL, &via, &auth); if (i < 0) { releaseAtom(url); do_log(L_ERROR, "Couldn't parse client headers.\n"); @@ -674,8 +669,7 @@ int httpClientRequest(HTTPRequestPtr request, AtomPtr url) connection->reqbegin = i; if (body_len < 0) { - if (request->method == METHOD_GET || request->method == METHOD_HEAD || request->method == METHOD_POST - || request->method == METHOD_OPTIONS) + if (request->method == METHOD_GET || request->method == METHOD_HEAD || request->method == METHOD_POST || request->method == METHOD_OPTIONS) body_len = 0; } connection->bodylen = body_len; @@ -771,8 +765,7 @@ int httpClientRequest(HTTPRequestPtr request, AtomPtr url) return 1; } -int httpClientRequestContinue( - int forbidden_code, AtomPtr url, AtomPtr forbidden_message, AtomPtr forbidden_headers, void* closure) +int httpClientRequestContinue(int forbidden_code, AtomPtr url, AtomPtr forbidden_message, AtomPtr forbidden_headers, void* closure) { HTTPRequestPtr request = (HTTPRequestPtr)closure; HTTPConnectionPtr connection = request->connection; @@ -900,15 +893,12 @@ int httpClientDiscardBody(HTTPConnectionPtr connection) if (connection->bodylen > 0) { httpSetTimeout(connection, clientTimeout); - do_stream_buf( - IO_READ | IO_NOTNOW, connection->fd, connection->reqlen, &connection->reqbuf, CHUNK_SIZE, - httpClientDiscardHandler, connection); + do_stream_buf(IO_READ | IO_NOTNOW, connection->fd, connection->reqlen, &connection->reqbuf, CHUNK_SIZE, httpClientDiscardHandler, connection); return 1; } if (connection->reqlen > connection->reqbegin) { - memmove( - connection->reqbuf, connection->reqbuf + connection->reqbegin, connection->reqlen - connection->reqbegin); + memmove(connection->reqbuf, connection->reqbuf + connection->reqbegin, connection->reqlen - connection->reqbegin); connection->reqlen -= connection->reqbegin; connection->reqbegin = 0; } else { @@ -953,13 +943,10 @@ static int httpClientDelayed(TimeEventHandlerPtr event) httpConnectionUnbigifyReqbuf(connection); /* Don't read new requests if buffer is big. */ bufsize = (connection->flags & CONN_BIGREQBUF) ? connection->reqlen : CHUNK_SIZE; - do_stream( - IO_READ | IO_IMMEDIATE | IO_NOTNOW, connection->fd, connection->reqlen, connection->reqbuf, bufsize, - httpClientHandler, connection); + do_stream(IO_READ | IO_IMMEDIATE | IO_NOTNOW, connection->fd, connection->reqlen, connection->reqbuf, bufsize, httpClientHandler, connection); } else { httpConnectionDestroyReqbuf(connection); - do_stream_buf( - IO_READ | IO_NOTNOW, connection->fd, 0, &connection->reqbuf, CHUNK_SIZE, httpClientHandler, connection); + do_stream_buf(IO_READ | IO_NOTNOW, connection->fd, 0, &connection->reqbuf, CHUNK_SIZE, httpClientHandler, connection); } return 1; } @@ -996,13 +983,11 @@ int httpClientNoticeRequest(HTTPRequestPtr request, int novalidate) assert(!request->chandler); if (request->error_code) { - if ((request->flags & REQUEST_FORCE_ERROR) || REQUEST_SIDE(request) || request->object == NULL - || (request->object->flags & OBJECT_LOCAL) || (request->object->flags & OBJECT_ABORTED) - || (relaxTransparency < 1 && !proxyOffline)) { + if ((request->flags & REQUEST_FORCE_ERROR) || REQUEST_SIDE(request) || request->object == NULL || (request->object->flags & OBJECT_LOCAL) + || (request->object->flags & OBJECT_ABORTED) || (relaxTransparency < 1 && !proxyOffline)) { if (serveNow) { connection->flags |= CONN_WRITER; - return httpClientRawErrorHeaders( - connection, request->error_code, retainAtom(request->error_message), 0, request->error_headers); + return httpClientRawErrorHeaders(connection, request->error_code, retainAtom(request->error_message), 0, request->error_headers); } else { return 1; } @@ -1013,8 +998,7 @@ int httpClientNoticeRequest(HTTPRequestPtr request, int novalidate) assert(!(request->flags & REQUEST_REQUESTED)); if (serveNow) { assert(!request->chandler); - request->chandler = - conditionWait(&request->object->condition, httpClientGetHandler, sizeof(request), &request); + request->chandler = conditionWait(&request->object->condition, httpClientGetHandler, sizeof(request), &request); if (request->chandler == NULL) { do_log(L_ERROR, "Couldn't register condition handler.\n"); connection->flags |= CONN_WRITER; @@ -1026,9 +1010,7 @@ int httpClientNoticeRequest(HTTPRequestPtr request, int novalidate) return 1; } connection->flags |= CONN_WRITER; - rc = object->request( - request->object, request->method, request->from, request->to, request, - request->object->request_closure); + rc = object->request(request->object, request->method, request->from, request->to, request, request->object->request_closure); } return 1; } @@ -1058,8 +1040,8 @@ int httpClientNoticeRequest(HTTPRequestPtr request, int novalidate) if (request->method == METHOD_HEAD) haveData = !(request->object->flags & OBJECT_INITIAL); else - haveData = (request->object->length >= 0 && request->object->length <= request->from) - || (objectHoleSize(request->object, request->from) == 0); + haveData = + (request->object->length >= 0 && request->object->length <= request->from) || (objectHoleSize(request->object, request->from) == 0); if (request->flags & REQUEST_REQUESTED) validate = 0; @@ -1071,9 +1053,7 @@ int httpClientNoticeRequest(HTTPRequestPtr request, int novalidate) validate = 0; else if ((request->object->flags & OBJECT_FAILED) && !(object->flags & OBJECT_INPROGRESS) && !relaxTransparency) validate = 1; - else if ( - request->method != METHOD_HEAD && !objectHasData(object, request->from, request->to) - && !(object->flags & OBJECT_INPROGRESS)) + else if (request->method != METHOD_HEAD && !objectHasData(object, request->from, request->to) && !(object->flags & OBJECT_INPROGRESS)) validate = 1; else if (objectMustRevalidate((relaxTransparency <= 1 ? request->object : NULL), &request->cache_control)) validate = 1; @@ -1091,8 +1071,7 @@ int httpClientNoticeRequest(HTTPRequestPtr request, int novalidate) } } - if (!(request->object->flags & OBJECT_VALIDATING) - && ((!validate && haveData) || (request->object->flags & OBJECT_FAILED))) { + if (!(request->object->flags & OBJECT_VALIDATING) && ((!validate && haveData) || (request->object->flags & OBJECT_FAILED))) { if (serveNow) { connection->flags |= CONN_WRITER; lockChunk(request->object, request->from / CHUNK_SIZE); @@ -1277,8 +1256,7 @@ int httpClientGetHandler(int status, ConditionHandlerPtr chandler) if (object->requestor != request && !(object->flags & OBJECT_ABORTED)) { /* Make sure we don't serve an object that is stale for us unless we're the requestor. */ - if ((object->flags & (OBJECT_LINEAR | OBJECT_MUTATING)) - || objectMustRevalidate(object, &request->cache_control)) { + if ((object->flags & (OBJECT_LINEAR | OBJECT_MUTATING)) || objectMustRevalidate(object, &request->cache_control)) { if (object->flags & OBJECT_INPROGRESS) return 0; rc = delayedHttpClientNoticeRequest(request); @@ -1491,8 +1469,7 @@ int httpServeObject(HTTPConnectionPtr connection) return httpClientRawError(connection, 304, internAtom("Not modified"), 0); } - objectFillFromDisk( - object, request->from, (request->method == METHOD_HEAD || condition_result != CONDITION_MATCH) ? 0 : 1); + objectFillFromDisk(object, request->from, (request->method == METHOD_HEAD || condition_result != CONDITION_MATCH) ? 0 : 1); if (((object->flags & OBJECT_LINEAR) && (object->requestor != connection->request)) || ((object->flags & OBJECT_SUPERSEDED) && !(object->flags & OBJECT_LINEAR))) { @@ -1554,8 +1531,7 @@ again: if ((request->from <= 0 && request->to < 0) || request->method == METHOD_HEAD) { n = snnprintf(connection->buf, 0, bufsize, "HTTP/1.1 %d %s", object->code, atomString(object->message)); } else { - if ((object->length >= 0 && request->from >= object->length) - || (request->to >= 0 && request->from >= request->to)) { + if ((object->length >= 0 && request->from >= object->length) || (request->to >= 0 && request->from >= request->to)) { unlockChunk(object, i); return httpClientRawError( connection, 416, @@ -1571,8 +1547,7 @@ again: if (n < 0) goto fail; - if (request->method != METHOD_HEAD && condition_result != CONDITION_NOT_MODIFIED && request->to < 0 - && object->length < 0) { + if (request->method != METHOD_HEAD && condition_result != CONDITION_NOT_MODIFIED && request->to < 0 && object->length < 0) { if (connection->version == HTTP_11) { connection->te = TE_CHUNKED; n = snnprintf(connection->buf, n, bufsize, "\r\nTransfer-Encoding: chunked"); @@ -1584,30 +1559,20 @@ again: if (object->age < current_time.tv_sec) { n = snnprintf(connection->buf, n, bufsize, "\r\nAge: %d", (int)(current_time.tv_sec - object->age)); } - n = snnprintf( - connection->buf, n, bufsize, "\r\nConnection: %s", - (request->flags & REQUEST_PERSISTENT) ? "keep-alive" : "close"); + n = snnprintf(connection->buf, n, bufsize, "\r\nConnection: %s", (request->flags & REQUEST_PERSISTENT) ? "keep-alive" : "close"); if (!(object->flags & OBJECT_LOCAL)) { if ((object->flags & OBJECT_FAILED) && !proxyOffline) { - n = snnprintf( - connection->buf, n, bufsize, "\r\nWarning: 111 %s:%d Revalidation failed", proxyName->string, - proxyPort); + n = snnprintf(connection->buf, n, bufsize, "\r\nWarning: 111 %s:%d Revalidation failed", proxyName->string, proxyPort); if (request->error_code) - n = snnprintf( - connection->buf, n, bufsize, " (%d %s)", request->error_code, atomString(request->error_message)); + n = snnprintf(connection->buf, n, bufsize, " (%d %s)", request->error_code, atomString(request->error_message)); object->flags &= ~OBJECT_FAILED; } else if (proxyOffline && objectMustRevalidate(object, &request->cache_control)) { - n = snnprintf( - connection->buf, n, bufsize, "\r\nWarning: 112 %s:%d Disconnected operation", proxyName->string, - proxyPort); + n = snnprintf(connection->buf, n, bufsize, "\r\nWarning: 112 %s:%d Disconnected operation", proxyName->string, proxyPort); } else if (objectIsStale(object, &request->cache_control)) { - n = snnprintf( - connection->buf, n, bufsize, "\r\nWarning: 110 %s:%d Object is stale", proxyName->string, proxyPort); + n = snnprintf(connection->buf, n, bufsize, "\r\nWarning: 110 %s:%d Object is stale", proxyName->string, proxyPort); } else if (object->expires < 0 && object->max_age < 0 && object->age < current_time.tv_sec - 24 * 3600) { - n = snnprintf( - connection->buf, n, bufsize, "\r\nWarning: 113 %s:%d Heuristic expiration", proxyName->string, - proxyPort); + n = snnprintf(connection->buf, n, bufsize, "\r\nWarning: 113 %s:%d Heuristic expiration", proxyName->string, proxyPort); } } @@ -1618,8 +1583,7 @@ again: connection->offset = request->from; - if (request->method == METHOD_HEAD || condition_result == CONDITION_NOT_MODIFIED - || (object->flags & OBJECT_ABORTED)) { + if (request->method == METHOD_HEAD || condition_result == CONDITION_NOT_MODIFIED || (object->flags & OBJECT_ABORTED)) { len = 0; } else { if (i < object->numchunks) { @@ -1637,11 +1601,10 @@ again: connection->offset = request->from; httpSetTimeout(connection, clientTimeout); do_log( - D_CLIENT_DATA, "Serving on 0x%lx for 0x%lx: offset %d len %d\n", (unsigned long)connection, - (unsigned long)object, connection->offset, len); + D_CLIENT_DATA, "Serving on 0x%lx for 0x%lx: offset %d len %d\n", (unsigned long)connection, (unsigned long)object, connection->offset, len); do_stream_h( - IO_WRITE | (connection->te == TE_CHUNKED && len > 0 ? IO_CHUNKED : 0), connection->fd, 0, connection->buf, n, - object->chunks[i].data + j, len, httpServeObjectStreamHandler, connection); + IO_WRITE | (connection->te == TE_CHUNKED && len > 0 ? IO_CHUNKED : 0), connection->fd, 0, connection->buf, n, object->chunks[i].data + j, len, + httpServeObjectStreamHandler, connection); return 1; fail: @@ -1654,8 +1617,7 @@ fail: goto again; } unlockChunk(object, i); - return httpClientRawError( - connection, 500, rc == 0 ? internAtom("No space for headers") : internAtom("Couldn't allocate big buffer"), 0); + return httpClientRawError(connection, 500, rc == 0 ? internAtom("No space for headers") : internAtom("Couldn't allocate big buffer"), 0); } static int httpServeObjectDelayed(TimeEventHandlerPtr event) @@ -1744,17 +1706,14 @@ int httpServeChunk(HTTPConnectionPtr connection) unlockChunk(object, i); if (connection->te == TE_CHUNKED) { httpSetTimeout(connection, clientTimeout); - do_stream( - IO_WRITE | IO_CHUNKED | IO_END, connection->fd, 0, NULL, 0, httpServeObjectFinishHandler, - connection); + do_stream(IO_WRITE | IO_CHUNKED | IO_END, connection->fd, 0, NULL, 0, httpServeObjectFinishHandler, connection); } else { httpClientFinish(connection, !(object->length >= 0 && connection->offset >= object->length)); } return 1; } else { if (!request->chandler) { - request->chandler = - conditionWait(&object->condition, httpServeObjectHandler, sizeof(connection), &connection); + request->chandler = conditionWait(&object->condition, httpServeObjectHandler, sizeof(connection), &connection); if (!request->chandler) { do_log(L_ERROR, "Couldn't register condition handler\n"); goto fail; @@ -1796,31 +1755,27 @@ int httpServeChunk(HTTPConnectionPtr connection) /* Prefetch */ if (!(object->flags & OBJECT_INPROGRESS) && !REQUEST_SIDE(request)) { if (object->chunks[i].size < CHUNK_SIZE && to >= 0 && connection->offset + len + 1 < to) - object->request( - object, request->method, connection->offset + len, -1, request, object->request_closure); - else if ( - i + 1 < object->numchunks && object->chunks[i + 1].size == 0 && to >= 0 - && (i + 1) * CHUNK_SIZE + 1 < to) + object->request(object, request->method, connection->offset + len, -1, request, object->request_closure); + else if (i + 1 < object->numchunks && object->chunks[i + 1].size == 0 && to >= 0 && (i + 1) * CHUNK_SIZE + 1 < to) object->request(object, request->method, (i + 1) * CHUNK_SIZE, -1, request, object->request_closure); } if (len2 == 0) { httpSetTimeout(connection, clientTimeout); do_log( - D_CLIENT_DATA, "Serving on 0x%lx for 0x%lx: offset %d len %d\n", (unsigned long)connection, - (unsigned long)object, connection->offset, len); + D_CLIENT_DATA, "Serving on 0x%lx for 0x%lx: offset %d len %d\n", (unsigned long)connection, (unsigned long)object, connection->offset, + len); /* IO_NOTNOW in order to give other clients a chance to run. */ do_stream( - IO_WRITE | IO_NOTNOW | (connection->te == TE_CHUNKED ? IO_CHUNKED : 0) | (end ? IO_END : 0), - connection->fd, 0, object->chunks[i].data + j, len, httpServeObjectStreamHandler, connection); + IO_WRITE | IO_NOTNOW | (connection->te == TE_CHUNKED ? IO_CHUNKED : 0) | (end ? IO_END : 0), connection->fd, 0, + object->chunks[i].data + j, len, httpServeObjectStreamHandler, connection); } else { httpSetTimeout(connection, clientTimeout); do_log( - D_CLIENT_DATA, "Serving on 0x%lx for 0x%lx: offset %d len %d + %d\n", (unsigned long)connection, - (unsigned long)object, connection->offset, len, len2); + D_CLIENT_DATA, "Serving on 0x%lx for 0x%lx: offset %d len %d + %d\n", (unsigned long)connection, (unsigned long)object, + connection->offset, len, len2); do_stream_2( - IO_WRITE | IO_NOTNOW | (connection->te == TE_CHUNKED ? IO_CHUNKED : 0) | (end ? IO_END : 0), - connection->fd, 0, object->chunks[i].data + j, len, object->chunks[i + 1].data, len2, - httpServeObjectStreamHandler2, connection); + IO_WRITE | IO_NOTNOW | (connection->te == TE_CHUNKED ? IO_CHUNKED : 0) | (end ? IO_END : 0), connection->fd, 0, + object->chunks[i].data + j, len, object->chunks[i + 1].data, len2, httpServeObjectStreamHandler2, connection); } return 1; } diff --git a/polipo/client.h b/polipo/client.h index 3518f978efd6619138143bc0ea9ce8055fce0fa7..c550a1bead2fe46ffa676455672251aaf4b42518 100644 --- a/polipo/client.h +++ b/polipo/client.h @@ -31,8 +31,7 @@ int httpErrorStreamHandler(int status, FdEventHandlerPtr event, StreamRequestPtr int httpErrorNocloseStreamHandler(int status, FdEventHandlerPtr event, StreamRequestPtr request); int httpErrorNofinishStreamHandler(int status, FdEventHandlerPtr event, StreamRequestPtr request); int httpClientRequest(HTTPRequestPtr request, AtomPtr url); -int httpClientRequestContinue( - int forbidden_code, AtomPtr url, AtomPtr forbidden_message, AtomPtr forbidden_headers, void* closure); +int httpClientRequestContinue(int forbidden_code, AtomPtr url, AtomPtr forbidden_message, AtomPtr forbidden_headers, void* closure); int httpClientDiscardBody(HTTPConnectionPtr connection); int httpClientDiscardHandler(int, FdEventHandlerPtr, StreamRequestPtr); int httpClientGetHandler(int, ConditionHandlerPtr); diff --git a/polipo/config.c b/polipo/config.c index 1aa2268dc211f7c30b2fad1a4ccfb3f83c7b8148..676bae45eab2b48a4c1fd2913725d3111e83336a 100644 --- a/polipo/config.c +++ b/polipo/config.c @@ -324,9 +324,7 @@ static void printVariableForm(FILE* out, ConfigVariablePtr var) case CONFIG_ATOM_LIST_LOWER: fprintf(out, "\n", var->type == CONFIG_PASSWORD ? " type=password" : "", var->name->string, - disabled); + fprintf(out, "\"%s size=14 name=%s %s>\n", var->type == CONFIG_PASSWORD ? " type=password" : "", var->name->string, disabled); break; case CONFIG_BOOLEAN: { @@ -652,8 +650,7 @@ static int parseAtom(char* buf, int offset, AtomPtr* value_return, int insensiti j = i + 1; } else { y0 = i; - while (letter(buf[i]) || digit(buf[i]) || buf[i] == '_' || buf[i] == '-' || buf[i] == '~' || buf[i] == '.' - || buf[i] == ':' || buf[i] == '/') + while (letter(buf[i]) || digit(buf[i]) || buf[i] == '_' || buf[i] == '-' || buf[i] == '~' || buf[i] == '.' || buf[i] == ':' || buf[i] == '/') i++; j = i; } diff --git a/polipo/config.h b/polipo/config.h index 4b69e522d11f203e71d6242ae5b279abfac16fed..7b5f9bf86b78d6bc8df5f9825ae68bf608c02c14 100644 --- a/polipo/config.h +++ b/polipo/config.h @@ -53,8 +53,7 @@ typedef struct _ConfigVariable { #define CONFIG_VARIABLE(name, type, help) CONFIG_VARIABLE_SETTABLE(name, type, NULL, help) -#define CONFIG_VARIABLE_SETTABLE(name, type, setter, help) \ - declareConfigVariable(internAtom(#name), type, &name, setter, help) +#define CONFIG_VARIABLE_SETTABLE(name, type, setter, help) declareConfigVariable(internAtom(#name), type, &name, setter, help) void declareConfigVariable(AtomPtr name, int type, void* value, int (*setter)(ConfigVariablePtr, void*), char* help); void printConfigVariables(FILE* out, int html); diff --git a/polipo/diskcache.c b/polipo/diskcache.c index 44b88908e3d486476c9151f0b35ec3002d3d01b8..cfed0846f4c447fedcd5aeaf0966574d766f211f 100644 --- a/polipo/diskcache.c +++ b/polipo/diskcache.c @@ -66,22 +66,17 @@ void preinitDiskcache() diskCacheRoot = internAtom(DISK_CACHE_ROOT); localDocumentRoot = internAtom(LOCAL_ROOT); - CONFIG_VARIABLE_SETTABLE( - diskCacheDirectoryPermissions, CONFIG_OCTAL, configIntSetter, "Access rights for new directories."); - CONFIG_VARIABLE_SETTABLE( - diskCacheFilePermissions, CONFIG_OCTAL, configIntSetter, "Access rights for new cache files."); - CONFIG_VARIABLE_SETTABLE( - diskCacheWriteoutOnClose, CONFIG_INT, configIntSetter, "Number of bytes to write out eagerly."); + CONFIG_VARIABLE_SETTABLE(diskCacheDirectoryPermissions, CONFIG_OCTAL, configIntSetter, "Access rights for new directories."); + CONFIG_VARIABLE_SETTABLE(diskCacheFilePermissions, CONFIG_OCTAL, configIntSetter, "Access rights for new cache files."); + CONFIG_VARIABLE_SETTABLE(diskCacheWriteoutOnClose, CONFIG_INT, configIntSetter, "Number of bytes to write out eagerly."); CONFIG_VARIABLE_SETTABLE(diskCacheRoot, CONFIG_ATOM, atomSetterFlush, "Root of the disk cache."); CONFIG_VARIABLE_SETTABLE(localDocumentRoot, CONFIG_ATOM, atomSetterFlush, "Root of the local tree."); - CONFIG_VARIABLE_SETTABLE( - maxDiskEntries, CONFIG_INT, maxDiskEntriesSetter, "File descriptors used by the on-disk cache."); + CONFIG_VARIABLE_SETTABLE(maxDiskEntries, CONFIG_INT, maxDiskEntriesSetter, "File descriptors used by the on-disk cache."); CONFIG_VARIABLE(diskCacheUnlinkTime, CONFIG_TIME, "Time after which on-disk objects are removed."); CONFIG_VARIABLE(diskCacheTruncateTime, CONFIG_TIME, "Time after which on-disk objects are truncated."); CONFIG_VARIABLE(diskCacheTruncateSize, CONFIG_INT, "Size to which on-disk objects are truncated."); CONFIG_VARIABLE(preciseExpiry, CONFIG_BOOLEAN, "Whether to consider all files for purging."); - CONFIG_VARIABLE_SETTABLE( - maxDiskCacheEntrySize, CONFIG_INT, configIntSetter, "Maximum size of objects cached on disk."); + CONFIG_VARIABLE_SETTABLE(maxDiskCacheEntrySize, CONFIG_INT, configIntSetter, "Maximum size of objects cached on disk."); } static int maxDiskEntriesSetter(ConfigVariablePtr var, void* value) @@ -112,8 +107,7 @@ static int checkRoot(AtomPtr root) return 0; #ifdef WIN32 /* Require "x:/" or "x:\\" */ - rc = - isalpha(root->string[0]) && (root->string[1] == ':') && ((root->string[2] == '/') || (root->string[2] == '\\')); + rc = isalpha(root->string[0]) && (root->string[1] == ':') && ((root->string[2] == '/') || (root->string[2] == '\\')); if (!rc) { return -2; } @@ -768,8 +762,7 @@ int validateLocalEntry(ObjectPtr object, int fd, int* body_offset_return, off_t* return -1; } - n = snnprintf( - buf, 0, 512, "%lx-%lx-%lx", (unsigned long)ss.st_ino, (unsigned long)ss.st_size, (unsigned long)ss.st_mtime); + n = snnprintf(buf, 0, 512, "%lx-%lx-%lx", (unsigned long)ss.st_ino, (unsigned long)ss.st_size, (unsigned long)ss.st_mtime); if (n >= 512) n = -1; @@ -910,8 +903,8 @@ parse_again: } rc = httpParseHeaders( - 0, NULL, buf, rc, NULL, &headers, &length, &cache_control, NULL, NULL, &date, &last_modified, &expires, - &polipo_age, &polipo_access, &body_offset, NULL, &etag, NULL, NULL, NULL, &location, &via, NULL); + 0, NULL, buf, rc, NULL, &headers, &length, &cache_control, NULL, NULL, &date, &last_modified, &expires, &polipo_age, &polipo_access, + &body_offset, NULL, &etag, NULL, NULL, NULL, &location, &via, NULL); if (rc < 0) { releaseAtom(message); goto fail; @@ -965,8 +958,7 @@ parse_again: } if ((object->cache_control & CACHE_VARY) && dontTrustVaryETag >= 1) { /* Check content-type to work around mod_gzip bugs */ - if (!httpHeaderMatch(atomContentType, object->headers, headers) - || !httpHeaderMatch(atomContentEncoding, object->headers, headers)) + if (!httpHeaderMatch(atomContentType, object->headers, headers) || !httpHeaderMatch(atomContentEncoding, object->headers, headers)) goto invalid; } } @@ -1471,9 +1463,7 @@ int objectFillFromDisk(ObjectPtr object, int offset, int chunks) complete = 1; if (object->flags & OBJECT_INITIAL) { complete = 0; - } else if ( - (object->length < 0 || object->size < object->length) - && object->size < (offset / CHUNK_SIZE + chunks) * CHUNK_SIZE) { + } else if ((object->length < 0 || object->size < object->length) && object->size < (offset / CHUNK_SIZE + chunks) * CHUNK_SIZE) { complete = 0; } else { for (k = 0; k < chunks; k++) { @@ -1545,15 +1535,13 @@ int objectFillFromDisk(ObjectPtr object, int offset, int chunks) if (object->size < o + rc) object->size = o + rc; - if (entry->object->length >= 0 && entry->size < 0 - && entry->offset - entry->body_offset == entry->object->length) + if (entry->object->length >= 0 && entry->size < 0 && entry->offset - entry->body_offset == entry->object->length) entry->size = entry->object->length; if (rc < CHUNK_SIZE - j) { /* Paranoia: the read may have been interrupted half-way. */ if (entry->size < 0) { - if (rc == 0 - || (entry->object->length >= 0 && entry->object->length == entry->offset - entry->body_offset)) + if (rc == 0 || (entry->object->length >= 0 && entry->object->length == entry->offset - entry->body_offset)) entry->size = entry->offset - entry->body_offset; break; } else if (entry->size != entry->offset - entry->body_offset) { @@ -1809,8 +1797,8 @@ DiskObjectPtr readDiskObject(char* filename, struct stat* sb) goto fail; rc = httpParseHeaders( - 0, NULL, buf, rc, NULL, NULL, &length, NULL, NULL, NULL, &date, &last_modified, &expires, &age, &atime, - &body_offset, NULL, NULL, NULL, NULL, NULL, &location, NULL, NULL); + 0, NULL, buf, rc, NULL, NULL, &length, NULL, NULL, NULL, &date, &last_modified, &expires, &age, &atime, &body_offset, NULL, NULL, NULL, + NULL, NULL, &location, NULL, NULL); if (rc < 0 || location == NULL) goto fail; if (body_offset < 0) @@ -2088,9 +2076,7 @@ void indexDiskObjects(FILE* out, const char* root, int recursive) if (!fe) break; if (fe->fts_info != FTS_DP) - dobjects = processObject( - dobjects, fe->fts_path, - fe->fts_info == FTS_NS || fe->fts_info == FTS_NSOK ? fe->fts_statp : NULL); + dobjects = processObject(dobjects, fe->fts_path, fe->fts_info == FTS_NS || fe->fts_info == FTS_NSOK ? fe->fts_statp : NULL); } fts_close(fts); } @@ -2297,8 +2283,7 @@ static long int expireFile(char* filename, struct stat* sb, int* considered, int t = current_time.tv_sec; } - if (t > current_time.tv_sec - diskCacheUnlinkTime - && (sb->st_size < diskCacheTruncateSize || t > current_time.tv_sec - diskCacheTruncateTime)) + if (t > current_time.tv_sec - diskCacheUnlinkTime && (sb->st_size < diskCacheTruncateSize || t > current_time.tv_sec - diskCacheTruncateTime)) return ret; } @@ -2324,9 +2309,7 @@ static long int expireFile(char* filename, struct stat* sb, int* considered, int t = dobject->date; if (t > current_time.tv_sec) - do_log( - L_WARN, "Disk entry %s (%s) has access time in the future.\n", scrub(dobject->location), - scrub(dobject->filename)); + do_log(L_WARN, "Disk entry %s (%s) has access time in the future.\n", scrub(dobject->location), scrub(dobject->filename)); if (t < current_time.tv_sec - diskCacheUnlinkTime) { rc = unlink(dobject->filename); @@ -2336,9 +2319,7 @@ static long int expireFile(char* filename, struct stat* sb, int* considered, int (*unlinked)++; ret = 0; } - } else if ( - dobject->size > diskCacheTruncateSize + 4 * dobject->body_offset - && t < current_time.tv_sec - diskCacheTruncateTime) { + } else if (dobject->size > diskCacheTruncateSize + 4 * dobject->body_offset && t < current_time.tv_sec - diskCacheTruncateTime) { /* We need to copy rather than simply truncate in place: the latter would confuse a running polipo. */ fd = open(dobject->filename, O_RDONLY | O_BINARY, 0); @@ -2410,8 +2391,7 @@ void expireDiskObjects() } if (!S_ISREG(fe->fts_statp->st_mode)) { - do_log( - L_ERROR, "Unexpected file %s type 0%o.\n", fe->fts_accpath, (unsigned int)fe->fts_statp->st_mode); + do_log(L_ERROR, "Unexpected file %s type 0%o.\n", fe->fts_accpath, (unsigned int)fe->fts_statp->st_mode); continue; } diff --git a/polipo/diskcache.h b/polipo/diskcache.h index 299714d2855f0b57d76f8de089cb87d5fc5c42ad..4b6bef24ed11ecf0bbf712726aa37cdabee020c7 100644 --- a/polipo/diskcache.h +++ b/polipo/diskcache.h @@ -36,7 +36,7 @@ typedef struct _DiskCacheEntry { short metadataDirty; struct _DiskCacheEntry* next; struct _DiskCacheEntry* previous; -} * DiskCacheEntryPtr, DiskCacheEntryRec; +} *DiskCacheEntryPtr, DiskCacheEntryRec; typedef struct _DiskObject { char* location; diff --git a/polipo/dns.c b/polipo/dns.c index 243a266ac490b6e75f5de6709f9c35d0364029e1..d9f65b7cd64a6579c8e4a59c0a3e9ec5c7b04f3c 100644 --- a/polipo/dns.c +++ b/polipo/dns.c @@ -92,15 +92,8 @@ static int labelsToString(char* buf, int offset, int n, char* d, int m, int* j_r static int dnsBuildQuery(int id, char* buf, int offset, int n, AtomPtr name, int af); static int dnsReplyHandler(int abort, FdEventHandlerPtr event); static int dnsReplyId(char* buf, int offset, int n, int* id_return); -static int dnsDecodeReply( - char* buf, - int offset, - int n, - int* id_return, - AtomPtr* name_return, - AtomPtr* value_return, - int* af_return, - unsigned* ttl_return); +static int + dnsDecodeReply(char* buf, int offset, int n, int* id_return, AtomPtr* name_return, AtomPtr* value_return, int* af_return, unsigned* ttl_return); static int dnsHandler(int status, ConditionHandlerPtr chandler); static int dnsGethostbynameFallback(int id, AtomPtr message); static int sendQuery(DnsQueryPtr query); @@ -808,9 +801,7 @@ static int dnsTimeoutHandler(TimeEventHandlerPtr event) /* People are reporting that this does happen. And I have no idea why. */ if (!queryInFlight(query)) { - do_log( - L_ERROR, "BUG: timing out martian query (%s, flags: 0x%x).\n", scrub(query->name->string), - (unsigned)object->flags); + do_log(L_ERROR, "BUG: timing out martian query (%s, flags: 0x%x).\n", scrub(query->name->string), (unsigned)object->flags); return 1; } @@ -1123,9 +1114,7 @@ static int dnsReplyHandler(int abort, FdEventHandlerPtr event) replies? */ if (rc < 0) { do_log_error(L_WARN, -rc, "DNS"); - if (dnsUseGethostbyname >= 2 - || (dnsUseGethostbyname - && (rc != -EDNS_HOST_NOT_FOUND && rc != -EDNS_NO_RECOVERY && rc != -EDNS_FORMAT))) { + if (dnsUseGethostbyname >= 2 || (dnsUseGethostbyname && (rc != -EDNS_HOST_NOT_FOUND && rc != -EDNS_NO_RECOVERY && rc != -EDNS_FORMAT))) { dnsGethostbynameFallback(id, message); return 0; } else { @@ -1485,15 +1474,8 @@ static int dnsReplyId(char* buf, int offset, int n, int* id_return) return 1; } -static int dnsDecodeReply( - char* buf, - int offset, - int n, - int* id_return, - AtomPtr* name_return, - AtomPtr* value_return, - int* af_return, - unsigned* ttl_return) +static int + dnsDecodeReply(char* buf, int offset, int n, int* id_return, AtomPtr* name_return, AtomPtr* value_return, int* af_return, unsigned* ttl_return) { int i = offset, j, m; int id = -1, b23, qdcount, ancount, nscount, arcount, rdlength; @@ -1633,9 +1615,7 @@ static int dnsDecodeReply( } if (type == 1 || type == 28) { if ((type == 1 && rdlength != 4) || (type == 28 && rdlength != 16)) { - do_log( - L_ERROR, "DNS: %s: unexpected length %d of %s record.\n", scrub(name->string), rdlength, - type == 1 ? "A" : "AAAA"); + do_log(L_ERROR, "DNS: %s: unexpected length %d of %s record.\n", scrub(name->string), rdlength, type == 1 ? "A" : "AAAA"); error = EDNS_INVALID; if (rdlength <= 0 || rdlength >= 32) goto fail; diff --git a/polipo/event.c b/polipo/event.c index bbc4305dfcacefb7b2dccdb5a66356b6ebde4a87..1e3d770c9dadf96b082909bf98b2ef3a19148476 100644 --- a/polipo/event.c +++ b/polipo/event.c @@ -386,8 +386,7 @@ FdEventHandlerPtr registerFdEventHelper(FdEventHandlerPtr event) return event; } -FdEventHandlerPtr - registerFdEvent(int fd, int poll_events, int (*handler)(int, FdEventHandlerPtr), int dsize, void* data) +FdEventHandlerPtr registerFdEvent(int fd, int poll_events, int (*handler)(int, FdEventHandlerPtr), int dsize, void* data) { FdEventHandlerPtr event; @@ -704,8 +703,7 @@ ConditionPtr makeCondition(void) return condition; } -ConditionHandlerPtr - conditionWait(ConditionPtr condition, int (*handler)(int, ConditionHandlerPtr), int dsize, void* data) +ConditionHandlerPtr conditionWait(ConditionPtr condition, int (*handler)(int, ConditionHandlerPtr), int dsize, void* data) { ConditionHandlerPtr chandler; diff --git a/polipo/event.h b/polipo/event.h index 9e8a3b21dc5ffd8fd653ca41d1645f0cd7d0372d..08e2e7030ffe873b1191d7a44aba15e580642028 100644 --- a/polipo/event.h +++ b/polipo/event.h @@ -65,8 +65,7 @@ void deallocateFdEventNum(int i); void timeToSleep(struct timeval*); void runTimeEventQueue(void); FdEventHandlerPtr makeFdEvent(int fd, int poll_events, int (*handler)(int, FdEventHandlerPtr), int dsize, void* data); -FdEventHandlerPtr - registerFdEvent(int fd, int poll_events, int (*handler)(int, FdEventHandlerPtr), int dsize, void* data); +FdEventHandlerPtr registerFdEvent(int fd, int poll_events, int (*handler)(int, FdEventHandlerPtr), int dsize, void* data); FdEventHandlerPtr registerFdEventHelper(FdEventHandlerPtr event); void unregisterFdEvent(FdEventHandlerPtr event); void pokeFdEvent(int fd, int status, int what); @@ -75,8 +74,7 @@ void eventLoop(void); ConditionPtr makeCondition(void); void initCondition(ConditionPtr); void signalCondition(ConditionPtr condition); -ConditionHandlerPtr - conditionWait(ConditionPtr condition, int (*handler)(int, ConditionHandlerPtr), int dsize, void* data); +ConditionHandlerPtr conditionWait(ConditionPtr condition, int (*handler)(int, ConditionHandlerPtr), int dsize, void* data); void unregisterConditionHandler(ConditionHandlerPtr); void abortConditionHandler(ConditionHandlerPtr); void polipoExit(void); diff --git a/polipo/forbidden.c b/polipo/forbidden.c index 8e392358ef9e7952567cf491af7af4e00763d779..6178f04df420443b1aea7d80a983c0c7ab9fb563 100644 --- a/polipo/forbidden.c +++ b/polipo/forbidden.c @@ -76,13 +76,11 @@ void preinitForbidden(void) CONFIG_VARIABLE_SETTABLE(forbiddenFile, CONFIG_ATOM, atomSetterForbidden, "File specifying forbidden URLs."); #ifndef NO_REDIRECTOR CONFIG_VARIABLE_SETTABLE(redirector, CONFIG_ATOM, atomSetterForbidden, "Squid-style redirector."); - CONFIG_VARIABLE_SETTABLE( - redirectorRedirectCode, CONFIG_INT, configIntSetter, "Redirect code to use with redirector."); + CONFIG_VARIABLE_SETTABLE(redirectorRedirectCode, CONFIG_INT, configIntSetter, "Redirect code to use with redirector."); #endif CONFIG_VARIABLE_SETTABLE(uncachableFile, CONFIG_ATOM, atomSetterForbidden, "File specifying uncachable URLs."); - CONFIG_VARIABLE_SETTABLE( - forbiddenTunnelsFile, CONFIG_ATOM, atomSetterForbidden, "File specifying forbidden tunnels."); + CONFIG_VARIABLE_SETTABLE(forbiddenTunnelsFile, CONFIG_ATOM, atomSetterForbidden, "File specifying forbidden tunnels."); } static int atomSetterForbidden(ConfigVariablePtr var, void* value) @@ -242,8 +240,7 @@ void parseDomainFile(AtomPtr file, DomainPtr** domains_return, regex_t** regex_r fe = fts_read(fts); if (!fe) break; - if (fe->fts_info != FTS_D && fe->fts_info != FTS_DP && fe->fts_info != FTS_DC - && fe->fts_info != FTS_DNR) + if (fe->fts_info != FTS_D && fe->fts_info != FTS_DP && fe->fts_info != FTS_DC && fe->fts_info != FTS_DNR) readDomainFile(fe->fts_accpath); } fts_close(fts); @@ -389,8 +386,7 @@ int urlIsMatched(char* url, int length, DomainPtr* domains, regex_t* regex) } domain = domains; while (*domain) { - if ((*domain)->length <= (i - 7) - && (url[i - (*domain)->length - 1] == '.' || url[i - (*domain)->length - 1] == '/') + if ((*domain)->length <= (i - 7) && (url[i - (*domain)->length - 1] == '.' || url[i - (*domain)->length - 1] == '/') && memcmp(url + i - (*domain)->length, (*domain)->domain, (*domain)->length) == 0) return 1; domain++; @@ -520,9 +516,7 @@ void redirectorTrigger(void) return; } } - do_stream_2( - IO_WRITE, redirector_write_fd, 0, request->url->string, request->url->length, "\n", 1, redirectorStreamHandler1, - request); + do_stream_2(IO_WRITE, redirector_write_fd, 0, request->url->string, request->url->length, "\n", 1, redirectorStreamHandler1, request); } int redirectorStreamHandler1(int status, FdEventHandlerPtr event, StreamRequestPtr srequest) @@ -539,8 +533,7 @@ int redirectorStreamHandler1(int status, FdEventHandlerPtr event, StreamRequestP if (!streamRequestDone(srequest)) return 0; - do_stream( - IO_READ, redirector_read_fd, 0, redirector_buffer, REDIRECTOR_BUFFER_SIZE, redirectorStreamHandler2, request); + do_stream(IO_READ, redirector_read_fd, 0, redirector_buffer, REDIRECTOR_BUFFER_SIZE, redirectorStreamHandler2, request); return 1; fail: @@ -577,8 +570,7 @@ int redirectorStreamHandler2(int status, FdEventHandlerPtr event, StreamRequestP do_log(L_WARN, "Stray bytes in redirector output.\n"); if (c > redirector_buffer + 1 - && (c - redirector_buffer != request->url->length - || memcmp(redirector_buffer, request->url->string, request->url->length) != 0)) { + && (c - redirector_buffer != request->url->length || memcmp(redirector_buffer, request->url->string, request->url->length) != 0)) { code = redirectorRedirectCode; message = internAtom("Redirected by external redirector"); if (message == NULL) { diff --git a/polipo/http.c b/polipo/http.c index 38c66c87d87a56641c429b562bffc2e3b0e3c127..1a8195775d48b8b674ddddb828189d892505e1b0 100644 --- a/polipo/http.c +++ b/polipo/http.c @@ -192,8 +192,7 @@ void initHttp() host = gethostbyaddr(host->h_addr_list[0], host->h_length, AF_INET); - if (!host || !host->h_name || strcmp(host->h_name, "localhost") == 0 - || strcmp(host->h_name, "localhost.localdomain") == 0) + if (!host || !host->h_name || strcmp(host->h_name, "localhost") == 0 || strcmp(host->h_name, "localhost.localdomain") == 0) goto success; namelen = strlen(host->h_name); @@ -791,17 +790,7 @@ int httpCondition(ObjectPtr object, HTTPConditionPtr condition) } int httpWriteErrorHeaders( - char* buf, - int size, - int offset, - int do_body, - int code, - AtomPtr message, - int close, - AtomPtr headers, - char* url, - int url_len, - char* etag) + char* buf, int size, int offset, int do_body, int code, AtomPtr message, int close, AtomPtr headers, char* url, int url_len, char* etag) { int n, m, i; char* body; @@ -832,8 +821,7 @@ int httpWriteErrorHeaders( "\n" "\n

%3d %s

" "\n

The following %s", - code >= 400 ? "error" : "result", code, htmlMessage, code, htmlMessage, - code >= 400 ? "error occurred" : "status was returned"); + code >= 400 ? "error" : "result", code, htmlMessage, code, htmlMessage, code >= 400 ? "error occurred" : "status was returned"); if (url_len > 0) { m = snnprintf(body, m, CHUNK_SIZE, " while trying to access "); m = htmlString(body, m, CHUNK_SIZE, url, url_len); @@ -977,8 +965,8 @@ void httpTweakCachability(ObjectPtr object) handle, even if Expires or Cache-Control says otherwise. As to known uncacheable replies, we obey Cache-Control and default to allowing sharing but not caching. */ - if (code != 200 && code != 206 && code != 300 && code != 301 && code != 302 && code != 303 && code != 304 - && code != 307 && code != 403 && code != 404 && code != 405 && code != 416) { + if (code != 200 && code != 206 && code != 300 && code != 301 && code != 302 && code != 303 && code != 304 && code != 307 && code != 403 + && code != 404 && code != 405 && code != 416) { object->cache_control |= (CACHE_NO_HIDDEN | CACHE_MISMATCH); object->flags |= OBJECT_LINEAR; } else if (code != 200 && code != 206 && code != 300 && code != 301 && code != 304 && code != 410) { diff --git a/polipo/http.h b/polipo/http.h index f18e01a0a616e6ebfc52372a26228d91dbbbb56f..8d0fc8446c0759043322093f9140c44fade55302 100644 --- a/polipo/http.h +++ b/polipo/http.h @@ -175,17 +175,7 @@ HTTPConditionPtr httpMakeCondition(void); void httpDestroyCondition(HTTPConditionPtr condition); int httpCondition(ObjectPtr, HTTPConditionPtr); int httpWriteErrorHeaders( - char* buf, - int size, - int offset, - int do_body, - int code, - AtomPtr message, - int close, - AtomPtr, - char* url, - int url_len, - char* etag); + char* buf, int size, int offset, int do_body, int code, AtomPtr message, int close, AtomPtr, char* url, int url_len, char* etag); AtomListPtr urlDecode(char*, int); void httpTweakCachability(ObjectPtr); int httpHeaderMatch(AtomPtr header, AtomPtr headers1, AtomPtr headers2); diff --git a/polipo/http_parse.c b/polipo/http_parse.c index fcd4ac72766d16de47be94f81a960188ecd6021c..0884af4949711148c94c9d47c02bc18cf122536e 100644 --- a/polipo/http_parse.c +++ b/polipo/http_parse.c @@ -24,14 +24,12 @@ THE SOFTWARE. static int getNextWord(const char* buf, int i, int* x_return, int* y_return); static int getNextToken(const char* buf, int i, int* x_return, int* y_return); -static int getNextTokenInList( - const char* buf, int i, int* x_return, int* y_return, int* z_return, int* t_return, int* end_return); - -static AtomPtr atomConnection, atomProxyConnection, atomContentLength, atomHost, atomAcceptRange, atomTE, atomReferer, - atomProxyAuthenticate, atomProxyAuthorization, atomKeepAlive, atomTrailer, atomUpgrade, atomDate, atomExpires, - atomIfModifiedSince, atomIfUnmodifiedSince, atomIfRange, atomLastModified, atomIfMatch, atomIfNoneMatch, atomAge, - atomTransferEncoding, atomETag, atomCacheControl, atomPragma, atomContentRange, atomRange, atomVia, atomVary, - atomExpect, atomAuthorization, atomSetCookie, atomCookie, atomCookie2, atomXPolipoDate, atomXPolipoAccess, +static int getNextTokenInList(const char* buf, int i, int* x_return, int* y_return, int* z_return, int* t_return, int* end_return); + +static AtomPtr atomConnection, atomProxyConnection, atomContentLength, atomHost, atomAcceptRange, atomTE, atomReferer, atomProxyAuthenticate, + atomProxyAuthorization, atomKeepAlive, atomTrailer, atomUpgrade, atomDate, atomExpires, atomIfModifiedSince, atomIfUnmodifiedSince, atomIfRange, + atomLastModified, atomIfMatch, atomIfNoneMatch, atomAge, atomTransferEncoding, atomETag, atomCacheControl, atomPragma, atomContentRange, + atomRange, atomVia, atomVary, atomExpect, atomAuthorization, atomSetCookie, atomCookie, atomCookie2, atomXPolipoDate, atomXPolipoAccess, atomXPolipoLocation, atomXPolipoBodyOffset; AtomPtr atomContentType, atomContentEncoding; @@ -278,8 +276,7 @@ static int getNextETag(const char* restrict buf, int i, int* x_return, int* y_re return i; } -static int getNextTokenInList( - const char* restrict buf, int i, int* x_return, int* y_return, int* z_return, int* t_return, int* end_return) +static int getNextTokenInList(const char* restrict buf, int i, int* x_return, int* y_return, int* z_return, int* t_return, int* end_return) { int j, x, y, z = -1, t = -1, end; j = getNextToken(buf, i, &x, &y); @@ -388,8 +385,7 @@ again: return j; } -int httpParseClientFirstLine( - const char* restrict buf, int offset, int* method_return, AtomPtr* url_return, int* version_return) +int httpParseClientFirstLine(const char* restrict buf, int offset, int* method_return, AtomPtr* url_return, int* version_return) { int i = 0; int x, y; @@ -509,13 +505,8 @@ static int parseInt(const char* restrict buf, int start, int* val_return) /* Returned *name_start_return is -1 at end of headers, -2 if the line couldn't be parsed. */ -static int parseHeaderLine( - const char* restrict buf, - int start, - int* name_start_return, - int* name_end_return, - int* value_start_return, - int* value_end_return) +static int + parseHeaderLine(const char* restrict buf, int start, int* name_start_return, int* name_end_return, int* value_start_return, int* value_end_return) { int i; int name_start, name_end, value_start, value_end; @@ -682,8 +673,7 @@ static int parseRange(const char* restrict buf, int i, int* from_return, int* to return i; } -static void - parseCacheControl(const char* restrict buf, int token_start, int token_end, int v_start, int v_end, int* age_return) +static void parseCacheControl(const char* restrict buf, int token_start, int token_end, int v_start, int v_end, int* age_return) { if (v_start <= 0 || !digit(buf[v_start])) { do_log(L_WARN, "Couldn't parse Cache-Control: "); @@ -924,8 +914,7 @@ int httpParseHeaders( } else if (name == atomReferer) { int h; if (censorReferer == 0 - || (censorReferer == 1 && url != NULL - && urlSameHost(url->string, url->length, buf + value_start, value_end - value_start))) { + || (censorReferer == 1 && url != NULL && urlSameHost(url->string, url->length, buf + value_start, value_end - value_start))) { while (hbuf_length > hbuf_size - 2) RESIZE_HBUF(); hbuf[hbuf_length++] = '\r'; @@ -941,8 +930,8 @@ int httpParseHeaders( do_log(L_ERROR, "Trailers or upgrade present.\n"); goto fail; } else if ( - name == atomDate || name == atomExpires || name == atomIfModifiedSince || name == atomIfUnmodifiedSince - || name == atomLastModified || name == atomXPolipoDate || name == atomXPolipoAccess) { + name == atomDate || name == atomExpires || name == atomIfModifiedSince || name == atomIfUnmodifiedSince || name == atomLastModified + || name == atomXPolipoDate || name == atomXPolipoAccess) { time_t t; j = parse_time(buf, value_start, value_end, &t); if (j < 0) { @@ -1072,10 +1061,8 @@ int httpParseHeaders( } else if (token_compare(buf, token_start, token_end, "only-if-cached")) { cache_control.flags |= CACHE_ONLY_IF_CACHED; } else if ( - token_compare(buf, token_start, token_end, "max-age") - || token_compare(buf, token_start, token_end, "maxage") || /* losers */ - token_compare(buf, token_start, token_end, "s-maxage") - || token_compare(buf, token_start, token_end, "min-fresh")) { + token_compare(buf, token_start, token_end, "max-age") || token_compare(buf, token_start, token_end, "maxage") || /* losers */ + token_compare(buf, token_start, token_end, "s-maxage") || token_compare(buf, token_start, token_end, "min-fresh")) { parseCacheControl(buf, token_start, token_end, v_start, v_end, &cache_control.max_age); } else if (token_compare(buf, token_start, token_end, "max-stale")) { parseCacheControl(buf, token_start, token_end, v_start, v_end, &cache_control.max_stale); @@ -1090,8 +1077,7 @@ int httpParseHeaders( } } else if (name == atomContentRange) { if (!client) { - j = parseContentRange( - buf, value_start, &content_range.from, &content_range.to, &content_range.full_length); + j = parseContentRange(buf, value_start, &content_range.from, &content_range.to, &content_range.full_length); if (j < 0) { do_log(L_ERROR, "Couldn't parse Content-Range: "); do_log_n(L_ERROR, buf + value_start, value_end - value_start); @@ -1158,8 +1144,7 @@ int httpParseHeaders( } } if (name == atomVary) { - if (!token_compare(buf, value_start, value_end, "host") - && !token_compare(buf, value_start, value_end, "*")) { + if (!token_compare(buf, value_start, value_end, "host") && !token_compare(buf, value_start, value_end, "*")) { /* What other vary headers should be ignored? */ do_log(L_VARY, "Vary header present ("); do_log_n(L_VARY, buf + value_start, value_end - value_start); @@ -1196,9 +1181,8 @@ int httpParseHeaders( cache_control.flags |= CACHE_COOKIE; if (hbuf) { - if (name != atomConnection && name != atomHost && name != atomAcceptRange && name != atomTE - && name != atomProxyAuthenticate && name != atomKeepAlive - && (!hopToHop || !atomListMember(name, hopToHop)) && !atomListMember(name, censoredHeaders)) { + if (name != atomConnection && name != atomHost && name != atomAcceptRange && name != atomTE && name != atomProxyAuthenticate + && name != atomKeepAlive && (!hopToHop || !atomListMember(name, hopToHop)) && !atomListMember(name, censoredHeaders)) { int h; while (hbuf_length > hbuf_size - 2) RESIZE_HBUF(); diff --git a/polipo/io.c b/polipo/io.c index 625607cf1cb9765b00bcb89c1d1a60c3d53eb094..2a963878d956f2e0fdbb488fcec2c0519bf4c8e0 100644 --- a/polipo/io.c +++ b/polipo/io.c @@ -40,8 +40,7 @@ void preinitIo() WORD wVersionRequested; int err; #ifdef HAVE_IPV6_PREFER_TEMPADDR - CONFIG_VARIABLE_SETTABLE( - useTemporarySourceAddress, CONFIG_TRISTATE, configIntSetter, "Prefer IPv6 temporary source address."); + CONFIG_VARIABLE_SETTABLE(useTemporarySourceAddress, CONFIG_TRISTATE, configIntSetter, "Prefer IPv6 temporary source address."); #endif CONFIG_VARIABLE(proxyOutgoingAddress, CONFIG_ATOM_LOWER, "The IP address which the proxy connects from."); @@ -64,29 +63,15 @@ void initIo() return; } -FdEventHandlerPtr do_stream( - int operation, - int fd, - int offset, - char* buf, - int len, - int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), - void* data) +FdEventHandlerPtr + do_stream(int operation, int fd, int offset, char* buf, int len, int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), void* data) { assert(len > offset || (operation & (IO_END | IO_IMMEDIATE))); return schedule_stream(operation, fd, offset, NULL, 0, buf, len, NULL, 0, NULL, 0, NULL, handler, data); } FdEventHandlerPtr do_stream_2( - int operation, - int fd, - int offset, - char* buf, - int len, - char* buf2, - int len2, - int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), - void* data) + int operation, int fd, int offset, char* buf, int len, char* buf2, int len2, int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), void* data) { assert(len + len2 > offset || (operation & (IO_END | IO_IMMEDIATE))); return schedule_stream(operation, fd, offset, NULL, 0, buf, len, buf2, len2, NULL, 0, NULL, handler, data); @@ -125,17 +110,10 @@ FdEventHandlerPtr do_stream_h( } FdEventHandlerPtr do_stream_buf( - int operation, - int fd, - int offset, - char** buf_location, - int len, - int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), - void* data) + int operation, int fd, int offset, char** buf_location, int len, int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), void* data) { assert((len > offset || (operation & (IO_END | IO_IMMEDIATE))) && len <= CHUNK_SIZE); - return schedule_stream( - operation, fd, offset, NULL, 0, *buf_location, len, NULL, 0, NULL, 0, buf_location, handler, data); + return schedule_stream(operation, fd, offset, NULL, 0, *buf_location, len, NULL, 0, NULL, 0, buf_location, handler, data); } static int chunkHeaderLen(int i) @@ -212,9 +190,7 @@ FdEventHandlerPtr schedule_stream( } request.handler = handler; request.data = data; - event = makeFdEvent( - fd, (operation & IO_MASK) == IO_WRITE ? POLLOUT : POLLIN, do_scheduled_stream, sizeof(StreamRequestRec), - &request); + event = makeFdEvent(fd, (operation & IO_MASK) == IO_WRITE ? POLLOUT : POLLIN, do_scheduled_stream, sizeof(StreamRequestRec), &request); if (!event) { done = (*handler)(-ENOMEM, NULL, &request); assert(done); @@ -475,8 +451,7 @@ static int serverSocket(int af) return fd; } -FdEventHandlerPtr - do_connect(AtomPtr addr, int index, int port, int (*handler)(int, FdEventHandlerPtr, ConnectRequestPtr), void* data) +FdEventHandlerPtr do_connect(AtomPtr addr, int index, int port, int (*handler)(int, FdEventHandlerPtr, ConnectRequestPtr), void* data) { ConnectRequestRec request; FdEventHandlerPtr event; @@ -695,8 +670,7 @@ int do_scheduled_accept(int status, FdEventHandlerPtr event) return done; } -FdEventHandlerPtr - create_listener(char* address, int port, int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr), void* data) +FdEventHandlerPtr create_listener(char* address, int port, int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr), void* data) { int fd, rc; int one = 1; diff --git a/polipo/io.h b/polipo/io.h index 6883ee3fc58f205057f1e17befd4975164d45417..dd8e3f1e73c44a946abd1093317582f5a5f87dfe 100644 --- a/polipo/io.h +++ b/polipo/io.h @@ -83,14 +83,8 @@ typedef struct _AcceptRequest { void preinitIo(); void initIo(); -FdEventHandlerPtr do_stream( - int operation, - int fd, - int offset, - char* buf, - int len, - int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), - void* data); +FdEventHandlerPtr + do_stream(int operation, int fd, int offset, char* buf, int len, int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), void* data); FdEventHandlerPtr do_stream_h( int operation, @@ -128,13 +122,7 @@ FdEventHandlerPtr do_stream_3( void* data); FdEventHandlerPtr do_stream_buf( - int operation, - int fd, - int offset, - char** buf_location, - int len, - int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), - void* data); + int operation, int fd, int offset, char** buf_location, int len, int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), void* data); FdEventHandlerPtr schedule_stream( int operation, @@ -155,8 +143,7 @@ FdEventHandlerPtr schedule_stream( int do_scheduled_stream(int, FdEventHandlerPtr); int streamRequestDone(StreamRequestPtr); -FdEventHandlerPtr do_connect( - struct _Atom* addr, int index, int port, int (*handler)(int, FdEventHandlerPtr, ConnectRequestPtr), void* data); +FdEventHandlerPtr do_connect(struct _Atom* addr, int index, int port, int (*handler)(int, FdEventHandlerPtr, ConnectRequestPtr), void* data); int do_scheduled_connect(int, FdEventHandlerPtr event); @@ -166,8 +153,7 @@ FdEventHandlerPtr schedule_accept(int fd, int (*handler)(int, FdEventHandlerPtr, int do_scheduled_accept(int, FdEventHandlerPtr event); -FdEventHandlerPtr - create_listener(char* address, int port, int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr), void* data); +FdEventHandlerPtr create_listener(char* address, int port, int (*handler)(int, FdEventHandlerPtr, AcceptRequestPtr), void* data); int setNonblocking(int fd, int nonblocking); int setNodelay(int fd, int nodelay); int setV6only(int fd, int v6only); diff --git a/polipo/local.c b/polipo/local.c index 2dacc2fa29fc60c8c00dd959af710887d4e0d655..37d02944f509817a57825032290bd85782c34872 100644 --- a/polipo/local.c +++ b/polipo/local.c @@ -207,9 +207,8 @@ int httpSpecialRequest(ObjectPtr object, int method, int from, int to, HTTPReque "

back

" "\n", proxyName->string, proxyPort, cacheIsShared ? "shared" : "private", proxyName->string, proxyPort, - proxyOffline ? "off line" : (relaxTransparency ? "on line (transparency relaxed)" : "on line"), - publicObjectCount, privateObjectCount, used_chunks * CHUNK_SIZE / 1024, used_chunks, - totalChunkArenaSize() / 1024, used_atoms); + proxyOffline ? "off line" : (relaxTransparency ? "on line (transparency relaxed)" : "on line"), publicObjectCount, privateObjectCount, + used_chunks * CHUNK_SIZE / 1024, used_chunks, totalChunkArenaSize() / 1024, used_atoms); object->expires = current_time.tv_sec; object->length = object->size; } else if (matchUrl("/polipo/config", object)) { @@ -322,9 +321,7 @@ int httpSpecialDoSide(HTTPRequestPtr requestor) client->reqlen -= client->reqbegin; client->reqbegin = 0; - do_stream( - IO_READ | IO_NOTNOW, client->fd, client->reqlen, client->reqbuf, CHUNK_SIZE, httpSpecialClientSideHandler, - client); + do_stream(IO_READ | IO_NOTNOW, client->fd, client->reqlen, client->reqbuf, CHUNK_SIZE, httpSpecialClientSideHandler, client); return 1; } @@ -382,9 +379,7 @@ int httpSpecialDoSideFinish(AtomPtr data, HTTPRequestPtr requestor) for (i = 0; i < list->length; i++) { rc = parseConfigLine(list->list[i]->string, NULL, 0, 1); if (rc < 0) { - abortObject( - object, 400, - rc == -1 ? internAtom("Couldn't parse variable to set") : internAtom("Variable is not settable")); + abortObject(object, 400, rc == -1 ? internAtom("Couldn't parse variable to set") : internAtom("Variable is not settable")); destroyAtomList(list); goto out; } @@ -413,8 +408,7 @@ int httpSpecialDoSideFinish(AtomPtr data, HTTPRequestPtr requestor) } for (i = 0; i < list->length; i++) { char* equals = memchr(list->list[i]->string, '=', list->list[i]->length); - AtomPtr name = - equals ? internAtomN(list->list[i]->string, equals - list->list[i]->string) : retainAtom(list->list[i]); + AtomPtr name = equals ? internAtomN(list->list[i]->string, equals - list->list[i]->string) : retainAtom(list->list[i]); if (name == atomInitForbidden) initForbidden(); else if (name == atomReopenLog) @@ -619,8 +613,7 @@ done: if (rc < 0) { do_log(L_ERROR, "Wait for %d: %d\n", (int)request->pid, errno); } else { - int normal = (WIFEXITED(status) && WEXITSTATUS(status) == 0) - || (killed && WIFSIGNALED(status) && WTERMSIG(status) == SIGTERM); + int normal = (WIFEXITED(status) && WEXITSTATUS(status) == 0) || (killed && WIFSIGNALED(status) && WTERMSIG(status) == SIGTERM); char* reason = WIFEXITED(status) ? "with status" : WIFSIGNALED(status) ? "on signal" : "with unknown status"; int value = WIFEXITED(status) ? WEXITSTATUS(status) : WIFSIGNALED(status) ? WTERMSIG(status) : status; do_log(normal ? D_CHILD : L_ERROR, "Child %d exited %s %d.\n", (int)request->pid, reason, value); diff --git a/polipo/md5.c b/polipo/md5.c index b104eaf8a8c36a81f74e59f462b1ae94c207bdac..b3d26f15f0c6be9a220634d228ed6a32efa56ded 100644 --- a/polipo/md5.c +++ b/polipo/md5.c @@ -58,11 +58,10 @@ static const #else static #endif - unsigned char PADDING[64] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + unsigned char PADDING[64] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; /* F, G, H and I are basic MD5 functions */ #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) @@ -153,8 +152,8 @@ void MD5Update(MD5_CTX* mdContext, unsigned const char* inBuf, unsigned int inLe /* transform if necessary */ if (mdi == 0x40) { for (i = 0, ii = 0; i < 16; i++, ii += 4) - in[i] = (((UINT4)mdContext->in[ii + 3]) << 24) | (((UINT4)mdContext->in[ii + 2]) << 16) - | (((UINT4)mdContext->in[ii + 1]) << 8) | ((UINT4)mdContext->in[ii]); + in[i] = (((UINT4)mdContext->in[ii + 3]) << 24) | (((UINT4)mdContext->in[ii + 2]) << 16) | (((UINT4)mdContext->in[ii + 1]) << 8) + | ((UINT4)mdContext->in[ii]); Transform(mdContext->buf, in); mdi = 0; } @@ -185,8 +184,8 @@ void MD5Final(MD5_CTX* mdContext) /* append length in bits and transform */ for (i = 0, ii = 0; i < 14; i++, ii += 4) - in[i] = (((UINT4)mdContext->in[ii + 3]) << 24) | (((UINT4)mdContext->in[ii + 2]) << 16) - | (((UINT4)mdContext->in[ii + 1]) << 8) | ((UINT4)mdContext->in[ii]); + in[i] = (((UINT4)mdContext->in[ii + 3]) << 24) | (((UINT4)mdContext->in[ii + 2]) << 16) | (((UINT4)mdContext->in[ii + 1]) << 8) + | ((UINT4)mdContext->in[ii]); Transform(mdContext->buf, in); /* store buffer in digest */ diff --git a/polipo/mingw.c b/polipo/mingw.c index 61905656c6ebf0df5e3385e299ff2dbba0ed0211..916a95e2ce2f25860870e66b94d775ed55e6dc46 100644 --- a/polipo/mingw.c +++ b/polipo/mingw.c @@ -225,9 +225,7 @@ int win32_poll(struct pollfd* fds, unsigned int nfds, int timo) } #ifdef DEBUG_POLL - printf( - "Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n", (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, - (long)op); + printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n", (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op); #endif rc = select(0, ip, op, &efds, toptr); #ifdef DEBUG_POLL @@ -248,9 +246,7 @@ int win32_poll(struct pollfd* fds, unsigned int nfds, int timo) /* Some error was detected ... should be some way to know. */ fds[i].revents |= POLLHUP; #ifdef DEBUG_POLL - printf( - "%d %d %d revent = %x\n", FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds), - fds[i].revents); + printf("%d %d %d revent = %x\n", FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds), fds[i].revents); #endif } } diff --git a/polipo/object.c b/polipo/object.c index f6a6b33fdfa5318fbcc765ea3013235bae131abc..37f57bad5e1d4196c4f7659fd25ac4745d67b411 100644 --- a/polipo/object.c +++ b/polipo/object.c @@ -49,23 +49,20 @@ int dontCacheCookies = 0; void preinitObject() { CONFIG_VARIABLE_SETTABLE(idleTime, CONFIG_TIME, configIntSetter, "Time to remain idle before writing out."); - CONFIG_VARIABLE_SETTABLE( - maxWriteoutWhenIdle, CONFIG_INT, configIntSetter, "Amount of data to write at a time when idle."); + CONFIG_VARIABLE_SETTABLE(maxWriteoutWhenIdle, CONFIG_INT, configIntSetter, "Amount of data to write at a time when idle."); CONFIG_VARIABLE_SETTABLE( maxObjectsWhenIdle, CONFIG_INT, configIntSetter, "Number of objects to write at a time " "when idle."); CONFIG_VARIABLE_SETTABLE(cacheIsShared, CONFIG_BOOLEAN, configIntSetter, "If false, ignore s-maxage and private."); - CONFIG_VARIABLE_SETTABLE( - mindlesslyCacheVary, CONFIG_BOOLEAN, configIntSetter, "If true, mindlessly cache negotiated objects."); + CONFIG_VARIABLE_SETTABLE(mindlesslyCacheVary, CONFIG_BOOLEAN, configIntSetter, "If true, mindlessly cache negotiated objects."); CONFIG_VARIABLE(objectHashTableSize, CONFIG_INT, "Size of the object hash table (0 = auto)."); CONFIG_VARIABLE(objectHighMark, CONFIG_INT, "High object count mark."); CONFIG_VARIABLE(publicObjectLowMark, CONFIG_INT, "Low object count mark (0 = auto)."); CONFIG_VARIABLE_SETTABLE(maxExpiresAge, CONFIG_TIME, configIntSetter, "Max age for objects with Expires header."); CONFIG_VARIABLE_SETTABLE(maxAge, CONFIG_TIME, configIntSetter, "Max age for objects without Expires header."); CONFIG_VARIABLE_SETTABLE(maxAgeFraction, CONFIG_FLOAT, configFloatSetter, "Fresh fraction of modification time."); - CONFIG_VARIABLE_SETTABLE( - maxNoModifiedAge, CONFIG_TIME, configIntSetter, "Max age for objects without Last-modified."); + CONFIG_VARIABLE_SETTABLE(maxNoModifiedAge, CONFIG_TIME, configIntSetter, "Max age for objects without Last-modified."); CONFIG_VARIABLE_SETTABLE(dontCacheCookies, CONFIG_BOOLEAN, configIntSetter, "Work around cachable cookies."); } @@ -149,8 +146,7 @@ ObjectPtr findObject(int type, const void* key, int key_size) return retainObject(object); } -ObjectPtr makeObject( - int type, const void* key, int key_size, int public, int fromdisk, RequestFunction request, void* request_closure) +ObjectPtr makeObject(int type, const void* key, int key_size, int public, int fromdisk, RequestFunction request, void* request_closure) { ObjectPtr object; int h; @@ -447,9 +443,7 @@ int objectAddData(ObjectPtr object, const char* data, int offset, int len) { int rc; - do_log( - D_OBJECT_DATA, "Adding data to 0x%lx (%d) at %d: %d bytes\n", (unsigned long)object, object->length, offset, - len); + do_log(D_OBJECT_DATA, "Adding data to 0x%lx (%d) at %d: %d bytes\n", (unsigned long)object, object->length, offset, len); if (len == 0) return 1; diff --git a/polipo/object.h b/polipo/object.h index 158b8b09e1c95cf968e9645fc8dd7b7c93def4f4..9701795cc7ef8fa44ef271d5e2315f5a2c02fd07 100644 --- a/polipo/object.h +++ b/polipo/object.h @@ -164,13 +164,7 @@ void preinitObject(void); void initObject(void); ObjectPtr findObject(int type, const void* key, int key_size); ObjectPtr makeObject( - int type, - const void* key, - int key_size, - int public, - int fromdisk, - int (*request)(ObjectPtr, int, int, int, struct _HTTPRequest*, void*), - void*); + int type, const void* key, int key_size, int public, int fromdisk, int (*request)(ObjectPtr, int, int, int, struct _HTTPRequest*, void*), void*); void objectMetadataChanged(ObjectPtr object, int dirty); ObjectPtr retainObject(ObjectPtr); void releaseObject(ObjectPtr); diff --git a/polipo/server.c b/polipo/server.c index 43f7d6de571cb1bb03116687df8d0d8746403c3c..5b9c5d5ab4c39035fe8eeb593aaca06341b67461 100644 --- a/polipo/server.c +++ b/polipo/server.c @@ -56,8 +56,7 @@ void preinitServer(void) CONFIG_VARIABLE_SETTABLE(smallRequestTime, CONFIG_TIME, configIntSetter, "Estimated time for a small request."); CONFIG_VARIABLE_SETTABLE(replyUnpipelineTime, CONFIG_TIME, configIntSetter, "Estimated time for a pipeline break."); CONFIG_VARIABLE_SETTABLE(replyUnpipelineSize, CONFIG_INT, configIntSetter, "Size for a pipeline break."); - CONFIG_VARIABLE_SETTABLE( - pipelineAdditionalRequests, CONFIG_TRISTATE, configIntSetter, "Pipeline requests on an active connection."); + CONFIG_VARIABLE_SETTABLE(pipelineAdditionalRequests, CONFIG_TRISTATE, configIntSetter, "Pipeline requests on an active connection."); CONFIG_VARIABLE_SETTABLE( maxPipelineTrain, CONFIG_INT, configIntSetter, "Maximum number of requests " @@ -68,14 +67,10 @@ void preinitServer(void) CONFIG_VARIABLE(serverSlots1, CONFIG_INT, "Maximum number of connections per HTTP/1.0 server."); CONFIG_VARIABLE(serverMaxSlots, CONFIG_INT, "Maximum number of connections per broken server."); CONFIG_VARIABLE(dontCacheRedirects, CONFIG_BOOLEAN, "If true, don't cache redirects."); - CONFIG_VARIABLE_SETTABLE( - allowUnalignedRangeRequests, CONFIG_BOOLEAN, configIntSetter, "Allow unaligned range requests (unreliable)."); - CONFIG_VARIABLE_SETTABLE( - maxSideBuffering, CONFIG_INT, configIntSetter, "Maximum buffering for PUT and POST requests."); - CONFIG_VARIABLE_SETTABLE( - maxConnectionAge, CONFIG_TIME, configIntSetter, "Maximum age of a server-side connection."); - CONFIG_VARIABLE_SETTABLE( - maxConnectionRequests, CONFIG_INT, configIntSetter, "Maximum number of requests on a server-side connection."); + CONFIG_VARIABLE_SETTABLE(allowUnalignedRangeRequests, CONFIG_BOOLEAN, configIntSetter, "Allow unaligned range requests (unreliable)."); + CONFIG_VARIABLE_SETTABLE(maxSideBuffering, CONFIG_INT, configIntSetter, "Maximum buffering for PUT and POST requests."); + CONFIG_VARIABLE_SETTABLE(maxConnectionAge, CONFIG_TIME, configIntSetter, "Maximum age of a server-side connection."); + CONFIG_VARIABLE_SETTABLE(maxConnectionRequests, CONFIG_INT, configIntSetter, "Maximum number of requests on a server-side connection."); CONFIG_VARIABLE(alwaysAddNoTransform, CONFIG_BOOLEAN, "If true, add a no-transform directive to all requests."); } @@ -351,13 +346,11 @@ void httpServerAbortRequest(HTTPRequestPtr request, int fail, int code, AtomPtr void httpServerClientReset(HTTPRequestPtr request) { - if (request->connection && request->connection->fd >= 0 && !request->connection->connecting - && request->connection->request == request) + if (request->connection && request->connection->fd >= 0 && !request->connection->connecting && request->connection->request == request) pokeFdEvent(request->connection->fd, -ECLIENTRESET, POLLIN | POLLOUT); } -int httpMakeServerRequest( - char* name, int port, ObjectPtr object, int method, int from, int to, HTTPRequestPtr requestor) +int httpMakeServerRequest(char* name, int port, ObjectPtr object, int method, int from, int to, HTTPRequestPtr requestor) { HTTPServerPtr server; HTTPRequestPtr request; @@ -519,9 +512,7 @@ int httpServerConnectionDnsHandler(int status, GethostbynameRequestPtr request) connection->connecting = CONNECTING_CONNECT; httpSetTimeout(connection, serverTimeout); - do_connect( - retainAtom(request->addr), connection->server->addrindex, connection->server->port, httpServerConnectionHandler, - connection); + do_connect(retainAtom(request->addr), connection->server->addrindex, connection->server->port, httpServerConnectionHandler, connection); return 1; } @@ -559,11 +550,9 @@ int httpServerConnectionHandlerCommon(int status, HTTPConnectionPtr connection) httpSetTimeout(connection, -1); if (status < 0) { - AtomPtr message = - internAtomError(-status, "Connect to %s:%d failed", connection->server->name, connection->server->port); + AtomPtr message = internAtomError(-status, "Connect to %s:%d failed", connection->server->name, connection->server->port); if (status != -ECLIENTRESET) - do_log_error( - L_ERROR, -status, "Connect to %s:%d failed", scrub(connection->server->name), connection->server->port); + do_log_error(L_ERROR, -status, "Connect to %s:%d failed", scrub(connection->server->name), connection->server->port); connection->connecting = 0; if (connection->server->request) httpServerAbortRequest(connection->server->request, status != -ECLIENTRESET, 504, retainAtom(message)); @@ -587,8 +576,7 @@ int httpServerIdleHandler(int a, FdEventHandlerPtr event) assert(!connection->request); - do_log( - D_SERVER_CONN, "Idle connection to %s:%d died.\n", scrub(connection->server->name), connection->server->port); + do_log(D_SERVER_CONN, "Idle connection to %s:%d died.\n", scrub(connection->server->name), connection->server->port); for (i = 0; i < server->maxslots; i++) { if (connection == server->connection[i]) { @@ -634,8 +622,7 @@ static int pipelineIsSmall(HTTPConnectionPtr connection) return 0; if (request->method == METHOD_HEAD || request->method == METHOD_CONDITIONAL_GET) return 1; - if (request->to >= 0 && connection->server->rate > 0 - && request->to - request->from < connection->server->rate * smallRequestTime) + if (request->to >= 0 && connection->server->rate > 0 && request->to - request->from < connection->server->rate * smallRequestTime) return 1; return 0; } @@ -812,9 +799,8 @@ int httpServerTrigger(HTTPServerPtr server) if (server->connection[i]->serviced == 0) server->connection[i]->serviced = 1; if (!server->idleHandler[i]) - server->idleHandler[i] = registerFdEvent( - server->connection[i]->fd, POLLIN, httpServerIdleHandler, sizeof(HTTPConnectionPtr), - &server->connection[i]); + server->idleHandler[i] = + registerFdEvent(server->connection[i]->fd, POLLIN, httpServerIdleHandler, sizeof(HTTPConnectionPtr), &server->connection[i]); if (!server->idleHandler[i]) { do_log(L_ERROR, "Couldn't register idle handler.\n"); httpServerFinish(server->connection[i], 1, 0); @@ -901,9 +887,9 @@ int httpServerDoSide(HTTPConnectionPtr connection) HTTPRequestPtr requestor = request->request; HTTPConnectionPtr client = requestor->connection; int len = MIN(client->reqlen - client->reqbegin, connection->bodylen - connection->reqoffset); - int doflush = len > 0 - && (len >= maxSideBuffering || client->reqbegin > 0 - || (connection->reqoffset + client->reqlen - client->reqbegin) >= connection->bodylen); + int doflush = + len > 0 + && (len >= maxSideBuffering || client->reqbegin > 0 || (connection->reqoffset + client->reqlen - client->reqbegin) >= connection->bodylen); int done = connection->reqoffset >= connection->bodylen; assert(connection->bodylen >= 0); @@ -933,8 +919,7 @@ int httpServerDoSide(HTTPConnectionPtr connection) if (connection->reqbuf == NULL) connection->reqbuf = get_chunk(); assert(connection->reqbuf != NULL); - do_stream( - IO_WRITE, connection->fd, 0, client->reqbuf + client->reqbegin, len, httpServerSideHandler, connection); + do_stream(IO_WRITE, connection->fd, 0, client->reqbuf + client->reqbegin, len, httpServerSideHandler, connection); } else { if (connection->reqbuf) { httpConnectionDestroyReqbuf(connection); @@ -943,8 +928,7 @@ int httpServerDoSide(HTTPConnectionPtr connection) if (request->flags & REQUEST_WAIT_CONTINUE) { ConditionHandlerPtr chandler; do_log(D_SERVER_CONN, "W... %s:%d.\n", scrub(connection->server->name), connection->server->port); - chandler = conditionWait( - &request->object->condition, httpServerContinueConditionHandler, sizeof(connection), &connection); + chandler = conditionWait(&request->object->condition, httpServerContinueConditionHandler, sizeof(connection), &connection); if (chandler) return 1; else @@ -953,8 +937,7 @@ int httpServerDoSide(HTTPConnectionPtr connection) } client->flags |= CONN_SIDE_READER; do_stream( - IO_READ | (done ? IO_IMMEDIATE : 0) | IO_NOTNOW, client->fd, client->reqlen, client->reqbuf, CHUNK_SIZE, - httpClientSideHandler, client); + IO_READ | (done ? IO_IMMEDIATE : 0) | IO_NOTNOW, client->fd, client->reqlen, client->reqbuf, CHUNK_SIZE, httpClientSideHandler, client); } return 1; } @@ -1018,8 +1001,7 @@ static int httpServerSideHandlerCommon(int kind, int status, FdEventHandlerPtr e assert(client->reqbegin + bodylen <= client->reqlen); if (client->reqlen > client->reqbegin + bodylen) - memmove( - client->reqbuf, client->reqbuf + client->reqbegin + bodylen, client->reqlen - client->reqbegin - bodylen); + memmove(client->reqbuf, client->reqbuf + client->reqbegin + bodylen, client->reqlen - client->reqbegin - bodylen); client->reqlen -= bodylen + client->reqbegin; client->reqbegin = 0; connection->reqoffset += bodylen; @@ -1119,9 +1101,7 @@ void httpServerFinish(HTTPConnectionPtr connection, int s, int offset) httpDestroyRequest(request); } - do_log( - D_SERVER_CONN, "Done with server %s:%d connection (%d)\n", scrub(connection->server->name), - connection->server->port, s); + do_log(D_SERVER_CONN, "Done with server %s:%d connection (%d)\n", scrub(connection->server->name), connection->server->port, s); assert(offset <= connection->len); @@ -1253,8 +1233,8 @@ void httpServerReply(HTTPConnectionPtr connection, int immediate) httpSetTimeout(connection, serverTimeout); do_stream_buf( - IO_READ | (immediate ? IO_IMMEDIATE : 0) | IO_NOTNOW, connection->fd, connection->len, &connection->buf, - CHUNK_SIZE, httpServerReplyHandler, connection); + IO_READ | (immediate ? IO_IMMEDIATE : 0) | IO_NOTNOW, connection->fd, connection->len, &connection->buf, CHUNK_SIZE, httpServerReplyHandler, + connection); } int httpConnectionPipelined(HTTPConnectionPtr connection) @@ -1301,8 +1281,7 @@ void httpServerRestart(HTTPConnectionPtr connection) if (request) { HTTPRequestPtr req; if (request->next) - do_log( - L_WARN, "Restarting pipeline to %s:%d.\n", scrub(connection->server->name), connection->server->port); + do_log(L_WARN, "Restarting pipeline to %s:%d.\n", scrub(connection->server->name), connection->server->port); req = request; while (req) { req->connection = NULL; @@ -1478,9 +1457,7 @@ again: do_log_n(D_SERVER_REQ, url + x, y - x); do_log(D_SERVER_REQ, ": "); do_log_n(D_SERVER_REQ, connection->reqbuf, n); - do_log( - D_SERVER_REQ, " (method %d from %d to %d, 0x%lx for 0x%lx)\n", method, from, to, (unsigned long)connection, - (unsigned long)object); + do_log(D_SERVER_REQ, " (method %d from %d to %d, 0x%lx for 0x%lx)\n", method, from, to, (unsigned long)connection, (unsigned long)object); n = snnprintf(connection->reqbuf, n, bufsize, " HTTP/1.1"); @@ -1508,8 +1485,8 @@ again: } if (method == METHOD_GET && object->etag && (from > 0 || to >= 0)) { - if (request->request && request->request->request == request && request->request->from == 0 - && request->request->to == -1 && pmmSize == 0 && pmmFirstSize == 0) + if (request->request && request->request->request == request && request->request->from == 0 && request->request->to == -1 && pmmSize == 0 + && pmmFirstSize == 0) n = snnprintf(connection->reqbuf, n, bufsize, "\r\nIf-Range: \"%s\"", object->etag); } @@ -1523,28 +1500,22 @@ again: } } - n = httpPrintCacheControl( - connection->reqbuf, n, bufsize, alwaysAddNoTransform ? CACHE_NO_TRANSFORM : 0, &request->cache_control); + n = httpPrintCacheControl(connection->reqbuf, n, bufsize, alwaysAddNoTransform ? CACHE_NO_TRANSFORM : 0, &request->cache_control); if (n < 0) goto fail; if (request->request && request->request->headers) { - n = snnprint_n( - connection->reqbuf, n, bufsize, request->request->headers->string, request->request->headers->length); + n = snnprint_n(connection->reqbuf, n, bufsize, request->request->headers->string, request->request->headers->length); } if (!disableVia) { if (request->request && request->request->via) { - n = snnprintf( - connection->reqbuf, n, bufsize, "\r\nVia: %s, 1.1 %s", request->request->via->string, - proxyName->string); + n = snnprintf(connection->reqbuf, n, bufsize, "\r\nVia: %s, 1.1 %s", request->request->via->string, proxyName->string); } else { n = snnprintf(connection->reqbuf, n, bufsize, "\r\nVia: 1.1 %s", proxyName->string); } } - n = snnprintf( - connection->reqbuf, n, bufsize, "\r\nConnection: %s\r\n\r\n", - (request->flags & REQUEST_PERSISTENT) ? "keep-alive" : "close"); + n = snnprintf(connection->reqbuf, n, bufsize, "\r\nConnection: %s\r\n\r\n", (request->flags & REQUEST_PERSISTENT) ? "keep-alive" : "close"); if (n < 0 || n >= bufsize - 1) goto fail; connection->reqlen = n; @@ -1648,8 +1619,7 @@ int httpServerReplyHandler(int status, FdEventHandlerPtr event, StreamRequestPtr } if (status < 0) { do_log(L_ERROR, "Error reading server headers: %d\n", -status); - httpServerAbort( - connection, status != -ECLIENTRESET, 502, internAtomError(-status, "Error reading server headers")); + httpServerAbort(connection, status != -ECLIENTRESET, 502, internAtomError(-status, "Error reading server headers")); } else httpServerAbort(connection, 1, 502, internAtom("Server dropped connection")); return 1; @@ -1672,9 +1642,7 @@ int httpServerReplyHandler(int status, FdEventHandlerPtr event, StreamRequestPtr return 1; } /* Can't just return 0 -- buf has moved. */ - do_stream( - IO_READ, connection->fd, connection->len, connection->buf, bigBufferSize, httpServerReplyHandler, - connection); + do_stream(IO_READ, connection->fd, connection->len, connection->buf, bigBufferSize, httpServerReplyHandler, connection); return 1; } @@ -1739,8 +1707,8 @@ int httpServerHandlerHeaders(int eof, FdEventHandlerPtr event, StreamRequestPtr url = internAtomN(object->key, object->key_size); rc = httpParseHeaders( - 0, url, connection->buf, rc, request, &headers, &len, &cache_control, NULL, &te, &date, &last_modified, - &expires, NULL, NULL, NULL, &age, &etag, NULL, NULL, &content_range, NULL, &via, NULL); + 0, url, connection->buf, rc, request, &headers, &len, &cache_control, NULL, &te, &date, &last_modified, &expires, NULL, NULL, NULL, &age, + &etag, NULL, NULL, &content_range, NULL, &via, NULL); if (rc < 0) { do_log(L_ERROR, "Couldn't parse server headers\n"); releaseAtom(url); @@ -1834,8 +1802,8 @@ int httpServerHandlerHeaders(int eof, FdEventHandlerPtr event, StreamRequestPtr /* Okay, we're going to accept this reply. */ if ((code == 200 || code == 206 || code == 304 || code == 412) - && (cache_control.flags & (CACHE_NO | CACHE_NO_STORE) || cache_control.max_age == 0 - || (cacheIsShared && cache_control.s_maxage == 0) || (expires >= 0 && expires <= object->age))) { + && (cache_control.flags & (CACHE_NO | CACHE_NO_STORE) || cache_control.max_age == 0 || (cacheIsShared && cache_control.s_maxage == 0) + || (expires >= 0 && expires <= object->age))) { do_log(L_UNCACHEABLE, "Uncacheable object %s (%d)\n", scrub(object->key), cache_control.flags); } @@ -1865,9 +1833,7 @@ int httpServerHandlerHeaders(int eof, FdEventHandlerPtr event, StreamRequestPtr if (code == 304 || code == 412) { if ((object->etag && etag && strcmp(object->etag, etag) != 0) || (object->last_modified >= 0 && last_modified >= 0 && object->last_modified != last_modified)) { - do_log( - L_ERROR, "Inconsistent \"%s\" reply for %s\n", code == 304 ? "not changed" : "precondition failed", - scrub(object->key)); + do_log(L_ERROR, "Inconsistent \"%s\" reply for %s\n", code == 304 ? "not changed" : "precondition failed", scrub(object->key)); object->flags |= OBJECT_DYNAMIC; supersede = 1; } @@ -1888,8 +1854,7 @@ int httpServerHandlerHeaders(int eof, FdEventHandlerPtr event, StreamRequestPtr if (!supersede && (object->cache_control & CACHE_VARY) && dontTrustVaryETag >= 1) { /* Check content-type to work around mod_gzip bugs */ - if (!httpHeaderMatch(atomContentType, object->headers, headers) - || !httpHeaderMatch(atomContentEncoding, object->headers, headers)) + if (!httpHeaderMatch(atomContentType, object->headers, headers) || !httpHeaderMatch(atomContentEncoding, object->headers, headers)) supersede = 1; } @@ -1928,9 +1893,8 @@ int httpServerHandlerHeaders(int eof, FdEventHandlerPtr event, StreamRequestPtr if (supersede) { do_log( - L_SUPERSEDED, "Superseding object %s (%d %d %d %s -> %d %d %d %s)\n", scrub(old_object->key), object->code, - object->length, (int)object->last_modified, object->etag ? object->etag : "(none)", code, full_len, - (int)last_modified, etag ? etag : "(none)"); + L_SUPERSEDED, "Superseding object %s (%d %d %d %s -> %d %d %d %s)\n", scrub(old_object->key), object->code, object->length, + (int)object->last_modified, object->etag ? object->etag : "(none)", code, full_len, (int)last_modified, etag ? etag : "(none)"); privatiseObject(old_object, 0); new_object = makeObject(object->type, object->key, object->key_size, 1, 0, object->request, NULL); if (new_object == NULL) { @@ -1945,12 +1909,9 @@ int httpServerHandlerHeaders(int eof, FdEventHandlerPtr event, StreamRequestPtr } suspectDynamic = - (!etag && last_modified < 0) - || (cache_control.flags & (CACHE_NO_HIDDEN | CACHE_NO | CACHE_NO_STORE | (cacheIsShared ? CACHE_PRIVATE : 0))) - || (cache_control.max_age >= 0 && cache_control.max_age <= 2) - || (cacheIsShared && cache_control.s_maxage >= 0 && cache_control.s_maxage <= 5) - || (old_object->last_modified >= 0 && old_object->expires >= 0 - && (old_object->expires - old_object->last_modified <= 1)) + (!etag && last_modified < 0) || (cache_control.flags & (CACHE_NO_HIDDEN | CACHE_NO | CACHE_NO_STORE | (cacheIsShared ? CACHE_PRIVATE : 0))) + || (cache_control.max_age >= 0 && cache_control.max_age <= 2) || (cacheIsShared && cache_control.s_maxage >= 0 && cache_control.s_maxage <= 5) + || (old_object->last_modified >= 0 && old_object->expires >= 0 && (old_object->expires - old_object->last_modified <= 1)) || (supersede && (old_object->date - date <= 5)); if (suspectDynamic) @@ -2115,9 +2076,7 @@ int httpServerHandlerHeaders(int eof, FdEventHandlerPtr event, StreamRequestPtr if (content_range.to >= 0) request->to = content_range.to; - do_log( - D_SERVER_OFFSET, "0x%lx(0x%lx): offset = %d\n", (unsigned long)connection, (unsigned long)object, - connection->offset); + do_log(D_SERVER_OFFSET, "0x%lx(0x%lx): offset = %d\n", (unsigned long)connection, (unsigned long)object, connection->offset); if (connection->len > rc) { rc = connectionAddData(connection, rc); @@ -2289,8 +2248,7 @@ int httpServerReadData(HTTPConnectionPtr connection, int immediate) } if (connection->len == 0 - && ((connection->te == TE_IDENTITY && to > connection->offset) - || (connection->te == TE_CHUNKED && connection->chunk_remaining > 0))) { + && ((connection->te == TE_IDENTITY && to > connection->offset) || (connection->te == TE_CHUNKED && connection->chunk_remaining > 0))) { /* Read directly into the object */ int i = connection->offset / CHUNK_SIZE; int j = connection->offset % CHUNK_SIZE; @@ -2334,9 +2292,9 @@ int httpServerReadData(HTTPConnectionPtr connection, int immediate) } if (object->chunks[i + 1].data) { do_stream_3( - IO_READ | IO_NOTNOW, connection->fd, j, object->chunks[i].data, CHUNK_SIZE, - object->chunks[i + 1].data, MIN(CHUNK_SIZE, end - (i + 1) * CHUNK_SIZE), connection->buf, - connection->buf ? more : 0, httpServerDirectHandler2, connection); + IO_READ | IO_NOTNOW, connection->fd, j, object->chunks[i].data, CHUNK_SIZE, object->chunks[i + 1].data, + MIN(CHUNK_SIZE, end - (i + 1) * CHUNK_SIZE), connection->buf, connection->buf ? more : 0, httpServerDirectHandler2, + connection); return 1; } unlockChunk(object, i + 1); @@ -2346,8 +2304,8 @@ int httpServerReadData(HTTPConnectionPtr connection, int immediate) connection->buf = get_chunk(); } do_stream_2( - IO_READ | IO_NOTNOW, connection->fd, j, object->chunks[i].data, MIN(CHUNK_SIZE, end - i * CHUNK_SIZE), - connection->buf, connection->buf ? more : 0, httpServerDirectHandler, connection); + IO_READ | IO_NOTNOW, connection->fd, j, object->chunks[i].data, MIN(CHUNK_SIZE, end - i * CHUNK_SIZE), connection->buf, + connection->buf ? more : 0, httpServerDirectHandler, connection); return 1; } else { unlockChunk(object, i); @@ -2359,9 +2317,8 @@ int httpServerReadData(HTTPConnectionPtr connection, int immediate) httpSetTimeout(connection, serverTimeout); do_stream_buf( - IO_READ | IO_NOTNOW | ((immediate && connection->len) ? IO_IMMEDIATE : 0), connection->fd, connection->len, - &connection->buf, (connection->te == TE_CHUNKED ? MIN(2048, CHUNK_SIZE) : CHUNK_SIZE), - httpServerIndirectHandler, connection); + IO_READ | IO_NOTNOW | ((immediate && connection->len) ? IO_IMMEDIATE : 0), connection->fd, connection->len, &connection->buf, + (connection->te == TE_CHUNKED ? MIN(2048, CHUNK_SIZE) : CHUNK_SIZE), httpServerIndirectHandler, connection); return 1; } @@ -2471,17 +2428,14 @@ int connectionAddData(HTTPConnectionPtr connection, int skip) return -1; connection->offset += len; connection->len -= (len + skip); - do_log( - D_SERVER_OFFSET, "0x%lx(0x%lx): offset = %d\n", (unsigned long)connection, (unsigned long)object, - connection->offset); + do_log(D_SERVER_OFFSET, "0x%lx(0x%lx): offset = %d\n", (unsigned long)connection, (unsigned long)object, connection->offset); } if (connection->len > 0 && skip + len > 0) { memmove(connection->buf, connection->buf + skip + len, connection->len); } - if ((object->length >= 0 && object->length <= connection->offset) - || (request->to >= 0 && request->to <= connection->offset)) { + if ((object->length >= 0 && object->length <= connection->offset) || (request->to >= 0 && request->to <= connection->offset)) { notifyObject(object); return 1; } else { @@ -2531,9 +2485,7 @@ int connectionAddData(HTTPConnectionPtr connection, int skip) return -1; i += size; connection->chunk_remaining -= size; - do_log( - D_SERVER_OFFSET, "0x%lx(0x%lx): offset = %d\n", (unsigned long)connection, - (unsigned long)object, connection->offset); + do_log(D_SERVER_OFFSET, "0x%lx(0x%lx): offset = %d\n", (unsigned long)connection, (unsigned long)object, connection->offset); } } } diff --git a/polipo/server.h b/polipo/server.h index dd0521d517dbbfe818fb8c68d562322efee33191..f005717347fe3e10348ce0f547de4e839f5a60f7 100644 --- a/polipo/server.h +++ b/polipo/server.h @@ -49,8 +49,7 @@ void preinitServer(void); void initServer(void); void httpServerAbortHandler(ObjectPtr object); -int httpMakeServerRequest( - char* name, int port, ObjectPtr object, int method, int from, int to, HTTPRequestPtr requestor); +int httpMakeServerRequest(char* name, int port, ObjectPtr object, int method, int from, int to, HTTPRequestPtr requestor); int httpServerQueueRequest(HTTPServerPtr server, HTTPRequestPtr request); int httpServerTrigger(HTTPServerPtr server); int httpServerSideRequest(HTTPServerPtr server); diff --git a/polipo/socks.c b/polipo/socks.c index 3ef58574fa2be3c29e4e1f5643c4516657708dde..34a4b3de7eba1e7ffa41b639a8694f6992352022 100644 --- a/polipo/socks.c +++ b/polipo/socks.c @@ -86,10 +86,8 @@ void preinitSocks() socksUserName = internAtom(""); socksPassWord = internAtom(""); - CONFIG_VARIABLE_SETTABLE( - socksParentProxy, CONFIG_ATOM_LOWER, socksParentProxySetter, "SOCKS parent proxy (host:port)"); - CONFIG_VARIABLE_SETTABLE( - socksAuthCredentials, CONFIG_PASSWORD, configAtomSetter, "SOCKS4a (or SOCKS5) credentials username:password"); + CONFIG_VARIABLE_SETTABLE(socksParentProxy, CONFIG_ATOM_LOWER, socksParentProxySetter, "SOCKS parent proxy (host:port)"); + CONFIG_VARIABLE_SETTABLE(socksAuthCredentials, CONFIG_PASSWORD, configAtomSetter, "SOCKS4a (or SOCKS5) credentials username:password"); CONFIG_VARIABLE_SETTABLE(socksProxyType, CONFIG_ATOM_LOWER, socksProxyTypeSetter, "One of socks4a or socks5"); // infer username and password from credentials @@ -284,9 +282,7 @@ static int socksConnectHandler(int status, FdEventHandlerPtr event, ConnectReque memcpy(request->buf + 8 + socksUserName->length + 1, request->name->string, request->name->length); request->buf[8 + socksUserName->length + 1 + request->name->length] = '\0'; - do_stream( - IO_WRITE, request->fd, 0, request->buf, 8 + socksUserName->length + 1 + request->name->length + 1, - socksWriteHandler, request); + do_stream(IO_WRITE, request->fd, 0, request->buf, 8 + socksUserName->length + 1 + request->name->length + 1, socksWriteHandler, request); } else if (socksProxyType == aSocks5) { request->buf = malloc(8); /* 8 needed for the subsequent read */ if (request->buf == NULL) { @@ -412,9 +408,7 @@ static int socks5ReadHandlerAuth(int status, FdEventHandlerPtr event, StreamRequ request->buf[2 + socksUserName->length] = socksPassWord->length; /* password length */ memcpy(request->buf + 3 + socksUserName->length, socksPassWord->string, socksPassWord->length); - do_stream( - IO_WRITE, request->fd, 0, request->buf, 3 + socksUserName->length + socksPassWord->length, socks5WriteHandler, - request); + do_stream(IO_WRITE, request->fd, 0, request->buf, 3 + socksUserName->length + socksPassWord->length, socks5WriteHandler, request); return 1; error: @@ -490,8 +484,8 @@ static int socks5WriteHandler(int status, FdEventHandlerPtr event, StreamRequest } do_stream( - IO_READ | IO_NOTNOW, request->fd, 0, request->buf, 10, - ((socksPassWord != NULL) && (authed == -1) ? socks5ReadHandler : socks5ReadHandler2), request); + IO_READ | IO_NOTNOW, request->fd, 0, request->buf, 10, ((socksPassWord != NULL) && (authed == -1) ? socks5ReadHandler : socks5ReadHandler2), + request); return 1; error: diff --git a/polipo/tunnel.c b/polipo/tunnel.c index 943df816aa7d8221b8ca877cb2c7d876a3962aab..5d00352492fa113de03f31c01bf74efe173e9d15 100644 --- a/polipo/tunnel.c +++ b/polipo/tunnel.c @@ -176,8 +176,7 @@ void do_tunnel(int fd, char* buf, int offset, int len, AtomPtr url) if (socksParentProxy) do_socks_connect( - parentHost ? parentHost->string : tunnel->hostname->string, parentHost ? parentPort : tunnel->port, - tunnelSocksHandler, tunnel); + parentHost ? parentHost->string : tunnel->hostname->string, parentHost ? parentPort : tunnel->port, tunnelSocksHandler, tunnel); else do_gethostbyname(parentHost ? parentHost->string : tunnel->hostname->string, 0, tunnelDnsHandler, tunnel); } @@ -247,9 +246,7 @@ static int tunnelHandlerParent(int fd, TunnelPtr tunnel) goto fail; } - n = snnprintf( - tunnel->buf1.buf, tunnel->buf1.tail, CHUNK_SIZE, "CONNECT %s:%d HTTP/1.1", tunnel->hostname->string, - tunnel->port); + n = snnprintf(tunnel->buf1.buf, tunnel->buf1.tail, CHUNK_SIZE, "CONNECT %s:%d HTTP/1.1", tunnel->hostname->string, tunnel->port); if (parentAuthCredentials) n = buildServerAuthHeaders(tunnel->buf1.buf, n, CHUNK_SIZE, parentAuthCredentials); n = snnprintf(tunnel->buf1.buf, n, CHUNK_SIZE, "\r\n\r\n"); @@ -310,8 +307,7 @@ static void bufRead(int fd, CircularBufferPtr buf, int (*handler)(int, FdEventHa do_stream_2(IO_READ | IO_NOTNOW, fd, buf->head, buf->buf, CHUNK_SIZE, buf->buf, tail, handler, data); } -static void - bufWrite(int fd, CircularBufferPtr buf, int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), void* data) +static void bufWrite(int fd, CircularBufferPtr buf, int (*handler)(int, FdEventHandlerPtr, StreamRequestPtr), void* data) { if (buf->head > buf->tail) do_stream(IO_WRITE, fd, buf->tail, buf->buf, buf->head, handler, data); diff --git a/stdcrt/algorithm/compat_aes.c b/stdcrt/algorithm/compat_aes.c index 3a3f62d7eb48db0423785a3f261268975b986e49..dd6d9ba7ea799a8219c3cce98fa07afa80943a73 100644 --- a/stdcrt/algorithm/compat_aes.c +++ b/stdcrt/algorithm/compat_aes.c @@ -24,270 +24,227 @@ Td4[x] = Si[x].[01]; } static const aes_u32 Te0[aes_e_len] = { - 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, 0x60303050U, - 0x02010103U, 0xce6767a9U, 0x562b2b7dU, 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU, 0x8fcaca45U, 0x1f82829dU, - 0x89c9c940U, 0xfa7d7d87U, 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU, 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, - 0x45afafeaU, 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU, 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU, - 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU, 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U, 0xe2717193U, - 0xabd8d873U, 0x62313153U, 0x2a15153fU, 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU, 0x30181828U, 0x379696a1U, - 0x0a05050fU, 0x2f9a9ab5U, 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU, 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, - 0xea75759fU, 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU, 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU, - 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU, 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U, 0xa65353f5U, - 0xb9d1d168U, 0x00000000U, 0xc1eded2cU, 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU, 0xd46a6abeU, 0x8dcbcb46U, - 0x67bebed9U, 0x7239394bU, 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU, 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, - 0xedfbfb16U, 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U, 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U, - 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U, 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU, 0x3f9292adU, - 0x219d9dbcU, 0x70383848U, 0xf1f5f504U, 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U, 0x20101030U, 0xe5ffff1aU, - 0xfdf3f30eU, 0xbfd2d26dU, 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU, 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, - 0x2e171739U, 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U, 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U, - 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU, 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U, 0x8c4646caU, - 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU, 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U, 0xdbe0e03bU, 0x64323256U, - 0x743a3a4eU, 0x140a0a1eU, 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U, 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, - 0xc46262a6U, 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU, 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U, - 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U, 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U, 0xca6565afU, - 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U, 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U, 0x381c1c24U, 0x57a6a6f1U, - 0x73b4b4c7U, 0x97c6c651U, 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U, 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, - 0x0f8a8a85U, 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU, 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U, - 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U, 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U, 0xd9e1e138U, - 0xebf8f813U, 0x2b9898b3U, 0x22111133U, 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U, 0x2d9b9bb6U, 0x3c1e1e22U, - 0x15878792U, 0xc9e9e920U, 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU, 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, - 0x1a0d0d17U, 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U, 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, - 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, + 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, 0x60303050U, 0x02010103U, 0xce6767a9U, + 0x562b2b7dU, 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU, 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U, 0xeffafa15U, 0xb25959ebU, + 0x8e4747c9U, 0xfbf0f00bU, 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU, 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU, 0x75b7b7c2U, + 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU, 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU, 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U, + 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU, 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU, 0x30181828U, 0x379696a1U, 0x0a05050fU, + 0x2f9a9ab5U, 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU, 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU, 0x1209091bU, 0x1d83839eU, + 0x582c2c74U, 0x341a1a2eU, 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU, 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU, 0x5229297bU, + 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U, 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU, 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU, + 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU, 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU, 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, + 0xedfbfb16U, 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U, 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U, 0xa05050f0U, 0x783c3c44U, + 0x259f9fbaU, 0x4ba8a8e3U, 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU, 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U, 0x63bcbcdfU, + 0x77b6b6c1U, 0xafdada75U, 0x42212163U, 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU, 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU, + 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U, 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U, 0xc86464acU, 0xba5d5de7U, 0x3219192bU, + 0xe6737395U, 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU, 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U, 0x8c4646caU, 0xc7eeee29U, + 0x6bb8b8d3U, 0x2814143cU, 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U, 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU, 0x924949dbU, + 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U, 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U, 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU, + 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U, 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U, 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, + 0xcfeaea25U, 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U, 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U, 0x381c1c24U, 0x57a6a6f1U, + 0x73b4b4c7U, 0x97c6c651U, 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U, 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U, 0xe0707090U, + 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU, 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U, 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U, + 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U, 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U, 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, + 0x339494a7U, 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U, 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU, 0x038c8c8fU, 0x59a1a1f8U, + 0x09898980U, 0x1a0d0d17U, 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U, 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, 0x7bb0b0cbU, + 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, }; static const aes_u32 Te1[aes_e_len] = { - 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, 0x50603030U, - 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U, 0x458fcacaU, 0x9d1f8282U, - 0x4089c9c9U, 0x87fa7d7dU, 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U, 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, - 0xea45afafU, 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U, 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U, - 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU, 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U, 0x93e27171U, - 0x73abd8d8U, 0x53623131U, 0x3f2a1515U, 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U, 0x28301818U, 0xa1379696U, - 0x0f0a0505U, 0xb52f9a9aU, 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U, 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, - 0x9fea7575U, 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU, 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U, - 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U, 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U, 0xf5a65353U, - 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU, 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU, 0xbed46a6aU, 0x468dcbcbU, - 0xd967bebeU, 0x4b723939U, 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU, 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, - 0x16edfbfbU, 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U, 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU, - 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U, 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU, 0xad3f9292U, - 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U, 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U, 0x30201010U, 0x1ae5ffffU, - 0x0efdf3f3U, 0x6dbfd2d2U, 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU, 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, - 0x392e1717U, 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU, 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U, - 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU, 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U, 0xca8c4646U, - 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U, 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU, 0x3bdbe0e0U, 0x56643232U, - 0x4e743a3aU, 0x1e140a0aU, 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU, 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, - 0xa6c46262U, 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U, 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU, - 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U, 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU, 0xafca6565U, - 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U, 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU, 0x24381c1cU, 0xf157a6a6U, - 0xc773b4b4U, 0x5197c6c6U, 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU, 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, - 0x850f8a8aU, 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U, 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU, - 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U, 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU, 0x38d9e1e1U, - 0x13ebf8f8U, 0xb32b9898U, 0x33221111U, 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U, 0xb62d9b9bU, 0x223c1e1eU, - 0x92158787U, 0x20c9e9e9U, 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU, 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, - 0x171a0d0dU, 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U, 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, - 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, + 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, 0x50603030U, 0x03020101U, 0xa9ce6767U, + 0x7d562b2bU, 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U, 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU, 0x15effafaU, 0xebb25959U, + 0xc98e4747U, 0x0bfbf0f0U, 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU, 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U, 0xc275b7b7U, + 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U, 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU, 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U, + 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U, 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U, 0x28301818U, 0xa1379696U, 0x0f0a0505U, + 0xb52f9a9aU, 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U, 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U, 0x1b120909U, 0x9e1d8383U, + 0x74582c2cU, 0x2e341a1aU, 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U, 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U, 0x7b522929U, + 0x3edde3e3U, 0x715e2f2fU, 0x97138484U, 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU, 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU, + 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U, 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU, 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, + 0x16edfbfbU, 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U, 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU, 0xf0a05050U, 0x44783c3cU, + 0xba259f9fU, 0xe34ba8a8U, 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU, 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U, 0xdf63bcbcU, + 0xc177b6b6U, 0x75afdadaU, 0x63422121U, 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U, 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU, + 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U, 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU, 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, + 0x95e67373U, 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU, 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U, 0xca8c4646U, 0x29c7eeeeU, + 0xd36bb8b8U, 0x3c281414U, 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU, 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU, 0xdb924949U, + 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU, 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U, 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U, + 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU, 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U, 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, + 0x25cfeaeaU, 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U, 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU, 0x24381c1cU, 0xf157a6a6U, + 0xc773b4b4U, 0x5197c6c6U, 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU, 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU, 0x90e07070U, + 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U, 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU, 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U, + 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU, 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U, 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, + 0xa7339494U, 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U, 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU, 0x8f038c8cU, 0xf859a1a1U, + 0x80098989U, 0x171a0d0dU, 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U, 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, 0xcb7bb0b0U, + 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, }; static const aes_u32 Te2[aes_e_len] = { - 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, 0x30506030U, - 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U, 0xca458fcaU, 0x829d1f82U, - 0xc94089c9U, 0x7d87fa7dU, 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U, 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, - 0xafea45afU, 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U, 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U, - 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU, 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U, 0x7193e271U, - 0xd873abd8U, 0x31536231U, 0x153f2a15U, 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U, 0x18283018U, 0x96a13796U, - 0x050f0a05U, 0x9ab52f9aU, 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U, 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, - 0x759fea75U, 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU, 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U, - 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U, 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U, 0x53f5a653U, - 0xd168b9d1U, 0x00000000U, 0xed2cc1edU, 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU, 0x6abed46aU, 0xcb468dcbU, - 0xbed967beU, 0x394b7239U, 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU, 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, - 0xfb16edfbU, 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U, 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU, - 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U, 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU, 0x92ad3f92U, - 0x9dbc219dU, 0x38487038U, 0xf504f1f5U, 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U, 0x10302010U, 0xff1ae5ffU, - 0xf30efdf3U, 0xd26dbfd2U, 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU, 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, - 0x17392e17U, 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU, 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U, - 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU, 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U, 0x46ca8c46U, - 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U, 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU, 0xe03bdbe0U, 0x32566432U, - 0x3a4e743aU, 0x0a1e140aU, 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU, 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, - 0x62a6c462U, 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U, 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU, - 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U, 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU, 0x65afca65U, - 0x7a8ef47aU, 0xaee947aeU, 0x08181008U, 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU, 0x1c24381cU, 0xa6f157a6U, - 0xb4c773b4U, 0xc65197c6U, 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU, 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, - 0x8a850f8aU, 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U, 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU, - 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U, 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU, 0xe138d9e1U, - 0xf813ebf8U, 0x98b32b98U, 0x11332211U, 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U, 0x9bb62d9bU, 0x1e223c1eU, - 0x87921587U, 0xe920c9e9U, 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU, 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, - 0x0d171a0dU, 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U, 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, - 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, + 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, 0x30506030U, 0x01030201U, 0x67a9ce67U, + 0x2b7d562bU, 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U, 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU, 0xfa15effaU, 0x59ebb259U, + 0x47c98e47U, 0xf00bfbf0U, 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU, 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U, 0xb7c275b7U, + 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U, 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU, 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U, + 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U, 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U, 0x18283018U, 0x96a13796U, 0x050f0a05U, + 0x9ab52f9aU, 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U, 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U, 0x091b1209U, 0x839e1d83U, + 0x2c74582cU, 0x1a2e341aU, 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U, 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U, 0x297b5229U, + 0xe33edde3U, 0x2f715e2fU, 0x84971384U, 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU, 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU, + 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U, 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU, 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, + 0xfb16edfbU, 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U, 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU, 0x50f0a050U, 0x3c44783cU, + 0x9fba259fU, 0xa8e34ba8U, 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU, 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U, 0xbcdf63bcU, + 0xb6c177b6U, 0xda75afdaU, 0x21634221U, 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U, 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU, + 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U, 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU, 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, + 0x7395e673U, 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU, 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U, 0x46ca8c46U, 0xee29c7eeU, + 0xb8d36bb8U, 0x143c2814U, 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU, 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU, 0x49db9249U, + 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU, 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U, 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U, + 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU, 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U, 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, + 0xea25cfeaU, 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U, 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU, 0x1c24381cU, 0xa6f157a6U, + 0xb4c773b4U, 0xc65197c6U, 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU, 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU, 0x7090e070U, + 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U, 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU, 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U, + 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU, 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U, 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, + 0x94a73394U, 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U, 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU, 0x8c8f038cU, 0xa1f859a1U, + 0x89800989U, 0x0d171a0dU, 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U, 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, 0xb0cb7bb0U, + 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, }; static const aes_u32 Te3[aes_e_len] = { - 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, 0x30305060U, - 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU, 0xcaca458fU, 0x82829d1fU, - 0xc9c94089U, 0x7d7d87faU, 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU, 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, - 0xafafea45U, 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU, 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU, - 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U, 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U, 0x717193e2U, - 0xd8d873abU, 0x31315362U, 0x15153f2aU, 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU, 0x18182830U, 0x9696a137U, - 0x05050f0aU, 0x9a9ab52fU, 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU, 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, - 0x75759feaU, 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U, 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU, - 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU, 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U, 0x5353f5a6U, - 0xd1d168b9U, 0x00000000U, 0xeded2cc1U, 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U, 0x6a6abed4U, 0xcbcb468dU, - 0xbebed967U, 0x39394b72U, 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U, 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, - 0xfbfb16edU, 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U, 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU, - 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU, 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U, 0x9292ad3fU, - 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U, 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U, 0x10103020U, 0xffff1ae5U, - 0xf3f30efdU, 0xd2d26dbfU, 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U, 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, - 0x1717392eU, 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU, 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U, - 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U, 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU, 0x4646ca8cU, - 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U, 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU, 0xe0e03bdbU, 0x32325664U, - 0x3a3a4e74U, 0x0a0a1e14U, 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U, 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, - 0x6262a6c4U, 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U, 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU, - 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U, 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU, 0x6565afcaU, - 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U, 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU, 0x1c1c2438U, 0xa6a6f157U, - 0xb4b4c773U, 0xc6c65197U, 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU, 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, - 0x8a8a850fU, 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU, 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU, - 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U, 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U, 0xe1e138d9U, - 0xf8f813ebU, 0x9898b32bU, 0x11113322U, 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U, 0x9b9bb62dU, 0x1e1e223cU, - 0x87879215U, 0xe9e920c9U, 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U, 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, - 0x0d0d171aU, 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U, 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, - 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, + 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, 0x30305060U, 0x01010302U, 0x6767a9ceU, + 0x2b2b7d56U, 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU, 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU, 0xfafa15efU, 0x5959ebb2U, + 0x4747c98eU, 0xf0f00bfbU, 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U, 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU, 0xb7b7c275U, + 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU, 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U, 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U, + 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU, 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU, 0x18182830U, 0x9696a137U, 0x05050f0aU, + 0x9a9ab52fU, 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU, 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU, 0x09091b12U, 0x83839e1dU, + 0x2c2c7458U, 0x1a1a2e34U, 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU, 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU, 0x29297b52U, + 0xe3e33eddU, 0x2f2f715eU, 0x84849713U, 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U, 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U, + 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U, 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U, 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, + 0xfbfb16edU, 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U, 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU, 0x5050f0a0U, 0x3c3c4478U, + 0x9f9fba25U, 0xa8a8e34bU, 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U, 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U, 0xbcbcdf63U, + 0xb6b6c177U, 0xdada75afU, 0x21216342U, 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU, 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U, + 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU, 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU, 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, + 0x737395e6U, 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U, 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU, 0x4646ca8cU, 0xeeee29c7U, + 0xb8b8d36bU, 0x14143c28U, 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU, 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U, 0x4949db92U, + 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U, 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U, 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U, + 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU, 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U, 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, + 0xeaea25cfU, 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U, 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU, 0x1c1c2438U, 0xa6a6f157U, + 0xb4b4c773U, 0xc6c65197U, 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU, 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU, 0x707090e0U, + 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU, 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU, 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U, + 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U, 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U, 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, + 0x9494a733U, 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U, 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U, 0x8c8c8f03U, 0xa1a1f859U, + 0x89898009U, 0x0d0d171aU, 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U, 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, 0xb0b0cb7bU, + 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, }; static const aes_u32 Td0[aes_d_len] = { - 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, 0x2030fa55U, - 0xad766df6U, 0x88cc7691U, 0xf5024c25U, 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU, 0xdeb15a49U, 0x25ba1b67U, - 0x45ea0e98U, 0x5dfec0e1U, 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U, 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, - 0x955259daU, 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U, 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU, - 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U, 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U, 0xb16477e0U, - 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U, 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U, 0xab73d323U, 0x724b02e2U, - 0xe31f8f57U, 0x6655ab2aU, 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U, 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, - 0xed16825cU, 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U, 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU, - 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U, 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U, 0x3e218af9U, - 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U, 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU, 0x1998fb24U, 0xd6bde997U, - 0x894043ccU, 0x67d99e77U, 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU, 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, - 0x00000000U, 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU, 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U, - 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU, 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU, 0x80c0c54fU, - 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U, 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU, 0x0e090d0bU, 0xf28bc7adU, - 0x2db6a8b9U, 0x141ea9c8U, 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU, 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, - 0x5bfb7e34U, 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U, 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U, - 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU, 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U, 0x2bb3166cU, - 0xa970b999U, 0x119448faU, 0x47e96422U, 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU, 0x87494ec7U, 0xd938d1c1U, - 0x8ccaa2feU, 0x98d40b36U, 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U, 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, - 0x547e4662U, 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U, 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U, - 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU, 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U, 0xe6956e65U, - 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U, 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U, 0x31a4b2afU, 0x2a3f2331U, - 0xc6a59430U, 0x35a266c0U, 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U, 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, - 0x1791f62fU, 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU, 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU, - 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU, 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U, 0x9ad7618cU, - 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U, 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU, 0x9cd2df59U, 0x55f2733fU, - 0x1814ce79U, 0x73c737bfU, 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U, 0xcaaff381U, 0xb968c43eU, 0x3824342cU, - 0xc2a3405fU, 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U, 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, - 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, + 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, 0x2030fa55U, 0xad766df6U, 0x88cc7691U, + 0xf5024c25U, 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU, 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U, 0xc32f7502U, 0x814cf012U, + 0x8d4697a3U, 0x6bd3f9c6U, 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU, 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U, 0x75c2896aU, + 0xf48e7978U, 0x99583e6bU, 0x27b971ddU, 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U, 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U, + 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U, 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U, 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, + 0x6655ab2aU, 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U, 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU, 0x8acf1c2bU, 0xa779b492U, + 0xf307f2f0U, 0x4e69e2a1U, 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU, 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U, 0x0b83ec39U, + 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U, 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U, 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU, + 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U, 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU, 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, + 0x00000000U, 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU, 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U, 0x0a0fd964U, 0x685ca621U, + 0x9b5b54d1U, 0x24362e3aU, 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU, 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U, 0xe293ba0aU, + 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU, 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U, 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU, + 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U, 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U, 0xd731dccaU, 0x42638510U, 0x13972240U, + 0x84c61120U, 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU, 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U, 0x2bb3166cU, 0xa970b999U, + 0x119448faU, 0x47e96422U, 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU, 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U, 0xa6f581cfU, + 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U, 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U, 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U, + 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U, 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU, 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, + 0x834f9aa8U, 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U, 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U, 0x31a4b2afU, 0x2a3f2331U, + 0xc6a59430U, 0x35a266c0U, 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U, 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU, 0x764dd68dU, + 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU, 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU, 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU, + 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U, 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U, 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, + 0x7a47b13cU, 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU, 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U, 0xcaaff381U, 0xb968c43eU, + 0x3824342cU, 0xc2a3405fU, 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U, 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, 0x7bcb8461U, + 0xd532b670U, 0x486c5c74U, 0xd0b85742U, }; static const aes_u32 Td1[aes_d_len] = { - 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, 0x552030faU, - 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U, 0x49deb15aU, 0x6725ba1bU, - 0x9845ea0eU, 0xe15dfec0U, 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U, 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, - 0xda955259U, 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U, 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U, - 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU, 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU, 0xe0b16477U, - 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU, 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U, 0x23ab73d3U, 0xe2724b02U, - 0x57e31f8fU, 0x2a6655abU, 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U, 0xf2302887U, 0xb223bfa5U, 0xba02036aU, - 0x5ced1682U, 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U, 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU, - 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU, 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U, 0xf93e218aU, - 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU, 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U, 0x241998fbU, 0x97d6bde9U, - 0xcc894043U, 0x7767d99eU, 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU, 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, - 0x00000000U, 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U, 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U, - 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU, 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U, 0x4f80c0c5U, - 0xa261dc20U, 0x695a774bU, 0x161c121aU, 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U, 0x0b0e090dU, 0xadf28bc7U, - 0xb92db6a8U, 0xc8141ea9U, 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U, 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, - 0x345bfb7eU, 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U, 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U, - 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U, 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U, 0x6c2bb316U, - 0x99a970b9U, 0xfa119448U, 0x2247e964U, 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U, 0xc787494eU, 0xc1d938d1U, - 0xfe8ccaa2U, 0x3698d40bU, 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU, 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, - 0x62547e46U, 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU, 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U, - 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU, 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU, 0x65e6956eU, - 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U, 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU, 0xaf31a4b2U, 0x312a3f23U, - 0x30c6a594U, 0xc035a266U, 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U, 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, - 0x2f1791f6U, 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U, 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U, - 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U, 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U, 0x8c9ad761U, - 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU, 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U, 0x599cd2dfU, 0x3f55f273U, - 0x791814ceU, 0xbf73c737U, 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU, 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, - 0x5fc2a340U, 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U, 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, - 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, + 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, 0x552030faU, 0xf6ad766dU, 0x9188cc76U, + 0x25f5024cU, 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U, 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U, 0x02c32f75U, 0x12814cf0U, + 0xa38d4697U, 0xc66bd3f9U, 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U, 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U, 0x6a75c289U, + 0x78f48e79U, 0x6b99583eU, 0xdd27b971U, 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU, 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU, + 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU, 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U, 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, + 0x2a6655abU, 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U, 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U, 0x2b8acf1cU, 0x92a779b4U, + 0xf0f307f2U, 0xa14e69e2U, 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU, 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU, 0x390b83ecU, + 0xaa4060efU, 0x065e719fU, 0x51bd6e10U, 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU, 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U, + 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU, 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU, 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, + 0x00000000U, 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U, 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U, 0x640a0fd9U, 0x21685ca6U, + 0xd19b5b54U, 0x3a24362eU, 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U, 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU, 0x0ae293baU, + 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U, 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U, 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U, + 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU, 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U, 0xcad731dcU, 0x10426385U, 0x40139722U, + 0x2084c611U, 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U, 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U, 0x6c2bb316U, 0x99a970b9U, + 0xfa119448U, 0x2247e964U, 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U, 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU, 0xcfa6f581U, + 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU, 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U, 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU, + 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U, 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU, 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, + 0xa8834f9aU, 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U, 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU, 0xaf31a4b2U, 0x312a3f23U, + 0x30c6a594U, 0xc035a266U, 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U, 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U, 0x8d764dd6U, + 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U, 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U, 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U, + 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U, 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU, 0xeecea927U, 0x35b761c9U, 0xede11ce5U, + 0x3c7a47b1U, 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U, 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU, 0x81caaff3U, 0x3eb968c4U, + 0x2c382434U, 0x5fc2a340U, 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U, 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, 0x617bcb84U, + 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, }; static const aes_u32 Td2[aes_d_len] = { - 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, 0xfa552030U, - 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U, 0x5a49deb1U, 0x1b6725baU, - 0x0e9845eaU, 0xc0e15dfeU, 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U, 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, - 0x59da9552U, 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U, 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U, - 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU, 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U, 0x77e0b164U, - 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U, 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU, 0xd323ab73U, 0x02e2724bU, - 0x8f57e31fU, 0xab2a6655U, 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U, 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, - 0x825ced16U, 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U, 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, - 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, 0x8af93e21U, - 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, 0xfb241998U, 0xe997d6bdU, - 0x43cc8940U, 0x9e7767d9U, 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U, 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, - 0x00000000U, 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU, 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU, - 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U, 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU, 0xc54f80c0U, - 0x20a261dcU, 0x4b695a77U, 0x1a161c12U, 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU, 0x0d0b0e09U, 0xc7adf28bU, - 0xa8b92db6U, 0xa9c8141eU, 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU, 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, - 0x7e345bfbU, 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U, 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U, - 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U, 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U, 0x166c2bb3U, - 0xb999a970U, 0x48fa1194U, 0x642247e9U, 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U, 0x4ec78749U, 0xd1c1d938U, - 0xa2fe8ccaU, 0x0b3698d4U, 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU, 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, - 0x4662547eU, 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U, 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U, - 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU, 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU, 0x6e65e695U, - 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U, 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U, 0xb2af31a4U, 0x23312a3fU, - 0x9430c6a5U, 0x66c035a2U, 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U, 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, - 0xf62f1791U, 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U, 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U, - 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU, 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U, 0x618c9ad7U, - 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U, 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U, 0xdf599cd2U, 0x733f55f2U, - 0xce791814U, 0x37bf73c7U, 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U, 0xf381caafU, 0xc43eb968U, 0x342c3824U, - 0x405fc2a3U, 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU, 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, - 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, + 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, 0xfa552030U, 0x6df6ad76U, 0x769188ccU, + 0x4c25f502U, 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U, 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU, 0x7502c32fU, 0xf012814cU, + 0x97a38d46U, 0xf9c66bd3U, 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U, 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U, 0x896a75c2U, + 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U, 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU, 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U, + 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U, 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU, 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, + 0xab2a6655U, 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U, 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U, 0x1c2b8acfU, 0xb492a779U, + 0xf2f0f307U, 0xe2a14e69U, 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, 0xec390b83U, + 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, + 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U, 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U, 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, + 0x00000000U, 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU, 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU, 0xd9640a0fU, 0xa621685cU, + 0x54d19b5bU, 0x2e3a2436U, 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU, 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U, 0xba0ae293U, + 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU, 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU, 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU, + 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU, 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U, 0xdccad731U, 0x85104263U, 0x22401397U, + 0x112084c6U, 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U, 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U, 0x166c2bb3U, 0xb999a970U, + 0x48fa1194U, 0x642247e9U, 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U, 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U, 0x81cfa6f5U, + 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU, 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU, 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U, + 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U, 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU, 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, + 0x9aa8834fU, 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U, 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U, 0xb2af31a4U, 0x23312a3fU, + 0x9430c6a5U, 0x66c035a2U, 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U, 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U, 0xd68d764dU, + 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U, 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U, 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU, + 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U, 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U, 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, + 0xb13c7a47U, 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U, 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U, 0xf381caafU, 0xc43eb968U, + 0x342c3824U, 0x405fc2a3U, 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU, 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, 0x84617bcbU, + 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, }; static const aes_u32 Td3[aes_d_len] = { - 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, 0x30fa5520U, - 0x766df6adU, 0xcc769188U, 0x024c25f5U, 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U, 0xb15a49deU, 0xba1b6725U, - 0xea0e9845U, 0xfec0e15dU, 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU, 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, - 0x5259da95U, 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU, 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U, - 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU, 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U, 0x6477e0b1U, - 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U, 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U, 0x73d323abU, 0x4b02e272U, - 0x1f8f57e3U, 0x55ab2a66U, 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U, 0x2887f230U, 0xbfa5b223U, 0x036aba02U, - 0x16825cedU, 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU, 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U, - 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U, 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU, 0x218af93eU, - 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU, 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U, 0x98fb2419U, 0xbde997d6U, - 0x4043cc89U, 0xd99e7767U, 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U, 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, - 0x00000000U, 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU, 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U, - 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U, 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU, 0xc0c54f80U, - 0xdc20a261U, 0x774b695aU, 0x121a161cU, 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U, 0x090d0b0eU, 0x8bc7adf2U, - 0xb6a8b92dU, 0x1ea9c814U, 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U, 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, - 0xfb7e345bU, 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U, 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U, - 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U, 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U, 0xb3166c2bU, - 0x70b999a9U, 0x9448fa11U, 0xe9642247U, 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U, 0x494ec787U, 0x38d1c1d9U, - 0xcaa2fe8cU, 0xd40b3698U, 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU, 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, - 0x7e466254U, 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U, 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU, - 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU, 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U, 0x956e65e6U, - 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU, 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U, 0xa4b2af31U, 0x3f23312aU, - 0xa59430c6U, 0xa266c035U, 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U, 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, - 0x91f62f17U, 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U, 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U, - 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU, 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU, 0xd7618c9aU, - 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU, 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU, 0xd2df599cU, 0xf2733f55U, - 0x14ce7918U, 0xc737bf73U, 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U, 0xaff381caU, 0x68c43eb9U, 0x24342c38U, - 0xa3405fc2U, 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU, 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, - 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, + 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, 0x30fa5520U, 0x766df6adU, 0xcc769188U, + 0x024c25f5U, 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U, 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU, 0x2f7502c3U, 0x4cf01281U, + 0x4697a38dU, 0xd3f9c66bU, 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U, 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU, 0xc2896a75U, + 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U, 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU, 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U, + 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U, 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U, 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, + 0x55ab2a66U, 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U, 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU, 0xcf1c2b8aU, 0x79b492a7U, + 0x07f2f0f3U, 0x69e2a14eU, 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U, 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U, 0x83ec390bU, + 0x60efaa40U, 0x719f065eU, 0x6e1051bdU, 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU, 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U, + 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U, 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U, 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, + 0x00000000U, 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU, 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U, 0x0fd9640aU, 0x5ca62168U, + 0x5b54d19bU, 0x362e3a24U, 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU, 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU, 0x93ba0ae2U, + 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U, 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U, 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U, + 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU, 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U, 0x31dccad7U, 0x63851042U, 0x97224013U, + 0xc6112084U, 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U, 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U, 0xb3166c2bU, 0x70b999a9U, + 0x9448fa11U, 0xe9642247U, 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U, 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U, 0xf581cfa6U, + 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU, 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U, 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U, + 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU, 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU, 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, + 0x4f9aa883U, 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU, 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U, 0xa4b2af31U, 0x3f23312aU, + 0xa59430c6U, 0xa266c035U, 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U, 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U, 0x4dd68d76U, + 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U, 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U, 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU, + 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU, 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU, 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, + 0x47b13c7aU, 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U, 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U, 0xaff381caU, 0x68c43eb9U, + 0x24342c38U, 0xa3405fc2U, 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU, 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, 0xcb84617bU, + 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, }; static const aes_u8 Td4[aes_d_len] = { - 0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U, 0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU, - 0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U, 0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU, - 0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU, 0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU, - 0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U, 0x76U, 0x5bU, 0xa2U, 0x49U, 0x6dU, 0x8bU, 0xd1U, 0x25U, - 0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U, 0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U, - 0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU, 0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U, - 0x90U, 0xd8U, 0xabU, 0x00U, 0x8cU, 0xbcU, 0xd3U, 0x0aU, 0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U, - 0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U, 0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU, - 0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU, 0x97U, 0xf2U, 0xcfU, 0xceU, 0xf0U, 0xb4U, 0xe6U, 0x73U, - 0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U, 0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU, - 0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U, 0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU, - 0xfcU, 0x56U, 0x3eU, 0x4bU, 0xc6U, 0xd2U, 0x79U, 0x20U, 0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U, - 0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U, 0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU, - 0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU, 0x2dU, 0xe5U, 0x7aU, 0x9fU, 0x93U, 0xc9U, 0x9cU, 0xefU, - 0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U, 0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U, + 0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U, 0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU, 0x7cU, 0xe3U, 0x39U, 0x82U, + 0x9bU, 0x2fU, 0xffU, 0x87U, 0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU, 0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU, + 0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU, 0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U, 0x76U, 0x5bU, 0xa2U, 0x49U, + 0x6dU, 0x8bU, 0xd1U, 0x25U, 0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U, 0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U, + 0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU, 0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U, 0x90U, 0xd8U, 0xabU, 0x00U, + 0x8cU, 0xbcU, 0xd3U, 0x0aU, 0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U, 0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U, + 0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU, 0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU, 0x97U, 0xf2U, 0xcfU, 0xceU, + 0xf0U, 0xb4U, 0xe6U, 0x73U, 0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U, 0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU, + 0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U, 0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU, 0xfcU, 0x56U, 0x3eU, 0x4bU, + 0xc6U, 0xd2U, 0x79U, 0x20U, 0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U, 0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U, + 0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU, 0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU, 0x2dU, 0xe5U, 0x7aU, 0x9fU, + 0x93U, 0xc9U, 0x9cU, 0xefU, 0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U, 0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U, 0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U, 0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU, }; @@ -324,8 +281,8 @@ int _aes_set_encrypt_key(const aes_byte_t* userKey, const aes_size_t bits, aes_c if (bits == 128) { while (1) { temp = rk[3]; - rk[4] = rk[0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) - ^ (Te0[(temp)&0xff] & 0x0000ff00) ^ (Te1[(temp >> 24)] & 0x000000ff) ^ rcon[i]; + rk[4] = rk[0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te0[(temp)&0xff] & 0x0000ff00) + ^ (Te1[(temp >> 24)] & 0x000000ff) ^ rcon[i]; rk[5] = rk[1] ^ rk[4]; rk[6] = rk[2] ^ rk[5]; rk[7] = rk[3] ^ rk[6]; @@ -340,8 +297,8 @@ int _aes_set_encrypt_key(const aes_byte_t* userKey, const aes_size_t bits, aes_c if (bits == 192) { while (1) { temp = rk[5]; - rk[6] = rk[0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) - ^ (Te0[(temp)&0xff] & 0x0000ff00) ^ (Te1[(temp >> 24)] & 0x000000ff) ^ rcon[i]; + rk[6] = rk[0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te0[(temp)&0xff] & 0x0000ff00) + ^ (Te1[(temp >> 24)] & 0x000000ff) ^ rcon[i]; rk[7] = rk[1] ^ rk[6]; rk[8] = rk[2] ^ rk[7]; rk[9] = rk[3] ^ rk[8]; @@ -358,8 +315,8 @@ int _aes_set_encrypt_key(const aes_byte_t* userKey, const aes_size_t bits, aes_c if (bits == 256) { while (1) { temp = rk[7]; - rk[8] = rk[0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) - ^ (Te0[(temp)&0xff] & 0x0000ff00) ^ (Te1[(temp >> 24)] & 0x000000ff) ^ rcon[i]; + rk[8] = rk[0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te0[(temp)&0xff] & 0x0000ff00) + ^ (Te1[(temp >> 24)] & 0x000000ff) ^ rcon[i]; rk[9] = rk[1] ^ rk[8]; rk[10] = rk[2] ^ rk[9]; rk[11] = rk[3] ^ rk[10]; @@ -367,8 +324,8 @@ int _aes_set_encrypt_key(const aes_byte_t* userKey, const aes_size_t bits, aes_c return 0; } temp = rk[11]; - rk[12] = rk[4] ^ (Te2[(temp >> 24)] & 0xff000000) ^ (Te3[(temp >> 16) & 0xff] & 0x00ff0000) - ^ (Te0[(temp >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(temp)&0xff] & 0x000000ff); + rk[12] = rk[4] ^ (Te2[(temp >> 24)] & 0xff000000) ^ (Te3[(temp >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(temp >> 8) & 0xff] & 0x0000ff00) + ^ (Te1[(temp)&0xff] & 0x000000ff); rk[13] = rk[5] ^ rk[12]; rk[14] = rk[6] ^ rk[13]; rk[15] = rk[7] ^ rk[14]; @@ -409,14 +366,14 @@ int _aes_set_decrypt_key(const aes_byte_t* userKey, const aes_size_t bits, aes_c /* apply the inverse MixColumn transform to all round keys but the first and the last: */ for (i = 1; i < (key->rounds); i++) { rk += 4; - rk[0] = Td0[Te1[(rk[0] >> 24)] & 0xff] ^ Td1[Te1[(rk[0] >> 16) & 0xff] & 0xff] - ^ Td2[Te1[(rk[0] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[0]) & 0xff] & 0xff]; - rk[1] = Td0[Te1[(rk[1] >> 24)] & 0xff] ^ Td1[Te1[(rk[1] >> 16) & 0xff] & 0xff] - ^ Td2[Te1[(rk[1] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[1]) & 0xff] & 0xff]; - rk[2] = Td0[Te1[(rk[2] >> 24)] & 0xff] ^ Td1[Te1[(rk[2] >> 16) & 0xff] & 0xff] - ^ Td2[Te1[(rk[2] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[2]) & 0xff] & 0xff]; - rk[3] = Td0[Te1[(rk[3] >> 24)] & 0xff] ^ Td1[Te1[(rk[3] >> 16) & 0xff] & 0xff] - ^ Td2[Te1[(rk[3] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[3]) & 0xff] & 0xff]; + rk[0] = Td0[Te1[(rk[0] >> 24)] & 0xff] ^ Td1[Te1[(rk[0] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[0] >> 8) & 0xff] & 0xff] + ^ Td3[Te1[(rk[0]) & 0xff] & 0xff]; + rk[1] = Td0[Te1[(rk[1] >> 24)] & 0xff] ^ Td1[Te1[(rk[1] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[1] >> 8) & 0xff] & 0xff] + ^ Td3[Te1[(rk[1]) & 0xff] & 0xff]; + rk[2] = Td0[Te1[(rk[2] >> 24)] & 0xff] ^ Td1[Te1[(rk[2] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[2] >> 8) & 0xff] & 0xff] + ^ Td3[Te1[(rk[2]) & 0xff] & 0xff]; + rk[3] = Td0[Te1[(rk[3] >> 24)] & 0xff] ^ Td1[Te1[(rk[3] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[3] >> 8) & 0xff] & 0xff] + ^ Td3[Te1[(rk[3]) & 0xff] & 0xff]; } return S_SUCCESS; @@ -457,20 +414,20 @@ int _aes_encrypt(const aes_byte_t* in, aes_byte_t* out, const aes_ctx_t* key) s3 = Te0[(t3 >> 24)] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[(t2)&0xff] ^ rk[3]; } - s0 = (Te2[(t0 >> 24)] & 0xff000000) ^ (Te3[(t1 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t2 >> 8) & 0xff] & 0x0000ff00) - ^ (Te1[(t3)&0xff] & 0x000000ff) ^ rk[0]; + s0 = (Te2[(t0 >> 24)] & 0xff000000) ^ (Te3[(t1 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t2 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t3)&0xff] & 0x000000ff) + ^ rk[0]; PUTU32(out, s0); - s1 = (Te2[(t1 >> 24)] & 0xff000000) ^ (Te3[(t2 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t3 >> 8) & 0xff] & 0x0000ff00) - ^ (Te1[(t0)&0xff] & 0x000000ff) ^ rk[1]; + s1 = (Te2[(t1 >> 24)] & 0xff000000) ^ (Te3[(t2 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t3 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t0)&0xff] & 0x000000ff) + ^ rk[1]; PUTU32(out + 4, s1); - s2 = (Te2[(t2 >> 24)] & 0xff000000) ^ (Te3[(t3 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t0 >> 8) & 0xff] & 0x0000ff00) - ^ (Te1[(t1)&0xff] & 0x000000ff) ^ rk[2]; + s2 = (Te2[(t2 >> 24)] & 0xff000000) ^ (Te3[(t3 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t0 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t1)&0xff] & 0x000000ff) + ^ rk[2]; PUTU32(out + 8, s2); - s3 = (Te2[(t3 >> 24)] & 0xff000000) ^ (Te3[(t0 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t1 >> 8) & 0xff] & 0x0000ff00) - ^ (Te1[(t2)&0xff] & 0x000000ff) ^ rk[3]; + s3 = (Te2[(t3 >> 24)] & 0xff000000) ^ (Te3[(t0 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t1 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t2)&0xff] & 0x000000ff) + ^ rk[3]; PUTU32(out + 12, s3); return S_SUCCESS; @@ -516,20 +473,20 @@ int _aes_decrypt(const aes_byte_t* in, aes_byte_t* out, const aes_ctx_t* key) * map cipher state to byte array block: */ - s0 = ((aes_u32)Td4[(t0 >> 24)] << 24) ^ ((aes_u32)Td4[(t3 >> 16) & 0xff] << 16) - ^ ((aes_u32)Td4[(t2 >> 8) & 0xff] << 8) ^ ((aes_u32)Td4[(t1)&0xff]) ^ rk[0]; + s0 = ((aes_u32)Td4[(t0 >> 24)] << 24) ^ ((aes_u32)Td4[(t3 >> 16) & 0xff] << 16) ^ ((aes_u32)Td4[(t2 >> 8) & 0xff] << 8) + ^ ((aes_u32)Td4[(t1)&0xff]) ^ rk[0]; PUTU32(out, s0); - s1 = ((aes_u32)Td4[(t1 >> 24)] << 24) ^ ((aes_u32)Td4[(t0 >> 16) & 0xff] << 16) - ^ ((aes_u32)Td4[(t3 >> 8) & 0xff] << 8) ^ ((aes_u32)Td4[(t2)&0xff]) ^ rk[1]; + s1 = ((aes_u32)Td4[(t1 >> 24)] << 24) ^ ((aes_u32)Td4[(t0 >> 16) & 0xff] << 16) ^ ((aes_u32)Td4[(t3 >> 8) & 0xff] << 8) + ^ ((aes_u32)Td4[(t2)&0xff]) ^ rk[1]; PUTU32(out + 4, s1); - s2 = ((aes_u32)Td4[(t2 >> 24)] << 24) ^ ((aes_u32)Td4[(t1 >> 16) & 0xff] << 16) - ^ ((aes_u32)Td4[(t0 >> 8) & 0xff] << 8) ^ ((aes_u32)Td4[(t3)&0xff]) ^ rk[2]; + s2 = ((aes_u32)Td4[(t2 >> 24)] << 24) ^ ((aes_u32)Td4[(t1 >> 16) & 0xff] << 16) ^ ((aes_u32)Td4[(t0 >> 8) & 0xff] << 8) + ^ ((aes_u32)Td4[(t3)&0xff]) ^ rk[2]; PUTU32(out + 8, s2); - s3 = ((aes_u32)Td4[(t3 >> 24)] << 24) ^ ((aes_u32)Td4[(t2 >> 16) & 0xff] << 16) - ^ ((aes_u32)Td4[(t1 >> 8) & 0xff] << 8) ^ ((aes_u32)Td4[(t0)&0xff]) ^ rk[3]; + s3 = ((aes_u32)Td4[(t3 >> 24)] << 24) ^ ((aes_u32)Td4[(t2 >> 16) & 0xff] << 16) ^ ((aes_u32)Td4[(t1 >> 8) & 0xff] << 8) + ^ ((aes_u32)Td4[(t0)&0xff]) ^ rk[3]; PUTU32(out + 12, s3); return S_SUCCESS; diff --git a/stdcrt/algorithm/compat_md5.c b/stdcrt/algorithm/compat_md5.c index 5db3cc823d6a0086ac2e8858f96d0f01880efdb2..7b98ae4f9b4975106b21328ff5a20ef05c325d37 100644 --- a/stdcrt/algorithm/compat_md5.c +++ b/stdcrt/algorithm/compat_md5.c @@ -34,9 +34,8 @@ static void MD5Transform(unsigned int state[4], unsigned char block[64]); static void MD5Encode(unsigned char* output, unsigned int* input, unsigned int len); static void MD5Decode(unsigned int* output, unsigned char* input, unsigned int len); -static unsigned char PADDING[] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +static unsigned char PADDING[] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; void MD5Init(MD5_CTX* ctx) { diff --git a/stdcrt/algorithm/compat_sha1.c b/stdcrt/algorithm/compat_sha1.c index 49e7bf65b38cf2d4eb818c3dd2e6a46db78a14b8..b335e15624fa91fde6d31d6848965af738b65b66 100644 --- a/stdcrt/algorithm/compat_sha1.c +++ b/stdcrt/algorithm/compat_sha1.c @@ -13,9 +13,7 @@ #else #error "Endianness not defined!" #endif -#define blk(i) \ - (block->l[i & 15] = \ - rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1)) +#define blk(i) (block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] ^ block->l[(i + 2) & 15] ^ block->l[i & 15], 1)) /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ #define R0(v, w, x, y, z, i) \ diff --git a/stdcrt/code/compat_cjson.c b/stdcrt/code/compat_cjson.c index 32f6579170dd4425d6566b11215b4fb081334962..eef82a74df3bf2555795b717e50cbe64a2c6ca15 100644 --- a/stdcrt/code/compat_cjson.c +++ b/stdcrt/code/compat_cjson.c @@ -462,8 +462,8 @@ static unsigned parse_hex4(const unsigned char* const input) /* converts a UTF-16 literal to UTF-8 * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char utf16_literal_to_utf8( - const unsigned char* const input_pointer, const unsigned char* const input_end, unsigned char** output_pointer) +static unsigned char + utf16_literal_to_utf8(const unsigned char* const input_pointer, const unsigned char* const input_end, unsigned char** output_pointer) { long unsigned int codepoint = 0; unsigned int first_code = 0; @@ -1535,8 +1535,7 @@ static cJSON* get_object_item(const cJSON* const object, const char* const name, } } else { while ((current_element != NULL) - && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) - != 0)) { + && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) { current_element = current_element->next; } } @@ -1790,8 +1789,7 @@ void cJSON_ReplaceItemInArray(cJSON* array, int which, cJSON* newitem) cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); } -static cJSON_bool - replace_item_in_object(cJSON* object, const char* string, cJSON* replacement, cJSON_bool case_sensitive) +static cJSON_bool replace_item_in_object(cJSON* object, const char* string, cJSON* replacement, cJSON_bool case_sensitive) { if ((replacement == NULL) || (string == NULL)) { return false; @@ -2077,9 +2075,7 @@ cJSON* cJSON_Duplicate(const cJSON* item, cJSON_bool recurse) } } if (item->string) { - newitem->string = (item->type & cJSON_StringIsConst) - ? item->string - : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + newitem->string = (item->type & cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); if (!newitem->string) { goto fail; } diff --git a/stdcrt/code/compat_endian.c b/stdcrt/code/compat_endian.c index fec9116131e92157f775a9afc5a5c4ddfc975cfd..d5426d270fdb4d54861a72ad762fe76055b2d7e9 100644 --- a/stdcrt/code/compat_endian.c +++ b/stdcrt/code/compat_endian.c @@ -20,8 +20,7 @@ uint16_t blushort(uint16_t value) uint32_t bluint32(uint32_t value) { - return ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8) | ((value & 0x00FF0000) >> 8) - | ((value & 0xFF000000) >> 24); + return ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8) | ((value & 0x00FF0000) >> 8) | ((value & 0xFF000000) >> 24); } int uint64touint32(uint64_t u64value, uint32* u32value) @@ -36,8 +35,7 @@ int uint64touint32(uint64_t u64value, uint32* u32value) rc_assert(rc > 0, S_ERROR); uint32_t value; - value = (((uint32_t)u8value[4]) << 24) | (((uint32_t)u8value[5]) << 16) | (((uint32_t)u8value[6]) << 8) - | ((uint32_t)u8value[7]); + value = (((uint32_t)u8value[4]) << 24) | (((uint32_t)u8value[5]) << 16) | (((uint32_t)u8value[6]) << 8) | ((uint32_t)u8value[7]); *u32value = value & UINT32_MAX; } else if (is_big_little() == Big_endian) { @@ -45,8 +43,7 @@ int uint64touint32(uint64_t u64value, uint32* u32value) rc_assert(rc > 0, S_ERROR); uint32_t value; - value = (((uint32_t)u8value[0]) << 24) | (((uint32_t)u8value[1]) << 16) | (((uint32_t)u8value[2]) << 8) - | ((uint32_t)u8value[3]); + value = (((uint32_t)u8value[0]) << 24) | (((uint32_t)u8value[1]) << 16) | (((uint32_t)u8value[2]) << 8) | ((uint32_t)u8value[3]); *u32value = value & UINT32_MAX; } @@ -80,9 +77,8 @@ void un_putl(uint8_t* buf, uint32_t val) uint64_t un_getll(const uint8_t* buf) { - return (((uint64_t)buf[0]) << 56) | (((uint64_t)buf[1]) << 48) | (((uint64_t)buf[2]) << 40) - | (((uint64_t)buf[3]) << 32) | (((uint64_t)buf[4]) << 24) | (((uint64_t)buf[5]) << 16) - | (((uint64_t)buf[6]) << 8) | (((uint64_t)buf[7] << 0)); + return (((uint64_t)buf[0]) << 56) | (((uint64_t)buf[1]) << 48) | (((uint64_t)buf[2]) << 40) | (((uint64_t)buf[3]) << 32) + | (((uint64_t)buf[4]) << 24) | (((uint64_t)buf[5]) << 16) | (((uint64_t)buf[6]) << 8) | (((uint64_t)buf[7] << 0)); } void un_putll(uint8_t* buf, uint64_t val) diff --git a/stdcrt/compat_log.c b/stdcrt/compat_log.c index 29dcb53bad61f51f5208c7260fa85da8de2793f5..67876f5cfc420b99b56f6770a532f4465e67fa77 100644 --- a/stdcrt/compat_log.c +++ b/stdcrt/compat_log.c @@ -12,8 +12,7 @@ */ #endif -static int - _log_print(int proi, const char* tag, const char* file, long line, const char* func, const char* fmt, va_list ap) +static int _log_print(int proi, const char* tag, const char* file, long line, const char* func, const char* fmt, va_list ap) { char* msg = NULL; int hmsglen = 0; @@ -46,16 +45,7 @@ static int return S_SUCCESS; } -int log_print( - int proi, - const char* tag, - const char* data, - const char* time, - const char* file, - long line, - const char* func, - const char* fmt, - ...) +int log_print(int proi, const char* tag, const char* data, const char* time, const char* file, long line, const char* func, const char* fmt, ...) { va_list ap; va_start(ap, fmt); diff --git a/stdcrt/event/compat_event.c b/stdcrt/event/compat_event.c index fc762b8388258f1bccb129e2c73bfd14019d7b23..c58540f2013de2225f6112ef9a8905db0ce15ff8 100644 --- a/stdcrt/event/compat_event.c +++ b/stdcrt/event/compat_event.c @@ -36,12 +36,14 @@ void* evoper_evbase(evoper_t* oper) void* evoper_private(evoper_t* oper) { - rc_assert(oper != NULL, NULL) return oper->private_data; + rc_assert(oper != NULL, NULL); + return oper->private_data; } int evoper_bindevloop(evloop_t* loop, evoper_t* oper) { rc_assert(loop != NULL, S_ERROR); - rc_assert(oper != NULL, S_ERROR) oper->loop = loop; + rc_assert(oper != NULL, S_ERROR); + oper->loop = loop; return S_SUCCESS; } int evloop_add(evoper_t* oper, ev_time_t tv, short event) diff --git a/stdcrt/event/compat_event_iocp.c b/stdcrt/event/compat_event_iocp.c index 66985db7d99f9ec25ecd4d02591a63931ddcc9a7..803313527ee90debdc993c063db6deeb074abf30 100644 --- a/stdcrt/event/compat_event_iocp.c +++ b/stdcrt/event/compat_event_iocp.c @@ -57,9 +57,7 @@ static void* get_mswsock_extfunc(SOCKET s, const GUID* which_fn) { void* ptr = NULL; DWORD bytes = 0; - WSAIoctl( - s, SIO_GET_EXTENSION_FUNCTION_POINTER, (GUID*)which_fn, sizeof(*which_fn), &ptr, sizeof(ptr), &bytes, NULL, - NULL); + WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, (GUID*)which_fn, sizeof(*which_fn), &ptr, sizeof(ptr), &bytes, NULL, NULL); return ptr; } @@ -459,8 +457,7 @@ int iocp_op_cmd_poll(iocp_op_t* base, evloop_t* loop, ev_msec_t timer) lpevoper_overlapped ov = NULL; ov = CONTAINING_RECORD(pov, evoper_overlapped, overlapped); - if (EVOP_NTSOCK == key || EVOP_CTSOCK == key || EVOP_CUSOCK == key || EVOP_CUDS == key - || EVOP_NUDS == key) { + if (EVOP_NTSOCK == key || EVOP_CTSOCK == key || EVOP_CUSOCK == key || EVOP_CUDS == key || EVOP_NUDS == key) { if (err == ERROR_CONNECTION_REFUSED || err == ERROR_HOST_UNREACHABLE || err == ERROR_NETWORK_UNREACHABLE || err == ERROR_SEM_TIMEOUT) { if (HasOverlappedIoCompleted(&ov->overlapped)) { diff --git a/stdcrt/event/event_mach.c b/stdcrt/event/event_mach.c index 6ef94c1fa6c9d13621a20fd345d1a5bc89944e46..aca9642f1ba6c0a8c65a6c89f85b5268caaceed2 100644 --- a/stdcrt/event/event_mach.c +++ b/stdcrt/event/event_mach.c @@ -18,7 +18,7 @@ int mach_uinxsock_connect(evoper_t* oper, const addressptr_t* addr) s_strncpy(unaddr.sun_path, addr->ptr, addr->len); set_blocking(oper->sock, 1); - return _asynconnect_ctcpsockv4(oper->sock, (struct sockaddr*)&unaddr, sizeof(unaddr)); + return _asynconnect_sock(oper->sock, (struct sockaddr*)&unaddr, sizeof(unaddr)); } int mach_tcpsock_connect(evoper_t* oper, const addressptr_t* addr) { diff --git a/stdcrt/event/event_posix.c b/stdcrt/event/event_posix.c index b18dd2d9597f92e033e8cd973256becf663d3423..75ddf020317b0021fea9003e002403aa7170214d 100644 --- a/stdcrt/event/event_posix.c +++ b/stdcrt/event/event_posix.c @@ -18,7 +18,7 @@ int posix_uinxsock_connect(evoper_t* oper, const addressptr_t* addr) s_strncpy(unaddr.sun_path, addr->ptr, addr->len); set_blocking(oper->sock, 1); - return _asynconnect_ctcpsockv4(oper->sock, (struct sockaddr*)&unaddr, sizeof(unaddr)); + return _asynconnect_sock(oper->sock, (struct sockaddr*)&unaddr, sizeof(unaddr)); } int posix_tcpsock_connect(evoper_t* oper, const addressptr_t* addr) { diff --git a/stdcrt/event/event_win32.c b/stdcrt/event/event_win32.c index aa23a1aae3375d9efd1ff76ef99950f4290ef5d6..dd795c249101de8684fb6a7bbbd6b2205fd20fdb 100644 --- a/stdcrt/event/event_win32.c +++ b/stdcrt/event/event_win32.c @@ -21,7 +21,7 @@ int win32_sock_connect(evoper_t* oper, const struct sockaddr* sa, socklen_t sock rc_assert(base->handler != NULL, rc); oper->event(oper, EVOP_ADDREF, 0); - rc = _asynconnect_ctcpsockv4(oper->sock, sa, socklen); + rc = _asynconnect_sock(oper->sock, sa, socklen); if (rc != S_PENDING) { oper->event(oper, EVOP_DELREF, 0); } @@ -99,9 +99,8 @@ int win32_sock_acceptex(evoper_t* oper, void* ptr) as->oper = oper; - fSuccess = base->extfns.AcceptEx( - oper->sock, as->sock, as->myAddrBlock, 0, ACCEPT_ADDRESS_LENGTH, ACCEPT_ADDRESS_LENGTH, &receivelen, - &as->overlapped); + fSuccess = + base->extfns.AcceptEx(oper->sock, as->sock, as->myAddrBlock, 0, ACCEPT_ADDRESS_LENGTH, ACCEPT_ADDRESS_LENGTH, &receivelen, &as->overlapped); if (fSuccess == TRUE) { rc = S_SUCCESS; diff --git a/stdcrt/io/compat_path.c b/stdcrt/io/compat_path.c index d1e347c7d88632994cfd8ad64d1aefc99bd1deaa..3efa15108d1ce6dd22794c08efd3a4e02a9611f2 100644 --- a/stdcrt/io/compat_path.c +++ b/stdcrt/io/compat_path.c @@ -22,7 +22,7 @@ #endif -int FileIsExist(const basic_tchar* file) +int fileisexist(const basic_tchar* file) { if (NULL == file || 0x00 == (*file)) return S_ERROR; @@ -48,7 +48,7 @@ int FileIsExist(const basic_tchar* file) #endif return S_SUCCESS; } -int FileIsDirectory(const basic_tchar* dir) +int fileisdirectory(const basic_tchar* dir) { int rc = S_ERROR; rc_assert(dir != NULL, S_ERROR); @@ -77,7 +77,7 @@ int FileIsDirectory(const basic_tchar* dir) return rc; } -int GetDynamicPath(void* name, basic_tchar* path, size_t len) +int get_dynamicpath(void* name, basic_tchar* path, size_t len) { #if (TARGET_OS == OS_WIN) GetModuleFileNameW(GetModuleHandle((basic_tchar*)name), path, len); @@ -101,7 +101,7 @@ int GetDynamicPath(void* name, basic_tchar* path, size_t len) return S_SUCCESS; } -int GetExecutePath(_pid_t pid, basic_tchar* path, size_t len) +int get_executepath(_pid_t pid, basic_tchar* path, pathlen len) { basic_tchar buf[MAX_PATH + 1] = {0x00}; @@ -137,7 +137,7 @@ int GetExecutePath(_pid_t pid, basic_tchar* path, size_t len) int count = 0; char* p = NULL; - uint32_t size = len; + pathlen size = len; count = _NSGetExecutablePath(buf, &size); p = s_strrchr(buf, '/'); @@ -151,7 +151,7 @@ int GetExecutePath(_pid_t pid, basic_tchar* path, size_t len) return S_SUCCESS; } -int GetDynamicName(const basic_tchar* name, basic_tchar* pluginame, size_t len) +int get_dynamicname(const basic_tchar* name, basic_tchar* pluginame, size_t len) { #if (TARGET_OS == OS_WIN) s_wstrcat(pluginame, len, name); @@ -245,8 +245,7 @@ int get_file_info(basic_tchar* cFilePath, get_file_cb entry, void* ctx) #define FILE_MAX_PATH 512 -void dirwalk( - basic_tchar* dir, int (*func)(basic_tchar* name, get_file_cb entry, void* ctx), get_file_cb entry, void* ctx) +void dirwalk(basic_tchar* dir, int (*func)(basic_tchar* name, get_file_cb entry, void* ctx), get_file_cb entry, void* ctx) { char name[FILE_MAX_PATH] = {0x00}; struct dirent* dp = NULL; @@ -296,8 +295,7 @@ int get_file_info(basic_tchar* name, get_file_cb entry, void* ctx) #define FILE_MAX_PATH 512 -void dirwalk( - basic_tchar* dir, int (*func)(basic_tchar* name, get_file_cb entry, void* ctx), get_file_cb entry, void* ctx) +void dirwalk(basic_tchar* dir, int (*func)(basic_tchar* name, get_file_cb entry, void* ctx), get_file_cb entry, void* ctx) { char name[FILE_MAX_PATH] = {0x00}; struct dirent* dp = NULL; @@ -343,7 +341,7 @@ int get_file_info(basic_tchar* name, get_file_cb entry, void* ctx) #endif -int GetFiles(basic_tchar* path, get_file_cb entry, void* ctx) +int get_files(basic_tchar* path, get_file_cb entry, void* ctx) { return get_file_info(path, entry, ctx); } diff --git a/stdcrt/net/compat_sock.c b/stdcrt/net/compat_sock.c index 4be7ab91dc1883c10869127874d86aa944335ab0..44193a0d1cc1ef4e29b6d3e63894b04d4f2f9dd7 100644 --- a/stdcrt/net/compat_sock.c +++ b/stdcrt/net/compat_sock.c @@ -1,15 +1,11 @@ #include -_sock_t _bind_unixsock(const char* name, size_t len, int af, int type, int protocol) +int _bind_unixsock(_sock_t s, const char* name, size_t len, int af) { struct sockaddr_un addr; - _sock_t s; s_memset(&addr, 0, sizeof(struct sockaddr_un)); - s = socket(af, type, protocol); - rc_assert(s != INVALID_SOCKET, INVALID_SOCKET); - _file_unlink(name); addr.sun_family = af; @@ -22,47 +18,39 @@ _sock_t _bind_unixsock(const char* name, size_t len, int af, int type, int proto if (listen(s, 10) < 0) { goto sockerr; } - - return s; - + return S_SUCCESS; sockerr: - _closesock(s); - return INVALID_SOCKET; + return S_ERROR; } -_sock_t _connect_unixsock(const char* name, size_t len, int af, int type, int protocol) +int _connect_unixsock(_sock_t s, const char* name, size_t len, int af) { struct sockaddr_un addr; - _sock_t s; int rc = 0; s_memset(&addr, 0, sizeof(struct sockaddr_un)); - s = socket(af, type, protocol); - rc_assert(s != INVALID_SOCKET, INVALID_SOCKET); - addr.sun_family = af; s_strncpy(addr.sun_path, name, len); rc = connect(s, (struct sockaddr*)&addr, sizeof(addr)); - rc_assert(rc < 0, s); + rc_assert(rc < 0, S_SUCCESS); - _closesock(s); - return INVALID_SOCKET; + return S_ERROR; } -_sock_t _bind_stcpsockv4(const char* name, size_t len, int slisten, unsigned short port) +int _bind_stcpsockv4(_sock_t s, const char* name, size_t len, int scount, unsigned short port) { struct sockaddr_in saddr; - _sock_t s = _createsock(PF_INET, SOCK_STREAM, IPPROTO_TCP); - - saddr.sin_family = PF_INET; + saddr.sin_family = AF_INET; if (len == 0) saddr.sin_addr.s_addr = htonl(INADDR_ANY); else - saddr.sin_addr.s_addr = inet_addr(name); + _inet_pton(AF_INET, name, (char*)&saddr.sin_addr); + + // saddr.sin_addr.s_addr = inet_addr(name); saddr.sin_port = htons(port); @@ -70,44 +58,56 @@ _sock_t _bind_stcpsockv4(const char* name, size_t len, int slisten, unsigned sho goto sockerr; } - if (listen(s, slisten) < 0) { + if (listen(s, scount) < 0) { goto sockerr; } - return s; + return S_SUCCESS; sockerr: - _closesock(s); - return INVALID_SOCKET; + return S_ERROR; } -_sock_t _bind_stcpsockv6(const char* name, size_t len, int slisten, unsigned short port) +int _bind_stcpsockv6(_sock_t s, const char* name, size_t len, int scount, unsigned short port) { - return INVALID_SOCKET; + struct sockaddr_in6 saddr6; + s_memset(&saddr6, 0, sizeof(struct sockaddr_in6)); + + saddr6.sin6_family = AF_INET6; + saddr6.sin6_port = htons(port); + + _inet_pton(AF_INET6, name, (char*)&saddr6.sin6_addr); + + if (bind(s, (struct sockaddr*)&saddr6, sizeof(saddr6)) < 0) { + goto sockerr; + } + + if (listen(s, scount) < 0) { + goto sockerr; + } + + return S_SUCCESS; +sockerr: + return S_ERROR; } -_sock_t _connect_ctcpsockv4(const char* name, size_t len, unsigned short port) +int _connect_ctcpsockv4(_sock_t s, const char* name, size_t len, unsigned short port) { - _sock_t s; int rc = 0; struct sockaddr_in saddr; s_memset(&saddr, 0, sizeof(struct sockaddr_in)); - s = _createsock(PF_INET, SOCK_STREAM, IPPROTO_TCP); - rc_assert(s != INVALID_SOCKET, INVALID_SOCKET); - saddr.sin_family = PF_INET; saddr.sin_addr.s_addr = inet_addr(name); saddr.sin_port = htons(port); rc = connect(s, (struct sockaddr*)&saddr, sizeof(saddr)); - rc_assert(rc < 0, s); + rc_assert(rc < 0, S_SUCCESS); - _closesock(s); - return INVALID_SOCKET; + return S_ERROR; } -_sock_t _connect_ctcpsockv6(const char* name, size_t len, unsigned short port) +int _connect_ctcpsockv6(_sock_t s, const char* name, size_t len, unsigned short port) { - return INVALID_SOCKET; + return S_ERROR; } #if (TARGET_OS == OS_WIN) @@ -131,28 +131,49 @@ int _socket_geterror(_sock_t sock) #endif -int _asynconnect_ctcpsockv4(_sock_t s, const struct sockaddr* sa, socklen_t socklen) +int _asynconnect_sockv4(_sock_t s, const char* name, size_t len, unsigned short port) +{ + struct sockaddr_in addr; + memset(&addr, 0, sizeof(struct sockaddr_in)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = inet_addr(name); + addr.sin_port = htons(port & UINT16_MAX); + + return _asynconnect_sock(s, (const struct sockaddr*)&addr, sizeof(struct sockaddr_in)); +} +int _asynconnect_sock(_sock_t s, SOCKADDR_PTR sa, socklen_t socklen) { int rc = 0; rc = set_blocking(s, 1); - if (connect(s, sa, socklen) < 0) { - int e = _socket_geterror(s); - if (_ERR_CONNECT_RETRIABLE(e)) - return S_PENDING; - if (_ERR_CONNECT_REFUSED(e)) + rc = connect(s, sa, socklen); + + if (rc < 0) { + int err = _socket_geterror(s); + + if (_ERR_CONNECT_RETRIABLE(err)) + return S_PENDING; // connecting + + if (_ERR_CONNECT_REFUSED(err)) + return S_ERROR; + + if (_ERR_CONNECT_ERRORRESET(err)) return S_ERROR; - goto err; + + if (_ERR_CONNECT_ERROR_ENET(err)) + return S_ERROR; + + if (_ERR_CONNECT_ERROR_EHOST(err)) + return S_ERROR; + + } else { + // The connect succeeded + return S_SUCCESS; } - return S_SUCCESS; -err: + return S_ERROR; } -int _asynconnect_ctcpsockv6(_sock_t s, const struct sockaddr* sa, socklen_t socklen) -{ - return S_SUCCESS; -} int _connectfinished_socket(_sock_t s) { int e; @@ -297,148 +318,159 @@ int set_blocking(_sock_t s, int turn) #endif return S_SUCCESS; } -int SetError(_sock_t* s, int turn) +int set_sockerror(_sock_t s, int turn) +{ + int one = turn; + setsockopt(s, SOL_SOCKET, SO_ERROR, (void*)&one, sizeof(int)); + return S_SUCCESS; +} +int set_reuseaddr(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int error = turn; - setsockopt(*s, SOL_SOCKET, SO_ERROR, (void*)&error, sizeof(int)); + int one = turn; + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one)); return S_SUCCESS; } -int SetReuseAddr(_sock_t* s, int turn) +int set_nodelay(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int reuse = turn; - setsockopt(*s, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)); + rc_assert(s != INVALID_SOCKET, S_ERROR); return S_SUCCESS; } -int SetNoDelay(_sock_t* s, int turn) +int set_deferaccpet(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); +#if defined(TCP_DEFER_ACCEPT) + int one = turn; + setsockopt(s, SOL_SOCKET, IPPROTO_TCP, TCP_DEFER_ACCEPT, &one, (socklen_t)sizeof(one)); +#endif + return S_SUCCESS; } -int SetBroadCast(_sock_t* s, int turn) +int set_broadcast(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int bBroadcast = turn; - setsockopt(*s, SOL_SOCKET, SO_BROADCAST, (const char*)&bBroadcast, sizeof(int)); + int one = turn; + setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const char*)&one, sizeof(int)); return S_SUCCESS; } -int SetDontRoute(_sock_t* s, int turn) +int set_dontroute(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int dontroute = turn; - setsockopt(*s, SOL_SOCKET, SO_DONTROUTE, (const char*)&dontroute, sizeof(dontroute)); + int one = turn; + setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (const char*)&one, sizeof(one)); return S_SUCCESS; } -int SetDoLinger(_sock_t* s, int turn) +int set_dolinger(_sock_t s, int turn) { #if (TARGET_OS == OS_WIN) - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int bDontlinger = turn; - setsockopt(*s, SOL_SOCKET, SO_DONTLINGER, (const char*)&bDontlinger, sizeof(int)); + int one = turn; + setsockopt(s, SOL_SOCKET, SO_DONTLINGER, (const char*)&one, sizeof(int)); #endif + return S_SUCCESS; +} +int set_reuseable(_sock_t s, int turn) +{ +#if defined(SO_REUSEADDR) && !defined(_WIN32) + int one = 1; + /* REUSEADDR on Unix means, "don't hang on to this address after the + * listener is closed." On Windows, though, it means "don't keep other + * processes from binding to this address while we're using it. */ + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&one, (socklen_t)sizeof(one)); +#else +#endif return S_SUCCESS; } -int SetLinger(_sock_t* s, int sec) +int set_reuseableport(_sock_t s, int turn) +{ +#if (TARGET_OS == OS_POSIX) && defined(SO_REUSEPORT) + int one = 1; + /* REUSEPORT on Linux 3.9+ means, "Multiple servers (processes or + * threads) can bind to the same port if they each set the option. */ + setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (void*)&one, (socklen_t)sizeof(one)); +#else + +#endif + return S_SUCCESS; +} +int set_linger(_sock_t s, int sec) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); struct linger so_linger; so_linger.l_onoff = 1; so_linger.l_linger = sec; - setsockopt(*s, SOL_SOCKET, SO_LINGER, (const char*)&so_linger, sizeof(so_linger)); + setsockopt(s, SOL_SOCKET, SO_LINGER, (const char*)&so_linger, sizeof(so_linger)); return S_SUCCESS; } -int SetKeepalive(_sock_t* s, int turn) +int set_keepalive(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int bKeepalive = turn; - setsockopt(*s, SOL_SOCKET, SO_KEEPALIVE, (const char*)&bKeepalive, sizeof(int)); + int one = turn; + setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (const char*)&one, sizeof(int)); return S_SUCCESS; } -int SetCork(_sock_t* s, int turn) +int set_cork(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int set = 0; - set = turn; + int one = 0; + one = turn; #if (TARGET_OS == OS_POSIX) - setsockopt(*s, SOL_TCP, TCP_CORK, (void*)&set, sizeof(int)); + setsockopt(s, SOL_TCP, TCP_CORK, (void*)&one, sizeof(int)); #endif return S_SUCCESS; } -int SetNoSigPipe(_sock_t* s, int turn) +int set_nosigpipe(_sock_t s, int turn) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - - int set = 0; - set = turn; + int one = 0; + one = turn; // unix no found MSG_NOSIGNAL, but have SO_NOSIGPIPE #if (TARGET_OS != OS_WIN) #if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) #define MSG_NOSIGNAL SO_NOSIGPIPE #endif - setsockopt(*s, SOL_SOCKET, MSG_NOSIGNAL, (void*)&set, sizeof(int)); + setsockopt(s, SOL_SOCKET, MSG_NOSIGNAL, (void*)&one, sizeof(int)); #endif return S_SUCCESS; } -int SetNonblock(_sock_t* s, int turn) -{ - rc_assert(*s != INVALID_SOCKET, S_ERROR); - return S_SUCCESS; -} -int SetSendTimeOut(_sock_t* s, int sec) +int set_sendtime(_sock_t s, int sec) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); struct timeval timeout; timeout.tv_sec = sec; timeout.tv_usec = 0; socklen_t len = sizeof(timeout); - setsockopt(*s, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, len); + setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, len); return S_SUCCESS; } -int SetRecvTimeOut(_sock_t* s, int sec) +int set_recvtime(_sock_t s, int sec) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); struct timeval timeout; timeout.tv_sec = sec; timeout.tv_usec = 0; socklen_t len = sizeof(timeout); - setsockopt(*s, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, len); + setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, len); return S_SUCCESS; } -int SetConTimeOut(_sock_t* s, int sec) +int set_connectime(_sock_t s, int sec) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); return S_SUCCESS; } -int SetSendBufLen(_sock_t* s, int size) +int set_sendbuflen(_sock_t s, int size) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - long nRecvBuf = size * 1024; - setsockopt(*s, SOL_SOCKET, SO_RCVBUF, (const char*)&nRecvBuf, sizeof(long)); + long len = size * 1024; + setsockopt(s, SOL_SOCKET, SO_RCVBUF, (const char*)&len, sizeof(long)); return S_SUCCESS; } -int SetRecvBufLen(_sock_t* s, int size) +int set_recvbuflen(_sock_t s, int size) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - long nRecvBuf = size * 1024; - setsockopt(*s, SOL_SOCKET, SO_RCVBUF, (const char*)&nRecvBuf, sizeof(long)); + long len = size * 1024; + setsockopt(s, SOL_SOCKET, SO_RCVBUF, (const char*)&len, sizeof(long)); return S_SUCCESS; } -int SetSendLoWat(_sock_t* s, int size) +int set_sendlowat(_sock_t s, int size) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int nSendLowAT = size; - setsockopt(*s, SOL_SOCKET, SO_SNDLOWAT, (void*)&nSendLowAT, sizeof(nSendLowAT)); + int value = size; + setsockopt(s, SOL_SOCKET, SO_SNDLOWAT, (void*)&value, sizeof(value)); return S_SUCCESS; } -int SetRecvLoWat(_sock_t* s, int size) +int set_recvlowat(_sock_t s, int size) { - rc_assert(*s != INVALID_SOCKET, S_ERROR); - int nRecvLowAT = size; - setsockopt(*s, SOL_SOCKET, SO_RCVLOWAT, (void*)&nRecvLowAT, sizeof(nRecvLowAT)); + int value = size; + setsockopt(s, SOL_SOCKET, SO_RCVLOWAT, (void*)&value, sizeof(value)); return S_SUCCESS; } diff --git a/stdcrt/net/compat_sockinet.c b/stdcrt/net/compat_sockinet.c index d0f98ef1ff481788078ab3cda477150fd1ad5a20..945e18dbea94ee7015a4a9f835c8592dee137d5d 100644 --- a/stdcrt/net/compat_sockinet.c +++ b/stdcrt/net/compat_sockinet.c @@ -387,8 +387,8 @@ char* inet_ntop4(const unsigned char* src, char* dst, size_t size) tmp[0] = '\0'; sprintf( - tmp, "%d.%d.%d.%d", ((int)((unsigned char)src[0])) & 0xff, ((int)((unsigned char)src[1])) & 0xff, - ((int)((unsigned char)src[2])) & 0xff, ((int)((unsigned char)src[3])) & 0xff); + tmp, "%d.%d.%d.%d", ((int)((unsigned char)src[0])) & 0xff, ((int)((unsigned char)src[1])) & 0xff, ((int)((unsigned char)src[2])) & 0xff, + ((int)((unsigned char)src[3])) & 0xff); // a[0] = ((inaddr & 0xff000000) >> 24); // a[1] = ((inaddr & 0x00ff0000) >> 16); diff --git a/stdcrt/stdlib/compat_guid.c b/stdcrt/stdlib/compat_guid.c index 16889f8b3c713b34ef6057297daeeb63c179ac42..02525407d6fee926885acbf6e3197c4009bc8b75 100644 --- a/stdcrt/stdlib/compat_guid.c +++ b/stdcrt/stdlib/compat_guid.c @@ -9,10 +9,9 @@ GUID StringToGUID(const char* lpString) s_strcpy(szTemp, GUIDStringLength, lpString); sscanf( - szTemp, GUIDFormatString, (unsigned int*)(&guid.Data1), (unsigned int*)(Data12 + 0), - (unsigned int*)(Data12 + 1), (unsigned int*)(Data234 + 2), (unsigned int*)(Data234 + 3), - (unsigned int*)(Data234 + 4), (unsigned int*)(Data234 + 5), (unsigned int*)(Data234 + 6), - (unsigned int*)(Data234 + 7), (unsigned int*)(Data234 + 8), (unsigned int*)(Data234 + 9)); + szTemp, GUIDFormatString, (unsigned int*)(&guid.Data1), (unsigned int*)(Data12 + 0), (unsigned int*)(Data12 + 1), + (unsigned int*)(Data234 + 2), (unsigned int*)(Data234 + 3), (unsigned int*)(Data234 + 4), (unsigned int*)(Data234 + 5), + (unsigned int*)(Data234 + 6), (unsigned int*)(Data234 + 7), (unsigned int*)(Data234 + 8), (unsigned int*)(Data234 + 9)); guid.Data2 = Data12[0]; guid.Data3 = Data12[1]; @@ -39,10 +38,9 @@ GUID WStringToGUID(wchar_t* lpString) s_wstrcpy(szTemp, GUIDStringLength, lpString); swscanf( - szTemp, GUIDFormatWString, (unsigned int*)(&guid.Data1), (unsigned int*)(Data12 + 0), - (unsigned int*)(Data12 + 1), (unsigned int*)(Data234 + 2), (unsigned int*)(Data234 + 3), - (unsigned int*)(Data234 + 4), (unsigned int*)(Data234 + 5), (unsigned int*)(Data234 + 6), - (unsigned int*)(Data234 + 7), (unsigned int*)(Data234 + 8), (unsigned int*)(Data234 + 9)); + szTemp, GUIDFormatWString, (unsigned int*)(&guid.Data1), (unsigned int*)(Data12 + 0), (unsigned int*)(Data12 + 1), + (unsigned int*)(Data234 + 2), (unsigned int*)(Data234 + 3), (unsigned int*)(Data234 + 4), (unsigned int*)(Data234 + 5), + (unsigned int*)(Data234 + 6), (unsigned int*)(Data234 + 7), (unsigned int*)(Data234 + 8), (unsigned int*)(Data234 + 9)); guid.Data2 = Data12[0]; guid.Data3 = Data12[1]; @@ -60,16 +58,16 @@ GUID WStringToGUID(wchar_t* lpString) const char* GUIDToString(const GUID* guid, char* lpGuidBuf) { sprintf( - lpGuidBuf, GUIDFormatString, (unsigned int)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], - guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); + lpGuidBuf, GUIDFormatString, (unsigned int)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2], + guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); return lpGuidBuf; }; const wchar_t* GUIDToWString(const GUID* guid, wchar_t* lpGuidBuf) { wprintf( - lpGuidBuf, GUIDFormatWString, (unsigned int)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], - guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); + lpGuidBuf, GUIDFormatWString, (unsigned int)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2], + guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); return lpGuidBuf; }; @@ -78,8 +76,8 @@ const char* StringToGUIDClassName(const char* strguid, char* lpGuidBuf) { GUID guid = StringToGUID(strguid); sprintf( - lpGuidBuf, GUIDClassName, guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], - guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); + lpGuidBuf, GUIDClassName, guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], + guid.Data4[5], guid.Data4[6], guid.Data4[7]); return 0; } diff --git a/stdcrt/stdlib/compat_proctol.c b/stdcrt/stdlib/compat_proctl.c similarity index 87% rename from stdcrt/stdlib/compat_proctol.c rename to stdcrt/stdlib/compat_proctl.c index f7b131a67f8a9b35655c6589aa13bfd04c14a71f..3902afa4cfb46dee20e723e9f57881b7864df365 100644 --- a/stdcrt/stdlib/compat_proctol.c +++ b/stdcrt/stdlib/compat_proctl.c @@ -1,6 +1,6 @@ #include -_pid_t GetProcessid(void) +_pid_t get_processid(void) { _pid_t p; #if (TARGET_OS == OS_WIN) @@ -12,7 +12,7 @@ _pid_t GetProcessid(void) #endif return p; } -_pid_instance GetInstance(void) +_pid_instance get_instance(void) { _pid_instance p; #if (TARGET_OS == OS_WIN) diff --git a/stdcrt/stdlib/compat_rbtree.c b/stdcrt/stdlib/compat_rbtree.c index 974583160ab4523c2b947f48a73287c20fe1628e..a7a2ae6b24ecfd5fbd09f2cb611edf1109506405 100644 --- a/stdcrt/stdlib/compat_rbtree.c +++ b/stdcrt/stdlib/compat_rbtree.c @@ -24,8 +24,7 @@ static inline void rb_set_parent_color(struct _rbtree_node* rb, struct _rbtree_n rb->__rb_parent_color = (unsigned long)p | color; } -static inline void __rb_change_child( - struct _rbtree_node* old, struct _rbtree_node* _new, struct _rbtree_node* parent, struct _rbtree_root* root) +static inline void __rb_change_child(struct _rbtree_node* old, struct _rbtree_node* _new, struct _rbtree_node* parent, struct _rbtree_root* root) { if (parent) { if (parent->rb_left == old) @@ -41,8 +40,7 @@ static inline void __rb_change_child( * - old's parent and color get assigned to new * - old gets assigned new as a parent and 'color' as a color. */ -static inline void - __rb_rotate_set_parents(struct _rbtree_node* old, struct _rbtree_node* _new, struct _rbtree_root* root, int color) +static inline void __rb_rotate_set_parents(struct _rbtree_node* old, struct _rbtree_node* _new, struct _rbtree_root* root, int color) { struct _rbtree_node* parent = rb_parent(old); _new->__rb_parent_color = old->__rb_parent_color; @@ -55,10 +53,7 @@ static void #else static __always_inline void #endif - __rb_insert( - struct _rbtree_node* node, - struct _rbtree_root* root, - void (*augment_rotate)(struct _rbtree_node* old, struct _rbtree_node* _new)) + __rb_insert(struct _rbtree_node* node, struct _rbtree_root* root, void (*augment_rotate)(struct _rbtree_node* old, struct _rbtree_node* _new)) { struct _rbtree_node *parent = rb_red_parent(node), *gparent, *tmp; @@ -189,9 +184,7 @@ static void static __always_inline void #endif ____rb_erase_color( - struct _rbtree_node* parent, - struct _rbtree_root* root, - void (*augment_rotate)(struct _rbtree_node* old, struct _rbtree_node* _new)) + struct _rbtree_node* parent, struct _rbtree_root* root, void (*augment_rotate)(struct _rbtree_node* old, struct _rbtree_node* _new)) { struct _rbtree_node *node = NULL, *sibling, *tmp1, *tmp2; @@ -378,8 +371,7 @@ static struct _rbtree_node* #else static __always_inline struct _rbtree_node* #endif - __rb_erase_augmented( - struct _rbtree_node* node, struct _rbtree_root* root, const struct rb_augment_callbacks* augment) + __rb_erase_augmented(struct _rbtree_node* node, struct _rbtree_root* root, const struct rb_augment_callbacks* augment) { struct _rbtree_node *child = node->rb_right, *tmp = node->rb_left; struct _rbtree_node *parent, *rebalance; diff --git a/stdcrt_test/main.c b/stdcrt_test/main.c index d9d118625980d15699d459cbd6f8c4c8f5912d9b..edd43796b346a66b07bd29ad2ed464948924a02d 100644 --- a/stdcrt_test/main.c +++ b/stdcrt_test/main.c @@ -86,9 +86,7 @@ int pipe_read_proc(evoper_t* oper, _sock_t s, short event, void* arg) logi("read error"); } else if (oper->mask & op_ev_read) { _thread_id tid = _get_cthreadid(); - logi( - "pipe_read_proc %u %u len:%u threadid:%u==>count==>%ld", oper->error, oper->r.ptr[0], oper->r.len, tid, - oper->ref); + logi("pipe_read_proc %u %u len:%u threadid:%u==>count==>%ld", oper->error, oper->r.ptr[0], oper->r.len, tid, oper->ref); _mutex_lock(&lock); @@ -105,9 +103,7 @@ int pipe_write_proc(evoper_t* oper, _sock_t s, short event, void* arg) } else if (oper->mask & op_ev_write) { _thread_id tid = _get_cthreadid(); ax = ax + 1; - logi( - "pipe_write_proc %u %u len:%u threadid:%u==>count==>%ld", oper->error, oper->w.ptr[0], oper->w.len, tid, - oper->ref); + logi("pipe_write_proc %u %u len:%u threadid:%u==>count==>%ld", oper->error, oper->w.ptr[0], oper->w.len, tid, oper->ref); s_memset(oper->w.ptr, 0, 1024); _sem_post(&sem5); } @@ -218,9 +214,9 @@ void thread_proc2(void* pthis) } } -//#pragma comment(lib, "kernel32.lib") -//#pragma comment(lib, "shell32.lib") -//#pragma comment(linker, "/ENTRY:main") +// #pragma comment(lib, "kernel32.lib") +// #pragma comment(lib, "shell32.lib") +// #pragma comment(linker, "/ENTRY:main") #if (TARGET_OS == OS_POSIX) @@ -239,18 +235,10 @@ void __attribute__((used)) pre_exit(void) int main(int argc, char* argv[]) { - /* + initsockenv(2, 2); - const WCHAR* pWCHAR = L"1111"; - char szBuf[40] = {0x00}; - int ax = wchar_to_char_s(pWCHAR, s_wstrlen(pWCHAR), szBuf, 40); - - const char* pCHAR = "111"; - WCHAR szwBuf[40] = {0x00}; - int awx = char_to_wchar_s(pCHAR, s_strlen(pCHAR), szwBuf, 40); - - test_ace(); + //test_ace(); int rc = 0; // test_rbtree(); @@ -373,7 +361,6 @@ int main(int argc, char* argv[]) evloop_run(&loop, 50000); uninitsockenv(2, 2); - */ - + return 0; } diff --git a/stdcrt_test/test_unixsock.c b/stdcrt_test/test_unixsock.c index 4ebc5adcbec8cd3479a95ae89f02d4839dbe5697..57f507b2589e90b7550f8f1cca011ee26a01d46b 100644 --- a/stdcrt_test/test_unixsock.c +++ b/stdcrt_test/test_unixsock.c @@ -8,8 +8,8 @@ int create_slocalsock(evoper_t* s, const SafeStringPtr* addr) s->sock = INVALID_SOCKET; s->type = EVOP_SUDS; - s->sock = _bind_unixsock(addr->ptr, addr->len, AF_UNIX, SOCK_STREAM, 0); - rc_assert(s->sock != INVALID_SOCKET, S_ERROR); + s->sock = socket(AF_UNIX, SOCK_STREAM, 0); + _bind_unixsock(s->sock, addr->ptr, addr->len, AF_UNIX); return S_SUCCESS; } @@ -21,9 +21,8 @@ int create_clocalsock(evoper_t* s, const SafeStringPtr* addr) s->sock = INVALID_SOCKET; s->type = EVOP_CUDS; - s->sock = _connect_unixsock(addr->ptr, addr->len, AF_UNIX, SOCK_STREAM, 0); - rc_assert(s->sock != INVALID_SOCKET, S_ERROR); - + s->sock = socket(AF_UNIX, SOCK_STREAM, 0); + _connect_unixsock(s->sock, addr->ptr, addr->len, AF_UNIX); return S_SUCCESS; } @@ -35,7 +34,8 @@ int create_stcpsock(evoper_t* s, const SafeStringPtr* addr, int listen, unsigned s->sock = INVALID_SOCKET; s->type = EVOP_STSOCK; - s->sock = _bind_stcpsockv4(addr->ptr, addr->len, listen, port & UINT_MAX); + s->sock = _createsock(AF_INET, SOCK_STREAM, IPPROTO_TCP); + _bind_stcpsockv4(s->sock, addr->ptr, addr->len, listen, port & UINT_MAX); rc_assert(s->sock != INVALID_SOCKET, S_ERROR); return S_SUCCESS; } @@ -48,7 +48,8 @@ int create_ctcpsock(evoper_t* s, const SafeStringPtr* addr, unsigned short port) s->sock = INVALID_SOCKET; s->type = EVOP_CTSOCK; - s->sock = _connect_ctcpsockv4(addr->ptr, addr->len, port & UINT_MAX); + s->sock = _createsock(AF_INET, SOCK_STREAM, IPPROTO_TCP); + _connect_ctcpsockv4(s->sock, addr->ptr, addr->len, port & UINT_MAX); rc_assert(s->sock != INVALID_SOCKET, S_ERROR); return S_SUCCESS; } diff --git a/testmain/main.cpp b/testmain/main.cpp index 2c5f142c6845fc7460f381e57a499312bcac824f..a32ae69d3c3fd48bb1244ef42d83fe7107e65ea5 100644 --- a/testmain/main.cpp +++ b/testmain/main.cpp @@ -74,8 +74,7 @@ int main_t(_pid_t pid, int argc, TCHAR* argv[]) index = index + 1; #endif - hr = com.RegisterComponent( - rid, CLSID_AppView, "AppView.impl.V1", pBase, index, "appview", STD_COMPOENT | STD_INIT /*| STD_START*/); + hr = com.RegisterComponent(rid, CLSID_AppView, "AppView.impl.V1", pBase, index, "appview", STD_COMPOENT | STD_INIT /*| STD_START*/); rc_assert(hr == S_OK, S_ERROR); @@ -87,7 +86,7 @@ int main_t(_pid_t pid, int argc, TCHAR* argv[]) hr = com.UnInitContainer(rid); rc_assert(hr == S_OK, S_ERROR) - logi("test_main_DestroyContainer"); + logi("test_main_DestroyContainer"); return 0; } @@ -110,9 +109,9 @@ int main(int argc, char* argv[]) #elif (TARGET_OS == OS_WIN) -//#pragma comment(lib,"Kernel32.lib") -//#pragma comment(lib,"comctl32.lib") -//#pragma comment(linker,"/subsystem:windows /entry:WinMain") +// #pragma comment(lib,"Kernel32.lib") +// #pragma comment(lib,"comctl32.lib") +// #pragma comment(linker,"/subsystem:windows /entry:WinMain") int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { diff --git a/uibase/stdafx.h b/uibase/stdafx.h index c4483379690564b709c05e995d75ee2c7edcd048..fa4d924ad30e2eaa0204a19e06a33e5705c8d5d9 100644 --- a/uibase/stdafx.h +++ b/uibase/stdafx.h @@ -17,9 +17,9 @@ #if (TARGET_OS == OS_WIN) -//#ifndef _WIN32_WINNT -//#define _WIN32_WINNT 0x0500 -//#endif +// #ifndef _WIN32_WINNT +// #define _WIN32_WINNT 0x0500 +// #endif #include "uilib/uilib.h" #include "uilib/dpi.hpp" diff --git a/uibase/uilib/control/uibutton.cpp b/uibase/uilib/control/uibutton.cpp index f423883a4fe0487b4263bc1e7c4e55201d057d27..c74d39f0b7dd812c9e3fb0c7ad2488ab01805426 100644 --- a/uibase/uilib/control/uibutton.cpp +++ b/uibase/uilib/control/uibutton.cpp @@ -4,8 +4,8 @@ namespace uilib { CButtonUI::CButtonUI() : - m_uButtonState(0), m_dwHotTextColor(0), m_dwPushedTextColor(0), m_dwFocusedTextColor(0), m_dwHotBkColor(0), - m_uFadeAlphaDelta(0), m_uFadeAlpha(255) + m_uButtonState(0), m_dwHotTextColor(0), m_dwPushedTextColor(0), m_dwFocusedTextColor(0), m_dwHotBkColor(0), m_uFadeAlphaDelta(0), + m_uFadeAlpha(255) { m_uTextStyle = DT_SINGLELINE | DT_VCENTER | DT_CENTER; } diff --git a/uibase/uilib/control/uicombo.cpp b/uibase/uilib/control/uicombo.cpp index 93340b3efbea1caf8fa336946937f4b8f2d16a59..cd75fbcd85e764673b62469e03ae6fb7318ebb68 100644 --- a/uibase/uilib/control/uicombo.cpp +++ b/uibase/uilib/control/uicombo.cpp @@ -80,13 +80,11 @@ bool CComboBodyUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopContro RECT rcPadding = pControl->GetPadding(); const RECT& rcPos = pControl->GetPos(); RECT rcBottomLine = { - rcPos.left, rcPos.bottom + rcPadding.bottom, rcPos.right, - rcPos.bottom + rcPadding.bottom + pListInfo->iHLineSize}; + rcPos.left, rcPos.bottom + rcPadding.bottom, rcPos.right, rcPos.bottom + rcPadding.bottom + pListInfo->iHLineSize}; if (::IntersectRect(&rcTemp, &rcPaint, &rcBottomLine)) { rcBottomLine.top += pListInfo->iHLineSize / 2; rcBottomLine.bottom = rcBottomLine.top; - CRenderEngine::DrawLine( - hDC, rcBottomLine, pListInfo->iHLineSize, GetAdjustColor(pListInfo->dwHLineColor)); + CRenderEngine::DrawLine(hDC, rcBottomLine, pListInfo->iHLineSize, GetAdjustColor(pListInfo->dwHLineColor)); } } } diff --git a/uibase/uilib/control/uidatetime.cpp b/uibase/uilib/control/uidatetime.cpp index fd29f872d4d188402455b4408f9c1908b2b5128f..122e47067fbf5504340739e9d6a16e3042d98c0b 100644 --- a/uibase/uilib/control/uidatetime.cpp +++ b/uibase/uilib/control/uidatetime.cpp @@ -248,8 +248,7 @@ void CDateTimeUI::UpdateText() SetText(_T("")); else if (m_nDTUpdateFlag == DT_UPDATE) { CDuiString sText; - sText.SmallFormat( - _T("%4d-%02d-%02d"), m_sysTime.wYear, m_sysTime.wMonth, m_sysTime.wDay, m_sysTime.wHour, m_sysTime.wMinute); + sText.SmallFormat(_T("%4d-%02d-%02d"), m_sysTime.wYear, m_sysTime.wMonth, m_sysTime.wDay, m_sysTime.wHour, m_sysTime.wMinute); SetText(sText); } } diff --git a/uibase/uilib/control/uiedit.cpp b/uibase/uilib/control/uiedit.cpp index b0ab023032d8257e71a541a70b0156d5600982f3..709319ce4ab256a8131bae946d06942f299b14b3 100644 --- a/uibase/uilib/control/uiedit.cpp +++ b/uibase/uilib/control/uiedit.cpp @@ -251,8 +251,8 @@ CEditWnd::OnEditChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOO // CEditUI::CEditUI() : - m_pWindow(NULL), m_uMaxChar(255), m_bReadOnly(false), m_bPasswordMode(false), m_cPasswordChar(_T('*')), - m_bAutoSelAll(false), m_uButtonState(0), m_dwEditbkColor(0xFFFFFFFF), m_iWindowStyls(0) + m_pWindow(NULL), m_uMaxChar(255), m_bReadOnly(false), m_bPasswordMode(false), m_cPasswordChar(_T('*')), m_bAutoSelAll(false), m_uButtonState(0), + m_dwEditbkColor(0xFFFFFFFF), m_iWindowStyls(0) { SetTextPadding(CDuiRect(4, 3, 4, 3)); SetBkColor(0xFFFFFFFF); @@ -700,8 +700,7 @@ void CEditUI::PaintText(HDC hDC) if (IsEnabled()) { CRenderEngine::DrawText(hDC, m_pManager, rc, sText, m_dwTextColor, m_iFont, DT_SINGLELINE | m_uTextStyle); } else { - CRenderEngine::DrawText( - hDC, m_pManager, rc, sText, m_dwDisabledTextColor, m_iFont, DT_SINGLELINE | m_uTextStyle); + CRenderEngine::DrawText(hDC, m_pManager, rc, sText, m_dwDisabledTextColor, m_iFont, DT_SINGLELINE | m_uTextStyle); } } } // namespace uilib diff --git a/uibase/uilib/control/uigifanim.cpp b/uibase/uilib/control/uigifanim.cpp index c83daf5a71ad3d22cb4c2ed0984a6c2931bb96be..629a8c6eaf1ddd7917f77ff199f11978e0288d89 100644 --- a/uibase/uilib/control/uigifanim.cpp +++ b/uibase/uilib/control/uigifanim.cpp @@ -214,8 +214,7 @@ void CGifAnimUI::DrawFrame(HDC hDC) return; GUID pageGuid = Gdiplus::FrameDimensionTime; Gdiplus::Graphics graphics(hDC); - graphics.DrawImage( - m_pGifImage, m_rcItem.left, m_rcItem.top, m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top); + graphics.DrawImage(m_pGifImage, m_rcItem.left, m_rcItem.top, m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top); m_pGifImage->SelectActiveFrame(&pageGuid, m_nFramePosition); } @@ -228,8 +227,7 @@ Gdiplus::Image* CGifAnimUI::LoadGifFromFile(LPSTRING pstrGifPath) CDuiString sFile = CPaintManagerUI::GetResourcePath(); sFile += pstrGifPath; - HANDLE hFile = ::CreateFile( - sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) break; dwSize = ::GetFileSize(hFile, NULL); @@ -252,8 +250,7 @@ Gdiplus::Image* CGifAnimUI::LoadGifFromFile(LPSTRING pstrGifPath) } while (0); while (!pData) { - HANDLE hFile = - ::CreateFile(pstrGifPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hFile = ::CreateFile(pstrGifPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) break; dwSize = ::GetFileSize(hFile, NULL); diff --git a/uibase/uilib/control/uilabel.cpp b/uibase/uilib/control/uilabel.cpp index e229388135c8cdc927e7be1f99a2bc969df9f982..6eb1981a45cb2603efff0baff2cc72e1e45d9d12 100644 --- a/uibase/uilib/control/uilabel.cpp +++ b/uibase/uilib/control/uilabel.cpp @@ -14,10 +14,10 @@ Color ARGB2Color(DWORD dwColor) } CLabelUI::CLabelUI() : - m_pWideText(0), m_uTextStyle(DT_VCENTER | DT_SINGLELINE), m_dwTextColor(0), m_dwDisabledTextColor(0), m_iFont(-1), - m_bShowHtml(false), m_bNeedEstimateSize(true), m_EnableEffect(false), m_bEnableLuminous(false), m_fLuminousFuzzy(3), - m_gdiplusToken(0), m_dwTextColor1(-1), m_dwTextShadowColorA(0xff000000), m_dwTextShadowColorB(-1), - m_GradientAngle(0), m_EnabledStroke(false), m_dwStrokeColor(0), m_EnabledShadow(false), m_GradientLength(0) + m_pWideText(0), m_uTextStyle(DT_VCENTER | DT_SINGLELINE), m_dwTextColor(0), m_dwDisabledTextColor(0), m_iFont(-1), m_bShowHtml(false), + m_bNeedEstimateSize(true), m_EnableEffect(false), m_bEnableLuminous(false), m_fLuminousFuzzy(3), m_gdiplusToken(0), m_dwTextColor1(-1), + m_dwTextShadowColorA(0xff000000), m_dwTextShadowColorB(-1), m_GradientAngle(0), m_EnabledStroke(false), m_dwStrokeColor(0), + m_EnabledShadow(false), m_GradientLength(0) { m_ShadowOffset.X = 0.0f; m_ShadowOffset.Y = 0.0f; @@ -183,8 +183,7 @@ SIZE CLabelUI::EstimateSize(SIZE szAvailable) if (m_cxyFixed.cx > 0 && m_cxyFixed.cy > 0) return m_cxyFixed; - if ((m_uTextStyle & DT_SINGLELINE) == 0 - && (szAvailable.cx != m_szAvailableLast.cx || szAvailable.cy != m_szAvailableLast.cy)) { + if ((m_uTextStyle & DT_SINGLELINE) == 0 && (szAvailable.cx != m_szAvailableLast.cx || szAvailable.cy != m_szAvailableLast.cy)) { m_bNeedEstimateSize = true; } @@ -206,8 +205,7 @@ SIZE CLabelUI::EstimateSize(SIZE szAvailable) DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER); } else { CRenderEngine::DrawText( - m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, m_iFont, - DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER); + m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, m_iFont, DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER); } m_cxyFixedLast.cx = rcText.right - rcText.left + m_rcTextPadding.left + m_rcTextPadding.right; } @@ -225,8 +223,7 @@ SIZE CLabelUI::EstimateSize(SIZE szAvailable) DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER); } else { CRenderEngine::DrawText( - m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, m_iFont, - DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER); + m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, m_iFont, DT_CALCRECT | m_uTextStyle & ~DT_RIGHT & ~DT_CENTER); } m_cxyFixedLast.cy = rcText.bottom - rcText.top + m_rcTextPadding.top + m_rcTextPadding.bottom; } @@ -378,14 +375,12 @@ void CLabelUI::PaintText(HDC hDC) int nLinks = 0; if (IsEnabled()) { if (m_bShowHtml) - CRenderEngine::DrawHtmlText( - hDC, m_pManager, rc, m_sText, m_dwTextColor, NULL, NULL, nLinks, m_iFont, m_uTextStyle); + CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, NULL, NULL, nLinks, m_iFont, m_uTextStyle); else CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, m_iFont, m_uTextStyle); } else { if (m_bShowHtml) - CRenderEngine::DrawHtmlText( - hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, NULL, NULL, nLinks, m_iFont, m_uTextStyle); + CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, NULL, NULL, nLinks, m_iFont, m_uTextStyle); else CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, m_iFont, m_uTextStyle); } @@ -461,8 +456,7 @@ void CLabelUI::PaintText(HDC hDC) if (GetEnabledStroke() && GetStrokeColor() > 0) { LinearGradientBrush nLineGrBrushStroke( - Point(GetGradientAngle(), 0), Point(0, rc.bottom - rc.top + 2), ARGB2Color(GetStrokeColor()), - ARGB2Color(GetStrokeColor())); + Point(GetGradientAngle(), 0), Point(0, rc.bottom - rc.top + 2), ARGB2Color(GetStrokeColor()), ARGB2Color(GetStrokeColor())); #ifdef _UNICODE nRc.Offset(-1, 0); nGraphics.DrawString(m_sText, m_sText.GetLength(), &nFont, nRc, &format, &nLineGrBrushStroke); diff --git a/uibase/uilib/control/uilist.cpp b/uibase/uilib/control/uilist.cpp index 17b42aa53fdd81d68ab95285e215b83fba707a61..9a3d14b331d499a2f03529dae21129f694460171 100644 --- a/uibase/uilib/control/uilist.cpp +++ b/uibase/uilib/control/uilist.cpp @@ -1371,8 +1371,7 @@ void CListBodyUI::SetPos(RECT rc, bool bNeedInvalidate) sz.cx = pControl->GetMinWidth(); RECT rcCtrl = { - iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + rcPadding.left + sz.cx, - iPosY + sz.cy + rcPadding.top + rcPadding.bottom}; + iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + rcPadding.left + sz.cx, iPosY + sz.cy + rcPadding.top + rcPadding.bottom}; pControl->SetPos(rcCtrl, false); iPosY += sz.cy + iChildPadding + rcPadding.top + rcPadding.bottom; @@ -1397,8 +1396,7 @@ void CListBodyUI::DoEvent(TEventUI& event) if (m_pOwner != NULL) { if (event.Type == UIEVENT_SCROLLWHEEL) { - if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() - && m_pHorizontalScrollBar->IsEnabled()) { + if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() && m_pHorizontalScrollBar->IsEnabled()) { RECT rcHorizontalScrollBar = m_pHorizontalScrollBar->GetPos(); if (::PtInRect(&rcHorizontalScrollBar, event.ptMouse)) { switch (LOWORD(event.wParam)) { @@ -1480,13 +1478,11 @@ bool CListBodyUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl RECT rcPadding = pControl->GetPadding(); const RECT& rcPos = pControl->GetPos(); RECT rcBottomLine = { - rcPos.left, rcPos.bottom + rcPadding.bottom, rcPos.right, - rcPos.bottom + rcPadding.bottom + pListInfo->iHLineSize}; + rcPos.left, rcPos.bottom + rcPadding.bottom, rcPos.right, rcPos.bottom + rcPadding.bottom + pListInfo->iHLineSize}; if (::IntersectRect(&rcTemp, &rcPaint, &rcBottomLine)) { rcBottomLine.top += pListInfo->iHLineSize / 2; rcBottomLine.bottom = rcBottomLine.top; - CRenderEngine::DrawLine( - hDC, rcBottomLine, pListInfo->iHLineSize, GetAdjustColor(pListInfo->dwHLineColor)); + CRenderEngine::DrawLine(hDC, rcBottomLine, pListInfo->iHLineSize, GetAdjustColor(pListInfo->dwHLineColor)); } } } @@ -1576,8 +1572,8 @@ SIZE CListHeaderUI::EstimateSize(SIZE szAvailable) // CListHeaderItemUI::CListHeaderItemUI() : - m_bDragable(true), m_uButtonState(0), m_iSepWidth(4), m_uTextStyle(DT_CENTER | DT_VCENTER | DT_SINGLELINE), - m_dwTextColor(0), m_dwSepColor(0), m_iFont(-1), m_bShowHtml(false) + m_bDragable(true), m_uButtonState(0), m_iSepWidth(4), m_uTextStyle(DT_CENTER | DT_VCENTER | DT_SINGLELINE), m_dwTextColor(0), m_dwSepColor(0), + m_iFont(-1), m_bShowHtml(false) { SetTextPadding(CDuiRect(2, 0, 2, 0)); ptLastMouse.x = ptLastMouse.y = 0; @@ -1992,8 +1988,7 @@ void CListHeaderItemUI::PaintStatusImage(HDC hDC) m_diSep.rcDestOffset.bottom = rcThumb.bottom - m_rcItem.top; if (!DrawImage(hDC, m_diSep)) { if (m_dwSepColor != 0) { - RECT rcSepLine = { - rcThumb.left + m_iSepWidth / 2, rcThumb.top, rcThumb.left + m_iSepWidth / 2, rcThumb.bottom}; + RECT rcSepLine = {rcThumb.left + m_iSepWidth / 2, rcThumb.top, rcThumb.left + m_iSepWidth / 2, rcThumb.bottom}; CRenderEngine::DrawLine(hDC, rcSepLine, m_iSepWidth, GetAdjustColor(m_dwSepColor)); } } @@ -2015,8 +2010,7 @@ void CListHeaderItemUI::PaintText(HDC hDC) return; int nLinks = 0; if (m_bShowHtml) - CRenderEngine::DrawHtmlText( - hDC, m_pManager, rcText, m_sText, m_dwTextColor, NULL, NULL, nLinks, m_iFont, m_uTextStyle); + CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, m_sText, m_dwTextColor, NULL, NULL, nLinks, m_iFont, m_uTextStyle); else CRenderEngine::DrawText(hDC, m_pManager, rcText, m_sText, m_dwTextColor, m_iFont, m_uTextStyle); } @@ -2275,8 +2269,7 @@ void CListElementUI::DrawItemBk(HDC hDC, const RECT& rcItem) // // -CListLabelElementUI::CListLabelElementUI() : - m_bNeedEstimateSize(true), m_uFixedHeightLast(0), m_nFontLast(-1), m_uTextStyleLast(0) +CListLabelElementUI::CListLabelElementUI() : m_bNeedEstimateSize(true), m_uFixedHeightLast(0), m_nFontLast(-1), m_uTextStyleLast(0) { m_szAvailableLast.cx = m_szAvailableLast.cy = 0; m_cxyFixedLast.cx = m_cxyFixedLast.cy = 0; @@ -2386,15 +2379,12 @@ SIZE CListLabelElementUI::EstimateSize(SIZE szAvailable) return CDuiSize(m_cxyFixed.cx, pInfo->uFixedHeight); } - if ((pInfo->uTextStyle & DT_SINGLELINE) == 0 - && (szAvailable.cx != m_szAvailableLast.cx || szAvailable.cy != m_szAvailableLast.cy)) { + if ((pInfo->uTextStyle & DT_SINGLELINE) == 0 && (szAvailable.cx != m_szAvailableLast.cx || szAvailable.cy != m_szAvailableLast.cy)) { m_bNeedEstimateSize = true; } - if (m_uFixedHeightLast != pInfo->uFixedHeight || m_nFontLast != pInfo->nFont - || m_uTextStyleLast != pInfo->uTextStyle || m_rcTextPaddingLast.left != pInfo->rcTextPadding.left - || m_rcTextPaddingLast.right != pInfo->rcTextPadding.right - || m_rcTextPaddingLast.top != pInfo->rcTextPadding.top - || m_rcTextPaddingLast.bottom != pInfo->rcTextPadding.bottom) { + if (m_uFixedHeightLast != pInfo->uFixedHeight || m_nFontLast != pInfo->nFont || m_uTextStyleLast != pInfo->uTextStyle + || m_rcTextPaddingLast.left != pInfo->rcTextPadding.left || m_rcTextPaddingLast.right != pInfo->rcTextPadding.right + || m_rcTextPaddingLast.top != pInfo->rcTextPadding.top || m_rcTextPaddingLast.bottom != pInfo->rcTextPadding.bottom) { m_bNeedEstimateSize = true; } @@ -2444,8 +2434,7 @@ SIZE CListLabelElementUI::EstimateSize(SIZE szAvailable) DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER); } else { CRenderEngine::DrawText( - m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, pInfo->nFont, - DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER); + m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, 0, pInfo->nFont, DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER); } m_cxyFixedLast.cy = rcText.bottom - rcText.top + pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom; } @@ -2488,8 +2477,7 @@ void CListLabelElementUI::DrawItemText(HDC hDC, const RECT& rcItem) rcText.bottom -= pInfo->rcTextPadding.bottom; if (pInfo->bShowHtml) - CRenderEngine::DrawHtmlText( - hDC, m_pManager, rcText, m_sText, iTextColor, NULL, NULL, nLinks, pInfo->nFont, pInfo->uTextStyle); + CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, m_sText, iTextColor, NULL, NULL, nLinks, pInfo->nFont, pInfo->uTextStyle); else CRenderEngine::DrawText(hDC, m_pManager, rcText, m_sText, iTextColor, pInfo->nFont, pInfo->uTextStyle); } @@ -2657,15 +2645,12 @@ SIZE CListTextElementUI::EstimateSize(SIZE szAvailable) return CDuiSize(cxyFixed.cx, pInfo->uFixedHeight); } - if ((pInfo->uTextStyle & DT_SINGLELINE) == 0 - && (szAvailable.cx != m_szAvailableLast.cx || szAvailable.cy != m_szAvailableLast.cy)) { + if ((pInfo->uTextStyle & DT_SINGLELINE) == 0 && (szAvailable.cx != m_szAvailableLast.cx || szAvailable.cy != m_szAvailableLast.cy)) { m_bNeedEstimateSize = true; } - if (m_uFixedHeightLast != pInfo->uFixedHeight || m_nFontLast != pInfo->nFont - || m_uTextStyleLast != pInfo->uTextStyle || m_rcTextPaddingLast.left != pInfo->rcTextPadding.left - || m_rcTextPaddingLast.right != pInfo->rcTextPadding.right - || m_rcTextPaddingLast.top != pInfo->rcTextPadding.top - || m_rcTextPaddingLast.bottom != pInfo->rcTextPadding.bottom) { + if (m_uFixedHeightLast != pInfo->uFixedHeight || m_nFontLast != pInfo->nFont || m_uTextStyleLast != pInfo->uTextStyle + || m_rcTextPaddingLast.left != pInfo->rcTextPadding.left || m_rcTextPaddingLast.right != pInfo->rcTextPadding.right + || m_rcTextPaddingLast.top != pInfo->rcTextPadding.top || m_rcTextPaddingLast.bottom != pInfo->rcTextPadding.bottom) { m_bNeedEstimateSize = true; } @@ -2730,8 +2715,7 @@ SIZE CListTextElementUI::EstimateSize(SIZE szAvailable) DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER); } else { CRenderEngine::DrawText( - m_pManager->GetPaintDC(), m_pManager, rcText, strText, 0, pInfo->nFont, - DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER); + m_pManager->GetPaintDC(), m_pManager, rcText, strText, 0, pInfo->nFont, DT_CALCRECT | pInfo->uTextStyle & ~DT_RIGHT & ~DT_CENTER); } m_cxyFixedLast.cy = rcText.bottom - rcText.top + pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom; } @@ -2765,9 +2749,7 @@ void CListTextElementUI::DrawItemText(HDC hDC, const RECT& rcItem) for (int i = 0; i < pInfo->nColumns; i++) { RECT rcItem = {pInfo->rcColumn[i].left, m_rcItem.top, pInfo->rcColumn[i].right, m_rcItem.bottom}; if (pInfo->iVLineSize > 0 && i < pInfo->nColumns - 1) { - RECT rcLine = { - rcItem.right - pInfo->iVLineSize / 2, rcItem.top, rcItem.right - pInfo->iVLineSize / 2, - rcItem.bottom}; + RECT rcLine = {rcItem.right - pInfo->iVLineSize / 2, rcItem.top, rcItem.right - pInfo->iVLineSize / 2, rcItem.bottom}; CRenderEngine::DrawLine(hDC, rcLine, pInfo->iVLineSize, GetAdjustColor(pInfo->dwVLineColor)); rcItem.right -= pInfo->iVLineSize; } @@ -2777,18 +2759,17 @@ void CListTextElementUI::DrawItemText(HDC hDC, const RECT& rcItem) rcItem.top += pInfo->rcTextPadding.top; rcItem.bottom -= pInfo->rcTextPadding.bottom; - CDuiString strText; //不使用LPCTSTR,否则限制太多 by cddjr 2011/10/20 + CDuiString strText; // 不使用LPCTSTR,否则限制太多 by cddjr 2011/10/20 if (pCallback) strText = pCallback->GetItemText(this, m_iIndex, i); else strText.Assign(GetText(i)); if (pInfo->bShowHtml) CRenderEngine::DrawHtmlText( - hDC, m_pManager, rcItem, strText.GetData(), iTextColor, &m_rcLinks[m_nLinks], &m_sLinks[m_nLinks], - nLinks, pInfo->nFont, pInfo->uTextStyle); + hDC, m_pManager, rcItem, strText.GetData(), iTextColor, &m_rcLinks[m_nLinks], &m_sLinks[m_nLinks], nLinks, pInfo->nFont, + pInfo->uTextStyle); else - CRenderEngine::DrawText( - hDC, m_pManager, rcItem, strText.GetData(), iTextColor, pInfo->nFont, pInfo->uTextStyle); + CRenderEngine::DrawText(hDC, m_pManager, rcItem, strText.GetData(), iTextColor, pInfo->nFont, pInfo->uTextStyle); m_nLinks += nLinks; nLinks = lengthof(m_rcLinks) - m_nLinks; @@ -2809,11 +2790,10 @@ void CListTextElementUI::DrawItemText(HDC hDC, const RECT& rcItem) strText = m_sText; if (pInfo->bShowHtml) CRenderEngine::DrawHtmlText( - hDC, m_pManager, rcItem, strText.GetData(), iTextColor, &m_rcLinks[m_nLinks], &m_sLinks[m_nLinks], - nLinks, pInfo->nFont, pInfo->uTextStyle); + hDC, m_pManager, rcItem, strText.GetData(), iTextColor, &m_rcLinks[m_nLinks], &m_sLinks[m_nLinks], nLinks, pInfo->nFont, + pInfo->uTextStyle); else - CRenderEngine::DrawText( - hDC, m_pManager, rcItem, strText.GetData(), iTextColor, pInfo->nFont, pInfo->uTextStyle); + CRenderEngine::DrawText(hDC, m_pManager, rcItem, strText.GetData(), iTextColor, pInfo->nFont, pInfo->uTextStyle); m_nLinks += nLinks; nLinks = lengthof(m_rcLinks) - m_nLinks; @@ -2830,8 +2810,7 @@ void CListTextElementUI::DrawItemText(HDC hDC, const RECT& rcItem) // CListContainerElementUI::CListContainerElementUI() : - m_iIndex(-1), m_iDrawIndex(0), m_pOwner(NULL), m_bSelected(false), m_bExpandable(false), m_bExpand(false), - m_uButtonState(0) + m_iIndex(-1), m_iDrawIndex(0), m_pOwner(NULL), m_bSelected(false), m_bExpandable(false), m_bExpand(false), m_uButtonState(0) { } @@ -3238,8 +3217,7 @@ void CListHBoxElementUI::SetPos(RECT rc, bool bNeedInvalidate) RECT rcPadding = pControl->GetPadding(); RECT rcItem = { - m_rcItem.left + rcPadding.left, m_rcItem.top + rcPadding.top, m_rcItem.right - rcPadding.right, - m_rcItem.bottom - rcPadding.bottom}; + m_rcItem.left + rcPadding.left, m_rcItem.top + rcPadding.top, m_rcItem.right - rcPadding.right, m_rcItem.bottom - rcPadding.bottom}; pControl->SetPos(rcItem, false); } } @@ -3258,8 +3236,7 @@ bool CListHBoxElementUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStop for (int i = 0; i < pInfo->nColumns; i++) { RECT rcItem = {pInfo->rcColumn[i].left, m_rcItem.top, pInfo->rcColumn[i].right, m_rcItem.bottom}; if (pInfo->iVLineSize > 0 && i < pInfo->nColumns - 1) { - RECT rcLine = { - rcItem.right - pInfo->iVLineSize / 2, rcItem.top, rcItem.right - pInfo->iVLineSize / 2, rcItem.bottom}; + RECT rcLine = {rcItem.right - pInfo->iVLineSize / 2, rcItem.top, rcItem.right - pInfo->iVLineSize / 2, rcItem.bottom}; CRenderEngine::DrawLine(hDC, rcLine, pInfo->iVLineSize, GetAdjustColor(pInfo->dwVLineColor)); } } diff --git a/uibase/uilib/control/uioption.cpp b/uibase/uilib/control/uioption.cpp index 0eb61cc3d60dabe74f5912abb3fda4c55ad34c21..7f9a8417a70e598b01a33265c2cb9aec79bd9a4e 100644 --- a/uibase/uilib/control/uioption.cpp +++ b/uibase/uilib/control/uioption.cpp @@ -276,12 +276,9 @@ void COptionUI::PaintText(HDC hDC) if (m_bShowHtml) CRenderEngine::DrawHtmlText( - hDC, m_pManager, rc, m_sText, IsEnabled() ? m_dwTextColor : m_dwDisabledTextColor, NULL, NULL, nLinks, - m_iFont, m_uTextStyle); + hDC, m_pManager, rc, m_sText, IsEnabled() ? m_dwTextColor : m_dwDisabledTextColor, NULL, NULL, nLinks, m_iFont, m_uTextStyle); else - CRenderEngine::DrawText( - hDC, m_pManager, rc, m_sText, IsEnabled() ? m_dwTextColor : m_dwDisabledTextColor, m_iFont, - m_uTextStyle); + CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, IsEnabled() ? m_dwTextColor : m_dwDisabledTextColor, m_iFont, m_uTextStyle); m_dwTextColor = oldTextColor; } else { diff --git a/uibase/uilib/control/uirichedit.cpp b/uibase/uilib/control/uirichedit.cpp index fb9960720edf0ddae56736cbe4ee1530e37de79c..5d3a9a8fffb30bc11028b1a0437efd4b6947915e 100644 --- a/uibase/uilib/control/uirichedit.cpp +++ b/uibase/uilib/control/uirichedit.cpp @@ -110,8 +110,7 @@ public: virtual BOOL TxSetCaretPos(INT x, INT y); virtual BOOL TxSetTimer(UINT idTimer, UINT uTimeout); virtual void TxKillTimer(UINT idTimer); - virtual void TxScrollWindowEx( - INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll); + virtual void TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll); virtual void TxSetCapture(BOOL fCapture); virtual void TxSetFocus(); virtual void TxSetCursor(HCURSOR hcur, BOOL fText); @@ -549,8 +548,7 @@ void CTxtWinHost::TxKillTimer(UINT idTimer) fTimer = FALSE; } -void CTxtWinHost::TxScrollWindowEx( - INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll) +void CTxtWinHost::TxScrollWindowEx(INT dx, INT dy, LPCRECT lprcScroll, LPCRECT lprcClip, HRGN hrgnUpdate, LPRECT lprcUpdate, UINT fuScroll) { return; } @@ -949,8 +947,7 @@ BOOL CTxtWinHost::DoSetCursor(RECT* prc, POINT* pt) // Is this in our rectangle? if (PtInRect(&rc, *pt)) { RECT* prcClient = (!fInplaceActive || prc) ? &rc : NULL; - pserv->OnTxSetCursor( - DVASPECT_CONTENT, -1, NULL, NULL, m_re->GetManager()->GetPaintDC(), NULL, prcClient, pt->x, pt->y); + pserv->OnTxSetCursor(DVASPECT_CONTENT, -1, NULL, NULL, m_re->GetManager()->GetPaintDC(), NULL, prcClient, pt->x, pt->y); return TRUE; } @@ -1047,9 +1044,9 @@ void CTxtWinHost::SetParaFormat(PARAFORMAT2& p) // CRichEditUI::CRichEditUI() : - m_pTwh(NULL), m_bVScrollBarFixing(false), m_bWantTab(true), m_bWantReturn(true), m_bWantCtrlReturn(true), - m_bTransparent(true), m_bRich(true), m_bReadOnly(false), m_bWordWrap(false), m_dwTextColor(0), m_iFont(-1), - m_iLimitText(cInitTextMax), m_lTwhStyle(ES_MULTILINE), m_bDrawCaret(true), m_bInited(false) + m_pTwh(NULL), m_bVScrollBarFixing(false), m_bWantTab(true), m_bWantReturn(true), m_bWantCtrlReturn(true), m_bTransparent(true), m_bRich(true), + m_bReadOnly(false), m_bWordWrap(false), m_dwTextColor(0), m_iFont(-1), m_iLimitText(cInitTextMax), m_lTwhStyle(ES_MULTILINE), m_bDrawCaret(true), + m_bInited(false) { ::ZeroMemory(&m_rcTextPadding, sizeof(m_rcTextPadding)); } @@ -1942,8 +1939,7 @@ void CRichEditUI::DoEvent(TEventUI& event) m_bDrawCaret = !m_bDrawCaret; POINT ptCaret; ::GetCaretPos(&ptCaret); - RECT rcCaret = { - ptCaret.x, ptCaret.y, ptCaret.x + m_pTwh->GetCaretWidth(), ptCaret.y + m_pTwh->GetCaretHeight()}; + RECT rcCaret = {ptCaret.x, ptCaret.y, ptCaret.x + m_pTwh->GetCaretWidth(), ptCaret.y + m_pTwh->GetCaretHeight()}; RECT rcTemp = rcCaret; if (!::IntersectRect(&rcCaret, &rcTemp, &m_rcItem)) return; @@ -2037,8 +2033,7 @@ void CRichEditUI::SetPos(RECT rc, bool bNeedInvalidate) LONG lHeight = 0; SIZEL szExtent = {-1, -1}; m_pTwh->GetTextServices()->TxGetNaturalSize( - DVASPECT_CONTENT, GetManager()->GetPaintDC(), NULL, NULL, TXTNS_FITTOCONTENT, &szExtent, &lWidth, - &lHeight); + DVASPECT_CONTENT, GetManager()->GetPaintDC(), NULL, NULL, TXTNS_FITTOCONTENT, &szExtent, &lWidth, &lHeight); if (lHeight > rcText.bottom - rcText.top) { m_pVerticalScrollBar->SetVisible(true); m_pVerticalScrollBar->SetScrollPos(0); @@ -2053,15 +2048,12 @@ void CRichEditUI::SetPos(RECT rc, bool bNeedInvalidate) } if (m_pVerticalScrollBar != NULL && m_pVerticalScrollBar->IsVisible()) { - RECT rcScrollBarPos = { - rcScrollView.right, rcScrollView.top, rcScrollView.right + m_pVerticalScrollBar->GetFixedWidth(), - rcScrollView.bottom}; + RECT rcScrollBarPos = {rcScrollView.right, rcScrollView.top, rcScrollView.right + m_pVerticalScrollBar->GetFixedWidth(), rcScrollView.bottom}; m_pVerticalScrollBar->SetPos(rcScrollBarPos, false); } if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible()) { RECT rcScrollBarPos = { - rcScrollView.left, rcScrollView.bottom, rcScrollView.right, - rcScrollView.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; + rcScrollView.left, rcScrollView.bottom, rcScrollView.right, rcScrollView.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; m_pHorizontalScrollBar->SetPos(rcScrollBarPos, false); } @@ -2138,8 +2130,7 @@ bool CRichEditUI::DoPaint(HDC hDC, const RECT& rcPaint, CControlUI* pStopControl LONG lHeight = 0; SIZEL szExtent = {-1, -1}; m_pTwh->GetTextServices()->TxGetNaturalSize( - DVASPECT_CONTENT, GetManager()->GetPaintDC(), NULL, NULL, TXTNS_FITTOCONTENT, &szExtent, &lWidth, - &lHeight); + DVASPECT_CONTENT, GetManager()->GetPaintDC(), NULL, NULL, TXTNS_FITTOCONTENT, &szExtent, &lWidth, &lHeight); if (lHeight <= rc.bottom - rc.top) { NeedUpdate(); } diff --git a/uibase/uilib/control/uiscrollbar.cpp b/uibase/uilib/control/uiscrollbar.cpp index 7feb09a67d7910c5ba294ae3c265736957ecd06e..5f4edd14ea013fae05292d63c617cb3ceefd1ff5 100644 --- a/uibase/uilib/control/uiscrollbar.cpp +++ b/uibase/uilib/control/uiscrollbar.cpp @@ -5,10 +5,9 @@ namespace uilib { CScrollBarUI::CScrollBarUI() : - m_bHorizontal(false), m_nRange(100), m_nScrollPos(0), m_nLineSize(SCROLLBAR_LINESIZE), m_nScrollUnit(1), - m_pOwner(NULL), m_nLastScrollPos(0), m_nLastScrollOffset(0), m_nScrollRepeatDelay(0), m_dwButton1Color(0), - m_uButton1State(0), m_dwButton2Color(0), m_uButton2State(0), m_dwThumbColor(0), m_uThumbState(0), - m_bShowButton1(true), m_bShowButton2(true) + m_bHorizontal(false), m_nRange(100), m_nScrollPos(0), m_nLineSize(SCROLLBAR_LINESIZE), m_nScrollUnit(1), m_pOwner(NULL), m_nLastScrollPos(0), + m_nLastScrollOffset(0), m_nScrollRepeatDelay(0), m_dwButton1Color(0), m_uButton1State(0), m_dwButton2Color(0), m_uButton2State(0), + m_dwThumbColor(0), m_uThumbState(0), m_bShowButton1(true), m_bShowButton2(true) { m_cxyFixed.cx = DEFAULT_SCROLLBAR_SIZE; ptLastMouse.x = ptLastMouse.y = 0; @@ -807,14 +806,12 @@ void CScrollBarUI::DoEvent(TEventUI& event) if ((m_uThumbState & UISTATE_CAPTURED) != 0) { if (!m_bHorizontal) { if (m_pOwner != NULL) - m_pOwner->SetScrollPos( - CDuiSize(m_pOwner->GetScrollPos().cx, m_nLastScrollPos + m_nLastScrollOffset)); + m_pOwner->SetScrollPos(CDuiSize(m_pOwner->GetScrollPos().cx, m_nLastScrollPos + m_nLastScrollOffset)); else SetScrollPos(m_nLastScrollPos + m_nLastScrollOffset); } else { if (m_pOwner != NULL) - m_pOwner->SetScrollPos( - CDuiSize(m_nLastScrollPos + m_nLastScrollOffset, m_pOwner->GetScrollPos().cy)); + m_pOwner->SetScrollPos(CDuiSize(m_nLastScrollPos + m_nLastScrollOffset, m_pOwner->GetScrollPos().cy)); else SetScrollPos(m_nLastScrollPos + m_nLastScrollOffset); } diff --git a/uibase/uilib/control/uislider.cpp b/uibase/uilib/control/uislider.cpp index 798c2d1836795b3a942ef771aaa8e7edb806e7cb..b57fe405fa68304e2a9105c68d2de0f0f5e5aab3 100644 --- a/uibase/uilib/control/uislider.cpp +++ b/uibase/uilib/control/uislider.cpp @@ -55,14 +55,12 @@ void CSliderUI::SetThumbSize(SIZE szXY) RECT CSliderUI::GetThumbRect() const { if (m_bHorizontal) { - int left = - m_rcItem.left + (m_rcItem.right - m_rcItem.left - m_szThumb.cx) * (m_nValue - m_nMin) / (m_nMax - m_nMin); + int left = m_rcItem.left + (m_rcItem.right - m_rcItem.left - m_szThumb.cx) * (m_nValue - m_nMin) / (m_nMax - m_nMin); int top = (m_rcItem.bottom + m_rcItem.top - m_szThumb.cy) / 2; return CDuiRect(left, top, left + m_szThumb.cx, top + m_szThumb.cy); } else { int left = (m_rcItem.right + m_rcItem.left - m_szThumb.cx) / 2; - int top = m_rcItem.bottom - m_szThumb.cy - - (m_rcItem.bottom - m_rcItem.top - m_szThumb.cy) * (m_nValue - m_nMin) / (m_nMax - m_nMin); + int top = m_rcItem.bottom - m_szThumb.cy - (m_rcItem.bottom - m_rcItem.top - m_szThumb.cy) * (m_nValue - m_nMin) / (m_nMax - m_nMin); return CDuiRect(left, top, left + m_szThumb.cx, top + m_szThumb.cy); } } @@ -147,9 +145,9 @@ void CSliderUI::DoEvent(TEventUI& event) else if (event.ptMouse.x <= m_rcItem.left + m_szThumb.cx / 2) nValue = m_nMin; else - nValue = m_nMin - + (m_nMax - m_nMin) * (event.ptMouse.x - m_rcItem.left - m_szThumb.cx / 2) - / (m_rcItem.right - m_rcItem.left - m_szThumb.cx); + nValue = + m_nMin + + (m_nMax - m_nMin) * (event.ptMouse.x - m_rcItem.left - m_szThumb.cx / 2) / (m_rcItem.right - m_rcItem.left - m_szThumb.cx); } else { if (event.ptMouse.y >= m_rcItem.bottom - m_szThumb.cy / 2) nValue = m_nMin; @@ -175,9 +173,9 @@ void CSliderUI::DoEvent(TEventUI& event) else if (event.ptMouse.x <= m_rcItem.left + m_szThumb.cx / 2) m_nValue = m_nMin; else - m_nValue = m_nMin - + (m_nMax - m_nMin) * (event.ptMouse.x - m_rcItem.left - m_szThumb.cx / 2) - / (m_rcItem.right - m_rcItem.left - m_szThumb.cx); + m_nValue = + m_nMin + + (m_nMax - m_nMin) * (event.ptMouse.x - m_rcItem.left - m_szThumb.cx / 2) / (m_rcItem.right - m_rcItem.left - m_szThumb.cx); } else { if (event.ptMouse.y >= m_rcItem.bottom - m_szThumb.cy / 2) m_nValue = m_nMin; @@ -217,9 +215,9 @@ void CSliderUI::DoEvent(TEventUI& event) else if (event.ptMouse.x <= m_rcItem.left + m_szThumb.cx / 2) m_nValue = m_nMin; else - m_nValue = m_nMin - + (m_nMax - m_nMin) * (event.ptMouse.x - m_rcItem.left - m_szThumb.cx / 2) - / (m_rcItem.right - m_rcItem.left - m_szThumb.cx); + m_nValue = + m_nMin + + (m_nMax - m_nMin) * (event.ptMouse.x - m_rcItem.left - m_szThumb.cx / 2) / (m_rcItem.right - m_rcItem.left - m_szThumb.cx); } else { if (event.ptMouse.y >= m_rcItem.bottom - m_szThumb.cy / 2) m_nValue = m_nMin; diff --git a/uibase/uilib/control/uitext.cpp b/uibase/uilib/control/uitext.cpp index 921cbd48d83f33f179e83fdcee06325deca71b9f..aca382de7d5f6bbc3696a57db0141ce6cb73f814 100644 --- a/uibase/uilib/control/uitext.cpp +++ b/uibase/uilib/control/uitext.cpp @@ -138,15 +138,12 @@ void CTextUI::PaintText(HDC hDC) rc.bottom -= m_rcTextPadding.bottom; if (IsEnabled()) { if (m_bShowHtml) - CRenderEngine::DrawHtmlText( - hDC, m_pManager, rc, m_sText, m_dwTextColor, m_rcLinks, m_sLinks, m_nLinks, m_iFont, m_uTextStyle); + CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, m_rcLinks, m_sLinks, m_nLinks, m_iFont, m_uTextStyle); else CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, m_iFont, m_uTextStyle); } else { if (m_bShowHtml) - CRenderEngine::DrawHtmlText( - hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, m_rcLinks, m_sLinks, m_nLinks, m_iFont, - m_uTextStyle); + CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, m_rcLinks, m_sLinks, m_nLinks, m_iFont, m_uTextStyle); else CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, m_iFont, m_uTextStyle); } diff --git a/uibase/uilib/control/uitreeview.cpp b/uibase/uilib/control/uitreeview.cpp index 62c34464fa49d62520cc331d654ffbe1d38d261f..6018b049ef3a587936396d1ed77db89c8e2b94d3 100644 --- a/uibase/uilib/control/uitreeview.cpp +++ b/uibase/uilib/control/uitreeview.cpp @@ -238,8 +238,7 @@ bool CTreeNodeUI::AddAt(CControlUI* pControl, int iIndex) return false; if (!pIndexNode && pTreeView && pTreeView->GetItemAt(GetTreeIndex() + 1)) - pIndexNode = - static_cast(pTreeView->GetItemAt(GetTreeIndex() + 1)->GetInterface(DUI_CTR_TREENODE)); + pIndexNode = static_cast(pTreeView->GetItemAt(GetTreeIndex() + 1)->GetInterface(DUI_CTR_TREENODE)); pControl = CalLocation((CTreeNodeUI*)pControl); diff --git a/uibase/uilib/core/pugixml.cpp b/uibase/uilib/core/pugixml.cpp index 0d34c67f1b3436d65d61af2682c597c0bbeecacc..a0126899d50f022fb3af066b19ebe037ea12af00 100644 --- a/uibase/uilib/core/pugixml.cpp +++ b/uibase/uilib/core/pugixml.cpp @@ -133,8 +133,7 @@ using std::memset; // Some MinGW/GCC versions have headers that erroneously omit LLONG_MIN/LLONG_MAX/ULLONG_MAX // definitions from limits.h in some configurations -#if defined(PUGIXML_HAS_LONG_LONG) && defined(__GNUC__) && !defined(LLONG_MAX) && !defined(LLONG_MIN) \ - && !defined(ULLONG_MAX) +#if defined(PUGIXML_HAS_LONG_LONG) && defined(__GNUC__) && !defined(LLONG_MAX) && !defined(LLONG_MIN) && !defined(ULLONG_MAX) #define LLONG_MIN (-LLONG_MAX - 1LL) #define LLONG_MAX __LONG_LONG_MAX__ #define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) @@ -463,22 +462,18 @@ static const uintptr_t xml_memory_page_value_allocated_mask = 16; static const uintptr_t xml_memory_page_type_mask = 15; // combined masks for string uniqueness -static const uintptr_t xml_memory_page_name_allocated_or_shared_mask = - xml_memory_page_name_allocated_mask | xml_memory_page_contents_shared_mask; -static const uintptr_t xml_memory_page_value_allocated_or_shared_mask = - xml_memory_page_value_allocated_mask | xml_memory_page_contents_shared_mask; +static const uintptr_t xml_memory_page_name_allocated_or_shared_mask = xml_memory_page_name_allocated_mask | xml_memory_page_contents_shared_mask; +static const uintptr_t xml_memory_page_value_allocated_or_shared_mask = xml_memory_page_value_allocated_mask | xml_memory_page_contents_shared_mask; #ifdef PUGIXML_COMPACT #define PUGI__GETHEADER_IMPL(object, page, flags) // unused #define PUGI__GETPAGE_IMPL(header) (header).get_page() #else -#define PUGI__GETHEADER_IMPL(object, page, flags) \ - (((reinterpret_cast(object) - reinterpret_cast(page)) << 8) | (flags)) +#define PUGI__GETHEADER_IMPL(object, page, flags) (((reinterpret_cast(object) - reinterpret_cast(page)) << 8) | (flags)) // this macro casts pointers through void* to avoid 'cast increases required alignment of target // type' warnings #define PUGI__GETPAGE_IMPL(header) \ - static_cast( \ - const_cast(static_cast(reinterpret_cast(&header) - (header >> 8)))) + static_cast(const_cast(static_cast(reinterpret_cast(&header) - (header >> 8)))) #endif #define PUGI__GETPAGE(n) PUGI__GETPAGE_IMPL((n)->header) @@ -674,8 +669,7 @@ struct xml_allocator { return 0; // setup header - ptrdiff_t page_offset = - reinterpret_cast(header) - reinterpret_cast(page) - sizeof(xml_memory_page); + ptrdiff_t page_offset = reinterpret_cast(header) - reinterpret_cast(page) - sizeof(xml_memory_page); assert(page_offset % xml_memory_block_alignment == 0); assert(page_offset >= 0 && static_cast(page_offset) < max_encoded_offset); @@ -684,8 +678,7 @@ struct xml_allocator { // full_size == 0 for large strings that occupy the whole page assert(full_size % xml_memory_block_alignment == 0); assert(full_size < max_encoded_offset || (page->busy_size == full_size && page_offset == 0)); - header->full_size = - static_cast(full_size < max_encoded_offset ? full_size / xml_memory_block_alignment : 0); + header->full_size = static_cast(full_size < max_encoded_offset ? full_size / xml_memory_block_alignment : 0); // round-trip through void* to avoid 'cast increases required alignment of target type' // warning header is guaranteed a pointer-sized alignment, which should be enough for char_t @@ -704,8 +697,7 @@ struct xml_allocator { // deallocate size_t page_offset = sizeof(xml_memory_page) + header->page_offset * xml_memory_block_alignment; - xml_memory_page* page = - reinterpret_cast(static_cast(reinterpret_cast(header) - page_offset)); + xml_memory_page* page = reinterpret_cast(static_cast(reinterpret_cast(header) - page_offset)); // if full_size == 0 then this string occupies the whole page size_t full_size = header->full_size == 0 ? page->busy_size : header->full_size * xml_memory_block_alignment; @@ -809,8 +801,7 @@ private: PUGI__FN xml_memory_page* compact_get_page(const void* object, int header_offset) { - const compact_header* header = - reinterpret_cast(static_cast(object) - header_offset); + const compact_header* header = reinterpret_cast(static_cast(object) - header_offset); return header->get_page(); } @@ -951,8 +942,7 @@ public: if (static_cast(offset) < (65535 << 7)) { // round-trip through void* to silence 'cast increases required alignment of target // type' warnings - uint16_t* base = - reinterpret_cast(static_cast(reinterpret_cast(this) - base_offset)); + uint16_t* base = reinterpret_cast(static_cast(reinterpret_cast(this) - base_offset)); if (*base == 0) { *base = static_cast((offset >> 7) + 1); @@ -986,8 +976,7 @@ public: // round-trip through void* to silence 'cast increases required alignment of target // type' warnings - const uint16_t* base = reinterpret_cast( - static_cast(reinterpret_cast(this) - base_offset)); + const uint16_t* base = reinterpret_cast(static_cast(reinterpret_cast(this) - base_offset)); assert(*base); ptrdiff_t offset = ((*base - 1) << 7) + (_data - 1); @@ -1010,10 +999,7 @@ PUGI__NS_END namespace pugi { struct xml_attribute_struct { - xml_attribute_struct(impl::xml_memory_page* page) : header(page, 0), namevalue_base(0) - { - PUGI__STATIC_ASSERT(sizeof(xml_attribute_struct) == 8); - } + xml_attribute_struct(impl::xml_memory_page* page) : header(page, 0), namevalue_base(0) { PUGI__STATIC_ASSERT(sizeof(xml_attribute_struct) == 8); } impl::compact_header header; @@ -1099,10 +1085,7 @@ struct xml_extra_buffer { struct xml_document_struct : public xml_node_struct, public xml_allocator { - xml_document_struct(xml_memory_page* page) : - xml_node_struct(page, node_document), xml_allocator(page), buffer(0), extra_buffers(0) - { - } + xml_document_struct(xml_memory_page* page) : xml_node_struct(page, node_document), xml_allocator(page), buffer(0), extra_buffers(0) { } const char_t* buffer; @@ -1345,8 +1328,7 @@ inline void remove_attribute(xml_attribute_struct* attr, xml_node_struct* node) attr->next_attribute = 0; } -PUGI__FN_NO_INLINE xml_node_struct* - append_new_node(xml_node_struct* node, xml_allocator& alloc, xml_node_type type = node_element) +PUGI__FN_NO_INLINE xml_node_struct* append_new_node(xml_node_struct* node, xml_allocator& alloc, xml_node_type type = node_element) { if (!alloc.reserve()) return 0; @@ -1456,10 +1438,7 @@ struct utf8_writer { return result + 4; } - static value_type any(value_type result, uint32_t ch) - { - return (ch < 0x10000) ? low(result, ch) : high(result, ch); - } + static value_type any(value_type result, uint32_t ch) { return (ch < 0x10000) ? low(result, ch) : high(result, ch); } }; struct utf16_counter { @@ -1491,10 +1470,7 @@ struct utf16_writer { return result + 2; } - static value_type any(value_type result, uint32_t ch) - { - return (ch < 0x10000) ? low(result, ch) : high(result, ch); - } + static value_type any(value_type result, uint32_t ch) { return (ch < 0x10000) ? low(result, ch) : high(result, ch); } }; struct utf32_counter { @@ -1554,8 +1530,7 @@ struct utf8_decoder { typedef uint8_t type; template - static inline typename Traits::value_type - process(const uint8_t* data, size_t size, typename Traits::value_type result, Traits) + static inline typename Traits::value_type process(const uint8_t* data, size_t size, typename Traits::value_type result, Traits) { const uint8_t utf8_byte_mask = 0x3f; @@ -1572,8 +1547,7 @@ struct utf8_decoder { if ((reinterpret_cast(data) & 3) == 0) { // round-trip through void* to silence 'cast increases required alignment of // target type' warnings - while (size >= 4 - && (*static_cast(static_cast(data)) & 0x80808080) == 0) { + while (size >= 4 && (*static_cast(static_cast(data)) & 0x80808080) == 0) { result = Traits::low(result, data[0]); result = Traits::low(result, data[1]); result = Traits::low(result, data[2]); @@ -1590,21 +1564,18 @@ struct utf8_decoder { size -= 2; } // 1110xxxx -> U+0800-U+FFFF - else if ( - static_cast(lead - 0xE0) < 0x10 && size >= 3 && (data[1] & 0xc0) == 0x80 - && (data[2] & 0xc0) == 0x80) { - result = Traits::low( - result, ((lead & ~0xE0) << 12) | ((data[1] & utf8_byte_mask) << 6) | (data[2] & utf8_byte_mask)); + else if (static_cast(lead - 0xE0) < 0x10 && size >= 3 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80) { + result = Traits::low(result, ((lead & ~0xE0) << 12) | ((data[1] & utf8_byte_mask) << 6) | (data[2] & utf8_byte_mask)); data += 3; size -= 3; } // 11110xxx -> U+10000..U+10FFFF else if ( - static_cast(lead - 0xF0) < 0x08 && size >= 4 && (data[1] & 0xc0) == 0x80 - && (data[2] & 0xc0) == 0x80 && (data[3] & 0xc0) == 0x80) { + static_cast(lead - 0xF0) < 0x08 && size >= 4 && (data[1] & 0xc0) == 0x80 && (data[2] & 0xc0) == 0x80 + && (data[3] & 0xc0) == 0x80) { result = Traits::high( - result, ((lead & ~0xF0) << 18) | ((data[1] & utf8_byte_mask) << 12) - | ((data[2] & utf8_byte_mask) << 6) | (data[3] & utf8_byte_mask)); + result, + ((lead & ~0xF0) << 18) | ((data[1] & utf8_byte_mask) << 12) | ((data[2] & utf8_byte_mask) << 6) | (data[3] & utf8_byte_mask)); data += 4; size -= 4; } @@ -1623,8 +1594,7 @@ template struct utf16_decoder { typedef uint16_t type; template - static inline typename Traits::value_type - process(const uint16_t* data, size_t size, typename Traits::value_type result, Traits) + static inline typename Traits::value_type process(const uint16_t* data, size_t size, typename Traits::value_type result, Traits) { while (size) { uint16_t lead = opt_swap::value ? endian_swap(*data) : *data; @@ -1667,8 +1637,7 @@ template struct utf32_decoder { typedef uint32_t type; template - static inline typename Traits::value_type - process(const uint32_t* data, size_t size, typename Traits::value_type result, Traits) + static inline typename Traits::value_type process(const uint32_t* data, size_t size, typename Traits::value_type result, Traits) { while (size) { uint32_t lead = opt_swap::value ? endian_swap(*data) : *data; @@ -1695,8 +1664,7 @@ struct latin1_decoder { typedef uint8_t type; template - static inline typename Traits::value_type - process(const uint8_t* data, size_t size, typename Traits::value_type result, Traits) + static inline typename Traits::value_type process(const uint8_t* data, size_t size, typename Traits::value_type result, Traits) { while (size) { result = Traits::low(result, *data); @@ -1731,8 +1699,7 @@ struct wchar_decoder { typedef wchar_t type; template - static inline typename Traits::value_type - process(const wchar_t* data, size_t size, typename Traits::value_type result, Traits traits) + static inline typename Traits::value_type process(const wchar_t* data, size_t size, typename Traits::value_type result, Traits traits) { typedef wchar_selector::decoder decoder; @@ -1772,11 +1739,10 @@ static const unsigned char chartype_table[256] = { 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 0, 0, 0, 0, 0, // 112-127 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, // 128+ - 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192}; + 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192}; enum chartypex_t { ctx_special_pcdata = 1, // Any symbol >= 0 and < 32 (except \t, \r, \n), &, <, > @@ -1786,26 +1752,25 @@ enum chartypex_t { ctx_symbol = 16 // Any symbol > 127, a-z, A-Z, 0-9, _, -, . }; -static const unsigned char chartypex_table[256] = { - 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, 3, 2, 3, 3, // 0-15 - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 16-31 - 0, 0, 2, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 16, 16, 0, // 32-47 - 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 3, 0, 1, 0, // 48-63 +static const unsigned char chartypex_table[256] = {3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, 3, 2, 3, 3, // 0-15 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 16-31 + 0, 0, 2, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 16, 16, 0, // 32-47 + 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 3, 0, 1, 0, // 48-63 - 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 64-79 - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 20, // 80-95 - 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 96-111 - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, // 112-127 + 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 64-79 + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 20, // 80-95 + 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 96-111 + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, // 112-127 - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 128+ - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}; + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 128+ + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20}; #ifdef PUGIXML_WCHAR_MODE -#define PUGI__IS_CHARTYPE_IMPL(c, ct, table) \ - ((static_cast(c) < 128 ? table[static_cast(c)] : table[128]) & (ct)) +#define PUGI__IS_CHARTYPE_IMPL(c, ct, table) ((static_cast(c) < 128 ? table[static_cast(c)] : table[128]) & (ct)) #else #define PUGI__IS_CHARTYPE_IMPL(c, ct, table) (table[static_cast(c)] & (ct)) #endif @@ -1830,8 +1795,7 @@ PUGI__FN xml_encoding get_wchar_encoding() return is_little_endian() ? encoding_utf32_le : encoding_utf32_be; } -PUGI__FN bool - parse_declaration_encoding(const uint8_t* data, size_t size, const uint8_t*& out_encoding, size_t& out_length) +PUGI__FN bool parse_declaration_encoding(const uint8_t* data, size_t size, const uint8_t*& out_encoding, size_t& out_length) { #define PUGI__SCANCHAR(ch) \ { \ @@ -1847,9 +1811,7 @@ PUGI__FN bool // check if we have a non-empty XML declaration if (size < 6 - || !( - (data[0] == '<') & (data[1] == '?') & (data[2] == 'x') & (data[3] == 'm') & (data[4] == 'l') - && PUGI__IS_CHARTYPE(data[5], ct_space))) + || !((data[0] == '<') & (data[1] == '?') & (data[2] == 'x') & (data[3] == 'm') & (data[4] == 'l') && PUGI__IS_CHARTYPE(data[5], ct_space))) return false; // scan XML declaration until the encoding field @@ -1943,16 +1905,15 @@ PUGI__FN xml_encoding guess_buffer_encoding(const uint8_t* data, size_t size) const uint8_t* enc = 0; size_t enc_length = 0; - if (d0 == 0x3c && d1 == 0x3f && d2 == 0x78 && d3 == 0x6d - && parse_declaration_encoding(data, size, enc, enc_length)) { + if (d0 == 0x3c && d1 == 0x3f && d2 == 0x78 && d3 == 0x6d && parse_declaration_encoding(data, size, enc, enc_length)) { // iso-8859-1 (case-insensitive) - if (enc_length == 10 && (enc[0] | ' ') == 'i' && (enc[1] | ' ') == 's' && (enc[2] | ' ') == 'o' && enc[3] == '-' - && enc[4] == '8' && enc[5] == '8' && enc[6] == '5' && enc[7] == '9' && enc[8] == '-' && enc[9] == '1') + if (enc_length == 10 && (enc[0] | ' ') == 'i' && (enc[1] | ' ') == 's' && (enc[2] | ' ') == 'o' && enc[3] == '-' && enc[4] == '8' + && enc[5] == '8' && enc[6] == '5' && enc[7] == '9' && enc[8] == '-' && enc[9] == '1') return encoding_latin1; // latin1 (case-insensitive) - if (enc_length == 6 && (enc[0] | ' ') == 'l' && (enc[1] | ' ') == 'a' && (enc[2] | ' ') == 't' - && (enc[3] | ' ') == 'i' && (enc[4] | ' ') == 'n' && enc[5] == '1') + if (enc_length == 6 && (enc[0] | ' ') == 'l' && (enc[1] | ' ') == 'a' && (enc[2] | ' ') == 't' && (enc[3] | ' ') == 'i' + && (enc[4] | ' ') == 'n' && enc[5] == '1') return encoding_latin1; } @@ -1983,8 +1944,7 @@ PUGI__FN xml_encoding get_buffer_encoding(xml_encoding encoding, const void* con return guess_buffer_encoding(data, size); } -PUGI__FN bool - get_mutable_buffer(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) +PUGI__FN bool get_mutable_buffer(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) { size_t length = size / sizeof(char_t); @@ -2014,12 +1974,10 @@ PUGI__FN bool PUGI__FN bool need_endian_swap_utf(xml_encoding le, xml_encoding re) { return (le == encoding_utf16_be && re == encoding_utf16_le) || (le == encoding_utf16_le && re == encoding_utf16_be) - || (le == encoding_utf32_be && re == encoding_utf32_le) - || (le == encoding_utf32_le && re == encoding_utf32_be); + || (le == encoding_utf32_be && re == encoding_utf32_le) || (le == encoding_utf32_le && re == encoding_utf32_be); } -PUGI__FN bool convert_buffer_endian_swap( - char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) +PUGI__FN bool convert_buffer_endian_swap(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) { const char_t* data = static_cast(contents); size_t length = size / sizeof(char_t); @@ -2046,8 +2004,7 @@ PUGI__FN bool convert_buffer_endian_swap( return true; } -template -PUGI__FN bool convert_buffer_generic(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, D) +template PUGI__FN bool convert_buffer_generic(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, D) { const typename D::type* data = static_cast(contents); size_t data_length = size / sizeof(typename D::type); @@ -2073,8 +2030,7 @@ PUGI__FN bool convert_buffer_generic(char_t*& out_buffer, size_t& out_length, co return true; } -PUGI__FN bool convert_buffer( - char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) +PUGI__FN bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) { // get native encoding xml_encoding wchar_encoding = get_wchar_encoding(); @@ -2095,18 +2051,16 @@ PUGI__FN bool convert_buffer( if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be; - return (native_encoding == encoding) - ? convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()) - : convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()); + return (native_encoding == encoding) ? convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()) + : convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()); } // source encoding is utf32 if (encoding == encoding_utf32_be || encoding == encoding_utf32_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be; - return (native_encoding == encoding) - ? convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()) - : convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()); + return (native_encoding == encoding) ? convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()) + : convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()); } // source encoding is latin1 @@ -2117,8 +2071,7 @@ PUGI__FN bool convert_buffer( return false; } #else -template -PUGI__FN bool convert_buffer_generic(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, D) +template PUGI__FN bool convert_buffer_generic(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, D) { const typename D::type* data = static_cast(contents); size_t data_length = size / sizeof(typename D::type); @@ -2153,8 +2106,7 @@ PUGI__FN size_t get_latin1_7bit_prefix_length(const uint8_t* data, size_t size) return size; } -PUGI__FN bool - convert_buffer_latin1(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) +PUGI__FN bool convert_buffer_latin1(char_t*& out_buffer, size_t& out_length, const void* contents, size_t size, bool is_mutable) { const uint8_t* data = static_cast(contents); size_t data_length = size; @@ -2193,8 +2145,7 @@ PUGI__FN bool return true; } -PUGI__FN bool convert_buffer( - char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) +PUGI__FN bool convert_buffer(char_t*& out_buffer, size_t& out_length, xml_encoding encoding, const void* contents, size_t size, bool is_mutable) { // fast path: no conversion required if (encoding == encoding_utf8) @@ -2204,18 +2155,16 @@ PUGI__FN bool convert_buffer( if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be; - return (native_encoding == encoding) - ? convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()) - : convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()); + return (native_encoding == encoding) ? convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()) + : convert_buffer_generic(out_buffer, out_length, contents, size, utf16_decoder()); } // source encoding is utf32 if (encoding == encoding_utf32_be || encoding == encoding_utf32_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be; - return (native_encoding == encoding) - ? convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()) - : convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()); + return (native_encoding == encoding) ? convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()) + : convert_buffer_generic(out_buffer, out_length, contents, size, utf32_decoder()); } // source encoding is latin1 @@ -2285,8 +2234,7 @@ PUGI__FN std::basic_string as_wide_impl(const char* str, size_t size) } #endif -template -inline bool strcpy_insitu_allow(size_t length, const Header& header, uintptr_t header_mask, char_t* target) +template inline bool strcpy_insitu_allow(size_t length, const Header& header, uintptr_t header_mask, char_t* target) { // never reuse shared memory if (header & xml_memory_page_contents_shared_mask) @@ -2305,8 +2253,7 @@ inline bool strcpy_insitu_allow(size_t length, const Header& header, uintptr_t h } template -PUGI__FN bool - strcpy_insitu(String& dest, Header& header, uintptr_t header_mask, const char_t* source, size_t source_length) +PUGI__FN bool strcpy_insitu(String& dest, Header& header, uintptr_t header_mask, const char_t* source, size_t source_length) { if (source_length == 0) { // empty string and null pointer are equivalent, so just deallocate old memory @@ -2845,8 +2792,7 @@ template struct strconv_attribute_impl { PUGI__FN strconv_attribute_t get_strconv_attribute(unsigned int optmask) { - PUGI__STATIC_ASSERT( - parse_escapes == 0x10 && parse_eol == 0x20 && parse_wconv_attribute == 0x40 && parse_wnorm_attribute == 0x80); + PUGI__STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20 && parse_wconv_attribute == 0x40 && parse_wnorm_attribute == 0x80); switch ((optmask >> 4) & 15) // get bitmask for flags (wnorm wconv eol escapes); this // simultaneously checks 4 options from assertion above @@ -2932,9 +2878,7 @@ struct xml_parser { s += 2; } else if (s[0] == '<' && s[1] == '!' && s[2] == '-' && s[3] == '-') { s += 4; - PUGI__SCANFOR( - s[0] == '-' && s[1] == '-' - && s[2] == '>'); // no need for ENDSWITH because --> can't terminate proper doctype + PUGI__SCANFOR(s[0] == '-' && s[1] == '-' && s[2] == '>'); // no need for ENDSWITH because --> can't terminate proper doctype if (!*s) PUGI__THROW_ERROR(status_bad_doctype, s); @@ -3080,9 +3024,7 @@ struct xml_parser { s += (s[1] == '>' ? 2 : 1); // Step over the last ']>'. } else PUGI__THROW_ERROR(status_bad_cdata, s); - } else if ( - s[0] == 'D' && s[1] == 'O' && s[2] == 'C' && s[3] == 'T' && s[4] == 'Y' && s[5] == 'P' - && PUGI__ENDSWITH(s[6], 'E')) { + } else if (s[0] == 'D' && s[1] == 'O' && s[2] == 'C' && s[3] == 'T' && s[4] == 'Y' && s[5] == 'P' && PUGI__ENDSWITH(s[6], 'E')) { s -= 2; if (cursor->parent) @@ -3135,8 +3077,7 @@ struct xml_parser { PUGI__CHECK_ERROR(status_bad_pi, s); // determine node type; stricmp / strcasecmp is not portable - bool declaration = - (target[0] | ' ') == 'x' && (target[1] | ' ') == 'm' && (target[2] | ' ') == 'l' && target + 3 == s; + bool declaration = (target[0] | ' ') == 'x' && (target[1] | ' ') == 'm' && (target[2] | ' ') == 'l' && target + 3 == s; if (declaration ? PUGI__OPTSET(parse_declaration) : PUGI__OPTSET(parse_pi)) { if (declaration) { @@ -3224,7 +3165,7 @@ struct xml_parser { cursor->name = s; PUGI__SCANWHILE_UNROLL(PUGI__IS_CHARTYPE(ss, ct_symbol)); // Scan for a terminator. - PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. + PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. if (ch == '>') { // end of tag @@ -3235,15 +3176,14 @@ struct xml_parser { if (PUGI__IS_CHARTYPE(*s, ct_start_symbol)) // <... #... { - xml_attribute_struct* a = - append_new_attribute(cursor, *alloc); // Make space for this attribute. + xml_attribute_struct* a = append_new_attribute(cursor, *alloc); // Make space for this attribute. if (!a) PUGI__THROW_ERROR(status_out_of_memory, s); a->name = s; // Save the offset. PUGI__SCANWHILE_UNROLL(PUGI__IS_CHARTYPE(ss, ct_symbol)); // Scan for a terminator. - PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. + PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. if (PUGI__IS_CHARTYPE(ch, ct_space)) { PUGI__SKIPWS(); // Eat any whitespace. @@ -3430,10 +3370,7 @@ struct xml_parser { return (s[0] == static_cast(bom)) ? s + 1 : s; } #else - static char_t* parse_skip_bom(char_t* s) - { - return (s[0] == '\xef' && s[1] == '\xbb' && s[2] == '\xbf') ? s + 3 : s; - } + static char_t* parse_skip_bom(char_t* s) { return (s[0] == '\xef' && s[1] == '\xbb' && s[2] == '\xbf') ? s + 3 : s; } #endif static bool has_element_node_siblings(xml_node_struct* node) @@ -3448,8 +3385,7 @@ struct xml_parser { return false; } - static xml_parse_result - parse(char_t* buffer, size_t length, xml_document_struct* xmldoc, xml_node_struct* root, unsigned int optmsk) + static xml_parse_result parse(char_t* buffer, size_t length, xml_document_struct* xmldoc, xml_node_struct* root, unsigned int optmsk) { // early-out for empty documents if (length == 0) @@ -3471,8 +3407,7 @@ struct xml_parser { // perform actual parsing parser.parse_tree(buffer_data, root, optmsk, endch); - xml_parse_result result = - make_parse_result(parser.error_status, parser.error_offset ? parser.error_offset - buffer : 0); + xml_parse_result result = make_parse_result(parser.error_status, parser.error_offset ? parser.error_offset - buffer : 0); assert(result.offset >= 0 && static_cast(result.offset) <= length); if (result) { @@ -3482,8 +3417,7 @@ struct xml_parser { return make_parse_result(status_unrecognized_tag, length - 1); // check if there are any element nodes parsed - xml_node_struct* first_root_child_parsed = - last_root_child ? last_root_child->next_sibling + 0 : root->first_child + 0; + xml_node_struct* first_root_child_parsed = last_root_child ? last_root_child->next_sibling + 0 : root->first_child + 0; if (!PUGI__OPTSET(parse_fragment) && !has_element_node_siblings(first_root_child_parsed)) return make_parse_result(status_no_document_element, length - 1); @@ -3529,8 +3463,7 @@ PUGI__FN xml_encoding get_write_encoding(xml_encoding encoding) return encoding_utf8; } -template -PUGI__FN size_t convert_buffer_output_generic(typename T::value_type dest, const char_t* data, size_t length, D, T) +template PUGI__FN size_t convert_buffer_output_generic(typename T::value_type dest, const char_t* data, size_t length, D, T) { PUGI__STATIC_ASSERT(sizeof(char_t) == sizeof(typename D::type)); @@ -3540,8 +3473,7 @@ PUGI__FN size_t convert_buffer_output_generic(typename T::value_type dest, const } template -PUGI__FN size_t - convert_buffer_output_generic(typename T::value_type dest, const char_t* data, size_t length, D, T, bool opt_swap) +PUGI__FN size_t convert_buffer_output_generic(typename T::value_type dest, const char_t* data, size_t length, D, T, bool opt_swap) { PUGI__STATIC_ASSERT(sizeof(char_t) == sizeof(typename D::type)); @@ -3562,19 +3494,11 @@ PUGI__FN size_t get_valid_length(const char_t* data, size_t length) return 0; // discard last character if it's the lead of a surrogate pair - return (sizeof(wchar_t) == 2 && static_cast(static_cast(data[length - 1]) - 0xD800) < 0x400) - ? length - 1 - : length; + return (sizeof(wchar_t) == 2 && static_cast(static_cast(data[length - 1]) - 0xD800) < 0x400) ? length - 1 : length; } -PUGI__FN size_t convert_buffer_output( - char_t* r_char, - uint8_t* r_u8, - uint16_t* r_u16, - uint32_t* r_u32, - const char_t* data, - size_t length, - xml_encoding encoding) +PUGI__FN size_t + convert_buffer_output(char_t* r_char, uint8_t* r_u8, uint16_t* r_u16, uint32_t* r_u32, const char_t* data, size_t length, xml_encoding encoding) { // only endian-swapping is required if (need_endian_swap_utf(encoding, get_wchar_encoding())) { @@ -3591,16 +3515,14 @@ PUGI__FN size_t convert_buffer_output( if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be; - return convert_buffer_output_generic( - r_u16, data, length, wchar_decoder(), utf16_writer(), native_encoding != encoding); + return convert_buffer_output_generic(r_u16, data, length, wchar_decoder(), utf16_writer(), native_encoding != encoding); } // convert to utf32 if (encoding == encoding_utf32_be || encoding == encoding_utf32_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be; - return convert_buffer_output_generic( - r_u32, data, length, wchar_decoder(), utf32_writer(), native_encoding != encoding); + return convert_buffer_output_generic(r_u32, data, length, wchar_decoder(), utf32_writer(), native_encoding != encoding); } // convert to latin1 @@ -3630,26 +3552,18 @@ PUGI__FN size_t get_valid_length(const char_t* data, size_t length) } PUGI__FN size_t convert_buffer_output( - char_t* /* r_char */, - uint8_t* r_u8, - uint16_t* r_u16, - uint32_t* r_u32, - const char_t* data, - size_t length, - xml_encoding encoding) + char_t* /* r_char */, uint8_t* r_u8, uint16_t* r_u16, uint32_t* r_u32, const char_t* data, size_t length, xml_encoding encoding) { if (encoding == encoding_utf16_be || encoding == encoding_utf16_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf16_le : encoding_utf16_be; - return convert_buffer_output_generic( - r_u16, data, length, utf8_decoder(), utf16_writer(), native_encoding != encoding); + return convert_buffer_output_generic(r_u16, data, length, utf8_decoder(), utf16_writer(), native_encoding != encoding); } if (encoding == encoding_utf32_be || encoding == encoding_utf32_le) { xml_encoding native_encoding = is_little_endian() ? encoding_utf32_le : encoding_utf32_be; - return convert_buffer_output_generic( - r_u32, data, length, utf8_decoder(), utf32_writer(), native_encoding != encoding); + return convert_buffer_output_generic(r_u32, data, length, utf8_decoder(), utf32_writer(), native_encoding != encoding); } if (encoding == encoding_latin1) @@ -3666,8 +3580,7 @@ class xml_buffered_writer xml_buffered_writer& operator=(const xml_buffered_writer&); public: - xml_buffered_writer(xml_writer& writer_, xml_encoding user_encoding) : - writer(writer_), bufsize(0), encoding(get_write_encoding(user_encoding)) + xml_buffered_writer(xml_writer& writer_, xml_encoding user_encoding) : writer(writer_), bufsize(0), encoding(get_write_encoding(user_encoding)) { PUGI__STATIC_ASSERT(bufcapacity >= 8); } @@ -3689,8 +3602,7 @@ public: writer.write(data, size * sizeof(char_t)); else { // convert chunk - size_t result = convert_buffer_output( - scratch.data_char, scratch.data_u8, scratch.data_u16, scratch.data_u32, data, size, encoding); + size_t result = convert_buffer_output(scratch.data_char, scratch.data_u8, scratch.data_u16, scratch.data_u32, data, size, encoding); assert(result <= sizeof(scratch)); // write data @@ -3953,8 +3865,7 @@ PUGI__FN void text_output_cdata(xml_buffered_writer& writer, const char_t* s) } while (*s); } -PUGI__FN void - text_output_indent(xml_buffered_writer& writer, const char_t* indent, size_t indent_length, unsigned int depth) +PUGI__FN void text_output_indent(xml_buffered_writer& writer, const char_t* indent, size_t indent_length, unsigned int depth) { switch (indent_length) { case 1: { @@ -4033,12 +3944,7 @@ PUGI__FN void node_output_pi_value(xml_buffered_writer& writer, const char_t* s) } PUGI__FN void node_output_attributes( - xml_buffered_writer& writer, - xml_node_struct* node, - const char_t* indent, - size_t indent_length, - unsigned int flags, - unsigned int depth) + xml_buffered_writer& writer, xml_node_struct* node, const char_t* indent, size_t indent_length, unsigned int flags, unsigned int depth) { const char_t* default_name = PUGIXML_TEXT(":anonymous"); const char_t enquotation_char = (flags & format_attribute_single_quote) ? '\'' : '"'; @@ -4063,12 +3969,7 @@ PUGI__FN void node_output_attributes( } PUGI__FN bool node_output_start( - xml_buffered_writer& writer, - xml_node_struct* node, - const char_t* indent, - size_t indent_length, - unsigned int flags, - unsigned int depth) + xml_buffered_writer& writer, xml_node_struct* node, const char_t* indent, size_t indent_length, unsigned int flags, unsigned int depth) { const char_t* default_name = PUGIXML_TEXT(":anonymous"); const char_t* name = node->name ? node->name + 0 : default_name; @@ -4183,11 +4084,9 @@ PUGI__FN void node_output_simple(xml_buffered_writer& writer, xml_node_struct* n enum indent_flags_t { indent_newline = 1, indent_indent = 2 }; -PUGI__FN void node_output( - xml_buffered_writer& writer, xml_node_struct* root, const char_t* indent, unsigned int flags, unsigned int depth) +PUGI__FN void node_output(xml_buffered_writer& writer, xml_node_struct* root, const char_t* indent, unsigned int flags, unsigned int depth) { - size_t indent_length = - ((flags & (format_indent | format_indent_attributes)) && (flags & format_raw) == 0) ? strlength(indent) : 0; + size_t indent_length = ((flags & (format_indent | format_indent_attributes)) && (flags & format_raw) == 0) ? strlength(indent) : 0; unsigned int indent_flags = indent_indent; xml_node_struct* node = root; @@ -4327,8 +4226,7 @@ PUGI__FN bool allow_move(xml_node parent, xml_node child) } template -PUGI__FN void node_copy_string( - String& dest, Header& header, uintptr_t header_mask, char_t* source, Header& source_header, xml_allocator* alloc) +PUGI__FN void node_copy_string(String& dest, Header& header, uintptr_t header_mask, char_t* source, Header& source_header, xml_allocator* alloc) { assert(!dest && (header & header_mask) == 0); @@ -4354,10 +4252,8 @@ PUGI__FN void node_copy_contents(xml_node_struct* dn, xml_node_struct* sn, xml_a xml_attribute_struct* da = append_new_attribute(dn, get_allocator(dn)); if (da) { - node_copy_string( - da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, shared_alloc); - node_copy_string( - da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, shared_alloc); + node_copy_string(da->name, da->header, xml_memory_page_name_allocated_mask, sa->name, sa->header, shared_alloc); + node_copy_string(da->value, da->header, xml_memory_page_value_allocated_mask, sa->value, sa->header, shared_alloc); } } } @@ -4488,8 +4384,7 @@ template PUGI__FN PUGI__UNSIGNED_OVERFLOW U string_to_integer(const const char_t max_lead = sizeof(U) == 8 ? '1' : sizeof(U) == 4 ? '4' : '6'; const size_t high_bit = sizeof(U) * 8 - 1; - overflow = digits >= max_digits10 - && !(digits == max_digits10 && (*start < max_lead || (*start == max_lead && result >> high_bit))); + overflow = digits >= max_digits10 && !(digits == max_digits10 && (*start < max_lead || (*start == max_lead && result >> high_bit))); } if (negative) { @@ -4552,8 +4447,7 @@ PUGI__FN unsigned long long get_value_ullong(const char_t* value) } #endif -template -PUGI__FN PUGI__UNSIGNED_OVERFLOW char_t* integer_to_string(char_t* begin, char_t* end, U value, bool negative) +template PUGI__FN PUGI__UNSIGNED_OVERFLOW char_t* integer_to_string(char_t* begin, char_t* end, U value, bool negative) { char_t* result = end - 1; U rest = negative ? 0 - value : value; @@ -4572,8 +4466,7 @@ PUGI__FN PUGI__UNSIGNED_OVERFLOW char_t* integer_to_string(char_t* begin, char_t } // set value with conversion functions -template -PUGI__FN bool set_value_ascii(String& dest, Header& header, uintptr_t header_mask, char* buf) +template PUGI__FN bool set_value_ascii(String& dest, Header& header, uintptr_t header_mask, char* buf) { #ifdef PUGIXML_WCHAR_MODE char_t wbuf[128]; @@ -4617,11 +4510,9 @@ PUGI__FN bool set_value_convert(String& dest, Header& header, uintptr_t header_m return set_value_ascii(dest, header, header_mask, buf); } -template -PUGI__FN bool set_value_bool(String& dest, Header& header, uintptr_t header_mask, bool value) +template PUGI__FN bool set_value_bool(String& dest, Header& header, uintptr_t header_mask, bool value) { - return strcpy_insitu( - dest, header, header_mask, value ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false"), value ? 4 : 5); + return strcpy_insitu(dest, header, header_mask, value ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false"), value ? 4 : 5); } PUGI__FN xml_parse_result load_buffer_impl( @@ -4681,8 +4572,7 @@ PUGI__FN xml_parse_status get_file_size(FILE* file, size_t& out_result) _fseeki64(file, 0, SEEK_END); length_type length = _ftelli64(file); _fseeki64(file, 0, SEEK_SET); -#elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) \ - && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR)) +#elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR)) // there are 64-bit versions of fseek/ftell, let's use them typedef off64_t length_type; @@ -4738,8 +4628,7 @@ PUGI__FN size_t zero_terminate_buffer(void* buffer, size_t size, xml_encoding en return size; } -PUGI__FN xml_parse_result load_file_impl( - xml_document_struct* doc, FILE* file, unsigned int options, xml_encoding encoding, char_t** out_buffer) +PUGI__FN xml_parse_result load_file_impl(xml_document_struct* doc, FILE* file, unsigned int options, xml_encoding encoding, char_t** out_buffer) { if (!file) return make_parse_result(status_file_not_found); @@ -4767,9 +4656,7 @@ PUGI__FN xml_parse_result load_file_impl( xml_encoding real_encoding = get_buffer_encoding(encoding, contents, size); - return load_buffer_impl( - doc, doc, contents, zero_terminate_buffer(contents, size, real_encoding), options, real_encoding, true, true, - out_buffer); + return load_buffer_impl(doc, doc, contents, zero_terminate_buffer(contents, size, real_encoding), options, real_encoding, true, true, out_buffer); } PUGI__FN void close_file(FILE* file) @@ -4808,8 +4695,7 @@ template struct xml_stream_chunk { T data[xml_memory_page_size / sizeof(T)]; }; -template -PUGI__FN xml_parse_status load_stream_data_noseek(std::basic_istream& stream, void** out_buffer, size_t* out_size) +template PUGI__FN xml_parse_status load_stream_data_noseek(std::basic_istream& stream, void** out_buffer, size_t* out_size) { auto_deleter> chunks(0, xml_stream_chunk::destroy); @@ -4868,8 +4754,7 @@ PUGI__FN xml_parse_status load_stream_data_noseek(std::basic_istream& stream, return status_ok; } -template -PUGI__FN xml_parse_status load_stream_data_seek(std::basic_istream& stream, void** out_buffer, size_t* out_size) +template PUGI__FN xml_parse_status load_stream_data_seek(std::basic_istream& stream, void** out_buffer, size_t* out_size) { // get length of remaining data in stream typename std::basic_istream::pos_type pos = stream.tellg(); @@ -4911,12 +4796,8 @@ PUGI__FN xml_parse_status load_stream_data_seek(std::basic_istream& stream, v } template -PUGI__FN xml_parse_result load_stream_impl( - xml_document_struct* doc, - std::basic_istream& stream, - unsigned int options, - xml_encoding encoding, - char_t** out_buffer) +PUGI__FN xml_parse_result + load_stream_impl(xml_document_struct* doc, std::basic_istream& stream, unsigned int options, xml_encoding encoding, char_t** out_buffer) { void* buffer = 0; size_t size = 0; @@ -4940,9 +4821,7 @@ PUGI__FN xml_parse_result load_stream_impl( xml_encoding real_encoding = get_buffer_encoding(encoding, buffer, size); - return load_buffer_impl( - doc, doc, buffer, zero_terminate_buffer(buffer, size, real_encoding), options, real_encoding, true, true, - out_buffer); + return load_buffer_impl(doc, doc, buffer, zero_terminate_buffer(buffer, size, real_encoding), options, real_encoding, true, true, out_buffer); } #endif @@ -5012,8 +4891,7 @@ PUGI__FN FILE* open_file(const char* path, const char* mode) #endif } -PUGI__FN bool - save_file_impl(const xml_document& doc, FILE* file, const char_t* indent, unsigned int flags, xml_encoding encoding) +PUGI__FN bool save_file_impl(const xml_document& doc, FILE* file, const char_t* indent, unsigned int flags, xml_encoding encoding) { if (!file) return false; @@ -5048,13 +4926,11 @@ PUGI__FN void xml_writer_file::write(const void* data, size_t size) #ifndef PUGIXML_NO_STL PUGI__FN -xml_writer_stream::xml_writer_stream(std::basic_ostream>& stream) : - narrow_stream(&stream), wide_stream(0) +xml_writer_stream::xml_writer_stream(std::basic_ostream>& stream) : narrow_stream(&stream), wide_stream(0) { } -PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream>& stream) : - narrow_stream(0), wide_stream(&stream) +PUGI__FN xml_writer_stream::xml_writer_stream(std::basic_ostream>& stream) : narrow_stream(0), wide_stream(&stream) { } @@ -5067,8 +4943,7 @@ PUGI__FN void xml_writer_stream::write(const void* data, size_t size) assert(wide_stream); assert(size % sizeof(wchar_t) == 0); - wide_stream->write( - reinterpret_cast(data), static_cast(size / sizeof(wchar_t))); + wide_stream->write(reinterpret_cast(data), static_cast(size / sizeof(wchar_t))); } } #endif @@ -5292,8 +5167,7 @@ PUGI__FN bool xml_attribute::set_name(const char_t* rhs) if (!_attr) return false; - return impl::strcpy_insitu( - _attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); + return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); } PUGI__FN bool xml_attribute::set_value(const char_t* rhs) @@ -5301,8 +5175,7 @@ PUGI__FN bool xml_attribute::set_value(const char_t* rhs) if (!_attr) return false; - return impl::strcpy_insitu( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)); + return impl::strcpy_insitu(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)); } PUGI__FN bool xml_attribute::set_value(int rhs) @@ -5310,8 +5183,7 @@ PUGI__FN bool xml_attribute::set_value(int rhs) if (!_attr) return false; - return impl::set_value_integer( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); + return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); } PUGI__FN bool xml_attribute::set_value(unsigned int rhs) @@ -5319,8 +5191,7 @@ PUGI__FN bool xml_attribute::set_value(unsigned int rhs) if (!_attr) return false; - return impl::set_value_integer( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); + return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); } PUGI__FN bool xml_attribute::set_value(long rhs) @@ -5328,8 +5199,7 @@ PUGI__FN bool xml_attribute::set_value(long rhs) if (!_attr) return false; - return impl::set_value_integer( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); + return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); } PUGI__FN bool xml_attribute::set_value(unsigned long rhs) @@ -5337,8 +5207,7 @@ PUGI__FN bool xml_attribute::set_value(unsigned long rhs) if (!_attr) return false; - return impl::set_value_integer( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); + return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); } PUGI__FN bool xml_attribute::set_value(double rhs) @@ -5346,8 +5215,7 @@ PUGI__FN bool xml_attribute::set_value(double rhs) if (!_attr) return false; - return impl::set_value_convert( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_double_precision); + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_double_precision); } PUGI__FN bool xml_attribute::set_value(double rhs, int precision) @@ -5355,8 +5223,7 @@ PUGI__FN bool xml_attribute::set_value(double rhs, int precision) if (!_attr) return false; - return impl::set_value_convert( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, precision); + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, precision); } PUGI__FN bool xml_attribute::set_value(float rhs) @@ -5364,8 +5231,7 @@ PUGI__FN bool xml_attribute::set_value(float rhs) if (!_attr) return false; - return impl::set_value_convert( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_float_precision); + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, default_float_precision); } PUGI__FN bool xml_attribute::set_value(float rhs, int precision) @@ -5373,8 +5239,7 @@ PUGI__FN bool xml_attribute::set_value(float rhs, int precision) if (!_attr) return false; - return impl::set_value_convert( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, precision); + return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, precision); } PUGI__FN bool xml_attribute::set_value(bool rhs) @@ -5391,8 +5256,7 @@ PUGI__FN bool xml_attribute::set_value(long long rhs) if (!_attr) return false; - return impl::set_value_integer( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); + return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0); } PUGI__FN bool xml_attribute::set_value(unsigned long long rhs) @@ -5400,8 +5264,7 @@ PUGI__FN bool xml_attribute::set_value(unsigned long long rhs) if (!_attr) return false; - return impl::set_value_integer( - _attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); + return impl::set_value_integer(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs, false); } #endif @@ -5685,20 +5548,17 @@ PUGI__FN bool xml_node::set_name(const char_t* rhs) if (type_ != node_element && type_ != node_pi && type_ != node_declaration) return false; - return impl::strcpy_insitu( - _root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); + return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); } PUGI__FN bool xml_node::set_value(const char_t* rhs) { xml_node_type type_ = _root ? PUGI__NODETYPE(_root) : node_null; - if (type_ != node_pcdata && type_ != node_cdata && type_ != node_comment && type_ != node_pi - && type_ != node_doctype) + if (type_ != node_pcdata && type_ != node_cdata && type_ != node_comment && type_ != node_pi && type_ != node_doctype) return false; - return impl::strcpy_insitu( - _root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)); + return impl::strcpy_insitu(_root->value, _root->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)); } PUGI__FN xml_attribute xml_node::append_attribute(const char_t* name_) @@ -6251,8 +6111,7 @@ PUGI__FN bool xml_node::remove_children() return true; } -PUGI__FN xml_parse_result - xml_node::append_buffer(const void* contents, size_t size, unsigned int options, xml_encoding encoding) +PUGI__FN xml_parse_result xml_node::append_buffer(const void* contents, size_t size, unsigned int options, xml_encoding encoding) { // append_buffer is only valid for elements/documents if (!impl::allow_insert_child(type(), node_element)) @@ -6268,8 +6127,7 @@ PUGI__FN xml_parse_result // get extra buffer element (we'll store the document fragment buffer there so that we can // deallocate it later) impl::xml_memory_page* page = 0; - impl::xml_extra_buffer* extra = static_cast( - doc->allocate_memory(sizeof(impl::xml_extra_buffer) + sizeof(void*), page)); + impl::xml_extra_buffer* extra = static_cast(doc->allocate_memory(sizeof(impl::xml_extra_buffer) + sizeof(void*), page)); (void)page; if (!extra) @@ -6279,8 +6137,7 @@ PUGI__FN xml_parse_result // align the memory block to a pointer boundary; this is required for compact mode where memory // allocations are only 4b aligned note that this requires up to sizeof(void*)-1 additional // memory, which the allocation above takes into account - extra = reinterpret_cast( - (reinterpret_cast(extra) + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1)); + extra = reinterpret_cast((reinterpret_cast(extra) + (sizeof(void*) - 1)) & ~(sizeof(void*) - 1)); #endif // add extra buffer to the list @@ -6292,12 +6149,10 @@ PUGI__FN xml_parse_result // be detected at the top level impl::name_null_sentry sentry(_root); - return impl::load_buffer_impl( - doc, _root, const_cast(contents), size, options, encoding, false, false, &extra->buffer); + return impl::load_buffer_impl(doc, _root, const_cast(contents), size, options, encoding, false, false, &extra->buffer); } -PUGI__FN xml_node - xml_node::find_child_by_attribute(const char_t* name_, const char_t* attr_name, const char_t* attr_value) const +PUGI__FN xml_node xml_node::find_child_by_attribute(const char_t* name_, const char_t* attr_name, const char_t* attr_value) const { if (!_root) return xml_node(); @@ -6305,8 +6160,7 @@ PUGI__FN xml_node for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) if (i->name && impl::strequal(name_, i->name)) { for (xml_attribute_struct* a = i->first_attribute; a; a = a->next_attribute) - if (a->name && impl::strequal(attr_name, a->name) - && impl::strequal(attr_value, a->value ? a->value + 0 : PUGIXML_TEXT(""))) + if (a->name && impl::strequal(attr_name, a->name) && impl::strequal(attr_value, a->value ? a->value + 0 : PUGIXML_TEXT(""))) return xml_node(i); } @@ -6320,8 +6174,7 @@ PUGI__FN xml_node xml_node::find_child_by_attribute(const char_t* attr_name, con for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) for (xml_attribute_struct* a = i->first_attribute; a; a = a->next_attribute) - if (a->name && impl::strequal(attr_name, a->name) - && impl::strequal(attr_value, a->value ? a->value + 0 : PUGIXML_TEXT(""))) + if (a->name && impl::strequal(attr_name, a->name) && impl::strequal(attr_value, a->value ? a->value + 0 : PUGIXML_TEXT(""))) return xml_node(i); return xml_node(); @@ -6392,8 +6245,7 @@ PUGI__FN xml_node xml_node::first_element_by_path(const char_t* path_, char_t de return context.parent().first_element_by_path(next_segment, delimiter); else { for (xml_node_struct* j = context._root->first_child; j; j = j->next_sibling) { - if (j->name - && impl::strequalrange(j->name, path_segment, static_cast(path_segment_end - path_segment))) { + if (j->name && impl::strequalrange(j->name, path_segment, static_cast(path_segment_end - path_segment))) { xml_node subsearch = xml_node(j).first_element_by_path(next_segment, delimiter); if (subsearch) @@ -6456,8 +6308,7 @@ PUGI__FN xml_node_struct* xml_node::internal_object() const return _root; } -PUGI__FN void xml_node::print( - xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const +PUGI__FN void xml_node::print(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding, unsigned int depth) const { if (!_root) return; @@ -6483,10 +6334,7 @@ PUGI__FN void xml_node::print( } PUGI__FN void xml_node::print( - std::basic_ostream>& stream, - const char_t* indent, - unsigned int flags, - unsigned int depth) const + std::basic_ostream>& stream, const char_t* indent, unsigned int flags, unsigned int depth) const { xml_writer_stream writer(stream); @@ -6512,17 +6360,13 @@ PUGI__FN ptrdiff_t xml_node::offset_debug() const case node_element: case node_declaration: case node_pi: - return _root->name && (_root->header & impl::xml_memory_page_name_allocated_or_shared_mask) == 0 - ? _root->name - doc.buffer - : -1; + return _root->name && (_root->header & impl::xml_memory_page_name_allocated_or_shared_mask) == 0 ? _root->name - doc.buffer : -1; case node_pcdata: case node_cdata: case node_comment: case node_doctype: - return _root->value && (_root->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0 - ? _root->value - doc.buffer - : -1; + return _root->value && (_root->header & impl::xml_memory_page_value_allocated_or_shared_mask) == 0 ? _root->value - doc.buffer : -1; default: assert(false && "Invalid node type"); // unreachable @@ -6663,81 +6507,63 @@ PUGI__FN bool xml_text::set(const char_t* rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::strcpy_insitu( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)) - : false; + return dn ? impl::strcpy_insitu(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, impl::strlength(rhs)) : false; } PUGI__FN bool xml_text::set(int rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_integer( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) - : false; + return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) : false; } PUGI__FN bool xml_text::set(unsigned int rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_integer( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) - : false; + return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) : false; } PUGI__FN bool xml_text::set(long rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_integer( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) - : false; + return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) : false; } PUGI__FN bool xml_text::set(unsigned long rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_integer( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) - : false; + return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) : false; } PUGI__FN bool xml_text::set(float rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_convert( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, default_float_precision) - : false; + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, default_float_precision) : false; } PUGI__FN bool xml_text::set(float rhs, int precision) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_convert( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) - : false; + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) : false; } PUGI__FN bool xml_text::set(double rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_convert( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, default_double_precision) - : false; + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, default_double_precision) : false; } PUGI__FN bool xml_text::set(double rhs, int precision) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_convert( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) - : false; + return dn ? impl::set_value_convert(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, precision) : false; } PUGI__FN bool xml_text::set(bool rhs) @@ -6752,18 +6578,14 @@ PUGI__FN bool xml_text::set(long long rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_integer( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) - : false; + return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, rhs < 0) : false; } PUGI__FN bool xml_text::set(unsigned long long rhs) { xml_node_struct* dn = _data_new(); - return dn ? impl::set_value_integer( - dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) - : false; + return dn ? impl::set_value_integer(dn->value, dn->header, impl::xml_memory_page_value_allocated_mask, rhs, false) : false; } #endif @@ -6854,8 +6676,7 @@ PUGI__FN xml_node_iterator::xml_node_iterator(const xml_node& node) : _wrap(node { } -PUGI__FN xml_node_iterator::xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent) : - _wrap(ref), _parent(parent) +PUGI__FN xml_node_iterator::xml_node_iterator(xml_node_struct* ref, xml_node_struct* parent) : _wrap(ref), _parent(parent) { } @@ -6912,13 +6733,11 @@ PUGI__FN xml_attribute_iterator::xml_attribute_iterator() { } -PUGI__FN xml_attribute_iterator::xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent) : - _wrap(attr), _parent(parent) +PUGI__FN xml_attribute_iterator::xml_attribute_iterator(const xml_attribute& attr, const xml_node& parent) : _wrap(attr), _parent(parent) { } -PUGI__FN xml_attribute_iterator::xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent) : - _wrap(ref), _parent(parent) +PUGI__FN xml_attribute_iterator::xml_attribute_iterator(xml_attribute_struct* ref, xml_node_struct* parent) : _wrap(ref), _parent(parent) { } @@ -6976,15 +6795,12 @@ PUGI__FN xml_named_node_iterator::xml_named_node_iterator() : _name(0) } PUGI__FN -xml_named_node_iterator::xml_named_node_iterator(const xml_node& node, const char_t* name) : - _wrap(node), _parent(node.parent()), _name(name) +xml_named_node_iterator::xml_named_node_iterator(const xml_node& node, const char_t* name) : _wrap(node), _parent(node.parent()), _name(name) { } -PUGI__FN xml_named_node_iterator::xml_named_node_iterator( - xml_node_struct* ref, xml_node_struct* parent, const char_t* name) : - _wrap(ref), - _parent(parent), _name(name) +PUGI__FN xml_named_node_iterator::xml_named_node_iterator(xml_node_struct* ref, xml_node_struct* parent, const char_t* name) : + _wrap(ref), _parent(parent), _name(name) { } @@ -7158,8 +6974,7 @@ PUGI__FN void xml_document::_create() #endif // initialize sentinel page - PUGI__STATIC_ASSERT( - sizeof(impl::xml_memory_page) + sizeof(impl::xml_document_struct) + page_offset <= sizeof(_memory)); + PUGI__STATIC_ASSERT(sizeof(impl::xml_memory_page) + sizeof(impl::xml_document_struct) + page_offset <= sizeof(_memory)); // prepare page structure impl::xml_memory_page* page = impl::xml_memory_page::construct(_memory); @@ -7170,14 +6985,12 @@ PUGI__FN void xml_document::_create() // setup first page marker #ifdef PUGIXML_COMPACT // round-trip through void* to avoid 'cast increases required alignment of target type' warning - page->compact_page_marker = - reinterpret_cast(static_cast(reinterpret_cast(page) + sizeof(impl::xml_memory_page))); + page->compact_page_marker = reinterpret_cast(static_cast(reinterpret_cast(page) + sizeof(impl::xml_memory_page))); *page->compact_page_marker = sizeof(impl::xml_memory_page); #endif // allocate new root - _root = new (reinterpret_cast(page) + sizeof(impl::xml_memory_page) + page_offset) - impl::xml_document_struct(page); + _root = new (reinterpret_cast(page) + sizeof(impl::xml_memory_page) + page_offset) impl::xml_document_struct(page); _root->prev_sibling_c = _root; // setup sentinel page @@ -7204,8 +7017,7 @@ PUGI__FN void xml_document::_destroy() // destroy extra buffers (note: no need to destroy linked list nodes, they're allocated using // document allocator) - for (impl::xml_extra_buffer* extra = static_cast(_root)->extra_buffers; extra; - extra = extra->next) { + for (impl::xml_extra_buffer* extra = static_cast(_root)->extra_buffers; extra; extra = extra->next) { if (extra->buffer) impl::xml_memory::deallocate(extra->buffer); } @@ -7213,9 +7025,7 @@ PUGI__FN void xml_document::_destroy() // destroy dynamic storage, leave sentinel page (it's in static memory) impl::xml_memory_page* root_page = PUGI__GETPAGE(_root); assert(root_page && !root_page->prev); - assert( - reinterpret_cast(root_page) >= _memory - && reinterpret_cast(root_page) < _memory + sizeof(_memory)); + assert(reinterpret_cast(root_page) >= _memory && reinterpret_cast(root_page) < _memory + sizeof(_memory)); for (impl::xml_memory_page* page = root_page->next; page;) { impl::xml_memory_page* next = page->next; @@ -7338,21 +7148,18 @@ PUGI__FN void xml_document::_move(xml_document& rhs) PUGIXML_NOEXCEPT_IF_NOT_COM #endif #ifndef PUGIXML_NO_STL -PUGI__FN xml_parse_result xml_document::load( - std::basic_istream>& stream, unsigned int options, xml_encoding encoding) +PUGI__FN xml_parse_result xml_document::load(std::basic_istream>& stream, unsigned int options, xml_encoding encoding) { reset(); return impl::load_stream_impl(static_cast(_root), stream, options, encoding, &_buffer); } -PUGI__FN xml_parse_result - xml_document::load(std::basic_istream>& stream, unsigned int options) +PUGI__FN xml_parse_result xml_document::load(std::basic_istream>& stream, unsigned int options) { reset(); - return impl::load_stream_impl( - static_cast(_root), stream, options, encoding_wchar, &_buffer); + return impl::load_stream_impl(static_cast(_root), stream, options, encoding_wchar, &_buffer); } #endif @@ -7393,37 +7200,29 @@ PUGI__FN xml_parse_result xml_document::load_file(const wchar_t* path_, unsigned return impl::load_file_impl(static_cast(_root), file.data, options, encoding, &_buffer); } -PUGI__FN xml_parse_result - xml_document::load_buffer(const void* contents, size_t size, unsigned int options, xml_encoding encoding) +PUGI__FN xml_parse_result xml_document::load_buffer(const void* contents, size_t size, unsigned int options, xml_encoding encoding) { reset(); return impl::load_buffer_impl( - static_cast(_root), _root, const_cast(contents), size, options, encoding, - false, false, &_buffer); + static_cast(_root), _root, const_cast(contents), size, options, encoding, false, false, &_buffer); } -PUGI__FN xml_parse_result - xml_document::load_buffer_inplace(void* contents, size_t size, unsigned int options, xml_encoding encoding) +PUGI__FN xml_parse_result xml_document::load_buffer_inplace(void* contents, size_t size, unsigned int options, xml_encoding encoding) { reset(); - return impl::load_buffer_impl( - static_cast(_root), _root, contents, size, options, encoding, true, false, - &_buffer); + return impl::load_buffer_impl(static_cast(_root), _root, contents, size, options, encoding, true, false, &_buffer); } -PUGI__FN xml_parse_result - xml_document::load_buffer_inplace_own(void* contents, size_t size, unsigned int options, xml_encoding encoding) +PUGI__FN xml_parse_result xml_document::load_buffer_inplace_own(void* contents, size_t size, unsigned int options, xml_encoding encoding) { reset(); - return impl::load_buffer_impl( - static_cast(_root), _root, contents, size, options, encoding, true, true, &_buffer); + return impl::load_buffer_impl(static_cast(_root), _root, contents, size, options, encoding, true, true, &_buffer); } -PUGI__FN void - xml_document::save(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding) const +PUGI__FN void xml_document::save(xml_writer& writer, const char_t* indent, unsigned int flags, xml_encoding encoding) const { impl::xml_buffered_writer buffered_writer(writer, encoding); @@ -7453,18 +7252,14 @@ PUGI__FN void #ifndef PUGIXML_NO_STL PUGI__FN void xml_document::save( - std::basic_ostream>& stream, - const char_t* indent, - unsigned int flags, - xml_encoding encoding) const + std::basic_ostream>& stream, const char_t* indent, unsigned int flags, xml_encoding encoding) const { xml_writer_stream writer(stream); save(writer, indent, flags, encoding); } -PUGI__FN void xml_document::save( - std::basic_ostream>& stream, const char_t* indent, unsigned int flags) const +PUGI__FN void xml_document::save(std::basic_ostream>& stream, const char_t* indent, unsigned int flags) const { xml_writer_stream writer(stream); @@ -7472,8 +7267,7 @@ PUGI__FN void xml_document::save( } #endif -PUGI__FN bool - xml_document::save_file(const char* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const +PUGI__FN bool xml_document::save_file(const char* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const { using impl::auto_deleter; // MSVC7 workaround auto_deleter file(impl::open_file(path_, (flags & format_save_file_text) ? "w" : "wb"), impl::close_file); @@ -7481,12 +7275,10 @@ PUGI__FN bool return impl::save_file_impl(*this, file.data, indent, flags, encoding); } -PUGI__FN bool - xml_document::save_file(const wchar_t* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const +PUGI__FN bool xml_document::save_file(const wchar_t* path_, const char_t* indent, unsigned int flags, xml_encoding encoding) const { using impl::auto_deleter; // MSVC7 workaround - auto_deleter file( - impl::open_file_wide(path_, (flags & format_save_file_text) ? L"w" : L"wb"), impl::close_file); + auto_deleter file(impl::open_file_wide(path_, (flags & format_save_file_text) ? L"w" : L"wb"), impl::close_file); return impl::save_file_impl(*this, file.data, indent, flags, encoding); } @@ -7528,8 +7320,7 @@ PUGI__FN std::basic_string PUGIXML_FUNCTION as_wide(const std::string& } #endif -PUGI__FN void PUGIXML_FUNCTION - set_memory_management_functions(allocation_function allocate, deallocation_function deallocate) +PUGI__FN void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate) { impl::xml_memory::allocate = allocate; impl::xml_memory::deallocate = deallocate; @@ -7688,8 +7479,7 @@ template inline I median3(I first, I middle, I last, return middle; } -template -PUGI__FN void partition3(T* begin, T* end, T pivot, const Pred& pred, T** out_eqbeg, T** out_eqend) +template PUGI__FN void partition3(T* begin, T* end, T pivot, const Pred& pred, T** out_eqbeg, T** out_eqend) { // invariant: array is split into 4 groups: = < ? > (each variable denotes the boundary between // the groups) @@ -7819,8 +7609,7 @@ struct xpath_allocator { // subsequent allocation requests size_t block_capacity_base = sizeof(_root->data); size_t block_capacity_req = size + block_capacity_base / 4; - size_t block_capacity = - (block_capacity_base > block_capacity_req) ? block_capacity_base : block_capacity_req; + size_t block_capacity = (block_capacity_base > block_capacity_req) ? block_capacity_base : block_capacity_req; size_t block_size = block_capacity + offsetof(xpath_memory_block, data); @@ -7976,10 +7765,7 @@ class xpath_string return result; } - xpath_string(const char_t* buffer, bool uses_heap_, size_t length_heap) : - _buffer(buffer), _uses_heap(uses_heap_), _length_heap(length_heap) - { - } + xpath_string(const char_t* buffer, bool uses_heap_, size_t length_heap) : _buffer(buffer), _uses_heap(uses_heap_), _length_heap(length_heap) { } public: static xpath_string from_const(const char_t* str) { return xpath_string(str, false, 0); } @@ -8023,8 +7809,7 @@ public: // allocate new buffer char_t* result = static_cast(alloc->reallocate( - _uses_heap ? const_cast(_buffer) : 0, (target_length + 1) * sizeof(char_t), - (result_length + 1) * sizeof(char_t))); + _uses_heap ? const_cast(_buffer) : 0, (target_length + 1) * sizeof(char_t), (result_length + 1) * sizeof(char_t))); if (!result) return; @@ -8401,8 +8186,7 @@ PUGI__FN void truncate_zeros(char* begin, char* end) // gets mantissa digits in the form of 0.xxxxx with 0. implied and the exponent #if defined(PUGI__MSVC_CRT_VERSION) && PUGI__MSVC_CRT_VERSION >= 1400 && !defined(_WIN32_WCE) -PUGI__FN void - convert_number_to_mantissa_exponent(double value, char (&buffer)[32], char** out_mantissa, int* out_exponent) +PUGI__FN void convert_number_to_mantissa_exponent(double value, char (&buffer)[32], char** out_mantissa, int* out_exponent) { // get base values int sign, exponent; @@ -8416,8 +8200,7 @@ PUGI__FN void *out_exponent = exponent; } #else -PUGI__FN void - convert_number_to_mantissa_exponent(double value, char (&buffer)[32], char** out_mantissa, int* out_exponent) +PUGI__FN void convert_number_to_mantissa_exponent(double value, char (&buffer)[32], char** out_mantissa, int* out_exponent) { // get a scientific notation value with IEEE DBL_DIG decimals PUGI__SNPRINTF(buffer, "%.*e", DBL_DIG, value); @@ -8559,8 +8342,7 @@ PUGI__FN double convert_string_to_number(const char_t* string) #endif } -PUGI__FN bool - convert_string_to_number_scratch(char_t (&buffer)[32], const char_t* begin, const char_t* end, double* out_result) +PUGI__FN bool convert_string_to_number_scratch(char_t (&buffer)[32], const char_t* begin, const char_t* end, double* out_result) { size_t length = static_cast(end - begin); char_t* scratch = buffer; @@ -8936,8 +8718,7 @@ PUGI__FN bool copy_xpath_variable(xpath_variable* lhs, const xpath_variable* rhs } } -PUGI__FN bool get_variable_scratch( - char_t (&buffer)[32], xpath_variable_set* set, const char_t* begin, const char_t* end, xpath_variable** out_result) +PUGI__FN bool get_variable_scratch(char_t (&buffer)[32], xpath_variable_set* set, const char_t* begin, const char_t* end, xpath_variable** out_result) { size_t length = static_cast(end - begin); char_t* scratch = buffer; @@ -9065,8 +8846,8 @@ public: if (size_ + count > capacity) { // reallocate the old array or allocate a new one - xpath_node* data = static_cast( - alloc->reallocate(_begin, capacity * sizeof(xpath_node), (size_ + count) * sizeof(xpath_node))); + xpath_node* data = + static_cast(alloc->reallocate(_begin, capacity * sizeof(xpath_node), (size_ + count) * sizeof(xpath_node))); if (!data) return; @@ -9137,8 +8918,7 @@ PUGI__FN_NO_INLINE void xpath_node_set_raw::push_back_grow(const xpath_node& nod size_t new_capacity = capacity + capacity / 2 + 1; // reallocate the old array or allocate a new one - xpath_node* data = static_cast( - alloc->reallocate(_begin, capacity * sizeof(xpath_node), new_capacity * sizeof(xpath_node))); + xpath_node* data = static_cast(alloc->reallocate(_begin, capacity * sizeof(xpath_node), new_capacity * sizeof(xpath_node))); if (!data) return; @@ -9467,9 +9247,7 @@ public: const xpath_lexer_string& contents() const { - assert( - _cur_lexeme == lex_var_ref || _cur_lexeme == lex_number || _cur_lexeme == lex_string - || _cur_lexeme == lex_quoted_string); + assert(_cur_lexeme == lex_var_ref || _cur_lexeme == lex_number || _cur_lexeme == lex_string || _cur_lexeme == lex_quoted_string); return _cur_lexeme_contents; } @@ -9612,8 +9390,7 @@ private: xpath_ast_node& operator=(const xpath_ast_node&); template - static bool compare_eq( - xpath_ast_node* lhs, xpath_ast_node* rhs, const xpath_context& c, const xpath_stack& stack, const Comp& comp) + static bool compare_eq(xpath_ast_node* lhs, xpath_ast_node* rhs, const xpath_context& c, const xpath_stack& stack, const Comp& comp) { xpath_value_type lt = lhs->rettype(), rt = rhs->rettype(); @@ -9694,8 +9471,7 @@ private: } template - static bool compare_rel( - xpath_ast_node* lhs, xpath_ast_node* rhs, const xpath_context& c, const xpath_stack& stack, const Comp& comp) + static bool compare_rel(xpath_ast_node* lhs, xpath_ast_node* rhs, const xpath_context& c, const xpath_stack& stack, const Comp& comp) { xpath_value_type lt = lhs->rettype(), rt = rhs->rettype(); @@ -9755,8 +9531,7 @@ private: } } - static void apply_predicate_boolean( - xpath_node_set_raw& ns, size_t first, xpath_ast_node* expr, const xpath_stack& stack, bool once) + static void apply_predicate_boolean(xpath_node_set_raw& ns, size_t first, xpath_ast_node* expr, const xpath_stack& stack, bool once) { assert(ns.size() >= first); assert(expr->rettype() != xpath_type_number); @@ -9781,8 +9556,7 @@ private: ns.truncate(last); } - static void apply_predicate_number( - xpath_node_set_raw& ns, size_t first, xpath_ast_node* expr, const xpath_stack& stack, bool once) + static void apply_predicate_number(xpath_node_set_raw& ns, size_t first, xpath_ast_node* expr, const xpath_stack& stack, bool once) { assert(ns.size() >= first); assert(expr->rettype() == xpath_type_number); @@ -9807,8 +9581,7 @@ private: ns.truncate(last); } - static void apply_predicate_number_const( - xpath_node_set_raw& ns, size_t first, xpath_ast_node* expr, const xpath_stack& stack) + static void apply_predicate_number_const(xpath_node_set_raw& ns, size_t first, xpath_ast_node* expr, const xpath_stack& stack) { assert(ns.size() >= first); assert(expr->rettype() == xpath_type_number); @@ -10137,17 +9910,14 @@ private: } } - template - void step_fill( - xpath_node_set_raw& ns, xml_attribute_struct* a, xml_node_struct* p, xpath_allocator* alloc, bool once, T v) + template void step_fill(xpath_node_set_raw& ns, xml_attribute_struct* a, xml_node_struct* p, xpath_allocator* alloc, bool once, T v) { const axis_t axis = T::axis; switch (axis) { case axis_ancestor: case axis_ancestor_or_self: { - if (axis == axis_ancestor_or_self - && _test == nodetest_type_node) // reject attributes based on principal node type test + if (axis == axis_ancestor_or_self && _test == nodetest_type_node) // reject attributes based on principal node type test if (step_push(ns, a, p, alloc) & once) return; @@ -10213,13 +9983,12 @@ private: } } - template - void step_fill(xpath_node_set_raw& ns, const xpath_node& xn, xpath_allocator* alloc, bool once, T v) + template void step_fill(xpath_node_set_raw& ns, const xpath_node& xn, xpath_allocator* alloc, bool once, T v) { const axis_t axis = T::axis; const bool axis_has_attributes = - (axis == axis_ancestor || axis == axis_ancestor_or_self || axis == axis_descendant_or_self - || axis == axis_following || axis == axis_parent || axis == axis_preceding || axis == axis_self); + (axis == axis_ancestor || axis == axis_ancestor_or_self || axis == axis_descendant_or_self || axis == axis_following + || axis == axis_parent || axis == axis_preceding || axis == axis_self); if (xn.node()) step_fill(ns, xn.node().internal_object(), alloc, once, v); @@ -10227,15 +9996,12 @@ private: step_fill(ns, xn.attribute().internal_object(), xn.parent().internal_object(), alloc, once, v); } - template - xpath_node_set_raw step_do(const xpath_context& c, const xpath_stack& stack, nodeset_eval_t eval, T v) + template xpath_node_set_raw step_do(const xpath_context& c, const xpath_stack& stack, nodeset_eval_t eval, T v) { const axis_t axis = T::axis; const bool axis_reverse = - (axis == axis_ancestor || axis == axis_ancestor_or_self || axis == axis_preceding - || axis == axis_preceding_sibling); - const xpath_node_set::type_t axis_type = - axis_reverse ? xpath_node_set::type_sorted_reverse : xpath_node_set::type_sorted; + (axis == axis_ancestor || axis == axis_ancestor_or_self || axis == axis_preceding || axis == axis_preceding_sibling); + const xpath_node_set::type_t axis_type = axis_reverse ? xpath_node_set::type_sorted_reverse : xpath_node_set::type_sorted; bool once = (axis == axis_attribute && _test == nodetest_name) || (!_right && eval_once(axis_type, eval)) || // coverity[mixed_enums] @@ -10272,8 +10038,7 @@ private: // child, attribute and self axes always generate unique set of nodes // for other axis, if the set stayed sorted, it stayed unique because the traversal // algorithms do not visit the same node twice - if (axis != axis_child && axis != axis_attribute && axis != axis_self - && ns.type() == xpath_node_set::type_unsorted) + if (axis != axis_child && axis != axis_attribute && axis != axis_self && ns.type() == xpath_node_set::type_unsorted) ns.remove_duplicates(stack.temp); return ns; @@ -10281,46 +10046,41 @@ private: public: xpath_ast_node(ast_type_t type, xpath_value_type rettype_, const char_t* value) : - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), - _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) { assert(type == ast_string_constant); _data.string = value; } xpath_ast_node(ast_type_t type, xpath_value_type rettype_, double value) : - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), - _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) { assert(type == ast_number_constant); _data.number = value; } xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_variable* value) : - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), - _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) { assert(type == ast_variable); _data.variable = value; } xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_ast_node* left = 0, xpath_ast_node* right = 0) : - _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(left), - _right(right), _next(0) + _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(left), _right(right), _next(0) { } xpath_ast_node(ast_type_t type, xpath_ast_node* left, axis_t axis, nodetest_t test, const char_t* contents) : - _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(static_cast(axis)), - _test(static_cast(test)), _left(left), _right(0), _next(0) + _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(static_cast(axis)), _test(static_cast(test)), _left(left), + _right(0), _next(0) { assert(type == ast_step); _data.nodetest = contents; } xpath_ast_node(ast_type_t type, xpath_ast_node* left, xpath_ast_node* right, predicate_t test) : - _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(0), _test(static_cast(test)), - _left(left), _right(right), _next(0) + _type(static_cast(type)), _rettype(xpath_type_node_set), _axis(0), _test(static_cast(test)), _left(left), _right(right), _next(0) { assert(type == ast_filter || type == ast_predicate); } @@ -10415,8 +10175,7 @@ public: } case ast_opt_compare_attribute: { - const char_t* value = - (_right->_type == ast_string_constant) ? _right->_data.string : _right->_data.variable->get_string(); + const char_t* value = (_right->_type == ast_string_constant) ? _right->_data.string : _right->_data.variable->get_string(); xml_attribute attr = c.n.node().attribute(_left->_data.nodetest); @@ -10722,8 +10481,7 @@ public: const char_t* rbegin = pos + p.length(); const char_t* rend = s.c_str() + s.length(); - return s.uses_heap() ? xpath_string::from_heap(rbegin, rend, stack.result) - : xpath_string::from_const(rbegin); + return s.uses_heap() ? xpath_string::from_heap(rbegin, rend, stack.result) : xpath_string::from_const(rbegin); } case ast_func_substring_2: { @@ -10747,8 +10505,7 @@ public: const char_t* rbegin = s.c_str() + (pos - 1); const char_t* rend = s.c_str() + s.length(); - return s.uses_heap() ? xpath_string::from_heap(rbegin, rend, stack.result) - : xpath_string::from_const(rbegin); + return s.uses_heap() ? xpath_string::from_heap(rbegin, rend, stack.result) : xpath_string::from_const(rbegin); } case ast_func_substring_3: { @@ -10778,8 +10535,7 @@ public: const char_t* rbegin = s.c_str() + (pos - 1); const char_t* rend = s.c_str() + (end - 1); - return (end == s_length + 1 && !s.uses_heap()) ? xpath_string::from_const(rbegin) - : xpath_string::from_heap(rbegin, rend, stack.result); + return (end == s_length + 1 && !s.uses_heap()) ? xpath_string::from_const(rbegin) : xpath_string::from_heap(rbegin, rend, stack.result); } case ast_func_normalize_space_0: { @@ -10896,8 +10652,7 @@ public: } case ast_filter: { - xpath_node_set_raw set = - _left->eval_node_set(c, stack, _test == predicate_constant_one ? nodeset_eval_first : nodeset_eval_all); + xpath_node_set_raw set = _left->eval_node_set(c, stack, _test == predicate_constant_one ? nodeset_eval_first : nodeset_eval_all); // either expression is a number or it contains position() call; sort by document order if (_test != predicate_posinv) @@ -11025,8 +10780,7 @@ public: // Note that this step has to go before classification to recognize [position()=1] if ((_type == ast_filter || _type == ast_predicate) && _right && // workaround for clang static analyzer (_right // is never null for ast_filter/ast_predicate) - _right->_type == ast_op_equal && _right->_left->_type == ast_func_position - && _right->_right->_rettype == xpath_type_number) { + _right->_type == ast_op_equal && _right->_left->_type == ast_func_position && _right->_right->_rettype == xpath_type_number) { _right = _right->_right; } @@ -11040,8 +10794,7 @@ public: _test = predicate_constant_one; else if ( _right->_rettype == xpath_type_number - && (_right->_type == ast_number_constant || _right->_type == ast_variable - || _right->_type == ast_func_last)) + && (_right->_type == ast_number_constant || _right->_type == ast_variable || _right->_type == ast_func_last)) _test = predicate_constant; else if (_right->_rettype != xpath_type_number && _right->is_posinv_expr()) _test = predicate_posinv; @@ -11051,11 +10804,9 @@ public: // The former is a full form of //foo, the latter is much faster since it executes the node // test immediately Do a similar kind of rewrite for self/descendant/descendant-or-self axes // Note that we only rewrite positionally invariant steps (//foo[1] != /descendant::foo[1]) - if (_type == ast_step - && (_axis == axis_child || _axis == axis_self || _axis == axis_descendant - || _axis == axis_descendant_or_self) - && _left && _left->_type == ast_step && _left->_axis == axis_descendant_or_self - && _left->_test == nodetest_type_node && !_left->_right && is_posinv_step()) { + if (_type == ast_step && (_axis == axis_child || _axis == axis_self || _axis == axis_descendant || _axis == axis_descendant_or_self) && _left + && _left->_type == ast_step && _left->_axis == axis_descendant_or_self && _left->_test == nodetest_type_node && !_left->_right + && is_posinv_step()) { if (_axis == axis_child || _axis == axis_descendant) _axis = axis_descendant; else @@ -11065,8 +10816,7 @@ public: } // Use optimized lookup table implementation for translate() with constant arguments - if (_type == ast_func_translate && _right - && // workaround for clang static analyzer (_right is never null for ast_func_translate) + if (_type == ast_func_translate && _right && // workaround for clang static analyzer (_right is never null for ast_func_translate) _right->_type == ast_string_constant && _right->_next->_type == ast_string_constant) { unsigned char* table = translate_table_generate(alloc, _right->_data.string, _right->_next->_data.string); @@ -11079,10 +10829,8 @@ public: // Use optimized path for @attr = 'value' or @attr = $value if (_type == ast_op_equal && _left && _right && // workaround for clang static analyzer and Coverity (_left and // _right are never null for ast_op_equal) coverity[mixed_enums] - _left->_type == ast_step && _left->_axis == axis_attribute && _left->_test == nodetest_name && !_left->_left - && !_left->_right - && (_right->_type == ast_string_constant - || (_right->_type == ast_variable && _right->_rettype == xpath_type_string))) { + _left->_type == ast_step && _left->_axis == axis_attribute && _left->_test == nodetest_name && !_left->_left && !_left->_right + && (_right->_type == ast_string_constant || (_right->_type == ast_variable && _right->_rettype == xpath_type_string))) { _type = ast_opt_compare_attribute; } } @@ -11195,15 +10943,13 @@ struct xpath_parser { return memory ? new (memory) xpath_ast_node(type, rettype, value) : 0; } - xpath_ast_node* - alloc_node(ast_type_t type, xpath_value_type rettype, xpath_ast_node* left = 0, xpath_ast_node* right = 0) + xpath_ast_node* alloc_node(ast_type_t type, xpath_value_type rettype, xpath_ast_node* left = 0, xpath_ast_node* right = 0) { void* memory = alloc_node(); return memory ? new (memory) xpath_ast_node(type, rettype, left, right) : 0; } - xpath_ast_node* - alloc_node(ast_type_t type, xpath_ast_node* left, axis_t axis, nodetest_t test, const char_t* contents) + xpath_ast_node* alloc_node(ast_type_t type, xpath_ast_node* left, axis_t axis, nodetest_t test, const char_t* contents) { void* memory = alloc_node(); return memory ? new (memory) xpath_ast_node(type, left, axis, test, contents) : 0; @@ -11277,8 +11023,7 @@ struct xpath_parser { else if (name == PUGIXML_TEXT("local-name") && argc <= 1) { if (argc == 1 && args[0]->rettype() != xpath_type_node_set) return error("Function has to be applied to node set"); - return alloc_node( - argc == 0 ? ast_func_local_name_0 : ast_func_local_name_1, xpath_type_string, args[0]); + return alloc_node(argc == 0 ? ast_func_local_name_0 : ast_func_local_name_1, xpath_type_string, args[0]); } break; @@ -11291,12 +11036,9 @@ struct xpath_parser { } else if (name == PUGIXML_TEXT("namespace-uri") && argc <= 1) { if (argc == 1 && args[0]->rettype() != xpath_type_node_set) return error("Function has to be applied to node set"); - return alloc_node( - argc == 0 ? ast_func_namespace_uri_0 : ast_func_namespace_uri_1, xpath_type_string, args[0]); + return alloc_node(argc == 0 ? ast_func_namespace_uri_0 : ast_func_namespace_uri_1, xpath_type_string, args[0]); } else if (name == PUGIXML_TEXT("normalize-space") && argc <= 1) - return alloc_node( - argc == 0 ? ast_func_normalize_space_0 : ast_func_normalize_space_1, xpath_type_string, args[0], - args[1]); + return alloc_node(argc == 0 ? ast_func_normalize_space_0 : ast_func_normalize_space_1, xpath_type_string, args[0], args[1]); else if (name == PUGIXML_TEXT("not") && argc == 1) return alloc_node(ast_func_not, xpath_type_boolean, args[0]); else if (name == PUGIXML_TEXT("number") && argc <= 1) @@ -11320,8 +11062,7 @@ struct xpath_parser { if (name == PUGIXML_TEXT("string") && argc <= 1) return alloc_node(argc == 0 ? ast_func_string_0 : ast_func_string_1, xpath_type_string, args[0]); else if (name == PUGIXML_TEXT("string-length") && argc <= 1) - return alloc_node( - argc == 0 ? ast_func_string_length_0 : ast_func_string_length_1, xpath_type_number, args[0]); + return alloc_node(argc == 0 ? ast_func_string_length_0 : ast_func_string_length_1, xpath_type_number, args[0]); else if (name == PUGIXML_TEXT("starts-with") && argc == 2) return alloc_node(ast_func_starts_with, xpath_type_boolean, args[0], args[1]); else if (name == PUGIXML_TEXT("substring-before") && argc == 2) @@ -11329,8 +11070,7 @@ struct xpath_parser { else if (name == PUGIXML_TEXT("substring-after") && argc == 2) return alloc_node(ast_func_substring_after, xpath_type_string, args[0], args[1]); else if (name == PUGIXML_TEXT("substring") && (argc == 2 || argc == 3)) - return alloc_node( - argc == 2 ? ast_func_substring_2 : ast_func_substring_3, xpath_type_string, args[0], args[1]); + return alloc_node(argc == 2 ? ast_func_substring_2 : ast_func_substring_3, xpath_type_string, args[0], args[1]); else if (name == PUGIXML_TEXT("sum") && argc == 1) { if (args[0]->rettype() != xpath_type_node_set) return error("Function has to be applied to node set"); @@ -11847,9 +11587,8 @@ struct xpath_parser { // PrimaryExpr begins with '$' in case of it being a variable reference, // '(' in case of it being an expression, string literal, number constant or // function call. - if (_lexer.current() == lex_var_ref || _lexer.current() == lex_open_brace - || _lexer.current() == lex_quoted_string || _lexer.current() == lex_number - || _lexer.current() == lex_string) { + if (_lexer.current() == lex_var_ref || _lexer.current() == lex_open_brace || _lexer.current() == lex_quoted_string + || _lexer.current() == lex_number || _lexer.current() == lex_string) { if (_lexer.current() == lex_string) { // This is either a function call, or not - if not, we shall proceed with location // path @@ -11909,8 +11648,7 @@ struct xpath_parser { binary_op_t() : asttype(ast_unknown), rettype(xpath_type_none), precedence(0) { } - binary_op_t(ast_type_t asttype_, xpath_value_type rettype_, int precedence_) : - asttype(asttype_), rettype(rettype_), precedence(precedence_) + binary_op_t(ast_type_t asttype_, xpath_value_type rettype_, int precedence_) : asttype(asttype_), rettype(rettype_), precedence(precedence_) { } @@ -11989,8 +11727,7 @@ struct xpath_parser { nextop = binary_op_t::parse(_lexer); } - if (op.asttype == ast_op_union - && (lhs->rettype() != xpath_type_node_set || rhs->rettype() != xpath_type_node_set)) + if (op.asttype == ast_op_union && (lhs->rettype() != xpath_type_node_set || rhs->rettype() != xpath_type_node_set)) return error("Union operator has to be applied to node sets"); lhs = alloc_node(op.asttype, op.rettype, lhs, rhs); @@ -12039,10 +11776,8 @@ struct xpath_parser { return n; } - xpath_parser( - const char_t* query, xpath_variable_set* variables, xpath_allocator* alloc, xpath_parse_result* result) : - _alloc(alloc), - _lexer(query), _query(query), _variables(variables), _result(result), _depth(0) + xpath_parser(const char_t* query, xpath_variable_set* variables, xpath_allocator* alloc, xpath_parse_result* result) : + _alloc(alloc), _lexer(query), _query(query), _variables(variables), _result(result), _depth(0) { } @@ -12061,8 +11796,7 @@ struct xpath_parser { return n; } - static xpath_ast_node* - parse(const char_t* query, xpath_variable_set* variables, xpath_allocator* alloc, xpath_parse_result* result) + static xpath_ast_node* parse(const char_t* query, xpath_variable_set* variables, xpath_allocator* alloc, xpath_parse_result* result) { xpath_parser parser(query, variables, alloc, result); @@ -12211,8 +11945,7 @@ PUGI__FN void xpath_node_set::_assign(const_iterator begin_, const_iterator end_ size_t size_ = static_cast(end_ - begin_); // use internal buffer for 0 or 1 elements, heap buffer otherwise - xpath_node* storage = - (size_ <= 1) ? _storage : static_cast(impl::xml_memory::allocate(size_ * sizeof(xpath_node))); + xpath_node* storage = (size_ <= 1) ? _storage : static_cast(impl::xml_memory::allocate(size_ * sizeof(xpath_node))); if (!storage) { #ifdef PUGIXML_NO_EXCEPTIONS @@ -12265,8 +11998,7 @@ PUGI__FN xpath_node_set::~xpath_node_set() impl::xml_memory::deallocate(_begin); } -PUGI__FN xpath_node_set::xpath_node_set(const xpath_node_set& ns) : - _type(type_unsorted), _begin(_storage), _end(_storage) +PUGI__FN xpath_node_set::xpath_node_set(const xpath_node_set& ns) : _type(type_unsorted), _begin(_storage), _end(_storage) { _assign(ns._begin, ns._end, ns._type); } @@ -12395,21 +12127,18 @@ PUGI__FN bool xpath_variable::get_boolean() const PUGI__FN double xpath_variable::get_number() const { - return (_type == xpath_type_number) ? static_cast(this)->value - : impl::gen_nan(); + return (_type == xpath_type_number) ? static_cast(this)->value : impl::gen_nan(); } PUGI__FN const char_t* xpath_variable::get_string() const { - const char_t* value = - (_type == xpath_type_string) ? static_cast(this)->value : 0; + const char_t* value = (_type == xpath_type_string) ? static_cast(this)->value : 0; return value ? value : PUGIXML_TEXT(""); } PUGI__FN const xpath_node_set& xpath_variable::get_node_set() const { - return (_type == xpath_type_node_set) ? static_cast(this)->value - : impl::dummy_node_set; + return (_type == xpath_type_node_set) ? static_cast(this)->value : impl::dummy_node_set; } PUGI__FN bool xpath_variable::set(bool value) @@ -12792,8 +12521,7 @@ PUGI__FN size_t xpath_query::evaluate_string(char_t* buffer, size_t capacity, co impl::xpath_context c(n, 1, 1); impl::xpath_stack_data sd; - impl::xpath_string r = - _impl ? static_cast(_impl)->root->eval_string(c, sd.stack) : impl::xpath_string(); + impl::xpath_string r = _impl ? static_cast(_impl)->root->eval_string(c, sd.stack) : impl::xpath_string(); if (sd.oom) { #ifdef PUGIXML_NO_EXCEPTIONS diff --git a/uibase/uilib/core/pugixml.hpp b/uibase/uilib/core/pugixml.hpp index 282c18aac23455347595dfe76d7c5b6f9f6b3e36..ae2f65f80f758e341d9ca91a36b01d9c74688b80 100644 --- a/uibase/uilib/core/pugixml.hpp +++ b/uibase/uilib/core/pugixml.hpp @@ -625,8 +625,7 @@ public: // node. Copies/converts the buffer, so it may be deleted or changed after the function returns. // Note: append_buffer allocates memory that has the lifetime of the owning document; removing // the appended nodes does not immediately reclaim that memory. - xml_parse_result append_buffer( - const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); // Find attribute using predicate. Returns first attribute for which predicate returned true. template xml_attribute find_attribute(Predicate pred) const @@ -708,8 +707,7 @@ public: xpath_node_set select_nodes(const xpath_query& query) const; // (deprecated: use select_node instead) Select single node by evaluating XPath query. - PUGIXML_DEPRECATED xpath_node - select_single_node(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const; + PUGIXML_DEPRECATED xpath_node select_single_node(const char_t* query, xpath_variable_set* variables = PUGIXML_NULL) const; PUGIXML_DEPRECATED xpath_node select_single_node(const xpath_query& query) const; #endif @@ -1104,12 +1102,9 @@ public: #ifndef PUGIXML_NO_STL // Load document from stream. - xml_parse_result load( - std::basic_istream>& stream, - unsigned int options = parse_default, - xml_encoding encoding = encoding_auto); xml_parse_result - load(std::basic_istream>& stream, unsigned int options = parse_default); + load(std::basic_istream>& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result load(std::basic_istream>& stream, unsigned int options = parse_default); #endif // (deprecated: use load_string instead) Load document from zero-terminated string. No encoding @@ -1120,29 +1115,25 @@ public: xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default); // Load document from file - xml_parse_result - load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); - xml_parse_result - load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after // the function returns. - xml_parse_result load_buffer( - const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and // used for storage of document data). You should ensure that buffer data will persist // throughout the document's lifetime, and free the buffer memory manually once document is // destroyed. - xml_parse_result load_buffer_inplace( - void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and // used for storage of document data). You should allocate the buffer with pugixml allocation // function; document will free the buffer when it is no longer needed (you can't use it // anymore). - xml_parse_result load_buffer_inplace_own( - void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); + xml_parse_result + load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); // Save XML document to writer (semantics is slightly different from xml_node::print, see // documentation for details). @@ -1519,8 +1510,7 @@ std::basic_string, std::allocator> PUGIXML_FUNCTION as_utf8(const std::basic_string, std::allocator>& str); // Convert UTF8 to wide string -std::basic_string, std::allocator> - PUGIXML_FUNCTION as_wide(const char* str); +std::basic_string, std::allocator> PUGIXML_FUNCTION as_wide(const char* str); std::basic_string, std::allocator> PUGIXML_FUNCTION as_wide(const std::basic_string, std::allocator>& str); #endif diff --git a/uibase/uilib/core/uibase.cpp b/uibase/uilib/core/uibase.cpp index bb321c62056999a2e56af46f965ec239a8b43e4c..79ac1e89645fd9be64ee9f88f219d7b13ca1852e 100644 --- a/uibase/uilib/core/uibase.cpp +++ b/uibase/uilib/core/uibase.cpp @@ -182,7 +182,7 @@ LDispatch: void CNotifyPump::NotifyPump(TNotifyUI& msg) { - ///遍历虚拟窗口 + /// 遍历虚拟窗口 if (!msg.sVirtualWnd.IsEmpty()) { for (int i = 0; i < m_VirtualWndMap.GetSize(); i++) { if (LPSTRING key = m_VirtualWndMap.GetAt(i)) { @@ -196,7 +196,7 @@ void CNotifyPump::NotifyPump(TNotifyUI& msg) } /// - //遍历主窗口 + // 遍历主窗口 LoopDispatch(msg); } @@ -233,12 +233,10 @@ HWND CWindowWnd::CreateDuiWindow(HWND hwndParent, LPSTRING pstrWindowName, DWORD HWND CWindowWnd::Create(HWND hwndParent, LPSTRING pstrName, DWORD dwStyle, DWORD dwExStyle, const RECT rc, HMENU hMenu) { - return Create( - hwndParent, pstrName, dwStyle, dwExStyle, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hMenu); + return Create(hwndParent, pstrName, dwStyle, dwExStyle, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hMenu); } -HWND CWindowWnd::Create( - HWND hwndParent, LPSTRING pstrName, DWORD dwStyle, DWORD dwExStyle, int x, int y, int cx, int cy, HMENU hMenu) +HWND CWindowWnd::Create(HWND hwndParent, LPSTRING pstrName, DWORD dwStyle, DWORD dwExStyle, int x, int y, int cx, int cy, HMENU hMenu) { if (GetSuperClassName() != NULL && !RegisterSuperclass()) return NULL; @@ -246,9 +244,8 @@ HWND CWindowWnd::Create( if (GetSuperClassName() == NULL && !RegisterWindowClass()) return NULL; - m_hWnd = ::CreateWindowEx( - dwExStyle, GetWindowClassName(), pstrName, dwStyle, x, y, cx, cy, hwndParent, hMenu, - CPaintManagerUI::GetInstance(), this); + m_hWnd = + ::CreateWindowEx(dwExStyle, GetWindowClassName(), pstrName, dwStyle, x, y, cx, cy, hwndParent, hMenu, CPaintManagerUI::GetInstance(), this); ASSERT(m_hWnd != NULL); return m_hWnd; } @@ -501,11 +498,9 @@ void CWindowWnd::ResizeClient(int cx /*= -1*/, int cy /*= -1*/) if (cy != -1) rc.bottom = cy; if (!::AdjustWindowRectEx( - &rc, GetWindowStyle(m_hWnd), (!(GetWindowStyle(m_hWnd) & WS_CHILD) && (::GetMenu(m_hWnd) != NULL)), - GetWindowExStyle(m_hWnd))) + &rc, GetWindowStyle(m_hWnd), (!(GetWindowStyle(m_hWnd) & WS_CHILD) && (::GetMenu(m_hWnd) != NULL)), GetWindowExStyle(m_hWnd))) return; - ::SetWindowPos( - m_hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); + ::SetWindowPos(m_hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); } LRESULT CWindowWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) diff --git a/uibase/uilib/core/uicontainer.cpp b/uibase/uilib/core/uicontainer.cpp index 666a7d8d32b7efac94a2fe95907c011b1fe23226..f06e0c8566e03327ec72e244726e0950bbfcc434 100644 --- a/uibase/uilib/core/uicontainer.cpp +++ b/uibase/uilib/core/uicontainer.cpp @@ -8,8 +8,8 @@ namespace uilib // CContainerUI::CContainerUI() : - m_iChildPadding(0), m_iChildAlign(DT_LEFT), m_iChildVAlign(DT_TOP), m_bAutoDestroy(true), m_bDelayedDestroy(true), - m_bMouseChildEnabled(true), m_pVerticalScrollBar(NULL), m_pHorizontalScrollBar(NULL), m_bScrollProcess(false) + m_iChildPadding(0), m_iChildAlign(DT_LEFT), m_iChildVAlign(DT_TOP), m_bAutoDestroy(true), m_bDelayedDestroy(true), m_bMouseChildEnabled(true), + m_pVerticalScrollBar(NULL), m_pHorizontalScrollBar(NULL), m_bScrollProcess(false) { ::ZeroMemory(&m_rcInset, sizeof(m_rcInset)); } @@ -299,8 +299,7 @@ void CContainerUI::DoEvent(TEventUI& event) } if (event.Type == UIEVENT_KEYDOWN) { if (IsKeyboardEnabled() && IsEnabled()) { - if (m_pVerticalScrollBar != NULL && m_pVerticalScrollBar->IsVisible() - && m_pVerticalScrollBar->IsEnabled()) { + if (m_pVerticalScrollBar != NULL && m_pVerticalScrollBar->IsVisible() && m_pVerticalScrollBar->IsEnabled()) { switch (event.chKey) { case VK_DOWN: LineDown(); @@ -321,9 +320,7 @@ void CContainerUI::DoEvent(TEventUI& event) EndDown(); return; } - } else if ( - m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() - && m_pHorizontalScrollBar->IsEnabled()) { + } else if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() && m_pHorizontalScrollBar->IsEnabled()) { switch (event.chKey) { case VK_DOWN: LineRight(); @@ -347,8 +344,7 @@ void CContainerUI::DoEvent(TEventUI& event) } } } else if (event.Type == UIEVENT_SCROLLWHEEL) { - if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() - && m_pHorizontalScrollBar->IsEnabled()) { + if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() && m_pHorizontalScrollBar->IsEnabled()) { RECT rcHorizontalScrollBar = m_pHorizontalScrollBar->GetPos(); if (::PtInRect(&rcHorizontalScrollBar, event.ptMouse)) { switch (LOWORD(event.wParam)) { @@ -371,8 +367,7 @@ void CContainerUI::DoEvent(TEventUI& event) return; } } - if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() - && m_pHorizontalScrollBar->IsEnabled()) { + if (m_pHorizontalScrollBar != NULL && m_pHorizontalScrollBar->IsVisible() && m_pHorizontalScrollBar->IsEnabled()) { switch (LOWORD(event.wParam)) { case SB_LINEUP: LineLeft(); @@ -613,15 +608,13 @@ int CContainerUI::FindSelectable(int iIndex, bool bForward /*= true*/) const if (bForward) { for (int i = iIndex; i < GetCount(); i++) { - if (GetItemAt(i)->GetInterface(DUI_CTR_ILISTITEM) != NULL && GetItemAt(i)->IsVisible() - && GetItemAt(i)->IsEnabled()) + if (GetItemAt(i)->GetInterface(DUI_CTR_ILISTITEM) != NULL && GetItemAt(i)->IsVisible() && GetItemAt(i)->IsEnabled()) return i; } return -1; } else { for (int i = iIndex; i >= 0; --i) { - if (GetItemAt(i)->GetInterface(DUI_CTR_ILISTITEM) != NULL && GetItemAt(i)->IsVisible() - && GetItemAt(i)->IsEnabled()) + if (GetItemAt(i)->GetInterface(DUI_CTR_ILISTITEM) != NULL && GetItemAt(i)->IsVisible() && GetItemAt(i)->IsEnabled()) return i; } return FindSelectable(0, true); @@ -813,8 +806,7 @@ CControlUI* CContainerUI::FindControl(FINDCONTROLPROC Proc, LPVOID pData, UINT u for (int it = m_items.GetSize() - 1; it >= 0; it--) { pResult = static_cast(m_items[it])->FindControl(Proc, pData, uFlags); if (pResult != NULL) { - if ((uFlags & UIFIND_HITTEST) != 0 && !pResult->IsFloat() - && !::PtInRect(&rc, *(static_cast(pData)))) + if ((uFlags & UIFIND_HITTEST) != 0 && !pResult->IsFloat() && !::PtInRect(&rc, *(static_cast(pData)))) continue; else return pResult; @@ -824,8 +816,7 @@ CControlUI* CContainerUI::FindControl(FINDCONTROLPROC Proc, LPVOID pData, UINT u for (int it = 0; it < m_items.GetSize(); it++) { pResult = static_cast(m_items[it])->FindControl(Proc, pData, uFlags); if (pResult != NULL) { - if ((uFlags & UIFIND_HITTEST) != 0 && !pResult->IsFloat() - && !::PtInRect(&rc, *(static_cast(pData)))) + if ((uFlags & UIFIND_HITTEST) != 0 && !pResult->IsFloat() && !::PtInRect(&rc, *(static_cast(pData)))) continue; else return pResult; @@ -988,8 +979,7 @@ void CContainerUI::ProcessScrollBar(RECT rc, int cxRequired, int cyRequired) else SetPos(GetRelativePos()); } else { - RECT rcScrollBarPos = { - rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; + RECT rcScrollBarPos = {rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; m_pHorizontalScrollBar->SetPos(rcScrollBarPos, false); if (m_pHorizontalScrollBar->GetScrollRange() != cxScroll) { @@ -1016,8 +1006,7 @@ void CContainerUI::ProcessScrollBar(RECT rc, int cxRequired, int cyRequired) m_pHorizontalScrollBar->SetScrollPos(0); rc.bottom -= m_pHorizontalScrollBar->GetFixedHeight(); } - RECT rcScrollBarPos = { - rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; + RECT rcScrollBarPos = {rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; m_pHorizontalScrollBar->SetPos(rcScrollBarPos, false); if (m_pHorizontalScrollBar->GetScrollRange() != cxRequired - (rc.right - rc.left)) { m_pHorizontalScrollBar->SetScrollRange(cxRequired - (rc.right - rc.left)); @@ -1036,8 +1025,7 @@ void CContainerUI::ProcessScrollBar(RECT rc, int cxRequired, int cyRequired) m_pVerticalScrollBar->SetScrollPos(0); rc.right -= m_pVerticalScrollBar->GetFixedWidth(); if (m_pHorizontalScrollBar->IsVisible()) { - RECT rcScrollBarPos = { - rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; + RECT rcScrollBarPos = {rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; m_pHorizontalScrollBar->SetPos(rcScrollBarPos, false); m_pHorizontalScrollBar->SetScrollRange(cxRequired - (rc.right - rc.left)); } @@ -1068,8 +1056,7 @@ void CContainerUI::ProcessScrollBar(RECT rc, int cxRequired, int cyRequired) m_pVerticalScrollBar->SetScrollRange(0); rc.right += m_pVerticalScrollBar->GetFixedWidth(); if (m_pHorizontalScrollBar->IsVisible()) { - RECT rcScrollBarPos = { - rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; + RECT rcScrollBarPos = {rc.left, rc.bottom, rc.right, rc.bottom + m_pHorizontalScrollBar->GetFixedHeight()}; m_pHorizontalScrollBar->SetPos(rcScrollBarPos, false); m_pHorizontalScrollBar->SetScrollRange(cxRequired - (rc.right - rc.left)); } diff --git a/uibase/uilib/core/uicontrol.cpp b/uibase/uilib/core/uicontrol.cpp index 5b7e10cc79d23a07f73a84874993a8c32ca66d8e..ccfdf69d381015b89911312b9be12f372337e390 100644 --- a/uibase/uilib/core/uicontrol.cpp +++ b/uibase/uilib/core/uicontrol.cpp @@ -4,11 +4,10 @@ namespace uilib { CControlUI::CControlUI() : - m_pManager(NULL), m_pParent(NULL), m_pCover(NULL), m_bUpdateNeeded(true), m_bMenuUsed(false), m_bAsyncNotify(false), - m_bVisible(true), m_bInternVisible(true), m_bFocused(false), m_bEnabled(true), m_bMouseEnabled(true), - m_bKeyboardEnabled(true), m_bFloat(false), m_bSetPos(false), m_chShortcut('\0'), m_pTag(NULL), m_dwBackColor(0), - m_dwBackColor2(0), m_dwBackColor3(0), m_dwBorderColor(0), m_dwFocusBorderColor(0), m_nBorderStyle(PS_SOLID), - m_nTooltipWidth(300) + m_pManager(NULL), m_pParent(NULL), m_pCover(NULL), m_bUpdateNeeded(true), m_bMenuUsed(false), m_bAsyncNotify(false), m_bVisible(true), + m_bInternVisible(true), m_bFocused(false), m_bEnabled(true), m_bMouseEnabled(true), m_bKeyboardEnabled(true), m_bFloat(false), m_bSetPos(false), + m_chShortcut('\0'), m_pTag(NULL), m_dwBackColor(0), m_dwBackColor2(0), m_dwBackColor3(0), m_dwBorderColor(0), m_dwFocusBorderColor(0), + m_nBorderStyle(PS_SOLID), m_nTooltipWidth(300) { m_cXY.cx = m_cXY.cy = 0; m_cxyFixed.cx = m_cxyFixed.cy = 0; @@ -304,16 +303,14 @@ void CControlUI::SetPos(RECT rc, bool bNeedInvalidate) CControlUI* pParent = GetParent(); if (pParent != NULL) { RECT rcParentPos = pParent->GetPos(); - RECT rcCtrl = { - rcParentPos.left + rc.left, rcParentPos.top + rc.top, rcParentPos.left + rc.right, - rcParentPos.top + rc.bottom}; + RECT rcCtrl = {rcParentPos.left + rc.left, rcParentPos.top + rc.top, rcParentPos.left + rc.right, rcParentPos.top + rc.bottom}; m_rcItem = rcCtrl; LONG width = rcParentPos.right - rcParentPos.left; LONG height = rcParentPos.bottom - rcParentPos.top; RECT rcPercent = { - (LONG)(width * m_piFloatPercent.left), (LONG)(height * m_piFloatPercent.top), - (LONG)(width * m_piFloatPercent.right), (LONG)(height * m_piFloatPercent.bottom)}; + (LONG)(width * m_piFloatPercent.left), (LONG)(height * m_piFloatPercent.top), (LONG)(width * m_piFloatPercent.right), + (LONG)(height * m_piFloatPercent.bottom)}; m_cXY.cx = rc.left - rcPercent.left; m_cXY.cy = rc.top - rcPercent.top; m_cxyFixed.cx = rc.right - rcPercent.right - m_cXY.cx; @@ -1170,15 +1167,12 @@ void CControlUI::PaintBkColor(HDC hDC) if (m_dwBackColor3 != 0) { RECT rc = m_rcItem; rc.bottom = (rc.bottom + rc.top) / 2; - CRenderEngine::DrawGradient( - hDC, rc, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), true, 8); + CRenderEngine::DrawGradient(hDC, rc, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), true, 8); rc.top = rc.bottom; rc.bottom = m_rcItem.bottom; - CRenderEngine::DrawGradient( - hDC, rc, GetAdjustColor(m_dwBackColor2), GetAdjustColor(m_dwBackColor3), true, 8); + CRenderEngine::DrawGradient(hDC, rc, GetAdjustColor(m_dwBackColor2), GetAdjustColor(m_dwBackColor3), true, 8); } else - CRenderEngine::DrawGradient( - hDC, m_rcItem, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), true, 16); + CRenderEngine::DrawGradient(hDC, m_rcItem, GetAdjustColor(m_dwBackColor), GetAdjustColor(m_dwBackColor2), true, 16); } else if (m_dwBackColor >= 0xFF000000) CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwBackColor)); else @@ -1204,25 +1198,22 @@ void CControlUI::PaintText(HDC hDC) void CControlUI::PaintBorder(HDC hDC) { if (m_rcBorderSize.left > 0 && (m_dwBorderColor != 0 || m_dwFocusBorderColor != 0)) { - if (m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0) //鐢诲渾瑙掕竟妗 + if (m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0) // 鐢诲渾瑙掕竟妗 { if (IsFocused() && m_dwFocusBorderColor != 0) CRenderEngine::DrawRoundRect( - hDC, m_rcItem, m_rcBorderSize.left, m_cxyBorderRound.cx, m_cxyBorderRound.cy, - GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); + hDC, m_rcItem, m_rcBorderSize.left, m_cxyBorderRound.cx, m_cxyBorderRound.cy, GetAdjustColor(m_dwFocusBorderColor), + m_nBorderStyle); else CRenderEngine::DrawRoundRect( - hDC, m_rcItem, m_rcBorderSize.left, m_cxyBorderRound.cx, m_cxyBorderRound.cy, - GetAdjustColor(m_dwBorderColor), m_nBorderStyle); + hDC, m_rcItem, m_rcBorderSize.left, m_cxyBorderRound.cx, m_cxyBorderRound.cy, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); } else { if (m_rcBorderSize.right == m_rcBorderSize.left && m_rcBorderSize.top == m_rcBorderSize.left && m_rcBorderSize.bottom == m_rcBorderSize.left) { if (IsFocused() && m_dwFocusBorderColor != 0) - CRenderEngine::DrawRect( - hDC, m_rcItem, m_rcBorderSize.left, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); + CRenderEngine::DrawRect(hDC, m_rcItem, m_rcBorderSize.left, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); else - CRenderEngine::DrawRect( - hDC, m_rcItem, m_rcBorderSize.left, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); + CRenderEngine::DrawRect(hDC, m_rcItem, m_rcBorderSize.left, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); } else { RECT rcBorder; if (m_rcBorderSize.left > 0) { @@ -1230,11 +1221,9 @@ void CControlUI::PaintBorder(HDC hDC) rcBorder.left += m_rcBorderSize.left / 2; rcBorder.right = rcBorder.left; if (IsFocused() && m_dwFocusBorderColor != 0) - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.left, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.left, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); else - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.left, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.left, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); } if (m_rcBorderSize.top > 0) { rcBorder = m_rcItem; @@ -1243,22 +1232,18 @@ void CControlUI::PaintBorder(HDC hDC) rcBorder.left += m_rcBorderSize.left; rcBorder.right -= m_rcBorderSize.right; if (IsFocused() && m_dwFocusBorderColor != 0) - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.top, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.top, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); else - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.top, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.top, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); } if (m_rcBorderSize.right > 0) { rcBorder = m_rcItem; rcBorder.left = m_rcItem.right - m_rcBorderSize.right / 2; rcBorder.right = rcBorder.left; if (IsFocused() && m_dwFocusBorderColor != 0) - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.right, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.right, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); else - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.right, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.right, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); } if (m_rcBorderSize.bottom > 0) { rcBorder = m_rcItem; @@ -1267,11 +1252,9 @@ void CControlUI::PaintBorder(HDC hDC) rcBorder.left += m_rcBorderSize.left; rcBorder.right -= m_rcBorderSize.right; if (IsFocused() && m_dwFocusBorderColor != 0) - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.bottom, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.bottom, GetAdjustColor(m_dwFocusBorderColor), m_nBorderStyle); else - CRenderEngine::DrawLine( - hDC, rcBorder, m_rcBorderSize.bottom, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); + CRenderEngine::DrawLine(hDC, rcBorder, m_rcBorderSize.bottom, GetAdjustColor(m_dwBorderColor), m_nBorderStyle); } } } diff --git a/uibase/uilib/core/uicontrol.h b/uibase/uilib/core/uicontrol.h index a9f5e3e434d80f36f08bf7dff1c96b1b6bb829d6..c2f85fd7e8f57927776886950ce11fec183c1c34 100644 --- a/uibase/uilib/core/uicontrol.h +++ b/uibase/uilib/core/uicontrol.h @@ -54,7 +54,7 @@ public: void SetBorderRound(SIZE cxyRound); bool DrawImage(HDC hDC, TDrawInfo& drawInfo); - //边框相关 + // 边框相关 DWORD GetBorderColor() const; void SetBorderColor(DWORD dwBorderColor); RECT GetBorderSize() const; @@ -166,7 +166,7 @@ public: virtual void DoPostPaint(HDC hDC, const RECT& rcPaint); - //虚拟窗口参数 + // 虚拟窗口参数 void SetVirtualWnd(LPSTRING pstrValue); CDuiString GetVirtualWnd() const; diff --git a/uibase/uilib/core/uidefine.h b/uibase/uilib/core/uidefine.h index d2da72be189611a2a563abd25933573536052945..5f34c557474f151f8b788b7b6b42d88cd2cedb93 100644 --- a/uibase/uilib/core/uidefine.h +++ b/uibase/uilib/core/uidefine.h @@ -59,11 +59,17 @@ protected: \ virtual const DUI_MSGMAP* GetMessageMap() const; #define DUI_BASE_BEGIN_MESSAGE_MAP(theClass) \ - const DUI_MSGMAP* theClass::GetMessageMap() const { return &theClass::messageMap; } \ + const DUI_MSGMAP* theClass::GetMessageMap() const \ + { \ + return &theClass::messageMap; \ + } \ const DUI_MSGMAP theClass::messageMap = {NULL, &theClass::_messageEntries[0]}; \ const DUI_MSGMAP_ENTRY theClass::_messageEntries[] = { #define DUI_BEGIN_MESSAGE_MAP(theClass, baseClass) \ - const DUI_MSGMAP* theClass::GetMessageMap() const { return &theClass::messageMap; } \ + const DUI_MSGMAP* theClass::GetMessageMap() const \ + { \ + return &theClass::messageMap; \ + } \ const DUI_MSGMAP theClass::messageMap = {&baseClass::messageMap, &theClass::_messageEntries[0]}; \ const DUI_MSGMAP_ENTRY theClass::_messageEntries[] = { #define DUI_END_MESSAGE_MAP() \ @@ -79,8 +85,7 @@ protected: \ #define DUI_ON_CLICK_CTRNAME(ctrname, memberFxn) {DUI_MSGTYPE_CLICK, ctrname, DuiSig_vn, (DUI_PMSG)&memberFxn}, -#define DUI_ON_SELECTCHANGED_CTRNAME(ctrname, memberFxn) \ - {DUI_MSGTYPE_SELECTCHANGED, ctrname, DuiSig_vn, (DUI_PMSG)&memberFxn}, +#define DUI_ON_SELECTCHANGED_CTRNAME(ctrname, memberFxn) {DUI_MSGTYPE_SELECTCHANGED, ctrname, DuiSig_vn, (DUI_PMSG)&memberFxn}, #define DUI_ON_KILLFOCUS_CTRNAME(ctrname, memberFxn) {DUI_MSGTYPE_KILLFOCUS, ctrname, DuiSig_vn, (DUI_PMSG)&memberFxn}, diff --git a/uibase/uilib/core/uidlgbuilder.cpp b/uibase/uilib/core/uidlgbuilder.cpp index 500f12bff48b6c9063e3592d2b29fb360d0011a1..4fc1b60edb4686bd7a24cd89aa14c9f2de94b424 100644 --- a/uibase/uilib/core/uidlgbuilder.cpp +++ b/uibase/uilib/core/uidlgbuilder.cpp @@ -8,8 +8,7 @@ CDlgBuilder::CDlgBuilder() : m_pCallback(NULL) { } -CControlUI* CDlgBuilder::Create( - STRINGorID xml, LPSTRING type, IDlgBuilderCB* pCallback, CPaintManagerUI* pManager, CControlUI* pParent) +CControlUI* CDlgBuilder::Create(STRINGorID xml, LPSTRING type, IDlgBuilderCB* pCallback, CPaintManagerUI* pManager, CControlUI* pParent) { if (*(xml.m_lpstr) == _T('<')) { if (m_xml.Load(xml.m_lpstr) == S_ERROR) @@ -276,8 +275,8 @@ CControlUI* CDlgBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent, CPaintM CMarkupNode node = pRoot->GetChild(); for (; node.IsValid(); node = node.GetSibling()) { LPSTRING pstrClass = node.GetName(); - if (_tcsicmp(pstrClass, _T("Image")) == 0 || _tcsicmp(pstrClass, _T("Font")) == 0 - || _tcsicmp(pstrClass, _T("Default")) == 0 || _tcsicmp(pstrClass, _T("MultiLanguage")) == 0) + if (_tcsicmp(pstrClass, _T("Image")) == 0 || _tcsicmp(pstrClass, _T("Font")) == 0 || _tcsicmp(pstrClass, _T("Default")) == 0 + || _tcsicmp(pstrClass, _T("MultiLanguage")) == 0) continue; CControlUI* pControl = NULL; @@ -305,7 +304,7 @@ CControlUI* CDlgBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent, CPaintM } continue; } - //树控件XML解析 + // 树控件XML解析 else if (_tcsicmp(pstrClass, _T("TreeNode")) == 0) { CTreeNodeUI* pParentNode = static_cast(pParent->GetInterface(_T("TreeNode"))); CTreeNodeUI* pNode = new CTreeNodeUI(); @@ -336,7 +335,7 @@ CControlUI* CDlgBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent, CPaintM } } - //检索子节点及附加控件 + // 检索子节点及附加控件 if (node.HasChildren()) { CControlUI* pSubControl = _Parse(&node, pNode, pManager); if (pSubControl && _tcsicmp(pSubControl->GetClass(), _T("TreeNodeUI")) != 0) { diff --git a/uibase/uilib/core/uidlgbuilder.h b/uibase/uilib/core/uidlgbuilder.h index d25cf36979c3a98d71db22d2076ffa97085288e2..1e56abc040b8726a6e06a06f374aa18a4a870782 100644 --- a/uibase/uilib/core/uidlgbuilder.h +++ b/uibase/uilib/core/uidlgbuilder.h @@ -17,12 +17,8 @@ class CDlgBuilder public: CDlgBuilder(); - CControlUI* Create( - STRINGorID xml, - LPSTRING type = NULL, - IDlgBuilderCB* pCallback = NULL, - CPaintManagerUI* pManager = NULL, - CControlUI* pParent = NULL); + CControlUI* + Create(STRINGorID xml, LPSTRING type = NULL, IDlgBuilderCB* pCallback = NULL, CPaintManagerUI* pManager = NULL, CControlUI* pParent = NULL); CControlUI* Create(IDlgBuilderCB* pCallback = NULL, CPaintManagerUI* pManager = NULL, CControlUI* pParent = NULL); CMarkup* GetMarkup(); diff --git a/uibase/uilib/core/uimanager.cpp b/uibase/uilib/core/uimanager.cpp index 1fef6888b85e2eade39f8c691d7725324d43cb09..82c871778e446f8a6e617579705f764edee49e5e 100644 --- a/uibase/uilib/core/uimanager.cpp +++ b/uibase/uilib/core/uimanager.cpp @@ -67,8 +67,7 @@ void tagTDrawInfo::Clear() } ///////////////////////////////////////////////////////////////////////////////////// -typedef BOOL(__stdcall* PFUNCUPDATELAYEREDWINDOW)( - HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD); +typedef BOOL(__stdcall* PFUNCUPDATELAYEREDWINDOW)(HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD); PFUNCUPDATELAYEREDWINDOW g_fUpdateLayeredWindow = NULL; HPEN m_hUpdateRectPen = NULL; @@ -78,14 +77,12 @@ TResInfo CPaintManagerUI::m_SharedResInfo; HINSTANCE CPaintManagerUI::m_hInstance = NULL; CPaintManagerUI::CPaintManagerUI() : - m_hWndPaint(NULL), m_hDcPaint(NULL), m_hDcOffscreen(NULL), m_hDcBackground(NULL), m_hbmpOffscreen(NULL), - m_pOffscreenBits(NULL), m_hbmpBackground(NULL), m_pBackgroundBits(NULL), m_iTooltipWidth(-1), - m_iLastTooltipWidth(-1), m_hwndTooltip(NULL), m_iHoverTime(1000), m_bNoActivate(false), m_bShowUpdateRect(false), - m_uTimerID(0x1000), m_pRoot(NULL), m_pFocus(NULL), m_pEventHover(NULL), m_pEventClick(NULL), m_pEventKey(NULL), - m_pLastToolTip(NULL), m_bFirstLayout(true), m_bFocusNeeded(false), m_bUpdateNeeded(false), m_bMouseTracking(false), - m_bMouseCapture(false), m_bIsPainting(false), m_bOffscreenPaint(true), m_bUsedVirtualWnd(false), - m_bAsyncNotifyPosted(false), m_bForceUseSharedRes(false), m_nOpacity(0xFF), m_bLayered(false), - m_bLayeredChanged(false) + m_hWndPaint(NULL), m_hDcPaint(NULL), m_hDcOffscreen(NULL), m_hDcBackground(NULL), m_hbmpOffscreen(NULL), m_pOffscreenBits(NULL), + m_hbmpBackground(NULL), m_pBackgroundBits(NULL), m_iTooltipWidth(-1), m_iLastTooltipWidth(-1), m_hwndTooltip(NULL), m_iHoverTime(1000), + m_bNoActivate(false), m_bShowUpdateRect(false), m_uTimerID(0x1000), m_pRoot(NULL), m_pFocus(NULL), m_pEventHover(NULL), m_pEventClick(NULL), + m_pEventKey(NULL), m_pLastToolTip(NULL), m_bFirstLayout(true), m_bFocusNeeded(false), m_bUpdateNeeded(false), m_bMouseTracking(false), + m_bMouseCapture(false), m_bIsPainting(false), m_bOffscreenPaint(true), m_bUsedVirtualWnd(false), m_bAsyncNotifyPosted(false), + m_bForceUseSharedRes(false), m_nOpacity(0xFF), m_bLayered(false), m_bLayeredChanged(false) { if (m_SharedResInfo.m_DefaultFontInfo.sFontName.IsEmpty()) { m_SharedResInfo.m_dwDefaultDisabledColor = 0xFFA7A6AA; @@ -405,8 +402,7 @@ void CPaintManagerUI::SetOpacity(BYTE nOpacity) HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll")); if (hUser32) { - fSetLayeredWindowAttributes = - (PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes"); + fSetLayeredWindowAttributes = (PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes"); if (fSetLayeredWindowAttributes == NULL) return; } @@ -504,8 +500,7 @@ bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, { for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++) { bool bHandled = false; - LRESULT lResult = - static_cast(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled); + LRESULT lResult = static_cast(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled); if (bHandled) { return true; } @@ -514,8 +509,7 @@ bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, case WM_KEYDOWN: { // Tabbing between controls if (wParam == VK_TAB) { - if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() - && _tcsstr(m_pFocus->GetClass(), DUI_CTR_RICHEDIT) != NULL) { + if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), DUI_CTR_RICHEDIT) != NULL) { if (static_cast(m_pFocus)->IsWantTab()) return false; } @@ -529,8 +523,7 @@ bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, // Handle ALT-shortcut key-combinations FINDSHORTCUT fs = {0}; fs.ch = toupper((int)wParam); - CControlUI* pControl = - m_pRoot->FindControl(__FindControlFromShortcut, &fs, UIFIND_ENABLED | UIFIND_ME_FIRST | UIFIND_TOP_FIRST); + CControlUI* pControl = m_pRoot->FindControl(__FindControlFromShortcut, &fs, UIFIND_ENABLED | UIFIND_ME_FIRST | UIFIND_TOP_FIRST); if (pControl != NULL) { pControl->SetFocus(); pControl->Activate(); @@ -555,25 +548,24 @@ bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes) { - //#ifdef _DEBUG - // switch( uMsg ) { - // case WM_NCPAINT: - // case WM_NCHITTEST: - // case WM_SETCURSOR: - // break; - // default: - // DUITRACE(_T("MSG: %-20s (%08ld)"), DUITRACEMSG(uMsg), ::GetTickCount()); - // } - //#endif - // Not ready yet? + // #ifdef _DEBUG + // switch( uMsg ) { + // case WM_NCPAINT: + // case WM_NCHITTEST: + // case WM_SETCURSOR: + // break; + // default: + // DUITRACE(_T("MSG: %-20s (%08ld)"), DUITRACEMSG(uMsg), ::GetTickCount()); + // } + // #endif + // Not ready yet? if (m_hWndPaint == NULL) return false; // Cycle through listeners for (int i = 0; i < m_aMessageFilters.GetSize(); i++) { bool bHandled = false; - LRESULT lResult = - static_cast(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled); + LRESULT lResult = static_cast(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled); if (bHandled) { lRes = lResult; switch (uMsg) { @@ -734,8 +726,7 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR } else { CControlUI* pControl = NULL; m_aFoundControls.Empty(); - m_pRoot->FindControl( - __FindControlsFromUpdate, NULL, UIFIND_VISIBLE | UIFIND_ME_FIRST | UIFIND_UPDATETEST); + m_pRoot->FindControl(__FindControlsFromUpdate, NULL, UIFIND_VISIBLE | UIFIND_ME_FIRST | UIFIND_UPDATETEST); for (int it = 0; it < m_aFoundControls.GetSize(); it++) { pControl = static_cast(m_aFoundControls[it]); if (!pControl->IsFloat()) @@ -774,11 +765,10 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR if (m_bOffscreenPaint && m_hbmpOffscreen == NULL) { m_hDcOffscreen = ::CreateCompatibleDC(m_hDcPaint); if (m_bLayered) - m_hbmpOffscreen = CRenderEngine::CreateARGB32Bitmap( - m_hDcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, &m_pOffscreenBits); + m_hbmpOffscreen = + CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, &m_pOffscreenBits); else - m_hbmpOffscreen = ::CreateCompatibleBitmap( - m_hDcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top); + m_hbmpOffscreen = ::CreateCompatibleBitmap(m_hDcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top); ASSERT(m_hDcOffscreen); ASSERT(m_hbmpOffscreen); } @@ -818,15 +808,10 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR COLORREF* pChildBitmapBits = NULL; HDC hChildMemDC = ::CreateCompatibleDC(m_hDcOffscreen); HBITMAP hChildBitmap = CRenderEngine::CreateARGB32Bitmap( - hChildMemDC, rcChildWnd.right - rcChildWnd.left, rcChildWnd.bottom - rcChildWnd.top, - &pChildBitmapBits); - ::ZeroMemory( - pChildBitmapBits, - (rcChildWnd.right - rcChildWnd.left) * (rcChildWnd.bottom - rcChildWnd.top) * 4); + hChildMemDC, rcChildWnd.right - rcChildWnd.left, rcChildWnd.bottom - rcChildWnd.top, &pChildBitmapBits); + ::ZeroMemory(pChildBitmapBits, (rcChildWnd.right - rcChildWnd.left) * (rcChildWnd.bottom - rcChildWnd.top) * 4); HBITMAP hOldChildBitmap = (HBITMAP)::SelectObject(hChildMemDC, hChildBitmap); - ::SendMessage( - hChildWnd, WM_PRINT, (WPARAM)hChildMemDC, - (LPARAM)(PRF_CHECKVISIBLE | PRF_CHILDREN | PRF_CLIENT | PRF_OWNED)); + ::SendMessage(hChildWnd, WM_PRINT, (WPARAM)hChildMemDC, (LPARAM)(PRF_CHECKVISIBLE | PRF_CHILDREN | PRF_CLIENT | PRF_OWNED)); COLORREF* pChildBitmapBit; for (LONG y = 0; y < rcChildWnd.bottom - rcChildWnd.top; y++) { for (LONG x = 0; x < rcChildWnd.right - rcChildWnd.left; x++) { @@ -836,8 +821,8 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR } } ::BitBlt( - m_hDcOffscreen, rcChildWnd.left, rcChildWnd.top, rcChildWnd.right - rcChildWnd.left, - rcChildWnd.bottom - rcChildWnd.top, hChildMemDC, 0, 0, SRCCOPY); + m_hDcOffscreen, rcChildWnd.left, rcChildWnd.top, rcChildWnd.right - rcChildWnd.left, rcChildWnd.bottom - rcChildWnd.top, + hChildMemDC, 0, 0, SRCCOPY); ::SelectObject(hChildMemDC, hOldChildBitmap); ::DeleteObject(hChildBitmap); ::DeleteDC(hChildMemDC); @@ -869,8 +854,7 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR if (m_diLayered.pImageInfo != NULL) { if (m_hbmpBackground == NULL) { m_hDcBackground = ::CreateCompatibleDC(m_hDcPaint); - m_hbmpBackground = - CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, &m_pBackgroundBits); + m_hbmpBackground = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, &m_pBackgroundBits); ASSERT(m_hDcBackground); ASSERT(m_hbmpBackground); ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4); @@ -902,12 +886,11 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR POINT ptPos = {rcWnd.left, rcWnd.top}; SIZE sizeWnd = {dwWidth, dwHeight}; POINT ptSrc = {0, 0}; - g_fUpdateLayeredWindow( - m_hWndPaint, m_hDcPaint, &ptPos, &sizeWnd, m_hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA); + g_fUpdateLayeredWindow(m_hWndPaint, m_hDcPaint, &ptPos, &sizeWnd, m_hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA); } else ::BitBlt( - m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top, - m_hDcOffscreen, rcPaint.left, rcPaint.top, SRCCOPY); + m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top, m_hDcOffscreen, rcPaint.left, + rcPaint.top, SRCCOPY); ::SelectObject(m_hDcOffscreen, hOldBitmap); if (m_bShowUpdateRect && !m_bLayered) { @@ -1053,8 +1036,8 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR m_ToolTip.rect = pHover->GetPos(); if (m_hwndTooltip == NULL) { m_hwndTooltip = ::CreateWindowEx( - 0, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, m_hWndPaint, NULL, m_hInstance, NULL); + 0, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + m_hWndPaint, NULL, m_hInstance, NULL); ::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&m_ToolTip); ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth()); ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip); @@ -1077,7 +1060,7 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip); } } - //修改在CListElementUI 有提示 子项无提示下无法跟随移动!(按理说不应该移动的) + // 修改在CListElementUI 有提示 子项无提示下无法跟随移动!(按理说不应该移动的) ::SendMessage(m_hwndTooltip, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD)MAKELONG(pt.x, pt.y)); } return true; @@ -1111,9 +1094,7 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR tme.cbSize = sizeof(TRACKMOUSEEVENT); tme.dwFlags = TME_HOVER | TME_LEAVE; tme.hwndTrack = m_hWndPaint; - tme.dwHoverTime = m_hwndTooltip == NULL - ? m_iHoverTime - : (DWORD)::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L); + tme.dwHoverTime = m_hwndTooltip == NULL ? m_iHoverTime : (DWORD)::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L); _TrackMouseEvent(&tme); m_bMouseTracking = true; } @@ -1139,9 +1120,7 @@ bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LR CDuiPtrArray aNeedMouseLeaveNeeded(m_aNeedMouseLeaveNeeded.GetSize()); aNeedMouseLeaveNeeded.Resize(m_aNeedMouseLeaveNeeded.GetSize()); - ::CopyMemory( - aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), - m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID)); + ::CopyMemory(aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID)); for (int i = 0; i < aNeedMouseLeaveNeeded.GetSize(); i++) { static_cast(aNeedMouseLeaveNeeded[i])->Event(event); } @@ -1803,16 +1782,14 @@ bool CPaintManagerUI::SetNextTabControl(bool bForward) FINDTABINFO info1 = {0}; info1.pFocus = m_pFocus; info1.bForward = bForward; - CControlUI* pControl = - m_pRoot->FindControl(__FindControlFromTab, &info1, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST); + CControlUI* pControl = m_pRoot->FindControl(__FindControlFromTab, &info1, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST); if (pControl == NULL) { if (bForward) { // Wrap around FINDTABINFO info2 = {0}; info2.pFocus = bForward ? NULL : info1.pLast; info2.bForward = bForward; - pControl = - m_pRoot->FindControl(__FindControlFromTab, &info2, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST); + pControl = m_pRoot->FindControl(__FindControlFromTab, &info2, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST); } else { pControl = info1.pLast; } @@ -1993,12 +1970,7 @@ bool CPaintManagerUI::RemoveMouseLeaveNeeded(CControlUI* pControl) } void CPaintManagerUI::SendNotify( - CControlUI* pControl, - LPSTRING pstrMessage, - WPARAM wParam /*= 0*/, - LPARAM lParam /*= 0*/, - bool bAsync /*= false*/, - bool bEnableRepeat /*= true*/) + CControlUI* pControl, LPSTRING pstrMessage, WPARAM wParam /*= 0*/, LPARAM lParam /*= 0*/, bool bAsync /*= false*/, bool bEnableRepeat /*= true*/) { TNotifyUI Msg; Msg.pSender = pControl; @@ -2165,8 +2137,7 @@ TFontInfo* CPaintManagerUI::GetDefaultFontInfo() } } -void CPaintManagerUI::SetDefaultFont( - LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared) +void CPaintManagerUI::SetDefaultFont(LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared) { LOGFONT lf = {0}; ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf); @@ -2222,8 +2193,7 @@ DWORD CPaintManagerUI::GetCustomFontCount(bool bShared) const return m_ResInfo.m_CustomFonts.GetSize(); } -HFONT CPaintManagerUI::AddFont( - int id, LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared) +HFONT CPaintManagerUI::AddFont(int id, LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared) { LOGFONT lf = {0}; ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf); @@ -2317,16 +2287,16 @@ HFONT CPaintManagerUI::GetFont(LPSTRING pStrFontName, int nSize, bool bBold, boo for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++) { if (LPSTRING key = m_ResInfo.m_CustomFonts.GetAt(i)) { pFontInfo = static_cast(m_ResInfo.m_CustomFonts.Find(key)); - if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize - && pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) + if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize && pFontInfo->bBold == bBold + && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) return pFontInfo->hFont; } } for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++) { if (LPSTRING key = m_SharedResInfo.m_CustomFonts.GetAt(i)) { pFontInfo = static_cast(m_SharedResInfo.m_CustomFonts.Find(key)); - if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize - && pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) + if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize && pFontInfo->bBold == bBold + && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) return pFontInfo->hFont; } } @@ -2358,17 +2328,15 @@ int CPaintManagerUI::GetFontIndex(HFONT hFont, bool bShared) return -1; } -int CPaintManagerUI::GetFontIndex( - LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared) +int CPaintManagerUI::GetFontIndex(LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared) { TFontInfo* pFontInfo = NULL; if (bShared) { for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++) { if (LPSTRING key = m_SharedResInfo.m_CustomFonts.GetAt(i)) { pFontInfo = static_cast(m_SharedResInfo.m_CustomFonts.Find(key)); - if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize - && pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline - && pFontInfo->bItalic == bItalic) + if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize && pFontInfo->bBold == bBold + && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) return _ttoi(key); } } @@ -2376,9 +2344,8 @@ int CPaintManagerUI::GetFontIndex( for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++) { if (LPSTRING key = m_ResInfo.m_CustomFonts.GetAt(i)) { pFontInfo = static_cast(m_ResInfo.m_CustomFonts.Find(key)); - if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize - && pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline - && pFontInfo->bItalic == bItalic) + if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize && pFontInfo->bBold == bBold + && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) return _ttoi(key); } } @@ -2598,8 +2565,7 @@ const TImageInfo* CPaintManagerUI::AddImage(LPSTRING bitmap, LPSTRING type, DWOR return data; } -const TImageInfo* - CPaintManagerUI::AddImage(LPSTRING bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared) +const TImageInfo* CPaintManagerUI::AddImage(LPSTRING bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared) { // 因无法确定外部HBITMAP格式,不能使用hsl调整 if (bitmap == NULL || bitmap[0] == _T('\0')) @@ -2734,16 +2700,14 @@ void CPaintManagerUI::AddDefaultAttributeList(LPSTRING pStrControlName, LPSTRING if (bShared || m_bForceUseSharedRes) { CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList); if (pDefaultAttr != NULL) { - CDuiString* pOldDefaultAttr = - static_cast(m_SharedResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr)); + CDuiString* pOldDefaultAttr = static_cast(m_SharedResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr)); if (pOldDefaultAttr) delete pOldDefaultAttr; } } else { CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList); if (pDefaultAttr != NULL) { - CDuiString* pOldDefaultAttr = - static_cast(m_ResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr)); + CDuiString* pOldDefaultAttr = static_cast(m_ResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr)); if (pOldDefaultAttr) delete pOldDefaultAttr; } diff --git a/uibase/uilib/core/uimanager.h b/uibase/uilib/core/uimanager.h index e7269d38f7e2cc9709faebdf28325a85bfda2a64..df5b6aa0903aba7f2ba9ac26a38f7d197d0c05b1 100644 --- a/uibase/uilib/core/uimanager.h +++ b/uibase/uilib/core/uimanager.h @@ -249,11 +249,9 @@ public: void SetDefaultSelectedBkColor(DWORD dwColor, bool bShared = false); TFontInfo* GetDefaultFontInfo(); - void SetDefaultFont( - LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false); + void SetDefaultFont(LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false); DWORD GetCustomFontCount(bool bShared = false) const; - HFONT AddFont( - int id, LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false); + HFONT AddFont(int id, LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false); HFONT GetFont(int id); HFONT GetFont(LPSTRING pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic); int GetFontIndex(HFONT hFont, bool bShared = false); @@ -266,10 +264,8 @@ public: const TImageInfo* GetImage(LPSTRING bitmap); const TImageInfo* GetImageEx(LPSTRING bitmap, LPSTRING type = NULL, DWORD mask = 0, bool bUseHSL = false); - const TImageInfo* - AddImage(LPSTRING bitmap, LPSTRING type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bShared = false); - const TImageInfo* - AddImage(LPSTRING bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared = false); + const TImageInfo* AddImage(LPSTRING bitmap, LPSTRING type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bShared = false); + const TImageInfo* AddImage(LPSTRING bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared = false); void RemoveImage(LPSTRING bitmap, bool bShared = false); void RemoveAllImages(bool bShared = false); void ReloadImages(); @@ -321,13 +317,7 @@ public: bool AddNotifier(INotifyUI* pControl); bool RemoveNotifier(INotifyUI* pControl); void SendNotify(TNotifyUI& Msg, bool bAsync = false, bool bEnableRepeat = true); - void SendNotify( - CControlUI* pControl, - LPSTRING pstrMessage, - WPARAM wParam = 0, - LPARAM lParam = 0, - bool bAsync = false, - bool bEnableRepeat = true); + void SendNotify(CControlUI* pControl, LPSTRING pstrMessage, WPARAM wParam = 0, LPARAM lParam = 0, bool bAsync = false, bool bEnableRepeat = true); bool AddPreMessageFilter(IMessageFilterUI* pFilter); bool RemovePreMessageFilter(IMessageFilterUI* pFilter); diff --git a/uibase/uilib/core/uimarkup.cpp b/uibase/uilib/core/uimarkup.cpp index 57ed80771417b89571527cc74fba6ab2ab946d21..1fa322e7743b89133267a268b93293a44d14a180 100644 --- a/uibase/uilib/core/uimarkup.cpp +++ b/uibase/uilib/core/uimarkup.cpp @@ -501,14 +501,10 @@ void CMarkup::_ParseMetaChar(LPTSTR& pstrText, LPTSTR& pstrDest) } else if (pstrText[0] == _T('g') && pstrText[1] == _T('t') && pstrText[2] == _T(';')) { *pstrDest++ = _T('>'); pstrText += 3; - } else if ( - pstrText[0] == _T('q') && pstrText[1] == _T('u') && pstrText[2] == _T('o') && pstrText[3] == _T('t') - && pstrText[4] == _T(';')) { + } else if (pstrText[0] == _T('q') && pstrText[1] == _T('u') && pstrText[2] == _T('o') && pstrText[3] == _T('t') && pstrText[4] == _T(';')) { *pstrDest++ = _T('\"'); pstrText += 5; - } else if ( - pstrText[0] == _T('a') && pstrText[1] == _T('p') && pstrText[2] == _T('o') && pstrText[3] == _T('s') - && pstrText[4] == _T(';')) { + } else if (pstrText[0] == _T('a') && pstrText[1] == _T('p') && pstrText[2] == _T('o') && pstrText[3] == _T('s') && pstrText[4] == _T(';')) { *pstrDest++ = _T('\''); pstrText += 5; } else { diff --git a/uibase/uilib/core/uirender.cpp b/uibase/uilib/core/uirender.cpp index 4804f0dfbd65092930251d53d9b07319cd9a8c21..ba417e8d5571e2d879c758720b73aeb352f3fd34 100644 --- a/uibase/uilib/core/uirender.cpp +++ b/uibase/uilib/core/uirender.cpp @@ -3,8 +3,7 @@ #define RES_TYPE_COLOR _T("*COLOR*") extern "C" { -extern unsigned char* - stbi_load_from_memory(unsigned char const* buffer, int len, int* x, int* y, int* comp, int req_comp); +extern unsigned char* stbi_load_from_memory(unsigned char const* buffer, int len, int* x, int* y, int* comp, int req_comp); extern void stbi_image_free(void* retval_from_stbi_load); }; @@ -72,15 +71,14 @@ static const float OneThird = 1.0f / 3; static void RGBtoHSL(DWORD ARGB, float* H, float* S, float* L) { - const float R = (float)GetRValue(ARGB), G = (float)GetGValue(ARGB), B = (float)GetBValue(ARGB), - nR = (R < 0 ? 0 : (R > 255 ? 255 : R)) / 255, nG = (G < 0 ? 0 : (G > 255 ? 255 : G)) / 255, - nB = (B < 0 ? 0 : (B > 255 ? 255 : B)) / 255, m = min(min(nR, nG), nB), M = max(max(nR, nG), nB); + const float R = (float)GetRValue(ARGB), G = (float)GetGValue(ARGB), B = (float)GetBValue(ARGB), nR = (R < 0 ? 0 : (R > 255 ? 255 : R)) / 255, + nG = (G < 0 ? 0 : (G > 255 ? 255 : G)) / 255, nB = (B < 0 ? 0 : (B > 255 ? 255 : B)) / 255, m = min(min(nR, nG), nB), + M = max(max(nR, nG), nB); *L = (m + M) / 2; if (M == m) *H = *S = 0; else { - const float f = (nR == m) ? (nG - nB) : ((nG == m) ? (nB - nR) : (nR - nG)), - i = (nR == m) ? 3.0f : ((nG == m) ? 5.0f : 1.0f); + const float f = (nR == m) ? (nG - nB) : ((nG == m) ? (nB - nR) : (nR - nG)), i = (nR == m) ? 3.0f : ((nG == m) ? 5.0f : 1.0f); *H = (i - f / (M - m)); if (*H >= 6) *H -= 6; @@ -91,44 +89,25 @@ static void RGBtoHSL(DWORD ARGB, float* H, float* S, float* L) static void HSLtoRGB(DWORD* ARGB, float H, float S, float L) { - const float q = 2 * L < 1 ? L * (1 + S) : (L + S - L * S), p = 2 * L - q, h = H / 360, tr = h + OneThird, tg = h, - tb = h - OneThird, ntr = tr < 0 ? tr + 1 : (tr > 1 ? tr - 1 : tr), - ntg = tg < 0 ? tg + 1 : (tg > 1 ? tg - 1 : tg), ntb = tb < 0 ? tb + 1 : (tb > 1 ? tb - 1 : tb), - B = 255 - * (6 * ntr < 1 ? p + (q - p) * 6 * ntr - : (2 * ntr < 1 ? q : (3 * ntr < 2 ? p + (q - p) * 6 * (2.0f * OneThird - ntr) : p))), - G = 255 - * (6 * ntg < 1 ? p + (q - p) * 6 * ntg - : (2 * ntg < 1 ? q : (3 * ntg < 2 ? p + (q - p) * 6 * (2.0f * OneThird - ntg) : p))), - R = 255 - * (6 * ntb < 1 ? p + (q - p) * 6 * ntb - : (2 * ntb < 1 ? q : (3 * ntb < 2 ? p + (q - p) * 6 * (2.0f * OneThird - ntb) : p))); + const float q = 2 * L < 1 ? L * (1 + S) : (L + S - L * S), p = 2 * L - q, h = H / 360, tr = h + OneThird, tg = h, tb = h - OneThird, + ntr = tr < 0 ? tr + 1 : (tr > 1 ? tr - 1 : tr), ntg = tg < 0 ? tg + 1 : (tg > 1 ? tg - 1 : tg), + ntb = tb < 0 ? tb + 1 : (tb > 1 ? tb - 1 : tb), + B = 255 * (6 * ntr < 1 ? p + (q - p) * 6 * ntr : (2 * ntr < 1 ? q : (3 * ntr < 2 ? p + (q - p) * 6 * (2.0f * OneThird - ntr) : p))), + G = 255 * (6 * ntg < 1 ? p + (q - p) * 6 * ntg : (2 * ntg < 1 ? q : (3 * ntg < 2 ? p + (q - p) * 6 * (2.0f * OneThird - ntg) : p))), + R = 255 * (6 * ntb < 1 ? p + (q - p) * 6 * ntb : (2 * ntb < 1 ? q : (3 * ntb < 2 ? p + (q - p) * 6 * (2.0f * OneThird - ntb) : p))); *ARGB &= 0xFF000000; - *ARGB |= - RGB((BYTE)(R < 0 ? 0 : (R > 255 ? 255 : R)), (BYTE)(G < 0 ? 0 : (G > 255 ? 255 : G)), - (BYTE)(B < 0 ? 0 : (B > 255 ? 255 : B))); + *ARGB |= RGB((BYTE)(R < 0 ? 0 : (R > 255 ? 255 : R)), (BYTE)(G < 0 ? 0 : (G > 255 ? 255 : G)), (BYTE)(B < 0 ? 0 : (B > 255 ? 255 : B))); } static COLORREF PixelAlpha(COLORREF clrSrc, double src_darken, COLORREF clrDest, double dest_darken) { return RGB( - GetRValue(clrSrc) * src_darken + GetRValue(clrDest) * dest_darken, - GetGValue(clrSrc) * src_darken + GetGValue(clrDest) * dest_darken, + GetRValue(clrSrc) * src_darken + GetRValue(clrDest) * dest_darken, GetGValue(clrSrc) * src_darken + GetGValue(clrDest) * dest_darken, GetBValue(clrSrc) * src_darken + GetBValue(clrDest) * dest_darken); } -static BOOL WINAPI AlphaBitBlt( - HDC hDC, - int nDestX, - int nDestY, - int dwWidth, - int dwHeight, - HDC hSrcDC, - int nSrcX, - int nSrcY, - int wSrc, - int hSrc, - BLENDFUNCTION ftn) +static BOOL WINAPI + AlphaBitBlt(HDC hDC, int nDestX, int nDestY, int dwWidth, int dwHeight, HDC hSrcDC, int nSrcX, int nSrcY, int wSrc, int hSrc, BLENDFUNCTION ftn) { HDC hTempDC = ::CreateCompatibleDC(hDC); if (NULL == hTempDC) @@ -275,8 +254,7 @@ HBITMAP CRenderEngine::CreateARGB32Bitmap(HDC hDC, int cx, int cy, COLORREF** pB void CRenderEngine::AdjustImage(bool bUseHSL, TImageInfo* imageInfo, short H, short S, short L) { - if (imageInfo == NULL || imageInfo->bUseHSL == false || imageInfo->hBitmap == NULL || imageInfo->pBits == NULL - || imageInfo->pSrcBits == NULL) + if (imageInfo == NULL || imageInfo->bUseHSL == false || imageInfo->hBitmap == NULL || imageInfo->pBits == NULL || imageInfo->pSrcBits == NULL) return; if (bUseHSL == false || (H == 180 && S == 100 && L == 100)) { ::CopyMemory(imageInfo->pBits, imageInfo->pSrcBits, imageInfo->nX * imageInfo->nY * 4); @@ -306,8 +284,7 @@ TImageInfo* CRenderEngine::LoadImage(STRINGorID bitmap, LPSTRING type, DWORD mas CDuiString sFile = CPaintManagerUI::GetResourcePath(); sFile += bitmap.m_lpstr; - HANDLE hFile = ::CreateFile( - sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) break; dwSize = ::GetFileSize(hFile, NULL); @@ -333,9 +310,8 @@ TImageInfo* CRenderEngine::LoadImage(STRINGorID bitmap, LPSTRING type, DWORD mas } while (0); while (!pData) { - //读不到图片, 则直接去读取bitmap.m_lpstr指向的路径 - HANDLE hFile = ::CreateFile( - bitmap.m_lpstr, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + // 读不到图片, 则直接去读取bitmap.m_lpstr指向的路径 + HANDLE hFile = ::CreateFile(bitmap.m_lpstr, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) break; dwSize = ::GetFileSize(hFile, NULL); @@ -474,8 +450,7 @@ void CRenderEngine::DrawImage( ASSERT(::GetObjectType(hDC) == OBJ_DC || ::GetObjectType(hDC) == OBJ_MEMDC); typedef BOOL(WINAPI * LPALPHABLEND)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION); - static LPALPHABLEND lpAlphaBlend = - (LPALPHABLEND)::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend"); + static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND)::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend"); if (lpAlphaBlend == NULL) lpAlphaBlend = AlphaBitBlt; @@ -503,9 +478,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, - rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, + rcBmpPart.top + rcScale9.top, rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, bf); } else if (bTiledX && bTiledY) { LONG lWidth = rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right; @@ -529,9 +503,8 @@ void CRenderEngine::DrawImage( lDestRight = rcDest.right; } lpAlphaBlend( - hDC, rcDest.left + lWidth * i, rcDest.top + lHeight * j, lDestRight - lDestLeft, - lDestBottom - lDestTop, hCloneDC, rcBmpPart.left + rcScale9.left, - rcBmpPart.top + rcScale9.top, lDrawWidth, lDrawHeight, bf); + hDC, rcDest.left + lWidth * i, rcDest.top + lHeight * j, lDestRight - lDestLeft, lDestBottom - lDestTop, hCloneDC, + rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, lDrawWidth, lDrawHeight, bf); } } } else if (bTiledX) { @@ -547,9 +520,8 @@ void CRenderEngine::DrawImage( } rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, lDestLeft, rcDest.top, lDestRight - lDestLeft, rcDest.bottom, hCloneDC, - rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, lDrawWidth, - rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, bf); + hDC, lDestLeft, rcDest.top, lDestRight - lDestLeft, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, + rcBmpPart.top + rcScale9.top, lDrawWidth, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, bf); } } else { // bTiledY LONG lHeight = rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom; @@ -584,8 +556,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, rcBmpPart.top, - rcScale9.left, rcScale9.top, bf); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, rcBmpPart.top, rcScale9.left, rcScale9.top, + bf); } } // top @@ -600,8 +572,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, - rcBmpPart.top, rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcScale9.top, bf); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, rcBmpPart.top, + rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcScale9.top, bf); } } // right-top @@ -616,8 +588,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.right - rcScale9.right, rcBmpPart.top, rcScale9.right, rcScale9.top, bf); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.right - rcScale9.right, rcBmpPart.top, + rcScale9.right, rcScale9.top, bf); } } // left @@ -632,8 +604,7 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, - rcBmpPart.top + rcScale9.top, rcScale9.left, + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, rcBmpPart.top + rcScale9.top, rcScale9.left, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, bf); } } @@ -649,9 +620,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.right - rcScale9.right, rcBmpPart.top + rcScale9.top, rcScale9.right, - rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, bf); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.right - rcScale9.right, + rcBmpPart.top + rcScale9.top, rcScale9.right, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, bf); } } // left-bottom @@ -666,8 +636,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, - rcBmpPart.bottom - rcScale9.bottom, rcScale9.left, rcScale9.bottom, bf); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, rcBmpPart.bottom - rcScale9.bottom, + rcScale9.left, rcScale9.bottom, bf); } } // bottom @@ -683,8 +653,7 @@ void CRenderEngine::DrawImage( rcDest.bottom -= rcDest.top; lpAlphaBlend( hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, - rcBmpPart.bottom - rcScale9.bottom, - rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcScale9.bottom, bf); + rcBmpPart.bottom - rcScale9.bottom, rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcScale9.bottom, bf); } } // right-bottom @@ -699,15 +668,13 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; lpAlphaBlend( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.right - rcScale9.right, rcBmpPart.bottom - rcScale9.bottom, rcScale9.right, - rcScale9.bottom, bf); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.right - rcScale9.right, + rcBmpPart.bottom - rcScale9.bottom, rcScale9.right, rcScale9.bottom, bf); } } } else { - if (rc.right - rc.left == rcBmpPart.right - rcBmpPart.left - && rc.bottom - rc.top == rcBmpPart.bottom - rcBmpPart.top && rcScale9.left == 0 && rcScale9.right == 0 - && rcScale9.top == 0 && rcScale9.bottom == 0) { + if (rc.right - rc.left == rcBmpPart.right - rcBmpPart.left && rc.bottom - rc.top == rcBmpPart.bottom - rcBmpPart.top && rcScale9.left == 0 + && rcScale9.right == 0 && rcScale9.top == 0 && rcScale9.bottom == 0) { if (::IntersectRect(&rcTemp, &rcPaint, &rc)) { ::BitBlt( hDC, rcTemp.left, rcTemp.top, rcTemp.right - rcTemp.left, rcTemp.bottom - rcTemp.top, hCloneDC, @@ -727,9 +694,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, - rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, + rcBmpPart.top + rcScale9.top, rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, SRCCOPY); } else if (bTiledX && bTiledY) { LONG lWidth = rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right; @@ -753,9 +719,8 @@ void CRenderEngine::DrawImage( lDestRight = rcDest.right; } ::BitBlt( - hDC, rcDest.left + lWidth * i, rcDest.top + lHeight * j, lDestRight - lDestLeft, - lDestBottom - lDestTop, hCloneDC, rcBmpPart.left + rcScale9.left, - rcBmpPart.top + rcScale9.top, SRCCOPY); + hDC, rcDest.left + lWidth * i, rcDest.top + lHeight * j, lDestRight - lDestLeft, lDestBottom - lDestTop, hCloneDC, + rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, SRCCOPY); } } } else if (bTiledX) { @@ -771,9 +736,8 @@ void CRenderEngine::DrawImage( } rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, lDestLeft, rcDest.top, lDestRight - lDestLeft, rcDest.bottom, hCloneDC, - rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, lDrawWidth, - rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, SRCCOPY); + hDC, lDestLeft, rcDest.top, lDestRight - lDestLeft, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, + rcBmpPart.top + rcScale9.top, lDrawWidth, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, SRCCOPY); } } else { // bTiledY LONG lHeight = rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom; @@ -788,10 +752,9 @@ void CRenderEngine::DrawImage( } rcDest.right -= rcDest.left; ::StretchBlt( - hDC, rcDest.left, rcDest.top + lHeight * i, rcDest.right, lDestBottom - lDestTop, - hCloneDC, rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, - rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, lDrawHeight, - SRCCOPY); + hDC, rcDest.left, rcDest.top + lHeight * i, rcDest.right, lDestBottom - lDestTop, hCloneDC, + rcBmpPart.left + rcScale9.left, rcBmpPart.top + rcScale9.top, + rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, lDrawHeight, SRCCOPY); } } } @@ -809,8 +772,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, - rcBmpPart.top, rcScale9.left, rcScale9.top, SRCCOPY); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, rcBmpPart.top, rcScale9.left, + rcScale9.top, SRCCOPY); } } // top @@ -825,8 +788,7 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.left + rcScale9.left, rcBmpPart.top, + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, rcBmpPart.top, rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcScale9.top, SRCCOPY); } } @@ -842,8 +804,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.right - rcScale9.right, rcBmpPart.top, rcScale9.right, rcScale9.top, SRCCOPY); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.right - rcScale9.right, rcBmpPart.top, + rcScale9.right, rcScale9.top, SRCCOPY); } } // left @@ -858,9 +820,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, - rcBmpPart.top + rcScale9.top, rcScale9.left, - rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, SRCCOPY); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, rcBmpPart.top + rcScale9.top, + rcScale9.left, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, SRCCOPY); } } // right @@ -875,9 +836,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.right - rcScale9.right, rcBmpPart.top + rcScale9.top, rcScale9.right, - rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, SRCCOPY); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.right - rcScale9.right, + rcBmpPart.top + rcScale9.top, rcScale9.right, rcBmpPart.bottom - rcBmpPart.top - rcScale9.top - rcScale9.bottom, SRCCOPY); } } // left-bottom @@ -892,8 +852,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, - rcBmpPart.bottom - rcScale9.bottom, rcScale9.left, rcScale9.bottom, SRCCOPY); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left, rcBmpPart.bottom - rcScale9.bottom, + rcScale9.left, rcScale9.bottom, SRCCOPY); } } // bottom @@ -908,9 +868,9 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.left + rcScale9.left, rcBmpPart.bottom - rcScale9.bottom, - rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcScale9.bottom, SRCCOPY); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.left + rcScale9.left, + rcBmpPart.bottom - rcScale9.bottom, rcBmpPart.right - rcBmpPart.left - rcScale9.left - rcScale9.right, rcScale9.bottom, + SRCCOPY); } } // right-bottom @@ -925,9 +885,8 @@ void CRenderEngine::DrawImage( rcDest.right -= rcDest.left; rcDest.bottom -= rcDest.top; ::StretchBlt( - hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, - rcBmpPart.right - rcScale9.right, rcBmpPart.bottom - rcScale9.bottom, rcScale9.right, - rcScale9.bottom, SRCCOPY); + hDC, rcDest.left, rcDest.top, rcDest.right, rcDest.bottom, hCloneDC, rcBmpPart.right - rcScale9.right, + rcBmpPart.bottom - rcScale9.bottom, rcScale9.right, rcScale9.bottom, SRCCOPY); } } } @@ -937,8 +896,7 @@ void CRenderEngine::DrawImage( ::DeleteDC(hCloneDC); } -bool CRenderEngine::DrawImage( - HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, TDrawInfo& drawInfo) +bool CRenderEngine::DrawImage(HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, TDrawInfo& drawInfo) { // 1、aaa.jpg // 2、file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0' scale9='0,0,0,0' @@ -1060,8 +1018,7 @@ bool CRenderEngine::DrawImage( return false; drawInfo.pImageInfo = data; - if (drawInfo.rcBmpPart.left == 0 && drawInfo.rcBmpPart.right == 0 && drawInfo.rcBmpPart.top == 0 - && drawInfo.rcBmpPart.bottom == 0) { + if (drawInfo.rcBmpPart.left == 0 && drawInfo.rcBmpPart.right == 0 && drawInfo.rcBmpPart.top == 0 && drawInfo.rcBmpPart.bottom == 0) { drawInfo.rcBmpPart.right = data->nX; drawInfo.rcBmpPart.bottom = data->nY; } @@ -1075,8 +1032,7 @@ bool CRenderEngine::DrawImage( return true; RECT rcDest = rcItem; - if (drawInfo.rcDestOffset.left != 0 || drawInfo.rcDestOffset.top != 0 || drawInfo.rcDestOffset.right != 0 - || drawInfo.rcDestOffset.bottom != 0) { + if (drawInfo.rcDestOffset.left != 0 || drawInfo.rcDestOffset.top != 0 || drawInfo.rcDestOffset.right != 0 || drawInfo.rcDestOffset.bottom != 0) { rcDest.left = rcItem.left + drawInfo.rcDestOffset.left; rcDest.top = rcItem.top + drawInfo.rcDestOffset.top; rcDest.right = rcItem.left + drawInfo.rcDestOffset.right; @@ -1093,8 +1049,8 @@ bool CRenderEngine::DrawImage( if (!::IntersectRect(&rcTemp, &rcDest, &rcPaint)) return true; DrawImage( - hDC, drawInfo.pImageInfo->hBitmap, rcDest, rcPaint, drawInfo.rcBmpPart, drawInfo.rcScale9, - drawInfo.pImageInfo->bAlpha, drawInfo.uFade, drawInfo.bHole, drawInfo.bTiledX, drawInfo.bTiledY); + hDC, drawInfo.pImageInfo->hBitmap, rcDest, rcPaint, drawInfo.rcBmpPart, drawInfo.rcScale9, drawInfo.pImageInfo->bAlpha, drawInfo.uFade, + drawInfo.bHole, drawInfo.bTiledX, drawInfo.bTiledY); return true; } @@ -1132,13 +1088,11 @@ void CRenderEngine::DrawColor(HDC hDC, const RECT& rc, DWORD color) void CRenderEngine::DrawGradient(HDC hDC, const RECT& rc, DWORD dwFirst, DWORD dwSecond, bool bVertical, int nSteps) { typedef BOOL(WINAPI * LPALPHABLEND)(HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION); - static LPALPHABLEND lpAlphaBlend = - (LPALPHABLEND)::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend"); + static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND)::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend"); if (lpAlphaBlend == NULL) lpAlphaBlend = AlphaBitBlt; typedef BOOL(WINAPI * PGradientFill)(HDC, PTRIVERTEX, ULONG, PVOID, ULONG, ULONG); - static PGradientFill lpGradientFill = - (PGradientFill)::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "GradientFill"); + static PGradientFill lpGradientFill = (PGradientFill)::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "GradientFill"); BYTE bAlpha = (BYTE)(((dwFirst >> 24) + (dwSecond >> 24)) >> 1); if (bAlpha == 0) @@ -1161,10 +1115,8 @@ void CRenderEngine::DrawGradient(HDC hDC, const RECT& rc, DWORD dwFirst, DWORD d } if (lpGradientFill != NULL) { TRIVERTEX triv[2] = { - {rcPaint.left, rcPaint.top, GetBValue(dwFirst) << 8, GetGValue(dwFirst) << 8, GetRValue(dwFirst) << 8, - 0xFF00 }, - {rcPaint.right, rcPaint.bottom, GetBValue(dwSecond) << 8, GetGValue(dwSecond) << 8, - GetRValue(dwSecond) << 8, 0xFF00} + {rcPaint.left, rcPaint.top, GetBValue(dwFirst) << 8, GetGValue(dwFirst) << 8, GetRValue(dwFirst) << 8, 0xFF00}, + {rcPaint.right, rcPaint.bottom, GetBValue(dwSecond) << 8, GetGValue(dwSecond) << 8, GetRValue(dwSecond) << 8, 0xFF00} }; GRADIENT_RECT grc = {0, 1}; lpGradientFill(hPaintDC, triv, 2, &grc, 1, bVertical ? GRADIENT_FILL_RECT_V : GRADIENT_FILL_RECT_H); @@ -1233,8 +1185,7 @@ void CRenderEngine::DrawLine(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColo void CRenderEngine::DrawRect(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor, int nStyle) { ASSERT(::GetObjectType(hDC) == OBJ_DC || ::GetObjectType(hDC) == OBJ_MEMDC); - HPEN hPen = ::CreatePen( - nStyle | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor))); + HPEN hPen = ::CreatePen(nStyle | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor))); HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen); ::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH)); ::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); @@ -1242,12 +1193,10 @@ void CRenderEngine::DrawRect(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColo ::DeleteObject(hPen); } -void CRenderEngine::DrawRoundRect( - HDC hDC, const RECT& rc, int nSize, int width, int height, DWORD dwPenColor, int nStyle) +void CRenderEngine::DrawRoundRect(HDC hDC, const RECT& rc, int nSize, int width, int height, DWORD dwPenColor, int nStyle) { ASSERT(::GetObjectType(hDC) == OBJ_DC || ::GetObjectType(hDC) == OBJ_MEMDC); - HPEN hPen = ::CreatePen( - nStyle | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor))); + HPEN hPen = ::CreatePen(nStyle | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor))); HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen); ::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH)); ::RoundRect(hDC, rc.left, rc.top, rc.right, rc.bottom, width, height); @@ -1255,8 +1204,7 @@ void CRenderEngine::DrawRoundRect( ::DeleteObject(hPen); } -void CRenderEngine::DrawText( - HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPSTRING pstrText, DWORD dwTextColor, int iFont, UINT uStyle) +void CRenderEngine::DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPSTRING pstrText, DWORD dwTextColor, int iFont, UINT uStyle) { ASSERT(::GetObjectType(hDC) == OBJ_DC || ::GetObjectType(hDC) == OBJ_MEMDC); if (pstrText == NULL || pManager == NULL) @@ -1334,8 +1282,7 @@ void CRenderEngine::DrawHtmlText( // If the drawstyle include a alignment, we'll need to first determine the text-size so // we can draw it at the correct position... - if (((uStyle & DT_CENTER) != 0 || (uStyle & DT_RIGHT) != 0 || (uStyle & DT_VCENTER) != 0 - || (uStyle & DT_BOTTOM) != 0) + if (((uStyle & DT_CENTER) != 0 || (uStyle & DT_RIGHT) != 0 || (uStyle & DT_VCENTER) != 0 || (uStyle & DT_BOTTOM) != 0) && (uStyle & DT_CALCRECT) == 0) { RECT rcText = {0, 0, 9999, 100}; if ((uStyle & DT_SINGLELINE) == 0) { @@ -1409,8 +1356,7 @@ void CRenderEngine::DrawHtmlText( bLineEnd = false; if (!bLineDraw) { if (bInLink && iLinkIndex < nLinkRects) { - ::SetRect( - &prcLinks[iLinkIndex++], ptLinkStart.x, ptLinkStart.y, MIN(pt.x, rc.right), pt.y + cyLine); + ::SetRect(&prcLinks[iLinkIndex++], ptLinkStart.x, ptLinkStart.y, MIN(pt.x, rc.right), pt.y + cyLine); CDuiString* pStr1 = (CDuiString*)(sLinks + iLinkIndex - 1); CDuiString* pStr2 = (CDuiString*)(sLinks + iLinkIndex); *pStr2 = *pStr1; @@ -1450,8 +1396,7 @@ void CRenderEngine::DrawHtmlText( if (pt.x >= rc.right) break; } else if ( - !bInRaw && (*pstrText == _T('<') || *pstrText == _T('{')) - && (pstrText[1] >= _T('a') && pstrText[1] <= _T('z')) + !bInRaw && (*pstrText == _T('<') || *pstrText == _T('{')) && (pstrText[1] >= _T('a') && pstrText[1] <= _T('z')) && (pstrText[2] == _T(' ') || pstrText[2] == _T('>') || pstrText[2] == _T('}'))) { pstrText++; LPSTRING pstrNextStart = NULL; @@ -1488,21 +1433,16 @@ void CRenderEngine::DrawHtmlText( if (aFontArray.GetSize() > 0) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1); if (pFontInfo->bUnderline == false) { - HFONT hFont = pManager->GetFont( - pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic); + HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic); if (hFont == NULL) { - hFont = pManager->AddFont( - g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, - pFontInfo->bItalic); + hFont = pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic); g_iFontID += 1; } pFontInfo = pManager->GetFontInfo(hFont); aFontArray.Add(pFontInfo); pTm = &pFontInfo->tm; ::SelectObject(hDC, pFontInfo->hFont); - cyLine = - MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading - + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); + cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); } ptLinkStart = pt; bInLink = true; @@ -1514,21 +1454,16 @@ void CRenderEngine::DrawHtmlText( if (aFontArray.GetSize() > 0) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1); if (pFontInfo->bBold == false) { - HFONT hFont = pManager->GetFont( - pFontInfo->sFontName, pFontInfo->iSize, true, pFontInfo->bUnderline, pFontInfo->bItalic); + HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, true, pFontInfo->bUnderline, pFontInfo->bItalic); if (hFont == NULL) { - hFont = pManager->AddFont( - g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, true, pFontInfo->bUnderline, - pFontInfo->bItalic); + hFont = pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, true, pFontInfo->bUnderline, pFontInfo->bItalic); g_iFontID += 1; } pFontInfo = pManager->GetFontInfo(hFont); aFontArray.Add(pFontInfo); pTm = &pFontInfo->tm; ::SelectObject(hDC, pFontInfo->hFont); - cyLine = - MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading - + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); + cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); } } break; case _T('c'): // Color @@ -1562,8 +1497,7 @@ void CRenderEngine::DrawHtmlText( bool bBold = false; bool bUnderline = false; bool bItalic = false; - while (*pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') - && *pstrText != _T(' ')) { + while (*pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}') && *pstrText != _T(' ')) { pstrTemp = ::CharNext(pstrText); while (pstrText < pstrTemp) { sFontName += *pstrText++; @@ -1599,9 +1533,7 @@ void CRenderEngine::DrawHtmlText( pTm = &pFontInfo->tm; ::SelectObject(hDC, pFontInfo->hFont); } - cyLine = - MAX(cyLine, - pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); + cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); } break; case _T('i'): // Italic or Image { @@ -1626,21 +1558,17 @@ void CRenderEngine::DrawHtmlText( if (aFontArray.GetSize() > 0) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1); if (pFontInfo->bItalic == false) { - HFONT hFont = pManager->GetFont( - pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, pFontInfo->bUnderline, true); + HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, pFontInfo->bUnderline, true); if (hFont == NULL) { - hFont = pManager->AddFont( - g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, - pFontInfo->bUnderline, true); + hFont = + pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, pFontInfo->bUnderline, true); g_iFontID += 1; } pFontInfo = pManager->GetFontInfo(hFont); aFontArray.Add(pFontInfo); pTm = &pFontInfo->tm; ::SelectObject(hDC, pFontInfo->hFont); - cyLine = - MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading - + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); + cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); } } else { while (*pstrText > _T('\0') && *pstrText <= _T(' ')) @@ -1654,8 +1582,7 @@ void CRenderEngine::DrawHtmlText( if (iImageListIndex < 0 || iImageListIndex >= iImageListNum) iImageListIndex = 0; - if (_tcsstr(sImageString.GetData(), _T("file=\'")) != NULL - || _tcsstr(sImageString.GetData(), _T("res=\'")) != NULL) { + if (_tcsstr(sImageString.GetData(), _T("file=\'")) != NULL || _tcsstr(sImageString.GetData(), _T("res=\'")) != NULL) { CDuiString sImageResType; CDuiString sImageName; LPSTRING pStrImage = sImageString.GetData(); @@ -1715,9 +1642,7 @@ void CRenderEngine::DrawHtmlText( } else { pstrNextStart = NULL; if (bDraw && bLineDraw) { - CDuiRect rcImage( - pt.x + cxOffset, pt.y + cyLineHeight - iHeight, pt.x + +cxOffset + iWidth, - pt.y + cyLineHeight); + CDuiRect rcImage(pt.x + cxOffset, pt.y + cyLineHeight - iHeight, pt.x + +cxOffset + iWidth, pt.y + cyLineHeight); iVAlign = DT_BOTTOM; if (aVAlignArray.GetSize() > 0) iVAlign = (UINT)aVAlignArray.GetAt(aVAlignArray.GetSize() - 1); @@ -1737,9 +1662,7 @@ void CRenderEngine::DrawHtmlText( rcBmpPart.left = iWidth * iImageListIndex; rcBmpPart.right = iWidth * (iImageListIndex + 1); CDuiRect rcCorner(0, 0, 0, 0); - DrawImage( - hDC, pImageInfo->hBitmap, rcImage, rcImage, rcBmpPart, rcCorner, pImageInfo->bAlpha, - 255); + DrawImage(hDC, pImageInfo->hBitmap, rcImage, rcImage, rcBmpPart, rcCorner, pImageInfo->bAlpha, 255); } cyLine = MAX(iHeight, cyLine); @@ -1813,21 +1736,16 @@ void CRenderEngine::DrawHtmlText( if (aFontArray.GetSize() > 0) pFontInfo = (TFontInfo*)aFontArray.GetAt(aFontArray.GetSize() - 1); if (pFontInfo->bUnderline == false) { - HFONT hFont = pManager->GetFont( - pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic); + HFONT hFont = pManager->GetFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic); if (hFont == NULL) { - hFont = pManager->AddFont( - g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, - pFontInfo->bItalic); + hFont = pManager->AddFont(g_iFontID, pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold, true, pFontInfo->bItalic); g_iFontID += 1; } pFontInfo = pManager->GetFontInfo(hFont); aFontArray.Add(pFontInfo); pTm = &pFontInfo->tm; ::SelectObject(hDC, pFontInfo->hFont); - cyLine = - MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading - + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); + cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); } } break; case _T('x'): // X Indent @@ -1870,9 +1788,7 @@ void CRenderEngine::DrawHtmlText( if (pt.x > rc.left) bLineEnd = true; aPIndentArray.Remove(aPIndentArray.GetSize() - 1); - cyLine = - MAX(cyLine, - pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); + cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); break; case _T('v'): pstrText++; @@ -1892,8 +1808,7 @@ void CRenderEngine::DrawHtmlText( if (iLinkIndex < nLinkRects) { if (!bLineDraw) ::SetRect( - &prcLinks[iLinkIndex], ptLinkStart.x, ptLinkStart.y, MIN(pt.x, rc.right), - pt.y + pTm->tmHeight + pTm->tmExternalLeading); + &prcLinks[iLinkIndex], ptLinkStart.x, ptLinkStart.y, MIN(pt.x, rc.right), pt.y + pTm->tmHeight + pTm->tmExternalLeading); iLinkIndex++; } aColorArray.Remove(aColorArray.GetSize() - 1); @@ -1920,17 +1835,13 @@ void CRenderEngine::DrawHtmlText( } pTm = &pFontInfo->tm; ::SelectObject(hDC, pFontInfo->hFont); - cyLine = - MAX(cyLine, - pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); + cyLine = MAX(cyLine, pTm->tmHeight + pTm->tmExternalLeading + (int)aPIndentArray.GetAt(aPIndentArray.GetSize() - 1)); } break; } while (*pstrText != _T('\0') && *pstrText != _T('>') && *pstrText != _T('}')) pstrText = ::CharNext(pstrText); pstrText = ::CharNext(pstrText); - } else if ( - !bInRaw && *pstrText == _T('<') && pstrText[2] == _T('>') - && (pstrText[1] == _T('{') || pstrText[1] == _T('}'))) { + } else if (!bInRaw && *pstrText == _T('<') && pstrText[2] == _T('>') && (pstrText[1] == _T('{') || pstrText[1] == _T('}'))) { SIZE szSpace = {0}; ::GetTextExtentPoint32(hDC, &pstrText[1], 1, &szSpace); if (bDraw && bLineDraw) { @@ -1938,15 +1849,11 @@ void CRenderEngine::DrawHtmlText( if (aVAlignArray.GetSize() > 0) iVAlign = (UINT)aVAlignArray.GetAt(aVAlignArray.GetSize() - 1); if (iVAlign == DT_VCENTER) - ::TextOut( - hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, - &pstrText[1], 1); + ::TextOut(hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, &pstrText[1], 1); else if (iVAlign == DT_TOP) ::TextOut(hDC, pt.x + cxOffset, pt.y, &pstrText[1], 1); else - ::TextOut( - hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, - &pstrText[1], 1); + ::TextOut(hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, &pstrText[1], 1); } pt.x += szSpace.cx; cxMaxWidth = MAX(cxMaxWidth, pt.x); @@ -1954,9 +1861,7 @@ void CRenderEngine::DrawHtmlText( pstrText++; pstrText++; pstrText++; - } else if ( - !bInRaw && *pstrText == _T('{') && pstrText[2] == _T('}') - && (pstrText[1] == _T('<') || pstrText[1] == _T('>'))) { + } else if (!bInRaw && *pstrText == _T('{') && pstrText[2] == _T('}') && (pstrText[1] == _T('<') || pstrText[1] == _T('>'))) { SIZE szSpace = {0}; ::GetTextExtentPoint32(hDC, &pstrText[1], 1, &szSpace); if (bDraw && bLineDraw) { @@ -1964,15 +1869,11 @@ void CRenderEngine::DrawHtmlText( if (aVAlignArray.GetSize() > 0) iVAlign = (UINT)aVAlignArray.GetAt(aVAlignArray.GetSize() - 1); if (iVAlign == DT_VCENTER) - ::TextOut( - hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, - &pstrText[1], 1); + ::TextOut(hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, &pstrText[1], 1); else if (iVAlign == DT_TOP) ::TextOut(hDC, pt.x + cxOffset, pt.y, &pstrText[1], 1); else - ::TextOut( - hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, - &pstrText[1], 1); + ::TextOut(hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, &pstrText[1], 1); } pt.x += szSpace.cx; cxMaxWidth = MAX(cxMaxWidth, pt.x); @@ -1990,14 +1891,11 @@ void CRenderEngine::DrawHtmlText( if (aVAlignArray.GetSize() > 0) iVAlign = (UINT)aVAlignArray.GetAt(aVAlignArray.GetSize() - 1); if (iVAlign == DT_VCENTER) - ::TextOut( - hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, - _T(" "), 1); + ::TextOut(hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, _T(" "), 1); else if (iVAlign == DT_TOP) ::TextOut(hDC, pt.x + cxOffset, pt.y, _T(" "), 1); else - ::TextOut( - hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, _T(" "), 1); + ::TextOut(hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, _T(" "), 1); } pt.x += szSpace.cx; cxMaxWidth = MAX(cxMaxWidth, pt.x); @@ -2019,8 +1917,7 @@ void CRenderEngine::DrawHtmlText( // slow when repeated so often. // TODO: Rewrite and use GetTextExtentExPoint() instead! if (bInRaw) { - if ((*p == _T('<') || *p == _T('{')) && p[1] == _T('/') && p[2] == _T('r') - && (p[3] == _T('>') || p[3] == _T('}'))) { + if ((*p == _T('<') || *p == _T('{')) && p[1] == _T('/') && p[2] == _T('r') && (p[3] == _T('>') || p[3] == _T('}'))) { p += 4; bInRaw = false; break; @@ -2078,27 +1975,19 @@ void CRenderEngine::DrawHtmlText( if (aVAlignArray.GetSize() > 0) iVAlign = (UINT)aVAlignArray.GetAt(aVAlignArray.GetSize() - 1); if (iVAlign == DT_VCENTER) - ::TextOut( - hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, - pstrText, cchSize); + ::TextOut(hDC, pt.x + cxOffset, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, pstrText, cchSize); else if (iVAlign == DT_TOP) ::TextOut(hDC, pt.x + cxOffset, pt.y, pstrText, cchSize); else - ::TextOut( - hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, pstrText, - cchSize); + ::TextOut(hDC, pt.x + cxOffset, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, pstrText, cchSize); if (pt.x >= rc.right && (uStyle & DT_END_ELLIPSIS) != 0) { if (iVAlign == DT_VCENTER) - ::TextOut( - hDC, pt.x + cxOffset + szText.cx, - pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, _T("..."), 3); + ::TextOut(hDC, pt.x + cxOffset + szText.cx, pt.y + (cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading) / 2, _T("..."), 3); else if (iVAlign == DT_TOP) ::TextOut(hDC, pt.x + cxOffset + szText.cx, pt.y, _T("..."), 3); else - ::TextOut( - hDC, pt.x + cxOffset + szText.cx, - pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, _T("..."), 3); + ::TextOut(hDC, pt.x + cxOffset + szText.cx, pt.y + cyLineHeight - pTm->tmHeight - pTm->tmExternalLeading, _T("..."), 3); } } pt.x += szText.cx; @@ -2114,14 +2003,11 @@ void CRenderEngine::DrawHtmlText( aFontArray.Resize(aLineFontArray.GetSize()); ::CopyMemory(aFontArray.GetData(), aLineFontArray.GetData(), aLineFontArray.GetSize() * sizeof(LPVOID)); aColorArray.Resize(aLineColorArray.GetSize()); - ::CopyMemory( - aColorArray.GetData(), aLineColorArray.GetData(), aLineColorArray.GetSize() * sizeof(LPVOID)); + ::CopyMemory(aColorArray.GetData(), aLineColorArray.GetData(), aLineColorArray.GetSize() * sizeof(LPVOID)); aPIndentArray.Resize(aLinePIndentArray.GetSize()); - ::CopyMemory( - aPIndentArray.GetData(), aLinePIndentArray.GetData(), aLinePIndentArray.GetSize() * sizeof(LPVOID)); + ::CopyMemory(aPIndentArray.GetData(), aLinePIndentArray.GetData(), aLinePIndentArray.GetSize() * sizeof(LPVOID)); aVAlignArray.Resize(aLineVAlignArray.GetSize()); - ::CopyMemory( - aVAlignArray.GetData(), aLineVAlignArray.GetData(), aLineVAlignArray.GetSize() * sizeof(LPVOID)); + ::CopyMemory(aVAlignArray.GetData(), aLineVAlignArray.GetData(), aLineVAlignArray.GetSize() * sizeof(LPVOID)); cxLineWidth = cxLine; cyLineHeight = cyLine; @@ -2146,11 +2032,9 @@ void CRenderEngine::DrawHtmlText( aLineColorArray.Resize(aColorArray.GetSize()); ::CopyMemory(aLineColorArray.GetData(), aColorArray.GetData(), aColorArray.GetSize() * sizeof(LPVOID)); aLinePIndentArray.Resize(aPIndentArray.GetSize()); - ::CopyMemory( - aLinePIndentArray.GetData(), aPIndentArray.GetData(), aPIndentArray.GetSize() * sizeof(LPVOID)); + ::CopyMemory(aLinePIndentArray.GetData(), aPIndentArray.GetData(), aPIndentArray.GetSize() * sizeof(LPVOID)); aLineVAlignArray.Resize(aVAlignArray.GetSize()); - ::CopyMemory( - aLineVAlignArray.GetData(), aVAlignArray.GetData(), aVAlignArray.GetSize() * sizeof(LPVOID)); + ::CopyMemory(aLineVAlignArray.GetData(), aVAlignArray.GetData(), aVAlignArray.GetSize() * sizeof(LPVOID)); pstrLineBegin = pstrText; bLineInSelected = bInSelected; diff --git a/uibase/uilib/core/uirender.h b/uibase/uilib/core/uirender.h index 946b566fe8a55c8760d8bacdb8f533e8852d3ad8..3c093659f148cbf9e7f27a44aa98f1bbb344dc7d 100644 --- a/uibase/uilib/core/uirender.h +++ b/uibase/uilib/core/uirender.h @@ -46,18 +46,15 @@ public: bool hole = false, bool xtiled = false, bool ytiled = false); - static bool - DrawImage(HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, TDrawInfo& drawInfo); + static bool DrawImage(HDC hDC, CPaintManagerUI* pManager, const RECT& rcItem, const RECT& rcPaint, TDrawInfo& drawInfo); static void DrawColor(HDC hDC, const RECT& rc, DWORD color); static void DrawGradient(HDC hDC, const RECT& rc, DWORD dwFirst, DWORD dwSecond, bool bVertical, int nSteps); // 以下函数中的颜色参数alpha值无效 static void DrawLine(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor, int nStyle = PS_SOLID); static void DrawRect(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor, int nStyle = PS_SOLID); - static void DrawRoundRect( - HDC hDC, const RECT& rc, int width, int height, int nSize, DWORD dwPenColor, int nStyle = PS_SOLID); - static void DrawText( - HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPSTRING pstrText, DWORD dwTextColor, int iFont, UINT uStyle); + static void DrawRoundRect(HDC hDC, const RECT& rc, int width, int height, int nSize, DWORD dwPenColor, int nStyle = PS_SOLID); + static void DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPSTRING pstrText, DWORD dwTextColor, int iFont, UINT uStyle); static void DrawHtmlText( HDC hDC, CPaintManagerUI* pManager, @@ -69,8 +66,7 @@ public: int& nLinkRects, int iDefaultFont, UINT uStyle); - static HBITMAP - GenerateBitmap(CPaintManagerUI* pManager, RECT rc, CControlUI* pStopControl = NULL, DWORD dwFilterColor = 0); + static HBITMAP GenerateBitmap(CPaintManagerUI* pManager, RECT rc, CControlUI* pStopControl = NULL, DWORD dwFilterColor = 0); static HBITMAP GenerateBitmap(CPaintManagerUI* pManager, CControlUI* pControl, RECT rc, DWORD dwFilterColor = 0); static SIZE GetTextSize(HDC hDC, CPaintManagerUI* pManager, LPSTRING pstrText, int iFont, UINT uStyle); }; diff --git a/uibase/uilib/dpi.hpp b/uibase/uilib/dpi.hpp index ab45f08219e90965200e650aea9832a694912ff4..59b6b3f42ec30f464859caf6fd88729f52eb09c0 100644 --- a/uibase/uilib/dpi.hpp +++ b/uibase/uilib/dpi.hpp @@ -14,12 +14,7 @@ typedef enum _PROCESS_DPI_AWARENESS { PROCESS_PER_MONITOR_DPI_AWARE = 2 } PROCESS_DPI_AWARENESS; -typedef enum _MONITOR_DPI_TYPE { - MDT_EFFECTIVE_DPI = 0, - MDT_ANGULAR_DPI = 1, - MDT_RAW_DPI = 2, - MDT_DEFAULT = MDT_EFFECTIVE_DPI -} Monitor_DPI_Type; +typedef enum _MONITOR_DPI_TYPE { MDT_EFFECTIVE_DPI = 0, MDT_ANGULAR_DPI = 1, MDT_RAW_DPI = 2, MDT_DEFAULT = MDT_EFFECTIVE_DPI } Monitor_DPI_Type; #endif // _SHELLSCALINGAPI_H_ class CDPI @@ -48,8 +43,7 @@ public: } if (hShcoreInstance != NULL) { - fnSetProcessDpiAwareness = - (FNSETPROCESSDPIAWARENESS)::GetProcAddress(hShcoreInstance, "SetProcessDpiAwareness"); + fnSetProcessDpiAwareness = (FNSETPROCESSDPIAWARENESS)::GetProcAddress(hShcoreInstance, "SetProcessDpiAwareness"); fnGetDpiForMonitor = (FNGETDPIFORMONITOR)::GetProcAddress(hShcoreInstance, "GetDpiForMonitor"); } else { fnSetProcessDpiAwareness = NULL; @@ -113,8 +107,8 @@ public: SetScale(LOWORD(wParam)); RECT* const prcNewWindow = (RECT*)lParam; ::SetWindowPos( - hWnd, NULL, prcNewWindow->left, prcNewWindow->top, prcNewWindow->right - prcNewWindow->left, - prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE); + hWnd, NULL, prcNewWindow->left, prcNewWindow->top, prcNewWindow->right - prcNewWindow->left, prcNewWindow->bottom - prcNewWindow->top, + SWP_NOZORDER | SWP_NOACTIVATE); } private: diff --git a/uibase/uilib/dwm.hpp b/uibase/uilib/dwm.hpp index 8ddeee66d98ad14b02a0187a97f38282b72181e9..92a211decfcf82687dde8a0ccad735dbbf2e7790 100644 --- a/uibase/uilib/dwm.hpp +++ b/uibase/uilib/dwm.hpp @@ -86,12 +86,9 @@ public: static HINSTANCE hDwmInstance = ::LoadLibrary(_T("dwmapi.dll")); if (hDwmInstance != NULL) { fnDwmEnableComposition = (FNDWMENABLECOMPOSITION)::GetProcAddress(hDwmInstance, "DwmEnableComposition"); - fnDwmIsCompositionEnabled = - (FNDWNISCOMPOSITIONENABLED)::GetProcAddress(hDwmInstance, "DwmIsCompositionEnabled"); - fnDwmEnableBlurBehindWindow = - (FNENABLEBLURBEHINDWINDOW)::GetProcAddress(hDwmInstance, "DwmEnableBlurBehindWindow"); - fnDwmExtendFrameIntoClientArea = - (FNDWMEXTENDFRAMEINTOCLIENTAREA)::GetProcAddress(hDwmInstance, "DwmExtendFrameIntoClientArea"); + fnDwmIsCompositionEnabled = (FNDWNISCOMPOSITIONENABLED)::GetProcAddress(hDwmInstance, "DwmIsCompositionEnabled"); + fnDwmEnableBlurBehindWindow = (FNENABLEBLURBEHINDWINDOW)::GetProcAddress(hDwmInstance, "DwmEnableBlurBehindWindow"); + fnDwmExtendFrameIntoClientArea = (FNDWMEXTENDFRAMEINTOCLIENTAREA)::GetProcAddress(hDwmInstance, "DwmExtendFrameIntoClientArea"); fnDwmSetWindowAttribute = (FNDWMSETWINDOWATTRIBUTE)::GetProcAddress(hDwmInstance, "DwmSetWindowAttribute"); } else { fnDwmEnableComposition = NULL; diff --git a/uibase/uilib/layout/uichildlayout.cpp b/uibase/uilib/layout/uichildlayout.cpp index 66eca7f43d1b7d2104db3552455c08795992929f..a7505645fedd4eb9a71268068a551b2e43b1e3a7 100644 --- a/uibase/uilib/layout/uichildlayout.cpp +++ b/uibase/uilib/layout/uichildlayout.cpp @@ -11,8 +11,7 @@ void CChildLayoutUI::Init() { if (!m_pstrXMLFile.IsEmpty()) { CDlgBuilder builder; - CContainerUI* pChildWindow = - static_cast(builder.Create(m_pstrXMLFile.GetData(), (UINT)0, NULL, m_pManager)); + CContainerUI* pChildWindow = static_cast(builder.Create(m_pstrXMLFile.GetData(), (UINT)0, NULL, m_pManager)); if (pChildWindow) { this->Add(pChildWindow); } else { diff --git a/uibase/uilib/layout/uihorizontallayout.cpp b/uibase/uilib/layout/uihorizontallayout.cpp index ae007fe27abb5807255c1265871ce2060b45da46..81a4d77308503a38ccde23a97887b6eddf4a06e3 100644 --- a/uibase/uilib/layout/uihorizontallayout.cpp +++ b/uibase/uilib/layout/uihorizontallayout.cpp @@ -189,8 +189,7 @@ void CHorizontalLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) iPosY += m_pVerticalScrollBar->GetScrollRange() / 2; iPosY -= m_pVerticalScrollBar->GetScrollPos(); } - RECT rcCtrl = { - iPosX + rcPadding.left, iPosY - sz.cy / 2, iPosX + sz.cx + rcPadding.left, iPosY + sz.cy - sz.cy / 2}; + RECT rcCtrl = {iPosX + rcPadding.left, iPosY - sz.cy / 2, iPosX + sz.cx + rcPadding.left, iPosY + sz.cy - sz.cy / 2}; pControl->SetPos(rcCtrl, false); } else if (iChildAlign == DT_BOTTOM) { int iPosY = rc.bottom; @@ -198,18 +197,14 @@ void CHorizontalLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) iPosY += m_pVerticalScrollBar->GetScrollRange(); iPosY -= m_pVerticalScrollBar->GetScrollPos(); } - RECT rcCtrl = { - iPosX + rcPadding.left, iPosY - rcPadding.bottom - sz.cy, iPosX + sz.cx + rcPadding.left, - iPosY - rcPadding.bottom}; + RECT rcCtrl = {iPosX + rcPadding.left, iPosY - rcPadding.bottom - sz.cy, iPosX + sz.cx + rcPadding.left, iPosY - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } else { int iPosY = rc.top; if (m_pVerticalScrollBar && m_pVerticalScrollBar->IsVisible()) { iPosY -= m_pVerticalScrollBar->GetScrollPos(); } - RECT rcCtrl = { - iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + sz.cx + rcPadding.left, - iPosY + sz.cy + rcPadding.top}; + RECT rcCtrl = {iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + sz.cx + rcPadding.left, iPosY + sz.cy + rcPadding.top}; pControl->SetPos(rcCtrl, false); } diff --git a/uibase/uilib/layout/uitilelayout.cpp b/uibase/uilib/layout/uitilelayout.cpp index 2c1263917adf1805bcdb574891f822cf47fc2415..e3ebaad1b413f022484c4e8ab17fe1532a774847 100644 --- a/uibase/uilib/layout/uitilelayout.cpp +++ b/uibase/uilib/layout/uitilelayout.cpp @@ -3,8 +3,7 @@ namespace uilib { -CTileLayoutUI::CTileLayoutUI() : - m_nColumns(1), m_nRows(0), m_nColumnsFixed(0), m_iChildVPadding(0), m_bIgnoreItemPadding(true) +CTileLayoutUI::CTileLayoutUI() : m_nColumns(1), m_nRows(0), m_nColumnsFixed(0), m_iChildVPadding(0), m_bIgnoreItemPadding(true) { m_szItem.cx = m_szItem.cy = 80; } @@ -152,8 +151,7 @@ void CTileLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) m_nColumns = m_nColumnsFixed; if (m_nColumns > 1) { if (iChildPadding <= 0) { - if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() - && rc.right - rc.left >= m_nColumns * m_szItem.cx) { + if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible() && rc.right - rc.left >= m_nColumns * m_szItem.cx) { iChildPadding = (rc.right - rc.left - m_nColumns * m_szItem.cx) / (m_nColumns - 1); } else { iChildPadding = (szAvailable.cx - m_nColumns * m_szItem.cx) / (m_nColumns - 1); @@ -209,16 +207,13 @@ void CTileLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) if (iChildAlign == DT_CENTER) { if (iChildVAlign == DT_VCENTER) { RECT rcCtrl = { - iPosX + (m_szItem.cx - sz.cx) / 2 + rcPadding.left, - iPosY + (m_szItem.cy - sz.cy) / 2 + rcPadding.top, - iPosX + (m_szItem.cx - sz.cx) / 2 + sz.cx - rcPadding.right, - iPosY + (m_szItem.cy - sz.cy) / 2 + sz.cy - rcPadding.bottom}; + iPosX + (m_szItem.cx - sz.cx) / 2 + rcPadding.left, iPosY + (m_szItem.cy - sz.cy) / 2 + rcPadding.top, + iPosX + (m_szItem.cx - sz.cx) / 2 + sz.cx - rcPadding.right, iPosY + (m_szItem.cy - sz.cy) / 2 + sz.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } else if (iChildVAlign == DT_BOTTOM) { RECT rcCtrl = { iPosX + (m_szItem.cx - sz.cx) / 2 + rcPadding.left, iPosY + m_szItem.cy - sz.cy + rcPadding.top, - iPosX + (m_szItem.cx - sz.cx) / 2 + sz.cx - rcPadding.right, - iPosY + m_szItem.cy - rcPadding.bottom}; + iPosX + (m_szItem.cx - sz.cx) / 2 + sz.cx - rcPadding.right, iPosY + m_szItem.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } else { RECT rcCtrl = { @@ -230,35 +225,32 @@ void CTileLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) if (iChildVAlign == DT_VCENTER) { RECT rcCtrl = { iPosX + m_szItem.cx - sz.cx + rcPadding.left, iPosY + (m_szItem.cy - sz.cy) / 2 + rcPadding.top, - iPosX + m_szItem.cx - rcPadding.right, - iPosY + (m_szItem.cy - sz.cy) / 2 + sz.cy - rcPadding.bottom}; + iPosX + m_szItem.cx - rcPadding.right, iPosY + (m_szItem.cy - sz.cy) / 2 + sz.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } else if (iChildVAlign == DT_BOTTOM) { RECT rcCtrl = { - iPosX + m_szItem.cx - sz.cx + rcPadding.left, iPosY + m_szItem.cy - sz.cy + rcPadding.top, - iPosX + m_szItem.cx - rcPadding.right, iPosY + m_szItem.cy - rcPadding.bottom}; + iPosX + m_szItem.cx - sz.cx + rcPadding.left, iPosY + m_szItem.cy - sz.cy + rcPadding.top, iPosX + m_szItem.cx - rcPadding.right, + iPosY + m_szItem.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } else { RECT rcCtrl = { - iPosX + m_szItem.cx - sz.cx + rcPadding.left, iPosY + rcPadding.top, - iPosX + m_szItem.cx - rcPadding.right, iPosY + sz.cy - rcPadding.bottom}; + iPosX + m_szItem.cx - sz.cx + rcPadding.left, iPosY + rcPadding.top, iPosX + m_szItem.cx - rcPadding.right, + iPosY + sz.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } } else { if (iChildVAlign == DT_VCENTER) { RECT rcCtrl = { - iPosX + rcPadding.left, iPosY + (m_szItem.cy - sz.cy) / 2 + rcPadding.top, - iPosX + sz.cx - rcPadding.right, iPosY + (m_szItem.cy - sz.cy) / 2 + sz.cy - rcPadding.bottom}; + iPosX + rcPadding.left, iPosY + (m_szItem.cy - sz.cy) / 2 + rcPadding.top, iPosX + sz.cx - rcPadding.right, + iPosY + (m_szItem.cy - sz.cy) / 2 + sz.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } else if (iChildVAlign == DT_BOTTOM) { RECT rcCtrl = { - iPosX + rcPadding.left, iPosY + m_szItem.cy - sz.cy + rcPadding.top, - iPosX + sz.cx - rcPadding.right, iPosY + m_szItem.cy - rcPadding.bottom}; + iPosX + rcPadding.left, iPosY + m_szItem.cy - sz.cy + rcPadding.top, iPosX + sz.cx - rcPadding.right, + iPosY + m_szItem.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } else { - RECT rcCtrl = { - iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + sz.cx - rcPadding.right, - iPosY + sz.cy - rcPadding.bottom}; + RECT rcCtrl = {iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + sz.cx - rcPadding.right, iPosY + sz.cy - rcPadding.bottom}; pControl->SetPos(rcCtrl, false); } } diff --git a/uibase/uilib/layout/uiverticallayout.cpp b/uibase/uilib/layout/uiverticallayout.cpp index 797496b6b5d44d56b5de3a8540b8f5d8d61a1094..63e207f5d32ac79e7ec41e3e8c04b09042382567 100644 --- a/uibase/uilib/layout/uiverticallayout.cpp +++ b/uibase/uilib/layout/uiverticallayout.cpp @@ -183,8 +183,7 @@ void CVerticalLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) iPosX += m_pHorizontalScrollBar->GetScrollRange() / 2; iPosX -= m_pHorizontalScrollBar->GetScrollPos(); } - RECT rcCtrl = { - iPosX - sz.cx / 2, iPosY + rcPadding.top, iPosX + sz.cx - sz.cx / 2, iPosY + sz.cy + rcPadding.top}; + RECT rcCtrl = {iPosX - sz.cx / 2, iPosY + rcPadding.top, iPosX + sz.cx - sz.cx / 2, iPosY + sz.cy + rcPadding.top}; pControl->SetPos(rcCtrl, false); } else if (iChildAlign == DT_RIGHT) { int iPosX = rc.right; @@ -192,18 +191,14 @@ void CVerticalLayoutUI::SetPos(RECT rc, bool bNeedInvalidate) iPosX += m_pHorizontalScrollBar->GetScrollRange(); iPosX -= m_pHorizontalScrollBar->GetScrollPos(); } - RECT rcCtrl = { - iPosX - rcPadding.right - sz.cx, iPosY + rcPadding.top, iPosX - rcPadding.right, - iPosY + sz.cy + rcPadding.top}; + RECT rcCtrl = {iPosX - rcPadding.right - sz.cx, iPosY + rcPadding.top, iPosX - rcPadding.right, iPosY + sz.cy + rcPadding.top}; pControl->SetPos(rcCtrl, false); } else { int iPosX = rc.left; if (m_pHorizontalScrollBar && m_pHorizontalScrollBar->IsVisible()) { iPosX -= m_pHorizontalScrollBar->GetScrollPos(); } - RECT rcCtrl = { - iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + rcPadding.left + sz.cx, - iPosY + sz.cy + rcPadding.top}; + RECT rcCtrl = {iPosX + rcPadding.left, iPosY + rcPadding.top, iPosX + rcPadding.left + sz.cx, iPosY + sz.cy + rcPadding.top}; pControl->SetPos(rcCtrl, false); } @@ -355,20 +350,14 @@ RECT CVerticalLayoutUI::GetThumbRect(bool bUseNew) const { if ((m_uButtonState & UISTATE_CAPTURED) != 0 && bUseNew) { if (m_iSepHeight >= 0) - return CDuiRect( - m_rcNewPos.left, MAX(m_rcNewPos.bottom - m_iSepHeight, m_rcNewPos.top), m_rcNewPos.right, - m_rcNewPos.bottom); + return CDuiRect(m_rcNewPos.left, MAX(m_rcNewPos.bottom - m_iSepHeight, m_rcNewPos.top), m_rcNewPos.right, m_rcNewPos.bottom); else - return CDuiRect( - m_rcNewPos.left, m_rcNewPos.top, m_rcNewPos.right, - MIN(m_rcNewPos.top - m_iSepHeight, m_rcNewPos.bottom)); + return CDuiRect(m_rcNewPos.left, m_rcNewPos.top, m_rcNewPos.right, MIN(m_rcNewPos.top - m_iSepHeight, m_rcNewPos.bottom)); } else { if (m_iSepHeight >= 0) - return CDuiRect( - m_rcItem.left, MAX(m_rcItem.bottom - m_iSepHeight, m_rcItem.top), m_rcItem.right, m_rcItem.bottom); + return CDuiRect(m_rcItem.left, MAX(m_rcItem.bottom - m_iSepHeight, m_rcItem.top), m_rcItem.right, m_rcItem.bottom); else - return CDuiRect( - m_rcItem.left, m_rcItem.top, m_rcItem.right, MIN(m_rcItem.top - m_iSepHeight, m_rcItem.bottom)); + return CDuiRect(m_rcItem.left, m_rcItem.top, m_rcItem.right, MIN(m_rcItem.top - m_iSepHeight, m_rcItem.bottom)); } } } // namespace uilib diff --git a/uibase/uilib/uilib.h b/uibase/uilib/uilib.h index 7b4fd3fe9ab88ce1ab9c96fea592aaf43eb78b35..d74348e131885606110c9a29c3f4c0bfd816498c 100644 --- a/uibase/uilib/uilib.h +++ b/uibase/uilib/uilib.h @@ -3,19 +3,19 @@ #define UILIB_STATIC 1 -//#if defined _M_IX86 -//# pragma comment(linker, "/manifestdependency:\"type='win32' -// name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' -// publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_IA64 # pragma -// comment(linker, "/manifestdependency:\"type='win32' -// name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' -// publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_X64 # pragma -// comment(linker, "/manifestdependency:\"type='win32' -// name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' -// publicKeyToken='6595b64144ccf1df' language='*'\"") #else # pragma comment(linker, +// #if defined _M_IX86 +// # pragma comment(linker, "/manifestdependency:\"type='win32' +// name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' +// publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_IA64 # pragma +// comment(linker, "/manifestdependency:\"type='win32' +// name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' +// publicKeyToken='6595b64144ccf1df' language='*'\"") #elif defined _M_X64 # pragma +// comment(linker, "/manifestdependency:\"type='win32' +// name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' +// publicKeyToken='6595b64144ccf1df' language='*'\"") #else # pragma comment(linker, //"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' -// version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' -// language='*'\"") #endif +// version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' +// language='*'\"") #endif #include #include diff --git a/uibase/uilib/utils/stb_image.c b/uibase/uilib/utils/stb_image.c index 6cbdb2d4eb1b16f881498c5fdfe120100644af54..55b279cba112b04f0b56e902700d10a4d95ad485 100644 --- a/uibase/uilib/utils/stb_image.c +++ b/uibase/uilib/utils/stb_image.c @@ -421,18 +421,15 @@ extern "C" { // typedef struct { - int (*read)( - void* user, - char* data, - int size); // fill 'data' with 'size' bytes. return number of bytes actually read + int (*read)(void* user, char* data, + int size); // fill 'data' with 'size' bytes. return number of bytes actually read void (*skip)(void* user, int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative int (*eof)(void* user); // returns nonzero if we are at end of file/data } stbi_io_callbacks; STBIDEF stbi_uc* stbi_load(char const* filename, int* x, int* y, int* comp, int req_comp); STBIDEF stbi_uc* stbi_load_from_memory(stbi_uc const* buffer, int len, int* x, int* y, int* comp, int req_comp); -STBIDEF stbi_uc* - stbi_load_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); +STBIDEF stbi_uc* stbi_load_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); #ifndef STBI_NO_STDIO STBIDEF stbi_uc* stbi_load_from_file(FILE* f, int* x, int* y, int* comp, int req_comp); @@ -442,8 +439,7 @@ STBIDEF stbi_uc* stbi_load_from_file(FILE* f, int* x, int* y, int* comp, int req #ifndef STBI_NO_LINEAR STBIDEF float* stbi_loadf(char const* filename, int* x, int* y, int* comp, int req_comp); STBIDEF float* stbi_loadf_from_memory(stbi_uc const* buffer, int len, int* x, int* y, int* comp, int req_comp); -STBIDEF float* - stbi_loadf_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); +STBIDEF float* stbi_loadf_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); #ifndef STBI_NO_STDIO STBIDEF float* stbi_loadf_from_file(FILE* f, int* x, int* y, int* comp, int req_comp); @@ -500,8 +496,7 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip); // ZLIB client - used by PNG, available for other purposes STBIDEF char* stbi_zlib_decode_malloc_guesssize(const char* buffer, int len, int initial_size, int* outlen); -STBIDEF char* stbi_zlib_decode_malloc_guesssize_headerflag( - const char* buffer, int len, int initial_size, int* outlen, int parse_header); +STBIDEF char* stbi_zlib_decode_malloc_guesssize_headerflag(const char* buffer, int len, int initial_size, int* outlen, int parse_header); STBIDEF char* stbi_zlib_decode_malloc(const char* buffer, int len, int* outlen); STBIDEF int stbi_zlib_decode_buffer(char* obuffer, int olen, const char* ibuffer, int ilen); @@ -519,9 +514,8 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char* obuffer, int olen, const char #ifdef STB_IMAGE_IMPLEMENTATION -#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) || defined(STBI_ONLY_TGA) \ - || defined(STBI_ONLY_GIF) || defined(STBI_ONLY_PSD) || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) \ - || defined(STBI_ONLY_PNM) || defined(STBI_ONLY_ZLIB) +#if defined(STBI_ONLY_JPEG) || defined(STBI_ONLY_PNG) || defined(STBI_ONLY_BMP) || defined(STBI_ONLY_TGA) || defined(STBI_ONLY_GIF) \ + || defined(STBI_ONLY_PSD) || defined(STBI_ONLY_HDR) || defined(STBI_ONLY_PIC) || defined(STBI_ONLY_PNM) || defined(STBI_ONLY_ZLIB) #ifndef STBI_ONLY_JPEG #define STBI_NO_JPEG #endif @@ -636,8 +630,7 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32) == 4 ? 1 : -1]; #define STBI__X86_TARGET #endif -#if defined(__GNUC__) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET)) && !defined(__SSE2__) \ - && !defined(STBI_NO_SIMD) +#if defined(__GNUC__) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET)) && !defined(__SSE2__) && !defined(STBI_NO_SIMD) // NOTE: not clear do we actually need this for the 64-bit path? // gcc doesn't support sse2 intrinsics unless you compile with -msse2, // (but compiling with -msse2 allows the compiler to use SSE2 everywhere; @@ -1057,8 +1050,7 @@ STBIDEF stbi_uc* stbi_load_from_memory(stbi_uc const* buffer, int len, int* x, i return stbi__load_flip(&s, x, y, comp, req_comp); } -STBIDEF stbi_uc* - stbi_load_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp) +STBIDEF stbi_uc* stbi_load_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks*)clbk, user); @@ -1090,8 +1082,7 @@ STBIDEF float* stbi_loadf_from_memory(stbi_uc const* buffer, int len, int* x, in return stbi__loadf_main(&s, x, y, comp, req_comp); } -STBIDEF float* - stbi_loadf_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp) +STBIDEF float* stbi_loadf_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp) { stbi__context s; stbi__start_callbacks(&s, (stbi_io_callbacks*)clbk, user); @@ -1531,8 +1522,7 @@ typedef struct { // kernels void (*idct_block_kernel)(stbi_uc* out, int out_stride, short data[64]); - void (*YCbCr_to_RGB_kernel)( - stbi_uc* out, const stbi_uc* y, const stbi_uc* pcb, const stbi_uc* pcr, int count, int step); + void (*YCbCr_to_RGB_kernel)(stbi_uc* out, const stbi_uc* y, const stbi_uc* pcb, const stbi_uc* pcr, int count, int step); stbi_uc* (*resample_row_hv_2_kernel)(stbi_uc* out, stbi_uc* in_near, stbi_uc* in_far, int w, int hs); } stbi__jpeg; @@ -1624,8 +1614,7 @@ static void stbi__grow_buffer_unsafe(stbi__jpeg* j) } // (1 << n) - 1 -static stbi__uint32 stbi__bmask[17] = {0, 1, 3, 7, 15, 31, 63, 127, 255, - 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535}; +static stbi__uint32 stbi__bmask[17] = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535}; // decode a jpeg huffman value from the bitstream stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg* j, stbi__huffman* h) @@ -1679,8 +1668,7 @@ stbi_inline static int stbi__jpeg_huff_decode(stbi__jpeg* j, stbi__huffman* h) } // bias[n] = (-1<img_comp[n].ha; if (!stbi__jpeg_decode_block( - z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, - z->dequant[z->img_comp[n].tq])) + z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; - z->idct_block_kernel( - z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, z->img_comp[n].w2, data); + z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, z->img_comp[n].w2, data); // every data block is an MCU, so countdown the restart interval if (--z->todo <= 0) { if (z->code_bits < 24) @@ -2586,11 +2570,9 @@ static int stbi__parse_entropy_coded_data(stbi__jpeg* z) int y2 = (j * z->img_comp[n].v + y) * 8; int ha = z->img_comp[n].ha; if (!stbi__jpeg_decode_block( - z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, - z->dequant[z->img_comp[n].tq])) + z, data, z->huff_dc + z->img_comp[n].hd, z->huff_ac + ha, z->fast_ac[ha], n, z->dequant[z->img_comp[n].tq])) return 0; - z->idct_block_kernel( - z->img_comp[n].data + z->img_comp[n].w2 * y2 + x2, z->img_comp[n].w2, data); + z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * y2 + x2, z->img_comp[n].w2, data); } } } @@ -2693,8 +2675,7 @@ static void stbi__jpeg_finish(stbi__jpeg* z) for (i = 0; i < w; ++i) { short* data = z->img_comp[n].coeff + 64 * (i + j * z->img_comp[n].coeff_w); stbi__jpeg_dequantize(data, z->dequant[z->img_comp[n].tq]); - z->idct_block_kernel( - z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, z->img_comp[n].w2, data); + z->idct_block_kernel(z->img_comp[n].data + z->img_comp[n].w2 * j * 8 + i * 8, z->img_comp[n].w2, data); } } } @@ -2805,8 +2786,7 @@ static int stbi__process_scan_header(stbi__jpeg* z) z->succ_high = (aa >> 4); z->succ_low = (aa & 15); if (z->progressive) { - if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 - || z->succ_low > 13) + if (z->spec_start > 63 || z->spec_end > 63 || z->spec_start > z->spec_end || z->succ_high > 13 || z->succ_low > 13) return stbi__err("bad SOS", "Corrupt JPEG"); } else { if (z->spec_start != 0) @@ -2914,8 +2894,7 @@ static int stbi__process_frame_header(stbi__jpeg* z, int scan) if (z->progressive) { z->img_comp[i].coeff_w = (z->img_comp[i].w2 + 7) >> 3; z->img_comp[i].coeff_h = (z->img_comp[i].h2 + 7) >> 3; - z->img_comp[i].raw_coeff = - STBI_MALLOC(z->img_comp[i].coeff_w * z->img_comp[i].coeff_h * 64 * sizeof(short) + 15); + z->img_comp[i].raw_coeff = STBI_MALLOC(z->img_comp[i].coeff_w * z->img_comp[i].coeff_h * 64 * sizeof(short) + 15); z->img_comp[i].coeff = (short*)(((size_t)z->img_comp[i].raw_coeff + 15) & ~15); } else { z->img_comp[i].coeff = 0; @@ -3216,8 +3195,7 @@ static stbi_uc* stbi__resample_row_generic(stbi_uc* out, stbi_uc* in_near, stbi_ // this is the same YCbCr-to-RGB calculation that stb_image has used // historically before the algorithm changes in 1.49 #define float2fixed(x) ((int)((x)*65536 + 0.5)) -static void - stbi__YCbCr_to_RGB_row(stbi_uc* out, const stbi_uc* y, const stbi_uc* pcb, const stbi_uc* pcr, int count, int step) +static void stbi__YCbCr_to_RGB_row(stbi_uc* out, const stbi_uc* y, const stbi_uc* pcb, const stbi_uc* pcr, int count, int step) { int i; for (i = 0; i < count; ++i) { @@ -3260,8 +3238,7 @@ static void // this is a reduced-precision calculation of YCbCr-to-RGB introduced // to make sure the code produces the same results in both SIMD and scalar #define float2fixed(x) (((int)((x)*4096.0f + 0.5f)) << 8) -static void - stbi__YCbCr_to_RGB_row(stbi_uc* out, const stbi_uc* y, const stbi_uc* pcb, const stbi_uc* pcr, int count, int step) +static void stbi__YCbCr_to_RGB_row(stbi_uc* out, const stbi_uc* y, const stbi_uc* pcb, const stbi_uc* pcr, int count, int step) { int i; for (i = 0; i < count; ++i) { @@ -3303,8 +3280,7 @@ static void #endif #if defined(STBI_SSE2) || defined(STBI_NEON) -static void - stbi__YCbCr_to_RGB_simd(stbi_uc* out, stbi_uc const* y, stbi_uc const* pcb, stbi_uc const* pcr, int count, int step) +static void stbi__YCbCr_to_RGB_simd(stbi_uc* out, stbi_uc const* y, stbi_uc const* pcb, stbi_uc const* pcr, int count, int step) { int i = 0; @@ -3585,9 +3561,7 @@ static stbi_uc* load_jpeg_image(stbi__jpeg* z, int* out_x, int* out_y, int* comp for (k = 0; k < decode_n; ++k) { stbi__resample* r = &res_comp[k]; int y_bot = r->ystep >= (r->vs >> 1); - coutput[k] = r->resample( - z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0, y_bot ? r->line0 : r->line1, r->w_lores, - r->hs); + coutput[k] = r->resample(z->img_comp[k].linebuf, y_bot ? r->line1 : r->line0, y_bot ? r->line0 : r->line1, r->w_lores, r->hs); if (++r->ystep >= r->vs) { r->ystep = 0; r->line0 = r->line1; @@ -3858,15 +3832,12 @@ static int stbi__zexpand(stbi__zbuf* z, char* zout, int n) // need to make room static int stbi__zlength_base[31] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; -static int stbi__zlength_extra[31] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0}; +static int stbi__zlength_extra[31] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0}; -static int stbi__zdist_base[32] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, - 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, - 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0}; +static int stbi__zdist_base[32] = {1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0}; -static int stbi__zdist_extra[32] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, - 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; +static int stbi__zdist_extra[32] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; static int stbi__parse_huffman_block(stbi__zbuf* a) { @@ -4111,8 +4082,7 @@ STBIDEF char* stbi_zlib_decode_malloc(char const* buffer, int len, int* outlen) return stbi_zlib_decode_malloc_guesssize(buffer, len, 16384, outlen); } -STBIDEF char* stbi_zlib_decode_malloc_guesssize_headerflag( - const char* buffer, int len, int initial_size, int* outlen, int parse_header) +STBIDEF char* stbi_zlib_decode_malloc_guesssize_headerflag(const char* buffer, int len, int initial_size, int* outlen, int parse_header) { stbi__zbuf a; char* p = (char*)stbi__malloc(initial_size); @@ -4239,8 +4209,8 @@ static int stbi__paeth(int a, int b, int c) static stbi_uc stbi__depth_scale_table[9] = {0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01}; // create the png data from post-deflated data -static int stbi__create_png_image_raw( - stbi__png* a, stbi_uc* raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color) +static int + stbi__create_png_image_raw(stbi__png* a, stbi_uc* raw, stbi__uint32 raw_len, int out_n, stbi__uint32 x, stbi__uint32 y, int depth, int color) { stbi__context* s = a->s; stbi__uint32 i, j, stride = x * out_n; @@ -4471,8 +4441,7 @@ static int stbi__create_png_image_raw( return 1; } -static int stbi__create_png_image( - stbi__png* a, stbi_uc* image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced) +static int stbi__create_png_image(stbi__png* a, stbi_uc* image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced) { stbi_uc* final; int p; @@ -4750,8 +4719,7 @@ static int stbi__parse_png_file(stbi__png* z, int scan, int req_comp) return stbi__err("bad tRNS len", "Corrupt PNG"); has_trans = 1; for (k = 0; k < s->img_n; ++k) - tc[k] = (stbi_uc)(stbi__get16be(s) & 255) - * stbi__depth_scale_table[depth]; // non 8-bit images will be larger + tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[depth]; // non 8-bit images will be larger } break; } @@ -4795,8 +4763,7 @@ static int stbi__parse_png_file(stbi__png* z, int scan, int req_comp) // initial guess for decoded data size to avoid unnecessary reallocs bpl = (s->img_x * depth + 7) / 8; // bytes per line, per component raw_len = bpl * s->img_y * s->img_n /* pixels */ + s->img_y /* filter mode per row */; - z->expanded = (stbi_uc*)stbi_zlib_decode_malloc_guesssize_headerflag( - (char*)z->idata, ioff, raw_len, (int*)&raw_len, !is_iphone); + z->expanded = (stbi_uc*)stbi_zlib_decode_malloc_guesssize_headerflag((char*)z->idata, ioff, raw_len, (int*)&raw_len, !is_iphone); if (z->expanded == NULL) return 0; // zlib should set error STBI_FREE(z->idata); @@ -5337,8 +5304,7 @@ static stbi_uc* stbi__tga_load(stbi__context* s, int* x, int* y, int* comp, int // error check if ( //(tga_indexed) || (tga_width < 1) || (tga_height < 1) || (tga_image_type < 1) || (tga_image_type > 3) - || ((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16) && (tga_bits_per_pixel != 24) - && (tga_bits_per_pixel != 32))) { + || ((tga_bits_per_pixel != 8) && (tga_bits_per_pixel != 16) && (tga_bits_per_pixel != 24) && (tga_bits_per_pixel != 32))) { return NULL; // we don't report this as a bad TGA because we don't even know if it's TGA } diff --git a/uibase/uilib/utils/stb_image.h b/uibase/uilib/utils/stb_image.h index 385155964d39619b1f6b99cc436cdd3298e4ec64..5ea27b480543f41b619000c6b154fbf698db029c 100644 --- a/uibase/uilib/utils/stb_image.h +++ b/uibase/uilib/utils/stb_image.h @@ -422,10 +422,8 @@ extern "C" { // typedef struct { - int (*read)( - void* user, - char* data, - int size); // fill 'data' with 'size' bytes. return number of bytes actually read + int (*read)(void* user, char* data, + int size); // fill 'data' with 'size' bytes. return number of bytes actually read void (*skip)(void* user, int n); // skip the next 'n' bytes, or 'unget' the last -n bytes if negative int (*eof)(void* user); // returns nonzero if we are at end of file/data @@ -433,8 +431,7 @@ typedef struct { STBIDEF stbi_uc* stbi_load(char const* filename, int* x, int* y, int* comp, int req_comp); STBIDEF stbi_uc* stbi_load_from_memory(stbi_uc const* buffer, int len, int* x, int* y, int* comp, int req_comp); -STBIDEF stbi_uc* - stbi_load_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); +STBIDEF stbi_uc* stbi_load_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); #ifndef STBI_NO_STDIO STBIDEF stbi_uc* stbi_load_from_file(FILE* f, int* x, int* y, int* comp, int req_comp); @@ -444,8 +441,7 @@ STBIDEF stbi_uc* stbi_load_from_file(FILE* f, int* x, int* y, int* comp, int req #ifndef STBI_NO_LINEAR STBIDEF float* stbi_loadf(char const* filename, int* x, int* y, int* comp, int req_comp); STBIDEF float* stbi_loadf_from_memory(stbi_uc const* buffer, int len, int* x, int* y, int* comp, int req_comp); -STBIDEF float* - stbi_loadf_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); +STBIDEF float* stbi_loadf_from_callbacks(stbi_io_callbacks const* clbk, void* user, int* x, int* y, int* comp, int req_comp); #ifndef STBI_NO_STDIO STBIDEF float* stbi_loadf_from_file(FILE* f, int* x, int* y, int* comp, int req_comp); @@ -502,8 +498,7 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip); // ZLIB client - used by PNG, available for other purposes STBIDEF char* stbi_zlib_decode_malloc_guesssize(const char* buffer, int len, int initial_size, int* outlen); -STBIDEF char* stbi_zlib_decode_malloc_guesssize_headerflag( - const char* buffer, int len, int initial_size, int* outlen, int parse_header); +STBIDEF char* stbi_zlib_decode_malloc_guesssize_headerflag(const char* buffer, int len, int initial_size, int* outlen, int parse_header); STBIDEF char* stbi_zlib_decode_malloc(const char* buffer, int len, int* outlen); STBIDEF int stbi_zlib_decode_buffer(char* obuffer, int olen, const char* ibuffer, int ilen); diff --git a/uibase/uilib/utils/utils.cpp b/uibase/uilib/utils/utils.cpp index 58032baef220ff814d4cf79528f53ae558f5a599..742fffbb664549d0c194f427c9b6a9d957270445 100644 --- a/uibase/uilib/utils/utils.cpp +++ b/uibase/uilib/utils/utils.cpp @@ -414,8 +414,7 @@ bool CDuiValArray::Remove(int iIndex, int iCount) return false; if (iIndex + iCount < m_nCount) ::CopyMemory( - m_pVoid + (iIndex * m_iElementSize), m_pVoid + (iIndex + iCount) * m_iElementSize, - (m_nCount - iIndex - iCount) * m_iElementSize); + m_pVoid + (iIndex * m_iElementSize), m_pVoid + (iIndex + iCount) * m_iElementSize, (m_nCount - iIndex - iCount) * m_iElementSize); m_nCount -= iCount; return true; } @@ -949,7 +948,7 @@ LPVOID CDuiStringPtrMap::Find(LPSTRING key, bool optimize) const pItem->pPrev = NULL; pItem->pNext = m_aT[slot]; pItem->pNext->pPrev = pItem; - //将item移动至链条头部 + // 将item移动至链条头部 m_aT[slot] = pItem; } return pItem->Data; diff --git a/uibase/uilib/utils/winimplbase.cpp b/uibase/uilib/utils/winimplbase.cpp index 36eeadcb724135a67bd71062db3afb31ea68fbd3..13400b76a3e6103f3049cd65d0318ddfc9dd21ce 100644 --- a/uibase/uilib/utils/winimplbase.cpp +++ b/uibase/uilib/utils/winimplbase.cpp @@ -155,11 +155,10 @@ LRESULT WindowImplBase::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOO } RECT rcCaption = m_PaintManager.GetCaptionRect(); - if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right && pt.y >= rcCaption.top - && pt.y < rcCaption.bottom) { + if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right && pt.y >= rcCaption.top && pt.y < rcCaption.bottom) { CControlUI* pControl = static_cast(m_PaintManager.FindControl(pt)); - if (pControl && _tcsicmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 - && _tcsicmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 && _tcsicmp(pControl->GetClass(), DUI_CTR_TEXT) != 0) + if (pControl && _tcsicmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 && _tcsicmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 + && _tcsicmp(pControl->GetClass(), DUI_CTR_TEXT) != 0) return HTCAPTION; } @@ -214,8 +213,7 @@ LRESULT WindowImplBase::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bH rcWnd.Offset(-rcWnd.left, -rcWnd.top); rcWnd.right++; rcWnd.bottom++; - HRGN hRgn = - ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy); + HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy); ::SetWindowRgn(*this, hRgn, TRUE); ::DeleteObject(hRgn); } @@ -241,9 +239,8 @@ LRESULT WindowImplBase::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BO BOOL bZoomed = ::IsZoomed(*this); LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam); if (::IsZoomed(*this) != bZoomed) { - CControlUI* pbtnMax = static_cast(m_PaintManager.FindControl(_T("maxbtn"))); // max button - CControlUI* pbtnRestore = - static_cast(m_PaintManager.FindControl(_T("restorebtn"))); // restore button + CControlUI* pbtnMax = static_cast(m_PaintManager.FindControl(_T("maxbtn"))); // max button + CControlUI* pbtnRestore = static_cast(m_PaintManager.FindControl(_T("restorebtn"))); // restore button // toggle status of max and restore button if (pbtnMax && pbtnRestore) { @@ -264,9 +261,7 @@ LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); RECT rcClient; ::GetClientRect(*this, &rcClient); - ::SetWindowPos( - *this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, - SWP_FRAMECHANGED); + ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); m_PaintManager.Init(m_hWnd); m_PaintManager.AddPreMessageFilter(this); diff --git a/uibase/uilib/utils/wndshadow.cpp b/uibase/uilib/utils/wndshadow.cpp index edfd0f5f59ac835bf5a3d78f44f17baba34c77e8..dccb7bbae2948680abf27028ef60b94c9b59ea4e 100644 --- a/uibase/uilib/utils/wndshadow.cpp +++ b/uibase/uilib/utils/wndshadow.cpp @@ -71,8 +71,8 @@ typedef struct HWNDSHADOW { uilib::CDuiValArray CWndShadow::s_ShadowArray(sizeof(HwndShadow), 10); CWndShadow::CWndShadow(void) : - m_hWnd((HWND)INVALID_HANDLE_VALUE), m_OriParentProc(NULL), m_nDarkness(150), m_nSharpness(5), m_nSize(0), - m_nxOffset(5), m_nyOffset(5), m_Color(RGB(0, 0, 0)), m_pImageInfo(NULL), m_WndSize(0), m_bUpdate(false) + m_hWnd((HWND)INVALID_HANDLE_VALUE), m_OriParentProc(NULL), m_nDarkness(150), m_nSharpness(5), m_nSize(0), m_nxOffset(5), m_nyOffset(5), + m_Color(RGB(0, 0, 0)), m_pImageInfo(NULL), m_WndSize(0), m_bUpdate(false) { ::ZeroMemory(&m_rcCorner, sizeof(m_rcCorner)); } @@ -154,8 +154,7 @@ void CWndShadow::Create(HWND hParentWnd) // Create the shadow window m_hWnd = CreateWindowEx( WS_EX_LAYERED | WS_EX_TRANSPARENT, strWndClassName, NULL, - /*WS_VISIBLE | */ /*WS_CAPTION | */ WS_POPUPWINDOW, CW_USEDEFAULT, 0, 0, 0, hParentWnd, NULL, s_hInstance, - NULL); + /*WS_VISIBLE | */ /*WS_CAPTION | */ WS_POPUPWINDOW, CW_USEDEFAULT, 0, 0, 0, hParentWnd, NULL, s_hInstance, NULL); // Determine the initial show state of shadow according to parent window's state LONG lParentStyle = GetWindowLong(hParentWnd, GWL_STYLE); @@ -198,13 +197,13 @@ LRESULT CALLBACK CWndShadow::ParentProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA GetWindowRect(hwnd, &WndRect); if (pThis->m_pImageInfo) { SetWindowPos( - pThis->m_hWnd, NULL, WndRect.left - pThis->m_rcCorner.left, WndRect.top - pThis->m_rcCorner.top, 0, - 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER); + pThis->m_hWnd, NULL, WndRect.left - pThis->m_rcCorner.left, WndRect.top - pThis->m_rcCorner.top, 0, 0, + SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER); } else { SetWindowPos( - pThis->m_hWnd, NULL, WndRect.left + pThis->m_nxOffset - pThis->m_nSize, - WndRect.top + pThis->m_nyOffset - pThis->m_nSize, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER); + pThis->m_hWnd, NULL, WndRect.left + pThis->m_nxOffset - pThis->m_nSize, WndRect.top + pThis->m_nyOffset - pThis->m_nSize, 0, 0, + SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER); } } break; @@ -338,8 +337,8 @@ void CWndShadow::Update(HWND hParent) RECT rc = {0, 0, nShadWndWid, nShadWndHei}; RECT rcBmpPart = {0, 0, m_pImageInfo->nX, m_pImageInfo->nY}; RECT rcCorner = { - m_rcCorner.left + m_rcHoleOffset.left, m_rcCorner.top + m_rcHoleOffset.top, - m_rcCorner.right + m_rcHoleOffset.right, m_rcCorner.bottom + m_rcHoleOffset.bottom}; + m_rcCorner.left + m_rcHoleOffset.left, m_rcCorner.top + m_rcHoleOffset.top, m_rcCorner.right + m_rcHoleOffset.right, + m_rcCorner.bottom + m_rcHoleOffset.bottom}; CRenderEngine::DrawImage(hMemDC, m_pImageInfo->hBitmap, rc, rc, rcBmpPart, rcCorner, true, 255, true); } else { MakeShadow((UINT32*)pvBits, hParent, &WndRect); @@ -357,8 +356,7 @@ void CWndShadow::Update(HWND hParent) MoveWindow(m_hWnd, ptDst.x, ptDst.y, nShadWndWid, nShadWndHei, FALSE); - BOOL bRet = - s_UpdateLayeredWindow(m_hWnd, NULL, &ptDst, &WndSize, hMemDC, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA); + BOOL bRet = s_UpdateLayeredWindow(m_hWnd, NULL, &ptDst, &WndSize, hMemDC, &ptSrc, 0, &blendPixelFunction, ULW_ALPHA); _ASSERT(bRet); // something was wrong.... @@ -468,8 +466,7 @@ void CWndShadow::MakeShadow(UINT32* pShadBits, HWND hParent, RECT* rcParent) UINT32* pKernelIter = pKernel; for (int i = 0; i <= 2 * nKernelSize; i++) { for (int j = 0; j <= 2 * nKernelSize; j++) { - double dLength = - sqrt((i - nKernelSize) * (i - nKernelSize) + (j - nKernelSize) * (double)(j - nKernelSize)); + double dLength = sqrt((i - nKernelSize) * (i - nKernelSize) + (j - nKernelSize) * (double)(j - nKernelSize)); if (dLength < nCenterSize) *pKernelIter = m_nDarkness << 24 | PreMultiply(m_Color, m_nDarkness); else if (dLength <= nKernelSize) { @@ -487,11 +484,9 @@ void CWndShadow::MakeShadow(UINT32* pShadBits, HWND hParent, RECT* rcParent) int j; if (ptAnchors[i][0] < ptAnchors[i][1]) { // Start of line - for (j = ptAnchors[i][0]; j < min(max(ptAnchors[i - 1][0], ptAnchors[i + 1][0]) + 1, ptAnchors[i][1]); - j++) { + for (j = ptAnchors[i][0]; j < min(max(ptAnchors[i - 1][0], ptAnchors[i + 1][0]) + 1, ptAnchors[i][1]); j++) { for (int k = 0; k <= 2 * nKernelSize; k++) { - UINT32* pPixel = - pShadBits + (szShadow.cy - i - 1 + nKernelSize - k) * szShadow.cx + j - nKernelSize; + UINT32* pPixel = pShadBits + (szShadow.cy - i - 1 + nKernelSize - k) * szShadow.cx + j - nKernelSize; UINT32* pKernelPixel = pKernel + k * (2 * nKernelSize + 1); for (int l = 0; l <= 2 * nKernelSize; l++) { if (*pPixel < *pKernelPixel) @@ -505,8 +500,7 @@ void CWndShadow::MakeShadow(UINT32* pShadBits, HWND hParent, RECT* rcParent) // End of line for (j = max(j, min(ptAnchors[i - 1][1], ptAnchors[i + 1][1]) - 1); j < ptAnchors[i][1]; j++) { for (int k = 0; k <= 2 * nKernelSize; k++) { - UINT32* pPixel = - pShadBits + (szShadow.cy - i - 1 + nKernelSize - k) * szShadow.cx + j - nKernelSize; + UINT32* pPixel = pShadBits + (szShadow.cy - i - 1 + nKernelSize - k) * szShadow.cx + j - nKernelSize; UINT32* pKernelPixel = pKernel + k * (2 * nKernelSize + 1); for (int l = 0; l <= 2 * nKernelSize; l++) { if (*pPixel < *pKernelPixel) @@ -524,27 +518,24 @@ void CWndShadow::MakeShadow(UINT32* pShadBits, HWND hParent, RECT* rcParent) for (int i = min(nKernelSize, max(m_nSize - m_nyOffset, 0)); i < max(szShadow.cy - nKernelSize, min(szParent.cy + m_nSize - m_nyOffset, szParent.cy + 2 * m_nSize)); i++) { UINT32* pLine = pShadBits + (szShadow.cy - i - 1) * szShadow.cx; - if (i - m_nSize + m_nyOffset < 0 - || i - m_nSize + m_nyOffset >= szParent.cy) // Line is not covered by parent window + if (i - m_nSize + m_nyOffset < 0 || i - m_nSize + m_nyOffset >= szParent.cy) // Line is not covered by parent window { for (int j = ptAnchors[i][0]; j < ptAnchors[i][1]; j++) { *(pLine + j) = clCenter; } } else { - for (int j = ptAnchors[i][0]; - j < min(ptAnchorsOri[i - m_nSize + m_nyOffset][0] + m_nSize - m_nxOffset, ptAnchors[i][1]); j++) + for (int j = ptAnchors[i][0]; j < min(ptAnchorsOri[i - m_nSize + m_nyOffset][0] + m_nSize - m_nxOffset, ptAnchors[i][1]); j++) *(pLine + j) = clCenter; for (int j = max(ptAnchorsOri[i - m_nSize + m_nyOffset][0] + m_nSize - m_nxOffset, 0); j < min(ptAnchorsOri[i - m_nSize + m_nyOffset][1] + m_nSize - m_nxOffset, szShadow.cx); j++) *(pLine + j) = 0; - for (int j = max(ptAnchorsOri[i - m_nSize + m_nyOffset][1] + m_nSize - m_nxOffset, ptAnchors[i][0]); - j < ptAnchors[i][1]; j++) + for (int j = max(ptAnchorsOri[i - m_nSize + m_nyOffset][1] + m_nSize - m_nxOffset, ptAnchors[i][0]); j < ptAnchors[i][1]; j++) *(pLine + j) = clCenter; } } // Delete used resources - delete[](ptAnchors - (m_nSize < 0 ? -m_nSize : 0) - 1); + delete[] (ptAnchors - (m_nSize < 0 ? -m_nSize : 0) - 1); delete[] ptAnchorsTmp; delete[] ptAnchorsOri; delete[] pKernel; diff --git a/uibase/uilib/utils/wndshadow.h b/uibase/uilib/utils/wndshadow.h index e88b3ce6292c2e14d5a8e9f4e2419967648a9a42..465e2130ec57711bc15e11c704a8c0020c89dde8 100644 --- a/uibase/uilib/utils/wndshadow.h +++ b/uibase/uilib/utils/wndshadow.h @@ -18,15 +18,7 @@ protected: // typedef BOOL(WINAPI* pfnUpdateLayeredWindow)( - HWND hWnd, - HDC hdcDst, - POINT* pptDst, - SIZE* psize, - HDC hdcSrc, - POINT* pptSrc, - COLORREF crKey, - BLENDFUNCTION* pblend, - DWORD dwFlags); + HWND hWnd, HDC hdcDst, POINT* pptDst, SIZE* psize, HDC hdcSrc, POINT* pptSrc, COLORREF crKey, BLENDFUNCTION* pblend, DWORD dwFlags); static pfnUpdateLayeredWindow s_UpdateLayeredWindow; HWND m_hWnd; @@ -98,7 +90,6 @@ protected: inline DWORD PreMultiply(COLORREF cl, unsigned char nAlpha) { // It's strange that the byte order of RGB in 32b BMP is reverse to in COLORREF - return (GetRValue(cl) * (DWORD)nAlpha / 255) << 16 | (GetGValue(cl) * (DWORD)nAlpha / 255) << 8 - | (GetBValue(cl) * (DWORD)nAlpha / 255); + return (GetRValue(cl) * (DWORD)nAlpha / 255) << 16 | (GetGValue(cl) * (DWORD)nAlpha / 255) << 8 | (GetBValue(cl) * (DWORD)nAlpha / 255); } }; diff --git a/uibase/uiwindowimpl.cpp b/uibase/uiwindowimpl.cpp index a218846cfa1a31320b1250fb32dc12ea6b803baf..ebd26828ba60a51f7053fd807634010eb2d2844d 100644 --- a/uibase/uiwindowimpl.cpp +++ b/uibase/uiwindowimpl.cpp @@ -144,8 +144,7 @@ LRESULT CUiWindowsImpl::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bH rcWnd.bottom++; RECT rc = {rcWnd.left, rcWnd.top + szRoundCorner.cx, rcWnd.right, rcWnd.bottom}; HRGN hRgn1 = ::CreateRectRgnIndirect(&rc); - HRGN hRgn2 = ::CreateRoundRectRgn( - rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom - szRoundCorner.cx, szRoundCorner.cx, szRoundCorner.cy); + HRGN hRgn2 = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom - szRoundCorner.cx, szRoundCorner.cx, szRoundCorner.cy); ::CombineRgn(hRgn1, hRgn1, hRgn2, RGN_OR); ::SetWindowRgn(*this, hRgn1, TRUE); ::DeleteObject(hRgn1); @@ -168,11 +167,10 @@ LRESULT CUiWindowsImpl::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOO ::GetClientRect(*this, &rcClient); RECT rcCaption = m_pm.GetCaptionRect(); - if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right && pt.y >= rcCaption.top - && pt.y < rcCaption.bottom) { + if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right && pt.y >= rcCaption.top && pt.y < rcCaption.bottom) { CControlUI* pControl = static_cast(m_pm.FindControl(pt)); - if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 - && _tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 && _tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0) + if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 && _tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 + && _tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0) return HTCAPTION; }