Skip to content

Commit

Permalink
Fix windows build and update BoringSSL to 2587c4974dbe9872451151c8e97…
Browse files Browse the repository at this point in the history
…5f58567a1ce0d (#279)

* Update vendoring script

* Update BoringSSL to 2587c4974dbe9872451151c8e975f58567a1ce0d
  • Loading branch information
Lukasa authored Oct 17, 2024
1 parent 4324b40 commit 4518e5e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Sources/CCryptoBoringSSL directory. The source repository is at
// https://boringssl.googlesource.com/boringssl.
//
// BoringSSL Commit: 76968bb3d53982560bcf08bcd0ba3e1865fe15cd
// BoringSSL Commit: 2587c4974dbe9872451151c8e975f58567a1ce0d

import PackageDescription

Expand Down
4 changes: 4 additions & 0 deletions Sources/CCryptoBoringSSL/crypto/bio/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,11 @@ static long conn_callback_ctrl(BIO *bio, int cmd, bio_info_cb fp) {
// convention.
OPENSSL_MSVC_PRAGMA(warning(push))
OPENSSL_MSVC_PRAGMA(warning(disable : 4191))
OPENSSL_CLANG_PRAGMA("clang diagnostic push")
OPENSSL_CLANG_PRAGMA("clang diagnostic ignored \"-Wunknown-warning-option\"")
OPENSSL_CLANG_PRAGMA("clang diagnostic ignored \"-Wcast-function-type\"")
data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
OPENSSL_CLANG_PRAGMA("clang diagnostic pop")
OPENSSL_MSVC_PRAGMA(warning(pop))
break;
default:
Expand Down
23 changes: 13 additions & 10 deletions Sources/CCryptoBoringSSL/crypto/poly1305/poly1305_vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@

typedef __m128i xmmi;

static const alignas(16) uint32_t poly1305_x64_sse2_message_mask[4] = {
alignas(16) static const uint32_t poly1305_x64_sse2_message_mask[4] = {
(1 << 26) - 1, 0, (1 << 26) - 1, 0};
static const alignas(16) uint32_t poly1305_x64_sse2_5[4] = {5, 0, 5, 0};
static const alignas(16) uint32_t poly1305_x64_sse2_1shl128[4] = {
(1 << 24), 0, (1 << 24), 0};
alignas(16) static const uint32_t poly1305_x64_sse2_5[4] = {5, 0, 5, 0};
alignas(16) static const uint32_t poly1305_x64_sse2_1shl128[4] = {(1 << 24), 0,
(1 << 24), 0};

static inline uint128_t add128(uint128_t a, uint128_t b) { return a + b; }

Expand Down Expand Up @@ -136,7 +136,8 @@ void CRYPTO_poly1305_init(poly1305_state *state, const uint8_t key[32]) {

static void poly1305_first_block(poly1305_state_internal *st,
const uint8_t *m) {
const xmmi MMASK = _mm_load_si128((const xmmi *)poly1305_x64_sse2_message_mask);
const xmmi MMASK =
_mm_load_si128((const xmmi *)poly1305_x64_sse2_message_mask);
const xmmi FIVE = _mm_load_si128((const xmmi *)poly1305_x64_sse2_5);
const xmmi HIBIT = _mm_load_si128((const xmmi *)poly1305_x64_sse2_1shl128);
xmmi T5, T6;
Expand Down Expand Up @@ -181,7 +182,7 @@ static void poly1305_first_block(poly1305_state_internal *st,
r20 = r20 & 0xfffffffffff;
r21 += c;

p->R20.v = _mm_shuffle_epi32(_mm_cvtsi32_si128((uint32_t)(r20)&0x3ffffff),
p->R20.v = _mm_shuffle_epi32(_mm_cvtsi32_si128((uint32_t)(r20) & 0x3ffffff),
_MM_SHUFFLE(1, 0, 1, 0));
p->R21.v = _mm_shuffle_epi32(
_mm_cvtsi32_si128((uint32_t)((r20 >> 26) | (r21 << 18)) & 0x3ffffff),
Expand Down Expand Up @@ -229,7 +230,8 @@ static void poly1305_first_block(poly1305_state_internal *st,

static void poly1305_blocks(poly1305_state_internal *st, const uint8_t *m,
size_t bytes) {
const xmmi MMASK = _mm_load_si128((const xmmi *)poly1305_x64_sse2_message_mask);
const xmmi MMASK =
_mm_load_si128((const xmmi *)poly1305_x64_sse2_message_mask);
const xmmi FIVE = _mm_load_si128((const xmmi *)poly1305_x64_sse2_5);
const xmmi HIBIT = _mm_load_si128((const xmmi *)poly1305_x64_sse2_1shl128);

Expand Down Expand Up @@ -419,7 +421,8 @@ static void poly1305_blocks(poly1305_state_internal *st, const uint8_t *m,

static size_t poly1305_combine(poly1305_state_internal *st, const uint8_t *m,
size_t bytes) {
const xmmi MMASK = _mm_load_si128((const xmmi *)poly1305_x64_sse2_message_mask);
const xmmi MMASK =
_mm_load_si128((const xmmi *)poly1305_x64_sse2_message_mask);
const xmmi HIBIT = _mm_load_si128((const xmmi *)poly1305_x64_sse2_1shl128);
const xmmi FIVE = _mm_load_si128((const xmmi *)poly1305_x64_sse2_5);

Expand Down Expand Up @@ -547,7 +550,7 @@ static size_t poly1305_combine(poly1305_state_internal *st, const uint8_t *m,
r1 = ((uint64_t)p->R21.d[3] << 32) | (uint64_t)p->R21.d[1];
r2 = ((uint64_t)p->R22.d[3] << 32) | (uint64_t)p->R22.d[1];

p->R20.d[2] = (uint32_t)(r0)&0x3ffffff;
p->R20.d[2] = (uint32_t)(r0) & 0x3ffffff;
p->R21.d[2] = (uint32_t)((r0 >> 26) | (r1 << 18)) & 0x3ffffff;
p->R22.d[2] = (uint32_t)((r1 >> 8)) & 0x3ffffff;
p->R23.d[2] = (uint32_t)((r1 >> 34) | (r2 << 10)) & 0x3ffffff;
Expand Down Expand Up @@ -838,7 +841,7 @@ void CRYPTO_poly1305_finish(poly1305_state *state, uint8_t mac[16]) {
c = (h1 >> 44);
h1 &= 0xfffffffffff;
t1 = (t1 >> 24);
h2 += (t1)+c;
h2 += (t1) + c;

CRYPTO_store_u64_le(mac + 0, ((h0) | (h1 << 44)));
CRYPTO_store_u64_le(mac + 8, ((h1 >> 20) | (h2 << 24)));
Expand Down
2 changes: 1 addition & 1 deletion Sources/CCryptoBoringSSL/hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 76968bb3d53982560bcf08bcd0ba3e1865fe15cd
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 2587c4974dbe9872451151c8e975f58567a1ce0d
3 changes: 3 additions & 0 deletions Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#define OPENSSL_HEADER_BASE_H

#define BORINGSSL_PREFIX CCryptoBoringSSL
#if defined(_WIN32) && (defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86))
#define OPENSSL_NO_ASM
#endif


// This file should be the first included by all BoringSSL headers.
Expand Down
2 changes: 1 addition & 1 deletion Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_evp.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ OPENSSL_EXPORT int PKCS5_PBKDF2_HMAC_SHA1(const char *password,
// as described below.
//
// |N|, |r|, and |p| are as described in RFC 7914 section 6. They determine the
// cost of the operation. If |max_mem| is zero, a defult limit of 32MiB will be
// cost of the operation. If |max_mem| is zero, a default limit of 32MiB will be
// used.
//
// The parameters are considered invalid under any of the following conditions:
Expand Down
9 changes: 9 additions & 0 deletions scripts/vendor-boringssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ echo "REMOVING libssl"
rm -rf "ssl"
)

echo "DISABLING assembly on x86 Windows"
(
# x86 Windows builds require nasm for acceleration. SwiftPM can't do that right now,
# so we disable the assembly.
cd "$DSTROOT"
gsed -i "/#define OPENSSL_HEADER_BASE_H/a#if defined(_WIN32) && (defined(__x86_64) || defined(_M_AMD64) || defined(_M_X64) || defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86))\n#define OPENSSL_NO_ASM\n#endif" "include/openssl/base.h"

)

mangle_symbols

echo "RENAMING header files"
Expand Down

0 comments on commit 4518e5e

Please sign in to comment.