Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NIST cipher and hash tests vectors. #698

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 254 additions & 0 deletions host/xtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ endif()
find_package(Python REQUIRED)

include(GNUInstallDirs)
include(ExternalProject)

macro(DOWNLOAD_FILE url filename hash)

ExternalProject_Add(
download_${hash}
URL_HASH SHA256=${hash}
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}
DOWNLOAD_COMMAND wget ${url}
UPDATE_COMMAND ""
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND unzip -o ${CMAKE_CURRENT_BINARY_DIR}/${filename} -d ${CMAKE_CURRENT_BINARY_DIR}
)

endmacro(DOWNLOAD_FILE)

macro(EMBED_8100FILE prefix infile)
add_custom_command(
Expand Down Expand Up @@ -117,6 +134,243 @@ if (CFG_CRYPTO_SE05X)
add_compile_options(-DCFG_CRYPTO_SE05X)
endif()

if (CFG_GCM_NIST_VECTORS)
add_compile_options(-DCFG_GCM_NIST_VECTORS)

macro(CREATE_NIST_GCM_VECTORS infile mode)
if (CFG_GCM_NIST_VECTORS_LIMITED)
set(limited "--limited")
endif()

add_custom_command(
OUTPUT ${infile}.h
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_gcm_test.py --inf ${infile}.rsp
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h --mode=${mode} ${limited}
DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_gcm_test.py ${infile}.rsp
DEPENDS download_f9fc479e134cde2980b3bb7cddbcb567b2cd96fd753835243ed067699f26a023
)

set_property(SOURCE regression_4000.c APPEND PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${infile}.h)
endmacro(CREATE_NIST_GCM_VECTORS)

DOWNLOAD_FILE(
https://csrc.nist.gov/csrc/media/projects/cryptographic-algorithm-validation-program/documents/mac/gcmtestvectors.zip
gcmtestvectors.zip
f9fc479e134cde2980b3bb7cddbcb567b2cd96fd753835243ed067699f26a023
)

CREATE_NIST_GCM_VECTORS(gcmDecrypt128 decrypt)
CREATE_NIST_GCM_VECTORS(gcmDecrypt192 decrypt)
CREATE_NIST_GCM_VECTORS(gcmDecrypt256 decrypt)
CREATE_NIST_GCM_VECTORS(gcmEncryptExtIV128 encrypt)
CREATE_NIST_GCM_VECTORS(gcmEncryptExtIV192 encrypt)
CREATE_NIST_GCM_VECTORS(gcmEncryptExtIV256 encrypt)
endif()

if (CFG_CMAC_NIST_VECTORS)
add_compile_options(-DCFG_CMAC_NIST_VECTORS)

macro(CREATE_NIST_CMAC_VECTORS infile mode)
if (CFG_CMAC_NIST_VECTORS_LIMITED)
set(limited "--limited")
endif()

add_custom_command(
OUTPUT ${infile}.h
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_cmac_test.py --inf ${infile}.rsp
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h --mode=${mode} ${limited}
DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_cmac_test.py ${infile}.rsp
DEPENDS download_bdda4edade394c9a2ae74d9cd0921caa120c911a5e735e37abf39d0d5f062be1
)

set_property(SOURCE regression_4000.c APPEND PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${infile}.h)
endmacro(CREATE_NIST_CMAC_VECTORS)

DOWNLOAD_FILE(
https://csrc.nist.gov/csrc/media/projects/cryptographic-algorithm-validation-program/documents/mac/cmactestvectors.zip
cmactestvectors.zip
bdda4edade394c9a2ae74d9cd0921caa120c911a5e735e37abf39d0d5f062be1
)

CREATE_NIST_CMAC_VECTORS(CMACGenAES128 generate)
CREATE_NIST_CMAC_VECTORS(CMACGenAES192 generate)
CREATE_NIST_CMAC_VECTORS(CMACGenAES256 generate)
CREATE_NIST_CMAC_VECTORS(CMACVerAES128 verify)
CREATE_NIST_CMAC_VECTORS(CMACVerAES192 verify)
CREATE_NIST_CMAC_VECTORS(CMACVerAES256 verify)
endif()

if (CFG_XTS_NIST_VECTORS)
add_compile_options(-DCFG_XTS_NIST_VECTORS)

macro(CREATE_NIST_XTS_VECTORS infile)
if (CFG_XTS_NIST_VECTORS_LIMITED)
set(limited "--limited")
endif()

add_custom_command(
OUTPUT ${infile}.h
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_xts_test.py
--inf "format\ tweak\ value\ input\ -\ 128\ hex\ str/${infile}.rsp"
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h --mode=encrypt ${limited}
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_xts_test.py
--inf "format\ tweak\ value\ input\ -\ 128\ hex\ str/${infile}.rsp"
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h --mode=decrypt ${limited}
DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_xts_test.py
DEPENDS "format\ tweak\ value\ input\ -\ 128\ hex\ str/${infile}.rsp"
DEPENDS download_67bb04b018182f65530596786e7783f817d2e56509bf3b1f066609b8e3e29c36
)

set_property(SOURCE regression_4000.c APPEND PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${infile}.h)
endmacro(CREATE_NIST_XTS_VECTORS)

DOWNLOAD_FILE(
https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/aes/XTSTestVectors.zip
XTSTestVectors.zip
67bb04b018182f65530596786e7783f817d2e56509bf3b1f066609b8e3e29c36
)

CREATE_NIST_XTS_VECTORS(XTSGenAES128)
CREATE_NIST_XTS_VECTORS(XTSGenAES256)
endif()

if (CFG_CCM_NIST_VECTORS)
add_compile_options(-DCFG_CCM_NIST_VECTORS)

macro(CREATE_NIST_CCM_VECTORS infile)
if (CFG_CCM_NIST_VECTORS_LIMITED)
set(limited "--limited")
endif()

add_custom_command(
OUTPUT ${infile}.h
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_ccm_test.py --inf ${infile}.rsp
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h --mode=encrypt ${limited}
DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_ccm_test.py ${infile}.rsp
DEPENDS download_0e3c96761bd8f1a0b4dfe666146c32f7d367a49968375ff091b8da9ecaa673aa
)

set_property(SOURCE regression_4000.c APPEND PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${infile}.h)
endmacro(CREATE_NIST_CCM_VECTORS)

DOWNLOAD_FILE(
https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/ccmtestvectors.zip
ccmtestvectors.zip
0e3c96761bd8f1a0b4dfe666146c32f7d367a49968375ff091b8da9ecaa673aa
)

CREATE_NIST_CCM_VECTORS(VTT128)
CREATE_NIST_CCM_VECTORS(VTT192)
CREATE_NIST_CCM_VECTORS(VTT256)
CREATE_NIST_CCM_VECTORS(VPT128)
CREATE_NIST_CCM_VECTORS(VPT192)
CREATE_NIST_CCM_VECTORS(VPT256)
CREATE_NIST_CCM_VECTORS(VNT128)
CREATE_NIST_CCM_VECTORS(VNT192)
CREATE_NIST_CCM_VECTORS(VNT256)
CREATE_NIST_CCM_VECTORS(VADT128)
CREATE_NIST_CCM_VECTORS(VADT192)
CREATE_NIST_CCM_VECTORS(VADT256)
endif()

if (CFG_HASH_NIST_VECTORS)
add_compile_options(-DCFG_HASH_NIST_VECTORS)

macro(CREATE_NIST_SHA_VECTORS infile algo)
if (CFG_HASH_NIST_VECTORS_LIMITED)
set(limited "--limited")
endif()

add_custom_command(
OUTPUT ${infile}.h
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_sha_test.py
--inf "shabytetestvectors/${infile}.rsp"
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h --algo=${algo} ${limited}
DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_sha_test.py "shabytetestvectors/${infile}.rsp"
DEPENDS download_929ef80b7b3418aca026643f6f248815913b60e01741a44bba9e118067f4c9b8
)

set_property(SOURCE regression_4000.c APPEND PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${infile}.h)
endmacro(CREATE_NIST_SHA_VECTORS)

macro(CREATE_NIST_SHA3_VECTORS infile algo)
if (CFG_HASH_NIST_VECTORS_LIMITED)
set(limited "--limited")
endif()

add_custom_command(
OUTPUT ${infile}.h
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_sha_test.py
--inf ${infile}.rsp
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h --algo=${algo} ${limited}
DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_sha_test.py ${infile}.rsp
DEPENDS download_cd07701af2e47f5cc889d642528b4bf11f8b6eb55797c7307a96828ed8d8fc8c
)

set_property(SOURCE regression_4000.c APPEND PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${infile}.h)
endmacro(CREATE_NIST_SHA3_VECTORS)

macro(CREATE_NIST_HMAC_VECTORS infile)
if (CFG_HASH_NIST_VECTORS_LIMITED)
set(limited "--limited")
endif()

add_custom_command(
OUTPUT ${infile}.h
COMMAND ${Python_EXECUTABLE} ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_hmac_test.py ${limited}
--inf ${infile}.rsp
--outf ${CMAKE_CURRENT_BINARY_DIR}/${infile}.h
DEPENDS ${OPTEE_TEST_ROOT_DIR}/scripts/rsp_to_hmac_test.py ${infile}.rsp
DEPENDS download_418c3837d38f249d6668146bd0090db24dd3c02d2e6797e3de33860a387ae4bd
)

set_property(SOURCE regression_4000.c APPEND PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${infile}.h)
endmacro(CREATE_NIST_HMAC_VECTORS)

DOWNLOAD_FILE(
https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/shs/shabytetestvectors.zip
shabytetestvectors.zip
929ef80b7b3418aca026643f6f248815913b60e01741a44bba9e118067f4c9b8
)
DOWNLOAD_FILE(
https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/sha3/sha-3bytetestvectors.zip
sha-3bytetestvectors.zip
cd07701af2e47f5cc889d642528b4bf11f8b6eb55797c7307a96828ed8d8fc8c
)
DOWNLOAD_FILE(
https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/mac/hmactestvectors.zip
hmactestvectors.zip
418c3837d38f249d6668146bd0090db24dd3c02d2e6797e3de33860a387ae4bd
)

CREATE_NIST_SHA_VECTORS(SHA1LongMsg SHA1)
CREATE_NIST_SHA_VECTORS(SHA1ShortMsg SHA1)
CREATE_NIST_SHA_VECTORS(SHA224LongMsg SHA224)
CREATE_NIST_SHA_VECTORS(SHA224ShortMsg SHA224)
CREATE_NIST_SHA_VECTORS(SHA256LongMsg SHA256)
CREATE_NIST_SHA_VECTORS(SHA256ShortMsg SHA256)
CREATE_NIST_SHA_VECTORS(SHA384LongMsg SHA384)
CREATE_NIST_SHA_VECTORS(SHA384ShortMsg SHA384)
CREATE_NIST_SHA_VECTORS(SHA512LongMsg SHA512)
CREATE_NIST_SHA_VECTORS(SHA512ShortMsg SHA512)
CREATE_NIST_SHA3_VECTORS(SHA3_224LongMsg SHA3_224)
CREATE_NIST_SHA3_VECTORS(SHA3_224ShortMsg SHA3_224)
CREATE_NIST_SHA3_VECTORS(SHA3_256LongMsg SHA3_256)
CREATE_NIST_SHA3_VECTORS(SHA3_256ShortMsg SHA3_256)
CREATE_NIST_SHA3_VECTORS(SHA3_384LongMsg SHA3_384)
CREATE_NIST_SHA3_VECTORS(SHA3_384ShortMsg SHA3_384)
CREATE_NIST_SHA3_VECTORS(SHA3_512LongMsg SHA3_512)
CREATE_NIST_SHA3_VECTORS(SHA3_512ShortMsg SHA3_512)
CREATE_NIST_HMAC_VECTORS(HMAC)
endif()

################################################################################
# Built binary
################################################################################
Expand Down
Loading