Skip to content

Commit 7914bac

Browse files
committed
ARM66 Windows: Add assembly
Add assembly generated for Windows ARM64. Add build option to project files. Add CI loops.
1 parent 7cea6d3 commit 7914bac

25 files changed

Lines changed: 84903 additions & 1028 deletions
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Windows ARM64 Test
2+
3+
# Builds and tests wolfSSL on a native Windows-on-ARM64 runner. Unlike the
4+
# cross-compiled ARM64 job in os-check.yml (which runs on an x64 runner and can
5+
# only build), this runs on GitHub's native windows-11-arm image so the test
6+
# suite executes on the target ISA. The WolfSSLAarch64Asm=true leg assembles
7+
# the ARMv8 crypto .asm (armasm64) and enables the WOLFSSL_ARMASM code paths.
8+
9+
on:
10+
push:
11+
branches: [ 'release/**' ]
12+
paths-ignore:
13+
- '**/*.md'
14+
- 'doc/**'
15+
pull_request:
16+
types: [opened, synchronize, reopened, ready_for_review]
17+
branches: [ '*' ]
18+
paths-ignore:
19+
- '**/*.md'
20+
- 'doc/**'
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.ref }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
windows_arm64_build:
28+
name: Windows ARM64 Build Test
29+
if: ${{ (github.repository_owner == 'wolfssl') && (github.event_name != 'pull_request' || github.event.pull_request.draft == false) }}
30+
runs-on: windows-11-arm
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
# false: pure-C ARM64 build. true: assemble the ARMv8 crypto .asm and
35+
# enable the matching WOLFSSL_ARMASM code paths.
36+
asm: [ false, true ]
37+
timeout-minutes: 10
38+
env:
39+
SOLUTION_FILE_PATH: wolfssl64.sln
40+
BUILD_CONFIGURATION: Release
41+
steps:
42+
- uses: actions/checkout@v5
43+
44+
- name: Add MSBuild to PATH
45+
uses: microsoft/setup-msbuild@v3
46+
47+
- name: Restore NuGet packages
48+
working-directory: ${{env.GITHUB_WORKSPACE}}
49+
run: nuget restore ${{env.SOLUTION_FILE_PATH}}
50+
51+
- name: Build
52+
working-directory: ${{env.GITHUB_WORKSPACE}}
53+
run: msbuild /m /p:PlatformToolset=v143 /p:Platform=ARM64 /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:WolfSSLAarch64Asm=${{matrix.asm}} ${{env.SOLUTION_FILE_PATH}}
54+
55+
- name: Run Test
56+
working-directory: ${{env.GITHUB_WORKSPACE}}
57+
run: Release/ARM64/testsuite.exe

examples/client/client.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@
486486
<PreprocessorDefinitions>USE_INTEL_SPEEDUP;WOLFSSL_X86_64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
487487
</ClCompile>
488488
</ItemDefinitionGroup>
489+
<!-- Keep WOLFSSL_ARMASM consistent with the library (set by
490+
/p:WolfSSLAarch64Asm=true) so struct layouts match. -->
491+
<ItemDefinitionGroup Condition="'$(WolfSSLAarch64Asm)'=='true' And '$(Platform)'=='ARM64'">
492+
<ClCompile>
493+
<PreprocessorDefinitions>WOLFSSL_ARMASM;WOLFSSL_ARMASM_CRYPTO_SHA3;WOLFSSL_ARMASM_CRYPTO_SHA512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
494+
</ClCompile>
495+
</ItemDefinitionGroup>
489496
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
490497
<ImportGroup Label="ExtensionTargets">
491498
</ImportGroup>

examples/echoclient/echoclient.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@
486486
<PreprocessorDefinitions>USE_INTEL_SPEEDUP;WOLFSSL_X86_64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
487487
</ClCompile>
488488
</ItemDefinitionGroup>
489+
<!-- Keep WOLFSSL_ARMASM consistent with the library (set by
490+
/p:WolfSSLAarch64Asm=true) so struct layouts match. -->
491+
<ItemDefinitionGroup Condition="'$(WolfSSLAarch64Asm)'=='true' And '$(Platform)'=='ARM64'">
492+
<ClCompile>
493+
<PreprocessorDefinitions>WOLFSSL_ARMASM;WOLFSSL_ARMASM_CRYPTO_SHA3;WOLFSSL_ARMASM_CRYPTO_SHA512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
494+
</ClCompile>
495+
</ItemDefinitionGroup>
489496
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
490497
<ImportGroup Label="ExtensionTargets">
491498
</ImportGroup>

examples/echoserver/echoserver.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@
486486
<PreprocessorDefinitions>USE_INTEL_SPEEDUP;WOLFSSL_X86_64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
487487
</ClCompile>
488488
</ItemDefinitionGroup>
489+
<!-- Keep WOLFSSL_ARMASM consistent with the library (set by
490+
/p:WolfSSLAarch64Asm=true) so struct layouts match. -->
491+
<ItemDefinitionGroup Condition="'$(WolfSSLAarch64Asm)'=='true' And '$(Platform)'=='ARM64'">
492+
<ClCompile>
493+
<PreprocessorDefinitions>WOLFSSL_ARMASM;WOLFSSL_ARMASM_CRYPTO_SHA3;WOLFSSL_ARMASM_CRYPTO_SHA512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
494+
</ClCompile>
495+
</ItemDefinitionGroup>
489496
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
490497
<ImportGroup Label="ExtensionTargets">
491498
</ImportGroup>

examples/server/server.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@
486486
<PreprocessorDefinitions>USE_INTEL_SPEEDUP;WOLFSSL_X86_64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
487487
</ClCompile>
488488
</ItemDefinitionGroup>
489+
<!-- Keep WOLFSSL_ARMASM consistent with the library (set by
490+
/p:WolfSSLAarch64Asm=true) so struct layouts match. -->
491+
<ItemDefinitionGroup Condition="'$(WolfSSLAarch64Asm)'=='true' And '$(Platform)'=='ARM64'">
492+
<ClCompile>
493+
<PreprocessorDefinitions>WOLFSSL_ARMASM;WOLFSSL_ARMASM_CRYPTO_SHA3;WOLFSSL_ARMASM_CRYPTO_SHA512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
494+
</ClCompile>
495+
</ItemDefinitionGroup>
489496
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
490497
<ImportGroup Label="ExtensionTargets">
491498
</ImportGroup>

sslSniffer/sslSniffer.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@
264264
<PreprocessorDefinitions>USE_INTEL_SPEEDUP;WOLFSSL_X86_64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
265265
</ClCompile>
266266
</ItemDefinitionGroup>
267+
<!-- Keep WOLFSSL_ARMASM consistent with the library (set by
268+
/p:WolfSSLAarch64Asm=true) so struct layouts match. -->
269+
<ItemDefinitionGroup Condition="'$(WolfSSLAarch64Asm)'=='true' And '$(Platform)'=='ARM64'">
270+
<ClCompile>
271+
<PreprocessorDefinitions>WOLFSSL_ARMASM;WOLFSSL_ARMASM_CRYPTO_SHA3;WOLFSSL_ARMASM_CRYPTO_SHA512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
272+
</ClCompile>
273+
</ItemDefinitionGroup>
267274
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
268275
<ImportGroup Label="ExtensionTargets">
269276
</ImportGroup>

sslSniffer/sslSnifferTest/sslSniffTest.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,13 @@
265265
<PreprocessorDefinitions>USE_INTEL_SPEEDUP;WOLFSSL_X86_64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
266266
</ClCompile>
267267
</ItemDefinitionGroup>
268+
<!-- Keep WOLFSSL_ARMASM consistent with the library (set by
269+
/p:WolfSSLAarch64Asm=true) so struct layouts match. -->
270+
<ItemDefinitionGroup Condition="'$(WolfSSLAarch64Asm)'=='true' And '$(Platform)'=='ARM64'">
271+
<ClCompile>
272+
<PreprocessorDefinitions>WOLFSSL_ARMASM;WOLFSSL_ARMASM_CRYPTO_SHA3;WOLFSSL_ARMASM_CRYPTO_SHA512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
273+
</ClCompile>
274+
</ItemDefinitionGroup>
268275
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
269276
<ImportGroup Label="ExtensionTargets">
270277
</ImportGroup>

testsuite/testsuite.vcxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,13 @@
492492
<PreprocessorDefinitions>USE_INTEL_SPEEDUP;WOLFSSL_X86_64_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
493493
</ClCompile>
494494
</ItemDefinitionGroup>
495+
<!-- Keep WOLFSSL_ARMASM consistent with the library (set by
496+
/p:WolfSSLAarch64Asm=true) so struct layouts match. -->
497+
<ItemDefinitionGroup Condition="'$(WolfSSLAarch64Asm)'=='true' And '$(Platform)'=='ARM64'">
498+
<ClCompile>
499+
<PreprocessorDefinitions>WOLFSSL_ARMASM;WOLFSSL_ARMASM_CRYPTO_SHA3;WOLFSSL_ARMASM_CRYPTO_SHA512;%(PreprocessorDefinitions)</PreprocessorDefinitions>
500+
</ClCompile>
501+
</ItemDefinitionGroup>
495502
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
496503
<ImportGroup Label="ExtensionTargets">
497504
</ImportGroup>

wolfcrypt/src/cpuid.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,73 @@
403403
new_cpuid_flags |= CPUID_SM4;
404404
#endif
405405

406+
(void)wolfSSL_Atomic_Uint_CompareExchange
407+
(&cpuid_flags, &old_cpuid_flags, new_cpuid_flags);
408+
}
409+
}
410+
#elif defined(_WIN32)
411+
/* Windows on ARM64. IsProcessorFeaturePresent() is the documented way to
412+
* query instruction-set extensions: NEON (the 32x64-bit VFP register bank),
413+
* the mandatory ARMv8 crypto extension (AES / PMULL / SHA-1 / SHA-256,
414+
* reported as one feature), and the optional FEAT_SHA3 / FEAT_SHA512
415+
* extensions each have their own flag. FEAT_RDM (SQRDMLSH, ARMv8.1) has no
416+
* dedicated flag, so it is gated on the ARMv8.2 dot-product feature. */
417+
#include <windows.h>
418+
419+
/* Older Windows SDKs may not define these processor-feature constants. */
420+
#ifndef PF_ARM_VFP_32_REGISTERS_AVAILABLE
421+
#define PF_ARM_VFP_32_REGISTERS_AVAILABLE 18
422+
#endif
423+
#ifndef PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
424+
#define PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE 30
425+
#endif
426+
#ifndef PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE
427+
#define PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE 64
428+
#endif
429+
#ifndef PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE
430+
#define PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE 65
431+
#endif
432+
/* No dedicated flag for FEAT_RDM (ARMv8.1); gate on ARMv8.2 dot-product -
433+
* a CPU reporting v8.2 DP necessarily implements the v8.1 RDM (SQRDMLSH)
434+
* instructions the ML-KEM assembly uses. */
435+
#ifndef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE
436+
#define PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE 43
437+
#endif
438+
439+
static WC_INLINE void cpuid_set_flags(void)
440+
{
441+
if (WOLFSSL_ATOMIC_LOAD(cpuid_flags) == WC_CPUID_INITIALIZER) {
442+
cpuid_flags_t new_cpuid_flags = 0,
443+
old_cpuid_flags = WC_CPUID_INITIALIZER;
444+
445+
#ifndef WOLFSSL_ARMASM_NO_NEON
446+
if (IsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE))
447+
new_cpuid_flags |= CPUID_ASIMD;
448+
#endif
449+
#ifndef WOLFSSL_ARMASM_NO_HW_CRYPTO
450+
if (IsProcessorFeaturePresent(
451+
PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE)) {
452+
new_cpuid_flags |= CPUID_AES;
453+
new_cpuid_flags |= CPUID_PMULL;
454+
new_cpuid_flags |= CPUID_SHA256;
455+
}
456+
#endif
457+
#ifdef WOLFSSL_ARMASM_CRYPTO_SHA512
458+
if (IsProcessorFeaturePresent(
459+
PF_ARM_SHA512_INSTRUCTIONS_AVAILABLE))
460+
new_cpuid_flags |= CPUID_SHA512;
461+
#endif
462+
#if !defined(WOLFSSL_AARCH64_NO_SQRDMLSH)
463+
if (IsProcessorFeaturePresent(
464+
PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE))
465+
new_cpuid_flags |= CPUID_RDM;
466+
#endif
467+
#ifdef WOLFSSL_ARMASM_CRYPTO_SHA3
468+
if (IsProcessorFeaturePresent(
469+
PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE))
470+
new_cpuid_flags |= CPUID_SHA3;
471+
#endif
472+
406473
(void)wolfSSL_Atomic_Uint_CompareExchange
407474
(&cpuid_flags, &old_cpuid_flags, new_cpuid_flags);
408475
}

wolfcrypt/src/include.am

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ EXTRA_DIST += wolfcrypt/src/sha512_asm.asm
2828
EXTRA_DIST += wolfcrypt/src/sha3_asm.asm
2929
EXTRA_DIST += wolfcrypt/src/wc_mlkem_asm.asm
3030
EXTRA_DIST += wolfcrypt/src/wc_mldsa_asm.asm
31+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-aes-asm.asm
32+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-chacha-asm.asm
33+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-curve25519.asm
34+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-mlkem-asm.asm
35+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-poly1305-asm.asm
36+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-sha256-asm.asm
37+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-sha3-asm.asm
38+
EXTRA_DIST += wolfcrypt/src/port/arm/armv8-sha512-asm.asm
3139
EXTRA_DIST += wolfcrypt/src/wc_dsp.c
3240
EXTRA_DIST += wolfcrypt/src/sp_dsp32.c
3341
EXTRA_DIST += wolfcrypt/src/sp_x86_64_asm.asm

0 commit comments

Comments
 (0)