Skip to content

Commit 7c1f6b4

Browse files
committed
Merged PR 10481180: Add OpenSSL implementation for AesGcm test
## Description: ## Admin Checklist: - [ ] You have updated documentation in symcrypt.h to reflect any changes in behavior - [ ] You have updated CHANGELOG.md to reflect any changes in behavior - [ ] You have updated symcryptunittest to exercise any new functionality - [ ] If you have introduced any symbols in symcrypt.h you have updated production and test dynamic export symbols (exports.ver / exports.def / symcrypt.src) and tested the updated dynamic modules with symcryptunittest - [ ] If you have introduced functionality that varies based on CPU features, you have manually tested with and without relevant features - [ ] If you have made significant changes to a particular algorithm, you have checked that performance numbers reported by symcryptunittest are in line with expectations - [ ] If you have added new algorithms/modes, you have updated the status indicator text for the associated modules if necessary Add OpenSSL implementation for AesGcm test
1 parent 476b838 commit 7c1f6b4

File tree

12 files changed

+532
-73
lines changed

12 files changed

+532
-73
lines changed

.pipelines/OneBranch.PullRequest.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ extends:
146146
cc: 'gcc'
147147
cxx: 'g++'
148148
skipTests: true
149-
additionalArgs: '--no-asm --openssl'
149+
additionalArgs: '--no-asm'
150+
openssl: true
150151
identifier: 'NoAsm'
151152
- template: .pipelines/templates/build-linux.yml@self
152153
parameters:
@@ -155,7 +156,8 @@ extends:
155156
cc: 'clang'
156157
cxx: 'clang++'
157158
skipTests: true
158-
additionalArgs: '--no-asm --openssl'
159+
additionalArgs: '--no-asm'
160+
openssl: true
159161
identifier: 'NoAsm'
160162
- template: .pipelines/templates/build-linux.yml@self
161163
parameters:

.pipelines/templates/build-linux.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
${{ else }}:
5151
verbose_build_flag: ''
5252
${{ if eq(parameters.openssl, true) }}:
53-
openssl_build_flag: '--openssl'
53+
openssl_build_flag: '--openssl-build-from-source'
5454
${{ else }}:
5555
openssl_build_flag: ''
5656

@@ -86,10 +86,12 @@ jobs:
8686
apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf qemu-user
8787
displayName: 'Install arm cross-compilation tools'
8888
89-
- ${{ if eq(parameters.openssl, true) }}:
90-
- script: |
91-
apt-get install -y libssl-dev
92-
displayName: 'Install OpenSSL'
89+
# TODO: Once we move to Azure Linux 3 we can use the system-provided OpenSSL package.
90+
# For now we will built from source since Ubuntu 20.04 doesn't have OpenSSL 3.
91+
# - ${{ if eq(parameters.openssl, true) }}:
92+
# - script: |
93+
# apt-get install -y libssl-dev
94+
# displayName: 'Install OpenSSL'
9395

9496
- task: PipAuthenticate@1
9597
inputs:

.vscode/launch.json

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "(lldb) symcryptunittest",
11+
"program": "${workspaceFolder}/bin/exe/symcryptunittest",
12+
"args": [],
13+
"cwd": "${workspaceFolder}"
14+
},
715
{
816
"name": "(Windows) symcryptunittest",
917
"type": "cppvsdbg",
@@ -17,34 +25,5 @@
1725
"console": "integratedTerminal",
1826
"internalConsoleOptions": "openOnSessionStart"
1927
},
20-
{
21-
"name": "(Windows) symcryptunittest [+openssl +symcrypt +xtsaes]",
22-
"type": "cppvsdbg",
23-
"request": "launch",
24-
"program": "${workspaceFolder}/bin/exe/symcryptunittest.exe",
25-
"args": [
26-
"+openssl",
27-
"+symcrypt",
28-
"+xtsaes",
29-
],
30-
"stopAtEntry": false,
31-
"cwd": "${fileDirname}",
32-
"console": "integratedTerminal",
33-
},
34-
{
35-
"name": "(Windows) symcryptunittest [+openssl +symcrypt +xtsaes -vaes]",
36-
"type": "cppvsdbg",
37-
"request": "launch",
38-
"program": "${workspaceFolder}/bin/exe/symcryptunittest.exe",
39-
"args": [
40-
"+openssl",
41-
"+symcrypt",
42-
"+xtsaes",
43-
"-vaes"
44-
],
45-
"stopAtEntry": false,
46-
"cwd": "${fileDirname}",
47-
"console": "integratedTerminal",
48-
},
4928
]
5029
}

.vscode/settings.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,18 @@
1111
"icon": "terminal-powershell",
1212
"overrideName": true,
1313
}
14-
}
14+
},
15+
"terminal.integrated.defaultProfile.linux": "SymCrypt Profile",
16+
"terminal.integrated.profiles.linux": {
17+
"SymCrypt Profile": {
18+
"args": [
19+
"-c",
20+
"[ -f ./.venv/bin/activate ] && . ./.venv/bin/activate; exec bash"
21+
],
22+
"path": "bash",
23+
"source": "bash",
24+
"icon": "terminal-bash",
25+
"overrideName": true,
26+
}
27+
},
1528
}

.vscode/tasks.json

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111
}
1212
},
1313
},
14+
"linux": {
15+
"options": {
16+
"shell": {
17+
"executable": "bash",
18+
"args": [
19+
"-c",
20+
]
21+
}
22+
},
23+
},
1424
"tasks": [
1525
{
1626
"label": "Setup",
1727
"type": "shell",
18-
"command": [
19-
"python -m venv .venv;",
20-
". .\\.venv\\Scripts\\activate.ps1;",
21-
"pip install -r .\\scripts\\requirements.txt;",
22-
"Set-Content -value ('pushd;\n& \"\"\"' + (resolve-path 'C:\\Program Files\\Microsoft Visual Studio\\*\\*\\Common7\\Tools\\Launch-VsDevShell.ps1').path + '\"\"\" -Arch $env:PROCESSOR_ARCHITECTURE -HostArch $env:PROCESSOR_ARCHITECTURE;\npopd') -path '${workspaceFolder}\\.venv\\profile.ps1';",
23-
],
2428
"options": {
2529
"cwd": "${workspaceFolder}/",
2630
},
@@ -31,14 +35,36 @@
3135
"panel": "shared",
3236
"showReuseMessage": true,
3337
"clear": false,
38+
},
39+
"windows": {
40+
"command": [
41+
"python -m venv .venv;",
42+
". .\\.venv\\Scripts\\activate.ps1;",
43+
"pip install -r .\\scripts\\requirements.txt;",
44+
"Set-Content -value ('pushd;\n& \"\"\"' + (resolve-path 'C:\\Program Files\\Microsoft Visual Studio\\*\\*\\Common7\\Tools\\Launch-VsDevShell.ps1').path + '\"\"\" -Arch $env:PROCESSOR_ARCHITECTURE -HostArch $env:PROCESSOR_ARCHITECTURE;\npopd') -path '${workspaceFolder}\\.venv\\profile.ps1';",
45+
],
46+
},
47+
"linux": {
48+
"command": [
49+
"python3 -m venv .venv;",
50+
". ./.venv/bin/activate;",
51+
"pip install -r ./scripts/requirements.txt;",
52+
],
3453
}
3554
},
3655
{
3756
"label": "Clean",
3857
"type": "shell",
39-
"command": [
40-
"del -recurse bin_*,bin;",
41-
],
58+
"windows": {
59+
"command": [
60+
"del -recurse bin_*,bin,.venv;",
61+
],
62+
},
63+
"linux": {
64+
"command": [
65+
"rm -rf bin_* bin .venv"
66+
]
67+
},
4268
"options": {
4369
"cwd": "${workspaceFolder}/",
4470
},
@@ -54,16 +80,25 @@
5480
{
5581
"label": "Build [Debug]",
5682
"type": "shell",
57-
"command": "python",
58-
"args": [
59-
".\\scripts\\build.py",
60-
"cmake",
61-
"bin",
62-
"--arch",
63-
"amd64",
64-
"--config",
65-
"Debug",
66-
],
83+
"windows": {
84+
"command": "python",
85+
"args": [
86+
".\\scripts\\build.py",
87+
"cmake",
88+
"bin",
89+
"--arch",
90+
"amd64",
91+
"--config",
92+
"Debug",
93+
],
94+
},
95+
"linux": {
96+
"command": [
97+
"[ -f ./.venv/bin/activate ] && . ./.venv/bin/activate;",
98+
"python3 ./scripts/build.py cmake bin --arch amd64 --config Debug;",
99+
"exit",
100+
]
101+
},
67102
"options": {
68103
"cwd": "${workspaceFolder}/",
69104
},

BUILD.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ apt update
8989
apt -y install --no-install-recommends \
9090
cmake \
9191
python3-pyelftools \
92+
build-essential \
9293
gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
9394
```
9495
`python3-pyelftools` is for integrity verification and `gcc-arm-linux-gnueabihf` `g++-arm-linux-gnueabihf` are for ARM cross compile
@@ -110,19 +111,19 @@ prerequisites to building OpenSSL.
110111

111112
```
112113
winget install nasm strawberryperl
113-
.\scripts\build.py cmake bin --config Release --openssl-build-from-source
114+
python3 .\scripts\build.py cmake bin --config Release --openssl-build-from-source
114115
```
115116

116117
And on Linux we can use OpenSSL installed by system's package manager.
117118

118119
```
119120
sudo apt install -y libssl-dev
120-
./scripts/build.py cmake bin --config Release --openssl
121+
python3 ./scripts/build.py cmake bin --config Release --openssl
121122
```
122123

123124
To build OpenSSL on Linux we need to install following prerequisites.
124125

125126
```
126127
sudo apt install -y nasm perl
127-
.\scripts\build.py cmake bin --config Release --openssl-build-from-source
128+
python3 ./scripts/build.py cmake bin --config Release --openssl-build-from-source
128129
```

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ option(
8181
OFF)
8282

8383

84-
if (SYMCRYPT_TEST_WITH_OPENSSL)
85-
include(${CMAKE_SOURCE_DIR}/cmake-configs/OpenSSL.cmake)
86-
endif()
8784
include(${CMAKE_SOURCE_DIR}/cmake-configs/SymCrypt-Platforms.cmake)
8885

8986
if(NOT DEFINED CMAKE_BUILD_TYPE)
@@ -122,4 +119,4 @@ configure_file(build/symcrypt.pc.in symcrypt.pc @ONLY)
122119

123120
add_subdirectory(lib)
124121
add_subdirectory(modules)
125-
add_subdirectory(unittest)
122+
add_subdirectory(unittest)

cmake-configs/OpenSSL.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ if(OPENSSL_BUILD_FROM_SOURCE)
2929
set(ENV{CL} /MP)
3030
if(OPENSSL_BUILD_TYPE STREQUAL "release")
3131
execute_process(
32-
COMMAND perl Configure no-ssl no-tls1 no-tls1_1 --release
32+
COMMAND perl Configure no-ssl no-tls no-dtls no-legacy no-engine no-weak-ssl-ciphers no-rc4 no-rc5 no-rc2 no-md4 no-deprecated no-apps no-docs no-tests no-shared --release
3333
WORKING_DIRECTORY ${OPENSSL_BUILD_ROOT}
3434
RESULT_VARIABLE result)
3535
else()
3636
execute_process(
37-
COMMAND perl Configure no-ssl no-tls1 no-tls1_1 --debug
37+
COMMAND perl Configure no-ssl no-tls no-dtls no-legacy no-engine no-weak-ssl-ciphers no-rc4 no-rc5 no-rc2 no-md4 no-deprecated no-apps no-docs no-tests no-shared --debug
3838
WORKING_DIRECTORY ${OPENSSL_BUILD_ROOT}
3939
RESULT_VARIABLE result)
4040
endif()
@@ -61,11 +61,11 @@ if(OPENSSL_BUILD_FROM_SOURCE)
6161

6262
include(${OPENSSL_BUILD_ROOT}/OpenSSLConfig.cmake)
6363
else()
64-
find_package(OpenSSL REQUIRED)
64+
find_package(OpenSSL 3 REQUIRED)
6565
endif()
6666

67-
message("Found OpenSSL include directory ${OPENSSL_INCLUDE_DIR}")
68-
include_directories(${OPENSSL_INCLUDE_DIR})
69-
link_directories(${OPENSSL_LIBRARY_DIR})
70-
link_libraries(${OPENSSL_CRYPTO_LIBRARIES})
71-
add_compile_options(-DINCLUDE_IMPL_OPENSSL=1)
67+
if(OPENSSL_VERSION_MAJOR LESS 3)
68+
message(FATAL_ERROR "-- Invalid OpenSSL version found ${OPENSSL_VERSION} at ${OPENSSL_INCLUDE_DIR}")
69+
else()
70+
message("-- Found OpenSSL ${OPENSSL_VERSION} include directory ${OPENSSL_INCLUDE_DIR}")
71+
endif()

unittest/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ if(WIN32 AND SYMCRYPT_TARGET_ARCH MATCHES "X86")
7979
add_link_options(/SAFESEH:NO)
8080
endif()
8181

82+
83+
if(SYMCRYPT_TEST_WITH_OPENSSL)
84+
include(${CMAKE_SOURCE_DIR}/cmake-configs/OpenSSL.cmake)
85+
include_directories(${OPENSSL_INCLUDE_DIR})
86+
link_directories(${OPENSSL_LIBRARY_DIR})
87+
link_libraries(${OPENSSL_CRYPTO_LIBRARIES})
88+
add_compile_options(-DINCLUDE_IMPL_OPENSSL=1)
89+
endif()
90+
8291
include_directories(inc)
8392
include_directories(lib)
8493
include_directories(resource)

unittest/inc/openssl_implementations.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,13 @@ class XtsImpState<ImpOpenssl, AlgXtsAes> {
2424
EVP_CIPHER_CTX* decCtx;
2525
};
2626

27+
template<>
28+
class AuthEncImpState<ImpOpenssl, AlgAes, ModeGcm> {
29+
public:
30+
EVP_CIPHER_CTX* encCtx;
31+
EVP_CIPHER_CTX* decCtx;
32+
BOOLEAN inComputation;
33+
};
34+
2735
VOID
28-
addOpensslAlgs();
36+
addOpensslAlgs();

0 commit comments

Comments
 (0)