Merged PR 4178671: Add x86 CMake build with CPU optimizations

This change adds a CMake toolchain file for compiling SymCrypt for Windows x86 targets, using an AMD64 compiler host. I had to disable testing YMM register saving/restoring for the unit test, because the latest CRT's implementation of memcpy uses the XMM registers even on x86, which causes the test to fail. I disabled the test across the board rather than only for x86, because the AMD64 implementation was already ignoring changed XMM values, so it didn't really validate anything. I updated the relevant comments to reflect this change.

Also added some comments to the build scripts and fixed compilation errors in printtable.cpp on Linux and x86 Windows.

Related work items: #15886191
This commit is contained in:
Mitch Lindgren 🦎 2020-01-11 01:22:33 +00:00
Родитель 6b24979c29
Коммит b67edbb1e7
70 изменённых файлов: 390 добавлений и 339 удалений

Просмотреть файл

@ -6,14 +6,12 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
#if(C_MAKE_BUILD_TYPE MATCHES "Debug")
#
#endif()
# SYMCRYPT_TARGET_ENV should be set by the toolchain file. If there is no toolchain file we will build with no
# CPU-specific optimizations
# SYMCRYPT_TARGET_ENV should be set by the toolchain file. If no toolchain file is specified, we will build
# with no CPU-specific optimizations. Some toolchain files may require additional arguments; see the files
# under cmake-toolchain for more information.
if(NOT SYMCRYPT_TARGET_ENV)
message(STATUS "No toolchain file specified (or toolchain file did not set SYMCRYPT_TARGET_ENV).")
message(STATUS "Building for generic environment with SYMCRYPT_IGNORE_PLATFORM.")
set(SYMCRYPT_TARGET_ENV Generic)
add_compile_options(-DSYMCRYPT_IGNORE_PLATFORM)
else()
@ -24,12 +22,14 @@ endif()
message(STATUS "Host: ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_PROCESSOR}")
message(STATUS "Target: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR} ${SYMCRYPT_TARGET_ENV}")
# Set output directories binaries
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/${CMAKE_SYSTEM_PROCESSOR}/${SYMCRYPT_TARGET_ENV})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/${CMAKE_SYSTEM_PROCESSOR}/${SYMCRYPT_TARGET_ENV})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/exe/${CMAKE_SYSTEM_PROCESSOR}/${SYMCRYPT_TARGET_ENV})
if(WIN32 AND SYMCRYPT_TARGET_ENV MATCHES "WindowsUserMode")
# Annoyingly, this has to be done in the main CMake file rather than in the toolchain file
# Set DBG=1 and enable ASM_MASM. Annoyingly, this has to be done in the main CMake file rather than in
# the toolchain file
add_compile_options(-DDBG=1)
enable_language(ASM_MASM)
elseif(NOT WIN32)

Просмотреть файл

@ -19,16 +19,26 @@ Like any engineering project, SymCrypt is a compromise between conflicting requi
- Provide high assurance in the proper functionality of the library.
# Build and Test
At the moment this library only compiles with the Windows build system.
Unfortunately this toolchain is not available outside Microsoft.
We expect to have a Linux port working in the near future.
SymCrypt can be compiled with CMake >= 2.8.9 and Visual Studio 2019 (with Windows 10 SDK version 18362) on Windows
or gcc 7.4.0 on Linux.
1. `mkdir bin; cd bin`
2. Configure CMake compilation:
* For 32-bit Windows targets: `cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/windows-x86.cmake -A Win32`
* For 64-bit Windows targets: `cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/windows-amd64.cmake`
* For Linux (or Windows with no CPU optimizations): `cmake ..`
3. `cmake --build .`
If compilation succeeds, the output will be put in the `exe` subdirectory relative to where compilation occurred
(i.e. `bin/exe` if you followed the instructions above).
The SymCrypt unit test is in the `\unittest` directory. It runs extensive functional tests on the SymCrypt
library, as well as on other implementations such as the Windows APIs CNG and CAPI, and the older crypto libraries
rsa32 and msbignum. It also provides detailed performance information.
library. On Windows it also compares results against on other implementations such as the Windows APIs CNG
and CAPI, and the older crypto libraries rsa32 and msbignum, if they are available. It also provides
detailed performance information.
# Security Bugs
If you believe you have found a problem that affects the security of this code, please do NOT create an issue
If you believe you have found a problem that affects the security of this code, please do **NOT** create an issue
or pull request, but instead email your comments to secure@microsoft.com.
# Contribute

Просмотреть файл

@ -1,32 +1,77 @@
# This file defines the build pipeline to build SymCrypt in Azure Dev Ops. It defines multiple jobs
# for building and testing SymCrypt in each of the target environments. For more information on Azure
# Pipelines, see https://docs.microsoft.com/en-us/azure/devops/pipelines/customize-pipeline
# Execute the pipeline whenever a change is made to master
trigger:
- master
# Execute the pipeline on any PR into master. (Currently not supported on Azure Git Repos; must
# be configured through the UI.)
pr:
- master
# List of jobs to build. Each job follows the same general format.
# 1. Windows AMD64 with CPU optimizations
# 2. Windows x86 with CPU optimizations
# 3. Linux (host native) with no CPU optimizations
jobs:
- job: Windows
- job: Windows_AMD64
pool:
vmImage: 'windows-2019'
vmImage: 'windows-2019' # Windows Server 2019 with Visual Studio 2019
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
submodules: recursive
# Initialize CMake
# cd bin; cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/windows-amd64.cmake
- task: CMake@1
inputs:
workingDirectory: '$(Build.SourcesDirectory)/bin'
cmakeArgs: '.. -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/windows-amd64.cmake'
# Build with CMake
# cmake --build .
- task: CMake@1
inputs:
workingDirectory: '$(Build.SourcesDirectory)/bin'
cmakeArgs: '--build .'
# Execute unit tests
# Execute unit tests using the inline script
- script: |
cd bin\exe\AMD64\WindowsUserMode\Debug
.\symcryptunittest.exe
displayName: 'Execute generic unit test'
name: 'WindowsGenericUnitTest'
# Copy build output files to artifact staging directory
- task: CopyFiles@2
inputs:
SourceFolder: 'bin'
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
# Publish staged artifacts so they're available in the pipeline results
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop-Windows-AMD64'
publishLocation: 'Container'
- job: Windows_x86
pool:
vmImage: 'windows-2019'
steps:
- checkout: self
submodules: recursive
- task: CMake@1
inputs:
workingDirectory: '$(Build.SourcesDirectory)/bin'
cmakeArgs: '.. -DCMAKE_TOOLCHAIN_FILE=../cmake-toolchain/windows-x86.cmake -A Win32'
- task: CMake@1
inputs:
workingDirectory: '$(Build.SourcesDirectory)/bin'
cmakeArgs: '--build .'
- script: |
cd bin\exe\x86\WindowsUserMode\Debug
.\symcryptunittest.exe
displayName: 'Execute generic unit test'
name: 'WindowsGenericUnitTest'
- task: CopyFiles@2
inputs:
SourceFolder: 'bin'
@ -35,26 +80,23 @@ jobs:
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop-Windows-Generic'
ArtifactName: 'drop-Windows-x86'
publishLocation: 'Container'
- job: Linux
pool:
vmImage: 'ubuntu-18.04'
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
- checkout: self
submodules: recursive
# Initialize CMake
- task: CMake@1
inputs:
workingDirectory: '$(Build.SourcesDirectory)/bin'
cmakeArgs: '..'
# Build with CMake
- task: CMake@1
inputs:
workingDirectory: '$(Build.SourcesDirectory)/bin'
cmakeArgs: '--build .'
# Execute unit tests
- script: |
cd bin/exe/x86_64/Generic
./symcryptunittest

Просмотреть файл

@ -1,10 +1,15 @@
# This toolchain file configures CMake options for Windows AMD64 compilation with CPU optimizations.
# To use the toolchain file, run cmake .. -DCMAKE_TOOLCHAIN_FILE=cmake-toolchain/windows-x64.cmake
# Require Windows 10 SDK version 18362 for BCRYPT_TLS_CBC_HMAC_VERIFY_FLAG
set(CMAKE_SYSTEM_VERSION 10.0.18362)
# Set CMake variables that subsequent CMake scripts can check against
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR AMD64)
# For now this is just used for separating the output directories
set(SYMCRYPT_TARGET_ENV WindowsUserMode)
# Define _AMD64_ to set up the correct SymCrypt macros, e.g. SYMCRYPT_CPU_AMD64
add_compile_options(-D_AMD64_)

Просмотреть файл

@ -0,0 +1,25 @@
# This toolchain file configures CMake options for Windows x86 compilation with CPU optimizations.
# To use the toolchain file, run cmake .. -DCMAKE_TOOLCHAIN_FILE=cmake-toolchain/windows-x86.cmake -A Win32
#
# (The "-A Win32" option seems to be required when compiling on a 64-bit host. Ideally this toolchain file
# should set all the required options, but I haven't figured out how to force 32-bit compilation from the
# toolchain file, so if you don't provide "-A Win32" it will try to use the 64-bit compiler and assembler
# and will fail.)
# Require Windows 10 SDK version 18362 for BCRYPT_TLS_CBC_HMAC_VERIFY_FLAG
set(CMAKE_SYSTEM_VERSION 10.0.18362)
# Set CMake variables that subsequent CMake scripts can check against
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR X86)
# For now this is just used for separating the output directories
set(SYMCRYPT_TARGET_ENV WindowsUserMode)
# Define _X86_ to set up the correct SymCrypt macros, e.g. SYMCRYPT_CPU_X86
add_compile_options(-D_X86_)
# We link with modules that use the __stdcall calling convention for X86, but not all of the
# functions declarations are annotated to specify the calling convention. Thus, we have to
# set the default to __stdcall.
add_compile_options(/Gz)

Просмотреть файл

@ -52,7 +52,6 @@ extern "C" {
// to indicate that the environment is kernel mode and the compact SHA-256 implementation is to
// be used.
// There are optimized environments for various Windows use cases.
// At the moment there is no Linux port of SymCrypt.
//
//
// CHECKED BUILDS
@ -440,6 +439,12 @@ SymCryptUint64Bytesize( UINT64 value );
// (e.g. if XMM register saving is not needed, the stub function declared by the macro
// will always succeed, and the compiler will inline it and optimize it away.)
//
// Warning: due to recent changes in the Visual Studio C runtime, we cannot test saving
// of the YMM registers in Windows user mode. Because we do not have a kernel mode test
// for saving/restoring the YMM registers, this functionality is currently not tested.
// Before using SymCrypt in Windows 7 kernel mode, additional kernel mode tests should be
// added to verify this functionality.
//
//
// The following environment macros are available. Callers should invoke one of these
@ -746,11 +751,11 @@ SymCryptHashStateSize( _In_ PCSYMCRYPT_HASH pHash );
VOID
SYMCRYPT_CALL
SymCryptHash(
_In_ PCSYMCRYPT_HASH pHash,
_In_reads_( cbData ) PCBYTE pbData,
SIZE_T cbData,
_Out_writes_( min( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult );
_In_ PCSYMCRYPT_HASH pHash,
_In_reads_( cbData ) PCBYTE pbData,
SIZE_T cbData,
_Out_writes_( SYMCRYPT_MIN( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult );
VOID
SYMCRYPT_CALL
@ -769,10 +774,10 @@ SymCryptHashAppend(
VOID
SYMCRYPT_CALL
SymCryptHashResult(
_In_ PCSYMCRYPT_HASH pHash,
_Inout_updates_bytes_( pHash->stateSize ) PVOID pState,
_Out_writes_( min( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult );
_In_ PCSYMCRYPT_HASH pHash,
_Inout_updates_bytes_( pHash->stateSize ) PVOID pState,
_Out_writes_( SYMCRYPT_MIN( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult );
////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -1731,8 +1731,8 @@ SYMCRYPT_ALIGN struct _SYMCRYPT_MODELEMENT {
4 * SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( _nDigits ) + \
SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( 2 * _nDigits ) + \
2 * SYMCRYPT_FDEF_SIZEOF_DIVISOR_FROM_DIGITS( _nDigits ) + \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_DIVMOD( 2 * _nDigits, _nDigits ), \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_MUL( 2 * _nDigits ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_DIVMOD( 2 * _nDigits, _nDigits ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_MUL( 2 * _nDigits ), \
SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( _nDigits ) )) )
#define SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( _nModDigits ) \
@ -1741,18 +1741,18 @@ SYMCRYPT_ALIGN struct _SYMCRYPT_MODELEMENT {
#define SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_CRT_GENERATION( _nDigits ) ( \
2*SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( _nDigits ) + \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_EXTENDED_GCD( _nDigits ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_EXTENDED_GCD( _nDigits ), \
SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( _nDigits ) ))
#define SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_CRT_SOLUTION( _nDigits ) ( \
SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( _nDigits ) + \
SYMCRYPT_FDEF_SIZEOF_MODELEMENT_FROM_DIGITS( _nDigits ) + \
SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( 2*_nDigits ) + \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( _nDigits ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( _nDigits ), \
SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_MUL( 2*_nDigits ) ))
#define SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_MODULUS( _nDigits ) ( \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( _nDigits ),\
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( _nDigits ),\
(2*_nDigits+1) * SYMCRYPT_FDEF_DIGIT_SIZE + SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_DIVMOD( 2*_nDigits + 1, nDigits )) )
#define SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_MODINV( _nModDigits ) ( \
@ -1772,21 +1772,21 @@ SYMCRYPT_ALIGN struct _SYMCRYPT_MODELEMENT {
SYMCRYPT_FDEF_SIZEOF_MODULUS_FROM_DIGITS(_nDigits) + \
3*SYMCRYPT_FDEF_SIZEOF_MODELEMENT_FROM_DIGITS(_nDigits) + \
SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS(_nDigits) + \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_MODULUS(_nDigits), \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(_nDigits), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_MODULUS(_nDigits), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(_nDigits), \
SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_MODEXP( _nDigits ) )) )
#define SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_IS_PRIME( _nDigits ) ( \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_IS_POTENTIAL_PRIME( _nDigits ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_IS_POTENTIAL_PRIME( _nDigits ), \
SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_MILLER_RABIN( _nDigits ) ))
#define SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_PRIME_GEN( _nDigits ) ( \
SYMCRYPT_RSAKEY_MAX_NUMOF_PUBEXPS * SYMCRYPT_FDEF_SIZEOF_DIVISOR_FROM_DIGITS( 1 ) + \
SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( 1 ) + \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( 1 ), \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_DIVMOD( _nDigits, 1 ), \
max( SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( _nDigits ), \
max( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_IS_POTENTIAL_PRIME( _nDigits ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( 1 ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_DIVMOD( _nDigits, 1 ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SIZEOF_INT_FROM_DIGITS( _nDigits ), \
SYMCRYPT_MAX( SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_IS_POTENTIAL_PRIME( _nDigits ), \
SYMCRYPT_FDEF_SCRATCH_BYTES_FOR_INT_MILLER_RABIN( _nDigits ) )))))
//

Просмотреть файл

@ -91,30 +91,38 @@ set(SOURCES
IEEE802_11SaeCustom.c
)
if(NOT(SYMCRYPT_TARGET_ENV MATCHES "Generic") AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
list(APPEND SOURCES
amd64/aesasm.asm
amd64/fdef_asm.asm
amd64/fdef_mulx.asm
amd64/fdef369_asm.asm
amd64/sha1asm.asm
amd64/wipe.asm)
set_source_files_properties(
amd64/aesasm.asm
amd64/fdef_asm.asm
amd64/fdef_mulx.asm
amd64/fdef369_asm.asm
amd64/sha1asm.asm
amd64/wipe.asm
PROPERTY LANGUAGE ASM_MASM)
# set_source_files_properties(
# amd64/aesasm.asm
# amd64/fdef_asm.asm
# amd64/fdef_mulx.asm
# amd64/fdef369_asm.asm
# amd64/sha1asm.asm
# amd64/wipe.asm
# PROPERTY COMPILE_FLAGS "/D\"DBG=1\"")
if(NOT(SYMCRYPT_TARGET_ENV MATCHES "Generic"))
if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
list(APPEND SOURCES
amd64/aesasm.asm
amd64/fdef_asm.asm
amd64/fdef_mulx.asm
amd64/fdef369_asm.asm
amd64/sha1asm.asm
amd64/wipe.asm)
set_source_files_properties(
amd64/aesasm.asm
amd64/fdef_asm.asm
amd64/fdef_mulx.asm
amd64/fdef369_asm.asm
amd64/sha1asm.asm
amd64/wipe.asm
PROPERTY LANGUAGE ASM_MASM)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "X86")
list(APPEND SOURCES
i386/aesasm.asm
i386/fdef_asm.asm
i386/rc4asm.asm
i386/sha1asm.asm
i386/wipe.asm)
set_source_files_properties(
i386/aesasm.asm
i386/fdef_asm.asm
i386/rc4asm.asm
i386/sha1asm.asm
i386/wipe.asm
PROPERTY LANGUAGE ASM_MASM)
endif()
endif()
include_directories(${CMAKE_SOURCE_DIR}/inc)

Просмотреть файл

@ -84,8 +84,8 @@ SymCrypt802_11SaeCustomInit(
nDigits = SymCryptDigitsFromBits( 256 );
cbScratch = max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigits ),
cbScratch = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigits ),
SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) ) );
pbScratch = SymCryptCallbackAlloc( cbScratch );
@ -387,8 +387,8 @@ SymCrypt802_11SaeCustomCommitCreate(
PCSYMCRYPT_ECURVE pCurve = pState->pCurve;
nDigits = SymCryptDigitsFromBits( 256 );
cbScratch = max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve ),
cbScratch = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve ),
SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) ) );
pbScratch = SymCryptCallbackAlloc( cbScratch );
@ -491,9 +491,9 @@ SymCrypt802_11SaeCustomCommitProcess(
SIZE_T cbScratch;
nDigits = SymCryptDigitsFromBits( 256 );
cbScratch = max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS( pCurve ),
cbScratch = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS( pCurve ),
SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) ) ) );
pbScratch = SymCryptCallbackAlloc( cbScratch );

Просмотреть файл

@ -235,7 +235,7 @@ SymCryptRngAesGenerateBlocks(
// 1 + (~v & mask) is the value you can add to v so that the mask bits of the sum
// end up to be zero. It is in the range 1 .. mask+1
//
blocksToDo = min( cBlocks, 1 + ( (~v) & (MAX_CTRMSB64_BLOCKS - 1) ) );
blocksToDo = SYMCRYPT_MIN( cBlocks, 1 + ( (~v) & (MAX_CTRMSB64_BLOCKS - 1) ) );
bytesToDo = blocksToDo * SYMCRYPT_AES_BLOCK_SIZE;
SYMCRYPT_ASSERT( bytesToDo <= cbRandom );

Просмотреть файл

@ -37,7 +37,7 @@ SymCryptCrtGenerateForTwoCoprimes(
SYMCRYPT_ASSERT( pmP != NULL );
SYMCRYPT_ASSERT( pmQ != NULL );
nDigits = max( SymCryptModulusDigitsizeOfObject( pmP ), SymCryptModulusDigitsizeOfObject( pmQ ));
nDigits = SYMCRYPT_MAX( SymCryptModulusDigitsizeOfObject( pmP ), SymCryptModulusDigitsizeOfObject( pmQ ));
SYMCRYPT_ASSERT( cbScratch >= 2*SymCryptSizeofIntFromDigits( nDigits ) +
SYMCRYPT_SCRATCH_BYTES_FOR_EXTENDED_GCD( nDigits ));
@ -156,12 +156,12 @@ SymCryptCrtSolve(
UNREFERENCED_PARAMETER( flags );
nDigitsMax = max( SymCryptModulusDigitsizeOfObject( ppmCoprimes[0] ), SymCryptModulusDigitsizeOfObject( ppmCoprimes[1] ) );
nDigitsMax = SYMCRYPT_MAX( SymCryptModulusDigitsizeOfObject( ppmCoprimes[0] ), SymCryptModulusDigitsizeOfObject( ppmCoprimes[1] ) );
SYMCRYPT_ASSERT( cbScratch >= SymCryptSizeofIntFromDigits( nDigitsMax ) +
SymCryptSizeofModElementFromModulus( ppmCoprimes[0] ) +
SymCryptSizeofIntFromDigits( 2*nDigitsMax ) +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsMax ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsMax ),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_MUL( 2*nDigitsMax ) )
);

Просмотреть файл

@ -134,7 +134,7 @@ SymCryptDhSecretAgreement(
// Objects and scratch space size calculation
cbModelement = SymCryptSizeofModElementFromModulus( pDlgroup->pmP );
cbScratch = cbModelement +
max( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pDlgroup->nDigitsOfP ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pDlgroup->nDigitsOfP ),
SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pDlgroup->nDigitsOfP ));
// Scratch space allocation

Просмотреть файл

@ -276,8 +276,8 @@ SymCryptDlgroupGeneratePrimeQ_FIPS(
UINT32 carry = 0;
UNREFERENCED_PARAMETER( cbScratch );
SYMCRYPT_ASSERT( cbScratch >= max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR(SymCryptDigitsFromBits(nBitsOfQ+1)),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_IS_PRIME(pDlgroup->nDigitsOfQ),
SYMCRYPT_ASSERT( cbScratch >= SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR(SymCryptDigitsFromBits(nBitsOfQ+1)),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_IS_PRIME(pDlgroup->nDigitsOfQ),
2 * cbHash )) );
SYMCRYPT_ASSERT( cbHash >= cbPrimeQ );
@ -447,12 +447,12 @@ SymCryptDlgroupGeneratePrimeP_FIPS(
UNREFERENCED_PARAMETER( cbScratch );
SYMCRYPT_ASSERT( cbScratch >= 2*cbIntTwoQ + cbHash + cbSeed + cbW +
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pDlgroup->nDigitsOfP, ndDivTwoQ ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pDlgroup->nDigitsOfP, ndDivTwoQ ),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_IS_PRIME( pDlgroup->nDigitsOfP )) );
// Create temporaries
pbScratchInternal = pbScratch;
cbScratchInternal = max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pDlgroup->nDigitsOfP, ndDivTwoQ ),
cbScratchInternal = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pDlgroup->nDigitsOfP, ndDivTwoQ ),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_IS_PRIME( pDlgroup->nDigitsOfP ) );
pbScratch += cbScratchInternal;
@ -498,7 +498,7 @@ SymCryptDlgroupGeneratePrimeP_FIPS(
for (counter = 0; counter < dwMaxCounter+1; counter++)
{
cbWBytesLeft = cbW; // Bytes left to write
pbWCurr = pbW + cbW - min(cbW,cbHash); // Position of the first hash chunk to write (if cbW < cbHash then we write only 1 chunk)
pbWCurr = pbW + cbW - SYMCRYPT_MIN(cbW,cbHash); // Position of the first hash chunk to write (if cbW < cbHash then we write only 1 chunk)
while (cbWBytesLeft > 0)
{
@ -537,8 +537,8 @@ SymCryptDlgroupGeneratePrimeP_FIPS(
}
// Update the positions on the W buffer
cbWBytesLeft -= min(cbHash,cbWBytesLeft);
pbWCurr -= min(cbHash,cbWBytesLeft);
cbWBytesLeft -= SYMCRYPT_MIN(cbHash,cbWBytesLeft);
pbWCurr -= SYMCRYPT_MIN(cbHash,cbWBytesLeft);
}
// Import the W buffer into P
@ -659,14 +659,14 @@ SymCryptDlgroupGenerateGenG_FIPS(
UNREFERENCED_PARAMETER( cbScratch );
UNREFERENCED_PARAMETER( nDigitsOfQ );
SYMCRYPT_ASSERT( cbScratch >= cbExp + cbModElement + cbState + cbHash +
max(SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
max(SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, nDigitsOfQ ),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, nDigitsOfQ ),
SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfP ) )) );
// Create temporaries
pbScratchInternal = pbScratch;
cbScratchInternal = max( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, nDigitsOfQ ),
cbScratchInternal = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, nDigitsOfQ ),
SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfP ) ));
pbScratch += cbScratchInternal;
@ -791,22 +791,22 @@ SymCryptDlgroupScratchSpace_FIPS( UINT32 nBitsOfP, UINT32 nBitsOfQ, PCSYMCRYPT_H
// - SYMCRYPT_SCRATCH_BYTES results are upper bounded by 2^27 (including RSA and ECURVE)
// Thus the following calculation does not overflow the result and is bounded by 2^28.
//
return max( cbDivTwoQ + max(
return SYMCRYPT_MAX( cbDivTwoQ + SYMCRYPT_MAX(
// Generate Q
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( ndDivTwoQ ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_IS_PRIME( nDigitsOfQ ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( ndDivTwoQ ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_IS_PRIME( nDigitsOfQ ),
2 * cbHash)),
// Generate P
2*cbIntTwoQ + cbHash + cbSeed + cbPrimeP +
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, ndDivTwoQ ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, ndDivTwoQ ),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_IS_PRIME( nDigitsOfP )) ),
max(
SYMCRYPT_MAX(
// Convert P and Q to moduli
SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS( nDigitsOfP ),
// Generate GenG
cbExp + cbModElement + cbState + cbHash +
max(SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
max(SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, nDigitsOfQ ),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( nDigitsOfP, nDigitsOfQ ),
SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfP ) )) ));
}
@ -1186,8 +1186,8 @@ SymCryptDlgroupSetValue(
// Also, we will need some additional space for the computed parameters:
// computedP, computedQ, and computedG.
cbScratchVerify = SymCryptDlgroupScratchSpace_FIPS( pDlgroup->nMaxBitsOfP, pDlgroup->nMaxBitsOfQ, pDlgroup->pHashAlgorithm ) +
max( SymCryptSizeofIntFromDigits(nMaxDigitsOfP),
max( SymCryptSizeofIntFromDigits(nMaxDigitsOfQ),
SYMCRYPT_MAX( SymCryptSizeofIntFromDigits(nMaxDigitsOfP),
SYMCRYPT_MAX( SymCryptSizeofIntFromDigits(nMaxDigitsOfQ),
2*SYMCRYPT_SIZEOF_MODELEMENT_FROM_BITS(nMaxDigitsOfP)));
}
@ -1200,9 +1200,9 @@ SymCryptDlgroupSetValue(
//
// Thus the following calculation does not overflow cbScratch.
//
cbScratch = max( SymCryptSizeofIntFromDigits(nMaxDigitsOfQ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS(nMaxDigitsOfP),
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nMaxDigitsOfP),
cbScratch = SYMCRYPT_MAX( SymCryptSizeofIntFromDigits(nMaxDigitsOfQ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS(nMaxDigitsOfP),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nMaxDigitsOfP),
cbScratchVerify )));
pbScratch = SymCryptCallbackAlloc( cbScratch );
if (pbScratch==NULL)

Просмотреть файл

@ -230,7 +230,7 @@ SymCryptDlkeyGenerate(
// Thus the following calculation does not overflow cbScratch.
//
cbScratch = cbPrivateKey +
max(SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nDigitsPriv),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nDigitsPriv),
SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP(pDlgroup->nDigitsOfP));
pbScratch = SymCryptCallbackAlloc( cbScratch );
if (pbScratch == NULL)
@ -334,7 +334,7 @@ SymCryptDlkeySetValue(
// - SYMCRYPT_SCRATCH_BYTES results are upper bounded by 2^27 (including RSA and ECURVE)
// Thus the following calculation does not overflow cbScratch.
//
cbScratch = max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(pDlgroup->nDigitsOfP),
cbScratch = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(pDlgroup->nDigitsOfP),
cbModElement + SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP(pDlgroup->nDigitsOfP) );
pbScratch = SymCryptCallbackAlloc( cbScratch );
if (pbScratch == NULL)

Просмотреть файл

@ -136,10 +136,10 @@ SymCryptDsaSignEx(
// Thus the following calculation does not overflow cbScratch.
//
cbScratch = cbIntLarge + cbIntQ + cbIntP + cbModelementP + 4*cbModelementQ +
max( cbScratchInputK,
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfQ ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfP ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
SYMCRYPT_MAX( cbScratchInputK,
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfQ ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfP ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( nDigitsOfP ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( nDigitsOfQ ) ))));
pbScratch = SymCryptCallbackAlloc( cbScratch );
if (pbScratch==NULL)
@ -433,7 +433,7 @@ SymCryptDsaVerify(
// Calculate the digit sizes
ndIntLarge = SymCryptDigitsFromBits( (UINT32)cbHashValue * 8 );
ndIntLarge = max( ndIntLarge, SymCryptDigitsFromBits( (UINT32)cbSignature * 4 ) ); // pbSignature contains (R,S)
ndIntLarge = SYMCRYPT_MAX( ndIntLarge, SymCryptDigitsFromBits( (UINT32)cbSignature * 4 ) ); // pbSignature contains (R,S)
// Calculate the sizes of temp objects
cbIntLarge = SymCryptSizeofIntFromDigits(ndIntLarge);
@ -450,10 +450,10 @@ SymCryptDsaVerify(
// Thus the following calculation does not overflow cbScratch.
//
cbScratch = cbIntLarge + cbIntP + 2*cbIntQ + cbModelementP + 3*cbModelementQ +
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD(nDigitsOfP,nDigitsOfQ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfQ ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfP ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_MODMULTIEXP( SymCryptModulusDigitsizeOfObject(pDlgroup->pmP), 2, pDlgroup->nBitsOfQ ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD(nDigitsOfP,nDigitsOfQ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfQ ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsOfP ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_MODMULTIEXP( SymCryptModulusDigitsizeOfObject(pDlgroup->pmP), 2, pDlgroup->nBitsOfQ ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( nDigitsOfQ ) ))));
pbScratch = SymCryptCallbackAlloc( cbScratch );
if (pbScratch==NULL)

Просмотреть файл

@ -61,8 +61,8 @@ SymCryptEcDhSecretAgreement(
goto cleanup;
}
cbScratchInternal = max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS(pCurve),
max( SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve ),
cbScratchInternal = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS(pCurve),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve ),
SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) ));
//

Просмотреть файл

@ -191,7 +191,7 @@ SymCryptEcDsaSignEx(
// Calculating the digits for the temporary integers
nDigitsInt = SymCryptDigitsFromBits( (UINT32)cbHashValue * 8 );
nDigitsInt = max( nDigitsInt, pCurve->GOrdDigits );
nDigitsInt = SYMCRYPT_MAX( nDigitsInt, pCurve->GOrdDigits );
nDigitsMul = SymCryptEcurveDigitsofScalarMultiplier(pCurve);
@ -203,10 +203,10 @@ SymCryptEcDsaSignEx(
cbX = SymCryptEcurveSizeofFieldElement( pCurve );
cbScratchInternal = SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ) );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ) );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( pCurve->GOrdDigits ) );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( pCurve->GOrdDigits ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) );
//
// From symcrypt_internal.h we have:
@ -433,9 +433,9 @@ SymCryptEcDsaVerify(
}
// Calculating the digits for the temporary integer
nDigitsInt = max( pCurve->FModDigits, pCurve->GOrdDigits );
nDigitsInt = max( nDigitsInt, SymCryptDigitsFromBits( (UINT32)cbHashValue * 8 ) );
nDigitsInt = max( nDigitsInt, SymCryptDigitsFromBits( (UINT32)cbSignature * 4 ) ); // pbSignature contains (c,d)
nDigitsInt = SYMCRYPT_MAX( pCurve->FModDigits, pCurve->GOrdDigits );
nDigitsInt = SYMCRYPT_MAX( nDigitsInt, SymCryptDigitsFromBits( (UINT32)cbHashValue * 8 ) );
nDigitsInt = SYMCRYPT_MAX( nDigitsInt, SymCryptDigitsFromBits( (UINT32)cbSignature * 4 ) ); // pbSignature contains (c,d)
nDigitsMul = SymCryptEcurveDigitsofScalarMultiplier(pCurve);
@ -447,11 +447,11 @@ SymCryptEcDsaVerify(
cbX = SymCryptEcurveSizeofFieldElement( pCurve );
cbScratchInternal = SYMCRYPT_SCRATCH_BYTES_FOR_MULTI_SCALAR_ECURVE_OPERATIONS( pCurve, 2 );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ) );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ) );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( pCurve->GOrdDigits ) );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) );
cbScratchInternal = max( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS( pCurve ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( pCurve->GOrdDigits ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_GETSET_VALUE_ECURVE_OPERATIONS( pCurve ) );
cbScratchInternal = SYMCRYPT_MAX( cbScratchInternal, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS( pCurve ) );
//
// From symcrypt_internal.h we have:

Просмотреть файл

@ -12,7 +12,7 @@ SymCryptMontgomeryFillScratchSpaces(_In_ PSYMCRYPT_ECURVE pCurve)
{
UINT32 nDigits = SymCryptDigitsFromBits( pCurve->FModBitsize );
UINT32 nBytes = SymCryptSizeofModElementFromModulus( pCurve->FMod );
UINT32 nCommon = max( SymCryptSizeofIntFromDigits( nDigits ), max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ), SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( nDigits ) ) );
UINT32 nCommon = SYMCRYPT_MAX( SymCryptSizeofIntFromDigits( nDigits ), SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ), SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( nDigits ) ) );
UINT32 cbModElement = pCurve->cbModElement;
UINT32 nDigitsFieldLength = pCurve->FModDigits;
@ -34,13 +34,13 @@ SymCryptMontgomeryFillScratchSpaces(_In_ PSYMCRYPT_ECURVE pCurve)
pCurve->cbScratchGetSetValue =
SymCryptSizeofEcpointEx( cbModElement, SYMCRYPT_ECPOINT_FORMAT_MAX_LENGTH ) +
2 * cbModElement +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsFieldLength ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsFieldLength ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( nDigitsFieldLength ) );
pCurve->cbScratchGetSetValue = max( pCurve->cbScratchGetSetValue, SymCryptSizeofIntFromDigits( nDigits ) );
pCurve->cbScratchGetSetValue = SYMCRYPT_MAX( pCurve->cbScratchGetSetValue, SymCryptSizeofIntFromDigits( nDigits ) );
pCurve->cbScratchEckey = pCurve->cbModElement + SymCryptSizeofIntFromDigits(SymCryptEcurveDigitsofScalarMultiplier(pCurve)) +
max( pCurve->cbScratchScalar, pCurve->cbScratchGetSetValue );
SYMCRYPT_MAX( pCurve->cbScratchScalar, pCurve->cbScratchGetSetValue );
}
VOID
@ -256,7 +256,7 @@ SymCryptMontgomeryPointScalarMul(
nDigits = SymCryptDigitsFromBits( pCurve->FModBitsize );
nBytes = SymCryptSizeofModElementFromModulus( pmMod );
nCommon = max( SymCryptSizeofIntFromDigits(nDigits), max(SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nDigits), SYMCRYPT_SCRATCH_BYTES_FOR_MODINV(nDigits)));
nCommon = SYMCRYPT_MAX( SymCryptSizeofIntFromDigits(nDigits), SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nDigits), SYMCRYPT_SCRATCH_BYTES_FOR_MODINV(nDigits)));
SYMCRYPT_ASSERT( cbScratch >= 6 * nBytes + nCommon );

Просмотреть файл

@ -88,7 +88,7 @@ SymCryptShortWeierstrassFillScratchSpaces( _In_ PSYMCRYPT_ECURVE pCurve )
pCurve->cbModElement +
2 * SymCryptSizeofEcpointEx( pCurve->cbModElement, SYMCRYPT_INTERNAL_NUMOF_COORDINATES( pCurve->eCoordinates ) ) +
2 * SymCryptSizeofIntFromDigits( pCurve->GOrdDigits ) +
max( pCurve->cbScratchCommon, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ));
SYMCRYPT_MAX( pCurve->cbScratchCommon, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ));
// Scalar dependent on precomp points (be careful to align the UINT32 arrays properly)
pCurve->cbScratchScalarMulti =
@ -99,14 +99,14 @@ SymCryptShortWeierstrassFillScratchSpaces( _In_ PSYMCRYPT_ECURVE pCurve )
pCurve->cbScratchGetSetValue =
SymCryptSizeofEcpointEx( pCurve->cbModElement, SYMCRYPT_ECPOINT_FORMAT_MAX_LENGTH ) +
2 * pCurve->cbModElement +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( pCurve->FModDigits ) );
pCurve->cbScratchGetSetValue = max( pCurve->cbScratchGetSetValue, SymCryptSizeofIntFromDigits( nDigits ) );
pCurve->cbScratchGetSetValue = SYMCRYPT_MAX( pCurve->cbScratchGetSetValue, SymCryptSizeofIntFromDigits( nDigits ) );
// Eckey
pCurve->cbScratchEckey = pCurve->cbModElement + SymCryptSizeofIntFromDigits(SymCryptEcurveDigitsofScalarMultiplier(pCurve)) +
max( pCurve->cbScratchScalar + pCurve->cbScratchScalarMulti, pCurve->cbScratchGetSetValue );
SYMCRYPT_MAX( pCurve->cbScratchScalar + pCurve->cbScratchScalarMulti, pCurve->cbScratchGetSetValue );
}
//

Просмотреть файл

@ -34,7 +34,7 @@ SymCryptTwistedEdwardsFillScratchSpaces( _In_ PSYMCRYPT_ECURVE pCurve )
(pCurve->cbModElement) +
2 * SymCryptSizeofEcpointEx( pCurve->cbModElement, SYMCRYPT_INTERNAL_NUMOF_COORDINATES( pCurve->eCoordinates ) ) +
2 * SymCryptSizeofIntFromDigits( pCurve->GOrdDigits ) +
max( pCurve->cbScratchCommon, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ));
SYMCRYPT_MAX( pCurve->cbScratchCommon, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->GOrdDigits ));
pCurve->cbScratchScalarMulti =
pCurve->info.sw.nPrecompPoints * SymCryptSizeofEcpointEx( pCurve->cbModElement, SYMCRYPT_INTERNAL_NUMOF_COORDINATES( pCurve->eCoordinates ) ) +
@ -43,13 +43,13 @@ SymCryptTwistedEdwardsFillScratchSpaces( _In_ PSYMCRYPT_ECURVE pCurve )
pCurve->cbScratchGetSetValue =
SymCryptSizeofEcpointEx(cbModElement, SYMCRYPT_ECPOINT_FORMAT_MAX_LENGTH) +
2 * cbModElement +
max(SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nDigitsFieldLength),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS(nDigitsFieldLength),
SYMCRYPT_SCRATCH_BYTES_FOR_MODINV(nDigitsFieldLength));
pCurve->cbScratchGetSetValue = max( pCurve->cbScratchGetSetValue, SymCryptSizeofIntFromDigits( nDigits ) );
pCurve->cbScratchGetSetValue = SYMCRYPT_MAX( pCurve->cbScratchGetSetValue, SymCryptSizeofIntFromDigits( nDigits ) );
pCurve->cbScratchEckey = pCurve->cbModElement + SymCryptSizeofIntFromDigits(SymCryptEcurveDigitsofScalarMultiplier(pCurve)) +
max( pCurve->cbScratchScalar + pCurve->cbScratchScalarMulti, pCurve->cbScratchGetSetValue );
SYMCRYPT_MAX( pCurve->cbScratchScalar + pCurve->cbScratchScalarMulti, pCurve->cbScratchGetSetValue );
}
VOID

Просмотреть файл

@ -219,7 +219,7 @@ SymCryptEcpointTransform(
PSYMCRYPT_MODELEMENT peT[2] = { 0 }; // Temporaries
SYMCRYPT_ASSERT( (flags & ~SYMCRYPT_FLAG_DATA_PUBLIC) == 0 );
SYMCRYPT_ASSERT( cbScratch >= max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ),
SYMCRYPT_ASSERT( cbScratch >= SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pCurve->FModDigits ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( pCurve->FModDigits )) +
2 * pCurve->cbModElement );

Просмотреть файл

@ -161,13 +161,13 @@ SymCryptEcurveAllocate(
//
cbScratch = SymCryptSizeofEcpointEx( cbModElement, SYMCRYPT_ECPOINT_FORMAT_MAX_LENGTH ) +
8 * cbModElement +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsFieldLength ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsFieldLength ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODINV( nDigitsFieldLength ) );
// IntToModulus( FMod and GOrd )
cbScratch = max( cbScratch,
SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS( max(nDigitsFieldLength, nDigitsSubgroupOrder) ) );
cbScratch = SYMCRYPT_MAX( cbScratch,
SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS( SYMCRYPT_MAX(nDigitsFieldLength, nDigitsSubgroupOrder) ) );
// ModElementSetValue( FMod )
cbScratch = max( cbScratch,
cbScratch = SYMCRYPT_MAX( cbScratch,
SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigitsFieldLength ) );
pbScratch = SymCryptCallbackAlloc( cbScratch );

Просмотреть файл

@ -341,7 +341,7 @@ SymCryptFdefIntCopyMixedSize(
// I would assume that this function isn't intended for use
// with private data due to branching
n = min( piSrc->nDigits, piDst->nDigits );
n = SYMCRYPT_MIN( piSrc->nDigits, piDst->nDigits );
memcpy( SYMCRYPT_FDEF_INT_PUINT32( piDst ), SYMCRYPT_FDEF_INT_PUINT32( piSrc ), n * SYMCRYPT_FDEF_DIGIT_SIZE );
if( piDst->nDigits > n )
@ -757,7 +757,7 @@ SymCryptFdefIntIsEqual(
PCUINT32 pSrc1 = SYMCRYPT_FDEF_INT_PUINT32( piSrc1 );
PCUINT32 pSrc2 = SYMCRYPT_FDEF_INT_PUINT32( piSrc2 );
n = min( n1, n2 );
n = SYMCRYPT_MIN( n1, n2 );
d = 0;
for( i=0; i < n ; i++ )
{
@ -1025,8 +1025,8 @@ SymCryptGenerateSmallPrimes( UINT32 maxPrime, PUINT32 * ppList )
UINT32 si;
UINT32 i;
maxPrime = max( maxPrime, 32 ); // simplify error handling by always producing primes at least up to 32
maxPrime = min( maxPrime, 1 << 24 ); // Limit prime list to something sane (sieve = 8 MB, list = 4 MB or so).
maxPrime = SYMCRYPT_MAX( maxPrime, 32 ); // simplify error handling by always producing primes at least up to 32
maxPrime = SYMCRYPT_MIN( maxPrime, 1 << 24 ); // Limit prime list to something sane (sieve = 8 MB, list = 4 MB or so).
// highest index is (maxPrime - 1)/2 which encodes maxPrime if odd, or maxPrime-1 if even
nSieve = (maxPrime - 1) / 2 + 1;
@ -1167,10 +1167,10 @@ SymCryptFdefCreateTrialDivisionContext( UINT32 nDigits )
// Now we know how many primes are in the last groups, let's find out how large the largest prime should be
tmp64 = cRabinMillerCost / cPerPrimeCost;
tmp64 = min( tmp64, SYMCRYPT_TRIALDIVISION_MAX_SMALL_PRIME );
tmp64 = SYMCRYPT_MIN( tmp64, SYMCRYPT_TRIALDIVISION_MAX_SMALL_PRIME );
maxPrime = (UINT32) tmp64;
SYMCRYPT_HARD_ASSERT( maxPrime == tmp64 );
maxPrime = max( maxPrime, minPrime ); // Make sure we don't fall into the previous group size that we don't want
maxPrime = SYMCRYPT_MAX( maxPrime, minPrime ); // Make sure we don't fall into the previous group size that we don't want
}
else
{

Просмотреть файл

@ -75,7 +75,7 @@ SymCryptGcmAddMacData(
SIZE_T nBytes;
if( pState->bytesInMacBlock > 0 )
{
nBytes = min( cbData, SYMCRYPT_GCM_BLOCK_SIZE - pState->bytesInMacBlock );
nBytes = SYMCRYPT_MIN( cbData, SYMCRYPT_GCM_BLOCK_SIZE - pState->bytesInMacBlock );
memcpy( &pState->macBlock[pState->bytesInMacBlock], pbData, nBytes );
pbData += nBytes;
cbData -= nBytes;
@ -151,7 +151,7 @@ SymCryptGcmEncryptDecryptPart(
if( bytesUsedInKeyStreamBuffer != 0 )
{
bytesToProcess = min( cbData, SYMCRYPT_GCM_BLOCK_SIZE - bytesUsedInKeyStreamBuffer );
bytesToProcess = SYMCRYPT_MIN( cbData, SYMCRYPT_GCM_BLOCK_SIZE - bytesUsedInKeyStreamBuffer );
SymCryptXorBytes( pbSrc, &pState->keystreamBlock[bytesUsedInKeyStreamBuffer], pbDst, bytesToProcess );
pbSrc += bytesToProcess;
pbDst += bytesToProcess;

Просмотреть файл

@ -183,7 +183,7 @@ SymCryptIntExtendedGcd(
_Out_writes_bytes_( cbScratch ) PBYTE pbScratch,
SIZE_T cbScratch )
{
UINT32 nDigits = max( SymCryptIntDigitsizeOfObject( piSrc1 ), SymCryptIntDigitsizeOfObject( piSrc2 ));
UINT32 nDigits = SYMCRYPT_MAX( SymCryptIntDigitsizeOfObject( piSrc1 ), SymCryptIntDigitsizeOfObject( piSrc2 ));
PSYMCRYPT_INT piA; // size nDigits
PSYMCRYPT_INT piB; // size nDigits, NOT ALLOCATED (part of the pdGcd divisor)
PSYMCRYPT_INT piTmp; // size nDigits
@ -202,8 +202,8 @@ SymCryptIntExtendedGcd(
// Compute how much scratch space we need for the functions we call
cbFnScratch = SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( 2 * nDigits, nDigits );
cbFnScratch = max( cbFnScratch, SYMCRYPT_SCRATCH_BYTES_FOR_INT_MUL( 2*nDigits ) );
cbFnScratch = max( cbFnScratch, SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( nDigits ) );
cbFnScratch = SYMCRYPT_MAX( cbFnScratch, SYMCRYPT_SCRATCH_BYTES_FOR_INT_MUL( 2*nDigits ) );
cbFnScratch = SYMCRYPT_MAX( cbFnScratch, SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR( nDigits ) );
SYMCRYPT_ASSERT( cbScratch >= 4 * SymCryptSizeofIntFromDigits( nDigits ) +
1 * SymCryptSizeofIntFromDigits( 2*nDigits ) +

Просмотреть файл

@ -687,7 +687,7 @@ SymCryptGHashAppendDataPclmulqdq(
//
// We process the data in blocks of up to SYMCRYPT_GHASH_PCLMULQDQ_HPOWERS blocks
//
todo = min( nBlocks, SYMCRYPT_GHASH_PCLMULQDQ_HPOWERS );
todo = SYMCRYPT_MIN( nBlocks, SYMCRYPT_GHASH_PCLMULQDQ_HPOWERS );
//
// The first block is xorred with the state before multiplying it with a power of H
@ -915,7 +915,7 @@ SymCryptGHashAppendDataPmull(
//
// We process the data in blocks of up to SYMCRYPT_GHASH_PCLMULQDQ_HPOWERS blocks
//
todo = min( nBlocks, SYMCRYPT_GHASH_PMULL_HPOWERS );
todo = SYMCRYPT_MIN( nBlocks, SYMCRYPT_GHASH_PMULL_HPOWERS );
//
// The first block is xorred with the state before multiplying it with a power of H

Просмотреть файл

@ -153,11 +153,11 @@ SymCryptHashStateSize( _In_ PCSYMCRYPT_HASH pHash )
VOID
SYMCRYPT_CALL
SymCryptHash(
_In_ PCSYMCRYPT_HASH pHash,
_In_reads_( cbData ) PCBYTE pbData,
SIZE_T cbData,
_Out_writes_( min( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult )
_In_ PCSYMCRYPT_HASH pHash,
_In_reads_( cbData ) PCBYTE pbData,
SIZE_T cbData,
_Out_writes_( SYMCRYPT_MIN( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult )
{
SYMCRYPT_HASH_STATE hash;
@ -191,17 +191,17 @@ SymCryptHashAppend(
VOID
SYMCRYPT_CALL
SymCryptHashResult(
_In_ PCSYMCRYPT_HASH pHash,
_Inout_updates_bytes_( pHash->stateSize ) PVOID pState,
_Out_writes_( min( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult )
_In_ PCSYMCRYPT_HASH pHash,
_Inout_updates_bytes_( pHash->stateSize ) PVOID pState,
_Out_writes_( SYMCRYPT_MIN( cbResult, pHash->resultSize ) ) PBYTE pbResult,
SIZE_T cbResult )
{
BYTE buf[SYMCRYPT_HASH_MAX_RESULT_SIZE];
_Analysis_assume_( pHash->resultSize <= SYMCRYPT_HASH_MAX_RESULT_SIZE );
(*pHash->resultFunc)( pState, buf );
memcpy( pbResult, buf, min( cbResult, pHash->resultSize ));
memcpy( pbResult, buf, SYMCRYPT_MIN( cbResult, pHash->resultSize ));
SymCryptWipe( buf, pHash->resultSize );
}

Просмотреть файл

@ -111,7 +111,7 @@ SymCryptHkdfDerive(
pMacAlgorithm->resultFunc( &state, rbPartialResult );
// Store the result in the output buffer
memcpy(pbCurr, rbPartialResult, min(cbResult, cbMacResultSize));
memcpy(pbCurr, rbPartialResult, SYMCRYPT_MIN(cbResult, cbMacResultSize));
if (cbResult <= cbMacResultSize)
{
goto cleanup;
@ -132,7 +132,7 @@ SymCryptHkdfDerive(
pMacAlgorithm->resultFunc( &state, rbPartialResult );
// Store the result in the output buffer
memcpy(pbCurr, rbPartialResult, min(cbResult, cbMacResultSize));
memcpy(pbCurr, rbPartialResult, SYMCRYPT_MIN(cbResult, cbMacResultSize));
if (cbResult <= cbMacResultSize)
{
goto cleanup;

Просмотреть файл

@ -46,7 +46,7 @@
_TEXT SEGMENT PARA PUBLIC USE32 'CODE'
ASSUME CS:_TEXT, DS:FLAT, SS:FLAT
include <..\inc\symcrypt_version.inc>
include symcrypt_version.inc
include symcrypt_magic.inc

Просмотреть файл

@ -40,7 +40,7 @@
_TEXT SEGMENT PARA PUBLIC USE32 'CODE'
ASSUME CS:_TEXT, DS:FLAT, SS:FLAT
include <..\inc\symcrypt_version.inc>
include symcrypt_version.inc
include symcrypt_magic.inc
include C_asm_shared.inc

Просмотреть файл

@ -15,17 +15,3 @@
#define FAST_FAIL_CRYPTO_LIBRARY 22
#define __fastfail(x) (*((volatile int *)(0)) = (int) (x))
#if !defined min
#define min(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a < __b ? __a : __b; })
#endif
#if !defined max
#define max(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a > __b ? __a : __b; })
#endif

Просмотреть файл

@ -79,7 +79,7 @@ SymCryptModExpWindowed(
UINT32 index = 0;
// Truncate the nBitsExp if above the object size
nBitsExp = min( nBitsExp, SymCryptIntBitsizeOfObject(piExp) );
nBitsExp = SYMCRYPT_MIN( nBitsExp, SymCryptIntBitsizeOfObject(piExp) );
// Calculate the window size
W = MIN_WINDOW_SIZE;

Просмотреть файл

@ -137,7 +137,7 @@ SymCryptParallelHashSetNextWork( PCSYMCRYPT_PARALLEL_HASH pParHash, PSYMCRYPT_PA
{
SYMCRYPT_ASSERT( pHash->inputBlockSize > bytesInBuffer );
todo = min( pHash->inputBlockSize - bytesInBuffer, pOp->cbBuffer );
todo = SYMCRYPT_MIN( pHash->inputBlockSize - bytesInBuffer, pOp->cbBuffer );
memcpy( &pState->buffer[bytesInBuffer], pOp->pbBuffer, todo );
pState->bytesInBuffer += (UINT32) todo;
if( pState->bytesInBuffer == pHash->inputBlockSize )
@ -435,7 +435,7 @@ SymCryptParallelHashProcess(
qsort( pWork, nWork, sizeof( *pWork ), &compareRequestSize );
}
nPar = min( nWork, maxParallel ); // # parallel states we currently work on
nPar = SYMCRYPT_MIN( nWork, maxParallel ); // # parallel states we currently work on
pNextWork = pWork + nPar; // next work pointer.
while( nWork > 0 )
@ -443,7 +443,7 @@ SymCryptParallelHashProcess(
todo = pWork[0]->cbData;
for( i=1; i<nPar; i++ )
{
todo = min( todo, pWork[i]->cbData );
todo = SYMCRYPT_MIN( todo, pWork[i]->cbData );
}
nBytes = todo & ~(pHash->inputBlockSize - 1 );

Просмотреть файл

@ -60,7 +60,7 @@ SymCryptPbkdf2Derive(
SymCryptXorBytes( &rbWorkBuffer[0], &rbBlockResult[0], &rbBlockResult[0], blockSize );
}
bytes = min( cbResult, blockSize );
bytes = SYMCRYPT_MIN( cbResult, blockSize );
memcpy( pbResult, rbBlockResult, bytes );
pbResult += bytes;
cbResult -= bytes;

Просмотреть файл

@ -187,7 +187,7 @@ SymCryptPositiveWidthNafRecoding(
for (UINT32 i=0; i < nRecodedDigits; i++)
{
T1 = SymCryptIntGetBits( piK, i, min(W, nBitsExp-i) ); // Get a batch of W bits (but don't go over nBitsExp)
T1 = SymCryptIntGetBits( piK, i, SYMCRYPT_MIN(W, nBitsExp-i) ); // Get a batch of W bits (but don't go over nBitsExp)
if ((cntrZ>=W) && ((T1 & 0x01) > 0)) // Only store odd digits
{

Просмотреть файл

@ -16,7 +16,7 @@ SymCryptRsaCoreEncScratchSpace( _In_ PCSYMCRYPT_RSAKEY pkRsakey)
{
// Bounded by 2^19 + 2^24 ~ 2^24 (see symcrypt_internal.h)
return SymCryptSizeofModElementFromModulus( pkRsakey->pmModulus ) +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ) );
}
@ -109,7 +109,7 @@ SymCryptRsaCoreEnc(
UNREFERENCED_PARAMETER( cbScratch );
SYMCRYPT_ASSERT( cbScratch >= cbModElement +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ) ));
pbFnScratch = pbScratch;
@ -182,9 +182,9 @@ SymCryptRsaCoreDecCrtScratchSpace( _In_ PCSYMCRYPT_RSAKEY pkRsakey)
SymCryptSizeofIntFromDigits( pkRsakey->nMaxDigitsOfPrimes ) +
cbModElementTotal +
SYMCRYPT_SIZEOF_MODELEMENT_FROM_BITS( pkRsakey->nBitsOfModulus) +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pkRsakey->nDigitsOfModulus, pkRsakey->nMaxDigitsOfPrimes ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pkRsakey->nDigitsOfModulus, pkRsakey->nMaxDigitsOfPrimes ),
SYMCRYPT_SCRATCH_BYTES_FOR_CRT_SOLUTION( pkRsakey->nMaxDigitsOfPrimes ) )));
}
@ -194,7 +194,7 @@ SymCryptRsaCoreDecScratchSpace( _In_ PCSYMCRYPT_RSAKEY pkRsakey)
{
// Bounded by 2^19 + 2^24 ~ 2^24 (see symcrypt_internal.h)
return SymCryptSizeofModElementFromModulus( pkRsakey->pmModulus ) +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ) );
}
@ -276,9 +276,9 @@ SymCryptRsaCoreDecCrt(
//
SYMCRYPT_ASSERT( cbScratch >=
3*cbInt + cbTmp + cbModElementTotal + cbModElementVerify +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pkRsakey->nDigitsOfModulus, pkRsakey->nMaxDigitsOfPrimes ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( pkRsakey->nDigitsOfModulus, pkRsakey->nMaxDigitsOfPrimes ),
SYMCRYPT_SCRATCH_BYTES_FOR_CRT_SOLUTION( pkRsakey->nMaxDigitsOfPrimes ) ))) );
pbFnScratch = pbScratch;
@ -457,7 +457,7 @@ SymCryptRsaCoreDec(
UNREFERENCED_PARAMETER( cbScratch );
SYMCRYPT_ASSERT( cbScratch >= cbModElement +
max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( pkRsakey->nDigitsOfModulus ),
SYMCRYPT_SCRATCH_BYTES_FOR_MODEXP( pkRsakey->nDigitsOfModulus ) ) );
pbFnScratch = pbScratch;
@ -835,7 +835,7 @@ SymCryptRsaOaepEncrypt(
// The SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP macro does not
// overflow cbScratch since cbTmp < 2^17.
cbScratch = cbTmp + max( SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP( hashAlgorithm, cbTmp ), SymCryptRsaCoreEncScratchSpace( pkRsakey ) );
cbScratch = cbTmp + SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP( hashAlgorithm, cbTmp ), SymCryptRsaCoreEncScratchSpace( pkRsakey ) );
pbScratch = (PBYTE)SymCryptCallbackAlloc( cbScratch );
if (pbScratch == NULL)
{
@ -939,9 +939,9 @@ SymCryptRsaOaepDecrypt(
// The SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP macro does not
// overflow cbScratch since cbTmp < 2^17.
#if (SYMCRYPT_CRT_DECRYPTION)
cbScratch = cbTmp + max( SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP( hashAlgorithm, cbSrc ), SymCryptRsaCoreDecCrtScratchSpace( pkRsakey ) );
cbScratch = cbTmp + SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP( hashAlgorithm, cbSrc ), SymCryptRsaCoreDecCrtScratchSpace( pkRsakey ) );
#else
cbScratch = cbTmp + max( SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP( hashAlgorithm, cbSrc ), SymCryptRsaCoreDecScratchSpace( pkRsakey ) );
cbScratch = cbTmp + SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_RSA_OAEP( hashAlgorithm, cbSrc ), SymCryptRsaCoreDecScratchSpace( pkRsakey ) );
#endif
pbScratch = (PBYTE)SymCryptCallbackAlloc( cbScratch );
@ -1184,7 +1184,7 @@ SymCryptRsaPkcs1Verify(
// The SYMCRYPT_SCRATCH_BYTES_FOR_RSA_PKCS1 macro does not
// overflow cbScratch since cbTmp < 2^17.
cbScratch = cbTmp +
max( SymCryptRsaCoreEncScratchSpace( pkRsakey ),
SYMCRYPT_MAX( SymCryptRsaCoreEncScratchSpace( pkRsakey ),
SYMCRYPT_SCRATCH_BYTES_FOR_RSA_PKCS1( cbTmp ) );
pbScratch = (PBYTE)SymCryptCallbackAlloc( cbScratch );
@ -1287,11 +1287,11 @@ SymCryptRsaPssSign(
// overflow cbScratch since cbTmp < 2^17.
#if (SYMCRYPT_CRT_DECRYPTION)
cbScratch = cbTmp +
max( SymCryptRsaCoreDecCrtScratchSpace( pkRsakey ),
SYMCRYPT_MAX( SymCryptRsaCoreDecCrtScratchSpace( pkRsakey ),
SYMCRYPT_SCRATCH_BYTES_FOR_RSA_PSS( hashAlgorithm, cbHashValue, cbTmp ) );
#else
cbScratch = cbTmp +
max( SymCryptRsaCoreDecScratchSpace( pkRsakey ),
SYMCRYPT_MAX( SymCryptRsaCoreDecScratchSpace( pkRsakey ),
SYMCRYPT_SCRATCH_BYTES_FOR_RSA_PSS( hashAlgorithm, cbHashValue, cbTmp ) );
#endif
@ -1412,7 +1412,7 @@ SymCryptRsaPssVerify(
// The SYMCRYPT_SCRATCH_BYTES_FOR_RSA_PSS macro does not
// overflow cbScratch since cbTmp < 2^17.
cbScratch = cbTmp +
max( SymCryptRsaCoreEncScratchSpace( pkRsakey ),
SYMCRYPT_MAX( SymCryptRsaCoreEncScratchSpace( pkRsakey ),
SYMCRYPT_SCRATCH_BYTES_FOR_RSA_PSS( hashAlgorithm, cbHashValue, cbTmp ) );
pbScratch = (PBYTE)SymCryptCallbackAlloc( cbScratch );

Просмотреть файл

@ -276,7 +276,7 @@ SymCryptRsaPkcs1RemoveEncryptionPadding(
// The ScsCopy function can copy the data to the destination buffer, but the input buffer must be
// as long as the output buffer. We can't just use cbPlaintext as the output buffer size, as it is
// unbounded. But we can limit it to cbPkcs1Format as that is the public key size and is public.
SymCryptScsCopy( pbPkcs1Format, cbPlaintextResult, pbPlaintext, min( cbPlaintext, cbPkcs1Format ) );
SymCryptScsCopy( pbPkcs1Format, cbPlaintextResult, pbPlaintext, SYMCRYPT_MIN( cbPlaintext, cbPkcs1Format ) );
cleanup:
// Update scError with the two error masks. Padding error given highest priority.

Просмотреть файл

@ -546,12 +546,12 @@ SymCryptRsakeyGenerate(
pkRsakey->nDigitsOfPrimes[0] = SymCryptDigitsFromBits(pkRsakey->nBitsOfPrimes[0]);
pkRsakey->nDigitsOfPrimes[1] = SymCryptDigitsFromBits(pkRsakey->nBitsOfPrimes[1]);
pkRsakey->nMaxDigitsOfPrimes = max(pkRsakey->nDigitsOfPrimes[0], pkRsakey->nDigitsOfPrimes[1]);
pkRsakey->nMaxDigitsOfPrimes = SYMCRYPT_MAX(pkRsakey->nDigitsOfPrimes[0], pkRsakey->nDigitsOfPrimes[1]);
ndPrimes = pkRsakey->nMaxDigitsOfPrimes;
ndLarge = ndPrimes + ndMod;
primeBits = max(pkRsakey->nBitsOfPrimes[0],pkRsakey->nBitsOfPrimes[1]);
primeBits = SYMCRYPT_MAX(pkRsakey->nBitsOfPrimes[0],pkRsakey->nBitsOfPrimes[1]);
maxTries = 100 * primeBits;
// Create all the SymCryptObjects
@ -565,12 +565,12 @@ SymCryptRsakeyGenerate(
cbDivisor = SymCryptSizeofDivisorFromDigits( ndPrimes );
cbScratch = 2*cbPrimes + cbMod + cbLarge + cbDivisor +
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_PRIME_GEN(ndPrimes),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS(ndMod),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_MUL(ndMod),
max( SYMCRYPT_SCRATCH_BYTES_FOR_CRT_GENERATION(ndPrimes),
max( SYMCRYPT_SCRATCH_BYTES_FOR_EXTENDED_GCD(ndMod),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR(ndPrimes),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_PRIME_GEN(ndPrimes),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS(ndMod),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_MUL(ndMod),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_CRT_GENERATION(ndPrimes),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_EXTENDED_GCD(ndMod),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR(ndPrimes),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( ndMod, ndPrimes )
))))));
@ -767,10 +767,10 @@ SymCryptRsakeySetValue(
cbDivisor = SymCryptSizeofDivisorFromDigits( ndMod );
cbScratch = cbMod + cbLarge + cbDivisor +
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS(ndMod),
max( SYMCRYPT_SCRATCH_BYTES_FOR_CRT_GENERATION(ndMod),
max( SYMCRYPT_SCRATCH_BYTES_FOR_EXTENDED_GCD(ndMod),
max( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR(ndMod),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS(ndMod),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_CRT_GENERATION(ndMod),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_EXTENDED_GCD(ndMod),
SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_DIVISOR(ndMod),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( ndMod, ndMod )
))));
}
@ -850,7 +850,7 @@ SymCryptRsakeySetValue(
pkRsakey->nBitsOfPrimes[i] = SymCryptIntBitsizeOfValue(piPhi);
pkRsakey->nDigitsOfPrimes[i] = SymCryptDigitsFromBits(pkRsakey->nBitsOfPrimes[i]);
pkRsakey->nMaxDigitsOfPrimes = max(pkRsakey->nMaxDigitsOfPrimes, pkRsakey->nDigitsOfPrimes[i]);
pkRsakey->nMaxDigitsOfPrimes = SYMCRYPT_MAX(pkRsakey->nMaxDigitsOfPrimes, pkRsakey->nDigitsOfPrimes[i]);
if (pkRsakey->nBitsOfPrimes[i] < SYMCRYPT_RSAKEY_MIN_BITSIZE_PRIME)
{

Просмотреть файл

@ -3277,19 +3277,6 @@ SymCryptPositiveWidthNafRecoding(
#define __fastfail(x) (*((volatile int *)(0)) = (int) (x))
#if !defined min
#define min(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a < __b ? __a : __b; })
#endif
#if !defined max
#define max(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a > __b ? __a : __b; })
#endif
#endif
// Atomics.

Просмотреть файл

@ -292,7 +292,7 @@ SymCryptScsRotateBuffer(
// Using the mask array is beneficial as long as the array is used twice or more
// Each swap loop processes 2 * blockSize of data, so the block size should never
// be larger than n/4
blockSizeLimit = min( SYMCRYPT_ARRAY_SIZE( Mask ), n/4 );
blockSizeLimit = SYMCRYPT_MIN( SYMCRYPT_ARRAY_SIZE( Mask ), n/4 );
while( blockSize <= blockSizeLimit )
{
// Compute the masks for this level

Просмотреть файл

@ -226,7 +226,7 @@ SymCryptParallelSha256SetNextWork( PSYMCRYPT_PARALLEL_HASH_SCRATCH_STATE pScratc
pState->dataLengthL += pOp->cbBuffer;
if( bytesInBuffer > 0 )
{
todo = (UINT32) min( SYMCRYPT_SHA256_INPUT_BLOCK_SIZE - bytesInBuffer, pOp->cbBuffer );
todo = (UINT32) SYMCRYPT_MIN( SYMCRYPT_SHA256_INPUT_BLOCK_SIZE - bytesInBuffer, pOp->cbBuffer );
memcpy( &pState->buffer[bytesInBuffer], pOp->pbBuffer, todo );
pState->bytesInBuffer += todo;
if( pState->bytesInBuffer == SYMCRYPT_SHA256_INPUT_BLOCK_SIZE )
@ -380,7 +380,7 @@ SymCryptParallelSha256SetNextWork( PSYMCRYPT_PARALLEL_HASH_SCRATCH_STATE pScratc
//
if( bytesInBuffer > 0 )
{
todo = min( SYMCRYPT_SHA256_INPUT_BLOCK_SIZE - bytesInBuffer, pState->cbData );
todo = SYMCRYPT_MIN( SYMCRYPT_SHA256_INPUT_BLOCK_SIZE - bytesInBuffer, pState->cbData );
memcpy( &pState->internalState.hashState.buffer[bytesInBuffer], pState->pbData, todo );
pState->pbData += todo;
pState->cbData -= todo;

Просмотреть файл

@ -76,7 +76,7 @@ SymCryptSp800_108Derive(
pExpandedKey->macAlg->resultFunc( &macState, rbBlockResult );
bytes = min( bytesRemaining, blockSize );
bytes = SYMCRYPT_MIN( bytesRemaining, blockSize );
memcpy( pbResult, rbBlockResult, bytes );
pbResult += bytes;
bytesRemaining -= bytes;

Просмотреть файл

@ -237,7 +237,7 @@ SymCryptTlsPrfPHash(
else
{
// Get the previous Ai
memcpy(rbAi, pbAiIn, min(SYMCRYPT_MAC_MAX_RESULT_SIZE, cbAiIn));
memcpy(rbAi, pbAiIn, SYMCRYPT_MIN(SYMCRYPT_MAC_MAX_RESULT_SIZE, cbAiIn));
}
while (cbBytesToWrite > 0)
@ -253,7 +253,7 @@ SymCryptTlsPrfPHash(
rbPartialResult);
// Store it in the output buffer
memcpy(pbTmp, rbPartialResult, min(cbBytesToWrite, cbMacResultSize));
memcpy(pbTmp, rbPartialResult, SYMCRYPT_MIN(cbBytesToWrite, cbMacResultSize));
// Build A(i+1)
SymCryptTlsPrfMac(
@ -277,7 +277,7 @@ SymCryptTlsPrfPHash(
// Store the next A(i) if needed
if (cbAiOut > 0)
{
memcpy(pbAiOut, rbAi, min(cbAiOut,cbMacResultSize));
memcpy(pbAiOut, rbAi, SYMCRYPT_MIN(cbAiOut,cbMacResultSize));
}
SymCryptWipeKnownSize(rbAi, sizeof(rbAi));
@ -370,7 +370,7 @@ SymCryptTlsPrf1_1Derive(
rbAiMd5,
SYMCRYPT_HMAC_MD5_RESULT_SIZE,
rbPartialResultMd5,
min(cbBytesToWrite, SYMCRYPT_TLS_1_1_CHUNK_SIZE),
SYMCRYPT_MIN(cbBytesToWrite, SYMCRYPT_TLS_1_1_CHUNK_SIZE),
rbAiMd5,
SYMCRYPT_HMAC_MD5_RESULT_SIZE);
@ -383,7 +383,7 @@ SymCryptTlsPrf1_1Derive(
rbAiSha1,
SYMCRYPT_HMAC_SHA1_RESULT_SIZE,
rbPartialResultSha1,
min(cbBytesToWrite, SYMCRYPT_TLS_1_1_CHUNK_SIZE),
SYMCRYPT_MIN(cbBytesToWrite, SYMCRYPT_TLS_1_1_CHUNK_SIZE),
rbAiSha1,
SYMCRYPT_HMAC_SHA1_RESULT_SIZE);
@ -392,7 +392,7 @@ SymCryptTlsPrf1_1Derive(
rbPartialResultMd5,
rbPartialResultSha1,
pbTmp,
min(cbBytesToWrite, SYMCRYPT_TLS_1_1_CHUNK_SIZE));
SYMCRYPT_MIN(cbBytesToWrite, SYMCRYPT_TLS_1_1_CHUNK_SIZE));
if (cbBytesToWrite <= SYMCRYPT_TLS_1_1_CHUNK_SIZE)
{

Просмотреть файл

@ -74,6 +74,11 @@ if(NOT WIN32)
create_resource_h("${DATA_FILES}")
endif()
if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "X86")
# Required on x86 to avoid "error LNK2026: module unsafe for SAFESEH image."
add_link_options(/SAFESEH:NO)
endif()
include_directories(${CMAKE_SOURCE_DIR}/unittest/inc)
include_directories(${CMAKE_SOURCE_DIR}/unittest/lib)
include_directories(${CMAKE_SOURCE_DIR}/unittest/resource)

Просмотреть файл

@ -11,7 +11,7 @@ include_directories(${CMAKE_SOURCE_DIR}/SymCryptDependencies/inc)
add_executable(symcryptunittest_win7nlater ${SOURCES})
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
target_link_libraries(symcryptunittest_win7nlater symcryptunittest_lib symcrypt_usermodewin7 bcrypt ntdll ${RSA32_LIB} ${MSBIGNUM_LIB})

Просмотреть файл

@ -11,7 +11,7 @@ include_directories(${CMAKE_SOURCE_DIR}/SymCryptDependencies/inc)
add_executable(symcryptunittest_win8_1nlater ${SOURCES})
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
target_link_libraries(symcryptunittest_win8_1nlater symcryptunittest_lib symcrypt_usermodewin8_1 bcrypt ntdll ${RSA32_LIB} ${MSBIGNUM_LIB})

Просмотреть файл

@ -11,7 +11,7 @@ include_directories(${CMAKE_SOURCE_DIR}/SymCryptDependencies/inc)
add_executable(symcryptunittest_legacy ${SOURCES})
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
target_link_libraries(symcryptunittest_legacy symcryptunittest_lib symcrypt_generic bcrypt ntdll ${RSA32_LIB} ${MSBIGNUM_LIB})

Просмотреть файл

@ -11,7 +11,7 @@ include_directories(${CMAKE_SOURCE_DIR}/SymCryptDependencies/inc)
add_executable(symcryptunittest ${SOURCES})
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/amd64)
find_library(RSA32_LIB rsa32.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
find_library(MSBIGNUM_LIB msbignum.lib HINTS ${CMAKE_SOURCE_DIR}/SymCryptDependencies/${CMAKE_SYSTEM_PROCESSOR})
target_link_libraries(symcryptunittest symcryptunittest_lib symcrypt_generic bcrypt ntdll ${RSA32_LIB} ${MSBIGNUM_LIB})

Просмотреть файл

@ -17,8 +17,12 @@ main( int argc, _In_reads_( argc ) char * argv[] )
initTestInfrastructure( argc, argv );
TestSaveXmmEnabled = TRUE;
TestSaveYmmEnabled = TRUE;
// As of January 2020, we can't test XMM/YMM register saving and restoring because basic CRT
// functions like memcpy and memcmp use the XMM registers. This causes the test to fail on
// x86, but there's no point in testing this on AMD64 either because it effectively ignores
// the modified XMM values, meaning it's not actually testing anything.
TestSaveXmmEnabled = FALSE;
TestSaveYmmEnabled = FALSE;
addAllAlgs();
@ -27,9 +31,6 @@ main( int argc, _In_reads_( argc ) char * argv[] )
runFunctionalTests();
}
TestSaveXmmEnabled = FALSE;
TestSaveYmmEnabled = FALSE;
if (g_profile)
{
runProfiling();

Просмотреть файл

@ -52,20 +52,4 @@ typedef struct _BCRYPT_MULTI_HASH_OPERATION {
BCRYPT_HASH_OPERATION_TYPE hashOperation; // operation to be performed
PUCHAR pbBuffer; // data to be hashed, or result buffer
uint32_t cbBuffer;
} BCRYPT_MULTI_HASH_OPERATION;
#if !defined min
#define min(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a < __b ? __a : __b; })
#endif
#if !defined max
#define max(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a > __b ? __a : __b; })
#endif
} BCRYPT_MULTI_HASH_OPERATION;

Просмотреть файл

@ -4,6 +4,9 @@
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
// Prevent Windows header files from defining min and max macros (breaks STL)
#define NOMINMAX
#ifdef KERNEL_MODE
//#include <ntddksec.h>
//#include <ntverp.h>
@ -122,21 +125,6 @@
uint32_t cbBuffer;
} BCRYPT_MULTI_HASH_OPERATION;
#if !defined min
#define min(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a < __b ? __a : __b; })
#endif
#if !defined max
#define max(a,b) \
({ __typeof__ (a) __a = (a); \
__typeof__ (b) __b = (b); \
__a > __b ? __a : __b; })
#endif
#define InterlockedAdd64(ptr, val) __sync_fetch_and_add(ptr, val)
#define InterlockedIncrement64(ptr) __sync_fetch_and_add(ptr, 1)
#define InterlockedDecrement64(ptr) __sync_fetch_and_sub(ptr, 1)

Просмотреть файл

@ -55,9 +55,12 @@ if(WIN32)
)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^AMD64")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
list(APPEND SOURCES amd64/saveymm.asm)
set_source_files_properties(amd64/saveymm.asm PROPERTY LANGUAGE ASM_MASM)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "X86")
list(APPEND SOURCES i386/savexmm.asm)
set_source_files_properties(i386/savexmm.asm PROPERTY LANGUAGE ASM_MASM)
endif()
# Need to include an asm file from here.

Просмотреть файл

@ -1078,7 +1078,7 @@ testpbkdf2()
}
iteration = 1 + iteration % 500;
resultsize = max( 1, resultsize % (SYMCRYPT_HMAC_SHA512_RESULT_SIZE * 4));
resultsize = SYMCRYPT_MAX( 1, resultsize % (SYMCRYPT_HMAC_SHA512_RESULT_SIZE * 4));
for (passwordSize = 0; passwordSize <= 32; passwordSize += 1)
{
@ -1676,6 +1676,9 @@ verifyXmmRegisters()
// no longer test this property, but we can at least detect some violations, which is better
// than none.
//
// As of January 2020, this now also affects memcpy(), meaning we can no longer test the YMM
// registers in user mode either.
//
if( (g_xmmTestState[0].m128i_u64[0] | g_xmmTestState[0].m128i_u64[1]) == 0 &&
memcmp( &g_xmmTestState[1], &g_xmmStartState[1], 7 * sizeof( g_xmmStartState[0] ) ) == 0 )
{

Просмотреть файл

@ -303,7 +303,7 @@ testRsaGenerateFunkyKey(
// Calculate scratch space
cbScratch = 3*cbModulus + cbPrime1 + cbPrime2 +
max(SYMCRYPT_SCRATCH_BYTES_FOR_INT_PRIME_GEN(ndModulus),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_INT_PRIME_GEN(ndModulus),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_MUL(ndModulus));
// Allocate

Просмотреть файл

@ -7,8 +7,6 @@
#include "precomp.h"
#undef min
#undef max
#include <chrono>
ULONGLONG g_minMeasurementClockTime = 0;
@ -125,9 +123,9 @@ setPerfScaleFactor() // FOR IA64, even older
maxCurrent = 0;
for( ULONG i=0; i<nProcessors; i++ )
{
//iprint( "Proc %2d, curr =%6d, max = %6d\n", i, pProcPowerInfo[i].CurrentMhz, pProcPowerInfo[i].MaxMhz );
//maxCurrent = max( maxCurrent, pProcPowerInfo[i].CurrentMhz );
maxCurrent = max( maxCurrent, pProcPowerInfo[i].MaxMhz );
//iprint( "Proc %2d, curr =%6d, SYMCRYPT_MAX = %6d\n", i, pProcPowerInfo[i].CurrentMhz, pProcPowerInfo[i].MaxMhz );
//maxCurrent = SYMCRYPT_MAX( maxCurrent, pProcPowerInfo[i].CurrentMhz );
maxCurrent = SYMCRYPT_MAX( maxCurrent, pProcPowerInfo[i].MaxMhz );
}
QueryPerformanceFrequency(&perfFreq);
@ -135,7 +133,7 @@ setPerfScaleFactor() // FOR IA64, even older
g_perfScaleFactor = (1e6 * maxCurrent)/perfFreq.QuadPart;
g_minMeasurementClockTime = min( 1000, (ULONG) (10000/g_perfScaleFactor) );
g_minMeasurementClockTime = SYMCRYPT_MIN( 1000, (ULONG) (10000/g_perfScaleFactor) );
delete[] pProcPowerInfo;
}

Просмотреть файл

@ -5,6 +5,7 @@
//
#include "precomp.h"
#include <sstream>
PrintTable::PrintTable()
@ -153,7 +154,7 @@ PrintTable::print( String heading )
//
for( SIZE_T r=0; r<nRows; r++ )
{
colSize[0] = max( colSize[0], m_rows[r].size() + 1 );
colSize[0] = SYMCRYPT_MAX( colSize[0], m_rows[r].size() + 1 );
}
//
@ -162,7 +163,7 @@ PrintTable::print( String heading )
for( SIZE_T c=0; c<nCols; c++ )
{
//print( "%d\n", m_cols[c].size() );
colSize[c+1] = max( colSize[ c+1 ], m_cols[c].size() );
colSize[c+1] = SYMCRYPT_MAX( colSize[ c+1 ], m_cols[c].size() );
}
for( SIZE_T r=0; r<nRows; r++ )
@ -172,7 +173,7 @@ PrintTable::print( String heading )
// print( "%d(%s) %d(%s)\n", i, m_rows[i].c_str(), j, m_cols[j].c_str() );
SIZE_T s = m_items[ make_pair( m_rows[r], m_cols[c] ) ].size();
// print( "%d %s\n", s, m_items[ make_pair( m_rows[r], m_cols[c] ) ].c_str() );
colSize[ c+1 ] = max( colSize[ c+1 ], s );
colSize[ c+1 ] = SYMCRYPT_MAX( colSize[ c+1 ], s );
}
}

Просмотреть файл

@ -55,7 +55,7 @@ ResultMerge::getResult( PBYTE pbResult, SIZE_T cbResult, BOOL countInvocation )
if( i->strData == j->strData )
{
i->nAgree++;
maxAgree = max( maxAgree, i->nAgree );
maxAgree = SYMCRYPT_MAX( maxAgree, i->nAgree );
}
}
}

Просмотреть файл

@ -124,7 +124,7 @@ Rng::sizetNonUniform( SIZE_T upb, SIZE_T uniformLimit, ULONG logIncrease )
prob >>= 1;
limit <<= logIncrease;
}
limit = min( upb, limit );
limit = SYMCRYPT_MIN( upb, limit );
return sizet( limit );
}
@ -132,7 +132,7 @@ VOID Rng::randomSubRange( SIZE_T bufSize, SIZE_T * pStart, SIZE_T * pLen )
{
SIZE_T a = sizet( bufSize );
SIZE_T b = sizet( bufSize );
*pStart = min( a, b );
*pLen = max( a, b ) - min( a, b);
*pStart = SYMCRYPT_MIN( a, b );
*pLen = SYMCRYPT_MAX( a, b ) - SYMCRYPT_MIN( a, b);
}

Просмотреть файл

@ -248,7 +248,7 @@ CFBAnyLen(
while( cbData > 0 )
{
todo = min( cbData, dwBlockLen );
todo = SYMCRYPT_MIN( cbData, dwBlockLen );
memcpy( buf, input, todo );
memcpy( oldFeedback, feedback, dwBlockLen );
CFB( Cipher, dwBlockLen, buf, buf, keyTable, op, feedback );

Просмотреть файл

@ -2434,7 +2434,7 @@ VOID
algImpDataPerfFunction<ImpSc,AlgXtsAes>( PBYTE buf1, PBYTE buf2, PBYTE buf3, SIZE_T dataSize )
{
SymCryptXtsAesEncrypt( (SYMCRYPT_XTS_AES_EXPANDED_KEY *) buf1,
min( dataSize, 4096 ),
SYMCRYPT_MIN( dataSize, 4096 ),
'twek',
buf2,
buf3,
@ -5313,7 +5313,7 @@ SetupSymCryptDsaAndDh( PBYTE buf1, PBYTE buf2, PBYTE buf3 )
signatureSize = 2*SymCryptDlkeySizeofPrivateKey( pPtrs[0] );
puiSignatureSize = (PUINT32) buf3;
CHECK( buff3Offset + max( signatureSize, SymCryptDlkeySizeofPublicKey( pPtrs[0] ) ) <= SCRATCH_BUF_SIZE,
CHECK( buff3Offset + SYMCRYPT_MAX( signatureSize, SymCryptDlkeySizeofPublicKey( pPtrs[0] ) ) <= SCRATCH_BUF_SIZE,
"Destination buffer cannot fit the DSA signature or the DH secret" );
*puiSignatureSize = signatureSize;

Просмотреть файл

@ -1090,7 +1090,7 @@ testIntAddMixedSize()
rand = g_rng.byte();
nDdst = max( nD1, nD2 );
nDdst = SYMCRYPT_MAX( nD1, nD2 );
if( (rand & 1) == 0 )
{
nDdst += g_rng.sizet( g_digitLimit - nDdst );
@ -1157,7 +1157,7 @@ testIntSubMixedSize()
rand = g_rng.byte();
nDdst = max( nD1, nD2 );
nDdst = SYMCRYPT_MAX( nD1, nD2 );
if( (rand & 1) == 0 )
{
nDdst += g_rng.sizet( g_digitLimit - nDdst );
@ -1446,7 +1446,7 @@ testIsEqual()
UINT32 expected;
UINT32 mask;
SIZE_T nBytes = max( nBytes1, nBytes2 );
SIZE_T nBytes = SYMCRYPT_MAX( nBytes1, nBytes2 );
ArithInt *pSrc1 = randomArithInt( nD1 );
ArithInt *pSrc2 = randomArithInt( nD2 );
@ -1477,7 +1477,7 @@ testIsLessThan()
UINT32 expected;
UINT32 mask;
SIZE_T nBytes = max( nBytes1, nBytes2 );
SIZE_T nBytes = SYMCRYPT_MAX( nBytes1, nBytes2 );
ArithInt *pSrc1 = randomArithInt( nD1 );
ArithInt *pSrc2 = randomArithInt( nD2 );
@ -2081,9 +2081,9 @@ testIntGcdEx()
piSrc2 = SymCryptIntFromDivisor( pSrc2->m_pScDivisor );
} while ( (SymCryptIntGetValueLsbits32(piSrc2) & 0x01) == 0);
ndGcd = min(nD1,nD2);
ndLarge = 2*max(nD1,nD2); // Big enough for LCM and the products InvSrcXModSrcY * SrcX
ndRemainder = max(nD1,nD2); // Big enough for remainders modulo Src1 and Src2
ndGcd = SYMCRYPT_MIN(nD1,nD2);
ndLarge = 2*SYMCRYPT_MAX(nD1,nD2); // Big enough for LCM and the products InvSrcXModSrcY * SrcX
ndRemainder = SYMCRYPT_MAX(nD1,nD2); // Big enough for remainders modulo Src1 and Src2
cbGcd = SymCryptSizeofDivisorFromDigits( ndGcd );
pdGcd = SymCryptDivisorCreate( pbTmp, cbGcd, ndGcd );
@ -2143,7 +2143,7 @@ testIntGcdEx()
piInvSrc1ModSrc2,
piInvSrc2ModSrc1,
pbTmp,
SYMCRYPT_SCRATCH_BYTES_FOR_EXTENDED_GCD( max( nD1, nD2 ) ) );
SYMCRYPT_SCRATCH_BYTES_FOR_EXTENDED_GCD( SYMCRYPT_MAX( nD1, nD2 ) ) );
// Verifications
switch (rand)
@ -2540,7 +2540,7 @@ ArithModElement::ArithModElement( ArithModulus * pModulus, UINT32 nFail )
// Pick a random Int value of the right size. Our Int values contain the low-Hamming-weight and small values we need for corner cases.
nSrcDigits = 1 + (UINT32)g_rng.sizet( 2 * nDigits ); // compute this once (min might be a macro)
nSrcDigits = min( nSrcDigits, g_digitLimit - 1);
nSrcDigits = SYMCRYPT_MIN( nSrcDigits, g_digitLimit - 1);
pSrc = randomArithInt( nSrcDigits, nFail );
SymCryptIntToModElement( pSrc->m_pScInt, m_pModulus->m_pScModulus, m_pScModElement,g_scratch, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ) );
@ -3215,7 +3215,7 @@ testModExp()
pMod->m_pScModulus,
pB1->m_pScModElement,
pE1->m_pScInt,
max(1, SymCryptIntBitsizeOfValue(pE1->m_pScInt)),
SYMCRYPT_MAX(1, SymCryptIntBitsizeOfValue(pE1->m_pScInt)),
flags,
peTmp1,
pbScratch,
@ -3226,7 +3226,7 @@ testModExp()
pMod->m_pScModulus,
pB1->m_pScModElement,
pE2->m_pScInt,
max(1, SymCryptIntBitsizeOfValue(pE2->m_pScInt)),
SYMCRYPT_MAX(1, SymCryptIntBitsizeOfValue(pE2->m_pScInt)),
flags,
peTmp2,
pbScratch,
@ -3243,7 +3243,7 @@ testModExp()
pMod->m_pScModulus,
pB1->m_pScModElement,
piTmp,
max(1, SymCryptIntBitsizeOfValue(piTmp)),
SYMCRYPT_MAX(1, SymCryptIntBitsizeOfValue(piTmp)),
flags,
peTmp2,
pbScratch,
@ -3303,8 +3303,8 @@ testModMultiExp()
pExp = randomArithInt( nDI );
piExps[i] = pExp->m_pScInt;
nBitsExps[i] = max( 1, SymCryptIntBitsizeOfValue(piExps[i])); // We can never pass nBitsExp == 0
nBitsExpMax = max( nBitsExpMax, nBitsExps[i] );
nBitsExps[i] = SYMCRYPT_MAX( 1, SymCryptIntBitsizeOfValue(piExps[i])); // We can never pass nBitsExp == 0
nBitsExpMax = SYMCRYPT_MAX( nBitsExpMax, nBitsExps[i] );
}
// Create temporary elements in the g_scratch space

Просмотреть файл

@ -378,7 +378,7 @@ testAuthEncRandom( AuthEncMultiImp * pImp, int rrep, PCBYTE pbResult, SIZE_T cbR
do
{
SIZE_T todo = g_rng.sizet( cbData - idx + cbData/10 + 10);
todo = min( todo, cbData - idx );
todo = SYMCRYPT_MIN( todo, cbData - idx );
BOOLEAN last = todo == cbData - idx;
pImp->encrypt( &buf[nonceIdx], cbNonce,
@ -425,7 +425,7 @@ testAuthEncRandom( AuthEncMultiImp * pImp, int rrep, PCBYTE pbResult, SIZE_T cbR
do
{
SIZE_T todo = g_rng.sizet( cbData - idx + cbData/10 + 10);
todo = min( todo, cbData - idx );
todo = SYMCRYPT_MIN( todo, cbData - idx );
BOOLEAN last = todo == cbData - idx;
if( last && (g_rng.byte() & 1) == 0 )
{

Просмотреть файл

@ -8,7 +8,7 @@
#include "testInterop.h"
// Maximum sizes of DSA and DH key blob (blobs passed around always contain **private** info)
#define TEST_DL_MAX_SIZEOF_DSA_BLOB (max(sizeof(BCRYPT_DSA_KEY_BLOB)+4*TEST_DL_MAX_NUMOF_BYTES, sizeof(BCRYPT_DSA_KEY_BLOB_V2) + 5*TEST_DL_MAX_NUMOF_BYTES))
#define TEST_DL_MAX_SIZEOF_DSA_BLOB (SYMCRYPT_MAX(sizeof(BCRYPT_DSA_KEY_BLOB)+4*TEST_DL_MAX_NUMOF_BYTES, sizeof(BCRYPT_DSA_KEY_BLOB_V2) + 5*TEST_DL_MAX_NUMOF_BYTES))
#define TEST_DL_MAX_SIZEOF_DH_BLOB (sizeof(BCRYPT_DH_KEY_BLOB)+4*TEST_DL_MAX_NUMOF_BYTES)
#define TEST_DL_MAX_SIZEOF_DH_PARAMS (sizeof(BCRYPT_DH_PARAMETER_HEADER)+2*TEST_DL_MAX_NUMOF_BYTES)

Просмотреть файл

@ -305,7 +305,7 @@ testDsaSingle(
// As the truncation is to the bit size, we introduce a difference in the bytes
// that are always relevant.
memcpy( buf, pbHash, cbHash );
buf[g_rng.sizet( min( cbHash, pKey->pGroup->cbPrimeQ - 1 ) )]++;
buf[g_rng.sizet( SYMCRYPT_MIN( cbHash, pKey->pGroup->cbPrimeQ - 1 ) )]++;
ntStatus = pDsa->verify( buf, cbHash, pbSig, cbSig );
CHECK( !NT_SUCCESS( ntStatus ), "Success verifying modified DSA signature" );
@ -399,7 +399,7 @@ testDsatestGroups( DsaImplementation * pDsa, INT64 line )
CHECK( NT_SUCCESS( ntStatus ), "?" );
// Modify the hash, but only in the bytes that are known to be used
SIZE_T j = g_rng.sizet( min( cbHash, pGroupBlob->cbPrimeQ - 1) );
SIZE_T j = g_rng.sizet( SYMCRYPT_MIN( cbHash, pGroupBlob->cbPrimeQ - 1) );
hash[j]++;
ntStatus = pDsa->verify( hash, cbHash, sig, cbSig );
hash[j]--;

Просмотреть файл

@ -162,7 +162,7 @@ testEccArithmetic( _In_ PCSYMCRYPT_ECURVE pCurve )
cbIntLargeSize = SymCryptSizeofIntFromDigits( SymCryptEcurveDigitsofScalarMultiplier(pCurve) + 1 );
cbEckeySize = SymCryptSizeofEckeyFromCurve( pCurve );
cbScratch = max( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS( pCurve ),
cbScratch = SYMCRYPT_MAX( SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_ECURVE_OPERATIONS( pCurve ),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_DIVMOD( SymCryptEcurveDigitsofScalarMultiplier(pCurve) + 1, pCurve->GOrdDigits ) );
cbScratchMul = SYMCRYPT_SCRATCH_BYTES_FOR_SCALAR_ECURVE_OPERATIONS( pCurve );
cbScratchMultiMul = SYMCRYPT_SCRATCH_BYTES_FOR_MULTI_SCALAR_ECURVE_OPERATIONS( pCurve, MULTIMUL_POINTS );

Просмотреть файл

@ -280,7 +280,7 @@ testMacRandom( MacMultiImp * pMac, int rrep, SIZE_T keyLen, PCBYTE pbResult, SIZ
//
rng.reset( (PCBYTE) pMac->m_algorithmName.data(), pMac->m_algorithmName.size() );
const SIZE_T bufSize = max( 64, pMac->inputBlockLen() * 4);
const SIZE_T bufSize = SYMCRYPT_MAX( 64, pMac->inputBlockLen() * 4);
CHECK( bufSize <= sizeof( buf ), "Input block len too large" );
// We used to set the buffer to 0 at the start, but Poly1305 has a fixed-point at 0

Просмотреть файл

@ -208,7 +208,7 @@ createKatFileSingleRawEnc( FILE * f, PCRSAKEY_TESTBLOB pBlob )
UINT32 nDigits = SymCryptDigitsFromBits( pBlob->nBitsModulus );
SIZE_T cbScratch = SYMCRYPT_SCRATCH_BYTES_FOR_INT_TO_MODULUS( nDigits );
cbScratch = max( cbScratch, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ) );
cbScratch = SYMCRYPT_MAX( cbScratch, SYMCRYPT_SCRATCH_BYTES_FOR_COMMON_MOD_OPERATIONS( nDigits ) );
PBYTE pbScratch = (PBYTE) SymCryptCallbackAlloc( cbScratch );
CHECK( pbScratch != NULL, "?" );

Просмотреть файл

@ -63,7 +63,7 @@ rsaTestKeysAddOneFunky( UINT32 nBitsOfModulus )
// Calculate scratch space
cbScratch = 3*cbModulus + cbPrime1 + cbPrime2 +
max(SYMCRYPT_SCRATCH_BYTES_FOR_INT_PRIME_GEN(ndModulus),
SYMCRYPT_MAX(SYMCRYPT_SCRATCH_BYTES_FOR_INT_PRIME_GEN(ndModulus),
SYMCRYPT_SCRATCH_BYTES_FOR_INT_MUL(ndModulus));
// Allocate
@ -991,7 +991,7 @@ testRsaSignPss()
UINT32 cbHash;
UINT32 cbSalt;
cbHash = g_rng.uint32() % sizeof( hash );
cbHash = min( cbHash, cbModulus - 3);
cbHash = SYMCRYPT_MIN( cbHash, cbModulus - 3);
cbSalt = g_rng.uint32() % (cbModulus - 2 - cbHash );
// The multi-imp sign automatically does a cross-verification of all

Просмотреть файл

@ -47,7 +47,7 @@ testScsCopy()
nSrc = nSrc % sizeof( buf1 );
nDst = nDst % sizeof( buf1 );
UINT32 nCopied = min( nSrc, nDst );
UINT32 nCopied = SYMCRYPT_MIN( nSrc, nDst );
GENRANDOM( buf1, sizeof( buf1 ) );
GENRANDOM( buf2, sizeof( buf2 ) );

Просмотреть файл

@ -632,8 +632,8 @@ testLongMessage( HashMultiImp * pHash, int maxLen, PCBYTE pbResult, SIZE_T cbRes
pHash->initWithLongMessage( startLen );
while( nBytes > 0 )
{
pHash->append( data, min( 5, nBytes ) );
nBytes -= min( 5, nBytes );
pHash->append( data, SYMCRYPT_MIN( 5, nBytes ) );
nBytes -= SYMCRYPT_MIN( 5, nBytes );
}
pHash->result( tmp, cbResult );
CHECK3( memcmp( tmp, res, cbResult ) == 0, "Inconsistent results in line %lld", line );
@ -700,7 +700,7 @@ testLongMessageConsistency( HashMultiImp * pHash, int nInputBlocks, LONGLONG li
while( cbData > 0 )
{
SIZE_T todo = min( cbData, blockLen );
SIZE_T todo = SYMCRYPT_MIN( cbData, blockLen );
pHash->append( pbData, todo );
pbData += todo;
cbData -= todo;