diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 454ea7b61..ac1761f65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,3 +76,39 @@ jobs: cmake .. -DOPENSSL_ROOT_DIR="$(brew --prefix ${OPENSSL})" make all VERBOSE=1 make check + windows: + name: "${{ matrix.name }}" + runs-on: [windows-latest] + # We want to run on external PRs, but not on our own internal PRs as they'll be run + # by the push to the branch. + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + + strategy: + fail-fast: false + matrix: + include: + - name: "Windows / OpenSSL 3.x" + openssl: openssl@3 + + timeout-minutes: 20 + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - uses: msys2/setup-msys2@v2 + with: + update: true + install: mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-openssl mingw-w64-x86_64-make + msystem: MINGW64 + path-type: inherit + + - name: Build + env: + OPENSSL: ${{ matrix.openssl }} + run: | + mkdir -p build + cd build + cmake -G "MSYS Makefiles" .. + mingw32-make all VERBOSE=1 + shell: msys2 {0} diff --git a/CMakeLists.txt b/CMakeLists.txt index 3af816dcb..e59266e6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,8 +125,10 @@ IF (OPENSSL_FOUND AND NOT (OPENSSL_VERSION VERSION_LESS "1.0.1")) INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) ADD_LIBRARY(picotls-openssl lib/openssl.c) TARGET_LINK_LIBRARIES(picotls-openssl ${OPENSSL_CRYPTO_LIBRARIES} picotls-core ${CMAKE_DL_LIBS}) - ADD_EXECUTABLE(cli t/cli.c lib/pembase64.c) - TARGET_LINK_LIBRARIES(cli picotls-openssl picotls-core) + IF (NOT WIN32) + ADD_EXECUTABLE(cli t/cli.c lib/pembase64.c) + TARGET_LINK_LIBRARIES(cli picotls-openssl picotls-core) + ENDIF () ADD_EXECUTABLE(test-openssl.t ${MINICRYPTO_LIBRARY_FILES} @@ -178,7 +180,9 @@ IF (NOT WITH_FUSION) SET_TARGET_PROPERTIES(ptlsbench PROPERTIES EXCLUDE_FROM_ALL 1) ENDIF () -ADD_CUSTOM_TARGET(check env BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} prove --exec '' -v ${CMAKE_CURRENT_BINARY_DIR}/*.t t/*.t WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${TEST_EXES} cli) +IF (NOT WIN32) + ADD_CUSTOM_TARGET(check env BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} prove --exec '' -v ${CMAKE_CURRENT_BINARY_DIR}/*.t t/*.t WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${TEST_EXES} cli) +ENDIF () IF (CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(CMAKE_C_FLAGS "-D_GNU_SOURCE -pthread ${CMAKE_C_FLAGS}") @@ -186,9 +190,19 @@ ELSEIF ("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS") TARGET_LINK_LIBRARIES(cli "socket" "nsl") ENDIF () -FIND_LIBRARY(LIBC_RESOLV_LIB "resolv") -IF (OPENSSL_FOUND AND LIBC_RESOLV_LIB) - TARGET_LINK_LIBRARIES(cli ${LIBC_RESOLV_LIB}) +IF (NOT WIN32) + FIND_LIBRARY(LIBC_RESOLV_LIB "resolv") + IF (OPENSSL_FOUND AND LIBC_RESOLV_LIB) + TARGET_LINK_LIBRARIES(cli ${LIBC_RESOLV_LIB}) + ENDIF () +ENDIF () + +IF (WIN32) + INCLUDE_DIRECTORIES(picotlsvs/picotls) + TARGET_LINK_LIBRARIES(test-minicrypto.t bcrypt ws2_32) + TARGET_LINK_LIBRARIES(test-openssl.t bcrypt ws2_32) + TARGET_LINK_LIBRARIES(test-fusion.t bcrypt ws2_32) + TARGET_LINK_LIBRARIES(ptlsbench bcrypt ws2_32) ENDIF () IF (BUILD_FUZZER) diff --git a/deps/cifra/src/bitops.h b/deps/cifra/src/bitops.h index a1c1e7d2e..eb5ace644 100644 --- a/deps/cifra/src/bitops.h +++ b/deps/cifra/src/bitops.h @@ -18,7 +18,7 @@ #include #include -#ifdef _WINDOWS +#ifdef _WIN32 #include #endif @@ -298,7 +298,7 @@ static inline void copy_bytes_unaligned(uint8_t *out, const uint8_t *in, size_t static inline uint32_t count_trailing_zeroes(uint32_t x) { -#ifdef _WINDOWS +#ifdef _WIN32 uint32_t r = 0; _BitScanReverse(&r, x); return (31 - r); diff --git a/include/picotls.h b/include/picotls.h index 9762dad64..a88f73788 100644 --- a/include/picotls.h +++ b/include/picotls.h @@ -26,7 +26,7 @@ extern "C" { #endif -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #endif @@ -60,7 +60,7 @@ extern "C" { #define PTLS_ELEMENTSOF(x) (PTLS_ASSERT_IS_ARRAY_EXPR(x) * sizeof(x) / sizeof((x)[0])) -#ifdef _WINDOWS +#ifdef _WIN32 #define PTLS_THREADLOCAL __declspec(thread) #else #define PTLS_THREADLOCAL __thread @@ -903,7 +903,7 @@ typedef enum en_ptls_early_data_acceptance_t { /** * optional arguments to client-driven handshake */ -#ifdef _WINDOWS +#ifdef _MSC_VER /* suppress warning C4201: nonstandard extension used: nameless struct/union */ #pragma warning(push) #pragma warning(disable : 4201) @@ -998,10 +998,10 @@ typedef struct st_ptls_handshake_properties_t { */ int (*collected_extensions)(ptls_t *tls, struct st_ptls_handshake_properties_t *properties, ptls_raw_extension_t *extensions); } ptls_handshake_properties_t; -#ifdef _WINDOWS +#ifdef _MSC_VER #pragma warning(pop) #endif -#ifdef _WINDOWS +#ifdef _MSC_VER /* suppress warning C4293: >> shift count negative or too big */ #pragma warning(disable : 4293) #endif diff --git a/include/picotls/ptlsbcrypt.h b/include/picotls/ptlsbcrypt.h index 531764173..a6d9537a7 100644 --- a/include/picotls/ptlsbcrypt.h +++ b/include/picotls/ptlsbcrypt.h @@ -28,7 +28,7 @@ extern "C" { #include "../picotls.h" -#ifdef _WINDOWS +#ifdef _WIN32 #include extern ptls_cipher_algorithm_t ptls_bcrypt_aes128ecb; diff --git a/lib/asn1.c b/lib/asn1.c index f394a8235..963cb7e10 100644 --- a/lib/asn1.c +++ b/lib/asn1.c @@ -18,7 +18,7 @@ * Basic ASN1 validation and optional print-out */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include diff --git a/lib/cifra/random.c b/lib/cifra/random.c index 17991be5f..648350e85 100644 --- a/lib/cifra/random.c +++ b/lib/cifra/random.c @@ -26,7 +26,7 @@ #include #include #include -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include @@ -35,7 +35,7 @@ #include "picotls.h" #include "picotls/minicrypto.h" #include -#ifdef _WINDOWS +#ifdef _WIN32 #ifdef _WINDOWS_XP /* The modern BCrypt API is only available on Windows Vista and later versions. * If compiling on Windows XP, we need to use the olded "wincrypt" API */ diff --git a/lib/ffx.c b/lib/ffx.c index 26b08c2e6..02376ff0f 100644 --- a/lib/ffx.c +++ b/lib/ffx.c @@ -13,7 +13,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include diff --git a/lib/fusion.c b/lib/fusion.c index b9f99daca..c54d03202 100644 --- a/lib/fusion.c +++ b/lib/fusion.c @@ -59,7 +59,7 @@ #define NO_SANITIZE_ADDRESS #endif -#ifdef _WINDOWS +#ifdef _WIN32 #define aligned_alloc(a, s) _aligned_malloc((s), (a)) #define aligned_free(p) _aligned_free(p) #else @@ -2168,7 +2168,7 @@ ptls_aead_algorithm_t ptls_non_temporal_aes256gcm = {"AES256-GCM", sizeof(struct aesgcm_context), non_temporal_aes256gcm_setup}; -#ifdef _WINDOWS +#ifdef _WIN32 /** * ptls_fusion_is_supported_by_cpu: * Check that the CPU has extended instructions for PCMUL, AES and AVX2. diff --git a/lib/minicrypto-pem.c b/lib/minicrypto-pem.c index d9e8dc584..e534d60bc 100644 --- a/lib/minicrypto-pem.c +++ b/lib/minicrypto-pem.c @@ -23,7 +23,7 @@ #include #include #include -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include diff --git a/lib/openssl.c b/lib/openssl.c index 511315eff..5826f53dc 100644 --- a/lib/openssl.c +++ b/lib/openssl.c @@ -20,7 +20,7 @@ * IN THE SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include @@ -45,7 +45,7 @@ #include "picotls.h" #include "picotls/openssl.h" -#ifdef _WINDOWS +#ifdef _MSC_VER #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif diff --git a/lib/pembase64.c b/lib/pembase64.c index 94246b21c..04fd00d5f 100644 --- a/lib/pembase64.c +++ b/lib/pembase64.c @@ -17,7 +17,7 @@ /* * Manage Base64 encoding. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include @@ -301,7 +301,7 @@ int ptls_load_pem_objects(char const *pem_fname, const char *label, ptls_iovec_t FILE *F; int ret = 0; size_t count = 0; -#ifdef _WINDOWS +#ifdef _WIN32 errno_t err = fopen_s(&F, pem_fname, "r"); if (err != 0) { ret = -1; diff --git a/lib/picotls.c b/lib/picotls.c index e8b7ac0f4..b9eb3a5f4 100644 --- a/lib/picotls.c +++ b/lib/picotls.c @@ -19,7 +19,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #endif #include @@ -27,7 +27,7 @@ #include #include #include -#ifndef _WINDOWS +#ifndef _WIN32 #include #include #include @@ -556,7 +556,7 @@ void ptls_buffer__release_memory(ptls_buffer_t *buf) { ptls_clear_memory(buf->base, buf->off); if (buf->is_allocated) { -#ifdef _WINDOWS +#ifdef _WIN32 if (buf->align_bits != 0) { _aligned_free(buf->base); } else { @@ -588,7 +588,7 @@ int ptls_buffer_reserve_aligned(ptls_buffer_t *buf, size_t delta, uint8_t align_ new_capacity *= 2; } if (align_bits != 0) { -#ifdef _WINDOWS +#ifdef _WIN32 if ((newp = _aligned_malloc(new_capacity, (size_t)1 << align_bits)) == NULL) return PTLS_ERROR_NO_MEMORY; #else diff --git a/lib/ptlsbcrypt.c b/lib/ptlsbcrypt.c index 2ffac7bd4..3b8032af1 100644 --- a/lib/ptlsbcrypt.c +++ b/lib/ptlsbcrypt.c @@ -20,7 +20,7 @@ * IN THE SOFTWARE. */ -#ifndef _WINDOWS +#ifndef _WIN32 /* This module is only defined for windows. * It is an implementation of the main crypto algorithms * using windows crypto libraries */ @@ -839,4 +839,4 @@ ptls_key_exchange_algorithm_t ptls_bcrypt_x25519 = {PTLS_GROUP_X25519, evp_keyex ptls_key_exchange_algorithm_t *ptls_bcrypt_key_exchanges[] = {&ptls_bcrypt_secp256r1, NULL}; #endif -#endif /* _WINDOWS */ +#endif /* _WIN32 */ diff --git a/lib/uecc.c b/lib/uecc.c index 5d42b3b6f..42ab3af29 100644 --- a/lib/uecc.c +++ b/lib/uecc.c @@ -23,7 +23,7 @@ #include #include #include -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include diff --git a/picotlsvs/picotls/wincompat.h b/picotlsvs/picotls/wincompat.h index 8c9c084c0..96f25f257 100644 --- a/picotlsvs/picotls/wincompat.h +++ b/picotlsvs/picotls/wincompat.h @@ -7,6 +7,9 @@ #include #include +#ifndef _MSC_VER +#include +#else #ifndef gettimeofday #define gettimeofday wintimeofday @@ -32,6 +35,7 @@ int wintimeofday(struct timeval *tv, struct timezone *tz); } /* extern "C" */ #endif +#endif #endif -#endif /* WINCOMPAT_H */ \ No newline at end of file +#endif /* WINCOMPAT_H */ diff --git a/picotlsvs/picotls/wintimeofday.c b/picotlsvs/picotls/wintimeofday.c index 7dfaeac58..ee6e945ca 100644 --- a/picotlsvs/picotls/wintimeofday.c +++ b/picotlsvs/picotls/wintimeofday.c @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" /* @@ -70,4 +70,4 @@ int wintimeofday(struct timeval* tv, struct timezone* tz) return 0; } -#endif /* WIN32 */ \ No newline at end of file +#endif /* WIN32 */ diff --git a/src/esni.c b/src/esni.c new file mode 100644 index 000000000..85d147c72 --- /dev/null +++ b/src/esni.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2018 Fastly, Kazuho Oku + * + * 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. + */ +#include +#include +#include +#include +#include +#ifdef _MSC_VER +#include "..\picotls\wincompat.h" +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS +#endif +#pragma warning(disable : 4996) +#else +#include +#endif +#include +#define OPENSSL_API_COMPAT 0x00908000L +#include +#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L +#include +#endif +#include +#include +#include "picotls.h" +#include "picotls/pembase64.h" +#include "picotls/openssl.h" + +static int emit_esni(ptls_key_exchange_context_t **key_exchanges, ptls_cipher_suite_t **cipher_suites, uint16_t padded_length, + uint64_t not_before, uint64_t lifetime, char const *published_sni, char const *file_output) +{ + ptls_buffer_t buf; + ptls_key_exchange_context_t *ctx[256] = {NULL}; + int ret; + + ptls_buffer_init(&buf, "", 0); + + ptls_buffer_push16(&buf, PTLS_ESNI_VERSION_DRAFT03); + ptls_buffer_push(&buf, 0, 0, 0, 0); /* checksum, filled later */ + if (published_sni != NULL) { + ptls_buffer_push_block(&buf, 2, { ptls_buffer_pushv(&buf, published_sni, strlen(published_sni)); }); + } else { + ptls_buffer_push16(&buf, 0); + } + ptls_buffer_push_block(&buf, 2, { + size_t i; + for (i = 0; key_exchanges[i] != NULL; ++i) { + ptls_buffer_push16(&buf, key_exchanges[i]->algo->id); + ptls_buffer_push_block(&buf, 2, + { ptls_buffer_pushv(&buf, key_exchanges[i]->pubkey.base, key_exchanges[i]->pubkey.len); }); + } + }); + ptls_buffer_push_block(&buf, 2, { + size_t i; + for (i = 0; cipher_suites[i] != NULL; ++i) + ptls_buffer_push16(&buf, cipher_suites[i]->id); + }); + ptls_buffer_push16(&buf, padded_length); + ptls_buffer_push64(&buf, not_before); + ptls_buffer_push64(&buf, not_before + lifetime - 1); + ptls_buffer_push_block(&buf, 2, {}); + { /* fill checksum */ + uint8_t d[PTLS_SHA256_DIGEST_SIZE]; + ptls_calc_hash(&ptls_openssl_sha256, d, buf.base, buf.off); + memcpy(buf.base + 2, d, 4); + } + + if (file_output != NULL) { + FILE *fo = fopen(file_output, "wb"); + if (fo == NULL) { + fprintf(stderr, "failed to open file:%s:%s\n", optarg, strerror(errno)); + goto Exit; + } else { + fwrite(buf.base, 1, buf.off, fo); + fclose(fo); + } + } else { + /* emit the structure to stdout */ + fwrite(buf.base, 1, buf.off, stdout); + fflush(stdout); + } + + ret = 0; +Exit : { + size_t i; + for (i = 0; ctx[i] != NULL; ++i) + ctx[i]->on_exchange(ctx + i, 1, NULL, ptls_iovec_init(NULL, 0)); +} + ptls_buffer_dispose(&buf); + return ret; +} + +static void usage(const char *cmd, int status) +{ + printf("picotls-esni - generates an ESNI Resource Record\n" + "\n" + "Usage: %s [options]\n" + "Options:\n" + " -n published sni value\n" + " -K private key files (repeat the option to include multiple\n" + " keys)\n" + " -c aes128-gcm, chacha20-poly1305, ...\n" + " -d number of days until expiration (default: 90)\n" + " -p padded length (default: 260)\n" + " -o write output to specified file instead of stdout\n" + " (use on Windows as stdout is not binary there)\n" + " -h prints this help\n" + "\n" + "-c and -x can be used multiple times.\n" + "\n", + cmd); + exit(status); +} + +int main(int argc, char **argv) +{ + char const *published_sni = NULL; + char const *file_output = NULL; + ERR_load_crypto_strings(); + OpenSSL_add_all_algorithms(); +#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L + (void)OSSL_PROVIDER_load(NULL, "default"); +#elif !defined(OPENSSL_NO_ENGINE) + /* Load all compiled-in ENGINEs */ + ENGINE_load_builtin_engines(); + ENGINE_register_all_ciphers(); + ENGINE_register_all_digests(); +#endif + + struct { + ptls_key_exchange_context_t *elements[256]; + size_t count; + } key_exchanges = {{NULL}, 0}; + struct { + ptls_cipher_suite_t *elements[256]; + size_t count; + } cipher_suites = {{NULL}, 0}; + uint16_t padded_length = 260; + uint64_t lifetime = 90 * 86400; + + int ch; + + while ((ch = getopt(argc, argv, "n:K:c:d:p:o:h")) != -1) { + switch (ch) { + case 'n': + published_sni = optarg; + break; + case 'K': { + FILE *fp; + EVP_PKEY *pkey; + + if ((fp = fopen(optarg, "rt")) == NULL) { + fprintf(stderr, "failed to open file:%s:%s\n", optarg, strerror(errno)); + exit(1); + } + + if ((pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL)) == NULL) { + fprintf(stderr, "failed to read private key from file:%s:%s\n", optarg, strerror(errno)); + exit(1); + } + fclose(fp); + if (ptls_openssl_create_key_exchange(key_exchanges.elements + key_exchanges.count++, pkey) != 0) { + fprintf(stderr, "unknown type of private key found in file:%s\n", optarg); + exit(1); + } + EVP_PKEY_free(pkey); + } break; + case 'c': { + size_t i; + for (i = 0; ptls_openssl_cipher_suites[i] != NULL; ++i) + if (strcasecmp(ptls_openssl_cipher_suites[i]->aead->name, optarg) == 0) + break; + if (ptls_openssl_cipher_suites[i] == NULL) { + fprintf(stderr, "unknown cipher-suite: %s\n", optarg); + exit(1); + } + cipher_suites.elements[cipher_suites.count++] = ptls_openssl_cipher_suites[i]; + } break; + case 'd': + if (sscanf(optarg, "%" SCNu64, &lifetime) != 1 || lifetime == 0) { + fprintf(stderr, "lifetime must be a positive integer\n"); + exit(1); + } + lifetime *= 86400; /* convert to seconds */ + break; + case 'p': +#ifdef _WIN32 + if (sscanf_s(optarg, "%" SCNu16, &padded_length) != 1 || padded_length == 0) { + fprintf(stderr, "padded length must be a positive integer\n"); + exit(1); + } +#else + if (sscanf(optarg, "%" SCNu16, &padded_length) != 1 || padded_length == 0) { + fprintf(stderr, "padded length must be a positive integer\n"); + exit(1); + } +#endif + break; + case 'o': + file_output = optarg; + break; + case 'h': + usage(argv[0], 0); + break; + default: + usage(argv[0], 1); + break; + } + } + if (cipher_suites.count == 0) + cipher_suites.elements[cipher_suites.count++] = &ptls_openssl_aes128gcmsha256; + if (key_exchanges.count == 0) { + fprintf(stderr, "no private key specified\n"); + exit(1); + } + + argc -= optind; + argv += optind; + + if (emit_esni(key_exchanges.elements, cipher_suites.elements, padded_length, time(NULL), lifetime, published_sni, + file_output) != 0) { + fprintf(stderr, "failed to generate ESNI private structure.\n"); + exit(1); + } + + return 0; +} diff --git a/t/fusion.c b/t/fusion.c index 1516485e9..b30de72f1 100644 --- a/t/fusion.c +++ b/t/fusion.c @@ -386,7 +386,7 @@ static void test_generated(void) ptls_cipher_context_t *rand = ptls_cipher_new(&ptls_minicrypto_aes128ctr, 1, zero); ptls_cipher_init(rand, zero); int i; -#ifdef _WINDOWS +#ifdef _WIN32 const int nb_runs = 1000; #else const int nb_runs = 10000; diff --git a/t/hpke.c b/t/hpke.c index e2cb0100f..d9cc8780e 100644 --- a/t/hpke.c +++ b/t/hpke.c @@ -19,7 +19,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #endif #include diff --git a/t/openssl.c b/t/openssl.c index b4c73b09b..0325d1865 100644 --- a/t/openssl.c +++ b/t/openssl.c @@ -19,7 +19,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #endif #include @@ -36,7 +36,7 @@ #include "picotls.h" #include "picotls/minicrypto.h" #include "picotls/openssl.h" -#if PTLS_OPENSSL_HAVE_ASYNC && PTLS_OPENSSL_HAVE_X25519 && !defined(_WINDOWS) +#if PTLS_OPENSSL_HAVE_ASYNC && PTLS_OPENSSL_HAVE_X25519 && !defined(_WIN32) #include #include #define ASYNC_TESTS 1 diff --git a/t/picotls.c b/t/picotls.c index 14fa849dc..42bcd0000 100644 --- a/t/picotls.c +++ b/t/picotls.c @@ -19,7 +19,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #endif #include diff --git a/t/ptlsbench.c b/t/ptlsbench.c index 62ac3595e..a3ae1f1d1 100644 --- a/t/ptlsbench.c +++ b/t/ptlsbench.c @@ -20,7 +20,7 @@ * IN THE SOFTWARE. */ -#ifdef _WINDOWS +#ifdef _WIN32 #include "wincompat.h" #else #include @@ -35,12 +35,12 @@ #include "picotls/ffx.h" #include "picotls/minicrypto.h" #include "picotls/openssl.h" -#ifndef _WINDOWS +#ifndef _WIN32 #include "picotls/fusion.h" #endif #include -#ifdef _WINDOWS +#ifdef _WIN32 #include #include "picotls/ptlsbcrypt.h" #ifdef _DEBUG @@ -205,7 +205,7 @@ static int bench_run_aead(char *OS, char *HW, int basic_ref, uint64_t s0, const int PP = (combined >> 4) & 0xFF; char letter = 'a' - 1 + PP; -#ifdef _WINDOWS +#ifdef _WIN32 (void)sprintf_s(p_version, sizeof(p_version), "%d.%d.%d%c", M, NN, FF, letter); #else (void)sprintf(p_version, "%d.%d.%d%c", M, NN, FF, letter); @@ -253,11 +253,11 @@ static ptls_bench_entry_t aead_list[] = { {"minicrypto", "aes128gcm", &ptls_minicrypto_aes128gcm, &ptls_minicrypto_sha256, 0}, {"minicrypto", "aes256gcm", &ptls_minicrypto_aes256gcm, &ptls_minicrypto_sha384, 0}, {"minicrypto", "chacha20poly1305", &ptls_minicrypto_chacha20poly1305, &ptls_minicrypto_sha256, 1}, -#ifdef _WINDOWS +#ifdef _WIN32 {"ptlsbcrypt", "aes128gcm", &ptls_bcrypt_aes128gcm, &ptls_bcrypt_sha256, 1}, {"ptlsbcrypt", "aes256gcm", &ptls_bcrypt_aes256gcm, &ptls_bcrypt_sha384, 1}, #endif -#if !defined(_WINDOWS) +#if !defined(_WIN32) {"fusion", "aes128gcm", &ptls_fusion_aes128gcm, &ptls_minicrypto_sha256, 1}, {"fusion", "aes256gcm", &ptls_fusion_aes256gcm, &ptls_minicrypto_sha384, 1}, #endif @@ -299,11 +299,11 @@ int main(int argc, char **argv) int basic_ref = bench_basic(&x); char OS[128]; char HW[128]; -#ifndef _WINDOWS +#ifndef _WIN32 struct utsname uts; #endif -#ifdef _WINDOWS +#ifdef _WIN32 (void)strcpy_s(OS, sizeof(OS), "windows"); (void)strcpy_s(HW, sizeof(HW), "x86_64"); #else diff --git a/t/util.h b/t/util.h index 0ead3f724..8fb00d99a 100644 --- a/t/util.h +++ b/t/util.h @@ -26,6 +26,14 @@ #define _XOPEN_SOURCE 700 /* required for glibc to use getaddrinfo, etc. */ #endif +#ifdef _WIN32 +#include +#include +#include +#include +#include +#define MAXPATHLEN MAXPNAMELEN +#else #include #include #include @@ -36,6 +44,7 @@ #include #include #include +#endif #include #include "picotls/pembase64.h" #include "picotls/openssl.h" @@ -441,7 +450,7 @@ static inline int normalize_txt(uint8_t *p, size_t len) /* The ptls_repeat_while_eintr macro will repeat a function call (block) if it is interrupted (EINTR) before completion. If failing * for other reason, the macro executes the exit block, such as either { break; } or { goto Fail; }. */ -#ifdef _WINDOWS +#ifdef _WIN32 #define repeat_while_eintr(expr, exit_block) \ while ((expr) < 0) { \ exit_block; \