Skip to content

Commit e222971

Browse files
Merged PR 12171827: Small build fixes
+ Make testing against legacy implementations entirely opt-in + Do not checkout SymCryptDependencies submodule by default + Never build against SymCryptDependencies in the official build pipeline + Enable AMD64 OP-TEE static lib build by adding CPUID detection logic
1 parent f6ec45c commit e222971

File tree

9 files changed

+99
-37
lines changed

9 files changed

+99
-37
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[submodule "SymCryptDependencies"]
22
path = unittest/SymCryptDependencies
33
url = https://microsoft.visualstudio.com/DefaultCollection/SymCryptDependencies/_git/SymCryptDependencies
4+
update = none
45

56
[submodule "jitterentropy-library"]
67
path = 3rdparty/jitterentropy-library

.pipelines/OneBranch.Official.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,21 @@ extends:
8585
arch: 'AMD64'
8686
config: 'Debug'
8787
sign: true
88-
additionalArgs: '--test-legacy-impl'
8988
- template: .pipelines/templates/build-windows-cmake.yml@self
9089
parameters:
9190
arch: 'AMD64'
9291
config: 'Release'
9392
sign: true
94-
additionalArgs: '--test-legacy-impl'
9593
- template: .pipelines/templates/build-windows-cmake.yml@self
9694
parameters:
9795
arch: 'X86'
9896
config: 'Debug'
9997
sign: true
100-
additionalArgs: '--test-legacy-impl'
10198
- template: .pipelines/templates/build-windows-cmake.yml@self
10299
parameters:
103100
arch: 'X86'
104101
config: 'Release'
105102
sign: true
106-
additionalArgs: '--test-legacy-impl'
107103
- template: .pipelines/templates/build-windows-cmake.yml@self
108104
parameters:
109105
arch: 'AMD64'

.pipelines/OneBranch.PullRequest.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ extends:
6969
parameters:
7070
arch: 'AMD64'
7171
config: 'Debug'
72-
additionalArgs: '--test-legacy-impl'
7372
- template: .pipelines/templates/build-windows-cmake.yml@self
7473
parameters:
7574
arch: 'AMD64'
7675
config: 'Release'
77-
additionalArgs: '--test-legacy-impl'
7876
libcrux: true
7977
- template: .pipelines/templates/build-windows-cmake.yml@self
8078
parameters:
@@ -95,12 +93,10 @@ extends:
9593
parameters:
9694
arch: 'X86'
9795
config: 'Debug'
98-
additionalArgs: '--test-legacy-impl'
9996
- template: .pipelines/templates/build-windows-cmake.yml@self
10097
parameters:
10198
arch: 'X86'
10299
config: 'Release'
103-
additionalArgs: '--test-legacy-impl'
104100
libcrux: true
105101
- template: .pipelines/templates/build-windows-cmake.yml@self
106102
parameters:

.pipelines/templates/build-windows-undocked.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
maximumCpuCount: true
135135
restoreNugetPackages: ${{ parameters.restoreNugetPackages }}
136136
msbuildArchitecture: 'x64'
137-
msbuildArgs: '-p:UndockedOfficial=${{ parameters.nativeCompiler }} -p:UndockedBuildId=$(Build.BuildId) -p:VER_BUILD_ID=$(Build.BuildId) -p:VER_SUFFIX=${{ parameters.buildType }} -p:SymCryptTestLegacyImpl=true ${{ parameters.msbuildArgs }}'
137+
msbuildArgs: '-p:UndockedOfficial=${{ parameters.nativeCompiler }} -p:UndockedBuildId=$(Build.BuildId) -p:VER_BUILD_ID=$(Build.BuildId) -p:VER_SUFFIX=${{ parameters.buildType }} ${{ parameters.msbuildArgs }}'
138138

139139
- task: SDLNativeRules@3
140140
displayName: '🛡 Guardian: PreFast'

BUILD.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ but not limited to the warranties of merchantability, fitness for a particular p
4141
## Build Instructions
4242
For Microsoft employees building the library internally, to include msbignum and RSA32 implementation benchmarks in
4343
the unit tests, make sure the SymCryptDependencies submodule is initialized by following the steps above
44-
(`git submodule update --init`). When building, specify `/p:SymCryptTestLegacyImpl=true` for MSBuild,
45-
or `-DSYMCRYPT_TEST_LEGACY_IMPL=ON` for CMake. This only affects the unit tests, and does not change the
46-
functionality of the SymCrypt library itself.
44+
(`git submodule init && git submodule update --checkout unittest/SymCryptDependencies`). When building, specify
45+
`/p:SymCryptTestLegacyImpl=true` for MSBuild, or `-DSYMCRYPT_TEST_LEGACY_IMPL=ON` for CMake. This only affects the
46+
unit tests, and does not change the functionality of the SymCrypt library itself.
4747

4848
### Using Python scripts
4949
Building SymCrypt can be complicated due to the number of platforms, architectures and targets supported. To improve

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Like any engineering project, SymCrypt is a compromise between conflicting requi
2222
In some of our Linux modules, SymCrypt uses [Jitterentropy](https://github.com/smuellerDD/jitterentropy-library)
2323
as a source of FIPS-certifiable entropy. To build these modules, you will need to ensure that the
2424
jitterentropy-library submodule is also cloned. You can do this by running
25-
`git submodule update --init -- 3rdparty/jitterentropy-library` after cloning.
25+
`git submodule update --init` after cloning.
2626

2727
The `unittest/SymCryptDependencies` submodule provides the RSA32 and msbignum implementations which are used as
2828
benchmarks in the unit tests when compiled on Windows. Due to licensing restrictions, we cannot release these

cmake-configs/SymCrypt-Platforms.cmake

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
8181
# Enable a baseline of features for the compiler to support everywhere
8282
# Assumes that the compiler will not emit crypto instructions as a result of normal C code
8383
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+simd+crypto")
84-
85-
if(SYMCRYPT_TARGET_ENV MATCHES "OPTEE")
86-
# TA DEV KIT is require for OPTEE TA compilation
87-
if(DEFINED TA_DEV_KIT_INC)
88-
# Get the compiler toolchain include
89-
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=include OUTPUT_VARIABLE TOOLCHAIN_INCLUDE)
90-
string(STRIP "${TOOLCHAIN_INCLUDE}" TOOLCHAIN_INCLUDE)
91-
# OPTEE env has a different stdlib and doesn't support atomic operations or multithreading.
92-
add_compile_options(-mno-outline-atomics -nostdinc -isystem ${TOOLCHAIN_INCLUDE})
93-
include_directories(${TA_DEV_KIT_INC})
94-
else()
95-
message(FATAL_ERROR "TA_DEV_KIT_INC must be defined for OPTEE build")
96-
endif()
97-
endif()
98-
84+
9985
# GCC complains about implicit casting between ASIMD registers (i.e. uint8x16_t -> uint64x2_t) by default,
10086
# whereas clang and MSVC do not. Setting -flax-vector-conversions to build Arm64 intrinsics code with GCC.
10187
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flax-vector-conversions")
@@ -107,6 +93,27 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")
10793
link_libraries(c)
10894
link_libraries(gcc)
10995
endif()
96+
97+
# OPTEE specific compilation options
98+
if(SYMCRYPT_TARGET_ENV MATCHES "OPTEE")
99+
# TA DEV KIT is require for OPTEE TA compilation
100+
if(DEFINED TA_DEV_KIT_INC)
101+
# Get the compiler toolchain include
102+
execute_process(COMMAND ${CMAKE_C_COMPILER} -print-file-name=include OUTPUT_VARIABLE TOOLCHAIN_INCLUDE)
103+
string(STRIP "${TOOLCHAIN_INCLUDE}" TOOLCHAIN_INCLUDE)
104+
105+
if(SYMCRYPT_TARGET_ARCH MATCHES "ARM64")
106+
# OPTEE env on Arm64 does not support atomic operations
107+
add_compile_options(-mno-outline-atomics)
108+
endif()
109+
110+
# OPTEE env has a different stdlib
111+
add_compile_options(-nostdinc -isystem ${TOOLCHAIN_INCLUDE})
112+
include_directories(${TA_DEV_KIT_INC})
113+
else()
114+
message(FATAL_ERROR "TA_DEV_KIT_INC must be defined for OPTEE build")
115+
endif()
116+
endif()
110117

111118
# add_compile_options(-Wall)
112119
add_compile_options(-Wno-unknown-pragmas)

lib/CMakeLists.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,14 +415,16 @@ if(NOT WIN32)
415415
set_target_properties(symcrypt_posixusermode PROPERTIES PREFIX "")
416416
target_link_libraries(symcrypt_posixusermode symcrypt_common)
417417
elseif(SYMCRYPT_TARGET_ENV MATCHES "OPTEE")
418-
# Remove files from symcrypt_common that are not supported in optee env.
419-
# aes-asm.c - use SymCryptAesDecryptAsm which is not defined for ARM64
420-
# cpuid_um.c - include auxv.h and use getauxval
421-
# session.c - use atomic operations (__atomic_compare_exchange)
422-
list(REMOVE_ITEM SOURCES_COMMON
423-
aes-asm.c
424-
cpuid_um.c
425-
session.c)
418+
if(SYMCRYPT_TARGET_ARCH MATCHES "ARM64")
419+
# Remove files from symcrypt_common that are not supported in ARM64 optee env.
420+
# aes-asm.c - use SymCryptAesDecryptAsm which is not defined for ARM64
421+
# cpuid_um.c - include auxv.h and use getauxval
422+
# session.c - use atomic operations (__atomic_compare_exchange)
423+
list(REMOVE_ITEM SOURCES_COMMON
424+
aes-asm.c
425+
cpuid_um.c
426+
session.c)
427+
endif()
426428

427429
add_library(symcrypt_envOpteeTa STATIC env_opteeTa.c)
428430
set_target_properties(symcrypt_envOpteeTa PROPERTIES PREFIX "")

lib/env_opteeTa.c

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,26 @@ SymCryptInitEnvOpteeTa( UINT32 version )
2929
return;
3030
}
3131

32-
// Optee module relies on the unconditional availability of certain CPU features (ASIMD, AES, PMULL, SHA256)
32+
#if SYMCRYPT_CPU_ARM64
33+
34+
// Optee on Arm64 currently relies on the unconditional availability of certain CPU features (ASIMD, AES, PMULL, SHA256)
3335
g_SymCryptCpuFeaturesNotPresent = (SYMCRYPT_CPU_FEATURES) ~(SYMCRYPT_CPU_FEATURE_NEON|SYMCRYPT_CPU_FEATURE_NEON_AES|SYMCRYPT_CPU_FEATURE_NEON_PMULL|SYMCRYPT_CPU_FEATURE_NEON_SHA256);
3436

37+
#elif SYMCRYPT_CPU_AMD64
38+
39+
SymCryptDetectCpuFeaturesByCpuid( SYMCRYPT_CPUID_DETECT_FLAG_CHECK_OS_SUPPORT_FOR_YMM );
40+
41+
//
42+
// Our SaveXmm function never fails because it doesn't have to do anything in User mode.
43+
//
44+
g_SymCryptCpuFeaturesNotPresent &= ~SYMCRYPT_CPU_FEATURE_SAVEXMM_NOFAIL;
45+
46+
#else
47+
48+
#error We only support ARM64 and AMD64 for OPTEE environment
49+
50+
#endif
51+
3552
SymCryptInitEnvCommon( version );
3653
}
3754

@@ -76,3 +93,46 @@ SymCryptTestInjectErrorEnvOpteeTa( PBYTE pbBuf, SIZE_T cbBuf )
7693
UNREFERENCED_PARAMETER( cbBuf );
7794
}
7895

96+
97+
#if SYMCRYPT_CPU_AMD64
98+
99+
SYMCRYPT_ERROR
100+
SYMCRYPT_CALL
101+
SymCryptSaveXmmEnvOpteeTa( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
102+
{
103+
UNREFERENCED_PARAMETER( pSaveData );
104+
105+
return SYMCRYPT_NO_ERROR;
106+
}
107+
108+
VOID
109+
SYMCRYPT_CALL
110+
SymCryptRestoreXmmEnvOpteeTa( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
111+
{
112+
UNREFERENCED_PARAMETER( pSaveData );
113+
}
114+
115+
SYMCRYPT_ERROR
116+
SYMCRYPT_CALL
117+
SymCryptSaveYmmEnvOpteeTa( _Out_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
118+
{
119+
UNREFERENCED_PARAMETER( pSaveData );
120+
121+
return SYMCRYPT_NO_ERROR;
122+
}
123+
124+
VOID
125+
SYMCRYPT_CALL
126+
SymCryptRestoreYmmEnvOpteeTa( _Inout_ PSYMCRYPT_EXTENDED_SAVE_DATA pSaveData )
127+
{
128+
UNREFERENCED_PARAMETER( pSaveData );
129+
}
130+
131+
VOID
132+
SYMCRYPT_CALL
133+
SymCryptCpuidExFuncEnvOpteeTa( int cpuInfo[4], int function_id, int subfunction_id )
134+
{
135+
__cpuidex( cpuInfo, function_id, subfunction_id );
136+
}
137+
138+
#endif

0 commit comments

Comments
 (0)